am a7af03ba: Merge "Get rid of public KeyboardState.setShifted and setShiftLocked"

* commit 'a7af03baf4aa9cd0f3ac124143c109ddcce153e6':
  Get rid of public KeyboardState.setShifted and setShiftLocked
main
Tadashi G. Takaoka 2011-12-09 11:00:43 -08:00 committed by Android Git Automerger
commit b0de19af06
2 changed files with 46 additions and 34 deletions

View File

@ -138,7 +138,8 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mMainKeyboardId = getKeyboardId(editorInfo, false, false, settingsValues); mMainKeyboardId = getKeyboardId(editorInfo, false, false, settingsValues);
mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues); mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues);
mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues); mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues);
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols)); mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols),
hasDistinctMultitouch());
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e); Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e);
LatinImeLogger.logOnException(mMainKeyboardId.toString(), e); LatinImeLogger.logOnException(mMainKeyboardId.toString(), e);
@ -318,7 +319,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
if (latinKeyboard == null) if (latinKeyboard == null)
return; return;
if (shiftMode == AUTOMATIC_SHIFT) { if (shiftMode == AUTOMATIC_SHIFT) {
mState.setAutomaticTemporaryUpperCase();
latinKeyboard.setAutomaticTemporaryUpperCase(); latinKeyboard.setAutomaticTemporaryUpperCase();
} else { } else {
final boolean shifted = (shiftMode == MANUAL_SHIFT); final boolean shifted = (shiftMode == MANUAL_SHIFT);
@ -326,11 +326,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
// state when shift key is pressed to go to normal mode. // state when shift key is pressed to go to normal mode.
// On the other hand, on distinct multi touch panel device, turning off the shift // On the other hand, on distinct multi touch panel device, turning off the shift
// locked state with shift key pressing is handled by onReleaseShift(). // locked state with shift key pressing is handled by onReleaseShift().
if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) { if (!hasDistinctMultitouch() && !shifted && mState.isShiftLocked()) {
mState.setShiftLocked(false);
latinKeyboard.setShiftLocked(false); latinKeyboard.setShiftLocked(false);
} }
mState.setShifted(shifted);
latinKeyboard.setShifted(shifted); latinKeyboard.setShifted(shifted);
} }
mKeyboardView.invalidateAllKeys(); mKeyboardView.invalidateAllKeys();
@ -343,7 +341,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
LatinKeyboard latinKeyboard = getLatinKeyboard(); LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard == null) if (latinKeyboard == null)
return; return;
mState.setShiftLocked(shiftLocked);
latinKeyboard.setShiftLocked(shiftLocked); latinKeyboard.setShiftLocked(shiftLocked);
mKeyboardView.invalidateAllKeys(); mKeyboardView.invalidateAllKeys();
if (!shiftLocked) { if (!shiftLocked) {

View File

@ -22,6 +22,12 @@ import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
// TODO: Add unit tests // TODO: Add unit tests
/**
* Keyboard state machine.
*
* This class contains all keyboard state transition logic.
* TODO: List up input events and actions.
*/
public class KeyboardState { public class KeyboardState {
private static final String TAG = KeyboardState.class.getSimpleName(); private static final String TAG = KeyboardState.class.getSimpleName();
private static final boolean DEBUG_STATE = false; private static final boolean DEBUG_STATE = false;
@ -53,6 +59,7 @@ public class KeyboardState {
private int mSwitchState = SWITCH_STATE_ALPHA; private int mSwitchState = SWITCH_STATE_ALPHA;
private String mLayoutSwitchBackSymbols; private String mLayoutSwitchBackSymbols;
private boolean mHasDistinctMultitouch;
private final SwitchActions mSwitchActions; private final SwitchActions mSwitchActions;
@ -70,8 +77,9 @@ public class KeyboardState {
mSwitchActions = switchActions; mSwitchActions = switchActions;
} }
public void onLoadKeyboard(String layoutSwitchBackSymbols) { public void onLoadKeyboard(String layoutSwitchBackSymbols, boolean hasDistinctMultitouch) {
mLayoutSwitchBackSymbols = layoutSwitchBackSymbols; mLayoutSwitchBackSymbols = layoutSwitchBackSymbols;
mHasDistinctMultitouch = hasDistinctMultitouch;
mKeyboardShiftState.setShifted(false); mKeyboardShiftState.setShifted(false);
mKeyboardShiftState.setShiftLocked(false); mKeyboardShiftState.setShiftLocked(false);
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
@ -118,10 +126,9 @@ public class KeyboardState {
state.mIsValid = false; state.mIsValid = false;
if (state.mIsAlphabetMode) { if (state.mIsAlphabetMode) {
mSwitchActions.setShiftLocked(state.mIsShiftLocked); setShiftLocked(state.mIsShiftLocked);
if (!state.mIsShiftLocked) { if (!state.mIsShiftLocked) {
mSwitchActions.setShifted( setShifted(state.mIsShifted ? SwitchActions.MANUAL_SHIFT : SwitchActions.UNSHIFT);
state.mIsShifted ? SwitchActions.MANUAL_SHIFT : SwitchActions.UNSHIFT);
} }
} }
} }
@ -150,19 +157,27 @@ public class KeyboardState {
return mKeyboardShiftState.isManualTemporaryUpperCaseFromAuto(); return mKeyboardShiftState.isManualTemporaryUpperCaseFromAuto();
} }
// TODO: Get rid of this method private void setShifted(int shiftMode) {
public void setShifted(boolean shifted) { if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) {
mKeyboardShiftState.setAutomaticTemporaryUpperCase();
} else {
// TODO: Duplicated logic in KeyboardSwitcher#setShifted()
final boolean shifted = (shiftMode == SwitchActions.MANUAL_SHIFT);
// On non-distinct multi touch panel device, we should also turn off the shift locked
// state when shift key is pressed to go to normal mode.
// On the other hand, on distinct multi touch panel device, turning off the shift
// locked state with shift key pressing is handled by onReleaseShift().
if (!mHasDistinctMultitouch && !shifted && isShiftLocked()) {
mKeyboardShiftState.setShiftLocked(false);
}
mKeyboardShiftState.setShifted(shifted); mKeyboardShiftState.setShifted(shifted);
} }
mSwitchActions.setShifted(shiftMode);
// TODO: Get rid of this method
public void setShiftLocked(boolean shiftLocked) {
mKeyboardShiftState.setShiftLocked(shiftLocked);
} }
// TODO: Get rid of this method private void setShiftLocked(boolean shiftLocked) {
public void setAutomaticTemporaryUpperCase() { mKeyboardShiftState.setShiftLocked(shiftLocked);
mKeyboardShiftState.setAutomaticTemporaryUpperCase(); mSwitchActions.setShiftLocked(shiftLocked);
} }
private void toggleAlphabetAndSymbols(boolean isAlphabetMode) { private void toggleAlphabetAndSymbols(boolean isAlphabetMode) {
@ -184,7 +199,7 @@ public class KeyboardState {
private void setAlphabetKeyboard() { private void setAlphabetKeyboard() {
mSwitchActions.setAlphabetKeyboard(); mSwitchActions.setAlphabetKeyboard();
mSwitchState = SWITCH_STATE_ALPHA; mSwitchState = SWITCH_STATE_ALPHA;
mSwitchActions.setShiftLocked(mPrevMainKeyboardWasShiftLocked); setShiftLocked(mPrevMainKeyboardWasShiftLocked);
mPrevMainKeyboardWasShiftLocked = false; mPrevMainKeyboardWasShiftLocked = false;
} }
@ -227,9 +242,9 @@ public class KeyboardState {
if (!isShiftLocked() && !mShiftKeyState.isIgnoring()) { if (!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.
mSwitchActions.setShifted(SwitchActions.AUTOMATIC_SHIFT); setShifted(SwitchActions.AUTOMATIC_SHIFT);
} else { } else {
mSwitchActions.setShifted(mShiftKeyState.isMomentary() setShifted(mShiftKeyState.isMomentary()
? SwitchActions.MANUAL_SHIFT : SwitchActions.UNSHIFT); ? SwitchActions.MANUAL_SHIFT : SwitchActions.UNSHIFT);
} }
} }
@ -246,12 +261,12 @@ public class KeyboardState {
if (isShiftLocked()) { if (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.
mSwitchActions.setShifted(SwitchActions.MANUAL_SHIFT); setShifted(SwitchActions.MANUAL_SHIFT);
mShiftKeyState.onPress(); mShiftKeyState.onPress();
} else if (isAutomaticTemporaryUpperCase()) { } else if (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.
mSwitchActions.setShifted(SwitchActions.MANUAL_SHIFT); setShifted(SwitchActions.MANUAL_SHIFT);
mShiftKeyState.onPress(); mShiftKeyState.onPress();
} else if (isShiftedOrShiftLocked()) { } else if (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
@ -259,7 +274,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.
mSwitchActions.setShifted(SwitchActions.MANUAL_SHIFT); setShifted(SwitchActions.MANUAL_SHIFT);
mShiftKeyState.onPress(); mShiftKeyState.onPress();
} }
} else { } else {
@ -277,22 +292,22 @@ public class KeyboardState {
final boolean isShiftLocked = isShiftLocked(); final boolean isShiftLocked = isShiftLocked();
if (mShiftKeyState.isMomentary()) { if (mShiftKeyState.isMomentary()) {
// After chording input while normal state. // After chording input while normal state.
mSwitchActions.setShifted(SwitchActions.UNSHIFT); setShifted(SwitchActions.UNSHIFT);
} else if (isShiftLocked && !isShiftLockShifted() && (mShiftKeyState.isPressing() } else if (isShiftLocked && !isShiftLockShifted() && (mShiftKeyState.isPressing()
|| mShiftKeyState.isPressingOnShifted()) && !withSliding) { || mShiftKeyState.isPressingOnShifted()) && !withSliding) {
// Shift has been long pressed, ignore this release. // Shift has been long pressed, ignore this release.
} else if (isShiftLocked && !mShiftKeyState.isIgnoring() && !withSliding) { } else if (isShiftLocked && !mShiftKeyState.isIgnoring() && !withSliding) {
// Shift has been pressed without chording while caps lock state. // Shift has been pressed without chording while caps lock state.
mSwitchActions.setShiftLocked(false); setShiftLocked(false);
} else if (isShiftedOrShiftLocked() && mShiftKeyState.isPressingOnShifted() } else if (isShiftedOrShiftLocked() && mShiftKeyState.isPressingOnShifted()
&& !withSliding) { && !withSliding) {
// Shift has been pressed without chording while shifted state. // Shift has been pressed without chording while shifted state.
mSwitchActions.setShifted(SwitchActions.UNSHIFT); setShifted(SwitchActions.UNSHIFT);
} else if (isManualTemporaryUpperCaseFromAuto() && mShiftKeyState.isPressing() } else if (isManualTemporaryUpperCaseFromAuto() && mShiftKeyState.isPressing()
&& !withSliding) { && !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.
mSwitchActions.setShifted(SwitchActions.UNSHIFT); setShifted(SwitchActions.UNSHIFT);
} }
} else { } else {
// In symbol mode, snap back to the previous keyboard mode if the user chords the shift // In symbol mode, snap back to the previous keyboard mode if the user chords the shift
@ -400,8 +415,8 @@ public class KeyboardState {
// TODO: Get rid of isAlphabetMode and isSymbolShifted arguments. // TODO: Get rid of isAlphabetMode and isSymbolShifted arguments.
public void onToggleShift(boolean isAlphabetMode, boolean isSymbolShifted) { public void onToggleShift(boolean isAlphabetMode, boolean isSymbolShifted) {
if (isAlphabetMode) { if (isAlphabetMode) {
mSwitchActions.setShifted( setShifted(isShiftedOrShiftLocked()
isShiftedOrShiftLocked() ? SwitchActions.UNSHIFT : SwitchActions.MANUAL_SHIFT); ? SwitchActions.UNSHIFT : SwitchActions.MANUAL_SHIFT);
} else { } else {
toggleShiftInSymbols(isSymbolShifted); toggleShiftInSymbols(isSymbolShifted);
} }
@ -411,12 +426,12 @@ public class KeyboardState {
public void onToggleCapsLock(boolean isAlphabetMode) { public void onToggleCapsLock(boolean isAlphabetMode) {
if (isAlphabetMode) { if (isAlphabetMode) {
if (isShiftLocked()) { if (isShiftLocked()) {
mSwitchActions.setShiftLocked(false); setShiftLocked(false);
// Shift key is long pressed while caps lock state, we will toggle back to normal // Shift key is long pressed while caps lock state, we will toggle back to normal
// state. And mark as if shift key is released. // state. And mark as if shift key is released.
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
} else { } else {
mSwitchActions.setShiftLocked(true); setShiftLocked(true);
} }
} }
} }