Remain in previous state while sliding off from shift key
Bug: 3502290 Change-Id: I69b60051863c78727363ae63576c28d87fb71a3amain
parent
6f99d12b07
commit
e59491460b
|
@ -24,16 +24,20 @@ public interface KeyboardActionListener {
|
||||||
*
|
*
|
||||||
* @param primaryCode the unicode of the key being pressed. If the touch is not on a valid key,
|
* @param primaryCode the unicode of the key being pressed. If the touch is not on a valid key,
|
||||||
* the value will be zero.
|
* the value will be zero.
|
||||||
|
* @param withSliding true if pressing has occurred because the user slid finger from other key
|
||||||
|
* to this key without releasing the finger.
|
||||||
*/
|
*/
|
||||||
public void onPress(int primaryCode);
|
public void onPress(int primaryCode, boolean withSliding);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user releases a key. This is sent after the {@link #onCodeInput} is called.
|
* Called when the user releases a key. This is sent after the {@link #onCodeInput} is called.
|
||||||
* For keys that repeat, this is only called once.
|
* For keys that repeat, this is only called once.
|
||||||
*
|
*
|
||||||
* @param primaryCode the code of the key that was released
|
* @param primaryCode the code of the key that was released
|
||||||
|
* @param withSliding true if releasing has occurred because the user slid finger from the key
|
||||||
|
* to other key without releasing the finger.
|
||||||
*/
|
*/
|
||||||
public void onRelease(int primaryCode);
|
public void onRelease(int primaryCode, boolean withSliding);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a key code to the listener.
|
* Send a key code to the listener.
|
||||||
|
|
|
@ -440,7 +440,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
updateShiftState();
|
updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPressShift() {
|
public void onPressShift(boolean withSliding) {
|
||||||
if (!isKeyboardAvailable())
|
if (!isKeyboardAvailable())
|
||||||
return;
|
return;
|
||||||
// If accessibility is enabled, disable momentary shift lock.
|
// If accessibility is enabled, disable momentary shift lock.
|
||||||
|
@ -450,7 +450,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
if (DEBUG_STATE)
|
if (DEBUG_STATE)
|
||||||
Log.d(TAG, "onPressShift:"
|
Log.d(TAG, "onPressShift:"
|
||||||
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
||||||
+ " shiftKeyState=" + shiftKeyState);
|
+ " shiftKeyState=" + shiftKeyState + " sliding=" + withSliding);
|
||||||
if (isAlphabetMode()) {
|
if (isAlphabetMode()) {
|
||||||
if (isShiftLocked()) {
|
if (isShiftLocked()) {
|
||||||
// Shift key is pressed while caps lock state, we will treat this state as shifted
|
// Shift key is pressed while caps lock state, we will treat this state as shifted
|
||||||
|
@ -478,7 +478,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReleaseShift() {
|
public void onReleaseShift(boolean withSliding) {
|
||||||
if (!isKeyboardAvailable())
|
if (!isKeyboardAvailable())
|
||||||
return;
|
return;
|
||||||
// If accessibility is enabled, disable momentary shift lock.
|
// If accessibility is enabled, disable momentary shift lock.
|
||||||
|
@ -488,18 +488,20 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
if (DEBUG_STATE)
|
if (DEBUG_STATE)
|
||||||
Log.d(TAG, "onReleaseShift:"
|
Log.d(TAG, "onReleaseShift:"
|
||||||
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
||||||
+ " shiftKeyState=" + shiftKeyState);
|
+ " shiftKeyState=" + shiftKeyState + " sliding=" + withSliding);
|
||||||
if (isAlphabetMode()) {
|
if (isAlphabetMode()) {
|
||||||
if (shiftKeyState.isMomentary()) {
|
if (shiftKeyState.isMomentary()) {
|
||||||
// After chording input while normal state.
|
// After chording input while normal state.
|
||||||
toggleShift();
|
toggleShift();
|
||||||
} else if (isShiftLocked() && !shiftKeyState.isIgnoring()) {
|
} else if (isShiftLocked() && !shiftKeyState.isIgnoring() && !withSliding) {
|
||||||
// Shift has been pressed without chording while caps lock state.
|
// Shift has been pressed without chording while caps lock state.
|
||||||
toggleCapsLock();
|
toggleCapsLock();
|
||||||
} else if (isShiftedOrShiftLocked() && shiftKeyState.isPressingOnShifted()) {
|
} else if (isShiftedOrShiftLocked() && shiftKeyState.isPressingOnShifted()
|
||||||
|
&& !withSliding) {
|
||||||
// Shift has been pressed without chording while shifted state.
|
// Shift has been pressed without chording while shifted state.
|
||||||
toggleShift();
|
toggleShift();
|
||||||
} else if (isManualTemporaryUpperCaseFromAuto() && shiftKeyState.isPressing()) {
|
} else if (isManualTemporaryUpperCaseFromAuto() && shiftKeyState.isPressing()
|
||||||
|
&& !withSliding) {
|
||||||
// Shift has been pressed without chording while manual temporary upper case
|
// Shift has been pressed without chording while manual temporary upper case
|
||||||
// transited from automatic temporary upper case.
|
// transited from automatic temporary upper case.
|
||||||
toggleShift();
|
toggleShift();
|
||||||
|
|
|
@ -1094,12 +1094,12 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onPress(int primaryCode) {
|
public void onPress(int primaryCode, boolean withSliding) {
|
||||||
mKeyboardActionListener.onPress(primaryCode);
|
mKeyboardActionListener.onPress(primaryCode, withSliding);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onRelease(int primaryCode) {
|
public void onRelease(int primaryCode, boolean withSliding) {
|
||||||
mKeyboardActionListener.onRelease(primaryCode);
|
mKeyboardActionListener.onRelease(primaryCode, withSliding);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Override default ProximityKeyDetector.
|
// Override default ProximityKeyDetector.
|
||||||
|
|
|
@ -93,9 +93,9 @@ public class PointerTracker {
|
||||||
// Empty {@link KeyboardActionListener}
|
// Empty {@link KeyboardActionListener}
|
||||||
private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() {
|
private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPress(int primaryCode) {}
|
public void onPress(int primaryCode, boolean withSliding) {}
|
||||||
@Override
|
@Override
|
||||||
public void onRelease(int primaryCode) {}
|
public void onRelease(int primaryCode, boolean withSliding) {}
|
||||||
@Override
|
@Override
|
||||||
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {}
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {}
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,11 +138,11 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if keyboard has been changed by this callback.
|
// Returns true if keyboard has been changed by this callback.
|
||||||
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key) {
|
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) {
|
||||||
if (DEBUG_LISTENER)
|
if (DEBUG_LISTENER)
|
||||||
Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode));
|
Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding);
|
||||||
if (key.mEnabled) {
|
if (key.mEnabled) {
|
||||||
mListener.onPress(key.mCode);
|
mListener.onPress(key.mCode, withSliding);
|
||||||
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
|
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
|
||||||
mKeyboardLayoutHasBeenChanged = false;
|
mKeyboardLayoutHasBeenChanged = false;
|
||||||
return keyboardLayoutHasBeenChanged;
|
return keyboardLayoutHasBeenChanged;
|
||||||
|
@ -169,11 +169,11 @@ public class PointerTracker {
|
||||||
|
|
||||||
// Note that we need primaryCode argument because the keyboard may in shifted state and the
|
// Note that we need primaryCode argument because the keyboard may in shifted state and the
|
||||||
// primaryCode is different from {@link Key#mCode}.
|
// primaryCode is different from {@link Key#mCode}.
|
||||||
private void callListenerOnRelease(Key key, int primaryCode) {
|
private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) {
|
||||||
if (DEBUG_LISTENER)
|
if (DEBUG_LISTENER)
|
||||||
Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode));
|
Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding=" + withSliding);
|
||||||
if (key.mEnabled)
|
if (key.mEnabled)
|
||||||
mListener.onRelease(primaryCode);
|
mListener.onRelease(primaryCode, withSliding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListenerOnCancelInput() {
|
private void callListenerOnCancelInput() {
|
||||||
|
@ -333,7 +333,7 @@ public class PointerTracker {
|
||||||
// This onPress call may have changed keyboard layout. Those cases are detected at
|
// 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
|
// {@link #setKeyboard}. In those cases, we should update keyIndex according to the new
|
||||||
// keyboard layout.
|
// keyboard layout.
|
||||||
if (callListenerOnPressAndCheckKeyboardLayoutChange(mKeys[keyIndex]))
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(mKeys[keyIndex], false))
|
||||||
keyIndex = mKeyState.onDownKey(x, y, eventTime);
|
keyIndex = mKeyState.onDownKey(x, y, eventTime);
|
||||||
}
|
}
|
||||||
if (isValidKeyIndex(keyIndex)) {
|
if (isValidKeyIndex(keyIndex)) {
|
||||||
|
@ -368,7 +368,7 @@ public class PointerTracker {
|
||||||
// This onPress call may have changed keyboard layout. Those cases are detected at
|
// 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
|
// {@link #setKeyboard}. In those cases, we should update keyIndex according to the
|
||||||
// new keyboard layout.
|
// new keyboard layout.
|
||||||
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex)))
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), true))
|
||||||
keyIndex = keyState.onMoveKey(x, y);
|
keyIndex = keyState.onMoveKey(x, y);
|
||||||
keyState.onMoveToNewKey(keyIndex, x, y);
|
keyState.onMoveToNewKey(keyIndex, x, y);
|
||||||
startLongPressTimer(keyIndex);
|
startLongPressTimer(keyIndex);
|
||||||
|
@ -377,13 +377,13 @@ public class PointerTracker {
|
||||||
// onRelease() first to notify that the previous key has been released, then call
|
// onRelease() first to notify that the previous key has been released, then call
|
||||||
// onPress() to notify that the new key is being pressed.
|
// onPress() to notify that the new key is being pressed.
|
||||||
mIsInSlidingKeyInput = true;
|
mIsInSlidingKeyInput = true;
|
||||||
callListenerOnRelease(oldKey, oldKey.mCode);
|
callListenerOnRelease(oldKey, oldKey.mCode, true);
|
||||||
mHandler.cancelLongPressTimers();
|
mHandler.cancelLongPressTimers();
|
||||||
if (mIsAllowedSlidingKeyInput) {
|
if (mIsAllowedSlidingKeyInput) {
|
||||||
// This onPress call may have changed keyboard layout. Those cases are detected
|
// This onPress call may have changed keyboard layout. Those cases are detected
|
||||||
// at {@link #setKeyboard}. In those cases, we should update keyIndex according
|
// at {@link #setKeyboard}. In those cases, we should update keyIndex according
|
||||||
// to the new keyboard layout.
|
// to the new keyboard layout.
|
||||||
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex)))
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), true))
|
||||||
keyIndex = keyState.onMoveKey(x, y);
|
keyIndex = keyState.onMoveKey(x, y);
|
||||||
keyState.onMoveToNewKey(keyIndex, x, y);
|
keyState.onMoveToNewKey(keyIndex, x, y);
|
||||||
startLongPressTimer(keyIndex);
|
startLongPressTimer(keyIndex);
|
||||||
|
@ -412,7 +412,7 @@ public class PointerTracker {
|
||||||
// The pointer has been slid out from the previous key, we must call onRelease() to
|
// The pointer has been slid out from the previous key, we must call onRelease() to
|
||||||
// notify that the previous key has been released.
|
// notify that the previous key has been released.
|
||||||
mIsInSlidingKeyInput = true;
|
mIsInSlidingKeyInput = true;
|
||||||
callListenerOnRelease(oldKey, oldKey.mCode);
|
callListenerOnRelease(oldKey, oldKey.mCode, true);
|
||||||
mHandler.cancelLongPressTimers();
|
mHandler.cancelLongPressTimers();
|
||||||
if (mIsAllowedSlidingKeyInput) {
|
if (mIsAllowedSlidingKeyInput) {
|
||||||
keyState.onMoveToNewKey(keyIndex, x ,y);
|
keyState.onMoveToNewKey(keyIndex, x ,y);
|
||||||
|
@ -568,7 +568,7 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
if (key.mOutputText != null) {
|
if (key.mOutputText != null) {
|
||||||
callListenerOnTextInput(key);
|
callListenerOnTextInput(key);
|
||||||
callListenerOnRelease(key, key.mCode);
|
callListenerOnRelease(key, key.mCode, false);
|
||||||
} else {
|
} else {
|
||||||
int code = key.mCode;
|
int code = key.mCode;
|
||||||
final int[] codes = mKeyDetector.newCodeArray();
|
final int[] codes = mKeyDetector.newCodeArray();
|
||||||
|
@ -590,7 +590,7 @@ public class PointerTracker {
|
||||||
codes[0] = code;
|
codes[0] = code;
|
||||||
}
|
}
|
||||||
callListenerOnCodeInput(key, code, codes, x, y);
|
callListenerOnCodeInput(key, code, codes, x, y);
|
||||||
callListenerOnRelease(key, code);
|
callListenerOnRelease(key, code, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1951,7 +1951,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPress(int primaryCode) {
|
public void onPress(int primaryCode, boolean withSliding) {
|
||||||
if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
|
if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
|
||||||
vibrate();
|
vibrate();
|
||||||
playKeyClick(primaryCode);
|
playKeyClick(primaryCode);
|
||||||
|
@ -1959,7 +1959,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
||||||
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
||||||
switcher.onPressShift();
|
switcher.onPressShift(withSliding);
|
||||||
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
||||||
switcher.onPressSymbol();
|
switcher.onPressSymbol();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1969,13 +1969,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRelease(int primaryCode) {
|
public void onRelease(int primaryCode, boolean withSliding) {
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
// Reset any drag flags in the keyboard
|
// Reset any drag flags in the keyboard
|
||||||
switcher.keyReleased();
|
switcher.keyReleased();
|
||||||
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
||||||
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
||||||
switcher.onReleaseShift();
|
switcher.onReleaseShift(withSliding);
|
||||||
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
||||||
switcher.onReleaseSymbol();
|
switcher.onReleaseSymbol();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue