From 8a092b4ede02b79422deae51f0a416b034777fb3 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 25 Jun 2012 16:33:06 +0900 Subject: [PATCH] Update current key reference in PointerTracker when keyboard is changed This change also checks that the current key is the same key that started the key repeat, when key repeat timer is fired. Bug: 6722052 Change-Id: Id69880ded3338a5a3cbe7f8bf951f94f2651119c --- .../keyboard/LatinKeyboardView.java | 19 +++++++++++++------ .../inputmethod/keyboard/PointerTracker.java | 8 ++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 383298de9..e3739eb3c 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -127,6 +127,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke private static final int MSG_TYPING_STATE_EXPIRED = 4; private final KeyTimerParams mParams; + // TODO: Suppress layout changes in key repeat mode + // TODO: Remove this variable. private boolean mInKeyRepeat; public KeyTimerHandler(LatinKeyboardView outerInstance, KeyTimerParams params) { @@ -140,8 +142,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke final PointerTracker tracker = (PointerTracker) msg.obj; switch (msg.what) { case MSG_REPEAT_KEY: - tracker.onRegisterKey(tracker.getKey()); - startKeyRepeatTimer(tracker, mParams.mKeyRepeatInterval); + final Key currentKey = tracker.getKey(); + if (currentKey != null && currentKey.mCode == msg.arg1) { + tracker.onRegisterKey(currentKey); + startKeyRepeatTimer(tracker, mParams.mKeyRepeatInterval); + } break; case MSG_LONGPRESS_KEY: if (tracker != null) { @@ -158,12 +163,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } private void startKeyRepeatTimer(PointerTracker tracker, long delay) { - sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, tracker), delay); + final Key key = tracker.getKey(); + if (key == null) return; + mInKeyRepeat = true; + sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.mCode, 0, tracker), delay); } @Override public void startKeyRepeatTimer(PointerTracker tracker) { - mInKeyRepeat = true; startKeyRepeatTimer(tracker, mParams.mKeyRepeatStartTimeout); } @@ -451,8 +458,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke */ @Override public void setKeyboard(Keyboard keyboard) { - // Remove any pending messages, except dismissing preview - mKeyTimerHandler.cancelKeyTimers(); + // Remove any pending messages, except dismissing preview and key repeat. + mKeyTimerHandler.cancelLongPressTimer(); super.setKeyboard(keyboard); mKeyDetector.setKeyboard( keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 34e428e82..8aac8d80c 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -148,6 +148,7 @@ public class PointerTracker { // true if this pointer has been long-pressed and is showing a more keys panel. private boolean mIsShowingMoreKeysPanel; + // TODO: Remove this variable. // true if this pointer is repeatable key private boolean mIsRepeatableKey; @@ -319,6 +320,13 @@ public class PointerTracker { private void setKeyDetectorInner(KeyDetector keyDetector) { mKeyDetector = keyDetector; mKeyboard = keyDetector.getKeyboard(); + final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY); + if (newKey != mCurrentKey) { + if (mDrawingProxy != null) { + setReleasedKeyGraphics(mCurrentKey); + } + mCurrentKey = newKey; + } final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; }