diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-03-09 18:27:16 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-03-09 18:27:16 -0800 |
commit | 06a0c9f5ee1f1c51607446f29ffb9697fa95e549 (patch) | |
tree | 6a28972d666a7c3345037272c0665f6a8445ecf5 /core/java/com | |
parent | 7fd981598ed0ec275d6da27c71e5e6c9db854e82 (diff) | |
parent | 696e66e44b89ca812137a31a1eab09bb8e84aa95 (diff) | |
download | frameworks_base-06a0c9f5ee1f1c51607446f29ffb9697fa95e549.zip frameworks_base-06a0c9f5ee1f1c51607446f29ffb9697fa95e549.tar.gz frameworks_base-06a0c9f5ee1f1c51607446f29ffb9697fa95e549.tar.bz2 |
Merge "Make PointerLocationView also log generic motions and some keys. (DO NOT MERGE)" into honeycomb-mr1
Diffstat (limited to 'core/java/com')
-rw-r--r-- | core/java/com/android/internal/widget/PointerLocationView.java | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java index 5ac903d..076a1cb 100644 --- a/core/java/com/android/internal/widget/PointerLocationView.java +++ b/core/java/com/android/internal/widget/PointerLocationView.java @@ -23,6 +23,7 @@ import android.graphics.RectF; import android.graphics.Paint.FontMetricsInt; import android.util.Log; import android.view.InputDevice; +import android.view.KeyEvent; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; @@ -97,7 +98,8 @@ public class PointerLocationView extends View { public PointerLocationView(Context c) { super(c); - setFocusable(true); + setFocusableInTouchMode(true); + mVC = ViewConfiguration.get(c); mTextPaint = new Paint(); mTextPaint.setAntiAlias(true); @@ -505,22 +507,69 @@ public class PointerLocationView extends View { @Override public boolean onTouchEvent(MotionEvent event) { addPointerEvent(event); + + if (event.getAction() == MotionEvent.ACTION_DOWN && !isFocused()) { + requestFocus(); + } return true; } @Override public boolean onGenericMotionEvent(MotionEvent event) { - if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { + final int source = event.getSource(); + if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { addPointerEvent(event); + } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + Log.i(TAG, "Joystick: " + event); + } else if ((source & InputDevice.SOURCE_CLASS_POSITION) != 0) { + Log.i(TAG, "Position: " + event); + } else { + Log.i(TAG, "Generic: " + event); + } + return true; + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (shouldLogKey(keyCode)) { + final int repeatCount = event.getRepeatCount(); + if (repeatCount == 0) { + Log.i(TAG, "Key Down: " + event); + } else { + Log.i(TAG, "Key Repeat #" + repeatCount + ": " + event); + } return true; } - return super.onGenericMotionEvent(event); + return super.onKeyDown(keyCode, event); + } + + @Override + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (shouldLogKey(keyCode)) { + Log.i(TAG, "Key Up: " + event); + return true; + } + return super.onKeyUp(keyCode, event); + } + + private static boolean shouldLogKey(int keyCode) { + switch (keyCode) { + case KeyEvent.KEYCODE_DPAD_UP: + case KeyEvent.KEYCODE_DPAD_DOWN: + case KeyEvent.KEYCODE_DPAD_LEFT: + case KeyEvent.KEYCODE_DPAD_RIGHT: + case KeyEvent.KEYCODE_DPAD_CENTER: + return true; + default: + return KeyEvent.isGamepadButton(keyCode) + || KeyEvent.isModifierKey(keyCode); + } } @Override public boolean onTrackballEvent(MotionEvent event) { Log.i(TAG, "Trackball: " + event); - return super.onTrackballEvent(event); + return true; } // HACK |