Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference of using MotionEvent.getAction() method

What is the difference between the two approaches below?

 int action1 = event.getAction() & MotionEvent.ACTION_MASK;

 int action2 = event.getAction();
like image 952
iCould7 Avatar asked May 09 '13 14:05

iCould7


1 Answers

The ACTION_MASK is used to separate the actual action and the pointer identifier (e.g. first finger touched, second finger touched, etc.) The first 8 bits of the value returned in getAction() is the actual action part, and so when you bitwise-AND it with the action mask (= 11111111 = 255 = 0xff), you are left with only the action and none of the pointer information.

Keep in mind here that & is used as an arithmetic operator (bitwise) and not a logical operator (single & is a perfectly valid logical operator in Java, as is &&).`

like image 130
Raghav Sood Avatar answered Oct 16 '22 19:10

Raghav Sood