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 Resources mResources;
private KeyboardState mState; 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 mMainKeyboardId;
private KeyboardId mSymbolsKeyboardId; private KeyboardId mSymbolsKeyboardId;
@ -141,8 +138,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
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));
mPrevMainKeyboardWasShiftLocked = false;
mState.onRestoreKeyboardState();
} 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);
@ -283,6 +278,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
return mCurrentId != null ? mCurrentId.mMode : KeyboardId.MODE_TEXT; return mCurrentId != null ? mCurrentId.mMode : KeyboardId.MODE_TEXT;
} }
// TODO: Delegate to KeyboardState
public boolean isAlphabetMode() { public boolean isAlphabetMode() {
return mCurrentId != null && mCurrentId.isAlphabetKeyboard(); return mCurrentId != null && mCurrentId.isAlphabetKeyboard();
} }
@ -368,10 +364,17 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
if (isAlphabetMode()) { if (isAlphabetMode()) {
setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT);
} else { } else {
toggleShiftInSymbols(); if (isSymbolShifted()) {
setSymbolsKeyboard();
} else {
setSymbolsShiftedKeyboard();
}
} }
} }
/**
* Toggle caps lock state triggered by user touch event.
*/
public void toggleCapsLock() { public void toggleCapsLock() {
if (DEBUG_STATE) { if (DEBUG_STATE) {
Log.d(TAG, "toggleCapsLock: " + mState); 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() { public void toggleKeyboardMode() {
if (DEBUG_STATE) { 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()); mState.onCancelInput(isAlphabetMode(), isSymbolShifted(), isSinglePointer());
} }
// TODO: Move this variable to KeyboardState.
private boolean mPrevMainKeyboardWasShiftLocked;
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setSymbolsKeyboard() { public void setSymbolsKeyboard() {
mPrevMainKeyboardWasShiftLocked = mState.isShiftLocked(); mState.onSaveShiftLockState();
setKeyboard(getKeyboard(mSymbolsKeyboardId)); setKeyboard(getKeyboard(mSymbolsKeyboardId));
} }
@ -464,19 +471,10 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
@Override @Override
public void setAlphabetKeyboard() { public void setAlphabetKeyboard() {
setKeyboard(getKeyboard(mMainKeyboardId)); setKeyboard(getKeyboard(mMainKeyboardId));
setShiftLocked(mPrevMainKeyboardWasShiftLocked); mState.onRestoreShiftLockState();
mPrevMainKeyboardWasShiftLocked = false;
}
// TODO: Remove this method and merge into toggleKeyboardMode().
private void toggleAlphabetAndSymbols() {
if (isAlphabetMode()) {
setSymbolsKeyboard();
} else {
setAlphabetKeyboard();
}
} }
// TODO: Remove this method
private boolean isSymbolShifted() { private boolean isSymbolShifted() {
return mCurrentId != null && mCurrentId.equals(mSymbolsShiftedKeyboardId); return mCurrentId != null && mCurrentId.equals(mSymbolsShiftedKeyboardId);
} }
@ -487,15 +485,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
setKeyboard(getKeyboard(mSymbolsShiftedKeyboardId)); setKeyboard(getKeyboard(mSymbolsShiftedKeyboardId));
} }
// TODO: Remove this method and merge into toggleShift().
private void toggleShiftInSymbols() {
if (isSymbolShifted()) {
setSymbolsKeyboard();
} else {
setSymbolsShiftedKeyboard();
}
}
public boolean isInMomentarySwitchState() { public boolean isInMomentarySwitchState() {
return mState.isInMomentarySwitchState(); return mState.isInMomentarySwitchState();
} }

View File

@ -57,6 +57,7 @@ public class KeyboardState {
private final SwitchActions mSwitchActions; private final SwitchActions mSwitchActions;
private final SavedKeyboardState mSavedKeyboardState = new SavedKeyboardState(); private final SavedKeyboardState mSavedKeyboardState = new SavedKeyboardState();
private boolean mPrevMainKeyboardWasShiftLocked;
private static class SavedKeyboardState { private static class SavedKeyboardState {
public boolean mIsValid; public boolean mIsValid;
@ -75,6 +76,8 @@ public class KeyboardState {
mKeyboardShiftState.setShiftLocked(false); mKeyboardShiftState.setShiftLocked(false);
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
mSymbolKeyState.onRelease(); mSymbolKeyState.onRelease();
mPrevMainKeyboardWasShiftLocked = false;
onRestoreKeyboardState();
} }
// TODO: Get rid of isAlphabetMode and isSymbolShifted arguments. // 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; final SavedKeyboardState state = mSavedKeyboardState;
if (DEBUG_STATE) { if (DEBUG_STATE) {
Log.d(TAG, "restore: valid=" + state.mIsValid + " alphabet=" + state.mIsAlphabetMode 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() { public void onReleaseCapsLock() {
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
} }