Merge "Update current key reference in PointerTracker when keyboard is changed"

main
Tadashi G. Takaoka 2012-06-26 00:58:16 -07:00 committed by Android (Google) Code Review
commit 1c6a9cc44d
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 static final int MSG_TYPING_STATE_EXPIRED = 4;
private final KeyTimerParams mParams; private final KeyTimerParams mParams;
// TODO: Suppress layout changes in key repeat mode
// TODO: Remove this variable.
private boolean mInKeyRepeat; private boolean mInKeyRepeat;
public KeyTimerHandler(LatinKeyboardView outerInstance, KeyTimerParams params) { public KeyTimerHandler(LatinKeyboardView outerInstance, KeyTimerParams params) {
@ -140,8 +142,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
final PointerTracker tracker = (PointerTracker) msg.obj; final PointerTracker tracker = (PointerTracker) msg.obj;
switch (msg.what) { switch (msg.what) {
case MSG_REPEAT_KEY: case MSG_REPEAT_KEY:
tracker.onRegisterKey(tracker.getKey()); final Key currentKey = tracker.getKey();
startKeyRepeatTimer(tracker, mParams.mKeyRepeatInterval); if (currentKey != null && currentKey.mCode == msg.arg1) {
tracker.onRegisterKey(currentKey);
startKeyRepeatTimer(tracker, mParams.mKeyRepeatInterval);
}
break; break;
case MSG_LONGPRESS_KEY: case MSG_LONGPRESS_KEY:
if (tracker != null) { if (tracker != null) {
@ -158,12 +163,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
} }
private void startKeyRepeatTimer(PointerTracker tracker, long delay) { 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 @Override
public void startKeyRepeatTimer(PointerTracker tracker) { public void startKeyRepeatTimer(PointerTracker tracker) {
mInKeyRepeat = true;
startKeyRepeatTimer(tracker, mParams.mKeyRepeatStartTimeout); startKeyRepeatTimer(tracker, mParams.mKeyRepeatStartTimeout);
} }
@ -451,8 +458,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
*/ */
@Override @Override
public void setKeyboard(Keyboard keyboard) { public void setKeyboard(Keyboard keyboard) {
// Remove any pending messages, except dismissing preview // Remove any pending messages, except dismissing preview and key repeat.
mKeyTimerHandler.cancelKeyTimers(); mKeyTimerHandler.cancelLongPressTimer();
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
mKeyDetector.setKeyboard( mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); 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. // true if this pointer has been long-pressed and is showing a more keys panel.
private boolean mIsShowingMoreKeysPanel; private boolean mIsShowingMoreKeysPanel;
// TODO: Remove this variable.
// true if this pointer is repeatable key // true if this pointer is repeatable key
private boolean mIsRepeatableKey; private boolean mIsRepeatableKey;
@ -319,6 +320,13 @@ public class PointerTracker {
private void setKeyDetectorInner(KeyDetector keyDetector) { private void setKeyDetectorInner(KeyDetector keyDetector) {
mKeyDetector = keyDetector; mKeyDetector = keyDetector;
mKeyboard = keyDetector.getKeyboard(); 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; final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4;
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
} }