Get rid of setShifted/setShiftLocked from SwitchActions
Change-Id: Ib54b0575be190556690ef2dfb14077842745f038
This commit is contained in:
parent
470e50493a
commit
0f05076990
3 changed files with 124 additions and 85 deletions
|
@ -216,44 +216,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
|
||||||
@Override
|
|
||||||
public void setShifted(int shiftMode) {
|
|
||||||
mInputMethodService.mHandler.cancelUpdateShiftState();
|
|
||||||
Keyboard keyboard = getKeyboard();
|
|
||||||
if (keyboard == null)
|
|
||||||
return;
|
|
||||||
switch (shiftMode) {
|
|
||||||
case AUTOMATIC_SHIFT:
|
|
||||||
keyboard.setAutomaticTemporaryUpperCase();
|
|
||||||
break;
|
|
||||||
case MANUAL_SHIFT:
|
|
||||||
keyboard.setShifted(true);
|
|
||||||
break;
|
|
||||||
case UNSHIFT:
|
|
||||||
keyboard.setShifted(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mKeyboardView.invalidateAllKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
|
||||||
@Override
|
|
||||||
public void setShiftLocked(boolean shiftLocked) {
|
|
||||||
mInputMethodService.mHandler.cancelUpdateShiftState();
|
|
||||||
Keyboard keyboard = getKeyboard();
|
|
||||||
if (keyboard == null)
|
|
||||||
return;
|
|
||||||
keyboard.setShiftLocked(shiftLocked);
|
|
||||||
mKeyboardView.invalidateAllKeys();
|
|
||||||
if (!shiftLocked) {
|
|
||||||
// To be able to turn off caps lock by "double tap" on shift key, we should ignore
|
|
||||||
// the second tap of the "double tap" from now for a while because we just have
|
|
||||||
// already turned off caps lock above.
|
|
||||||
mKeyboardView.startIgnoringDoubleTap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update keyboard shift state triggered by connected EditText status change.
|
* Update keyboard shift state triggered by connected EditText status change.
|
||||||
*/
|
*/
|
||||||
|
@ -273,16 +235,73 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
||||||
mState.onCancelInput(isSinglePointer());
|
mState.onCancelInput(isSinglePointer());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
// TODO: Remove these constants.
|
||||||
@Override
|
private static final int ALPHABET_UNSHIFTED = 0;
|
||||||
public void setSymbolsKeyboard() {
|
private static final int ALPHABET_MANUAL_SHIFTED = 1;
|
||||||
setKeyboard(mKeyboardSet.getSymbolsKeyboard());
|
private static final int ALPHABET_AUTOMATIC_SHIFTED = 2;
|
||||||
|
private static final int ALPHABET_SHIFT_LOCKED = 3;
|
||||||
|
|
||||||
|
// TODO: Remove this method.
|
||||||
|
private void updateAlphabetKeyboardShiftState(int shiftMode) {
|
||||||
|
mInputMethodService.mHandler.cancelUpdateShiftState();
|
||||||
|
Keyboard keyboard = getKeyboard();
|
||||||
|
if (keyboard == null)
|
||||||
|
return;
|
||||||
|
switch (shiftMode) {
|
||||||
|
case ALPHABET_UNSHIFTED:
|
||||||
|
keyboard.setShifted(false);
|
||||||
|
break;
|
||||||
|
case ALPHABET_MANUAL_SHIFTED:
|
||||||
|
keyboard.setShifted(true);
|
||||||
|
break;
|
||||||
|
case ALPHABET_AUTOMATIC_SHIFTED:
|
||||||
|
keyboard.setAutomaticTemporaryUpperCase();
|
||||||
|
break;
|
||||||
|
case ALPHABET_SHIFT_LOCKED:
|
||||||
|
keyboard.setShiftLocked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mKeyboardView.invalidateAllKeys();
|
||||||
|
if (shiftMode != ALPHABET_SHIFT_LOCKED) {
|
||||||
|
// To be able to turn off caps lock by "double tap" on shift key, we should ignore
|
||||||
|
// the second tap of the "double tap" from now for a while because we just have
|
||||||
|
// already turned off caps lock above.
|
||||||
|
mKeyboardView.startIgnoringDoubleTap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
@Override
|
@Override
|
||||||
public void setAlphabetKeyboard() {
|
public void setAlphabetKeyboard() {
|
||||||
setKeyboard(mKeyboardSet.getMainKeyboard());
|
setKeyboard(mKeyboardSet.getMainKeyboard());
|
||||||
|
updateAlphabetKeyboardShiftState(ALPHABET_UNSHIFTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
|
@Override
|
||||||
|
public void setAlphabetManualShiftedKeyboard() {
|
||||||
|
setKeyboard(mKeyboardSet.getMainKeyboard());
|
||||||
|
updateAlphabetKeyboardShiftState(ALPHABET_MANUAL_SHIFTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
|
@Override
|
||||||
|
public void setAlphabetAutomaticShiftedKeyboard() {
|
||||||
|
setKeyboard(mKeyboardSet.getMainKeyboard());
|
||||||
|
updateAlphabetKeyboardShiftState(ALPHABET_AUTOMATIC_SHIFTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
|
@Override
|
||||||
|
public void setAlphabetShiftLockedKeyboard() {
|
||||||
|
setKeyboard(mKeyboardSet.getMainKeyboard());
|
||||||
|
updateAlphabetKeyboardShiftState(ALPHABET_SHIFT_LOCKED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
|
@Override
|
||||||
|
public void setSymbolsKeyboard() {
|
||||||
|
setKeyboard(mKeyboardSet.getSymbolsKeyboard());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
|
|
|
@ -40,16 +40,10 @@ public class KeyboardState {
|
||||||
|
|
||||||
public interface SwitchActions {
|
public interface SwitchActions {
|
||||||
public void setAlphabetKeyboard();
|
public void setAlphabetKeyboard();
|
||||||
|
public void setAlphabetManualShiftedKeyboard();
|
||||||
public static final int UNSHIFT = 0;
|
public void setAlphabetAutomaticShiftedKeyboard();
|
||||||
public static final int MANUAL_SHIFT = 1;
|
public void setAlphabetShiftLockedKeyboard();
|
||||||
public static final int AUTOMATIC_SHIFT = 2;
|
|
||||||
public void setShifted(int shiftMode);
|
|
||||||
|
|
||||||
public void setShiftLocked(boolean shiftLocked);
|
|
||||||
|
|
||||||
public void setSymbolsKeyboard();
|
public void setSymbolsKeyboard();
|
||||||
|
|
||||||
public void setSymbolsShiftedKeyboard();
|
public void setSymbolsShiftedKeyboard();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,6 +57,9 @@ public class KeyboardState {
|
||||||
private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift");
|
private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift");
|
||||||
private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol");
|
private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol");
|
||||||
|
|
||||||
|
// TODO: Merge {@link #mSwitchState}, {@link #mIsAlphabetMode}, {@link #mAlphabetShiftState},
|
||||||
|
// {@link #mIsSymbolShifted}, {@link #mPrevMainKeyboardWasShiftLocked}, and
|
||||||
|
// {@link #mPrevSymbolsKeyboardWasShifted} into single state variable.
|
||||||
private static final int SWITCH_STATE_ALPHA = 0;
|
private static final int SWITCH_STATE_ALPHA = 0;
|
||||||
private static final int SWITCH_STATE_SYMBOL_BEGIN = 1;
|
private static final int SWITCH_STATE_SYMBOL_BEGIN = 1;
|
||||||
private static final int SWITCH_STATE_SYMBOL = 2;
|
private static final int SWITCH_STATE_SYMBOL = 2;
|
||||||
|
@ -88,6 +85,7 @@ public class KeyboardState {
|
||||||
public boolean mIsShiftLocked;
|
public boolean mIsShiftLocked;
|
||||||
public boolean mIsShifted;
|
public boolean mIsShifted;
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (!mIsValid) return "INVALID";
|
if (!mIsValid) return "INVALID";
|
||||||
if (mIsAlphabetMode) {
|
if (mIsAlphabetMode) {
|
||||||
|
@ -155,7 +153,7 @@ public class KeyboardState {
|
||||||
if (state.mIsAlphabetMode) {
|
if (state.mIsAlphabetMode) {
|
||||||
setShiftLocked(state.mIsShiftLocked);
|
setShiftLocked(state.mIsShiftLocked);
|
||||||
if (!state.mIsShiftLocked) {
|
if (!state.mIsShiftLocked) {
|
||||||
setShifted(state.mIsShifted ? SwitchActions.MANUAL_SHIFT : SwitchActions.UNSHIFT);
|
setShifted(state.mIsShifted ? MANUAL_SHIFT : UNSHIFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,30 +163,58 @@ public class KeyboardState {
|
||||||
return mAlphabetShiftState.isShiftLocked();
|
return mAlphabetShiftState.isShiftLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int UNSHIFT = 0;
|
||||||
|
private static final int MANUAL_SHIFT = 1;
|
||||||
|
private static final int AUTOMATIC_SHIFT = 2;
|
||||||
|
|
||||||
private void setShifted(int shiftMode) {
|
private void setShifted(int shiftMode) {
|
||||||
if (DEBUG_ACTION) {
|
if (DEBUG_ACTION) {
|
||||||
Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode));
|
Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode) + " " + this);
|
||||||
|
}
|
||||||
|
if (!mIsAlphabetMode) return;
|
||||||
|
final int prevShiftMode;
|
||||||
|
if (mAlphabetShiftState.isAutomaticTemporaryUpperCase()) {
|
||||||
|
prevShiftMode = AUTOMATIC_SHIFT;
|
||||||
|
} else if (mAlphabetShiftState.isManualTemporaryUpperCase()) {
|
||||||
|
prevShiftMode = MANUAL_SHIFT;
|
||||||
|
} else {
|
||||||
|
prevShiftMode = UNSHIFT;
|
||||||
}
|
}
|
||||||
switch (shiftMode) {
|
switch (shiftMode) {
|
||||||
case SwitchActions.AUTOMATIC_SHIFT:
|
case AUTOMATIC_SHIFT:
|
||||||
mAlphabetShiftState.setAutomaticTemporaryUpperCase();
|
mAlphabetShiftState.setAutomaticTemporaryUpperCase();
|
||||||
|
if (shiftMode != prevShiftMode) {
|
||||||
|
mSwitchActions.setAlphabetAutomaticShiftedKeyboard();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SwitchActions.MANUAL_SHIFT:
|
case MANUAL_SHIFT:
|
||||||
mAlphabetShiftState.setShifted(true);
|
mAlphabetShiftState.setShifted(true);
|
||||||
|
if (shiftMode != prevShiftMode) {
|
||||||
|
mSwitchActions.setAlphabetManualShiftedKeyboard();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SwitchActions.UNSHIFT:
|
case UNSHIFT:
|
||||||
mAlphabetShiftState.setShifted(false);
|
mAlphabetShiftState.setShifted(false);
|
||||||
|
if (shiftMode != prevShiftMode) {
|
||||||
|
mSwitchActions.setAlphabetKeyboard();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mSwitchActions.setShifted(shiftMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setShiftLocked(boolean shiftLocked) {
|
private void setShiftLocked(boolean shiftLocked) {
|
||||||
if (DEBUG_ACTION) {
|
if (DEBUG_ACTION) {
|
||||||
Log.d(TAG, "setShiftLocked: shiftLocked=" + shiftLocked);
|
Log.d(TAG, "setShiftLocked: shiftLocked=" + shiftLocked + " " + this);
|
||||||
|
}
|
||||||
|
if (!mIsAlphabetMode) return;
|
||||||
|
if (shiftLocked && (!mAlphabetShiftState.isShiftLocked()
|
||||||
|
|| mAlphabetShiftState.isShiftLockShifted())) {
|
||||||
|
mSwitchActions.setAlphabetShiftLockedKeyboard();
|
||||||
|
}
|
||||||
|
if (!shiftLocked && mAlphabetShiftState.isShiftLocked()) {
|
||||||
|
mSwitchActions.setAlphabetKeyboard();
|
||||||
}
|
}
|
||||||
mAlphabetShiftState.setShiftLocked(shiftLocked);
|
mAlphabetShiftState.setShiftLocked(shiftLocked);
|
||||||
mSwitchActions.setShiftLocked(shiftLocked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleAlphabetAndSymbols() {
|
private void toggleAlphabetAndSymbols() {
|
||||||
|
@ -308,10 +334,9 @@ public class KeyboardState {
|
||||||
if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
|
if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
|
||||||
if (mShiftKeyState.isReleasing() && autoCaps) {
|
if (mShiftKeyState.isReleasing() && autoCaps) {
|
||||||
// Only when shift key is releasing, automatic temporary upper case will be set.
|
// Only when shift key is releasing, automatic temporary upper case will be set.
|
||||||
setShifted(SwitchActions.AUTOMATIC_SHIFT);
|
setShifted(AUTOMATIC_SHIFT);
|
||||||
} else {
|
} else {
|
||||||
setShifted(mShiftKeyState.isMomentary()
|
setShifted(mShiftKeyState.isMomentary() ? MANUAL_SHIFT : UNSHIFT);
|
||||||
? SwitchActions.MANUAL_SHIFT : SwitchActions.UNSHIFT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -326,12 +351,12 @@ public class KeyboardState {
|
||||||
if (mAlphabetShiftState.isShiftLocked()) {
|
if (mAlphabetShiftState.isShiftLocked()) {
|
||||||
// Shift key is pressed while caps lock state, we will treat this state as shifted
|
// Shift key is pressed while caps lock state, we will treat this state as shifted
|
||||||
// caps lock state and mark as if shift key pressed while normal state.
|
// caps lock state and mark as if shift key pressed while normal state.
|
||||||
setShifted(SwitchActions.MANUAL_SHIFT);
|
setShifted(MANUAL_SHIFT);
|
||||||
mShiftKeyState.onPress();
|
mShiftKeyState.onPress();
|
||||||
} else if (mAlphabetShiftState.isAutomaticTemporaryUpperCase()) {
|
} else if (mAlphabetShiftState.isAutomaticTemporaryUpperCase()) {
|
||||||
// Shift key is pressed while automatic temporary upper case, we have to move to
|
// Shift key is pressed while automatic temporary upper case, we have to move to
|
||||||
// manual temporary upper case.
|
// manual temporary upper case.
|
||||||
setShifted(SwitchActions.MANUAL_SHIFT);
|
setShifted(MANUAL_SHIFT);
|
||||||
mShiftKeyState.onPress();
|
mShiftKeyState.onPress();
|
||||||
} else if (mAlphabetShiftState.isShiftedOrShiftLocked()) {
|
} else if (mAlphabetShiftState.isShiftedOrShiftLocked()) {
|
||||||
// In manual upper case state, we just record shift key has been pressing while
|
// In manual upper case state, we just record shift key has been pressing while
|
||||||
|
@ -339,7 +364,7 @@ public class KeyboardState {
|
||||||
mShiftKeyState.onPressOnShifted();
|
mShiftKeyState.onPressOnShifted();
|
||||||
} else {
|
} else {
|
||||||
// In base layout, chording or manual temporary upper case mode is started.
|
// In base layout, chording or manual temporary upper case mode is started.
|
||||||
setShifted(SwitchActions.MANUAL_SHIFT);
|
setShifted(MANUAL_SHIFT);
|
||||||
mShiftKeyState.onPress();
|
mShiftKeyState.onPress();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -358,7 +383,7 @@ public class KeyboardState {
|
||||||
if (mAlphabetShiftState.isShiftLockShifted()) {
|
if (mAlphabetShiftState.isShiftLockShifted()) {
|
||||||
setShiftLocked(true);
|
setShiftLocked(true);
|
||||||
} else {
|
} else {
|
||||||
setShifted(SwitchActions.UNSHIFT);
|
setShifted(UNSHIFT);
|
||||||
}
|
}
|
||||||
} else if (isShiftLocked && !mAlphabetShiftState.isShiftLockShifted()
|
} else if (isShiftLocked && !mAlphabetShiftState.isShiftLockShifted()
|
||||||
&& (mShiftKeyState.isPressing() || mShiftKeyState.isPressingOnShifted())
|
&& (mShiftKeyState.isPressing() || mShiftKeyState.isPressingOnShifted())
|
||||||
|
@ -370,12 +395,12 @@ public class KeyboardState {
|
||||||
} else if (mAlphabetShiftState.isShiftedOrShiftLocked()
|
} else if (mAlphabetShiftState.isShiftedOrShiftLocked()
|
||||||
&& mShiftKeyState.isPressingOnShifted() && !withSliding) {
|
&& mShiftKeyState.isPressingOnShifted() && !withSliding) {
|
||||||
// Shift has been pressed without chording while shifted state.
|
// Shift has been pressed without chording while shifted state.
|
||||||
setShifted(SwitchActions.UNSHIFT);
|
setShifted(UNSHIFT);
|
||||||
} else if (mAlphabetShiftState.isManualTemporaryUpperCaseFromAuto()
|
} else if (mAlphabetShiftState.isManualTemporaryUpperCaseFromAuto()
|
||||||
&& mShiftKeyState.isPressing() && !withSliding) {
|
&& mShiftKeyState.isPressing() && !withSliding) {
|
||||||
// Shift has been pressed without chording while manual temporary upper case
|
// Shift has been pressed without chording while manual temporary upper case
|
||||||
// transited from automatic temporary upper case.
|
// transited from automatic temporary upper case.
|
||||||
setShifted(SwitchActions.UNSHIFT);
|
setShifted(UNSHIFT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In symbol mode, switch back to the previous keyboard mode if the user chords the
|
// In symbol mode, switch back to the previous keyboard mode if the user chords the
|
||||||
|
@ -504,9 +529,9 @@ public class KeyboardState {
|
||||||
|
|
||||||
private static String shiftModeToString(int shiftMode) {
|
private static String shiftModeToString(int shiftMode) {
|
||||||
switch (shiftMode) {
|
switch (shiftMode) {
|
||||||
case SwitchActions.UNSHIFT: return "UNSHIFT";
|
case UNSHIFT: return "UNSHIFT";
|
||||||
case SwitchActions.MANUAL_SHIFT: return "MANUAL";
|
case MANUAL_SHIFT: return "MANUAL";
|
||||||
case SwitchActions.AUTOMATIC_SHIFT: return "AUTOMATIC";
|
case AUTOMATIC_SHIFT: return "AUTOMATIC";
|
||||||
default: return null;
|
default: return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,23 +78,18 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShifted(int shiftMode) {
|
public void setAlphabetManualShiftedKeyboard() {
|
||||||
if (shiftMode == SwitchActions.UNSHIFT) {
|
mLayout = Constants.ALPHABET_MANUAL_SHIFTED;
|
||||||
mLayout = Constants.ALPHABET_UNSHIFTED;
|
|
||||||
} else if (shiftMode == SwitchActions.MANUAL_SHIFT) {
|
|
||||||
mLayout = Constants.ALPHABET_MANUAL_SHIFTED;
|
|
||||||
} else if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) {
|
|
||||||
mLayout = Constants.ALPHABET_AUTOMATIC_SHIFTED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShiftLocked(boolean shiftLocked) {
|
public void setAlphabetAutomaticShiftedKeyboard() {
|
||||||
if (shiftLocked) {
|
mLayout = Constants.ALPHABET_AUTOMATIC_SHIFTED;
|
||||||
mLayout = Constants.ALPHABET_SHIFT_LOCKED;
|
}
|
||||||
} else {
|
|
||||||
mLayout = Constants.ALPHABET_UNSHIFTED;
|
@Override
|
||||||
}
|
public void setAlphabetShiftLockedKeyboard() {
|
||||||
|
mLayout = Constants.ALPHABET_SHIFT_LOCKED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue