diff options
author | 2011-04-22 21:05:30 +0900 | |
---|---|---|
committer | 2011-04-22 21:17:55 +0900 | |
commit | a0537fb4c73dff8beecc328720830af9719d0277 (patch) | |
tree | 96b4f5bd0d6d138c622b8ab92a96fcbee5afe9f0 /java/src | |
parent | 0156713f2a8f398eeb54a3e41fa15c87dcd70a89 (diff) | |
download | latinime-a0537fb4c73dff8beecc328720830af9719d0277.tar.gz latinime-a0537fb4c73dff8beecc328720830af9719d0277.tar.xz latinime-a0537fb4c73dff8beecc328720830af9719d0277.zip |
Fix repeat key behavior
Change-Id: Ia7e5b2e9579aa0e5050857cdb14f16fa05a33621
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardView.java | 22 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 32 |
2 files changed, 36 insertions, 18 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 95ecb3bc9..c36895258 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -139,6 +139,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private final boolean mHasDistinctMultitouch; private int mOldPointerCount = 1; + private int mOldKeyIndex; // Accessibility private boolean mIsAccessibilityEnabled; @@ -202,7 +203,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { break; case MSG_REPEAT_KEY: { final PointerTracker tracker = (PointerTracker)msg.obj; - tracker.repeatKey(msg.arg1); + tracker.onRepeatKey(msg.arg1); startKeyRepeatTimer(mKeyRepeatInterval, msg.arg1, tracker); break; } @@ -1270,10 +1271,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } if (mHandler.isInKeyRepeat()) { - // It will keep being in the key repeating mode while the key is being pressed. - if (action == MotionEvent.ACTION_MOVE) { - return true; - } final PointerTracker tracker = getPointerTracker(id); // Key repeating timer will be canceled if 2 or more keys are in action, and current // event (UP or DOWN) is non-modifier key. @@ -1291,12 +1288,21 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { PointerTracker tracker = getPointerTracker(0); if (pointerCount == 1 && oldPointerCount == 2) { // Multi-touch to single touch transition. - // Send a down event for the latest pointer. - tracker.onDownEvent(x, y, eventTime, null); + // Send a down event for the latest pointer if the key is different from the + // previous key. + final int newKeyIndex = tracker.getKeyIndexOn(x, y); + if (mOldKeyIndex != newKeyIndex) { + tracker.onDownEvent(x, y, eventTime, null); + if (action == MotionEvent.ACTION_UP) + tracker.onUpEvent(x, y, eventTime, null); + } } else if (pointerCount == 2 && oldPointerCount == 1) { // Single-touch to multi-touch transition. // Send an up event for the last pointer. - tracker.onUpEvent(tracker.getLastX(), tracker.getLastY(), eventTime, null); + final int lastX = tracker.getLastX(); + final int lastY = tracker.getLastY(); + mOldKeyIndex = tracker.getKeyIndexOn(lastX, lastY); + tracker.onUpEvent(lastX, lastY, eventTime, null); } else if (pointerCount == 1 && oldPointerCount == 1) { tracker.onTouchEvent(action, x, y, eventTime, null); } else { diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index d975b39b9..e3161f610 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -251,6 +251,10 @@ 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; @@ -355,14 +359,7 @@ public class PointerTracker { if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), false)) keyIndex = mKeyState.onDownKey(x, y, eventTime); - // Accessibility disables key repeat because users may need to pause on a key to hear - // its spoken description. - final Key key = getKey(keyIndex); - if (key != null && key.mRepeatable && !mIsAccessibilityEnabled) { - repeatKey(keyIndex); - mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); - mIsRepeatableKey = true; - } + startRepeatKey(keyIndex); startLongPressTimer(keyIndex); showKeyPreview(keyIndex); setPressedKeyGraphics(keyIndex); @@ -414,7 +411,8 @@ public class PointerTracker { setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); startSlidingKeyInput(oldKey); - mHandler.cancelLongPressTimers(); + 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 @@ -576,7 +574,21 @@ public class PointerTracker { mIsInSlidingKeyInput = false; } - public void repeatKey(int keyIndex) { + private void startRepeatKey(int keyIndex) { + // Accessibility disables key repeat because users may need to pause on a key to hear + // its spoken description. + final Key key = getKey(keyIndex); + if (key != null && key.mRepeatable && !mIsAccessibilityEnabled) { + 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); |