Home » Android » Understanding Android Touch Event , onTouchEvent ( Motion Event )

Understanding Android Touch Event , onTouchEvent ( Motion Event )

When we just touched the touchscreen and printed the logs in application using “onTouchEvent” it printed following logs,

onTouchEvent:  MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=64.92398, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=795415, downTime=795415, deviceId=6, source=0x1002, displayId=0, eventId=939187150 }


onTouchEvent:  MotionEvent { action=ACTION_POINTER_DOWN(1), actionButton=0, id[0]=0, x[0]=64.92398, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=134.8421, y[1]=209.46985, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=795415, downTime=795415, deviceId=6, source=0x1002, displayId=0, eventId=304474425 }


onTouchEvent:  MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=64.92398, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=135.84094, y[1]=209.46985, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=795450, downTime=795415, deviceId=6, source=0x1002, displayId=0, eventId=677404928 }

onTouchEvent:  MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=64.92398, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=136.83977, y[1]=209.46985, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=795470, downTime=795415, deviceId=6, source=0x1002, displayId=0, eventId=48397247 }

onTouchEvent:  MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=64.92398, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=145.82924, y[1]=209.46985, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=795490, downTime=795415, deviceId=6, source=0x1002, displayId=0, eventId=229968023 }

onTouchEvent:  MotionEvent { action=ACTION_POINTER_UP(0), actionButton=0, id[0]=0, x[0]=64.92398, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=145.82924, y[1]=209.46985, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=795509, downTime=795415, deviceId=6, source=0x1002, displayId=0, eventId=605444067 }

onTouchEvent:  MotionEvent { action=ACTION_UP, actionButton=0, id[0]=1, x[0]=145.82924, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=795509, downTime=795415, deviceId=6, source=0x1002, displayId=0, eventId=804607639 }

As we can see, the motion event action occurred during one touch on touchscreen was of following type,

  • ACTION_DOWN – First finger touch has started, the motion contains the initial starting location.
  • ACTION_POINTER_DOWN – pointer has gone down ( Actual Touch is happened ) , This event triggered whenever the second finger touches the screen.
  • ACTION_MOVE – A change has happened during a press gesture ( Finger is moving on touchscreen )
  • ACTION_POINTER_UP – Pointer has gone up ( Second Finger is lifted from touchscreen )
  • ACTION_UP – First Finger touch has finished, the motion contains the final release location

Reference : https://developer.android.com/develop/ui/views/touch-and-input/gestures/multi#track

The other important things to understand from this motion event for multitouch screen when two fingers are active is,

id[0]=0, x[0]=64.92398, y[0]=209.46985, toolType[0]=TOOL_TYPE_FINGER
id[1]=1, x[1]=145.82924, y[1]=209.46985, toolType[1]=TOOL_TYPE_FINGER

This indicated that the touch was on multitouch touchscreen and finger 1 coordinates ( x[0] , y[0] ) were x = 64.92398 and y = 209.46985 and Finger 2 coordinates (x[1] , y[1]) were x = 145.82924 and y = 209.46985

In Android application, this log messages can be printed as,

@Override
public boolean onTouchEvent(MotionEvent event) {
         Log.d(TAG, "onTouchEvent = " + event.toString() )
}

Reference – https://medium.com/@arj.sna/multi-touch-in-android-c87031d106b3


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment