diff options
author | Dake Gu <dake@google.com> | 2013-01-18 13:26:02 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-01-18 13:26:02 -0800 |
commit | 85a06152ce9b7d3a198639eb1918a9c2a3fd34d4 (patch) | |
tree | f0ff7128d05c4e0250ecfae6309090c6e4a814a7 /core/java/android/view | |
parent | 00ef2a3622baa477d7dfdd8df7d68bab84008b4d (diff) | |
parent | fe88f1be3d197987a874f6c29fefdeb11db183f6 (diff) | |
download | frameworks_base-85a06152ce9b7d3a198639eb1918a9c2a3fd34d4.zip frameworks_base-85a06152ce9b7d3a198639eb1918a9c2a3fd34d4.tar.gz frameworks_base-85a06152ce9b7d3a198639eb1918a9c2a3fd34d4.tar.bz2 |
am fe88f1be: Merge "Fix bug of SimulatedTrackball" into jb-mr1-aah-dev
* commit 'fe88f1be3d197987a874f6c29fefdeb11db183f6':
Fix bug of SimulatedTrackball
Diffstat (limited to 'core/java/android/view')
-rw-r--r-- | core/java/android/view/SimulatedDpad.java (renamed from core/java/android/view/SimulatedTrackball.java) | 67 | ||||
-rw-r--r-- | core/java/android/view/ViewRootImpl.java | 13 |
2 files changed, 43 insertions, 37 deletions
diff --git a/core/java/android/view/SimulatedTrackball.java b/core/java/android/view/SimulatedDpad.java index 4ab557a..0a37fdd 100644 --- a/core/java/android/view/SimulatedTrackball.java +++ b/core/java/android/view/SimulatedDpad.java @@ -28,15 +28,15 @@ import android.os.UserHandle; import android.util.Log; /** - * This class creates trackball events from touchpad events. + * This class creates DPAD events from touchpad events. * * @see ViewRootImpl */ //TODO: Make this class an internal class of ViewRootImpl.java -class SimulatedTrackball { +class SimulatedDpad { - private static final String TAG = "SimulatedTrackball"; + private static final String TAG = "SimulatedDpad"; // Maximum difference in milliseconds between the down and up of a touch // event for it to be considered a tap @@ -97,7 +97,7 @@ class SimulatedTrackball { // How quickly the repeated events die off private float mFlickDecay; - public SimulatedTrackball(Context context) { + public SimulatedDpad(Context context) { mDistancePerTick = SystemProperties.getInt("persist.vr_dist_tick", 64); mDistancePerTickSquared = mDistancePerTick * mDistancePerTick; mMaxRepeatDelay = SystemProperties.getInt("persist.vr_repeat_delay", 300); @@ -140,7 +140,11 @@ class SimulatedTrackball { } }; - public void updateTrackballDirection(ViewRootImpl viewroot, MotionEvent event) { + public void updateTouchPad(ViewRootImpl viewroot, MotionEvent event, + boolean synthesizeNewKeys) { + if (!synthesizeNewKeys) { + mHandler.removeMessages(MSG_FLICK); + } // Store what time the touchpad event occurred final long time = SystemClock.uptimeMillis(); switch (event.getAction()) { @@ -159,8 +163,9 @@ class SimulatedTrackball { mEdgeSwipePossible = true; } // Clear any flings - mHandler.removeMessages(MSG_FLICK); - + if (synthesizeNewKeys) { + mHandler.removeMessages(MSG_FLICK); + } break; case MotionEvent.ACTION_MOVE: // Determine whether the move is slop or an intentional move @@ -226,12 +231,16 @@ class SimulatedTrackball { while (dominantAxis * dominantAxis > mDistancePerTickSquared) { repeatCount++; dominantAxis -= sign * mDistancePerTick; - viewroot.enqueueInputEvent(new KeyEvent(time, time, - KeyEvent.ACTION_DOWN, key, 0, event.getMetaState(), - event.getDeviceId(), 0, KeyEvent.FLAG_FALLBACK, event.getSource())); - viewroot.enqueueInputEvent(new KeyEvent(time, time, - KeyEvent.ACTION_UP, key, 0, event.getMetaState(), - event.getDeviceId(), 0, KeyEvent.FLAG_FALLBACK, event.getSource())); + if (synthesizeNewKeys) { + viewroot.enqueueInputEvent(new KeyEvent(time, time, + KeyEvent.ACTION_DOWN, key, 0, event.getMetaState(), + event.getDeviceId(), 0, KeyEvent.FLAG_FALLBACK, + event.getSource())); + viewroot.enqueueInputEvent(new KeyEvent(time, time, + KeyEvent.ACTION_UP, key, 0, event.getMetaState(), + event.getDeviceId(), 0, KeyEvent.FLAG_FALLBACK, + event.getSource())); + } } // Save new axis values mAccumulatedX = isXAxis ? dominantAxis : 0; @@ -244,18 +253,16 @@ class SimulatedTrackball { break; case MotionEvent.ACTION_UP: if (time - mLastTouchPadStartTimeMs < MAX_TAP_TIME && mAlwaysInTapRegion) { - // Trackball Down - MotionEvent trackballEvent = MotionEvent.obtain(mLastTouchPadStartTimeMs, time, - MotionEvent.ACTION_DOWN, 0, 0, 0, 0, event.getMetaState(), - 10f, 10f, event.getDeviceId(), 0); - trackballEvent.setSource(InputDevice.SOURCE_TRACKBALL); - viewroot.enqueueInputEvent(trackballEvent); - // Trackball Release - trackballEvent = MotionEvent.obtain(mLastTouchPadStartTimeMs, time, - MotionEvent.ACTION_UP, 0, 0, 0, 0, event.getMetaState(), - 10f, 10f, event.getDeviceId(), 0); - trackballEvent.setSource(InputDevice.SOURCE_TRACKBALL); - viewroot.enqueueInputEvent(trackballEvent); + if (synthesizeNewKeys) { + viewroot.enqueueInputEvent(new KeyEvent(mLastTouchPadStartTimeMs, time, + KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, + event.getMetaState(), event.getDeviceId(), 0, + KeyEvent.FLAG_FALLBACK, event.getSource())); + viewroot.enqueueInputEvent(new KeyEvent(mLastTouchPadStartTimeMs, time, + KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, + event.getMetaState(), event.getDeviceId(), 0, + KeyEvent.FLAG_FALLBACK, event.getSource())); + } } else { float xMoveSquared = mLastMoveX * mLastMoveX; float yMoveSquared = mLastMoveY * mLastMoveY; @@ -267,10 +274,12 @@ class SimulatedTrackball { mLastSource = event.getSource(); mLastMetaState = event.getMetaState(); - Message message = Message.obtain(mHandler, MSG_FLICK, - mKeySendRateMs, mLastKeySent, viewroot); - message.setAsynchronous(true); - mHandler.sendMessageDelayed(message, mKeySendRateMs); + if (synthesizeNewKeys) { + Message message = Message.obtain(mHandler, MSG_FLICK, + mKeySendRateMs, mLastKeySent, viewroot); + message.setAsynchronous(true); + mHandler.sendMessageDelayed(message, mKeySendRateMs); + } } } mEdgeSwipePossible = false; diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 9ef9d01..58e6fbe 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -144,7 +144,7 @@ public final class ViewRootImpl implements ViewParent, final TrackballAxis mTrackballAxisX = new TrackballAxis(); final TrackballAxis mTrackballAxisY = new TrackballAxis(); - final SimulatedTrackball mSimulatedTrackball; + final SimulatedDpad mSimulatedDpad; int mLastJoystickXDirection; int mLastJoystickYDirection; @@ -392,7 +392,7 @@ public final class ViewRootImpl implements ViewParent, PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); mAttachInfo.mScreenOn = powerManager.isScreenOn(); loadSystemProperties(); - mSimulatedTrackball = new SimulatedTrackball(context); + mSimulatedDpad = new SimulatedDpad(context); } /** @@ -3452,8 +3452,7 @@ public final class ViewRootImpl implements ViewParent, if (isJoystick) { updateJoystickDirection(event, false); } else if (isTouchPad) { - //Convert TouchPad motion into a TrackBall event - mSimulatedTrackball.updateTrackballDirection(this, event); + mSimulatedDpad.updateTouchPad(this, event, false); } return EVENT_NOT_HANDLED; } @@ -3463,8 +3462,7 @@ public final class ViewRootImpl implements ViewParent, if (isJoystick) { updateJoystickDirection(event, false); } else if (isTouchPad) { - //Convert TouchPad motion into a TrackBall event - mSimulatedTrackball.updateTrackballDirection(this, event); + mSimulatedDpad.updateTouchPad(this, event, false); } return EVENT_HANDLED; } @@ -3476,8 +3474,7 @@ public final class ViewRootImpl implements ViewParent, return EVENT_HANDLED; } if (isTouchPad) { - //Convert TouchPad motion into a TrackBall event - mSimulatedTrackball.updateTrackballDirection(this, event); + mSimulatedDpad.updateTouchPad(this, event, true); return EVENT_HANDLED; } return EVENT_NOT_HANDLED; |