Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 17
Registered: ‎05-12-2011
My Device: 9630
My Carrier: Developer

Get Direction on Touchevent.move

      I am creating a picturescrollfield and i am playing audio on each image i have override  the touchevent when move the image touch.Move is call.

i want to get the direction of MOVE left/right

i have tryied by x,y coordinate but i am coming in next image only one time move so coordinate meet only one so i can not compare 

                      Thanks in advance

pls quickly relply me

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get Direction on Touchevent.move

I believe MOVE is a Gesture, so you need to get the Gesture (getGesture()), and then you can check the direction.  The API should help you. 

Contributor
Posts: 17
Registered: ‎05-12-2011
My Device: 9630
My Carrier: Developer

Re: Get Direction on Touchevent.move

I have applied the get gesture

this type 

     TouchGesture touchgesture=message.getGesture();

if (touchgesture!=null) {

if (touchgesture.getEvent()==TouchGesture.SWIPE)

 {

switch (touchgesture.getSwipeDirection()) {

case TouchGesture.SWIPE_WEST:

but when we move control is not goning on    if (touchgesture.getEvent()==TouchGesture.SWIPE)    this line

and throw the null pointer exception

pls help me

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get Direction on Touchevent.move

Given the code you have shown us, it is not possible for touchGesture to be null, and since none of the other variables in this line are Objects, from your code it is not possible for it to throw NPE.  Which I think means that there is something missing with the code you supplied us or the exception is not a NPE.  I suggest you step through the code and your logic and fingure out what is wrong, and if you find a problem you can't solve please give us the complete information. 

Contributor
Posts: 17
Registered: ‎05-12-2011
My Device: 9630
My Carrier: Developer

Re: Get Direction on Touchevent.move

if (TouchEvent.GESTURE==message.getEvent()) {

TouchGesture touchgesture=message.getGesture();

if (touchgesture!=null){if (touchgesture.getEvent()==TouchGesture.SWIPE) {switch (touchgesture.getSwipeDirection()) {
case TouchGesture.SWIPE_WEST:

System.out.println("West");break;

case TouchGesture.SWIPE_EAST:
System.out.println("East");break;

default:break;}}}

 

 

This code is work 

 

but

when

if (TouchEvent.MOVE==message.getEvent()) 

use this then problem is come compiler not inside the loop

Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Get Direction on Touchevent.move

I think Gesture is calling before theMove is captured. So try removing/commenting Gesture code or try with return super.touchEvent() instead of break in the switch case of Gesture.
Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get Direction on Touchevent.move

If you wish to process the move instead of the gesture, then you can process all the points that were touched using code like the following

 

                if (eventType == TouchEvent.MOVE) {
                    //Get the move points
                    int pointsSize = message.getMovePointsSize();
                    int[] xPoints = new int[pointsSize];
                    int[] yPoints = new int[pointsSize];

 

This code is from the Signature Capture demo.

 

I think if you process the Gesture (which is basically the BlackBerry trying to make it easy for you to detect swipes without going through all the points yourself) then you can ignore MOVE. 

Contributor
Posts: 17
Registered: ‎05-12-2011
My Device: 9630
My Carrier: Developer

Re: Get Direction on Touchevent.move

By using this code how to take the the left write direction

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get Direction on Touchevent.move

AFAIK, you can use the Gesture to detect this, so you do not need to use the datapoints supplied by MOVE.  So why are you bothering with this?

 

If you really want to do this, then get the array variables as in my code, then take the first x and the last x and compare them.  If the last x is less than the first one, the user has moved his/finger to the left, and vice versa.  So you can move your Fields appropriately.