diff options
author | 2010-12-17 14:13:01 +0900 | |
---|---|---|
committer | 2010-12-21 23:46:15 +0900 | |
commit | baf83886be975d804eda3e1519b7255026e5163e (patch) | |
tree | af416dad800e01f2e8b23e51bfe637fa68f20703 /java/src | |
parent | 1d7d9664a9850a7c8043651e4b7a055ec034f571 (diff) | |
download | latinime-baf83886be975d804eda3e1519b7255026e5163e.tar.gz latinime-baf83886be975d804eda3e1519b7255026e5163e.tar.xz latinime-baf83886be975d804eda3e1519b7255026e5163e.zip |
Filter out too short noisy touch events
Bug: 3294017
Change-Id: I1769eab1d096d16bfa9d6f23b973483ee6e7a478
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 44 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java | 9 |
2 files changed, 47 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 552ab528b..c07035d62 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -56,6 +56,9 @@ public class PointerTracker { private final boolean mHasDistinctMultitouch; private final boolean mConfigSlidingKeyInputEnabled; + private final int mTouchNoiseThresholdMillis; + private final int mTouchNoiseThresholdDistanceSquared; + private Keyboard mKeyboard; private Key[] mKeys; private int mKeyHysteresisDistanceSquared = -1; @@ -108,6 +111,11 @@ public class PointerTracker { mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start); mLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout); mLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout); + mTouchNoiseThresholdMillis = res.getInteger(R.integer.config_touch_noise_threshold_millis); + final float touchNoiseThresholdDistance = res.getDimension( + R.dimen.config_touch_noise_threshold_distance); + mTouchNoiseThresholdDistanceSquared = (int)( + touchNoiseThresholdDistance * touchNoiseThresholdDistance); } public void setOnKeyboardActionListener(KeyboardActionListener listener) { @@ -253,6 +261,24 @@ public class PointerTracker { if (DEBUG_EVENT) printTouchEvent("onDownEvent:", x, y, eventTime); + // TODO: up-to-down filter, if (down-up) is less than threshold, removeMessage(UP, this) in + // Handler, and just ignore this down event. + // TODO: down-to-up filter, just record down time. do not enqueue pointer now. + + // Naive up-to-down noise filter. + final long deltaT = eventTime - mKeyState.getUpTime(); + if (deltaT < mTouchNoiseThresholdMillis) { + final int dx = x - mKeyState.getLastX(); + final int dy = y - mKeyState.getLastY(); + final int distanceSquared = (dx * dx + dy * dy); + if (distanceSquared < mTouchNoiseThresholdDistanceSquared) { + Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT + + " distance=" + distanceSquared); + setAlreadyProcessed(); + return; + } + } + if (queue != null) { if (isOnModifierKey(x, y)) { // Before processing a down event of modifier key, all pointers already being @@ -264,7 +290,7 @@ public class PointerTracker { onDownEventInternal(x, y, eventTime); } - public void onDownEventInternal(int x, int y, long eventTime) { + private void onDownEventInternal(int x, int y, long eventTime) { int keyIndex = mKeyState.onDownKey(x, y, eventTime); // Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding // from modifier key, or 3) this pointer is on mini-keyboard. @@ -297,6 +323,10 @@ public class PointerTracker { if (mKeyAlreadyProcessed) return; final PointerTrackerKeyState keyState = mKeyState; + + // TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore + // this move event. Otherwise fire {@link onDownEventInternal} and continue. + final int keyIndex = keyState.onMoveKey(x, y); final Key oldKey = getKey(keyState.getKeyIndex()); if (isValidKeyIndex(keyIndex)) { @@ -342,11 +372,17 @@ public class PointerTracker { showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex()); } + // TODO: up-to-down filter, if delayed UP message is fired, invoke {@link onUpEventInternal}. + public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { if (ENABLE_ASSERTION) checkAssertion(queue); if (DEBUG_EVENT) printTouchEvent("onUpEvent :", x, y, eventTime); + // TODO: up-to-down filter, just sendDelayedMessage(UP, this) to Handler. + // TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore + // this up event. Otherwise fire {@link onDownEventInternal} and {@link onUpEventInternal}. + if (queue != null) { if (isModifier()) { // Before processing an up event of modifier key, all pointers already being @@ -374,7 +410,7 @@ public class PointerTracker { if (mKeyAlreadyProcessed) return; final PointerTrackerKeyState keyState = mKeyState; - int keyIndex = keyState.onUpKey(x, y); + int keyIndex = keyState.onUpKey(x, y, eventTime); if (isMinorMoveBounce(x, y, keyIndex)) { // Use previous fixed key index and coordinates. keyIndex = keyState.getKeyIndex(); @@ -396,10 +432,10 @@ public class PointerTracker { if (queue != null) queue.remove(this); - onCancelEventInternal(x, y, eventTime); + onCancelEventInternal(); } - private void onCancelEventInternal(int x, int y, long eventTime) { + private void onCancelEventInternal() { mHandler.cancelKeyTimers(); mHandler.cancelPopupPreview(); showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java b/java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java index b9ae03a59..8b969c70a 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java @@ -26,6 +26,7 @@ package com.android.inputmethod.keyboard; private int mStartX; private int mStartY; private long mDownTime; + private long mUpTime; // The current key index where this pointer is. private int mKeyIndex = KeyDetector.NOT_A_KEY; @@ -65,6 +66,10 @@ package com.android.inputmethod.keyboard; return mDownTime; } + public long getUpTime() { + return mUpTime; + } + public int getLastX() { return mLastX; } @@ -77,7 +82,6 @@ package com.android.inputmethod.keyboard; mStartX = x; mStartY = y; mDownTime = eventTime; - return onMoveToNewKey(onMoveKeyInternal(x, y), x, y); } @@ -98,7 +102,8 @@ package com.android.inputmethod.keyboard; return keyIndex; } - public int onUpKey(int x, int y) { + public int onUpKey(int x, int y, long eventTime) { + mUpTime = eventTime; return onMoveKeyInternal(x, y); } |