Merge "Refactor KeyboardState.SavedKeyboardState class a bit"

This commit is contained in:
Tadashi G. Takaoka 2014-11-17 09:59:59 +00:00 committed by Android (Google) Code Review
commit 76f47ee433

View file

@ -106,15 +106,17 @@ public final class KeyboardState {
@Override @Override
public String toString() { public String toString() {
if (!mIsValid) return "INVALID"; if (!mIsValid) {
if (mIsAlphabetMode) { return "INVALID";
if (mIsAlphabetShiftLocked) return "ALPHABET_SHIFT_LOCKED";
return "ALPHABET_" + shiftModeToString(mShiftMode);
} else if (mIsEmojiMode) {
return "EMOJI";
} else {
return "SYMBOLS_" + shiftModeToString(mShiftMode);
} }
if (mIsAlphabetMode) {
return mIsAlphabetShiftLocked ? "ALPHABET_SHIFT_LOCKED"
: "ALPHABET_" + shiftModeToString(mShiftMode);
}
if (mIsEmojiMode) {
return "EMOJI";
}
return "SYMBOLS_" + shiftModeToString(mShiftMode);
} }
} }
@ -133,9 +135,16 @@ public final class KeyboardState {
mPrevSymbolsKeyboardWasShifted = false; mPrevSymbolsKeyboardWasShifted = false;
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
mSymbolKeyState.onRelease(); mSymbolKeyState.onRelease();
onRestoreKeyboardState(autoCapsFlags, recapitalizeMode); if (mSavedKeyboardState.mIsValid) {
onRestoreKeyboardState(autoCapsFlags, recapitalizeMode);
mSavedKeyboardState.mIsValid = false;
} else {
// Reset keyboard to alphabet mode.
setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
}
} }
// Constants for {@link SavedKeyboardState#mShiftMode} and {@link #setShifted(int)}.
private static final int UNSHIFT = 0; private static final int UNSHIFT = 0;
private static final int MANUAL_SHIFT = 1; private static final int MANUAL_SHIFT = 1;
private static final int AUTOMATIC_SHIFT = 2; private static final int AUTOMATIC_SHIFT = 2;
@ -165,28 +174,24 @@ public final class KeyboardState {
Log.d(TAG, "onRestoreKeyboardState: saved=" + state Log.d(TAG, "onRestoreKeyboardState: saved=" + state
+ " " + stateToString(autoCapsFlags, recapitalizeMode)); + " " + stateToString(autoCapsFlags, recapitalizeMode));
} }
if (!state.mIsValid || state.mIsAlphabetMode) { mPrevMainKeyboardWasShiftLocked = state.mIsAlphabetShiftLocked;
setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
} else if (state.mIsEmojiMode) {
setEmojiKeyboard();
} else {
if (state.mShiftMode == MANUAL_SHIFT) {
setSymbolsShiftedKeyboard();
} else {
setSymbolsKeyboard();
}
}
if (!state.mIsValid) return;
state.mIsValid = false;
if (state.mIsAlphabetMode) { if (state.mIsAlphabetMode) {
setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
setShiftLocked(state.mIsAlphabetShiftLocked); setShiftLocked(state.mIsAlphabetShiftLocked);
if (!state.mIsAlphabetShiftLocked) { if (!state.mIsAlphabetShiftLocked) {
setShifted(state.mShiftMode); setShifted(state.mShiftMode);
} }
return;
}
if (state.mIsEmojiMode) {
setEmojiKeyboard();
return;
}
// Symbol mode
if (state.mShiftMode == MANUAL_SHIFT) {
setSymbolsShiftedKeyboard();
} else { } else {
mPrevMainKeyboardWasShiftLocked = state.mIsAlphabetShiftLocked; setSymbolsKeyboard();
} }
} }