Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use multitouch properly - purpose of MotionEvent.getActionIndex()?

MotionEvent's documentation states in Consistency Guarantees that: "(For touch events)... pointers go down one at a time, move around as a group and then go up one at a time or are canceled".

If I understand correctly, there are two ways one can determine the action that triggered onTouchEvent():

  • MotionEvent.getAction()
  • MotionEvent.getActionMasked() with MotionEvent.getActionIndex() (this should be used for multitouch, which is what I'm after)

Since getActionMasked() always returns just ACTION_POINTER_DOWN and ACTION_POINTER_UP, according to Consistency Guarantees there should always be just one pointer passed inside MotionEvent to onTouchEvent(), which means that MotionEvent.getActionIndex() will always return 0.

If that is so, what is the point of having MotionEvent.getActionIndex() at all? In other words: what am I missing?

UPDATE: To further clarify my question: MotionEvent.getActionMasked() returns just one action and MotionEvent.getActionIndex() tells us which pointer it applies to. Does that mean that we can't get the action for other pointers? Or if it is the same for all pointers, why specify actionIndex at all?

like image 340
johndodo Avatar asked Dec 18 '25 02:12

johndodo


1 Answers

The event ACTION_POINTER_DOWN means two or more fingers are now touching the screen, to distinguish whether it is the second or third (etc) finger you need to use getActionIndex().


Since getActionMasked() always returns just ACTION_POINTER_DOWN and ACTION_POINTER_UP

In case there is any confusion, getActionMasked() returns many more types like ACTION_DOWN, ACTION_MOVE, etc.

like image 189
Sam Avatar answered Dec 19 '25 18:12

Sam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!