diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 123 |
1 files changed, 84 insertions, 39 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 3250cdd01..6d8803148 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -151,7 +151,6 @@ public class LatinIME extends InputMethodService private static final int POS_METHOD = 0; private static final int POS_SETTINGS = 1; - //private LatinKeyboardView mInputView; private LinearLayout mCandidateViewContainer; private CandidateView mCandidateView; private Suggest mSuggest; @@ -195,8 +194,6 @@ public class LatinIME extends InputMethodService private boolean mReCorrectionEnabled; private boolean mBigramSuggestionEnabled; private boolean mAutoCorrectOn; - // TODO move this state variable outside LatinIME - private boolean mCapsLock; private boolean mPasswordText; private boolean mVibrateOn; private boolean mSoundOn; @@ -586,7 +583,6 @@ public class LatinIME extends InputMethodService mPredictionOn = false; mCompletionOn = false; mCompletions = null; - mCapsLock = false; mEnteredText = null; switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) { @@ -991,9 +987,11 @@ public class LatinIME extends InputMethodService return true; } LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView == null) break; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) break; // Enable shift key and DPAD to do selections - if (inputView != null && inputView.isShown() - && inputView.isShifted()) { + if (inputView.isShown() && latinKeyboard.isShifted()) { event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(), @@ -1053,9 +1051,14 @@ public class LatinIME extends InputMethodService public void updateShiftKeyState(EditorInfo attr) { InputConnection ic = getCurrentInputConnection(); - if (ic != null && attr != null && mKeyboardSwitcher.isAlphabetMode()) { - mKeyboardSwitcher.setShifted(mShiftKeyState.isMomentary() || mCapsLock - || getCursorCapsMode(ic, attr) != 0); + LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView == null) return; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) return; + if (ic != null && attr != null && mKeyboardSwitcher.isAlphabetMode() + && !mShiftKeyState.isIgnoring()) { + mKeyboardSwitcher.setShifted(mShiftKeyState.isMomentary() + || latinKeyboard.isShiftLocked() || getCursorCapsMode(ic, attr) != 0); } } @@ -1368,11 +1371,13 @@ public class LatinIME extends InputMethodService KeyboardSwitcher switcher = mKeyboardSwitcher; if (switcher.isAlphabetMode()) { LatinKeyboardView inputView = switcher.getInputView(); - if (mCapsLock || forceNormal) { - mCapsLock = false; + if (inputView == null) return; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) return; + if (latinKeyboard.isShiftLocked() || forceNormal) { switcher.setShifted(false); - } else if (inputView != null) { - switcher.setShifted(!inputView.isShifted()); + } else { + switcher.setShifted(!latinKeyboard.isShifted()); } } else { switcher.toggleShift(); @@ -1383,13 +1388,15 @@ public class LatinIME extends InputMethodService mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE); KeyboardSwitcher switcher = mKeyboardSwitcher; if (switcher.isAlphabetMode()) { - if (mCapsLock) { - mCapsLock = false; + LatinKeyboardView inputView = switcher.getInputView(); + if (inputView == null) return; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) return; + if (latinKeyboard.isShiftLocked()) { // LatinKeyboard.setShifted(false) also disable shift locked state. // Note: Caps lock LED is off when Key.on is false. switcher.setShifted(false); } else { - mCapsLock = true; // LatinKeyboard.setShiftLocked(true) enable shift state too. // Note: Caps lock LED is on when Key.on is true. switcher.setShiftLocked(true); @@ -1425,7 +1432,8 @@ public class LatinIME extends InputMethodService mWord.reset(); } } - if (mKeyboardSwitcher.getInputView().isShifted()) { + LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard(); + if (latinKeyboard != null && latinKeyboard.isShifted()) { if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT || keyCodes[0] > Character.MAX_CODE_POINT) { return; @@ -1444,7 +1452,7 @@ public class LatinIME extends InputMethodService } } if (mPredicting) { - if (mKeyboardSwitcher.getInputView().isShifted() + if (latinKeyboard != null && latinKeyboard.isShifted() && mKeyboardSwitcher.isAlphabetMode() && mComposing.length() == 0) { mWord.setFirstCharCapitalized(true); @@ -1739,7 +1747,8 @@ public class LatinIME extends InputMethodService final List<CharSequence> nBest = new ArrayList<CharSequence>(); boolean capitalizeFirstWord = preferCapitalization() || (mKeyboardSwitcher.isAlphabetMode() - && mKeyboardSwitcher.getInputView().isShifted()); + && mKeyboardSwitcher.getInputView().getLatinKeyboard() != null + && mKeyboardSwitcher.getInputView().getLatinKeyboard().isShifted()); for (String c : mVoiceResults.candidates) { if (capitalizeFirstWord) { c = Character.toUpperCase(c.charAt(0)) + c.substring(1, c.length()); @@ -1791,7 +1800,10 @@ public class LatinIME extends InputMethodService private void updateSuggestions() { LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); - ((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null); + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard != null) { + latinKeyboard.setPreferredLetters(null); + } // Check if we have a suggestion engine attached. if ((mSuggest == null || !isPredictionOn()) && !mVoiceInputHighlighted) { @@ -1813,7 +1825,10 @@ public class LatinIME extends InputMethodService private void showCorrections(WordAlternatives alternatives) { List<CharSequence> stringList = alternatives.getAlternatives(); - ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setPreferredLetters(null); + LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard(); + if (latinKeyboard != null) { + latinKeyboard.setPreferredLetters(null); + } showSuggestions(stringList, alternatives.getOriginalWord(), false, false); } @@ -1829,8 +1844,10 @@ public class LatinIME extends InputMethodService int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies(); - ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setPreferredLetters( - nextLettersFrequencies); + LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard(); + if (latinKeyboard != null) { + latinKeyboard.setPreferredLetters(nextLettersFrequencies); + } boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasMinimalCorrection(); //|| mCorrectionMode == mSuggest.CORRECTION_FULL; @@ -2002,11 +2019,13 @@ public class LatinIME extends InputMethodService */ private void pickSuggestion(CharSequence suggestion, boolean correcting) { LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); - if (mCapsLock) { + if (inputView == null) return; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) return; + if (latinKeyboard.isShiftLocked()) { suggestion = suggestion.toString().toUpperCase(); } else if (preferCapitalization() - || (mKeyboardSwitcher.isAlphabetMode() - && inputView.isShifted())) { + || (mKeyboardSwitcher.isAlphabetMode() && latinKeyboard.isShifted())) { suggestion = suggestion.toString().toUpperCase().charAt(0) + suggestion.subSequence(1, suggestion.length()).toString(); } @@ -2018,7 +2037,9 @@ public class LatinIME extends InputMethodService saveWordInHistory(suggestion); mPredicting = false; mCommittedLength = suggestion.length(); - ((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null); + if (latinKeyboard != null) { + latinKeyboard.setPreferredLetters(null); + } // If we just corrected a word, then don't show punctuations if (!correcting) { setNextSuggestions(); @@ -2305,11 +2326,19 @@ public class LatinIME extends InputMethodService vibrate(); playKeyClick(primaryCode); final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch(); + LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView == null) return; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) return; if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) { - mShiftKeyState.onPress(); - // Not in caps lock mode, shift key is in effect on pressed. - if (mKeyboardSwitcher.isAlphabetMode() && !mCapsLock) + // In alphabet mode, we call handleShift() to go into the shifted mode in this + // method, onPress(), only when we are in the small letter mode. + if (mKeyboardSwitcher.isAlphabetMode() && latinKeyboard.isShifted()) { + mShiftKeyState.onPressOnShifted(); + } else { + mShiftKeyState.onPress(); handleShift(); + } } else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) { mSymbolKeyState.onPress(); changeKeyboardMode(); @@ -2319,21 +2348,34 @@ public class LatinIME extends InputMethodService } } + // TODO: Bug - onRelease() could be dropped if the user slides finger out of the key. It's OK + // for general keys, but we need to obtain onRelease() for the shift key even in such case. public void onRelease(int primaryCode) { // Reset any drag flags in the keyboard - ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).keyReleased(); + LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView == null) return; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) return; + latinKeyboard.keyReleased(); //vibrate(); final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch(); if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) { - if (mShiftKeyState.isMomentary()) + if (mShiftKeyState.isMomentary()) { resetShift(); - // In caps lock mode, shift key is in effect on released. - if (mKeyboardSwitcher.isAlphabetMode() && mCapsLock) - handleShift(); + } + if (mKeyboardSwitcher.isAlphabetMode()) { + // In alphabet mode, we call handleShift() to go into the small letter mode in this + // method, onRelease(), only when we are in the shifted modes -- temporary shifted + // mode or caps lock mode. + if (latinKeyboard.isShifted() && mShiftKeyState.isPressingOnShifted()) { + handleShift(); + } + } mShiftKeyState.onRelease(); } else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) { - if (mSymbolKeyState.isMomentary()) + if (mSymbolKeyState.isMomentary()) { changeKeyboardMode(); + } mSymbolKeyState.onRelease(); } } @@ -2636,8 +2678,12 @@ public class LatinIME extends InputMethodService private void changeKeyboardMode() { mKeyboardSwitcher.toggleSymbols(); - if (mCapsLock && mKeyboardSwitcher.isAlphabetMode()) { - mKeyboardSwitcher.setShiftLocked(mCapsLock); + LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView == null) return; + LatinKeyboard latinKeyboard = inputView.getLatinKeyboard(); + if (latinKeyboard == null) return; + if (latinKeyboard.isShiftLocked() && mKeyboardSwitcher.isAlphabetMode()) { + mKeyboardSwitcher.setShiftLocked(true); } updateShiftKeyState(getCurrentInputEditorInfo()); @@ -2657,7 +2703,6 @@ public class LatinIME extends InputMethodService final Printer p = new PrintWriterPrinter(fout); p.println("LatinIME state :"); p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode()); - p.println(" mCapsLock=" + mCapsLock); p.println(" mComposing=" + mComposing.toString()); p.println(" mPredictionOn=" + mPredictionOn); p.println(" mCorrectionMode=" + mCorrectionMode); |