Merge "Remove direct calls of setKeyboardXXX from KeyboardSwitcher"
This commit is contained in:
commit
a76c62e92d
3 changed files with 54 additions and 51 deletions
|
@ -164,7 +164,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
|||
mKeyboardView.setKeyboard(keyboard);
|
||||
mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding);
|
||||
mCurrentId = keyboard.mId;
|
||||
mState.onSetKeyboard(isAlphabetMode());
|
||||
updateShiftLockState(keyboard);
|
||||
mKeyboardView.setKeyPreviewPopupEnabled(
|
||||
SettingsValues.isKeyPreviewPopupEnabled(mPrefs, mResources),
|
||||
|
@ -362,15 +361,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
|||
if (DEBUG_STATE) {
|
||||
Log.d(TAG, "toggleShift: " + mState);
|
||||
}
|
||||
if (isAlphabetMode()) {
|
||||
setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT);
|
||||
} else {
|
||||
if (isSymbolShifted()) {
|
||||
setSymbolsKeyboard();
|
||||
} else {
|
||||
setSymbolsShiftedKeyboard();
|
||||
}
|
||||
}
|
||||
mState.onToggleShift(isAlphabetMode(), isSymbolShifted());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,31 +371,17 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
|||
if (DEBUG_STATE) {
|
||||
Log.d(TAG, "toggleCapsLock: " + mState);
|
||||
}
|
||||
if (isAlphabetMode()) {
|
||||
if (mState.isShiftLocked()) {
|
||||
setShiftLocked(false);
|
||||
// TODO: Remove this.
|
||||
// Shift key is long pressed while caps lock state, we will toggle back to normal
|
||||
// state. And mark as if shift key is released.
|
||||
mState.onReleaseCapsLock();
|
||||
} else {
|
||||
setShiftLocked(true);
|
||||
}
|
||||
}
|
||||
mState.onToggleCapsLock(isAlphabetMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle keyboard mode triggered by user touch event.
|
||||
* Toggle between alphabet and symbols modes triggered by user touch event.
|
||||
*/
|
||||
public void toggleKeyboardMode() {
|
||||
public void toggleAlphabetAndSymbols() {
|
||||
if (DEBUG_STATE) {
|
||||
Log.d(TAG, "toggleKeyboardMode: " + mState);
|
||||
}
|
||||
if (isAlphabetMode()) {
|
||||
setSymbolsKeyboard();
|
||||
} else {
|
||||
setAlphabetKeyboard();
|
||||
Log.d(TAG, "toggleAlphabetAndSymbols: " + mState);
|
||||
}
|
||||
mState.onToggleAlphabetAndSymbols(isAlphabetMode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -464,7 +441,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
|||
// Implements {@link KeyboardState.SwitchActions}.
|
||||
@Override
|
||||
public void setSymbolsKeyboard() {
|
||||
mState.onSaveShiftLockState();
|
||||
setKeyboard(getKeyboard(mSymbolsKeyboardId));
|
||||
}
|
||||
|
||||
|
@ -472,7 +448,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
|||
@Override
|
||||
public void setAlphabetKeyboard() {
|
||||
setKeyboard(getKeyboard(mMainKeyboardId));
|
||||
mState.onRestoreShiftLockState();
|
||||
}
|
||||
|
||||
// TODO: Remove this method
|
||||
|
|
|
@ -105,12 +105,12 @@ public class KeyboardState {
|
|||
+ " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted);
|
||||
}
|
||||
if (!state.mIsValid || state.mIsAlphabetMode) {
|
||||
mSwitchActions.setAlphabetKeyboard();
|
||||
setAlphabetKeyboard();
|
||||
} else {
|
||||
if (state.mIsShifted) {
|
||||
mSwitchActions.setSymbolsShiftedKeyboard();
|
||||
setSymbolsShiftedKeyboard();
|
||||
} else {
|
||||
mSwitchActions.setSymbolsKeyboard();
|
||||
setSymbolsKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,11 +126,6 @@ public class KeyboardState {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Get rid of this method
|
||||
public void onSetKeyboard(boolean isAlphabetMode) {
|
||||
mSwitchState = isAlphabetMode ? SWITCH_STATE_ALPHA : SWITCH_STATE_SYMBOL_BEGIN;
|
||||
}
|
||||
|
||||
public boolean isShiftLocked() {
|
||||
return mKeyboardShiftState.isShiftLocked();
|
||||
}
|
||||
|
@ -172,32 +167,36 @@ public class KeyboardState {
|
|||
|
||||
private void toggleAlphabetAndSymbols(boolean isAlphabetMode) {
|
||||
if (isAlphabetMode) {
|
||||
mSwitchActions.setSymbolsKeyboard();
|
||||
setSymbolsKeyboard();
|
||||
} else {
|
||||
mSwitchActions.setAlphabetKeyboard();
|
||||
setAlphabetKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleShiftInSymbols(boolean isSymbolShifted) {
|
||||
if (isSymbolShifted) {
|
||||
mSwitchActions.setSymbolsKeyboard();
|
||||
setSymbolsKeyboard();
|
||||
} else {
|
||||
mSwitchActions.setSymbolsShiftedKeyboard();
|
||||
setSymbolsShiftedKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRestoreShiftLockState() {
|
||||
private void setAlphabetKeyboard() {
|
||||
mSwitchActions.setAlphabetKeyboard();
|
||||
mSwitchState = SWITCH_STATE_ALPHA;
|
||||
mSwitchActions.setShiftLocked(mPrevMainKeyboardWasShiftLocked);
|
||||
mPrevMainKeyboardWasShiftLocked = false;
|
||||
}
|
||||
|
||||
public void onSaveShiftLockState() {
|
||||
private void setSymbolsKeyboard() {
|
||||
mPrevMainKeyboardWasShiftLocked = isShiftLocked();
|
||||
mSwitchActions.setSymbolsKeyboard();
|
||||
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
|
||||
}
|
||||
|
||||
// TODO: Remove this method.
|
||||
public void onReleaseCapsLock() {
|
||||
mShiftKeyState.onRelease();
|
||||
private void setSymbolsShiftedKeyboard() {
|
||||
mSwitchActions.setSymbolsShiftedKeyboard();
|
||||
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
|
||||
}
|
||||
|
||||
// TODO: Get rid of isAlphabetMode argument.
|
||||
|
@ -384,7 +383,7 @@ public class KeyboardState {
|
|||
}
|
||||
// Snap back to alpha keyboard mode immediately if user types a quote character.
|
||||
if (isLayoutSwitchBackCharacter(code)) {
|
||||
mSwitchActions.setAlphabetKeyboard();
|
||||
setAlphabetKeyboard();
|
||||
}
|
||||
break;
|
||||
case SWITCH_STATE_SYMBOL:
|
||||
|
@ -392,12 +391,41 @@ public class KeyboardState {
|
|||
// Snap back to alpha keyboard mode if user types one or more non-space/enter
|
||||
// characters followed by a space/enter or a quote character.
|
||||
if (isSpaceCharacter(code) || isLayoutSwitchBackCharacter(code)) {
|
||||
mSwitchActions.setAlphabetKeyboard();
|
||||
setAlphabetKeyboard();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Get rid of isAlphabetMode and isSymbolShifted arguments.
|
||||
public void onToggleShift(boolean isAlphabetMode, boolean isSymbolShifted) {
|
||||
if (isAlphabetMode) {
|
||||
mSwitchActions.setShifted(
|
||||
isShiftedOrShiftLocked() ? SwitchActions.UNSHIFT : SwitchActions.MANUAL_SHIFT);
|
||||
} else {
|
||||
toggleShiftInSymbols(isSymbolShifted);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Get rid of isAlphabetMode arguments.
|
||||
public void onToggleCapsLock(boolean isAlphabetMode) {
|
||||
if (isAlphabetMode) {
|
||||
if (isShiftLocked()) {
|
||||
mSwitchActions.setShiftLocked(false);
|
||||
// Shift key is long pressed while caps lock state, we will toggle back to normal
|
||||
// state. And mark as if shift key is released.
|
||||
mShiftKeyState.onRelease();
|
||||
} else {
|
||||
mSwitchActions.setShiftLocked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Get rid of isAlphabetMode arguments.
|
||||
public void onToggleAlphabetAndSymbols(boolean isAlphabetMode) {
|
||||
toggleAlphabetAndSymbols(isAlphabetMode);
|
||||
}
|
||||
|
||||
private static String switchStateToString(int switchState) {
|
||||
switch (switchState) {
|
||||
case SWITCH_STATE_ALPHA: return "ALPHA";
|
||||
|
|
|
@ -1335,7 +1335,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
|
||||
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
|
||||
if (!distinctMultiTouch) {
|
||||
switcher.toggleKeyboardMode();
|
||||
switcher.toggleAlphabetAndSymbols();
|
||||
}
|
||||
break;
|
||||
case Keyboard.CODE_CANCEL:
|
||||
|
|
Loading…
Reference in a new issue