aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-20 08:02:36 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-12-20 08:02:36 +0000
commit84e78cb769995040243024e774527e84b99a6ebf (patch)
treed04c481644686374288f1b26c97a14da1f114c73 /java/src
parent689cff2e3b1ad3709033b36040dc8607a7cb53d6 (diff)
parent11730aa224ac9fb026a393f6883e3f748f37d464 (diff)
downloadlatinime-84e78cb769995040243024e774527e84b99a6ebf.tar.gz
latinime-84e78cb769995040243024e774527e84b99a6ebf.tar.xz
latinime-84e78cb769995040243024e774527e84b99a6ebf.zip
Merge "[IL22] Move onTextInput to InputLogic."
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java47
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java72
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
@@ -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.
*
@@ -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() {