Loading java/src/com/android/inputmethod/keyboard/Keyboard.java +29 −22 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.text.TextUtils; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardParams; import com.android.inputmethod.keyboard.internal.KeyboardShiftState; import java.util.Collections; import java.util.HashMap; Loading Loading @@ -112,11 +111,17 @@ public class Keyboard { public final KeyboardIconsSet mIconsSet; private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>(); // TODO: Move this state to KeyboardSwitcher /* package for debug */ final KeyboardShiftState mShiftState = new KeyboardShiftState(); private final ProximityInfo mProximityInfo; // TODO: Remove these variables. private static final int UNSHIFT = 0; private static final int MANUAL_SHIFT = 1; private static final int AUTOMATIC_SHIFT = 2; private int mShiftMode; private boolean mShifted; private boolean mShiftLocked; public Keyboard(KeyboardParams params) { mId = params.mId; mThemeId = params.mThemeId; Loading Loading @@ -163,10 +168,12 @@ public class Keyboard { return null; } // TODO: Remove this method. public boolean hasShiftLockKey() { return !mShiftLockKeys.isEmpty(); } // TODO: Remove this method. public void setShiftLocked(boolean newShiftLockState) { for (final Key key : mShiftLockKeys) { // To represent "shift locked" state. The highlight is handled by background image that Loading @@ -174,47 +181,47 @@ public class Keyboard { key.setHighlightOn(newShiftLockState); key.setIcon(newShiftLockState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key)); } mShiftState.setShiftLocked(newShiftLockState); mShiftLocked = newShiftLockState; } // TODO: Move this method to KeyboardId. public boolean isShiftLocked() { return mShiftState.isShiftLocked(); return mShiftLocked; } public boolean isShiftLockShifted() { return mShiftState.isShiftLockShifted(); // TODO: Remove this method. public void setShifted(boolean newShiftState) { mShiftMode = (newShiftState ? MANUAL_SHIFT : UNSHIFT); setShiftedInternal(newShiftState); } public void setShifted(boolean newShiftState) { if (!mShiftState.isShiftLocked()) { // TODO: Remove this method private void setShiftedInternal(boolean newShiftState) { if (!mShiftLocked) { for (final Key key : mShiftKeys) { key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key)); } } mShiftState.setShifted(newShiftState); mShifted = newShiftState; } // TODO: Move this method to KeyboardId. public boolean isShiftedOrShiftLocked() { return mShiftState.isShiftedOrShiftLocked(); return mShifted || mShiftLocked; } // TODO: Remove this method public void setAutomaticTemporaryUpperCase() { setShifted(true); mShiftState.setAutomaticTemporaryUpperCase(); } public boolean isAutomaticTemporaryUpperCase() { return mId.isAlphabetKeyboard() && mShiftState.isAutomaticTemporaryUpperCase(); mShiftMode = AUTOMATIC_SHIFT; setShiftedInternal(true); } // TODO: Move this method to KeyboardId. public boolean isManualTemporaryUpperCase() { return mId.isAlphabetKeyboard() && mShiftState.isManualTemporaryUpperCase(); } public boolean isManualTemporaryUpperCaseFromAuto() { return mId.isAlphabetKeyboard() && mShiftState.isManualTemporaryUpperCaseFromAuto(); return mShiftMode == MANUAL_SHIFT; } // TODO: Remove this method. public CharSequence adjustLabelCase(CharSequence label) { if (isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { Loading java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +46 −93 Original line number Diff line number Diff line Loading @@ -118,8 +118,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } mIsAlphabetMode = isAlphabetMode(); if (mIsAlphabetMode) { mIsShiftLocked = isShiftLocked(); mIsShifted = !mIsShiftLocked && isShiftedOrShiftLocked(); mIsShiftLocked = mState.isShiftLocked(); mIsShifted = !mIsShiftLocked && mState.isShiftedOrShiftLocked(); } else { mIsShiftLocked = false; mIsShifted = mCurrentId.equals(mSymbolsShiftedKeyboardId); Loading @@ -143,8 +143,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (mIsAlphabetMode) { final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isAlphabetMode && isShiftLocked(); final boolean isShifted = !isShiftLocked && isShiftedOrShiftLocked(); final boolean isShiftLocked = isAlphabetMode && mState.isShiftLocked(); final boolean isShifted = !isShiftLocked && mState.isShiftedOrShiftLocked(); if (mIsShiftLocked != isShiftLocked) { toggleCapsLock(); } else if (mIsShifted != isShifted) { Loading Loading @@ -252,10 +252,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked() // that takes care of the current keyboard having such ALT key or not. keyboard.setShiftLocked(keyboard.hasShiftLockKey()); mState.setShiftLocked(keyboard.hasShiftLockKey()); } else if (mCurrentId.equals(mSymbolsKeyboardId)) { // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the // indicator, we need to call setShiftLocked(false). keyboard.setShiftLocked(false); mState.setShiftLocked(false); } } Loading Loading @@ -374,52 +376,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } public boolean isShiftedOrShiftLocked() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isShiftedOrShiftLocked(); return false; } public boolean isShiftLocked() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isShiftLocked(); return false; } private boolean isShiftLockShifted() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isShiftLockShifted(); return false; } private boolean isAutomaticTemporaryUpperCase() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isAutomaticTemporaryUpperCase(); return false; return mState.isShiftedOrShiftLocked(); } public boolean isManualTemporaryUpperCase() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isManualTemporaryUpperCase(); return false; } private boolean isManualTemporaryUpperCaseFromAuto() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isManualTemporaryUpperCaseFromAuto(); return false; return mState.isManualTemporaryUpperCase(); } private void setShift(int shiftMode) { private void setShifted(int shiftMode) { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard == null) return; if (shiftMode == AUTOMATIC_SHIFT) { mState.setAutomaticTemporaryUpperCase(); latinKeyboard.setAutomaticTemporaryUpperCase(); } else { final boolean shifted = (shiftMode == MANUAL_SHIFT); Loading @@ -428,8 +397,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // On the other hand, on distinct multi touch panel device, turning off the shift // locked state with shift key pressing is handled by onReleaseShift(). if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) { mState.setShiftLocked(false); latinKeyboard.setShiftLocked(false); } mState.setShifted(shifted); latinKeyboard.setShifted(shifted); } mKeyboardView.invalidateAllKeys(); Loading @@ -437,11 +408,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private void setShiftLocked(boolean shiftLocked) { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) { if (latinKeyboard == null) return; mState.setShiftLocked(shiftLocked); latinKeyboard.setShiftLocked(shiftLocked); mKeyboardView.invalidateAllKeys(); } } /** * Toggle keyboard shift state triggered by user touch event. Loading @@ -449,12 +421,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void toggleShift() { mInputMethodService.mHandler.cancelUpdateShiftState(); if (DEBUG_STATE) { Log.d(TAG, "toggleShift:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "toggleShift: " + mState); } if (isAlphabetMode()) { setShift(isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); } else { toggleShiftInSymbol(); } Loading @@ -463,12 +433,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void toggleCapsLock() { mInputMethodService.mHandler.cancelUpdateShiftState(); if (DEBUG_STATE) { Log.d(TAG, "toggleCapsLock:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "toggleCapsLock: " + mState); } if (isAlphabetMode()) { if (isShiftLocked()) { if (mState.isShiftLocked()) { // Shift key is long pressed while caps lock state, we will toggle back to normal // state. And mark as if shift key is released. setShiftLocked(false); Loading @@ -481,12 +449,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void changeKeyboardMode() { if (DEBUG_STATE) { Log.d(TAG, "changeKeyboardMode:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "changeKeyboardMode: " + mState); } toggleKeyboardMode(); if (isShiftLocked() && isAlphabetMode()) { if (mState.isShiftLocked() && isAlphabetMode()) { setShiftLocked(true); } updateShiftState(); Loading @@ -502,23 +468,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha * Update keyboard shift state triggered by connected EditText status change. */ public void updateShiftState() { final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isShiftLocked(); if (DEBUG_STATE) { Log.d(TAG, "updateShiftState:" + " autoCaps=" + mInputMethodService.getCurrentAutoCapsState() + " keyboard=" + getLatinKeyboard().mShiftState + " isAlphabetMode=" + isAlphabetMode + " isShiftLocked=" + isShiftLocked + " state=" + mState); Log.d(TAG, "updateShiftState: " + mState + " autoCaps=" + mInputMethodService.getCurrentAutoCapsState()); } final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = mState.isShiftLocked(); if (isAlphabetMode) { if (!isShiftLocked && !mState.isShiftKeyIgnoring()) { if (mState.isShiftKeyReleasing() && mInputMethodService.getCurrentAutoCapsState()) { // Only when shift key is releasing, automatic temporary upper case will be set. setShift(AUTOMATIC_SHIFT); setShifted(AUTOMATIC_SHIFT); } else { setShift(mState.isShiftKeyMomentary() ? MANUAL_SHIFT : UNSHIFT); setShifted(mState.isShiftKeyMomentary() ? MANUAL_SHIFT : UNSHIFT); } } } Loading @@ -529,23 +491,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (!isKeyboardAvailable()) return; if (DEBUG_STATE) { Log.d(TAG, "onPressShift:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState + " sliding=" + withSliding); Log.d(TAG, "onPressShift: " + mState + " sliding=" + withSliding); } final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isShiftLocked(); final boolean isAutomaticTemporaryUpperCase = isAutomaticTemporaryUpperCase(); final boolean isShiftedOrShiftLocked = isShiftedOrShiftLocked(); final boolean isShiftLocked = mState.isShiftLocked(); final boolean isAutomaticTemporaryUpperCase = mState.isAutomaticTemporaryUpperCase(); final boolean isShiftedOrShiftLocked = mState.isShiftedOrShiftLocked(); if (isAlphabetMode) { if (isShiftLocked) { // Shift key is pressed while caps lock state, we will treat this state as shifted // caps lock state and mark as if shift key pressed while normal state. setShift(MANUAL_SHIFT); setShifted(MANUAL_SHIFT); } else if (isAutomaticTemporaryUpperCase) { // Shift key is pressed while automatic temporary upper case, we have to move to // manual temporary upper case. setShift(MANUAL_SHIFT); setShifted(MANUAL_SHIFT); } else if (isShiftedOrShiftLocked) { // In manual upper case state, we just record shift key has been pressing while // shifted state. Loading @@ -566,15 +526,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (!isKeyboardAvailable()) return; if (DEBUG_STATE) { Log.d(TAG, "onReleaseShift:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState + " sliding=" + withSliding); Log.d(TAG, "onReleaseShift: " + mState + " sliding=" + withSliding); } final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isShiftLocked(); final boolean isShiftLockShifted = isShiftLockShifted(); final boolean isShiftedOrShiftLocked = isShiftedOrShiftLocked(); final boolean isManualTemporaryUpperCaseFromAuto = isManualTemporaryUpperCaseFromAuto(); final boolean isShiftLocked = mState.isShiftLocked(); final boolean isShiftLockShifted = mState.isShiftLockShifted(); final boolean isShiftedOrShiftLocked = mState.isShiftedOrShiftLocked(); final boolean isManualTemporaryUpperCaseFromAuto = mState.isManualTemporaryUpperCaseFromAuto(); if (isAlphabetMode) { if (mState.isShiftKeyMomentary()) { // After chording input while normal state. Loading Loading @@ -611,9 +570,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onPressSymbol() { if (DEBUG_STATE) { Log.d(TAG, "onPressSymbol:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "onPressSymbol: " + mState); } changeKeyboardMode(); mState.onPressSymbol(); Loading @@ -622,9 +579,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onReleaseSymbol() { if (DEBUG_STATE) { Log.d(TAG, "onReleaseSymbol:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "onReleaseSymbol: " + mState); } // Snap back to the previous keyboard mode if the user chords the mode change key and // another key, then releases the mode change key. Loading @@ -636,9 +591,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onOtherKeyPressed() { if (DEBUG_STATE) { Log.d(TAG, "onOtherKeyPressed:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "onOtherKeyPressed: " + mState); } mState.onOtherKeyPressed(); } Loading @@ -658,7 +611,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private void toggleKeyboardMode() { if (mCurrentId.equals(mMainKeyboardId)) { mPrevMainKeyboardWasShiftLocked = isShiftLocked(); mPrevMainKeyboardWasShiftLocked = mState.isShiftLocked(); setKeyboard(getKeyboard(mSymbolsKeyboardId)); } else { setKeyboard(getKeyboard(mMainKeyboardId)); Loading java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ import android.util.Log; import com.android.inputmethod.keyboard.KeyboardSwitcher; public class KeyboardShiftState { /* package */ class KeyboardShiftState { private static final String TAG = KeyboardShiftState.class.getSimpleName(); private static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE; Loading java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +43 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard.internal; // TODO: Add unit tests public class KeyboardState { private KeyboardShiftState mKeyboardShiftState = new KeyboardShiftState(); // TODO: Combine these key state objects with auto mode switch state. private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift"); private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol"); Loading @@ -25,6 +27,45 @@ public class KeyboardState { public KeyboardState() { } public boolean isShiftLocked() { return mKeyboardShiftState.isShiftLocked(); } public boolean isShiftLockShifted() { return mKeyboardShiftState.isShiftLockShifted(); } public boolean isShiftedOrShiftLocked() { return mKeyboardShiftState.isShiftedOrShiftLocked(); } public boolean isAutomaticTemporaryUpperCase() { return mKeyboardShiftState.isAutomaticTemporaryUpperCase(); } public boolean isManualTemporaryUpperCase() { return mKeyboardShiftState.isManualTemporaryUpperCase(); } public boolean isManualTemporaryUpperCaseFromAuto() { return mKeyboardShiftState.isManualTemporaryUpperCaseFromAuto(); } // TODO: Get rid of this method public void setShifted(boolean shifted) { mKeyboardShiftState.setShifted(shifted); } // TODO: Get rid of this method public void setShiftLocked(boolean shiftLocked) { mKeyboardShiftState.setShiftLocked(shiftLocked); } // TODO: Get rid of this method public void setAutomaticTemporaryUpperCase() { mKeyboardShiftState.setAutomaticTemporaryUpperCase(); } // TODO: Get rid of this method public boolean isShiftKeyIgnoring() { return mShiftKeyState.isIgnoring(); Loading Loading @@ -107,7 +148,8 @@ public class KeyboardState { @Override public String toString() { return "[shift=" + mShiftKeyState return "[keyboard=" + mKeyboardShiftState + " shift=" + mShiftKeyState + " symbol=" + mSymbolKeyState + "]"; } } Loading
java/src/com/android/inputmethod/keyboard/Keyboard.java +29 −22 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.text.TextUtils; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardParams; import com.android.inputmethod.keyboard.internal.KeyboardShiftState; import java.util.Collections; import java.util.HashMap; Loading Loading @@ -112,11 +111,17 @@ public class Keyboard { public final KeyboardIconsSet mIconsSet; private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>(); // TODO: Move this state to KeyboardSwitcher /* package for debug */ final KeyboardShiftState mShiftState = new KeyboardShiftState(); private final ProximityInfo mProximityInfo; // TODO: Remove these variables. private static final int UNSHIFT = 0; private static final int MANUAL_SHIFT = 1; private static final int AUTOMATIC_SHIFT = 2; private int mShiftMode; private boolean mShifted; private boolean mShiftLocked; public Keyboard(KeyboardParams params) { mId = params.mId; mThemeId = params.mThemeId; Loading Loading @@ -163,10 +168,12 @@ public class Keyboard { return null; } // TODO: Remove this method. public boolean hasShiftLockKey() { return !mShiftLockKeys.isEmpty(); } // TODO: Remove this method. public void setShiftLocked(boolean newShiftLockState) { for (final Key key : mShiftLockKeys) { // To represent "shift locked" state. The highlight is handled by background image that Loading @@ -174,47 +181,47 @@ public class Keyboard { key.setHighlightOn(newShiftLockState); key.setIcon(newShiftLockState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key)); } mShiftState.setShiftLocked(newShiftLockState); mShiftLocked = newShiftLockState; } // TODO: Move this method to KeyboardId. public boolean isShiftLocked() { return mShiftState.isShiftLocked(); return mShiftLocked; } public boolean isShiftLockShifted() { return mShiftState.isShiftLockShifted(); // TODO: Remove this method. public void setShifted(boolean newShiftState) { mShiftMode = (newShiftState ? MANUAL_SHIFT : UNSHIFT); setShiftedInternal(newShiftState); } public void setShifted(boolean newShiftState) { if (!mShiftState.isShiftLocked()) { // TODO: Remove this method private void setShiftedInternal(boolean newShiftState) { if (!mShiftLocked) { for (final Key key : mShiftKeys) { key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key)); } } mShiftState.setShifted(newShiftState); mShifted = newShiftState; } // TODO: Move this method to KeyboardId. public boolean isShiftedOrShiftLocked() { return mShiftState.isShiftedOrShiftLocked(); return mShifted || mShiftLocked; } // TODO: Remove this method public void setAutomaticTemporaryUpperCase() { setShifted(true); mShiftState.setAutomaticTemporaryUpperCase(); } public boolean isAutomaticTemporaryUpperCase() { return mId.isAlphabetKeyboard() && mShiftState.isAutomaticTemporaryUpperCase(); mShiftMode = AUTOMATIC_SHIFT; setShiftedInternal(true); } // TODO: Move this method to KeyboardId. public boolean isManualTemporaryUpperCase() { return mId.isAlphabetKeyboard() && mShiftState.isManualTemporaryUpperCase(); } public boolean isManualTemporaryUpperCaseFromAuto() { return mId.isAlphabetKeyboard() && mShiftState.isManualTemporaryUpperCaseFromAuto(); return mShiftMode == MANUAL_SHIFT; } // TODO: Remove this method. public CharSequence adjustLabelCase(CharSequence label) { if (isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { Loading
java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +46 −93 Original line number Diff line number Diff line Loading @@ -118,8 +118,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } mIsAlphabetMode = isAlphabetMode(); if (mIsAlphabetMode) { mIsShiftLocked = isShiftLocked(); mIsShifted = !mIsShiftLocked && isShiftedOrShiftLocked(); mIsShiftLocked = mState.isShiftLocked(); mIsShifted = !mIsShiftLocked && mState.isShiftedOrShiftLocked(); } else { mIsShiftLocked = false; mIsShifted = mCurrentId.equals(mSymbolsShiftedKeyboardId); Loading @@ -143,8 +143,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (mIsAlphabetMode) { final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isAlphabetMode && isShiftLocked(); final boolean isShifted = !isShiftLocked && isShiftedOrShiftLocked(); final boolean isShiftLocked = isAlphabetMode && mState.isShiftLocked(); final boolean isShifted = !isShiftLocked && mState.isShiftedOrShiftLocked(); if (mIsShiftLocked != isShiftLocked) { toggleCapsLock(); } else if (mIsShifted != isShifted) { Loading Loading @@ -252,10 +252,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked() // that takes care of the current keyboard having such ALT key or not. keyboard.setShiftLocked(keyboard.hasShiftLockKey()); mState.setShiftLocked(keyboard.hasShiftLockKey()); } else if (mCurrentId.equals(mSymbolsKeyboardId)) { // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the // indicator, we need to call setShiftLocked(false). keyboard.setShiftLocked(false); mState.setShiftLocked(false); } } Loading Loading @@ -374,52 +376,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } public boolean isShiftedOrShiftLocked() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isShiftedOrShiftLocked(); return false; } public boolean isShiftLocked() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isShiftLocked(); return false; } private boolean isShiftLockShifted() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isShiftLockShifted(); return false; } private boolean isAutomaticTemporaryUpperCase() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isAutomaticTemporaryUpperCase(); return false; return mState.isShiftedOrShiftLocked(); } public boolean isManualTemporaryUpperCase() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isManualTemporaryUpperCase(); return false; } private boolean isManualTemporaryUpperCaseFromAuto() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) return latinKeyboard.isManualTemporaryUpperCaseFromAuto(); return false; return mState.isManualTemporaryUpperCase(); } private void setShift(int shiftMode) { private void setShifted(int shiftMode) { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard == null) return; if (shiftMode == AUTOMATIC_SHIFT) { mState.setAutomaticTemporaryUpperCase(); latinKeyboard.setAutomaticTemporaryUpperCase(); } else { final boolean shifted = (shiftMode == MANUAL_SHIFT); Loading @@ -428,8 +397,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // On the other hand, on distinct multi touch panel device, turning off the shift // locked state with shift key pressing is handled by onReleaseShift(). if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) { mState.setShiftLocked(false); latinKeyboard.setShiftLocked(false); } mState.setShifted(shifted); latinKeyboard.setShifted(shifted); } mKeyboardView.invalidateAllKeys(); Loading @@ -437,11 +408,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private void setShiftLocked(boolean shiftLocked) { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) { if (latinKeyboard == null) return; mState.setShiftLocked(shiftLocked); latinKeyboard.setShiftLocked(shiftLocked); mKeyboardView.invalidateAllKeys(); } } /** * Toggle keyboard shift state triggered by user touch event. Loading @@ -449,12 +421,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void toggleShift() { mInputMethodService.mHandler.cancelUpdateShiftState(); if (DEBUG_STATE) { Log.d(TAG, "toggleShift:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "toggleShift: " + mState); } if (isAlphabetMode()) { setShift(isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); } else { toggleShiftInSymbol(); } Loading @@ -463,12 +433,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void toggleCapsLock() { mInputMethodService.mHandler.cancelUpdateShiftState(); if (DEBUG_STATE) { Log.d(TAG, "toggleCapsLock:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "toggleCapsLock: " + mState); } if (isAlphabetMode()) { if (isShiftLocked()) { if (mState.isShiftLocked()) { // Shift key is long pressed while caps lock state, we will toggle back to normal // state. And mark as if shift key is released. setShiftLocked(false); Loading @@ -481,12 +449,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void changeKeyboardMode() { if (DEBUG_STATE) { Log.d(TAG, "changeKeyboardMode:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "changeKeyboardMode: " + mState); } toggleKeyboardMode(); if (isShiftLocked() && isAlphabetMode()) { if (mState.isShiftLocked() && isAlphabetMode()) { setShiftLocked(true); } updateShiftState(); Loading @@ -502,23 +468,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha * Update keyboard shift state triggered by connected EditText status change. */ public void updateShiftState() { final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isShiftLocked(); if (DEBUG_STATE) { Log.d(TAG, "updateShiftState:" + " autoCaps=" + mInputMethodService.getCurrentAutoCapsState() + " keyboard=" + getLatinKeyboard().mShiftState + " isAlphabetMode=" + isAlphabetMode + " isShiftLocked=" + isShiftLocked + " state=" + mState); Log.d(TAG, "updateShiftState: " + mState + " autoCaps=" + mInputMethodService.getCurrentAutoCapsState()); } final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = mState.isShiftLocked(); if (isAlphabetMode) { if (!isShiftLocked && !mState.isShiftKeyIgnoring()) { if (mState.isShiftKeyReleasing() && mInputMethodService.getCurrentAutoCapsState()) { // Only when shift key is releasing, automatic temporary upper case will be set. setShift(AUTOMATIC_SHIFT); setShifted(AUTOMATIC_SHIFT); } else { setShift(mState.isShiftKeyMomentary() ? MANUAL_SHIFT : UNSHIFT); setShifted(mState.isShiftKeyMomentary() ? MANUAL_SHIFT : UNSHIFT); } } } Loading @@ -529,23 +491,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (!isKeyboardAvailable()) return; if (DEBUG_STATE) { Log.d(TAG, "onPressShift:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState + " sliding=" + withSliding); Log.d(TAG, "onPressShift: " + mState + " sliding=" + withSliding); } final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isShiftLocked(); final boolean isAutomaticTemporaryUpperCase = isAutomaticTemporaryUpperCase(); final boolean isShiftedOrShiftLocked = isShiftedOrShiftLocked(); final boolean isShiftLocked = mState.isShiftLocked(); final boolean isAutomaticTemporaryUpperCase = mState.isAutomaticTemporaryUpperCase(); final boolean isShiftedOrShiftLocked = mState.isShiftedOrShiftLocked(); if (isAlphabetMode) { if (isShiftLocked) { // Shift key is pressed while caps lock state, we will treat this state as shifted // caps lock state and mark as if shift key pressed while normal state. setShift(MANUAL_SHIFT); setShifted(MANUAL_SHIFT); } else if (isAutomaticTemporaryUpperCase) { // Shift key is pressed while automatic temporary upper case, we have to move to // manual temporary upper case. setShift(MANUAL_SHIFT); setShifted(MANUAL_SHIFT); } else if (isShiftedOrShiftLocked) { // In manual upper case state, we just record shift key has been pressing while // shifted state. Loading @@ -566,15 +526,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (!isKeyboardAvailable()) return; if (DEBUG_STATE) { Log.d(TAG, "onReleaseShift:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState + " sliding=" + withSliding); Log.d(TAG, "onReleaseShift: " + mState + " sliding=" + withSliding); } final boolean isAlphabetMode = isAlphabetMode(); final boolean isShiftLocked = isShiftLocked(); final boolean isShiftLockShifted = isShiftLockShifted(); final boolean isShiftedOrShiftLocked = isShiftedOrShiftLocked(); final boolean isManualTemporaryUpperCaseFromAuto = isManualTemporaryUpperCaseFromAuto(); final boolean isShiftLocked = mState.isShiftLocked(); final boolean isShiftLockShifted = mState.isShiftLockShifted(); final boolean isShiftedOrShiftLocked = mState.isShiftedOrShiftLocked(); final boolean isManualTemporaryUpperCaseFromAuto = mState.isManualTemporaryUpperCaseFromAuto(); if (isAlphabetMode) { if (mState.isShiftKeyMomentary()) { // After chording input while normal state. Loading Loading @@ -611,9 +570,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onPressSymbol() { if (DEBUG_STATE) { Log.d(TAG, "onPressSymbol:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "onPressSymbol: " + mState); } changeKeyboardMode(); mState.onPressSymbol(); Loading @@ -622,9 +579,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onReleaseSymbol() { if (DEBUG_STATE) { Log.d(TAG, "onReleaseSymbol:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "onReleaseSymbol: " + mState); } // Snap back to the previous keyboard mode if the user chords the mode change key and // another key, then releases the mode change key. Loading @@ -636,9 +591,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onOtherKeyPressed() { if (DEBUG_STATE) { Log.d(TAG, "onOtherKeyPressed:" + " keyboard=" + getLatinKeyboard().mShiftState + " state=" + mState); Log.d(TAG, "onOtherKeyPressed: " + mState); } mState.onOtherKeyPressed(); } Loading @@ -658,7 +611,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private void toggleKeyboardMode() { if (mCurrentId.equals(mMainKeyboardId)) { mPrevMainKeyboardWasShiftLocked = isShiftLocked(); mPrevMainKeyboardWasShiftLocked = mState.isShiftLocked(); setKeyboard(getKeyboard(mSymbolsKeyboardId)); } else { setKeyboard(getKeyboard(mMainKeyboardId)); Loading
java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ import android.util.Log; import com.android.inputmethod.keyboard.KeyboardSwitcher; public class KeyboardShiftState { /* package */ class KeyboardShiftState { private static final String TAG = KeyboardShiftState.class.getSimpleName(); private static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE; Loading
java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +43 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard.internal; // TODO: Add unit tests public class KeyboardState { private KeyboardShiftState mKeyboardShiftState = new KeyboardShiftState(); // TODO: Combine these key state objects with auto mode switch state. private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift"); private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol"); Loading @@ -25,6 +27,45 @@ public class KeyboardState { public KeyboardState() { } public boolean isShiftLocked() { return mKeyboardShiftState.isShiftLocked(); } public boolean isShiftLockShifted() { return mKeyboardShiftState.isShiftLockShifted(); } public boolean isShiftedOrShiftLocked() { return mKeyboardShiftState.isShiftedOrShiftLocked(); } public boolean isAutomaticTemporaryUpperCase() { return mKeyboardShiftState.isAutomaticTemporaryUpperCase(); } public boolean isManualTemporaryUpperCase() { return mKeyboardShiftState.isManualTemporaryUpperCase(); } public boolean isManualTemporaryUpperCaseFromAuto() { return mKeyboardShiftState.isManualTemporaryUpperCaseFromAuto(); } // TODO: Get rid of this method public void setShifted(boolean shifted) { mKeyboardShiftState.setShifted(shifted); } // TODO: Get rid of this method public void setShiftLocked(boolean shiftLocked) { mKeyboardShiftState.setShiftLocked(shiftLocked); } // TODO: Get rid of this method public void setAutomaticTemporaryUpperCase() { mKeyboardShiftState.setAutomaticTemporaryUpperCase(); } // TODO: Get rid of this method public boolean isShiftKeyIgnoring() { return mShiftKeyState.isIgnoring(); Loading Loading @@ -107,7 +148,8 @@ public class KeyboardState { @Override public String toString() { return "[shift=" + mShiftKeyState return "[keyboard=" + mKeyboardShiftState + " shift=" + mShiftKeyState + " symbol=" + mSymbolKeyState + "]"; } }