Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

touch - In Android, what is the difference between getAction() and getActionMasked() in MotionEvent?

I am confused by the two methods in Android. It seems that both methods tell you what kind of event it is, i.e., whether it is a down or up event.

When will I use which?

public void onTouchEvent(MotionEvent e)

Don't quote the documentation please, because I read it, and I don't see any parameter I can supply to either of the methods to get something different.

public final int getAction ()

and

public final int getActionMasked()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

getAction() returns a pointer id and an event (i.e., up, down, move) information.

getActionMasked() returns just an event (i.e., up, down, move) information. Other info is masked out.

For example:

getAction() returns 0x0105.
getActionMasked() will return 0x0005, which is 0x0105 && ACTION_MASK.

  1. The value of ACTION_MASK is 0xFF. It masks the following actions.
    • ACTION_DOWN 0, UP 1, MOVE 2
    • ACTION_POINTER_DOWN 5, UP 6
  2. The value of ACTION_POINTER_ID_MASK is 0xFF00. It masked the pointer ID from following deprecated constants.
    • ACTION_POINTER_1_DOWN 0x0005
    • ACTION_POINTER_2_DOWN 0x0105
    • ACTION_POINTER_3_DOWN 0x0205
    • ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...