am 7d19ab5c: Using int instead of booleans to save keyboard shift state
* commit '7d19ab5c9d20cb71f9892a147a854809eb20ca49': Using int instead of booleans to save keyboard shift statemain
commit
9bb189f613
|
@ -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";
|
||||||
|
|
Loading…
Reference in New Issue