Fix potential keyboard layout change bug
Change-Id: I2518dd1d2ef4b77fe32bb1fed4e0c722f3d120c1main
parent
5797cefca6
commit
1a6fba5702
|
@ -65,6 +65,9 @@ public class PointerTracker {
|
||||||
|
|
||||||
private final PointerTrackerKeyState mKeyState;
|
private final PointerTrackerKeyState mKeyState;
|
||||||
|
|
||||||
|
// true if keyboard layout has been changed.
|
||||||
|
private boolean mKeyboardLayoutHasBeenChanged;
|
||||||
|
|
||||||
// true if event is already translated to a key action (long press or mini-keyboard)
|
// true if event is already translated to a key action (long press or mini-keyboard)
|
||||||
private boolean mKeyAlreadyProcessed;
|
private boolean mKeyAlreadyProcessed;
|
||||||
|
|
||||||
|
@ -122,10 +125,14 @@ public class PointerTracker {
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListenerOnPress(int primaryCode) {
|
// Returns true if keyboard has been changed by this callback.
|
||||||
|
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(int primaryCode) {
|
||||||
if (DEBUG_LISTENER)
|
if (DEBUG_LISTENER)
|
||||||
Log.d(TAG, "onPress : " + keyCodePrintable(primaryCode));
|
Log.d(TAG, "onPress : " + keyCodePrintable(primaryCode));
|
||||||
mListener.onPress(primaryCode);
|
mListener.onPress(primaryCode);
|
||||||
|
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
|
||||||
|
mKeyboardLayoutHasBeenChanged = false;
|
||||||
|
return keyboardLayoutHasBeenChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListenerOnCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
private void callListenerOnCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
||||||
|
@ -159,8 +166,8 @@ public class PointerTracker {
|
||||||
mKeyboard = keyboard;
|
mKeyboard = keyboard;
|
||||||
mKeys = keys;
|
mKeys = keys;
|
||||||
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
|
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
|
||||||
// Update current key index because keyboard layout has been changed.
|
// Mark that keyboard layout has been changed.
|
||||||
mKeyState.onSetKeyboard();
|
mKeyboardLayoutHasBeenChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInSlidingKeyInput() {
|
public boolean isInSlidingKeyInput() {
|
||||||
|
@ -296,14 +303,16 @@ public class PointerTracker {
|
||||||
// from modifier key, or 3) this pointer is on mini-keyboard.
|
// from modifier key, or 3) this pointer is on mini-keyboard.
|
||||||
mIsAllowedSlidingKeyInput = mConfigSlidingKeyInputEnabled || isModifierInternal(keyIndex)
|
mIsAllowedSlidingKeyInput = mConfigSlidingKeyInputEnabled || isModifierInternal(keyIndex)
|
||||||
|| mKeyDetector instanceof MiniKeyboardKeyDetector;
|
|| mKeyDetector instanceof MiniKeyboardKeyDetector;
|
||||||
|
mKeyboardLayoutHasBeenChanged = false;
|
||||||
mKeyAlreadyProcessed = false;
|
mKeyAlreadyProcessed = false;
|
||||||
mIsRepeatableKey = false;
|
mIsRepeatableKey = false;
|
||||||
mIsInSlidingKeyInput = false;
|
mIsInSlidingKeyInput = false;
|
||||||
if (isValidKeyIndex(keyIndex)) {
|
if (isValidKeyIndex(keyIndex)) {
|
||||||
callListenerOnPress(mKeys[keyIndex].mCode);
|
// This onPress call may have changed keyboard layout. Those cases are detected at
|
||||||
// This onPress call may have changed keyboard layout and have updated mKeyIndex.
|
// {@link #setKeyboard}. In those cases, we should update keyIndex according to the new
|
||||||
// If that's the case, mKeyIndex has been updated in setKeyboard().
|
// keyboard layout.
|
||||||
keyIndex = mKeyState.getKeyIndex();
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(mKeys[keyIndex].mCode))
|
||||||
|
keyIndex = mKeyState.onDownKey(x, y, eventTime);
|
||||||
}
|
}
|
||||||
if (isValidKeyIndex(keyIndex)) {
|
if (isValidKeyIndex(keyIndex)) {
|
||||||
if (mKeys[keyIndex].mRepeatable) {
|
if (mKeys[keyIndex].mRepeatable) {
|
||||||
|
@ -327,13 +336,17 @@ public class PointerTracker {
|
||||||
// TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore
|
// TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore
|
||||||
// this move event. Otherwise fire {@link onDownEventInternal} and continue.
|
// this move event. Otherwise fire {@link onDownEventInternal} and continue.
|
||||||
|
|
||||||
final int keyIndex = keyState.onMoveKey(x, y);
|
int keyIndex = keyState.onMoveKey(x, y);
|
||||||
final Key oldKey = getKey(keyState.getKeyIndex());
|
final Key oldKey = getKey(keyState.getKeyIndex());
|
||||||
if (isValidKeyIndex(keyIndex)) {
|
if (isValidKeyIndex(keyIndex)) {
|
||||||
if (oldKey == null) {
|
if (oldKey == null) {
|
||||||
// The pointer has been slid in to the new key, but the finger was not on any keys.
|
// The pointer has been slid in to the new key, but the finger was not on any keys.
|
||||||
// In this case, we must call onPress() to notify that the new key is being pressed.
|
// In this case, we must call onPress() to notify that the new key is being pressed.
|
||||||
callListenerOnPress(getKey(keyIndex).mCode);
|
// This onPress call may have changed keyboard layout. Those cases are detected at
|
||||||
|
// {@link #setKeyboard}. In those cases, we should update keyIndex according to the
|
||||||
|
// new keyboard layout.
|
||||||
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex).mCode))
|
||||||
|
keyIndex = keyState.onMoveKey(x, y);
|
||||||
keyState.onMoveToNewKey(keyIndex, x, y);
|
keyState.onMoveToNewKey(keyIndex, x, y);
|
||||||
startLongPressTimer(keyIndex);
|
startLongPressTimer(keyIndex);
|
||||||
} else if (!isMinorMoveBounce(x, y, keyIndex)) {
|
} else if (!isMinorMoveBounce(x, y, keyIndex)) {
|
||||||
|
@ -344,7 +357,11 @@ public class PointerTracker {
|
||||||
callListenerOnRelease(oldKey.mCode);
|
callListenerOnRelease(oldKey.mCode);
|
||||||
mHandler.cancelLongPressTimers();
|
mHandler.cancelLongPressTimers();
|
||||||
if (mIsAllowedSlidingKeyInput) {
|
if (mIsAllowedSlidingKeyInput) {
|
||||||
callListenerOnPress(getKey(keyIndex).mCode);
|
// This onPress call may have changed keyboard layout. Those cases are detected
|
||||||
|
// at {@link #setKeyboard}. In those cases, we should update keyIndex according
|
||||||
|
// to the new keyboard layout.
|
||||||
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex).mCode))
|
||||||
|
keyIndex = keyState.onMoveKey(x, y);
|
||||||
keyState.onMoveToNewKey(keyIndex, x, y);
|
keyState.onMoveToNewKey(keyIndex, x, y);
|
||||||
startLongPressTimer(keyIndex);
|
startLongPressTimer(keyIndex);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -106,8 +106,4 @@ package com.android.inputmethod.keyboard;
|
||||||
mUpTime = eventTime;
|
mUpTime = eventTime;
|
||||||
return onMoveKeyInternal(x, y);
|
return onMoveKeyInternal(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSetKeyboard() {
|
|
||||||
mKeyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(mKeyX, mKeyY, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue