diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 734189689..6686de047 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -163,7 +163,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mKeyboardView.setKeyboard(keyboard); mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding); mCurrentId = keyboard.mId; - mState.onSetKeyboard(isAlphabetMode()); updateShiftLockState(keyboard); mKeyboardView.setKeyPreviewPopupEnabled( Settings.Values.isKeyPreviewPopupEnabled(mPrefs, mResources), @@ -361,15 +360,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, if (DEBUG_STATE) { Log.d(TAG, "toggleShift: " + mState); } - if (isAlphabetMode()) { - setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); - } else { - if (isSymbolShifted()) { - setSymbolsKeyboard(); - } else { - setSymbolsShiftedKeyboard(); - } - } + mState.onToggleShift(isAlphabetMode(), isSymbolShifted()); } /** @@ -379,31 +370,17 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, if (DEBUG_STATE) { Log.d(TAG, "toggleCapsLock: " + mState); } - if (isAlphabetMode()) { - if (mState.isShiftLocked()) { - setShiftLocked(false); - // TODO: Remove this. - // Shift key is long pressed while caps lock state, we will toggle back to normal - // state. And mark as if shift key is released. - mState.onReleaseCapsLock(); - } else { - setShiftLocked(true); - } - } + mState.onToggleCapsLock(isAlphabetMode()); } /** - * Toggle keyboard mode triggered by user touch event. + * Toggle between alphabet and symbols modes triggered by user touch event. */ - public void toggleKeyboardMode() { + public void toggleAlphabetAndSymbols() { if (DEBUG_STATE) { - Log.d(TAG, "toggleKeyboardMode: " + mState); - } - if (isAlphabetMode()) { - setSymbolsKeyboard(); - } else { - setAlphabetKeyboard(); + Log.d(TAG, "toggleAlphabetAndSymbols: " + mState); } + mState.onToggleAlphabetAndSymbols(isAlphabetMode()); } /** @@ -463,7 +440,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, // Implements {@link KeyboardState.SwitchActions}. @Override public void setSymbolsKeyboard() { - mState.onSaveShiftLockState(); setKeyboard(getKeyboard(mSymbolsKeyboardId)); } @@ -471,7 +447,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, @Override public void setAlphabetKeyboard() { setKeyboard(getKeyboard(mMainKeyboardId)); - mState.onRestoreShiftLockState(); } // TODO: Remove this method diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 95c9162ef..c952ea62a 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -105,12 +105,12 @@ public class KeyboardState { + " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted); } if (!state.mIsValid || state.mIsAlphabetMode) { - mSwitchActions.setAlphabetKeyboard(); + setAlphabetKeyboard(); } else { if (state.mIsShifted) { - mSwitchActions.setSymbolsShiftedKeyboard(); + setSymbolsShiftedKeyboard(); } else { - mSwitchActions.setSymbolsKeyboard(); + setSymbolsKeyboard(); } } @@ -126,11 +126,6 @@ public class KeyboardState { } } - // TODO: Get rid of this method - public void onSetKeyboard(boolean isAlphabetMode) { - mSwitchState = isAlphabetMode ? SWITCH_STATE_ALPHA : SWITCH_STATE_SYMBOL_BEGIN; - } - public boolean isShiftLocked() { return mKeyboardShiftState.isShiftLocked(); } @@ -172,32 +167,36 @@ public class KeyboardState { private void toggleAlphabetAndSymbols(boolean isAlphabetMode) { if (isAlphabetMode) { - mSwitchActions.setSymbolsKeyboard(); + setSymbolsKeyboard(); } else { - mSwitchActions.setAlphabetKeyboard(); + setAlphabetKeyboard(); } } private void toggleShiftInSymbols(boolean isSymbolShifted) { if (isSymbolShifted) { - mSwitchActions.setSymbolsKeyboard(); + setSymbolsKeyboard(); } else { - mSwitchActions.setSymbolsShiftedKeyboard(); + setSymbolsShiftedKeyboard(); } } - public void onRestoreShiftLockState() { + private void setAlphabetKeyboard() { + mSwitchActions.setAlphabetKeyboard(); + mSwitchState = SWITCH_STATE_ALPHA; mSwitchActions.setShiftLocked(mPrevMainKeyboardWasShiftLocked); mPrevMainKeyboardWasShiftLocked = false; } - public void onSaveShiftLockState() { + private void setSymbolsKeyboard() { mPrevMainKeyboardWasShiftLocked = isShiftLocked(); + mSwitchActions.setSymbolsKeyboard(); + mSwitchState = SWITCH_STATE_SYMBOL_BEGIN; } - // TODO: Remove this method. - public void onReleaseCapsLock() { - mShiftKeyState.onRelease(); + private void setSymbolsShiftedKeyboard() { + mSwitchActions.setSymbolsShiftedKeyboard(); + mSwitchState = SWITCH_STATE_SYMBOL_BEGIN; } // TODO: Get rid of isAlphabetMode argument. @@ -384,7 +383,7 @@ public class KeyboardState { } // Snap back to alpha keyboard mode immediately if user types a quote character. if (isLayoutSwitchBackCharacter(code)) { - mSwitchActions.setAlphabetKeyboard(); + setAlphabetKeyboard(); } break; case SWITCH_STATE_SYMBOL: @@ -392,12 +391,41 @@ public class KeyboardState { // Snap back to alpha keyboard mode if user types one or more non-space/enter // characters followed by a space/enter or a quote character. if (isSpaceCharacter(code) || isLayoutSwitchBackCharacter(code)) { - mSwitchActions.setAlphabetKeyboard(); + setAlphabetKeyboard(); } break; } } + // TODO: Get rid of isAlphabetMode and isSymbolShifted arguments. + public void onToggleShift(boolean isAlphabetMode, boolean isSymbolShifted) { + if (isAlphabetMode) { + mSwitchActions.setShifted( + isShiftedOrShiftLocked() ? SwitchActions.UNSHIFT : SwitchActions.MANUAL_SHIFT); + } else { + toggleShiftInSymbols(isSymbolShifted); + } + } + + // TODO: Get rid of isAlphabetMode arguments. + public void onToggleCapsLock(boolean isAlphabetMode) { + if (isAlphabetMode) { + if (isShiftLocked()) { + mSwitchActions.setShiftLocked(false); + // Shift key is long pressed while caps lock state, we will toggle back to normal + // state. And mark as if shift key is released. + mShiftKeyState.onRelease(); + } else { + mSwitchActions.setShiftLocked(true); + } + } + } + + // TODO: Get rid of isAlphabetMode arguments. + public void onToggleAlphabetAndSymbols(boolean isAlphabetMode) { + toggleAlphabetAndSymbols(isAlphabetMode); + } + private static String switchStateToString(int switchState) { switch (switchState) { case SWITCH_STATE_ALPHA: return "ALPHA"; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5ee69d1c4..ac1e71837 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1335,7 +1335,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case Keyboard.CODE_SWITCH_ALPHA_SYMBOL: // Symbol key is handled in onPress() when device has distinct multi-touch panel. if (!distinctMultiTouch) { - switcher.toggleKeyboardMode(); + switcher.toggleAlphabetAndSymbols(); } break; case Keyboard.CODE_CANCEL: