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
This commit is contained in:
parent
55c0198eee
commit
2e263b70d5
1 changed files with 24 additions and 26 deletions
|
@ -106,6 +106,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
||||||
|
|
||||||
|
// TODO: Move this to KeyboardState.
|
||||||
private class KeyboardLayoutState {
|
private class KeyboardLayoutState {
|
||||||
private boolean mIsValid;
|
private boolean mIsValid;
|
||||||
private boolean mIsAlphabetMode;
|
private boolean mIsAlphabetMode;
|
||||||
|
@ -113,43 +114,39 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
private boolean mIsShifted;
|
private boolean mIsShifted;
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if (mCurrentId == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mIsAlphabetMode = isAlphabetMode();
|
mIsAlphabetMode = isAlphabetMode();
|
||||||
if (mIsAlphabetMode) {
|
if (mIsAlphabetMode) {
|
||||||
mIsShiftLocked = mState.isShiftLocked();
|
mIsShiftLocked = mState.isShiftLocked();
|
||||||
mIsShifted = !mIsShiftLocked && mState.isShiftedOrShiftLocked();
|
mIsShifted = !mIsShiftLocked && mState.isShiftedOrShiftLocked();
|
||||||
} else {
|
} else {
|
||||||
mIsShiftLocked = false;
|
mIsShiftLocked = false;
|
||||||
mIsShifted = mCurrentId.equals(mSymbolsShiftedKeyboardId);
|
mIsShifted = isSymbolShifted();
|
||||||
}
|
}
|
||||||
mIsValid = true;
|
mIsValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyboardId getKeyboardId() {
|
public void restore(boolean forceRestore) {
|
||||||
if (!mIsValid) return mMainKeyboardId;
|
if (!mIsValid) {
|
||||||
|
if (forceRestore) {
|
||||||
if (mIsAlphabetMode) {
|
setAlphabetKeyboard();
|
||||||
return mMainKeyboardId;
|
}
|
||||||
} else {
|
return;
|
||||||
return mIsShifted ? mSymbolsShiftedKeyboardId : mSymbolsKeyboardId;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void restore() {
|
|
||||||
if (!mIsValid) return;
|
|
||||||
mIsValid = false;
|
mIsValid = false;
|
||||||
|
|
||||||
if (mIsAlphabetMode) {
|
if (mIsAlphabetMode) {
|
||||||
final boolean isAlphabetMode = isAlphabetMode();
|
setAlphabetKeyboard();
|
||||||
final boolean isShiftLocked = isAlphabetMode && mState.isShiftLocked();
|
if (mIsShiftLocked) {
|
||||||
final boolean isShifted = !isShiftLocked && mState.isShiftedOrShiftLocked();
|
setShiftLocked(true);
|
||||||
if (mIsShiftLocked != isShiftLocked) {
|
}
|
||||||
toggleCapsLock();
|
if (mIsShifted) {
|
||||||
} else if (mIsShifted != isShifted) {
|
setShifted(MANUAL_SHIFT);
|
||||||
onPressShift(false);
|
}
|
||||||
onReleaseShift(false);
|
} else {
|
||||||
|
if (mIsShifted) {
|
||||||
|
setSymbolsShiftedKeyboard();
|
||||||
|
} else {
|
||||||
|
setSymbolsKeyboard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,8 +203,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues);
|
mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues);
|
||||||
mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues);
|
mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues);
|
||||||
mLayoutSwitchBackSymbols = mResources.getString(R.string.layout_switch_back_symbols);
|
mLayoutSwitchBackSymbols = mResources.getString(R.string.layout_switch_back_symbols);
|
||||||
setKeyboard(getKeyboard(mSavedKeyboardState.getKeyboardId()));
|
mSavedKeyboardState.restore(mCurrentId == null);
|
||||||
mSavedKeyboardState.restore();
|
|
||||||
} 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);
|
||||||
|
@ -215,7 +211,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveKeyboardState() {
|
public void saveKeyboardState() {
|
||||||
mSavedKeyboardState.save();
|
if (mCurrentId != null) {
|
||||||
|
mSavedKeyboardState.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFinishInputView() {
|
public void onFinishInputView() {
|
||||||
|
|
Loading…
Reference in a new issue