Merge "Add setup wizard launcher icon" into jb-mr2-dev
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index f7d34c8..2a47d7a 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -409,26 +409,27 @@
     <!-- Title of the button to revert to the default value of the device in the settings dialog [CHAR LIMIT=15] -->
     <string name="button_default">Default</string>
 
+    <!-- TODO: Remove translatable="false" once wordings are finalized. -->
     <!-- Title of the setup wizard. [CHAR LIMT=40] -->
-    <string name="setup_title">"Installing <xliff:g id="application_name">%s</xliff:g>"</string>
+    <string name="setup_title" translatable="false">"Installing <xliff:g id="application_name">%s</xliff:g>"</string>
     <!-- Ordinal number of the 1st step in the setup wizard. [CHAR LIMIT=5] -->
-    <string name="setup_step1_bullet">1</string>
+    <string name="setup_step1_bullet" translatable="false">1</string>
     <!-- Title of the 1st step in the setup wizard. [CHAR LIMIT=64] -->
-    <string name="setup_step1_title">"Enable <xliff:g id="application_name">%s</xliff:g> in settings."</string>
+    <string name="setup_step1_title" translatable="false">"Enable <xliff:g id="application_name">%s</xliff:g> in settings."</string>
     <!-- Detailed instruction of the 1st step in the setup wizard. [CHAR LIMIT=80] -->
-    <string name="setup_step1_instruction">"For security, please check \"<xliff:g id="application_name">%s</xliff:g>\""</string>
+    <string name="setup_step1_instruction" translatable="false">"For security, please check \"<xliff:g id="application_name">%s</xliff:g>\""</string>
     <!-- Ordinal number of the 2nd step in the setup wizard. [CHAR LIMIT=5] -->
-    <string name="setup_step2_bullet">2</string>
+    <string name="setup_step2_bullet" translatable="false">2</string>
     <!-- Title of the 2nd step in the setup wizard. [CHAR LIMIT=64] -->
-    <string name="setup_step2_title">"Switch to <xliff:g id="application_name">%s</xliff:g>."</string>
+    <string name="setup_step2_title" translatable="false">"Switch to <xliff:g id="application_name">%s</xliff:g>."</string>
     <!-- Detailed instruction of the 2nd step in the setup wizard. [CHAR LIMIT=80] -->
-    <string name="setup_step2_instruction">"Now that you've enabled <xliff:g id="application_name">%s</xliff:g>, you can switch to it."</string>
+    <string name="setup_step2_instruction" translatable="false">"Now that you've enabled <xliff:g id="application_name">%s</xliff:g>, you can switch to it."</string>
     <!-- Ordinal number of the 3rd step in the setup wizard. [CHAR LIMIT=5] -->
-    <string name="setup_step3_bullet">3</string>
+    <string name="setup_step3_bullet" translatable="false">3</string>
     <!-- Title of the 3rd step in the setup wizard. [CHAR LIMIT=64] -->
-    <string name="setup_step3_title">"Congratulations, you're all set!"</string>
+    <string name="setup_step3_title" translatable="false">"Congratulations, you're all set!"</string>
     <!-- Detailed instruction of the 3rd step in the setup wizard. [CHAR LIMIT=80] -->
-    <string name="setup_step3_instruction">Configure additional languages</string>
+    <string name="setup_step3_instruction" translatable="false">Configure additional languages</string>
     <!-- Title of the Language & input settings. This should be aligned with msgid="5292716747264442359" -->
     <string name="language_settings">Language &amp; input</string>
     <!-- Title of the Input method picker. This should be aligned with msgid="4653387336791222978" -->
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 365c35b..350dc69 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -635,15 +635,9 @@
         invalidate(x, y, x + key.mWidth, y + key.mHeight);
     }
 
-    // TODO: Remove this method.
-    public void closing() {
-        mInvalidateAllKeys = true;
-    }
-
     @Override
     protected void onDetachedFromWindow() {
         super.onDetachedFromWindow();
-        closing();
         freeOffscreenBuffer();
     }
 }
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 4d10f0e..bc27f85 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -1236,13 +1236,11 @@
         mDrawingHandler.cancelAllMessages();
     }
 
-    @Override
     public void closing() {
         dismissAllKeyPreviews();
         cancelAllMessages();
         onDismissMoreKeysPanel();
         mMoreKeysKeyboardCache.clear();
-        super.closing();
     }
 
     /**
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
index 9e75f8b..0d42ab2 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
@@ -174,7 +174,6 @@
 
     @Override
     public boolean dismissMoreKeysPanel() {
-        super.closing();
         if (mController == null) return false;
         return mController.onDismissMoreKeysPanel();
     }
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 20209b6..e934746 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -132,6 +132,8 @@
     private View mKeyPreviewBackingView;
     private View mSuggestionsContainer;
     private SuggestionStripView mSuggestionStripView;
+    // Never null
+    private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
     @UsedForTesting Suggest mSuggest;
     private CompletionInfo[] mApplicationSpecifiedCompletions;
     private ApplicationInfo mTargetApplicationInfo;
@@ -728,6 +730,7 @@
             // otherwise it will clear the suggestion strip.
             setPunctuationSuggestions();
         }
+        mSuggestedWords = SuggestedWords.EMPTY;
 
         mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
 
@@ -992,7 +995,7 @@
                 false /* isPrediction */);
         // When in fullscreen mode, show completions generated by the application
         final boolean isAutoCorrection = false;
-        setSuggestionStrip(suggestedWords, isAutoCorrection);
+        setSuggestedWords(suggestedWords, isAutoCorrection);
         setAutoCorrectionIndicator(isAutoCorrection);
         setSuggestionStripShown(true);
         if (ProductionFlag.IS_EXPERIMENTAL) {
@@ -1117,7 +1120,7 @@
         if (mSettings.getCurrent().mBigramPredictionEnabled) {
             clearSuggestionStrip();
         } else {
-            setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false);
+            setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
         }
         mConnection.resetCachesUponCursorMove(newCursorPosition);
     }
@@ -1980,8 +1983,8 @@
     // Outside LatinIME, only used by the test suite.
     @UsedForTesting
     boolean isShowingPunctuationList() {
-        if (mSuggestionStripView == null) return false;
-        return mSettings.getCurrent().mSuggestPuncList == mSuggestionStripView.getSuggestions();
+        if (mSuggestedWords == null) return false;
+        return mSettings.getCurrent().mSuggestPuncList == mSuggestedWords;
     }
 
     private boolean isSuggestionsStripVisible() {
@@ -1997,11 +2000,12 @@
     }
 
     private void clearSuggestionStrip() {
-        setSuggestionStrip(SuggestedWords.EMPTY, false);
+        setSuggestedWords(SuggestedWords.EMPTY, false);
         setAutoCorrectionIndicator(false);
     }
 
-    private void setSuggestionStrip(final SuggestedWords words, final boolean isAutoCorrection) {
+    private void setSuggestedWords(final SuggestedWords words, final boolean isAutoCorrection) {
+        mSuggestedWords = words;
         if (mSuggestionStripView != null) {
             mSuggestionStripView.setSuggestions(words);
             mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection);
@@ -2084,15 +2088,16 @@
     }
 
     private SuggestedWords getOlderSuggestions(final String typedWord) {
-        SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions();
-        if (previousSuggestions == mSettings.getCurrent().mSuggestPuncList) {
-            previousSuggestions = SuggestedWords.EMPTY;
+        SuggestedWords previousSuggestedWords = mSuggestedWords;
+        if (previousSuggestedWords == mSettings.getCurrent().mSuggestPuncList) {
+            previousSuggestedWords = SuggestedWords.EMPTY;
         }
         if (typedWord == null) {
-            return previousSuggestions;
+            return previousSuggestedWords;
         }
         final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
-                SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
+                SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord,
+                        previousSuggestedWords);
         return new SuggestedWords(typedWordAndPreviousSuggestions,
                 false /* typedWordValid */,
                 false /* hasAutoCorrectionCandidate */,
@@ -2114,7 +2119,7 @@
         }
         mWordComposer.setAutoCorrection(autoCorrection);
         final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
-        setSuggestionStrip(suggestedWords, isAutoCorrection);
+        setSuggestedWords(suggestedWords, isAutoCorrection);
         setAutoCorrectionIndicator(isAutoCorrection);
         setSuggestionStripShown(isSuggestionsStripVisible());
     }
@@ -2137,7 +2142,7 @@
                 Stats.onAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer);
             }
             if (ProductionFlag.IS_EXPERIMENTAL) {
-                final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
+                final SuggestedWords suggestedWords = mSuggestedWords;
                 ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
                         separatorString, mWordComposer.isBatchMode(), suggestedWords);
             }
@@ -2162,7 +2167,7 @@
     // interface
     @Override
     public void pickSuggestionManually(final int index, final String suggestion) {
-        final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
+        final SuggestedWords suggestedWords = mSuggestedWords;
         // If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
         if (suggestion.length() == 1 && isShowingPunctuationList()) {
             // Word separators are suggested before the user inputs something.
@@ -2194,6 +2199,7 @@
         if (mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()
                 && mApplicationSpecifiedCompletions != null
                 && index >= 0 && index < mApplicationSpecifiedCompletions.length) {
+            mSuggestedWords = SuggestedWords.EMPTY;
             if (mSuggestionStripView != null) {
                 mSuggestionStripView.clear();
             }
@@ -2249,7 +2255,7 @@
      */
     private void commitChosenWord(final String chosenWord, final int commitType,
             final String separatorString) {
-        final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
+        final SuggestedWords suggestedWords = mSuggestedWords;
         mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
                 this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1);
         // Add the word to the user history dictionary
@@ -2266,7 +2272,7 @@
         if (mSettings.getCurrent().mBigramPredictionEnabled) {
             clearSuggestionStrip();
         } else {
-            setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false);
+            setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
         }
         setAutoCorrectionIndicator(false);
         setSuggestionStripShown(isSuggestionsStripVisible());
@@ -2563,6 +2569,12 @@
         dialog.show();
     }
 
+    // TODO: can this be removed somehow without breaking the tests?
+    @UsedForTesting
+    /* package for test */ String getFirstSuggestedWord() {
+        return mSuggestedWords.size() > 0 ? mSuggestedWords.getWord(0) : null;
+    }
+
     public void debugDumpStateAndCrashWithException(final String context) {
         final StringBuilder s = new StringBuilder();
         s.append("Target application : ").append(mTargetApplicationInfo.name)
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index bc51d5d..5a29eee 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -644,10 +644,6 @@
         return false;
     }
 
-    public SuggestedWords getSuggestions() {
-        return mSuggestedWords;
-    }
-
     public void clear() {
         mSuggestionsStrip.removeAllViews();
         removeAllViews();
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 28fe1fe..a84dfdd 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -398,8 +398,10 @@
     EQUIVALENT_CHAR,
     // It is a char located nearby on the keyboard
     NEAR_PROXIMITY_CHAR,
-    // It is an unrelated char
+    // It is an unrelated char and could be a substitution char
     UNRELATED_CHAR,
+    // It is an unrelated char nor a substitution char
+    UNRELATED_NOR_SUBSTITUTION_CHAR,
     // Additional proximity char which can differ by language.
     ADDITIONAL_PROXIMITY_CHAR
 } ProximityType;
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
index 005f8b2..333b602 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
@@ -74,15 +74,22 @@
     public void testWordThenSpaceDisplaysPredictions() {
         final String WORD_TO_TYPE = "beaujolais ";
         final String EXPECTED_RESULT = "nouveau";
-        changeLanguage("fr");
-        type(WORD_TO_TYPE);
-        sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
-        runMessages();
-        final SuggestionStripView suggestionStripView =
-                (SuggestionStripView)mInputView.findViewById(R.id.suggestion_strip_view);
-        final SuggestedWords suggestedWords = suggestionStripView.getSuggestions();
-        assertEquals("type word then type space yields predictions for French",
-                EXPECTED_RESULT, suggestedWords.getWord(0));
+        final boolean defaultNextWordPredictionOption =
+                mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
+        final boolean previousNextWordPredictionOption =
+                setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, true,
+                        defaultNextWordPredictionOption);
+        try {
+            changeLanguage("fr");
+            type(WORD_TO_TYPE);
+            sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
+            runMessages();
+            assertEquals("type word then type space yields predictions for French",
+                    EXPECTED_RESULT, mLatinIME.getFirstSuggestedWord());
+        } finally {
+            setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
+                    defaultNextWordPredictionOption);
+        }
     }
 
     public void testAutoCorrectForGerman() {