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: 638
Registered: ‎07-02-2009
My Device: Not Specified

touchEvent.getGesture() == null on device.

Hi all,

 

I am overrideing the

 

protected boolean touchEvent(TouchEvent touchEvent)
   {

           // my logic

   }

 

to implement my custom logic. But when I tested on device, touchEvent.getGesture() returns null


so am unable to handle the events like Tap and Swipe.

 

Even though am performing TAP, SWIPE they are not recognizing.

 

Surprisingly these events are getting exectuing on a different screen.

 

Note: The major difference in overriding the touchEvent function is:

           exectuing case: overriden the function in a class extended from the screen.

           non - exectuing case: overriden the function in a class extended from Manager.

 

suggestions !!

Thanks and Regards,
PraveenGoparaju.
Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: touchEvent.getGesture() == null on device.

You sure that it is a Gesture that is occuring? touchEvent.getEvent() == TouchEvent.GESTURE. I've had no trouble with this when used on Screens, Fields, and Managers.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: touchEvent.getGesture() == null on device.

Are you processing DOWN, UP and other events?  If you do, make sure to propagate them to super.touchEvent even if you think you've done all that's needed!  That TouchEvent.DOWN event might have been the beginning of your gesture, but if you don't let the system register it the whole gesture will not be detected.

 

I'm doing it like this:

 

    protected boolean touchEvent(TouchEvent message) {
        _scrollingTask = QScrollingTask.getInstance();
        int x = message.getX(1);
        int y = message.getY(1);
        int event = message.getEvent();
        switch (event) {
        case TouchEvent.CLICK:
            // don't do anything - it will call navigationClick
            break;
        case TouchEvent.UNCLICK:
            // don't do anything - it will call navigationUnclick
            break;
        case TouchEvent.DOWN:
            // process DOWN here
            break;
        case TouchEvent.UP:
            // process UP here
            break;
        case TouchEvent.MOVE:
            // sample processing - make your own if needed
            int[] x_points;
            int[] y_points;
            int[] time_points;
            int size = message.getMovePointsSize();
            x_points = new int[size];
            y_points = new int[size];
            time_points = new int[size];
            message.getMovePoints(1, x_points, y_points, time_points);
            // process that MOVE here!
            break;
        case TouchEvent.CANCEL:
            // something happened in the middle of your touch
            break;
        case TouchEvent.GESTURE:
            // process your gestures here
            break;
        }
        return super.touchEvent(message);
    }

 As you can see, all switch branches break to super.touchEvent().  If you don't want BlackBerry to register some of them (most reasonable for moves and gestures), return true - but make sure you know exactly what you are doing.

 

I do have DOWN and UP processing, as well as CANCEL.  Still I let super.touchEvent do its job as well.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: touchEvent.getGesture() == null on device.

Ok thanks for the updates!!

 

I will handle all other clicks.

 

I will let you know once checked on the device.

Thanks and Regards,
PraveenGoparaju.
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: touchEvent.getGesture() == null on device.

You could also check for the gestures first in the switch since you know they are composed of simple events. That way if you don't need to do anymore processing after the gesture you can just return true instead of super.touchEvent(message). This will especially help with custom fields, as i have found that some fields activate on more than just the CLICK and DOWN events.