diff options
Diffstat (limited to 'java/src')
10 files changed, 169 insertions, 194 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 164d2b748..f476d83b4 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -50,20 +50,20 @@ public class SuggestionSpanUtils { .getConstructor(CLASS_SuggestionSpan, INPUT_TYPE_SuggestionSpan); public static final Field FIELD_FLAG_AUTO_CORRECTION = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_AUTO_CORRECTION"); - public static final Field FIELD_SUGGESTION_MAX_SIZE - = CompatUtils.getField(CLASS_SuggestionSpan, "SUGGESTION_MAX_SIZE"); + public static final Field FIELD_SUGGESTIONS_MAX_SIZE + = CompatUtils.getField(CLASS_SuggestionSpan, "SUGGESTIONS_MAX_SIZE"); public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION);; - public static final Integer OBJ_SUGGESTION_MAX_SIZE = (Integer) CompatUtils - .getFieldValue(null, null, FIELD_SUGGESTION_MAX_SIZE);; + public static final Integer OBJ_SUGGESTIONS_MAX_SIZE = (Integer) CompatUtils + .getFieldValue(null, null, FIELD_SUGGESTIONS_MAX_SIZE);; static { SUGGESTION_SPAN_IS_SUPPORTED = CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null; if (LatinImeLogger.sDBG) { if (SUGGESTION_SPAN_IS_SUPPORTED - && (OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTION_MAX_SIZE == null)) { - Log.e(TAG, "Field is accidentially null."); + && (OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null)) { + throw new RuntimeException("Field is accidentially null."); } } } @@ -71,7 +71,7 @@ public class SuggestionSpanUtils { public static CharSequence getTextWithAutoCorrectionIndicatorUnderline( Context context, CharSequence text) { if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null - || OBJ_FLAG_AUTO_CORRECTION == null) { + || OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null) { return text; } final Spannable spannable = text instanceof Spannable @@ -94,7 +94,7 @@ public class SuggestionSpanUtils { if (TextUtils.isEmpty(pickedWord) || CONSTRUCTOR_SuggestionSpan == null || suggestedWords == null || suggestedWords.size() == 0 || suggestedWords.getInfo(0).isObsoleteSuggestedWord() - || OBJ_SUGGESTION_MAX_SIZE == null) { + || OBJ_SUGGESTIONS_MAX_SIZE == null) { return pickedWord; } @@ -106,7 +106,7 @@ public class SuggestionSpanUtils { } final ArrayList<String> suggestionsList = new ArrayList<String>(); for (int i = 0; i < suggestedWords.size(); ++i) { - if (suggestionsList.size() >= OBJ_SUGGESTION_MAX_SIZE) { + if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) { break; } final CharSequence word = suggestedWords.getWord(i); diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index b3b20ca21..2bc140ed5 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -112,10 +112,12 @@ public class Keyboard { public final KeyboardIconsSet mIconsSet; private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>(); - private final KeyboardShiftState mShiftState = new KeyboardShiftState(); private final ProximityInfo mProximityInfo; + // TODO: Remove this variable. + private final KeyboardShiftState mShiftState = new KeyboardShiftState(); + public Keyboard(KeyboardParams params) { mId = params.mId; mThemeId = params.mThemeId; @@ -162,78 +164,53 @@ public class Keyboard { return null; } + // TODO: Remove this method. public boolean hasShiftLockKey() { return !mShiftLockKeys.isEmpty(); } - public boolean setShiftLocked(boolean newShiftLockState) { + // 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 // might be a StateListDrawable. key.setHighlightOn(newShiftLockState); - // To represent "shifted" state. The key might have a shifted icon. - if (newShiftLockState && mShiftedIcons.containsKey(key)) { - key.setIcon(mShiftedIcons.get(key)); - } else { - key.setIcon(mUnshiftedIcons.get(key)); - } + key.setIcon(newShiftLockState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key)); } mShiftState.setShiftLocked(newShiftLockState); - return true; } + // TODO: Move this method to KeyboardId. public boolean isShiftLocked() { return mShiftState.isShiftLocked(); } - public boolean isShiftLockShifted() { - return mShiftState.isShiftLockShifted(); - } - - public boolean setShifted(boolean newShiftState) { - for (final Key key : mShiftKeys) { - if (!newShiftState && !mShiftState.isShiftLocked()) { - key.setIcon(mUnshiftedIcons.get(key)); - } else if (newShiftState && !mShiftState.isShiftedOrShiftLocked()) { - key.setIcon(mShiftedIcons.get(key)); + // TODO: Remove this method. + public void setShifted(boolean newShiftState) { + if (!mShiftState.isShiftLocked()) { + for (final Key key : mShiftKeys) { + key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key)); } } - return mShiftState.setShifted(newShiftState); + mShiftState.setShifted(newShiftState); } + // TODO: Move this method to KeyboardId. public boolean isShiftedOrShiftLocked() { return mShiftState.isShiftedOrShiftLocked(); } + // TODO: Remove this method public void setAutomaticTemporaryUpperCase() { - setShifted(true); mShiftState.setAutomaticTemporaryUpperCase(); } - public boolean isAutomaticTemporaryUpperCase() { - return isAlphaKeyboard() && mShiftState.isAutomaticTemporaryUpperCase(); - } - + // TODO: Move this method to KeyboardId. public boolean isManualTemporaryUpperCase() { - return isAlphaKeyboard() && mShiftState.isManualTemporaryUpperCase(); - } - - public boolean isManualTemporaryUpperCaseFromAuto() { - return isAlphaKeyboard() && mShiftState.isManualTemporaryUpperCaseFromAuto(); - } - - public KeyboardShiftState getKeyboardShiftState() { - return mShiftState; - } - - public boolean isAlphaKeyboard() { - return mId.isAlphabetKeyboard(); - } - - public boolean isPhoneKeyboard() { - return mId.isPhoneKeyboard(); + return mShiftState.isManualTemporaryUpperCase(); } + // TODO: Remove this method. public CharSequence adjustLabelCase(CharSequence label) { if (isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 19bfef38a..32aabf928 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -99,7 +99,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final int SWITCH_STATE_CHORDING_SYMBOL = 6; private int mSwitchState = SWITCH_STATE_ALPHA; - private static String mLayoutSwitchBackSymbols; + private String mLayoutSwitchBackSymbols; private int mThemeIndex = -1; private Context mThemeContext; @@ -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); @@ -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) { @@ -231,7 +231,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mKeyboardView.setKeyboard(keyboard); mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding); mCurrentId = keyboard.mId; - mSwitchState = getSwitchState(mCurrentId); + mSwitchState = getSwitchState(); updateShiftLockState(keyboard); mKeyboardView.setKeyPreviewPopupEnabled( Settings.Values.isKeyPreviewPopupEnabled(mPrefs, mResources), @@ -242,8 +242,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha updateShiftState(); } - private int getSwitchState(KeyboardId id) { - return id.equals(mMainKeyboardId) ? SWITCH_STATE_ALPHA : SWITCH_STATE_SYMBOL_BEGIN; + private int getSwitchState() { + return isAlphabetMode() ? SWITCH_STATE_ALPHA : SWITCH_STATE_SYMBOL_BEGIN; } private void updateShiftLockState(Keyboard keyboard) { @@ -374,54 +374,20 @@ 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; + return mState.isManualTemporaryUpperCase(); } - private boolean isManualTemporaryUpperCaseFromAuto() { - LatinKeyboard latinKeyboard = getLatinKeyboard(); - if (latinKeyboard != null) - return latinKeyboard.isManualTemporaryUpperCaseFromAuto(); - return false; - } - - 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(); - mKeyboardView.invalidateAllKeys(); } else { final boolean shifted = (shiftMode == MANUAL_SHIFT); // On non-distinct multi touch panel device, we should also turn off the shift locked @@ -429,19 +395,22 @@ 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); } - if (latinKeyboard.setShifted(shifted)) { - mKeyboardView.invalidateAllKeys(); - } + mState.setShifted(shifted); + latinKeyboard.setShifted(shifted); } + mKeyboardView.invalidateAllKeys(); } private void setShiftLocked(boolean shiftLocked) { LatinKeyboard latinKeyboard = getLatinKeyboard(); - if (latinKeyboard != null && latinKeyboard.setShiftLocked(shiftLocked)) { - mKeyboardView.invalidateAllKeys(); - } + if (latinKeyboard == null) + return; + mState.setShiftLocked(shiftLocked); + latinKeyboard.setShiftLocked(shiftLocked); + mKeyboardView.invalidateAllKeys(); } /** @@ -450,26 +419,22 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void toggleShift() { mInputMethodService.mHandler.cancelUpdateShiftState(); if (DEBUG_STATE) { - Log.d(TAG, "toggleShift:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " state=" + mState); + Log.d(TAG, "toggleShift: " + mState); } if (isAlphabetMode()) { - setShift(isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); + setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT); } else { - toggleShiftInSymbol(); + toggleShiftInSymbols(); } } public void toggleCapsLock() { mInputMethodService.mHandler.cancelUpdateShiftState(); if (DEBUG_STATE) { - Log.d(TAG, "toggleCapsLock:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " 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); @@ -480,17 +445,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - public void changeKeyboardMode() { + public void toggleKeyboardMode() { if (DEBUG_STATE) { - Log.d(TAG, "changeKeyboardMode:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " state=" + mState); - } - toggleKeyboardMode(); - if (isShiftLocked() && isAlphabetMode()) { - setShiftLocked(true); + Log.d(TAG, "toggleKeyboard: " + mState); } - updateShiftState(); + toggleAlphabetAndSymbols(); } private void startIgnoringDoubleTap() { @@ -503,23 +462,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().getKeyboardShiftState() - + " 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); } } } @@ -530,23 +485,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (!isKeyboardAvailable()) return; if (DEBUG_STATE) { - Log.d(TAG, "onPressShift:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " 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. @@ -556,7 +509,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } else { // In symbol mode, just toggle symbol and symbol more keyboard. - toggleShift(); + toggleShiftInSymbols(); mSwitchState = SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE; } mState.onPressShift(isAlphabetMode, isShiftLocked, isAutomaticTemporaryUpperCase, @@ -567,15 +520,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (!isKeyboardAvailable()) return; if (DEBUG_STATE) { - Log.d(TAG, "onReleaseShift:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " 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. @@ -604,7 +556,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // In symbol mode, snap back to the previous keyboard mode if the user chords the shift // key and another key, then releases the shift key. if (mSwitchState == SWITCH_STATE_CHORDING_SYMBOL) { - toggleShift(); + toggleShiftInSymbols(); } } mState.onReleaseShift(); @@ -612,34 +564,28 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onPressSymbol() { if (DEBUG_STATE) { - Log.d(TAG, "onPressSymbol:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " state=" + mState); + Log.d(TAG, "onPressSymbol: " + mState); } - changeKeyboardMode(); + toggleAlphabetAndSymbols(); mState.onPressSymbol(); mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL; } public void onReleaseSymbol() { if (DEBUG_STATE) { - Log.d(TAG, "onReleaseSymbol:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " 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. if (mSwitchState == SWITCH_STATE_CHORDING_ALPHA) { - changeKeyboardMode(); + toggleAlphabetAndSymbols(); } mState.onReleaseSymbol(); } public void onOtherKeyPressed() { if (DEBUG_STATE) { - Log.d(TAG, "onOtherKeyPressed:" - + " keyboard=" + getLatinKeyboard().getKeyboardShiftState() - + " state=" + mState); + Log.d(TAG, "onOtherKeyPressed: " + mState); } mState.onOtherKeyPressed(); } @@ -648,37 +594,48 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // Snap back to the previous keyboard mode if the user cancels sliding input. if (isSinglePointer()) { if (mSwitchState == SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL) { - changeKeyboardMode(); + toggleAlphabetAndSymbols(); } else if (mSwitchState == SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE) { - toggleShift(); + toggleShiftInSymbols(); } } } private boolean mPrevMainKeyboardWasShiftLocked; - private void toggleKeyboardMode() { - if (mCurrentId.equals(mMainKeyboardId)) { - mPrevMainKeyboardWasShiftLocked = isShiftLocked(); - setKeyboard(getKeyboard(mSymbolsKeyboardId)); + private void setSymbolsKeyboard() { + mPrevMainKeyboardWasShiftLocked = mState.isShiftLocked(); + setKeyboard(getKeyboard(mSymbolsKeyboardId)); + } + + private void setAlphabetKeyboard() { + setKeyboard(getKeyboard(mMainKeyboardId)); + setShiftLocked(mPrevMainKeyboardWasShiftLocked); + mPrevMainKeyboardWasShiftLocked = false; + } + + private void toggleAlphabetAndSymbols() { + if (isAlphabetMode()) { + setSymbolsKeyboard(); } else { - setKeyboard(getKeyboard(mMainKeyboardId)); - setShiftLocked(mPrevMainKeyboardWasShiftLocked); - mPrevMainKeyboardWasShiftLocked = false; + setAlphabetKeyboard(); } } - private void toggleShiftInSymbol() { - if (isAlphabetMode()) - return; - final LatinKeyboard keyboard; - if (mCurrentId.equals(mSymbolsKeyboardId) - || !mCurrentId.equals(mSymbolsShiftedKeyboardId)) { - keyboard = getKeyboard(mSymbolsShiftedKeyboardId); + private boolean isSymbolShifted() { + return mCurrentId != null && mCurrentId.equals(mSymbolsShiftedKeyboardId); + } + + private void setSymbolsShiftedKeyboard() { + setKeyboard(getKeyboard(mSymbolsShiftedKeyboardId)); + } + + private void toggleShiftInSymbols() { + if (isSymbolShifted()) { + setSymbolsKeyboard(); } else { - keyboard = getKeyboard(mSymbolsKeyboardId); + setSymbolsShiftedKeyboard(); } - setKeyboard(keyboard); } public boolean isInMomentarySwitchState() { @@ -702,7 +659,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha return c == Keyboard.CODE_SPACE || c == Keyboard.CODE_ENTER; } - private static boolean isLayoutSwitchBackCharacter(int c) { + private boolean isLayoutSwitchBackCharacter(int c) { if (TextUtils.isEmpty(mLayoutSwitchBackSymbols)) return false; if (mLayoutSwitchBackSymbols.indexOf(c) >= 0) return true; return false; @@ -736,7 +693,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // and slid to other key, then released the finger. // If the user cancels the sliding input, snapping back to the previous keyboard // mode is handled by {@link #onCancelInput}. - changeKeyboardMode(); + toggleAlphabetAndSymbols(); } else { // Chording input is being started. The keyboard mode will be snapped back to the // previous mode in {@link onReleaseSymbol} when the mode change key is released. @@ -750,7 +707,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } else if (isSinglePointer()) { // Snap back to the previous keyboard mode if the user pressed the shift key on // symbol mode and slid to other key, then released the finger. - toggleShift(); + toggleShiftInSymbols(); mSwitchState = SWITCH_STATE_SYMBOL; } else { // Chording input is being started. The keyboard mode will be snapped back to the @@ -764,7 +721,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } // Snap back to alpha keyboard mode immediately if user types a quote character. if (isLayoutSwitchBackCharacter(code)) { - changeKeyboardMode(); + setAlphabetKeyboard(); } break; case SWITCH_STATE_SYMBOL: @@ -772,7 +729,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // Snap back to alpha keyboard mode if user types one or more non-space/enter // characters followed by a space/enter or a quote character. if (isSpaceCharacter(code) || isLayoutSwitchBackCharacter(code)) { - changeKeyboardMode(); + setAlphabetKeyboard(); } break; } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 762039625..a9fcd9ac4 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -176,7 +176,7 @@ public class LatinKeyboard extends Keyboard { @Override public CharSequence adjustLabelCase(CharSequence label) { - if (isAlphaKeyboard() && isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) + if (mId.isAlphabetKeyboard() && isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { return label.toString().toUpperCase(mId.mLocale); } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 9ddf40119..af5f808fd 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -177,7 +177,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke public boolean onDoubleTap(MotionEvent firstDown) { final Keyboard keyboard = getKeyboard(); if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard - && ((LatinKeyboard) keyboard).isAlphaKeyboard()) { + && ((LatinKeyboard) keyboard).mId.isAlphabetKeyboard()) { final int pointerIndex = firstDown.getActionIndex(); final int id = firstDown.getPointerId(pointerIndex); final PointerTracker tracker = getPointerTracker(id); @@ -396,14 +396,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke final Keyboard keyboard = getKeyboard(); if (keyboard instanceof LatinKeyboard) { final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard; - if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) { + if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.mId.isPhoneKeyboard()) { tracker.onLongPressed(); // Long pressing on 0 in phone number keypad gives you a '+'. invokeCodeInput(Keyboard.CODE_PLUS); invokeReleaseKey(primaryCode); return true; } - if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) { + if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.mId.isAlphabetKeyboard()) { tracker.onLongPressed(); invokeCodeInput(Keyboard.CODE_CAPSLOCK); invokeReleaseKey(primaryCode); diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java index f2c5b7b49..8e9929681 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java @@ -132,9 +132,8 @@ public class MiniKeyboardView extends KeyboardView implements MoreKeysPanel { @Override public void setShifted(boolean shifted) { final Keyboard keyboard = getKeyboard(); - if (keyboard.setShifted(shifted)) { - invalidateAllKeys(); - } + keyboard.setShifted(shifted); + invalidateAllKeys(); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java b/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java index 6314a99db..a3ff37269 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java @@ -24,6 +24,7 @@ public interface MoreKeysPanel extends PointerTracker.KeyEventHandler { public boolean dismissMoreKeysPanel(); } + // TODO: Remove this method. public void setShifted(boolean shifted); /** diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java index 28a53cedc..4a77e0735 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java @@ -33,7 +33,7 @@ public class KeyboardShiftState { private int mState = NORMAL; - public boolean setShifted(boolean newShiftState) { + public void setShifted(boolean newShiftState) { final int oldState = mState; if (newShiftState) { switch (oldState) { @@ -61,7 +61,6 @@ public class KeyboardShiftState { } if (DEBUG) Log.d(TAG, "setShifted(" + newShiftState + "): " + toString(oldState) + " > " + this); - return mState != oldState; } public void setShiftLocked(boolean newShiftLockState) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index b6e4f2daa..fd7e77863 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -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"); @@ -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(); @@ -107,7 +148,8 @@ public class KeyboardState { @Override public String toString() { - return "[shift=" + mShiftKeyState + return "[keyboard=" + mKeyboardShiftState + + " shift=" + mShiftKeyState + " symbol=" + mSymbolKeyState + "]"; } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 60b436f69..5f446a5c4 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1333,7 +1333,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case Keyboard.CODE_SWITCH_ALPHA_SYMBOL: // Symbol key is handled in onPress() when device has distinct multi-touch panel. if (!distinctMultiTouch) { - switcher.changeKeyboardMode(); + switcher.toggleKeyboardMode(); } break; case Keyboard.CODE_CANCEL: |