diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic')
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index db27d22b7..fd44dde85 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -121,6 +121,46 @@ public final class InputLogic { } /** + * React to a string input. + * + * This is triggered by keys that input many characters at once, like the ".com" key or + * some additional keys for example. + * + * @param settingsValues the current values of the settings. + * @param rawText the text to input. + */ + public void onTextInput(final SettingsValues settingsValues, final String rawText, + // TODO: remove these arguments + final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) { + mConnection.beginBatchEdit(); + if (mWordComposer.isComposingWord()) { + commitCurrentAutoCorrection(settingsValues, rawText, handler); + } else { + resetComposingState(true /* alsoResetLastComposedWord */); + } + handler.postUpdateSuggestionStrip(); + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS + && ResearchLogger.RESEARCH_KEY_OUTPUT_TEXT.equals(rawText)) { + ResearchLogger.getInstance().onResearchKeySelected(mLatinIME); + return; + } + final String text = performSpecificTldProcessingOnTextInput(rawText); + if (SpaceState.PHANTOM == mSpaceState) { + promotePhantomSpace(settingsValues); + } + mConnection.commitText(text, 1); + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { + ResearchLogger.latinIME_onTextInput(text, false /* isBatchMode */); + } + mConnection.endBatchEdit(); + // Space state must be updated before calling updateShiftState + mSpaceState = SpaceState.NONE; + keyboardSwitcher.updateShiftState(); + keyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT); + mEnteredText = text; + } + + /** * React to a code input. It may be a code point to insert, or a symbolic value that influences * the keyboard behavior. * @@ -387,7 +427,7 @@ public final class InputLogic { final boolean swapWeakSpace = maybeStripSpace(settingsValues, codePoint, spaceState, Constants.SUGGESTION_STRIP_COORDINATE == x); - sendKeyCodePoint(codePoint); + sendKeyCodePoint(settingsValues, codePoint); if (swapWeakSpace) { swapSwapperAndSpace(keyboardSwitcher); @@ -449,7 +489,7 @@ public final class InputLogic { } if (!shouldAvoidSendingCode) { - sendKeyCodePoint(codePoint); + sendKeyCodePoint(settingsValues, codePoint); } if (Constants.CODE_SPACE == codePoint) { @@ -593,7 +633,7 @@ public final class InputLogic { // This should never happen. Log.e(TAG, "Backspace when we don't know the selection position"); } - if (mLatinIME.mAppWorkAroundsUtils.isBeforeJellyBean() || + if (settingsValues.isBeforeJellyBean() || settingsValues.mInputAttributes.isTypeNull()) { // There are two possible reasons to send a key event: either the field has // type TYPE_NULL, in which case the keyboard should send events, or we are @@ -1070,6 +1110,38 @@ public final class InputLogic { } /** + * Perform the processing specific to inputting TLDs. + * + * Some keys input a TLD (specifically, the ".com" key) and this warrants some specific + * processing. First, if this is a TLD, we ignore PHANTOM spaces -- this is done by type + * of character in onCodeInput, but since this gets inputted as a whole string we need to + * do it here specifically. Then, if the last character before the cursor is a period, then + * we cut the dot at the start of ".com". This is because humans tend to type "www.google." + * and then press the ".com" key and instinctively don't expect to get "www.google..com". + * + * @param text the raw text supplied to onTextInput + * @return the text to actually send to the editor + */ + private String performSpecificTldProcessingOnTextInput(final String text) { + if (text.length() <= 1 || text.charAt(0) != Constants.CODE_PERIOD + || !Character.isLetter(text.charAt(1))) { + // Not a tld: do nothing. + return text; + } + // We have a TLD (or something that looks like this): make sure we don't add + // a space even if currently in phantom mode. + mSpaceState = SpaceState.NONE; + // TODO: use getCodePointBeforeCursor instead to improve performance and simplify the code + final CharSequence lastOne = mConnection.getTextBeforeCursor(1, 0); + if (lastOne != null && lastOne.length() == 1 + && lastOne.charAt(0) == Constants.CODE_PERIOD) { + return text.substring(1); + } else { + return text; + } + } + + /** * Handle a press on the settings key. */ private void onSettingsKeyPressed() { @@ -1167,9 +1239,10 @@ public final class InputLogic { * Normally we send code points with commitText, but there are some cases (where backward * compatibility is a concern for example) where we want to use deprecated methods. * + * @param settingsValues the current values of the settings. * @param codePoint the code point to send. */ - private void sendKeyCodePoint(final int codePoint) { + private void sendKeyCodePoint(final SettingsValues settingsValues, final int codePoint) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_sendKeyCodePoint(codePoint); } @@ -1181,8 +1254,7 @@ public final class InputLogic { } // TODO: we should do this also when the editor has TYPE_NULL - if (Constants.CODE_ENTER == codePoint - && mLatinIME.mAppWorkAroundsUtils.isBeforeJellyBean()) { + if (Constants.CODE_ENTER == codePoint && settingsValues.isBeforeJellyBean()) { // Backward compatibility mode. Before Jelly bean, the keyboard would simulate // a hardware keyboard event on pressing enter or delete. This is bad for many // reasons (there are race conditions with commits) but some applications are @@ -1209,7 +1281,7 @@ public final class InputLogic { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_promotePhantomSpace(); } - sendKeyCodePoint(Constants.CODE_SPACE); + sendKeyCodePoint(settingsValues, Constants.CODE_SPACE); } } |