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: 59
Registered: ‎05-06-2012
My Device: Blackberry torch 9850
Accepted Solution

pinch touch gesture event

My code :

int _lastX= -1;
int _lastY= -1;
protected boolean touchEvent(TouchEvent message)
{
// Retrieve the new x and y touch positions
int x = message.getX(1);
int y = message.getY(1);

boolean isGesture= false;
int eventCode = message.getEvent();

if(eventCode == TouchEvent.DOWN)
{
// If this event is followed by a move event we'll need
// to know the starting point.
_lastX = x;
_lastY = y;

}

if(eventCode == TouchEvent.GESTURE)
{
TouchGesture ges= message.getGesture();
int gesEventCode= ges.getEvent();
if(gesEventCode == TouchGesture.PINCH_END || gesEventCode == TouchGesture.PINCH_UPDATE){
isGesture= true;

float pinchM= ges.getPinchMagnitude();
//-Zoom out.
if( pinchM< 0 ){_renderer.zoom-= pinchM/2.0f;}
//-Zoom in.
if(pinchM> 0 ){_renderer.zoom+= pinchM/2.0f;}
}

}
if(!isGesture){
if(eventCode == TouchEvent.MOVE)
{
_renderer.isAlt= true;

// Move Point calculation
int XmoveSize= x -_lastX;
int YmoveSize= y - _lastY;
if(XmoveSize< 0){_renderer.rotateLX();}
if(XmoveSize> 0){_renderer.rotateRX();}

if(YmoveSize< 0){_renderer.rotateDZ();}
if(YmoveSize> 0){_renderer.rotateUZ();}


_lastX = x;
_lastY = y;

}

}

if(eventCode == TouchEvent.UP){
_renderer.isAlt= false;
// We have lost contact with the screen, reset the last x and y
_lastX = -1;
_lastY = -1;
}
return true;
}
________________________________________________________

Hello,
I took the above code from the touchScreen blackberry sample project and modified a bit to accept pinch gesture.
Now I get one issue with it, the method getPinchmagnitude() always return a positive value so, how to be able to know if this was a pinch out or a pinch in event.

Any answer will help.
Thank.
Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: pinch touch gesture event

Note something I have tried, but reading the API, you need to retain the PINCH_BEGIN value and action as to the extent of the change between that and your currently detected PINCH Gesture magnitude.  Remember that users can PINCH in and out in the one gesture (hence the use of PINCH_UPDATE), there is not just a beginning and end value. 

Developer
Posts: 59
Registered: ‎05-06-2012
My Device: Blackberry torch 9850

Re: pinch touch gesture event

Ok, i will try.
And thank for the reply Peter.
Developer
Posts: 253
Registered: ‎08-14-2010
My Device: Not Specified

Re: pinch touch gesture event

Hi peter,

 

could you please explain your answer bit further . I am not getting the idea.

 

Many Thanks