I'm working with the Blackberry Touch Event and I need to process the TouchEvent.MOVE, TouchEvent.UP and TouchEvent.DOWN to move a carousel of images and the TouchEvent.CLICK to generate some specific action.
My problem is that the touchEvent() method is being called several times. How can I prevent this? Because the behaviour is getting all messed up.
For example: when I just want to capture the TouchEvent.CLICK event, the UP-DOWN-MOVE-CLICK are being triggered one after the next.
My code does the following:
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
//CHANGE THE CONTENT OF A FIELD
return true;
} else if ((message.getEvent() == TouchEvent.MOVE)
|| (message.getEvent() == TouchEvent.UP)
|| (message.getEvent() == TouchEvent.DOWN)) {
//DELETE THE FIELD
//MOVE A CAROUSEL OF IMAGES
} else {
return false;
}
}
public void moverTouch(int dx) {
//ADD THE FIELD PREVIOUSLY DELETED
}
As you can see, when the CLICK event is captured, I need to change the content of a field, but when the MOVE or UP or DOWN event is captured, I need to delete that Field from his manager, do some working with a carousel of images, and then re-add the field previously deleted.
The carousel moving part works fine, but when I try to capture JUST the CLICK event, and the others are being triggered as well, but the moverTouch() function doesn't get triggered because there is no actual movement on the carousel of images, I end up with a deleted field that I need to update its content.
At a glance:
I think you need to differentiate touch gestures (I believe you are "listening" for something like a swipe gesture to scroll the gallery image) from "normal" touch events (specifically you need to process TouchEvent.CLICK to apply "some specific action" to the clicked image).
To decide whether the TouchEvent represents a gesture there is a TouchEvent.GESTURE constant. Then it is possible to know what exactly TouchGesture it represents by calling TouchEvent.getGesture().
Some sample code for touch gestures can be viewed here.
Related
I'm developing a game on Unity for iOS devices. I've implemented the following code for touch:
void Update () {
ApplyForce ();
}
void ApplyForce() {
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) {
Debug.Log("Touch Occured");
}
}
I've dragged this script onto my game object which is a sphere. But the log message appears no matter where I touch. I want to detect touch only when the users touches the object.
stick the code bellow in your camera, or something else that will persist in the level you're designing. It can be anything, even an empty gameobject. The only important thing is that it only exists ONCE in your level, otherwise you'll have multiple touch checks running at the same time, which will cause some seriously heavy load on the system.
void Update () {
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay( Input.GetTouch(0).position );
RaycastHit hit;
if ( Physics.Raycast(ray, out hit) && hit.transform.gameObject.Name == "myGameObjectName")
{
hit.GetComponent<TouchObjectScript>().ApplyForce();
}
}
}
In the above script, hit.transform.gameObject.Name == "myGameObjectName" can be replaced by any other method you want to check that the object hit by the raycast is the object you want to apply a force to. One easy method is by Tags for example.
Another thing to keep in mind is that raycast will originate at your camera (at the position relative to your finger's touch) and hit the first object with a collider. So if your object is hidden behind something else, you won't be able to touch it.
Also put the script bellow in your touch object (in this example, called TouchObjectScript.cs)
void Update () {
}
public void ApplyForce() {
Debug.Log("Touch Occured");
}
If something wasn't clear, or you need any further help, leave a comment and I'll get back to you.
The best way to do this, is just adding:
void OnMouseDown () {}
to the gameobject you want to be clicked.
The problem with this is that you cannot press 2 things at one time.
I am dealing with KeywordFilterField which is populated with the list of the countries. Now the problem i am facing is that when i click the particular country it should move to the next screen as I have written the pushScreen code in the trackwheelClick event after checking that _keywordFilterField is focusable or not, but this is not the case. The Menu opens when trackwheelClick event is fired, at the center of the screen, rather than moving onto the next screen.Can anybody have the idea why Menu dialog opens on the trackwheelclick event instead of going to the next screen.
See what i have done on trackwheel click event:
protected boolean trackwheelClick(int status, int time) {
if (_keywordFilterField.isFocus()) {
int index = _keywordFilterField.getSelectedIndex();
ReadableList readableList = _keywordFilterField.getResultList();
Object selectedCountry = readableList.getAt(index);
String countryName=selectedCountry.toString();
urlutf8Encoder=new URLUTF8Encoder();
String newCountry=urlutf8Encoder.encode(countryName);
pushToSearchResult(newCountry,countryName);//To Next SCreen
return true;
}
return false;
}
But it looks like:
The trackwheelClick event returns a boolean that indicates whether the event is consumed. Once an event is consumed, it stops propagating to other UI elements. If you return true, the menu will stop appearing.
We have a iPad app which includes a two-column news reader. The left view contains the list of news of which some link directly to a news and some push another view controller with another list of news. This will also cause a UIButton to be set as the leftBarButtonItem of the navigation bar. If we are on first level, a simple image that cannot be tapped will be the leftBarButtonItem.
My goal is now to have a test that taps every news on the first level. If a news leads to a second level list, it should tap the UIButton in the navigation bar.
How can I check, if the leftBarButtonItem is "tappable"? Since it can be either an image or a button, just calling navigationBar().leftButton().tap() will lead to an error if it's an image.
I'm also using the tuneup library if that's any help.
Almost all elements in UIAutomation could be tapped. It does not matter if it is an Image, View or a Button. You will get an error in case an object you are trying to tap is invalid.
How to check:
if ( navigationBar().leftButton().checkIsValid() )
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}
or you can check if an object you are trying to tap is a button, for example (not the best way but it works):
if ( navigationBar().leftButton().toString() == "[object UIAButton]" )
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}
checkIsValid() is available for all UI elements. It will return true if an object exists.
toString() will return [object UIAElementNil] if element is invalid or will return [object UIAButton] or [object UIAImage].
Also try to use Apple documentation:
http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIAElementClassReference/UIAElement/UIAElement.html
You can simply use
if (navigationBar().leftButton().exists)
{
navigationBar().leftButton().tap();
}
else
{
//do what you need.
}
Hello all i stuck at one problem. I have implemented a ListField in one Screen. On top of the Screen i have used one HorizontalFieldManager to hold a TitleLabel and Two Butons. I have pushed some screen on all the rows of the listfield. My problem is, letSuppose when i am on 4th row and i have selected what i want then when i clicking on the button, then the button worked but the screen which i have implemented at 4th row also appear how to avoid it. I am testing it on storm 9550 simulator and using Blackberry eclipse plugin5.0 . I am running out of idea please help me .
navigation click is like this
protected boolean navigationClick(int status, int time) {
selectListAndButton();
return true;
}
//And here is the selectListAndButton Method
private selectListAndButton(){
Field field = getFieldWithFocus().getLeafFieldWithFocus();
if(field == backCustomButton){
//Popped the active Screen
}else if(field == saveCustomButton){
//Saving some Data to the Database And pushing another Screen here
// problem comes here if i am at 2nd row of the listfield and selects
something from there and clicked on the button the screen which was
implemented at 2nd row also appears
}
else if (_list.getSelectedIndex() == 0){
//Called a date picker
}
else if (_list.getSelectedIndex() == 1){
//Pushed some another screen
}
else if (_list.getSelectedIndex() == ){
//Pushed some another screen
}
You need to override onTouch for Screen and call specific functionality depend on event coordinates and Field boundaries:
protected boolean touchEvent(TouchEvent message) {
if (isTouchInside(message, saveCustomButton)) {
save();
} else {
showNextScreen();
}
}
private boolean isTouchInside(TouchEvent messages, Field field) {
int eventCode = message.getEvent();
int touchX = message.getX(1);
int touchY = message.getY(1);
XYRect rect = field.getContentRect();
return rect.contains(touchX, touchY);
}
I had solved it. but posting the answer late. I just dropped the idea of using ListField because i dont have so much rows to add. So i have just used the little trick rather using ListField i have used HorizontalFieldManager and its look like a List so everything working fine.
Thanks cheers :)
My workFlow is like this ... I have taken Three HoriZontalManager one for holding theBackgroundImage of the button and two HoriZontalManager to hold the CustomButton and i am adding the main hfm which hold the button and the background image at top and then i have added the list in a VerticalfieldManager but i dont get the button Working the focus always remains on the list Field. Now when I click on the Button the focus always resides on the First row of the list Field so it always show me the picker which is actually i have implemented on the first row of listfield. How can i Solve it ..
Thanks in Advanced..
Please help.
I have solved This issue ... I had to check that if the focus is on the button then do my work else the list field will be invoked and it solved the issue. And it works for touchScreen simulator as well as trackpad devices.
protected boolean navigationClick(int status, int time) {
// if the row select do something with it
// for first row which is time
if(backCustomButton.isFocus()) {
UiApplication.getUiApplication().pushScreen(new saveScreen());
}else if (saveCustomButton.isFocus()) {
Dialog.inform("Save Button on focus");
}else
if (_list.getSelectedIndex() == 0){
// Do the ListSpecific things
}