IAmGroot
IAmGroot

Reputation: 13865

Blackberry touchscreen event clashing

I have

    if(eventCode == TouchEvent.DOWN)
    {
        //code
    }
    if(eventCode == TouchEvent.MOVE)
    {
        //code
    }
    if(eventCode == TouchEvent.UP)
    {
        //code
    }
    if(eventCode == TouchEvent.GESTURE)
    {
        if (gestureCode == TouchGesture.PINCH_END)
        {
           //code
        }
    }

The problem is that a Pinch, fires DOWN -> GESTURE -> UP

The Events DOWN MOVE UP are used for dragging the map around.

Where as Pinch is for zooming in/out.

How can I keep them separate?

Upvotes: 0

Views: 98

Answers (1)

IAmGroot
IAmGroot

Reputation: 13865

Using PINCH_BEGIN. I set a global myMode variable that tells it its in pinch mode. So MOVE and UP Cannot fire.

And then on pinch up, reset the mode.

if(eventCode == TouchEvent.DOWN)
{
    mode = 1;
    //code
}
if(eventCode == TouchEvent.MOVE && mode == 1)
{
    //code
}
if(eventCode == TouchEvent.UP && mode == 1)
{
    mode = 0;
    //code
}
if(eventCode == TouchEvent.GESTURE)
{
    if (gestureCode == TouchGesture.PINCH_BEGIN)
   {
       mode = 2;
    }
    if (gestureCode == TouchGesture.PINCH_END)
    {
       mode = 0;
       //code

    }
}

This way for MOVE it runs :

DOWN -> MOVE -> UP

and pinch runs:

DOWN -> DOWN -> PINCH_BEGIN -> PINCH_END

(PINCH_BEGIN executes before MOVE is attempted to be called. And so is overriden by the new mode)

Upvotes: 1

Related Questions