diff options
author | 2011-12-07 12:53:51 +0900 | |
---|---|---|
committer | 2011-12-07 13:02:58 +0900 | |
commit | 2e263b70d5769b52cba4a002e44dbf81db5de7f8 (patch) | |
tree | bf63445cf590790e848294ca526446d43e8785f4 /java | |
parent | 55c0198eee18dfa4ec750d23fc589bced289d23c (diff) | |
download | latinime-2e263b70d5769b52cba4a002e44dbf81db5de7f8.tar.gz latinime-2e263b70d5769b52cba4a002e44dbf81db5de7f8.tar.xz latinime-2e263b70d5769b52cba4a002e44dbf81db5de7f8.zip |
Get rid of direct reference to KeyboardId from KeyboardLayoutState
KeyboardLayoutState.restore directly loads keyboard using private
methods such as setAlphabetKeyboard and setShifted etc. instaed of
calling public methods such as toggleCapsLock, onPressShift, and
onReleaseShift.
Bug: 5708602
Change-Id: I799f80f1d505ac7bdf17b92b189fc418994bfa2f
Diffstat (limited to 'java')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 32aabf928..27be68131 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -106,6 +106,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final KeyboardSwitcher sInstance = new KeyboardSwitcher(); + // TODO: Move this to KeyboardState. private class KeyboardLayoutState { private boolean mIsValid; private boolean mIsAlphabetMode; @@ -113,43 +114,39 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private boolean mIsShifted; public void save() { - if (mCurrentId == null) { - return; - } mIsAlphabetMode = isAlphabetMode(); if (mIsAlphabetMode) { mIsShiftLocked = mState.isShiftLocked(); mIsShifted = !mIsShiftLocked && mState.isShiftedOrShiftLocked(); } else { mIsShiftLocked = false; - mIsShifted = mCurrentId.equals(mSymbolsShiftedKeyboardId); + mIsShifted = isSymbolShifted(); } mIsValid = true; } - public KeyboardId getKeyboardId() { - if (!mIsValid) return mMainKeyboardId; - - if (mIsAlphabetMode) { - return mMainKeyboardId; - } else { - return mIsShifted ? mSymbolsShiftedKeyboardId : mSymbolsKeyboardId; + public void restore(boolean forceRestore) { + if (!mIsValid) { + if (forceRestore) { + setAlphabetKeyboard(); + } + return; } - } - - public void restore() { - if (!mIsValid) return; mIsValid = false; if (mIsAlphabetMode) { - final boolean isAlphabetMode = isAlphabetMode(); - final boolean isShiftLocked = isAlphabetMode && mState.isShiftLocked(); - final boolean isShifted = !isShiftLocked && mState.isShiftedOrShiftLocked(); - if (mIsShiftLocked != isShiftLocked) { - toggleCapsLock(); - } else if (mIsShifted != isShifted) { - onPressShift(false); - onReleaseShift(false); + setAlphabetKeyboard(); + if (mIsShiftLocked) { + setShiftLocked(true); + } + if (mIsShifted) { + setShifted(MANUAL_SHIFT); + } + } else { + if (mIsShifted) { + setSymbolsShiftedKeyboard(); + } else { + setSymbolsKeyboard(); } } } @@ -206,8 +203,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues); mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues); mLayoutSwitchBackSymbols = mResources.getString(R.string.layout_switch_back_symbols); - setKeyboard(getKeyboard(mSavedKeyboardState.getKeyboardId())); - mSavedKeyboardState.restore(); + mSavedKeyboardState.restore(mCurrentId == null); } catch (RuntimeException e) { Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e); LatinImeLogger.logOnException(mMainKeyboardId.toString(), e); @@ -215,7 +211,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } public void saveKeyboardState() { - mSavedKeyboardState.save(); + if (mCurrentId != null) { + mSavedKeyboardState.save(); + } } public void onFinishInputView() { |