Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid multitouch and getActionMasked()
    text
    copied!<p>I have a some small questions to do with the masking of touch events. I have read many things on here and elsewhere but am still a little confused with parts. </p> <p>1) Is <code>event.getActionMasked()</code> same as <code>event.getAction() &amp; MotionEvent.ACTION_MASK</code> (they appear to be on Samsung S2 and HTC Desire)</p> <p>2) Will the two above commands give all the information and more than that <code>event.getAction()</code> alone will, or is it different.</p> <p>3) I have written a peice of code which simple says where is being touch and with which pointerId, or if the pointer is not in use (only written for two touches at the moment). It seems to work correctly on the devices mention above, however I know how some devices can act very differently if not done absolutely correct. I am therefore wondering if the following is correct and will behave on all devices.</p> <pre><code>boolean pointer0down=false, pointer1down=false; String st="", str0 ="", str1 =""; public boolean onTouchEvent( MotionEvent event ) { if (event.getActionMasked()==MotionEvent.ACTION_UP ||event.getActionMasked()==MotionEvent.ACTION_POINTER_UP ||event.getActionMasked()==MotionEvent.ACTION_CANCEL) { if (event.getPointerId((event.getActionIndex()&amp; MotionEvent.ACTION_MASK))==0) pointer0down=false; if (event.getPointerId((event.getActionIndex()&amp; MotionEvent.ACTION_MASK))==1) pointer1down=false; } if (event.getActionMasked()==MotionEvent.ACTION_DOWN ||event.getActionMasked()==MotionEvent.ACTION_POINTER_DOWN) { if (event.getPointerId((event.getActionIndex()&amp; MotionEvent.ACTION_MASK))==0) pointer0down=true; if (event.getPointerId((event.getActionIndex()&amp; MotionEvent.ACTION_MASK))==1) pointer1down=true; } if (pointer0down) str0="\tx: " + event.getX(0) + "\ty: "+event.getY(0); else str0="\tNot down"; if (pointer1down ) str1="\tx: " + event.getX(1) + "\ty: "+event.getY(1); else str1="\tNot down"; st="pointer0:"+str0+"\npointer1:"+str1; return true; } </code></pre>
 

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