diff options
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PointerTracker.java')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 330 |
1 files changed, 209 insertions, 121 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 4b3fe8b8b..6b4e9469f 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -19,12 +19,14 @@ package com.android.inputmethod.keyboard; import com.android.inputmethod.keyboard.KeyboardView.UIHandler; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SubtypeSwitcher; import android.content.res.Resources; import android.util.Log; import android.view.MotionEvent; import java.util.Arrays; +import java.util.List; public class PointerTracker { private static final String TAG = PointerTracker.class.getSimpleName(); @@ -36,9 +38,9 @@ public class PointerTracker { public interface UIProxy { public void invalidateKey(Key key); - public void showPreview(int keyIndex, PointerTracker tracker); + public void showKeyPreview(int keyIndex, PointerTracker tracker); + public void dismissKeyPreview(PointerTracker tracker); public boolean hasDistinctMultitouch(); - public boolean isAccessibilityEnabled(); } public final int mPointerId; @@ -48,9 +50,7 @@ public class PointerTracker { private final int mLongPressKeyTimeout; private final int mLongPressShiftKeyTimeout; - // Miscellaneous constants - private static final int NOT_A_KEY = KeyDetector.NOT_A_KEY; - + private final KeyboardView mKeyboardView; private final UIProxy mProxy; private final UIHandler mHandler; private final KeyDetector mKeyDetector; @@ -63,15 +63,12 @@ public class PointerTracker { private final int mTouchNoiseThresholdDistanceSquared; private Keyboard mKeyboard; - private Key[] mKeys; + private List<Key> mKeys; private int mKeyHysteresisDistanceSquared = -1; private int mKeyQuarterWidthSquared; private final PointerTrackerKeyState mKeyState; - // true if accessibility is enabled in the parent keyboard - private boolean mIsAccessibilityEnabled; - // true if keyboard layout has been changed. private boolean mKeyboardLayoutHasBeenChanged; @@ -87,8 +84,14 @@ public class PointerTracker { // true if sliding key is allowed. private boolean mIsAllowedSlidingKeyInput; - // pressed key - private int mPreviousKey = NOT_A_KEY; + // ignore modifier key if true + private boolean mIgnoreModifierKey; + + // TODO: Remove these hacking variables + // true if this pointer is in sliding language switch + private boolean mIsInSlidingLanguageSwitch; + private int mSpaceKeyIndex; + private final SubtypeSwitcher mSubtypeSwitcher; // Empty {@link KeyboardActionListener} private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() { @@ -106,18 +109,19 @@ public class PointerTracker { public void onSwipeDown() {} }; - public PointerTracker(int id, UIHandler handler, KeyDetector keyDetector, UIProxy proxy, - Resources res) { + public PointerTracker(int id, KeyboardView keyboardView, UIHandler handler, + KeyDetector keyDetector, UIProxy proxy) { if (proxy == null || handler == null || keyDetector == null) throw new NullPointerException(); mPointerId = id; + mKeyboardView = keyboardView; mProxy = proxy; mHandler = handler; mKeyDetector = keyDetector; mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mKeyState = new PointerTrackerKeyState(keyDetector); - mIsAccessibilityEnabled = proxy.isAccessibilityEnabled(); mHasDistinctMultitouch = proxy.hasDistinctMultitouch(); + final Resources res = mKeyboardView.getResources(); mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled); mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start); mLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout); @@ -127,20 +131,21 @@ public class PointerTracker { R.dimen.config_touch_noise_threshold_distance); mTouchNoiseThresholdDistanceSquared = (int)( touchNoiseThresholdDistance * touchNoiseThresholdDistance); + mSubtypeSwitcher = SubtypeSwitcher.getInstance(); } public void setOnKeyboardActionListener(KeyboardActionListener listener) { mListener = listener; } - public void setAccessibilityEnabled(boolean accessibilityEnabled) { - mIsAccessibilityEnabled = accessibilityEnabled; - } - // Returns true if keyboard has been changed by this callback. private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) - Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding); + Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding + + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return false; if (key.mEnabled) { mListener.onPress(key.mCode, withSliding); final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; @@ -153,9 +158,13 @@ public class PointerTracker { // Note that we need primaryCode argument because the keyboard may in shifted state and the // primaryCode is different from {@link Key#mCode}. private void callListenerOnCodeInput(Key key, int primaryCode, int[] keyCodes, int x, int y) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) Log.d(TAG, "onCodeInput: " + keyCodePrintable(primaryCode) - + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y); + + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y + + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return; if (key.mEnabled) mListener.onCodeInput(primaryCode, keyCodes, x, y); } @@ -170,8 +179,12 @@ public class PointerTracker { // Note that we need primaryCode argument because the keyboard may in shifted state and the // primaryCode is different from {@link Key#mCode}. private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) - Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding=" + withSliding); + Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding=" + + withSliding + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return; if (key.mEnabled) mListener.onRelease(primaryCode, withSliding); } @@ -182,11 +195,11 @@ public class PointerTracker { mListener.onCancelInput(); } - public void setKeyboard(Keyboard keyboard, Key[] keys, float keyHysteresisDistance) { - if (keyboard == null || keys == null || keyHysteresisDistance < 0) + public void setKeyboard(Keyboard keyboard, float keyHysteresisDistance) { + if (keyboard == null || keyHysteresisDistance < 0) throw new IllegalArgumentException(); mKeyboard = keyboard; - mKeys = keys; + mKeys = keyboard.getKeys(); mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance); final int keyQuarterWidth = keyboard.getKeyWidth() / 4; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; @@ -199,11 +212,11 @@ public class PointerTracker { } private boolean isValidKeyIndex(int keyIndex) { - return keyIndex >= 0 && keyIndex < mKeys.length; + return keyIndex >= 0 && keyIndex < mKeys.size(); } public Key getKey(int keyIndex) { - return isValidKeyIndex(keyIndex) ? mKeys[keyIndex] : null; + return isValidKeyIndex(keyIndex) ? mKeys.get(keyIndex) : null; } private static boolean isModifierCode(int primaryCode) { @@ -229,34 +242,33 @@ public class PointerTracker { return key != null && key.mCode == Keyboard.CODE_SHIFT; } + public int getKeyIndexOn(int x, int y) { + return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); + } + public boolean isSpaceKey(int keyIndex) { Key key = getKey(keyIndex); return key != null && key.mCode == Keyboard.CODE_SPACE; } - public void releaseKey() { - updateKeyGraphics(NOT_A_KEY); + public void setReleasedKeyGraphics() { + setReleasedKeyGraphics(mKeyState.getKeyIndex()); } - private void updateKeyGraphics(int keyIndex) { - int oldKeyIndex = mPreviousKey; - mPreviousKey = keyIndex; - if (keyIndex != oldKeyIndex) { - if (isValidKeyIndex(oldKeyIndex)) { - // if new key index is not a key, old key was just released inside of the key. - final boolean inside = (keyIndex == NOT_A_KEY); - mKeys[oldKeyIndex].onReleased(inside); - mProxy.invalidateKey(mKeys[oldKeyIndex]); - } - if (isValidKeyIndex(keyIndex)) { - mKeys[keyIndex].onPressed(); - mProxy.invalidateKey(mKeys[keyIndex]); - } + private void setReleasedKeyGraphics(int keyIndex) { + final Key key = getKey(keyIndex); + if (key != null) { + key.onReleased(); + mProxy.invalidateKey(key); } } - public void setAlreadyProcessed() { - mKeyAlreadyProcessed = true; + private void setPressedKeyGraphics(int keyIndex) { + final Key key = getKey(keyIndex); + if (key != null && key.mEnabled) { + key.onPressed(); + mProxy.invalidateKey(key); + } } private void checkAssertion(PointerTrackerQueue queue) { @@ -302,7 +314,7 @@ public class PointerTracker { if (DEBUG_MODE) Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT + " distance=" + distanceSquared); - setAlreadyProcessed(); + mKeyAlreadyProcessed = true; return; } } @@ -321,32 +333,33 @@ public class PointerTracker { 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, 3) this pointer is on mini-keyboard, or 4) accessibility is enabled. + // from modifier key, or 3) this pointer is on mini-keyboard. mIsAllowedSlidingKeyInput = mConfigSlidingKeyInputEnabled || isModifierInternal(keyIndex) - || mKeyDetector instanceof MiniKeyboardKeyDetector - || mIsAccessibilityEnabled; + || mKeyDetector instanceof MiniKeyboardKeyDetector; mKeyboardLayoutHasBeenChanged = false; mKeyAlreadyProcessed = false; mIsRepeatableKey = false; mIsInSlidingKeyInput = false; + mIsInSlidingLanguageSwitch = false; + mIgnoreModifierKey = false; if (isValidKeyIndex(keyIndex)) { // This onPress call may have changed keyboard layout. Those cases are detected at // {@link #setKeyboard}. In those cases, we should update keyIndex according to the new // keyboard layout. - if (callListenerOnPressAndCheckKeyboardLayoutChange(mKeys[keyIndex], false)) + if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), false)) keyIndex = mKeyState.onDownKey(x, y, eventTime); - } - if (isValidKeyIndex(keyIndex)) { - // Accessibility disables key repeat because users may need to pause on a key to hear - // its spoken description. - if (mKeys[keyIndex].mRepeatable && !mIsAccessibilityEnabled) { - repeatKey(keyIndex); - mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); - mIsRepeatableKey = true; - } + + startRepeatKey(keyIndex); startLongPressTimer(keyIndex); + showKeyPreview(keyIndex); + setPressedKeyGraphics(keyIndex); } - showKeyPreviewAndUpdateKeyGraphics(keyIndex); + } + + private void startSlidingKeyInput(Key key) { + if (!mIsInSlidingKeyInput) + mIgnoreModifierKey = isModifierCode(key.mCode); + mIsInSlidingKeyInput = true; } public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { @@ -357,10 +370,17 @@ public class PointerTracker { return; final PointerTrackerKeyState keyState = mKeyState; + // TODO: Remove this hacking code + if (mIsInSlidingLanguageSwitch) { + ((LatinKeyboard)mKeyboard).updateSpacebarPreviewIcon(x - keyState.getKeyX()); + showKeyPreview(mSpaceKeyIndex); + return; + } final int lastX = keyState.getLastX(); final int lastY = keyState.getLastY(); + final int oldKeyIndex = keyState.getKeyIndex(); + final Key oldKey = getKey(oldKeyIndex); int keyIndex = keyState.onMoveKey(x, y); - final Key oldKey = getKey(keyState.getKeyIndex()); if (isValidKeyIndex(keyIndex)) { if (oldKey == null) { // The pointer has been slid in to the new key, but the finger was not on any keys. @@ -372,13 +392,17 @@ public class PointerTracker { keyIndex = keyState.onMoveKey(x, y); keyState.onMoveToNewKey(keyIndex, x, y); startLongPressTimer(keyIndex); - } else if (!isMinorMoveBounce(x, y, keyIndex)) { + showKeyPreview(keyIndex); + setPressedKeyGraphics(keyIndex); + } else if (isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) { // The pointer has been slid in to the new key from the previous key, we must call // onRelease() first to notify that the previous key has been released, then call // onPress() to notify that the new key is being pressed. - mIsInSlidingKeyInput = true; + setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); - mHandler.cancelLongPressTimers(); + startSlidingKeyInput(oldKey); + mHandler.cancelKeyTimers(); + startRepeatKey(keyIndex); if (mIsAllowedSlidingKeyInput) { // This onPress call may have changed keyboard layout. Those cases are detected // at {@link #setKeyboard}. In those cases, we should update keyIndex according @@ -387,6 +411,8 @@ public class PointerTracker { keyIndex = keyState.onMoveKey(x, y); keyState.onMoveToNewKey(keyIndex, x, y); startLongPressTimer(keyIndex); + setPressedKeyGraphics(keyIndex); + showKeyPreview(keyIndex); } else { // HACK: On some devices, quick successive touches may be translated to sudden // move by touch panel firmware. This hack detects the case and translates the @@ -398,32 +424,50 @@ public class PointerTracker { if (DEBUG_MODE) Log.w(TAG, String.format("onMoveEvent: sudden move is translated to " + "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y)); - onUpEventInternal(lastX, lastY, eventTime); + onUpEventInternal(lastX, lastY, eventTime, true); onDownEventInternal(x, y, eventTime); } else { - setAlreadyProcessed(); - showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); + mKeyAlreadyProcessed = true; + dismissKeyPreview(); + setReleasedKeyGraphics(oldKeyIndex); + } + } + } + // TODO: Remove this hack code + else if (isSpaceKey(keyIndex) && !mIsInSlidingLanguageSwitch + && mKeyboard instanceof LatinKeyboard) { + final LatinKeyboard keyboard = ((LatinKeyboard)mKeyboard); + if (mSubtypeSwitcher.useSpacebarLanguageSwitcher() + && mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) { + final int diff = x - keyState.getKeyX(); + if (keyboard.shouldTriggerSpacebarSlidingLanguageSwitch(diff)) { + // Detect start sliding language switch. + mIsInSlidingLanguageSwitch = true; + mSpaceKeyIndex = keyIndex; + keyboard.updateSpacebarPreviewIcon(diff); + // Display spacebar slide language switcher. + showKeyPreview(keyIndex); + if (queue != null) + queue.releaseAllPointersExcept(this, eventTime, true); } - return; } } } else { - if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) { + if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) { // The pointer has been slid out from the previous key, we must call onRelease() to // notify that the previous key has been released. - mIsInSlidingKeyInput = true; + setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); + startSlidingKeyInput(oldKey); mHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { - keyState.onMoveToNewKey(keyIndex, x ,y); + keyState.onMoveToNewKey(keyIndex, x, y); } else { - setAlreadyProcessed(); - showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); - return; + mKeyAlreadyProcessed = true; + dismissKeyPreview(); } } } - showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex()); } public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { @@ -435,42 +479,69 @@ public class PointerTracker { if (isModifier()) { // Before processing an up event of modifier key, all pointers already being // tracked should be released. - queue.releaseAllPointersExcept(this, eventTime); + queue.releaseAllPointersExcept(this, eventTime, true); } else { queue.releaseAllPointersOlderThan(this, eventTime); } queue.remove(this); } - onUpEventInternal(x, y, eventTime); + onUpEventInternal(x, y, eventTime, true); } - public void onUpEventForRelease(int x, int y, long eventTime) { - onUpEventInternal(x, y, eventTime); + // Let this pointer tracker know that one of newer-than-this pointer trackers got an up event. + // This pointer tracker needs to keep the key top graphics "pressed", but needs to get a + // "virtual" up event. + public void onPhantomUpEvent(int x, int y, long eventTime, boolean updateReleasedKeyGraphics) { + if (DEBUG_EVENT) + printTouchEvent("onPhntEvent:", x, y, eventTime); + onUpEventInternal(x, y, eventTime, updateReleasedKeyGraphics); + mKeyAlreadyProcessed = true; } - private void onUpEventInternal(int pointX, int pointY, long eventTime) { - int x = pointX; - int y = pointY; + private void onUpEventInternal(int x, int y, long eventTime, + boolean updateReleasedKeyGraphics) { mHandler.cancelKeyTimers(); - mHandler.cancelPopupPreview(); - showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); + mHandler.cancelShowKeyPreview(this); mIsInSlidingKeyInput = false; + final PointerTrackerKeyState keyState = mKeyState; + final int keyX, keyY; + if (isMajorEnoughMoveToBeOnNewKey(x, y, keyState.onMoveKey(x, y))) { + keyX = x; + keyY = y; + } else { + // Use previous fixed key coordinates. + keyX = keyState.getKeyX(); + keyY = keyState.getKeyY(); + } + final int keyIndex = keyState.onUpKey(keyX, keyY, eventTime); + dismissKeyPreview(); + if (updateReleasedKeyGraphics) + setReleasedKeyGraphics(keyIndex); if (mKeyAlreadyProcessed) return; - final PointerTrackerKeyState keyState = mKeyState; - int keyIndex = keyState.onUpKey(x, y, eventTime); - if (isMinorMoveBounce(x, y, keyIndex)) { - // Use previous fixed key index and coordinates. - keyIndex = keyState.getKeyIndex(); - x = keyState.getKeyX(); - y = keyState.getKeyY(); + // TODO: Remove this hacking code + if (mIsInSlidingLanguageSwitch) { + setReleasedKeyGraphics(mSpaceKeyIndex); + final int languageDir = ((LatinKeyboard)mKeyboard).getLanguageChangeDirection(); + if (languageDir != 0) { + final int code = (languageDir == 1) + ? LatinKeyboard.CODE_NEXT_LANGUAGE : LatinKeyboard.CODE_PREV_LANGUAGE; + // This will change keyboard layout. + mListener.onCodeInput(code, new int[] {code}, keyX, keyY); + } + mIsInSlidingLanguageSwitch = false; + ((LatinKeyboard)mKeyboard).setSpacebarSlidingLanguageSwitchDiff(0); + return; } if (!mIsRepeatableKey) { - detectAndSendKey(keyIndex, x, y); + detectAndSendKey(keyIndex, keyX, keyY); } + } - if (isValidKeyIndex(keyIndex)) - mProxy.invalidateKey(mKeys[keyIndex]); + public void onLongPressed(PointerTrackerQueue queue) { + mKeyAlreadyProcessed = true; + if (queue != null) + queue.remove(this); } public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { @@ -478,22 +549,34 @@ public class PointerTracker { if (DEBUG_EVENT) printTouchEvent("onCancelEvt:", x, y, eventTime); - if (queue != null) + if (queue != null) { + queue.releaseAllPointersExcept(this, eventTime, true); queue.remove(this); + } onCancelEventInternal(); } private void onCancelEventInternal() { mHandler.cancelKeyTimers(); - mHandler.cancelPopupPreview(); - showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); + mHandler.cancelShowKeyPreview(this); + dismissKeyPreview(); + setReleasedKeyGraphics(mKeyState.getKeyIndex()); mIsInSlidingKeyInput = false; - int keyIndex = mKeyState.getKeyIndex(); - if (isValidKeyIndex(keyIndex)) - mProxy.invalidateKey(mKeys[keyIndex]); } - public void repeatKey(int keyIndex) { + private void startRepeatKey(int keyIndex) { + final Key key = getKey(keyIndex); + if (key != null && key.mRepeatable) { + dismissKeyPreview(); + onRepeatKey(keyIndex); + mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); + mIsRepeatableKey = true; + } else { + mIsRepeatableKey = false; + } + } + + public void onRepeatKey(int keyIndex) { Key key = getKey(keyIndex); if (key != null) { detectAndSendKey(keyIndex, key.mX, key.mY); @@ -512,38 +595,43 @@ public class PointerTracker { return mKeyState.getDownTime(); } - private boolean isMinorMoveBounce(int x, int y, int newKey) { + private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, int newKey) { if (mKeys == null || mKeyHysteresisDistanceSquared < 0) throw new IllegalStateException("keyboard and/or hysteresis not set"); int curKey = mKeyState.getKeyIndex(); if (newKey == curKey) { - return true; + return false; } else if (isValidKeyIndex(curKey)) { - return mKeys[curKey].squaredDistanceToEdge(x, y) < mKeyHysteresisDistanceSquared; + return mKeys.get(curKey).squaredDistanceToEdge(x, y) >= mKeyHysteresisDistanceSquared; } else { - return false; + return true; } } - private void showKeyPreviewAndUpdateKeyGraphics(int keyIndex) { - updateKeyGraphics(keyIndex); - // The modifier key, such as shift key, should not be shown as preview when multi-touch is - // supported. On the other hand, if multi-touch is not supported, the modifier key should - // be shown as preview. If accessibility is turned on, the modifier key should be shown as - // preview. - if (mHasDistinctMultitouch && isModifier() && !mIsAccessibilityEnabled) { - mProxy.showPreview(NOT_A_KEY, this); - } else { - mProxy.showPreview(keyIndex, this); - } + // The modifier key, such as shift key, should not show its key preview. + private boolean isKeyPreviewNotRequired(int keyIndex) { + final Key key = getKey(keyIndex); + if (!key.mEnabled) + return true; + // Such as spacebar sliding language switch. + if (mKeyboard.needSpacebarPreview(keyIndex)) + return false; + final int code = key.mCode; + return isModifierCode(code) || code == Keyboard.CODE_DELETE + || code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE; } - private void startLongPressTimer(int keyIndex) { - // Accessibility disables long press because users are likely to need to pause on a key - // for an unspecified duration in order to hear the key's spoken description. - if (mIsAccessibilityEnabled) { + private void showKeyPreview(int keyIndex) { + if (isKeyPreviewNotRequired(keyIndex)) return; - } + mProxy.showKeyPreview(keyIndex, this); + } + + private void dismissKeyPreview() { + mProxy.dismissKeyPreview(this); + } + + private void startLongPressTimer(int keyIndex) { Key key = getKey(keyIndex); if (key.mCode == Keyboard.CODE_SHIFT) { mHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); @@ -552,7 +640,7 @@ public class PointerTracker { // We need not start long press timer on the key which has manual temporary upper case // code defined and the keyboard is in manual temporary upper case mode. return; - } else if (mKeyboardSwitcher.isInMomentaryAutoModeSwitchState()) { + } else if (mKeyboardSwitcher.isInMomentarySwitchState()) { // We use longer timeout for sliding finger input started from the symbols mode key. mHandler.startLongPressTimer(mLongPressKeyTimeout * 3, keyIndex, this); } else { |