From f091c491ea8259ea696186ea6d97e6ce0c4c3597 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 14 Apr 2014 17:04:50 +0900 Subject: [PATCH] [IL135] Make getCurrentAutoCapsState private Bug: 8636060 Change-Id: I800aefe6fee4c14df6fe5abe21b2387c69abb8f5 --- .../keyboard/KeyboardSwitcher.java | 32 ++++---- .../keyboard/internal/KeyboardState.java | 82 +++++++++++-------- .../android/inputmethod/latin/LatinIME.java | 34 ++++---- .../internal/MockKeyboardSwitcher.java | 14 ++-- 4 files changed, 83 insertions(+), 79 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 1f8db4c23..6f93d825a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -147,7 +147,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { return false; } - public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues) { + public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues, + final int currentAutoCapsState, final int currentRecapitalizeState) { final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( mThemeContext, editorInfo); final Resources res = mThemeContext.getResources(); @@ -162,7 +163,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mKeyboardLayoutSet = builder.build(); mCurrentSettingsValues = settingsValues; try { - mState.onLoadKeyboard(); + mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState); mKeyboardTextsSet.setLocale(mSubtypeSwitcher.getCurrentSubtypeLocale(), mThemeContext); } catch (KeyboardLayoutSetException e) { Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause()); @@ -221,13 +222,14 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { // TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout // when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal(). - public void resetKeyboardStateToAlphabet() { - mState.onResetKeyboardStateToAlphabet(); + public void resetKeyboardStateToAlphabet(final int currentAutoCapsState, + final int currentRecapitalizeState) { + mState.onResetKeyboardStateToAlphabet(currentAutoCapsState, currentRecapitalizeState); } public void onPressKey(final int code, final boolean isSinglePointer, - final int currentAutoCapsState) { - mState.onPressKey(code, isSinglePointer, currentAutoCapsState); + final int currentAutoCapsState, final int currentRecapitalizeState) { + mState.onPressKey(code, isSinglePointer, currentAutoCapsState, currentRecapitalizeState); } public void onReleaseKey(final int code, final boolean withSliding, @@ -235,8 +237,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mState.onReleaseKey(code, withSliding, currentAutoCapsState, currentRecapitalizeState); } - public void onFinishSlidingInput() { - mState.onFinishSlidingInput(); + public void onFinishSlidingInput(final int currentAutoCapsState, + final int currentRecapitalizeState) { + mState.onFinishSlidingInput(currentAutoCapsState, currentRecapitalizeState); } // Implements {@link KeyboardState.SwitchActions}. @@ -297,14 +300,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS_SHIFTED)); } - // Implements {@link KeyboardState.SwitchActions}. - // TODO[IL]: merge the two following methods; remove the one without args. - @Override - public void requestUpdatingShiftState() { - mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState(), - mLatinIME.getCurrentRecapitalizeState()); - } - // Future method for requesting an updating to the shift state. public void requestUpdatingShiftState(final int currentAutoCapsState, final int currentRecapitalizeState) { @@ -339,8 +334,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { /** * Updates state machine to figure out when to automatically switch back to the previous mode. */ - public void onCodeInput(final int code, final int currentAutoCapsState) { - mState.onCodeInput(code, currentAutoCapsState); + public void onCodeInput(final int code, final int currentAutoCapsState, + final int currentRecapitalizeState) { + mState.onCodeInput(code, currentAutoCapsState, currentRecapitalizeState); } public boolean isShowingEmojiPalettes() { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 12870fba7..b98ced97c 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -27,10 +27,10 @@ import com.android.inputmethod.latin.utils.RecapitalizeStatus; * * This class contains all keyboard state transition logic. * - * The input events are {@link #onLoadKeyboard()}, {@link #onSaveKeyboardState()}, - * {@link #onPressKey(int,boolean,int)}, {@link #onReleaseKey(int,boolean,int,int)}, - * {@link #onCodeInput(int,int)}, {@link #onFinishSlidingInput()}, - * {@link #onUpdateShiftState(int,int)}, {@link #onResetKeyboardStateToAlphabet()}. + * The input events are {@link #onLoadKeyboard(int, int)}, {@link #onSaveKeyboardState()}, + * {@link #onPressKey(int,boolean,int,int)}, {@link #onReleaseKey(int,boolean,int,int)}, + * {@link #onCodeInput(int,int,int)}, {@link #onFinishSlidingInput(int,int)}, + * {@link #onUpdateShiftState(int,int)}, {@link #onResetKeyboardStateToAlphabet(int,int)}. * * The actions are {@link SwitchActions}'s methods. */ @@ -49,8 +49,6 @@ public final class KeyboardState { public void setSymbolsKeyboard(); public void setSymbolsShiftedKeyboard(); - // Legacy method. TODO: remove the following method. - public void requestUpdatingShiftState(); /** * Request to call back {@link KeyboardState#onUpdateShiftState(int, int)}. */ @@ -120,7 +118,8 @@ public final class KeyboardState { mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; } - public void onLoadKeyboard() { + public void onLoadKeyboard(final int currentAutoCapsState, + final int currentRecapitalizeState) { if (DEBUG_EVENT) { Log.d(TAG, "onLoadKeyboard: " + this); } @@ -130,7 +129,7 @@ public final class KeyboardState { mPrevSymbolsKeyboardWasShifted = false; mShiftKeyState.onRelease(); mSymbolKeyState.onRelease(); - onRestoreKeyboardState(); + onRestoreKeyboardState(currentAutoCapsState, currentRecapitalizeState); } private static final int UNSHIFT = 0; @@ -156,13 +155,14 @@ public final class KeyboardState { } } - private void onRestoreKeyboardState() { + private void onRestoreKeyboardState(final int currentAutoCapsState, + final int currentRecapitalizeState) { final SavedKeyboardState state = mSavedKeyboardState; if (DEBUG_EVENT) { Log.d(TAG, "onRestoreKeyboardState: saved=" + state + " " + this); } if (!state.mIsValid || state.mIsAlphabetMode) { - setAlphabetKeyboard(); + setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); } else if (state.mIsEmojiMode) { setEmojiKeyboard(); } else { @@ -240,7 +240,8 @@ public final class KeyboardState { mAlphabetShiftState.setShiftLocked(shiftLocked); } - private void toggleAlphabetAndSymbols() { + private void toggleAlphabetAndSymbols(final int currentAutoCapsState, + final int currentRecapitalizeState) { if (DEBUG_ACTION) { Log.d(TAG, "toggleAlphabetAndSymbols: " + this); } @@ -254,7 +255,7 @@ public final class KeyboardState { mPrevSymbolsKeyboardWasShifted = false; } else { mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; - setAlphabetKeyboard(); + setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); if (mPrevMainKeyboardWasShiftLocked) { setShiftLocked(true); } @@ -264,14 +265,15 @@ public final class KeyboardState { // TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout // when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal(). - private void resetKeyboardStateToAlphabet() { + private void resetKeyboardStateToAlphabet(final int currentAutoCapsState, + final int currentRecapitalizeState) { if (DEBUG_ACTION) { Log.d(TAG, "resetKeyboardStateToAlphabet: " + this); } if (mIsAlphabetMode) return; mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; - setAlphabetKeyboard(); + setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); if (mPrevMainKeyboardWasShiftLocked) { setShiftLocked(true); } @@ -286,7 +288,8 @@ public final class KeyboardState { } } - private void setAlphabetKeyboard() { + private void setAlphabetKeyboard(final int currentAutoCapsState, + final int currentRecapitalizeState) { if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetKeyboard"); } @@ -297,7 +300,7 @@ public final class KeyboardState { mIsSymbolShifted = false; mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; mSwitchState = SWITCH_STATE_ALPHA; - mSwitchActions.requestUpdatingShiftState(); + mSwitchActions.requestUpdatingShiftState(currentAutoCapsState, currentRecapitalizeState); } private void setSymbolsKeyboard() { @@ -339,10 +342,11 @@ public final class KeyboardState { mSwitchActions.setEmojiKeyboard(); } - public void onPressKey(final int code, final boolean isSinglePointer, final int autoCaps) { + public void onPressKey(final int code, final boolean isSinglePointer, + final int currentAutoCapsState, final int currentRecapitalizeState) { if (DEBUG_EVENT) { - Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code) - + " single=" + isSinglePointer + " autoCaps=" + autoCaps + " " + this); + Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code) + " single=" + + isSinglePointer + " autoCaps=" + currentAutoCapsState + " " + this); } if (code != Constants.CODE_SHIFT) { // Because the double tap shift key timer is to detect two consecutive shift key press, @@ -354,7 +358,7 @@ public final class KeyboardState { } else if (code == Constants.CODE_CAPSLOCK) { // Nothing to do here. See {@link #onReleaseKey(int,boolean)}. } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) { - onPressSymbol(); + onPressSymbol(currentAutoCapsState, currentRecapitalizeState); } else { mShiftKeyState.onOtherKeyPressed(); mSymbolKeyState.onOtherKeyPressed(); @@ -366,7 +370,8 @@ public final class KeyboardState { // As for #3, please note that it's required to check even when the auto caps mode is // off because, for example, we may be in the #1 state within the manual temporary // shifted mode. - if (!isSinglePointer && mIsAlphabetMode && autoCaps != TextUtils.CAP_MODE_CHARACTERS) { + if (!isSinglePointer && mIsAlphabetMode + && currentAutoCapsState != TextUtils.CAP_MODE_CHARACTERS) { final boolean needsToResetAutoCaps = mAlphabetShiftState.isAutomaticShifted() || (mAlphabetShiftState.isManualShifted() && mShiftKeyState.isReleasing()); if (needsToResetAutoCaps) { @@ -387,21 +392,23 @@ public final class KeyboardState { } else if (code == Constants.CODE_CAPSLOCK) { setShiftLocked(!mAlphabetShiftState.isShiftLocked()); } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) { - onReleaseSymbol(withSliding); + onReleaseSymbol(withSliding, currentAutoCapsState, currentRecapitalizeState); } } - private void onPressSymbol() { - toggleAlphabetAndSymbols(); + private void onPressSymbol(final int currentAutoCapsState, + final int currentRecapitalizeState) { + toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); mSymbolKeyState.onPress(); mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL; } - private void onReleaseSymbol(final boolean withSliding) { + private void onReleaseSymbol(final boolean withSliding, final int currentAutoCapsState, + final int currentRecapitalizeState) { if (mSymbolKeyState.isChording()) { // Switch back to the previous keyboard mode if the user chords the mode change key and // another key, then releases the mode change key. - toggleAlphabetAndSymbols(); + toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); } else if (!withSliding) { // If the mode change key is being released without sliding, we should forget the // previous symbols keyboard shift state and simply switch back to symbols layout @@ -422,11 +429,12 @@ public final class KeyboardState { // TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout // when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal(). - public void onResetKeyboardStateToAlphabet() { + public void onResetKeyboardStateToAlphabet(final int currentAutoCapsState, + final int currentRecapitalizeState) { if (DEBUG_EVENT) { Log.d(TAG, "onResetKeyboardStateToAlphabet: " + this); } - resetKeyboardStateToAlphabet(); + resetKeyboardStateToAlphabet(currentAutoCapsState, currentRecapitalizeState); } private void updateShiftStateForRecapitalize(final int recapitalizeMode) { @@ -579,20 +587,21 @@ public final class KeyboardState { mShiftKeyState.onRelease(); } - public void onFinishSlidingInput() { + public void onFinishSlidingInput(final int currentAutoCapsState, + final int currentRecapitalizeState) { if (DEBUG_EVENT) { Log.d(TAG, "onFinishSlidingInput: " + this); } // Switch back to the previous keyboard mode if the user cancels sliding input. switch (mSwitchState) { case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL: - toggleAlphabetAndSymbols(); + toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); break; case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE: toggleShiftInSymbols(); break; case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT: - setAlphabetKeyboard(); + setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); break; } } @@ -601,10 +610,11 @@ public final class KeyboardState { return c == Constants.CODE_SPACE || c == Constants.CODE_ENTER; } - public void onCodeInput(final int code, final int autoCaps) { + public void onCodeInput(final int code, final int currentAutoCapsState, + final int currentRecapitalizeState) { if (DEBUG_EVENT) { Log.d(TAG, "onCodeInput: code=" + Constants.printableCode(code) - + " autoCaps=" + autoCaps + " " + this); + + " autoCaps=" + currentAutoCapsState + " " + this); } switch (mSwitchState) { @@ -640,7 +650,7 @@ public final class KeyboardState { // Switch back to alpha keyboard mode if user types one or more non-space/enter // characters followed by a space/enter. if (isSpaceOrEnter(code)) { - toggleAlphabetAndSymbols(); + toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); mPrevSymbolsKeyboardWasShifted = false; } break; @@ -648,11 +658,11 @@ public final class KeyboardState { // If the code is a letter, update keyboard shift state. if (Constants.isLetterCode(code)) { - updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + updateAlphabetShiftState(currentAutoCapsState, currentRecapitalizeState); } else if (code == Constants.CODE_EMOJI) { setEmojiKeyboard(); } else if (code == Constants.CODE_ALPHA_FROM_EMOJI) { - setAlphabetKeyboard(); + setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 083e5b8a3..7fa9b6e15 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -236,7 +236,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // If we were able to reset the caches, then we can reload the keyboard. // Otherwise, we'll do it when we can. latinIme.mKeyboardSwitcher.loadKeyboard(latinIme.getCurrentInputEditorInfo(), - settingsValues); + settingsValues, latinIme.getCurrentAutoCapsState(), + latinIme.getCurrentAutoCapsState()); } break; } @@ -833,7 +834,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold); } - switcher.loadKeyboard(editorInfo, currentSettingsValues); + switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); if (!canReachInputConnection) { // If we can't reach the input connection, we will call loadKeyboard again later, // so we need to save its state now. The call will be done in #retryResetCaches. @@ -842,7 +844,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else if (restarting) { // TODO: Come up with a more comprehensive way to reset the keyboard layout when // a keyboard layout set doesn't get reloaded in this method. - switcher.resetKeyboardStateToAlphabet(); + switcher.resetKeyboardStateToAlphabet(getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); // In apps like Talk, we come here when the text is sent and the field gets emptied and // we need to re-evaluate the shift state, but not the whole layout which would be // disruptive. @@ -1119,17 +1122,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE); } - // Called from the KeyboardSwitcher which needs to know auto caps state to display - // the right layout. - // TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead? - public int getCurrentAutoCapsState() { + private int getCurrentAutoCapsState() { return mInputLogic.getCurrentAutoCapsState(mSettings.getCurrent()); } - // Called from the KeyboardSwitcher which needs to know recaps state to display - // the right layout. - // TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead? - public int getCurrentRecapitalizeState() { + private int getCurrentRecapitalizeState() { return mInputLogic.getCurrentRecapitalizeState(); } @@ -1255,7 +1252,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.onCodeInput(mSettings.getCurrent(), event, mKeyboardSwitcher.getKeyboardShiftMode(), mHandler); updateStateAfterInputTransaction(completeInputTransaction); - mKeyboardSwitcher.onCodeInput(codePoint, getCurrentAutoCapsState()); + mKeyboardSwitcher.onCodeInput(codePoint, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); } // A helper method to split the code point and the key code. Ultimately, they should not be @@ -1282,7 +1280,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.onTextInput(mSettings.getCurrent(), event, mHandler); mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState()); - mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT, getCurrentAutoCapsState()); + mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); } @Override @@ -1320,7 +1319,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onFinishSlidingInput() { // User finished sliding input. - mKeyboardSwitcher.onFinishSlidingInput(); + mKeyboardSwitcher.onFinishSlidingInput(getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); } // Called from PointerTracker through the KeyboardActionListener interface @@ -1509,7 +1509,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadSettings(); if (mKeyboardSwitcher.getMainKeyboardView() != null) { // Reload keyboard because the current language has been changed. - mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent()); + mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent(), + getCurrentAutoCapsState(), getCurrentRecapitalizeState()); } } @@ -1566,7 +1567,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onPressKey(final int primaryCode, final int repeatCount, final boolean isSinglePointer) { - mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer, getCurrentAutoCapsState()); + mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); hapticAndAudioFeedback(primaryCode, repeatCount); } diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java index 7b1a2355c..a353e5a35 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java @@ -124,11 +124,6 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { // Just ignore. } - @Override - public void requestUpdatingShiftState() { - mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); - } - @Override public void requestUpdatingShiftState(final int currentAutoCapsState, final int currentRecapitalizeState) { @@ -155,7 +150,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { } public void loadKeyboard() { - mState.onLoadKeyboard(); + mState.onLoadKeyboard(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); } public void saveKeyboardState() { @@ -163,7 +158,8 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { } public void onPressKey(final int code, final boolean isSinglePointer) { - mState.onPressKey(code, isSinglePointer, mAutoCapsState); + mState.onPressKey(code, isSinglePointer, mAutoCapsState, + RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); } public void onReleaseKey(final int code, final boolean withSliding) { @@ -187,10 +183,10 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { } else { mAutoCapsState = mAutoCapsMode; } - mState.onCodeInput(code, mAutoCapsState); + mState.onCodeInput(code, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); } public void onFinishSlidingInput() { - mState.onFinishSlidingInput(); + mState.onFinishSlidingInput(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); } }