Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Some background -</strong> </p> <p>The integer returned from getAction is a packed integer that encodes both the action code (e.g ACTION_DOWN) and pointer index (e.g which finger). </p> <p>For single touch, since there is only one finger involved there is no need to store the pointer index so the value is just the action code. Hence its safe to do something like <code>getAction() == ACTION_DOWN</code></p> <p>For multi touch, this comparison is incorrect b/c you have the extra pointer index in the packaged integer. You can extract the action code by doing <code>getAction() &amp; ACTION_MASK</code> and extract the pointer index by doing <code>getAction() &amp; ACTION_POINTER_INDEX_MASK</code></p> <p><strong>Now to your question -</strong> </p> <p>1: Yes. think of <strong>getActionMasked</strong> as a helper method that extract the action code bits. To extract the pointer index you have the equivalent <strong>getActionIndex</strong> helper method. Both these methods will work for single or multi touch hence they are the "safest".</p> <p>2: As explained above, getAction also encodes pointer index for multitouch</p> <p>3: there is a bug in your code. <code>event.getPointerId((event.getActionIndex() &amp; MotionEvent.ACTION_MASK))</code> is technically incorrect. Instead you should be doing <strong><code>event.getPointerId(event.getActionIndex())</code></strong>. You are getting <strong>very lucky</strong> with the incorrect logical and operator on getActionIndex which turns out to be 2 bytes and the mask is itself 2 bytes (0xff) :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload