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
Developer
Posts: 34
Registered: ‎09-24-2009
My Device: Not Specified

How to handle TouchGesture events

Hi,

 

In my project, I need to pan over an image when the image is shown in fullscreen. I searched in the forum for any sample code. But couldn't find any. Can somebody suggest me how to handle panning and other TouchGesture events.

 

 

Thanks in advance for your help.

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to handle TouchGesture events

  You can handle the touch events in storm in the following way:

protected boolean touchEvent(TouchEvent event)
{
try
{
// first get the event code...
int eventCode = event.getEvent();

int x = event.getX(1);
int y = event.getY(1);

// If the event code is the gesture event then

// check which kind of gesture is this
switch (eventCode)
{
// This is for the Touch Event, got from the source editor...
case TouchEvent.CLICK:
//handle click event
//notifyClickEvent(x, y);
break;
case TouchEvent.UNCLICK:
//handle unclick event
//notifyUnclickEvent(x,y);
break;
// This one is for Gesture....
case TouchEvent.GESTURE:
gesture = event.getGesture();
gestureEvent = gesture.getEvent();
// Now switch between the different possible gestures
// to detect which one
switch (gestureEvent)
{
case TouchGesture.SWIPE:
{
// Get the gesture direction
// and the magnitude here...
swipeMagnitude = gesture.getSwipeMagnitude();
gestureDirection = gesture.getSwipeDirection();
switch (gestureDirection)
{
//handle gesture event depending on direction
case TouchGesture.SWIPE_NORTH:
swipeMagnitude = gesture.getSwipeMagnitude();
//notifyNorthSwipeEvent(swipeMagnitude);
break;
case TouchGesture.SWIPE_SOUTH:
swipeMagnitude = gesture.getSwipeMagnitude();
//notifySouthSwipeEvent(swipeMagnitude);
break;
case TouchGesture.SWIPE_EAST:
swipeMagnitude = gesture.getSwipeMagnitude();
//notifyEastSwipeEvent(swipeMagnitude);
break;
case TouchGesture.SWIPE_WEST:
swipeMagnitude = gesture.getSwipeMagnitude();
//notifyWestSwipeEvent(swipeMagnitude);
break;
}
}
break;
case TouchGesture.HOVER:
break;
case TouchGesture.TAP:
//handle tap event
//notifyTapEvent(x, y);
break;
}
break;
// This one for the Move on the touch screen...
case TouchEvent.MOVE:
//handle move event
//moveScreen(event.getX(1), event.getY(1), event.getMovePointsSize());
break;
case TouchEvent.UP:
//moveUp();
break;
case TouchEvent.DOWN:
//moveDown();
break;
}
}
catch (Exception ex)
{
return false;
}
return true;
}

 

Regards

Bikas 

Developer
Posts: 34
Registered: ‎09-24-2009
My Device: Not Specified

Re: How to handle TouchGesture events

Thanks Bikas, I tried your code. Based on that I could find more information at below thread, which helped me a lot

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=375&query.id=3217...

 

 

Thanks,

Ravi