diff options
author | 2010-09-22 23:10:47 +0900 | |
---|---|---|
committer | 2010-12-03 13:08:21 -0800 | |
commit | b80f171623a11bceb99b563594162d0034b9bde8 (patch) | |
tree | 9d6996fe249113dbf24d96f5c6981fe0deeb8918 /java/src/com/android/inputmethod/latin/PointerTracker.java | |
parent | 3dbc3a0afacda6a95803e7f15aac5a960f289add (diff) | |
parent | 36f64d2bba87ce098513c07814c86b40e5a978bd (diff) | |
download | latinime-b80f171623a11bceb99b563594162d0034b9bde8.tar.gz latinime-b80f171623a11bceb99b563594162d0034b9bde8.tar.xz latinime-b80f171623a11bceb99b563594162d0034b9bde8.zip |
Merge remote branch 'goog/master' into merge6
Change-Id: If021cd2074cd4c4f6755a7ceaec0e90ea122956c
Diffstat (limited to 'java/src/com/android/inputmethod/latin/PointerTracker.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/PointerTracker.java | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/PointerTracker.java b/java/src/com/android/inputmethod/latin/PointerTracker.java index 8b1f019d4..cb717cbe7 100644 --- a/java/src/com/android/inputmethod/latin/PointerTracker.java +++ b/java/src/com/android/inputmethod/latin/PointerTracker.java @@ -55,7 +55,7 @@ public class PointerTracker { private final boolean mHasDistinctMultitouch; private Key[] mKeys; - private int mKeyDebounceThresholdSquared = -1; + private int mKeyHysteresisDistanceSquared = -1; private int mCurrentKey = NOT_A_KEY; private int mStartX; @@ -106,11 +106,13 @@ public class PointerTracker { mListener = listener; } - public void setKeyboard(Key[] keys, float hysteresisPixel) { - if (keys == null || hysteresisPixel < 1.0f) + public void setKeyboard(Key[] keys, float keyHysteresisDistance) { + if (keys == null || keyHysteresisDistance < 0) throw new IllegalArgumentException(); mKeys = keys; - mKeyDebounceThresholdSquared = (int)(hysteresisPixel * hysteresisPixel); + mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance); + // Update current key index because keyboard layout has been changed. + mCurrentKey = mKeyDetector.getKeyIndexAndNearbyCodes(mStartX, mStartY, null); } private boolean isValidKeyIndex(int keyIndex) { @@ -121,13 +123,26 @@ public class PointerTracker { return isValidKeyIndex(keyIndex) ? mKeys[keyIndex] : null; } - public boolean isModifier() { - Key key = getKey(mCurrentKey); + private boolean isModifierInternal(int keyIndex) { + Key key = getKey(keyIndex); if (key == null) return false; int primaryCode = key.codes[0]; - // TODO: KEYCODE_MODE_CHANGE (symbol) will be also a modifier key - return primaryCode == Keyboard.KEYCODE_SHIFT; + return primaryCode == Keyboard.KEYCODE_SHIFT + || primaryCode == Keyboard.KEYCODE_MODE_CHANGE; + } + + public boolean isModifier() { + return isModifierInternal(mCurrentKey); + } + + public boolean isOnModifierKey(int x, int y) { + return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null)); + } + + public boolean isSpaceKey(int keyIndex) { + Key key = getKey(keyIndex); + return key != null && key.codes[0] == LatinIME.KEYCODE_SPACE; } public void updateKey(int keyIndex) { @@ -173,6 +188,8 @@ public class PointerTracker { } public void onDownEvent(int x, int y, long eventTime) { + if (DEBUG) + debugLog("onDownEvent:", x, y); int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); mCurrentKey = keyIndex; mStartX = x; @@ -186,6 +203,8 @@ public class PointerTracker { if (mListener != null) { int primaryCode = isValidKeyIndex(keyIndex) ? mKeys[keyIndex].codes[0] : 0; mListener.onPress(primaryCode); + // This onPress call may have changed keyboard layout and have updated mCurrentKey + keyIndex = mCurrentKey; } if (isValidKeyIndex(keyIndex)) { if (mKeys[keyIndex].repeatable) { @@ -197,11 +216,11 @@ public class PointerTracker { } showKeyPreviewAndUpdateKey(keyIndex); updateMoveDebouncing(x, y); - if (DEBUG) - debugLog("onDownEvent:", x, y); } public void onMoveEvent(int x, int y, long eventTime) { + if (DEBUG_MOVE) + debugLog("onMoveEvent:", x, y); if (mKeyAlreadyProcessed) return; int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); @@ -242,15 +261,13 @@ public class PointerTracker { */ showKeyPreviewAndUpdateKey(isMinorTimeBounce() ? mLastKey : mCurrentKey); updateMoveDebouncing(x, y); - if (DEBUG_MOVE) - debugLog("onMoveEvent:", x, y); } public void onUpEvent(int x, int y, long eventTime) { - if (mKeyAlreadyProcessed) - return; if (DEBUG) debugLog("onUpEvent :", x, y); + if (mKeyAlreadyProcessed) + return; mHandler.cancelKeyTimers(); mHandler.cancelPopupPreview(); int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); @@ -331,13 +348,12 @@ public class PointerTracker { } private boolean isMinorMoveBounce(int x, int y, int newKey, int curKey) { - if (mKeys == null || mKeyDebounceThresholdSquared < 0) + if (mKeys == null || mKeyHysteresisDistanceSquared < 0) throw new IllegalStateException("keyboard and/or hysteresis not set"); if (newKey == curKey) { return true; } else if (isValidKeyIndex(curKey)) { - return getSquareDistanceToKeyEdge(x, y, mKeys[curKey]) - < mKeyDebounceThresholdSquared; + return getSquareDistanceToKeyEdge(x, y, mKeys[curKey]) < mKeyHysteresisDistanceSquared; } else { return false; } @@ -384,8 +400,11 @@ public class PointerTracker { // The modifier key, such as shift key, should not be shown as preview when multi-touch is // supported. On thge other hand, if multi-touch is not supported, the modifier key should // be shown as preview. - if (!isModifier() || !mHasDistinctMultitouch) + if (mHasDistinctMultitouch && isModifier()) { + mProxy.showPreview(NOT_A_KEY, this); + } else { mProxy.showPreview(keyIndex, this); + } } private void detectAndSendKey(int index, int x, int y, long eventTime) { @@ -478,7 +497,7 @@ public class PointerTracker { } private void debugLog(String title, int x, int y) { - Key key = getKey(mCurrentKey); + Key key = getKey(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null)); final String code; if (key == null) { code = "----"; |