aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-12-08 05:55:16 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-12-08 05:55:16 -0800
commitd52e76053031f282279112fbc6136bb9ccd643a6 (patch)
treebc4d530ad41cf56737711fb49aa3088a5176fbd3 /java/src
parent92e5756dfb4c2d5f0ebd2da53ba1a8fd9f633721 (diff)
parent6ad9b012d947458155609e418aaeb3904cf27f6f (diff)
downloadlatinime-d52e76053031f282279112fbc6136bb9ccd643a6.tar.gz
latinime-d52e76053031f282279112fbc6136bb9ccd643a6.tar.xz
latinime-d52e76053031f282279112fbc6136bb9ccd643a6.zip
Merge "Cleanup KeyboardSwitcher a bit"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java53
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java15
2 files changed, 35 insertions, 33 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index d38f25496..734189689 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -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();
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index ee5ef9164..95c9162ef 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -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();
}