diff options
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PointerTracker.java')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 163 |
1 files changed, 56 insertions, 107 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 8d7496c54..1f8119a0f 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -19,11 +19,11 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.res.Resources; import android.util.Log; +import android.widget.TextView; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; import java.util.ArrayList; import java.util.Arrays; @@ -65,9 +65,11 @@ public class PointerTracker { public interface DrawingProxy { public void invalidateKey(Key key); + public TextView inflateKeyPreviewText(); public void showKeyPreview(int keyIndex, PointerTracker tracker); public void cancelShowKeyPreview(PointerTracker tracker); public void dismissKeyPreview(PointerTracker tracker); + public boolean dismissPopupPanel(); } public interface TimerProxy { @@ -100,6 +102,7 @@ public class PointerTracker { private Keyboard mKeyboard; private List<Key> mKeys; private int mKeyQuarterWidthSquared; + private final TextView mKeyPreviewText; // The position and time at which first down event occurred. private long mDownTime; @@ -118,9 +121,12 @@ public class PointerTracker { // true if keyboard layout has been changed. private boolean mKeyboardLayoutHasBeenChanged; - // true if event is already translated to a key action (long press or mini-keyboard) + // true if event is already translated to a key action. private boolean mKeyAlreadyProcessed; + // true if this pointer has been long-pressed and is showing a popup panel. + private boolean mIsShowingPopupPanel; + // true if this pointer is repeatable key private boolean mIsRepeatableKey; @@ -133,12 +139,6 @@ public class PointerTracker { // 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 static SubtypeSwitcher sSubtypeSwitcher; - // Empty {@link KeyboardActionListener} private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() { @Override @@ -151,6 +151,8 @@ public class PointerTracker { public void onTextInput(CharSequence text) {} @Override public void onCancelInput() {} + @Override + public boolean onCustomRequest(int requestCode) { return false; } }; public static void init(boolean hasDistinctMultitouch, Context context) { @@ -172,7 +174,6 @@ public class PointerTracker { sTouchNoiseThresholdDistanceSquared = (int)( touchNoiseThresholdDistance * touchNoiseThresholdDistance); sKeyboardSwitcher = KeyboardSwitcher.getInstance(); - sSubtypeSwitcher = SubtypeSwitcher.getInstance(); } public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) { @@ -207,8 +208,7 @@ public class PointerTracker { public static void dismissAllKeyPreviews() { for (final PointerTracker tracker : sTrackers) { - tracker.setReleasedKeyGraphics(); - tracker.dismissKeyPreview(); + tracker.setReleasedKeyGraphics(tracker.mKeyIndex); } } @@ -220,6 +220,11 @@ public class PointerTracker { mListener = handler.getKeyboardActionListener(); mDrawingProxy = handler.getDrawingProxy(); mTimerProxy = handler.getTimerProxy(); + mKeyPreviewText = mDrawingProxy.inflateKeyPreviewText(); + } + + public TextView getKeyPreviewText() { + return mKeyPreviewText; } // Returns true if keyboard has been changed by this callback. @@ -282,8 +287,8 @@ public class PointerTracker { public void setKeyDetectorInner(KeyDetector keyDetector) { mKeyDetector = keyDetector; mKeyboard = keyDetector.getKeyboard(); - mKeys = mKeyboard.getKeys(); - final int keyQuarterWidth = mKeyboard.getKeyWidth() / 4; + mKeys = mKeyboard.mKeys; + final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; } @@ -326,18 +331,10 @@ public class PointerTracker { 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 setReleasedKeyGraphics() { - setReleasedKeyGraphics(mKeyIndex); - } - private void setReleasedKeyGraphics(int keyIndex) { + mDrawingProxy.dismissKeyPreview(this); final Key key = getKey(keyIndex); - if (key != null) { + if (key != null && key.isEnabled()) { key.onReleased(); mDrawingProxy.invalidateKey(key); } @@ -346,11 +343,23 @@ public class PointerTracker { private void setPressedKeyGraphics(int keyIndex) { final Key key = getKey(keyIndex); if (key != null && key.isEnabled()) { + if (isKeyPreviewRequired(key)) { + mDrawingProxy.showKeyPreview(keyIndex, this); + } key.onPressed(); mDrawingProxy.invalidateKey(key); } } + // 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; } @@ -436,7 +445,6 @@ public class PointerTracker { 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 @@ -447,7 +455,6 @@ public class PointerTracker { startRepeatKey(keyIndex); startLongPressTimer(keyIndex); - showKeyPreview(keyIndex); setPressedKeyGraphics(keyIndex); } } @@ -464,12 +471,6 @@ public class PointerTracker { if (mKeyAlreadyProcessed) return; - // TODO: Remove this hacking code - if (mIsInSlidingLanguageSwitch) { - ((LatinKeyboard)mKeyboard).updateSpacebarPreviewIcon(x - mKeyX); - showKeyPreview(mSpaceKeyIndex); - return; - } final int lastX = mLastX; final int lastY = mLastY; final int oldKeyIndex = mKeyIndex; @@ -486,7 +487,6 @@ public class PointerTracker { keyIndex = onMoveKey(x, y); onMoveToNewKey(keyIndex, x, y); startLongPressTimer(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 @@ -506,7 +506,6 @@ public class PointerTracker { 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 @@ -518,35 +517,14 @@ 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, true); + onUpEventInternal(lastX, lastY, eventTime); onDownEventInternal(x, y, eventTime); } else { mKeyAlreadyProcessed = true; - dismissKeyPreview(); setReleasedKeyGraphics(oldKeyIndex); } } } - // TODO: Remove this hack code - else if (isSpaceKey(keyIndex) && !mIsInSlidingLanguageSwitch - && mKeyboard instanceof LatinKeyboard) { - final LatinKeyboard keyboard = ((LatinKeyboard)mKeyboard); - if (sSubtypeSwitcher.useSpacebarLanguageSwitcher() - && sSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) { - final int diff = x - mKeyX; - if (keyboard.shouldTriggerSpacebarSlidingLanguageSwitch(diff)) { - // Detect start sliding language switch. - mIsInSlidingLanguageSwitch = true; - mSpaceKeyIndex = keyIndex; - keyboard.updateSpacebarPreviewIcon(diff); - // Display spacebar slide language switcher. - showKeyPreview(keyIndex); - final PointerTrackerQueue queue = sPointerTrackerQueue; - if (queue != null) - queue.releaseAllPointersExcept(this, eventTime, true); - } - } - } } else { if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) { // The pointer has been slid out from the previous key, we must call onRelease() to @@ -559,7 +537,6 @@ public class PointerTracker { onMoveToNewKey(keyIndex, x, y); } else { mKeyAlreadyProcessed = true; - dismissKeyPreview(); } } } @@ -574,27 +551,26 @@ 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, true); + queue.releaseAllPointersExcept(this, eventTime); } else { queue.releaseAllPointersOlderThan(this, eventTime); } queue.remove(this); } - onUpEventInternal(x, y, eventTime, true); + 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) { + public void onPhantomUpEvent(int x, int y, long eventTime) { if (DEBUG_EVENT) printTouchEvent("onPhntEvent:", x, y, eventTime); - onUpEventInternal(x, y, eventTime, updateReleasedKeyGraphics); + onUpEventInternal(x, y, eventTime); mKeyAlreadyProcessed = true; } - private void onUpEventInternal(int x, int y, long eventTime, - boolean updateReleasedKeyGraphics) { + private void onUpEventInternal(int x, int y, long eventTime) { mTimerProxy.cancelKeyTimers(); mDrawingProxy.cancelShowKeyPreview(this); mIsInSlidingKeyInput = false; @@ -608,34 +584,27 @@ public class PointerTracker { keyY = mKeyY; } final int keyIndex = onUpKey(keyX, keyY, eventTime); - dismissKeyPreview(); - if (updateReleasedKeyGraphics) - setReleasedKeyGraphics(keyIndex); + setReleasedKeyGraphics(keyIndex); + if (mIsShowingPopupPanel) { + mDrawingProxy.dismissPopupPanel(); + mIsShowingPopupPanel = false; + } if (mKeyAlreadyProcessed) return; - // 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, keyX, keyY); } } + public void onShowPopupPanel(int x, int y, long eventTime, KeyEventHandler handler) { + onLongPressed(); + onDownEvent(x, y, eventTime, handler); + mIsShowingPopupPanel = true; + } + public void onLongPressed() { mKeyAlreadyProcessed = true; - setReleasedKeyGraphics(); - dismissKeyPreview(); + setReleasedKeyGraphics(mKeyIndex); final PointerTrackerQueue queue = sPointerTrackerQueue; if (queue != null) { queue.remove(this); @@ -648,7 +617,7 @@ public class PointerTracker { final PointerTrackerQueue queue = sPointerTrackerQueue; if (queue != null) { - queue.releaseAllPointersExcept(this, eventTime, true); + queue.releaseAllPointersExcept(this, eventTime); queue.remove(this); } onCancelEventInternal(); @@ -657,15 +626,17 @@ public class PointerTracker { private void onCancelEventInternal() { mTimerProxy.cancelKeyTimers(); mDrawingProxy.cancelShowKeyPreview(this); - dismissKeyPreview(); setReleasedKeyGraphics(mKeyIndex); mIsInSlidingKeyInput = false; + if (mIsShowingPopupPanel) { + mDrawingProxy.dismissPopupPanel(); + mIsShowingPopupPanel = false; + } } private void startRepeatKey(int keyIndex) { final Key key = getKey(keyIndex); if (key != null && key.mRepeatable) { - dismissKeyPreview(); onRepeatKey(keyIndex); mTimerProxy.startKeyRepeatTimer(sDelayBeforeKeyRepeatStart, keyIndex, this); mIsRepeatableKey = true; @@ -695,31 +666,9 @@ public class PointerTracker { } } - // 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 == null || !key.isEnabled()) - 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 showKeyPreview(int keyIndex) { - if (isKeyPreviewNotRequired(keyIndex)) - return; - mDrawingProxy.showKeyPreview(keyIndex, this); - } - - private void dismissKeyPreview() { - mDrawingProxy.dismissKeyPreview(this); - } - private void startLongPressTimer(int keyIndex) { Key key = getKey(keyIndex); + if (key == null) return; if (key.mCode == Keyboard.CODE_SHIFT) { if (sLongPressShiftKeyTimeout > 0) { mTimerProxy.startLongPressTimer(sLongPressShiftKeyTimeout, keyIndex, this); |