8

The documentation say this about that:

A gesture starts with a motion event with ACTION_DOWN that provides the location of the first pointer down. As each additional pointer that goes down or up, the framework will generate a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP accordingly.

So i have done the override of onTouchEvent function in my activity:

@Override
public boolean onTouchEvent(MotionEvent MEvent) 
{

    motionaction = MEvent.getAction();

    if(motionaction == MotionEvent.ACTION_DOWN)
    {
        System.out.println("DEBUG MESSAGE POINTER1 " + MEvent.getActionIndex() );
    }

    if(motionaction == MotionEvent.ACTION_POINTER_DOWN)
    {
        System.out.println("DEBUG MESSAGE POINTER2 "  + MEvent.getActionIndex() );
    }

}

Unfortunately the second if is never entered. The activity contains 2 view with 2 OnTouchListener, i know that onTouchEvent is called only if the view of the activity don't consume the event so i tried to return false in the listener and in that way i can recognize only the first finger touch but this avoid the listener to receive the ACTION_UP event and don't allow me to recognize the second finger touch. I also tried to return true in the listener but after manually invoke the onTouchEvent function but this allow me to recognize only the first finger touch too.

What's wrong in my code ?

1 Answer 1

20

I believe your code is missing the masking operation like:

switch (motionaction & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
}

This code should be able to check for ACTION_POINTER_DOWN.

Good luck & tell us what happens.

Tommy Kwee

8
  • Yes this is the problem. Adding the 'and' with ACTION_MASK solved the problem. What make me pissed off is that in the official documentation don't say anything about that.
    – Bemipefe
    Commented Jul 7, 2012 at 10:42
  • 1
    Bernipefe, I feel for you sir. Anyone can make a mistake in a documentation. This one is probably a common error because sometimes you don't need to mask. My only suggestion for next time is to use the debugger to see what values are incoming, and see if any of the values are what you expected. Good luck to another Android fan! Commented Jul 7, 2012 at 17:15
  • I can grab the ACTION_POINTER_UP and ACTION_POINTER_DOWN but i can't find how to grab ACTION_MOVE. I can grab it in a single finger mode in the view listener but when i put the second finger on the screen the only thing that i can grup from the onTouchEvent method is the UP and DOWN and not the MOVE action. How can fix it ?
    – Bemipefe
    Commented Jul 15, 2012 at 17:17
  • 1
    As stated in document link developer.android.com/reference/android/view/… , there is no masking for this event value ACTION_MOVE. Between ACTION_MOVE, ACTION_UP, and ACTION_DOWN, there is no masking. When you check for ACTION_POINTER_DOWN, there is masking. Yeah...I admit I just noticed this. I m sure you can handle this confusion in code. Good luck again. Commented Jul 16, 2012 at 6:20
  • Ok not masking let me to receive the ACTION_MOVE action. But now if i put 2 finger in the view what if i want to receive the movement of one pointer only. The function getActionIndex() only work with ACTION_POINTER_UP and ACTION_POINTER_DOWN. Thanks in advance.
    – Bemipefe
    Commented Jul 19, 2012 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.