From 11730aa224ac9fb026a393f6883e3f748f37d464 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 20 Dec 2013 15:44:26 +0900 Subject: [PATCH] [IL22] Move onTextInput to InputLogic. Also pull the TLD specific processing Bug: 8636060 Change-Id: I20931ac6fc6c55a05aa8f8b97b0210c07d230ea2 --- .../android/inputmethod/latin/LatinIME.java | 47 +----------- .../latin/inputlogic/InputLogic.java | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 46 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 6f5cc9fee..f8909e86a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1302,35 +1302,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // Called from PointerTracker through the KeyboardActionListener interface - // TODO[IL]: Move this to InputLogic @Override public void onTextInput(final String rawText) { - mInputLogic.mConnection.beginBatchEdit(); - if (mInputLogic.mWordComposer.isComposingWord()) { - mInputLogic.commitCurrentAutoCorrection(mSettings.getCurrent(), rawText, mHandler); - } else { - mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */); - } - mHandler.postUpdateSuggestionStrip(); - if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS - && ResearchLogger.RESEARCH_KEY_OUTPUT_TEXT.equals(rawText)) { - ResearchLogger.getInstance().onResearchKeySelected(this); - return; - } - final String text = specificTldProcessingOnTextInput(rawText); - if (SpaceState.PHANTOM == mInputLogic.mSpaceState) { - mInputLogic.promotePhantomSpace(mSettings.getCurrent()); - } - mInputLogic.mConnection.commitText(text, 1); - if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { - ResearchLogger.latinIME_onTextInput(text, false /* isBatchMode */); - } - mInputLogic.mConnection.endBatchEdit(); - // Space state must be updated before calling updateShiftState - mInputLogic.mSpaceState = SpaceState.NONE; - mKeyboardSwitcher.updateShiftState(); - mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT); - mInputLogic.mEnteredText = text; + mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mKeyboardSwitcher, mHandler); } @Override @@ -1614,25 +1588,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputUpdater.onEndBatchInput(batchPointers); } - private String specificTldProcessingOnTextInput(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. - mInputLogic.mSpaceState = SpaceState.NONE; - // TODO: use getCodePointBeforeCursor instead to improve performance and simplify the code - final CharSequence lastOne = mInputLogic.mConnection.getTextBeforeCursor(1, 0); - if (lastOne != null && lastOne.length() == 1 - && lastOne.charAt(0) == Constants.CODE_PERIOD) { - return text.substring(1); - } else { - return text; - } - } - // Called from PointerTracker through the KeyboardActionListener interface @Override public void onFinishSlidingInput() { diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index db9bf348f..fd44dde85 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -120,6 +120,46 @@ public final class InputLogic { public void finishInput() { } + /** + * 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. @@ -1069,6 +1109,38 @@ public final class InputLogic { mConnection.performEditorAction(actionId); } + /** + * 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. */