48

From the android doc alone I dont really understand the difference between ACTION_UP and ACTION_POINTER_UP. http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN

Basically I want to capture the event when one finger is released from the screen (even if another one may still be touching it)

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
clamp
  • 33,000
  • 75
  • 203
  • 299

2 Answers2

142

Start here if you haven't read it already: http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html

Android thinks about touch events in terms of gestures. A gesture in this sense includes all events from the first finger that touches the screen to the last finger that leaves the screen. A single gesture's entire event sequence is always sent to the same view that was picked during the initial ACTION_DOWN unless a parent intercepts the event stream for some reason. If a parent intercepts a child's event stream, the child will get ACTION_CANCEL.

If you're working with multitouch events, always use the value returned by getActionMasked() to determine the action. If you don't need multitouch or are working with an older platform version, you can ignore the ACTION_POINTER_* events.

  • ACTION_DOWN is for the first finger that touches the screen. This starts the gesture. The pointer data for this finger is always at index 0 in the MotionEvent.
  • ACTION_POINTER_DOWN is for extra fingers that enter the screen beyond the first. The pointer data for this finger is at the index returned by getActionIndex().
  • ACTION_POINTER_UP is sent when a finger leaves the screen but at least one finger is still touching it. The last data sample about the finger that went up is at the index returned by getActionIndex().
  • ACTION_UP is sent when the last finger leaves the screen. The last data sample about the finger that went up is at index 0. This ends the gesture.
  • ACTION_CANCEL means the entire gesture was aborted for some reason. This ends the gesture.
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
adamp
  • 28,862
  • 9
  • 81
  • 69
  • @adamp In my app I want to implement single finger swipe and double finger swipe. But what is happening is when I do the double finger swipe 2 actions are performed i.e., 1st which was for 1 finger swipe and 2nd which was for 2 fingers swipe.. Could you kindly check this [Question](http://stackoverflow.com/questions/34135432/motion-event-single-and-double-finger-swipe) – Prabs Dec 11 '15 at 07:36
15

I believe it stemmed from Multi-touch being added in, ACTION_UP has been in since API Level 1, but ACTION_POINTER_UP was added in API Level 5 when multi-touch was added.

The result you get will depend on which method you are calling, getAction() would return ACTION_UP whereas getActionMasked() would give ACTION_POINTER_UP but also allow you to call getActionIndex() to find out which of the multi-touch pointers has just been raised. I think this is what you want to do.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
GeekYouUp
  • 1,651
  • 11
  • 10
  • 6
    ACTION_POINTER_UP is used instead of ACTION_UP when there is still a finger on the screen – Chris Mar 04 '15 at 02:07