am d52e7605: Merge "Cleanup KeyboardSwitcher a bit"

* commit 'd52e76053031f282279112fbc6136bb9ccd643a6':
  Cleanup KeyboardSwitcher a bit
main
Tadashi G. Takaoka 2011-12-08 05:56:28 -08:00 committed by Android Git Automerger
commit f0fcda0899
2 changed files with 35 additions and 33 deletions

View File

@ -69,9 +69,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
private Resources mResources;
private KeyboardState mState;
private static final int UNSHIFT = 0;
private static final int MANUAL_SHIFT = 1;
private static final int AUTOMATIC_SHIFT = 2;
private KeyboardId mMainKeyboardId;
private KeyboardId mSymbolsKeyboardId;
@ -141,8 +138,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues);
mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues);
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
mPrevMainKeyboardWasShiftLocked = false;
mState.onRestoreKeyboardState();
} catch (RuntimeException e) {
Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e);
LatinImeLogger.logOnException(mMainKeyboardId.toString(), e);
@ -283,6 +278,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
return mCurrentId != null ? mCurrentId.mMode : KeyboardId.MODE_TEXT;
}
// TODO: Delegate to KeyboardState
public boolean isAlphabetMode() {
return mCurrentId != null && mCurrentId.isAlphabetKeyboard();
}
@ -368,10 +364,17 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
if (isAlphabetMode()) {
setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT);
} else {
toggleShiftInSymbols();
if (isSymbolShifted()) {
setSymbolsKeyboard();
} else {
setSymbolsShiftedKeyboard();
}
}
}
/**
* Toggle caps lock state triggered by user touch event.
*/
public void toggleCapsLock() {
if (DEBUG_STATE) {
Log.d(TAG, "toggleCapsLock: " + mState);
@ -389,11 +392,18 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
}
}
/**
* Toggle keyboard mode triggered by user touch event.
*/
public void toggleKeyboardMode() {
if (DEBUG_STATE) {
Log.d(TAG, "toggleKeyboard: " + mState);
Log.d(TAG, "toggleKeyboardMode: " + mState);
}
if (isAlphabetMode()) {
setSymbolsKeyboard();
} else {
setAlphabetKeyboard();
}
toggleAlphabetAndSymbols();
}
/**
@ -450,13 +460,10 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mState.onCancelInput(isAlphabetMode(), isSymbolShifted(), isSinglePointer());
}
// TODO: Move this variable to KeyboardState.
private boolean mPrevMainKeyboardWasShiftLocked;
// Implements {@link KeyboardState.SwitchActions}.
@Override
public void setSymbolsKeyboard() {
mPrevMainKeyboardWasShiftLocked = mState.isShiftLocked();
mState.onSaveShiftLockState();
setKeyboard(getKeyboard(mSymbolsKeyboardId));
}
@ -464,19 +471,10 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
@Override
public void setAlphabetKeyboard() {
setKeyboard(getKeyboard(mMainKeyboardId));
setShiftLocked(mPrevMainKeyboardWasShiftLocked);
mPrevMainKeyboardWasShiftLocked = false;
}
// TODO: Remove this method and merge into toggleKeyboardMode().
private void toggleAlphabetAndSymbols() {
if (isAlphabetMode()) {
setSymbolsKeyboard();
} else {
setAlphabetKeyboard();
}
mState.onRestoreShiftLockState();
}
// TODO: Remove this method
private boolean isSymbolShifted() {
return mCurrentId != null && mCurrentId.equals(mSymbolsShiftedKeyboardId);
}
@ -487,15 +485,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
setKeyboard(getKeyboard(mSymbolsShiftedKeyboardId));
}
// TODO: Remove this method and merge into toggleShift().
private void toggleShiftInSymbols() {
if (isSymbolShifted()) {
setSymbolsKeyboard();
} else {
setSymbolsShiftedKeyboard();
}
}
public boolean isInMomentarySwitchState() {
return mState.isInMomentarySwitchState();
}

View File

@ -57,6 +57,7 @@ public class KeyboardState {
private final SwitchActions mSwitchActions;
private final SavedKeyboardState mSavedKeyboardState = new SavedKeyboardState();
private boolean mPrevMainKeyboardWasShiftLocked;
private static class SavedKeyboardState {
public boolean mIsValid;
@ -75,6 +76,8 @@ public class KeyboardState {
mKeyboardShiftState.setShiftLocked(false);
mShiftKeyState.onRelease();
mSymbolKeyState.onRelease();
mPrevMainKeyboardWasShiftLocked = false;
onRestoreKeyboardState();
}
// TODO: Get rid of isAlphabetMode and isSymbolShifted arguments.
@ -95,7 +98,7 @@ public class KeyboardState {
}
}
public void onRestoreKeyboardState() {
private void onRestoreKeyboardState() {
final SavedKeyboardState state = mSavedKeyboardState;
if (DEBUG_STATE) {
Log.d(TAG, "restore: valid=" + state.mIsValid + " alphabet=" + state.mIsAlphabetMode
@ -183,6 +186,16 @@ public class KeyboardState {
}
}
public void onRestoreShiftLockState() {
mSwitchActions.setShiftLocked(mPrevMainKeyboardWasShiftLocked);
mPrevMainKeyboardWasShiftLocked = false;
}
public void onSaveShiftLockState() {
mPrevMainKeyboardWasShiftLocked = isShiftLocked();
}
// TODO: Remove this method.
public void onReleaseCapsLock() {
mShiftKeyState.onRelease();
}