diff options
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PointerTracker.java')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index d5986aa32..f7a0d97ae 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -74,6 +74,8 @@ public class PointerTracker { } public interface TimerProxy { + public void startKeyTypedTimer(long delay); + public boolean isTyping(); public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker); public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker); public void cancelLongPressTimer(); @@ -81,6 +83,10 @@ public class PointerTracker { public static class Adapter implements TimerProxy { @Override + public void startKeyTypedTimer(long delay) {} + @Override + public boolean isTyping() { return false; } + @Override public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {} @Override public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker) {} @@ -98,6 +104,7 @@ public class PointerTracker { private static int sLongPressKeyTimeout; private static int sLongPressShiftKeyTimeout; private static int sLongPressSpaceKeyTimeout; + private static int sIgnoreSpecialKeyTimeout; private static int sTouchNoiseThresholdMillis; private static int sTouchNoiseThresholdDistanceSquared; @@ -168,7 +175,9 @@ public class PointerTracker { sLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout); sLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout); sLongPressSpaceKeyTimeout = res.getInteger(R.integer.config_long_press_space_key_timeout); + sIgnoreSpecialKeyTimeout = res.getInteger(R.integer.config_ignore_special_key_timeout); sTouchNoiseThresholdMillis = res.getInteger(R.integer.config_touch_noise_threshold_millis); + final float touchNoiseThresholdDistance = res.getDimension( R.dimen.config_touch_noise_threshold_distance); sTouchNoiseThresholdDistanceSquared = (int)( @@ -233,8 +242,9 @@ public class PointerTracker { if (DEBUG_LISTENER) Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey); - if (ignoreModifierKey) + if (ignoreModifierKey) { return false; + } if (key.isEnabled()) { mListener.onPress(key.mCode, withSliding); final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; @@ -254,15 +264,17 @@ public class PointerTracker { + " ignoreModifier=" + ignoreModifierKey); if (ignoreModifierKey) return; - if (key.isEnabled()) + if (key.isEnabled()) { mListener.onCodeInput(primaryCode, keyCodes, x, y); + } } private void callListenerOnTextInput(Key key) { if (DEBUG_LISTENER) Log.d(TAG, "onTextInput: text=" + key.mOutputText); - if (key.isEnabled()) + if (key.isEnabled()) { mListener.onTextInput(key.mOutputText); + } } // Note that we need primaryCode argument because the keyboard may in shifted state and the @@ -274,8 +286,9 @@ public class PointerTracker { + withSliding + " ignoreModifier=" + ignoreModifierKey); if (ignoreModifierKey) return; - if (key.isEnabled()) + if (key.isEnabled()) { mListener.onRelease(primaryCode, withSliding); + } } private void callListenerOnCancelInput() { @@ -343,7 +356,7 @@ public class PointerTracker { private void setPressedKeyGraphics(int keyIndex) { final Key key = getKey(keyIndex); if (key != null && key.isEnabled()) { - if (isKeyPreviewRequired(key)) { + if (!key.noKeyPreview()) { mDrawingProxy.showKeyPreview(keyIndex, this); } key.onPressed(); @@ -351,15 +364,6 @@ public class PointerTracker { } } - // The modifier key, such as shift key, should not show its key preview. - private static boolean isKeyPreviewRequired(Key key) { - final int code = key.mCode; - if (isModifierCode(code) || code == Keyboard.CODE_DELETE - || code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE) - return false; - return true; - } - public int getLastX() { return mLastX; } @@ -656,7 +660,7 @@ public class PointerTracker { private void startRepeatKey(int keyIndex) { final Key key = getKey(keyIndex); - if (key != null && key.mRepeatable) { + if (key != null && key.isRepeatable()) { onRepeatKey(keyIndex); mTimerProxy.startKeyRepeatTimer(sDelayBeforeKeyRepeatStart, keyIndex, this); mIsRepeatableKey = true; @@ -709,15 +713,21 @@ public class PointerTracker { } } - private void detectAndSendKey(int index, int x, int y) { - final Key key = getKey(index); + private void detectAndSendKey(int keyIndex, int x, int y) { + final Key key = getKey(keyIndex); if (key == null) { callListenerOnCancelInput(); return; } if (key.mOutputText != null) { - callListenerOnTextInput(key); + final boolean ignoreText = key.ignoreWhileTyping() && mTimerProxy.isTyping(); + if (!ignoreText) { + callListenerOnTextInput(key); + } callListenerOnRelease(key, key.mCode, false); + if (!ignoreText) { + mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); + } } else { int code = key.mCode; final int[] codes = mKeyDetector.newCodeArray(); @@ -737,8 +747,16 @@ public class PointerTracker { codes[1] = codes[0]; codes[0] = code; } - callListenerOnCodeInput(key, code, codes, x, y); + final boolean ignoreCode = key.ignoreWhileTyping() && mTimerProxy.isTyping(); + if (!ignoreCode) { + // TODO: It might be useful to register the nearest key code in codes[] instead of + // just ignoring. + callListenerOnCodeInput(key, code, codes, x, y); + } callListenerOnRelease(key, code, false); + if (!key.ignoreWhileTyping() && !isModifierCode(code)) { + mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); + } } } |