From c654fe57b1686dde764ea31b0e510885b75b14a1 Mon Sep 17 00:00:00 2001
From: Jean Chalard <jchalard@google.com>
Date: Wed, 25 Dec 2013 20:08:52 +0900
Subject: [PATCH] [IL48] Move onEndBatchInputAsyncInternal to InputLogic.

Bug: 8636060
Change-Id: Idfabf7231a80e21786ce1910b5140bb3dddcac7d
---
 .../android/inputmethod/latin/LatinIME.java   | 37 +----------------
 .../latin/inputlogic/InputLogic.java          | 41 +++++++++++++++++++
 2 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 68818b8242..901e502a68 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -215,7 +215,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
                 postUpdateSuggestionStrip();
                 break;
             case MSG_ON_END_BATCH_INPUT:
-                latinIme.onEndBatchInputAsyncInternal((SuggestedWords) msg.obj);
+                latinIme.mInputLogic.onEndBatchInputAsyncInternal(latinIme.mSettings.getCurrent(),
+                        (SuggestedWords) msg.obj, latinIme.mKeyboardSwitcher);
                 break;
             case MSG_RESET_CACHES:
                 latinIme.mInputLogic.retryResetCaches(latinIme.mSettings.getCurrent(),
@@ -1428,40 +1429,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
         }
     }
 
-    // This method must run on the UI Thread.
-    public void onEndBatchInputAsyncInternal(final SuggestedWords suggestedWords) {
-        final String batchInputText = suggestedWords.isEmpty() ? null : suggestedWords.getWord(0);
-        if (TextUtils.isEmpty(batchInputText)) {
-            return;
-        }
-        mInputLogic.mConnection.beginBatchEdit();
-        if (SpaceState.PHANTOM == mInputLogic.mSpaceState) {
-            mInputLogic.promotePhantomSpace(mSettings.getCurrent());
-        }
-        if (mSettings.getCurrent().mPhraseGestureEnabled) {
-            // Find the last space
-            final int indexOfLastSpace = batchInputText.lastIndexOf(Constants.CODE_SPACE) + 1;
-            if (0 != indexOfLastSpace) {
-                mInputLogic.mConnection.commitText(batchInputText.substring(0, indexOfLastSpace),
-                        1);
-                showSuggestionStrip(suggestedWords.getSuggestedWordsForLastWordOfPhraseGesture());
-            }
-            final String lastWord = batchInputText.substring(indexOfLastSpace);
-            mInputLogic.mWordComposer.setBatchInputWord(lastWord);
-            mInputLogic.mConnection.setComposingText(lastWord, 1);
-        } else {
-            mInputLogic.mWordComposer.setBatchInputWord(batchInputText);
-            mInputLogic.mConnection.setComposingText(batchInputText, 1);
-        }
-        mInputLogic.mConnection.endBatchEdit();
-        if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
-            ResearchLogger.latinIME_onEndBatchInput(batchInputText, 0, suggestedWords);
-        }
-        // Space state must be updated before calling updateShiftState
-        mInputLogic.mSpaceState = SpaceState.PHANTOM;
-        mKeyboardSwitcher.updateShiftState();
-    }
-
     // 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 5613fe6a31..34377e9552 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1508,6 +1508,47 @@ public final class InputLogic {
         }
     }
 
+    /**
+     * Do the final processing after a batch input has ended. This commits the word to the editor.
+     * @param settingsValues the current values of the settings.
+     * @param suggestedWords suggestedWords to use.
+     */
+    public void onEndBatchInputAsyncInternal(final SettingsValues settingsValues,
+            final SuggestedWords suggestedWords,
+            // TODO: remove this argument
+            final KeyboardSwitcher keyboardSwitcher) {
+        final String batchInputText = suggestedWords.isEmpty() ? null : suggestedWords.getWord(0);
+        if (TextUtils.isEmpty(batchInputText)) {
+            return;
+        }
+        mConnection.beginBatchEdit();
+        if (SpaceState.PHANTOM == mSpaceState) {
+            promotePhantomSpace(settingsValues);
+        }
+        if (settingsValues.mPhraseGestureEnabled) {
+            // Find the last space
+            final int indexOfLastSpace = batchInputText.lastIndexOf(Constants.CODE_SPACE) + 1;
+            if (0 != indexOfLastSpace) {
+                mConnection.commitText(batchInputText.substring(0, indexOfLastSpace), 1);
+                mLatinIME.showSuggestionStrip(
+                        suggestedWords.getSuggestedWordsForLastWordOfPhraseGesture());
+            }
+            final String lastWord = batchInputText.substring(indexOfLastSpace);
+            mWordComposer.setBatchInputWord(lastWord);
+            mConnection.setComposingText(lastWord, 1);
+        } else {
+            mWordComposer.setBatchInputWord(batchInputText);
+            mConnection.setComposingText(batchInputText, 1);
+        }
+        mConnection.endBatchEdit();
+        if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
+            ResearchLogger.latinIME_onEndBatchInput(batchInputText, 0, suggestedWords);
+        }
+        // Space state must be updated before calling updateShiftState
+        mSpaceState = SpaceState.PHANTOM;
+        keyboardSwitcher.updateShiftState();
+    }
+
     /**
      * Commit the typed string to the editor.
      *
-- 
GitLab