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
main
Tadashi G. Takaoka 2012-06-25 16:33:06 +09:00
parent 223b8b44df
commit 8a092b4ede
2 changed files with 21 additions and 6 deletions

View File

@ -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);

View File

@ -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;
}