Merge "Move creating children methods to structurePolicy."
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b28406b..9366abd 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -155,7 +155,7 @@
     private SuggestionStripView mSuggestionStripView;
     // Never null
     private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
-    @UsedForTesting Suggest mSuggest;
+    private Suggest mSuggest;
     private CompletionInfo[] mApplicationSpecifiedCompletions;
     private AppWorkaroundsUtils mAppWorkAroundsUtils = new AppWorkaroundsUtils();
 
@@ -714,7 +714,7 @@
         super.onStartInputView(editorInfo, restarting);
         final KeyboardSwitcher switcher = mKeyboardSwitcher;
         final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView();
-        final SettingsValues currentSettings = mSettings.getCurrent();
+        final SettingsValues currentSettingsValues = mSettings.getCurrent();
 
         if (editorInfo == null) {
             Log.e(TAG, "Null EditorInfo in onStartInputView()");
@@ -769,7 +769,7 @@
             accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting);
         }
 
-        final boolean inputTypeChanged = !currentSettings.isSameInputType(editorInfo);
+        final boolean inputTypeChanged = !currentSettingsValues.isSameInputType(editorInfo);
         final boolean isDifferentTextField = !restarting || inputTypeChanged;
         if (isDifferentTextField) {
             mSubtypeSwitcher.updateParametersOnStartInputView();
@@ -808,12 +808,12 @@
         if (isDifferentTextField) {
             mainKeyboardView.closing();
             loadSettings();
-
-            if (mSuggest != null && currentSettings.mCorrectionEnabled) {
-                mSuggest.setAutoCorrectionThreshold(currentSettings.mAutoCorrectionThreshold);
+            // TODO: Need to update currentSettingsValues after loadSettings()
+            if (mSuggest != null && currentSettingsValues.mCorrectionEnabled) {
+                mSuggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold);
             }
 
-            switcher.loadKeyboard(editorInfo, currentSettings);
+            switcher.loadKeyboard(editorInfo, currentSettingsValues);
         } 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.
@@ -834,14 +834,14 @@
         mHandler.cancelDoubleSpacePeriodTimer();
 
         mainKeyboardView.setMainDictionaryAvailability(mIsMainDictionaryAvailable);
-        mainKeyboardView.setKeyPreviewPopupEnabled(currentSettings.mKeyPreviewPopupOn,
-                currentSettings.mKeyPreviewPopupDismissDelay);
+        mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn,
+                currentSettingsValues.mKeyPreviewPopupDismissDelay);
         mainKeyboardView.setSlidingKeyInputPreviewEnabled(
-                currentSettings.mSlidingKeyInputPreviewEnabled);
+                currentSettingsValues.mSlidingKeyInputPreviewEnabled);
         mainKeyboardView.setGestureHandlingEnabledByUser(
-                currentSettings.mGestureInputEnabled);
-        mainKeyboardView.setGesturePreviewMode(currentSettings.mGesturePreviewTrailEnabled,
-                currentSettings.mGestureFloatingPreviewTextEnabled);
+                currentSettingsValues.mGestureInputEnabled);
+        mainKeyboardView.setGesturePreviewMode(currentSettingsValues.mGesturePreviewTrailEnabled,
+                currentSettingsValues.mGestureFloatingPreviewTextEnabled);
 
         // If we have a user dictionary addition in progress, we should check now if we should
         // replace the previously committed string with the word that has actually been added
@@ -2243,7 +2243,8 @@
 
     private SuggestedWords getSuggestedWords(final int sessionId) {
         final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
-        if (keyboard == null || mSuggest == null) {
+        final Suggest suggest = mSuggest;
+        if (keyboard == null || suggest == null) {
             return SuggestedWords.EMPTY;
         }
         // Get the word on which we should search the bigrams. If we are composing a word, it's
@@ -2253,7 +2254,7 @@
         final String prevWord =
                 mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators,
                 mWordComposer.isComposingWord() ? 2 : 1);
-        return mSuggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(),
+        return suggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(),
                 mSettings.getBlockPotentiallyOffensive(),
                 mSettings.getCurrent().mCorrectionEnabled, sessionId);
     }
@@ -2857,6 +2858,18 @@
         return mSuggestedWords.size() > 0 ? mSuggestedWords.getWord(0) : null;
     }
 
+    // DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME.
+    @UsedForTesting
+    /* package for test */ boolean isCurrentlyWaitingForMainDictionary() {
+        return mSuggest.isCurrentlyWaitingForMainDictionary();
+    }
+
+    // DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME.
+    @UsedForTesting
+    /* package for test */ boolean hasMainDictionary() {
+        return mSuggest.hasMainDictionary();
+    }
+
     public void debugDumpStateAndCrashWithException(final String context) {
         final StringBuilder s = new StringBuilder(mAppWorkAroundsUtils.toString());
         s.append("\nAttributes : ").append(mSettings.getCurrent().mInputAttributes)
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index d1ce104..eb4f706 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -225,7 +225,7 @@
 
     protected void waitForDictionaryToBeLoaded() {
         int remainingAttempts = 300;
-        while (remainingAttempts > 0 && mLatinIME.mSuggest.isCurrentlyWaitingForMainDictionary()) {
+        while (remainingAttempts > 0 && mLatinIME.isCurrentlyWaitingForMainDictionary()) {
             try {
                 Thread.sleep(200);
             } catch (InterruptedException e) {
@@ -234,7 +234,7 @@
                 --remainingAttempts;
             }
         }
-        if (!mLatinIME.mSuggest.hasMainDictionary()) {
+        if (!mLatinIME.hasMainDictionary()) {
             throw new RuntimeException("Can't initialize the main dictionary");
         }
     }