diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 46 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 22 |
2 files changed, 36 insertions, 32 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 84558ca24..1fdb8d16c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -236,7 +236,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // If we were able to reset the caches, then we can reload the keyboard. // Otherwise, we'll do it when we can. latinIme.mKeyboardSwitcher.loadKeyboard(latinIme.getCurrentInputEditorInfo(), - settingsValues); + settingsValues, latinIme.getCurrentAutoCapsState(), + latinIme.getCurrentAutoCapsState()); } break; } @@ -833,7 +834,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold); } - switcher.loadKeyboard(editorInfo, currentSettingsValues); + switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); if (!canReachInputConnection) { // If we can't reach the input connection, we will call loadKeyboard again later, // so we need to save its state now. The call will be done in #retryResetCaches. @@ -842,7 +844,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else if (restarting) { // TODO: Come up with a more comprehensive way to reset the keyboard layout when // a keyboard layout set doesn't get reloaded in this method. - switcher.resetKeyboardStateToAlphabet(); + switcher.resetKeyboardStateToAlphabet(getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); // In apps like Talk, we come here when the text is sent and the field gets emptied and // we need to re-evaluate the shift state, but not the whole layout which would be // disruptive. @@ -1119,17 +1122,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE); } - // Called from the KeyboardSwitcher which needs to know auto caps state to display - // the right layout. - // TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead? - public int getCurrentAutoCapsState() { + private int getCurrentAutoCapsState() { return mInputLogic.getCurrentAutoCapsState(mSettings.getCurrent()); } - // Called from the KeyboardSwitcher which needs to know recaps state to display - // the right layout. - // TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead? - public int getCurrentRecapitalizeState() { + private int getCurrentRecapitalizeState() { return mInputLogic.getCurrentRecapitalizeState(); } @@ -1224,7 +1221,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Implementation of {@link KeyboardActionListener}. @Override - public void onCodeInput(final int codePoint, final int x, final int y) { + public void onCodeInput(final int codePoint, final int x, final int y, + final boolean isKeyRepeat) { final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); // x and y include some padding, but everything down the line (especially native // code) needs the coordinates in the keyboard frame. @@ -1250,18 +1248,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSubtypeSwitcher.switchToShortcutIME(this); // Still call the *#onCodeInput methods for readability. } - final Event event = createSoftwareKeypressEvent(codeToSend, keyX, keyY); + final Event event = createSoftwareKeypressEvent(codeToSend, keyX, keyY, isKeyRepeat); final InputTransaction completeInputTransaction = mInputLogic.onCodeInput(mSettings.getCurrent(), event, mKeyboardSwitcher.getKeyboardShiftMode(), mHandler); updateStateAfterInputTransaction(completeInputTransaction); - mKeyboardSwitcher.onCodeInput(codePoint, getCurrentAutoCapsState()); + mKeyboardSwitcher.onCodeInput(codePoint, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); } // A helper method to split the code point and the key code. Ultimately, they should not be // squashed into the same variable, and this method should be removed. private static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX, - final int keyY) { + final int keyY, final boolean isKeyRepeat) { final int keyCode; final int codePoint; if (keyCodeOrCodePoint <= 0) { @@ -1271,7 +1270,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen keyCode = Event.NOT_A_KEY_CODE; codePoint = keyCodeOrCodePoint; } - return Event.createSoftwareKeypressEvent(codePoint, keyCode, keyX, keyY); + return Event.createSoftwareKeypressEvent(codePoint, keyCode, keyX, keyY, isKeyRepeat); } // Called from PointerTracker through the KeyboardActionListener interface @@ -1282,7 +1281,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.onTextInput(mSettings.getCurrent(), event, mHandler); mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState()); - mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT, getCurrentAutoCapsState()); + mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); } @Override @@ -1320,7 +1320,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onFinishSlidingInput() { // User finished sliding input. - mKeyboardSwitcher.onFinishSlidingInput(); + mKeyboardSwitcher.onFinishSlidingInput(getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); } // Called from PointerTracker through the KeyboardActionListener interface @@ -1509,7 +1510,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadSettings(); if (mKeyboardSwitcher.getMainKeyboardView() != null) { // Reload keyboard because the current language has been changed. - mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent()); + mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent(), + getCurrentAutoCapsState(), getCurrentRecapitalizeState()); } } @@ -1566,7 +1568,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onPressKey(final int primaryCode, final int repeatCount, final boolean isSinglePointer) { - mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer, getCurrentAutoCapsState()); + mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); hapticAndAudioFeedback(primaryCode, repeatCount); } @@ -1574,7 +1577,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // press matching call is {@link #onPressKey(int,int,boolean)} above. @Override public void onReleaseKey(final int primaryCode, final boolean withSliding) { - mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding); + mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding, getCurrentAutoCapsState(), + getCurrentRecapitalizeState()); // If accessibility is on, ensure the user receives keyboard state updates. if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index bf8467eb6..491d98074 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -884,10 +884,17 @@ public final class InputLogic { mSpaceState = SpaceState.NONE; mDeleteCount++; - // In many cases, we may have to put the keyboard in auto-shift state again. However - // we want to wait a few milliseconds before doing it to avoid the keyboard flashing - // during key repeat. - inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_LATER); + // In many cases after backspace, we need to update the shift state. Normally we need + // to do this right away to avoid the shift state being out of date in case the user types + // backspace then some other character very fast. However, in the case of backspace key + // repeat, this can lead to flashiness when the cursor flies over positions where the + // shift state should be updated, so if this is a key repeat, we update after a small delay. + // Then again, even in the case of a key repeat, if the cursor is at start of text, it + // can't go any further back, so we can update right away even if it's a key repeat. + final int shiftUpdateKind = + inputTransaction.mEvent.isKeyRepeat() && mConnection.getExpectedSelectionStart() > 0 + ? InputTransaction.SHIFT_UPDATE_LATER : InputTransaction.SHIFT_UPDATE_NOW; + inputTransaction.requireShiftUpdate(shiftUpdateKind); if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) { // If we are in the middle of a recorrection, we need to commit the recorrection @@ -910,11 +917,6 @@ public final class InputLogic { } mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); inputTransaction.setRequiresUpdateSuggestions(); - if (!mWordComposer.isComposingWord()) { - // If we just removed the last character, auto-caps mode may have changed so we - // need to re-evaluate. - inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); - } } else { if (mLastComposedWord.canRevertCommit()) { if (inputTransaction.mSettingsValues.mIsInternal) { @@ -1025,8 +1027,6 @@ public final class InputLogic { restartSuggestionsOnWordTouchedByCursor(inputTransaction.mSettingsValues, true /* includeResumedWordInSuggestions */); } - // We just removed at least one character. We need to update the auto-caps state. - inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); } } |