Refactor KeyboardState.SavedKeyboardState class a bit

Change-Id: I5be7339c4797b0308c1a192d2984056619fdfbdd
main
Tadashi G. Takaoka 2014-10-31 16:12:39 +09:00
parent e895f5f914
commit dd0b8a06a8
1 changed files with 30 additions and 25 deletions

View File

@ -106,15 +106,17 @@ public final class KeyboardState {
@Override
public String toString() {
if (!mIsValid) return "INVALID";
if (mIsAlphabetMode) {
if (mIsAlphabetShiftLocked) return "ALPHABET_SHIFT_LOCKED";
return "ALPHABET_" + shiftModeToString(mShiftMode);
} else if (mIsEmojiMode) {
return "EMOJI";
} else {
return "SYMBOLS_" + shiftModeToString(mShiftMode);
if (!mIsValid) {
return "INVALID";
}
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;
mShiftKeyState.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 MANUAL_SHIFT = 1;
private static final int AUTOMATIC_SHIFT = 2;
@ -165,28 +174,24 @@ public final class KeyboardState {
Log.d(TAG, "onRestoreKeyboardState: saved=" + state
+ " " + stateToString(autoCapsFlags, recapitalizeMode));
}
if (!state.mIsValid || state.mIsAlphabetMode) {
setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
} else if (state.mIsEmojiMode) {
setEmojiKeyboard();
} else {
if (state.mShiftMode == MANUAL_SHIFT) {
setSymbolsShiftedKeyboard();
} else {
setSymbolsKeyboard();
}
}
if (!state.mIsValid) return;
state.mIsValid = false;
mPrevMainKeyboardWasShiftLocked = state.mIsAlphabetShiftLocked;
if (state.mIsAlphabetMode) {
setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
setShiftLocked(state.mIsAlphabetShiftLocked);
if (!state.mIsAlphabetShiftLocked) {
setShifted(state.mShiftMode);
}
return;
}
if (state.mIsEmojiMode) {
setEmojiKeyboard();
return;
}
// Symbol mode
if (state.mShiftMode == MANUAL_SHIFT) {
setSymbolsShiftedKeyboard();
} else {
mPrevMainKeyboardWasShiftLocked = state.mIsAlphabetShiftLocked;
setSymbolsKeyboard();
}
}