Created
September 20, 2011 03:31
-
-
Save linuxmotion/1228252 to your computer and use it in GitHub Desktop.
Android MotionEvent dumper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Show an event in the LogCat view, for debugging */ | |
private void dumpEvent(MotionEvent event) { | |
String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" , | |
"POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" }; | |
StringBuilder sb = new StringBuilder(); | |
int action = event.getAction(); | |
int actionCode = action & MotionEvent.ACTION_MASK; | |
sb.append("event ACTION_" ).append(names[actionCode]); | |
if (actionCode == MotionEvent.ACTION_POINTER_DOWN | |
|| actionCode == MotionEvent.ACTION_POINTER_UP) { | |
sb.append("(pid " ).append( | |
action >> MotionEvent.ACTION_POINTER_ID_SHIFT); | |
sb.append(")" ); | |
} | |
sb.append("[" ); | |
for (int i = 0; i < event.getPointerCount(); i++) { | |
sb.append("#" ).append(i); | |
sb.append("(pid " ).append(event.getPointerId(i)); | |
sb.append(")=" ).append((int) event.getX(i)); | |
sb.append("," ).append((int) event.getY(i)); | |
if (i + 1 < event.getPointerCount()) | |
sb.append(";" ); | |
} | |
sb.append("]" ); | |
Log.d(TAG, sb.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment