Using int instead of booleans to save keyboard shift state

This is a follow up of Ib2bc262aac.

Bug: 8734294
Change-Id: I0b56797ffc4f16e18da72352777fe0f000d173aa
main
Tadashi G. Takaoka 2013-05-02 15:20:57 +09:00
parent 7f8dd50b8f
commit 7d19ab5c9d
1 changed files with 14 additions and 19 deletions

View File

@ -95,20 +95,17 @@ public final class KeyboardState {
static final class SavedKeyboardState { static final class SavedKeyboardState {
public boolean mIsValid; public boolean mIsValid;
public boolean mIsAlphabetMode; public boolean mIsAlphabetMode;
// TODO: Use <code>int</code> to represent saved shift state.
public boolean mIsAlphabetAutomaticShifted;
public boolean mIsAlphabetShiftLocked; public boolean mIsAlphabetShiftLocked;
public boolean mIsShifted; public int mShiftMode;
@Override @Override
public String toString() { public String toString() {
if (!mIsValid) return "INVALID"; if (!mIsValid) return "INVALID";
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
if (mIsAlphabetShiftLocked) return "ALPHABET_SHIFT_LOCKED"; if (mIsAlphabetShiftLocked) return "ALPHABET_SHIFT_LOCKED";
return mIsAlphabetAutomaticShifted ? "ALPHABET_AUTOMATIC_SHIFTED" return "ALPHABET_" + shiftModeToString(mShiftMode);
: (mIsShifted ? "ALPHABET_SHIFTED" : "ALPHABET");
} else { } else {
return mIsShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS"; return "SYMBOLS_" + shiftModeToString(mShiftMode);
} }
} }
} }
@ -131,17 +128,21 @@ public final class KeyboardState {
onRestoreKeyboardState(); onRestoreKeyboardState();
} }
private static final int UNSHIFT = 0;
private static final int MANUAL_SHIFT = 1;
private static final int AUTOMATIC_SHIFT = 2;
private static final int SHIFT_LOCK_SHIFTED = 3;
public void onSaveKeyboardState() { public void onSaveKeyboardState() {
final SavedKeyboardState state = mSavedKeyboardState; final SavedKeyboardState state = mSavedKeyboardState;
state.mIsAlphabetMode = mIsAlphabetMode; state.mIsAlphabetMode = mIsAlphabetMode;
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
state.mIsAlphabetShiftLocked = mAlphabetShiftState.isShiftLocked(); state.mIsAlphabetShiftLocked = mAlphabetShiftState.isShiftLocked();
state.mIsAlphabetAutomaticShifted = mAlphabetShiftState.isAutomaticShifted(); state.mShiftMode = mAlphabetShiftState.isAutomaticShifted() ? AUTOMATIC_SHIFT
state.mIsShifted = !state.mIsAlphabetShiftLocked : (mAlphabetShiftState.isShiftedOrShiftLocked() ? MANUAL_SHIFT : UNSHIFT);
&& mAlphabetShiftState.isShiftedOrShiftLocked();
} else { } else {
state.mIsAlphabetShiftLocked = mPrevMainKeyboardWasShiftLocked; state.mIsAlphabetShiftLocked = mPrevMainKeyboardWasShiftLocked;
state.mIsShifted = mIsSymbolShifted; state.mShiftMode = mIsSymbolShifted ? MANUAL_SHIFT : UNSHIFT;
} }
state.mIsValid = true; state.mIsValid = true;
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
@ -157,7 +158,7 @@ public final class KeyboardState {
if (!state.mIsValid || state.mIsAlphabetMode) { if (!state.mIsValid || state.mIsAlphabetMode) {
setAlphabetKeyboard(); setAlphabetKeyboard();
} else { } else {
if (state.mIsShifted) { if (state.mShiftMode == MANUAL_SHIFT) {
setSymbolsShiftedKeyboard(); setSymbolsShiftedKeyboard();
} else { } else {
setSymbolsKeyboard(); setSymbolsKeyboard();
@ -170,19 +171,13 @@ public final class KeyboardState {
if (state.mIsAlphabetMode) { if (state.mIsAlphabetMode) {
setShiftLocked(state.mIsAlphabetShiftLocked); setShiftLocked(state.mIsAlphabetShiftLocked);
if (!state.mIsAlphabetShiftLocked) { if (!state.mIsAlphabetShiftLocked) {
setShifted(state.mIsAlphabetAutomaticShifted ? AUTOMATIC_SHIFT setShifted(state.mShiftMode);
: (state.mIsShifted ? MANUAL_SHIFT : UNSHIFT));
} }
} else { } else {
mPrevMainKeyboardWasShiftLocked = state.mIsAlphabetShiftLocked; mPrevMainKeyboardWasShiftLocked = state.mIsAlphabetShiftLocked;
} }
} }
private static final int UNSHIFT = 0;
private static final int MANUAL_SHIFT = 1;
private static final int AUTOMATIC_SHIFT = 2;
private static final int SHIFT_LOCK_SHIFTED = 3;
private void setShifted(final int shiftMode) { private void setShifted(final int shiftMode) {
if (DEBUG_ACTION) { if (DEBUG_ACTION) {
Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode) + " " + this); Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode) + " " + this);
@ -639,7 +634,7 @@ public final class KeyboardState {
} }
} }
private static String shiftModeToString(final int shiftMode) { static String shiftModeToString(final int shiftMode) {
switch (shiftMode) { switch (shiftMode) {
case UNSHIFT: return "UNSHIFT"; case UNSHIFT: return "UNSHIFT";
case MANUAL_SHIFT: return "MANUAL"; case MANUAL_SHIFT: return "MANUAL";