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.
1) Is event.getActionMasked()
same as event.getAction() & MotionEvent.ACTION_MASK
(they appear to be on Samsung S2 and HTC Desire)
2) Will the two above commands give all the information and more than that event.getAction()
alone will, or is it different.
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.
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()& MotionEvent.ACTION_MASK))==0)
pointer0down=false;
if (event.getPointerId((event.getActionIndex()& MotionEvent.ACTION_MASK))==1)
pointer1down=false;
}
if (event.getActionMasked()==MotionEvent.ACTION_DOWN
||event.getActionMasked()==MotionEvent.ACTION_POINTER_DOWN)
{
if (event.getPointerId((event.getActionIndex()& MotionEvent.ACTION_MASK))==0)
pointer0down=true;
if (event.getPointerId((event.getActionIndex()& 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;
}