Merge "Fix the base character of D with stroke"
diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml
index 5f05e8b..e148622 100644
--- a/java/res/xml/method.xml
+++ b/java/res/xml/method.xml
@@ -28,7 +28,7 @@
     be_BY: Belarusian (Belarus)/east_slavic
     bg: Bulgarian/bulgarian
     bg: Bulgarian/bulgarian_bds
-    bn_BD: Bengali (Bangladesh)/bengali_akkhor # This is a preliminary keyboard layout.
+    bn_BD: Bengali (Bangladesh)/bengali_akkhor
     bn_IN: Bengali (India)/bengali
     ca: Catalan/spanish
     cs: Czech/qwertz
@@ -181,8 +181,6 @@
             android:imeSubtypeExtraValue="KeyboardLayoutSet=bulgarian_bds,EmojiCapable"
             android:isAsciiCapable="false"
     />
-    <!-- TODO: This Bengali (Bangladesh) keyboard is a preliminary layout.
-               This isn't based on the final specification. -->
     <subtype android:icon="@drawable/ic_ime_switcher_dark"
             android:label="@string/subtype_generic"
             android:subtypeId="0xa2144b0c"
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 719656b..2be8459 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1171,9 +1171,13 @@
                 SuggestedWords.getFromApplicationSpecifiedCompletions(
                         applicationSpecifiedCompletions);
         final SuggestedWords suggestedWords = new SuggestedWords(applicationSuggestedWords,
-                null /* rawSuggestions */, false /* typedWordValid */, false /* willAutoCorrect */,
+                null /* rawSuggestions */,
+                null /* typedWord */,
+                false /* typedWordValid */,
+                false /* willAutoCorrect */,
                 false /* isObsoleteSuggestions */,
-                SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED /* inputStyle */);
+                SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED /* inputStyle */,
+                SuggestedWords.NOT_A_SEQUENCE_NUMBER);
         // When in fullscreen mode, show completions generated by the application forcibly
         setSuggestedWords(suggestedWords);
     }
diff --git a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java
index a65304c..555bbc7 100644
--- a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java
@@ -33,10 +33,12 @@
     private PunctuationSuggestions(final ArrayList<SuggestedWordInfo> punctuationsList) {
         super(punctuationsList,
                 null /* rawSuggestions */,
+                null /* typedWord */,
                 false /* typedWordValid */,
                 false /* hasAutoCorrectionCandidate */,
                 false /* isObsoleteSuggestions */,
-                INPUT_STYLE_NONE /* inputStyle */);
+                INPUT_STYLE_NONE /* inputStyle */,
+                SuggestedWords.NOT_A_SEQUENCE_NUMBER);
     }
 
     /**
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index bddeac4..02b2d56 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -50,8 +50,9 @@
     private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST = new ArrayList<>(0);
     @Nonnull
     private static final SuggestedWords EMPTY = new SuggestedWords(
-            EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, false /* typedWordValid */,
-            false /* willAutoCorrect */, false /* isObsoleteSuggestions */, INPUT_STYLE_NONE);
+            EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, null /* typedWord */,
+            false /* typedWordValid */, false /* willAutoCorrect */,
+            false /* isObsoleteSuggestions */, INPUT_STYLE_NONE, NOT_A_SEQUENCE_NUMBER);
 
     public final String mTypedWord;
     public final boolean mTypedWordValid;
@@ -69,19 +70,6 @@
 
     public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
             final ArrayList<SuggestedWordInfo> rawSuggestions,
-            final boolean typedWordValid,
-            final boolean willAutoCorrect,
-            final boolean isObsoleteSuggestions,
-            final int inputStyle) {
-        this(suggestedWordInfoList, rawSuggestions,
-                (suggestedWordInfoList.isEmpty() || isPrediction(inputStyle)) ? null
-                        : suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
-                typedWordValid, willAutoCorrect,
-                isObsoleteSuggestions, inputStyle, NOT_A_SEQUENCE_NUMBER);
-    }
-
-    public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
-            final ArrayList<SuggestedWordInfo> rawSuggestions,
             final String typedWord,
             final boolean typedWordValid,
             final boolean willAutoCorrect,
@@ -423,8 +411,10 @@
                     info.mSourceDict, SuggestedWordInfo.NOT_AN_INDEX,
                     SuggestedWordInfo.NOT_A_CONFIDENCE));
         }
-        return new SuggestedWords(newSuggestions, null /* rawSuggestions */, mTypedWordValid,
-                mWillAutoCorrect, mIsObsoleteSuggestions, INPUT_STYLE_TAIL_BATCH);
+        return new SuggestedWords(newSuggestions, null /* rawSuggestions */,
+                newSuggestions.isEmpty() ? null : newSuggestions.get(0).mWord /* typedWord */,
+                mTypedWordValid, mWillAutoCorrect, mIsObsoleteSuggestions, INPUT_STYLE_TAIL_BATCH,
+                NOT_A_SEQUENCE_NUMBER);
     }
 
     /**
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index bafea17..e6d69a9 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -255,7 +255,7 @@
         handler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_TYPING);
         final String text = performSpecificTldProcessingOnTextInput(rawText);
         if (SpaceState.PHANTOM == mSpaceState) {
-            promotePhantomSpace(settingsValues);
+            insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
         }
         mConnection.commitText(text, 1);
         StatsUtils.onWordCommitUserTyped(mEnteredText, mWordComposer.isBatchMode());
@@ -322,7 +322,7 @@
             final int firstChar = Character.codePointAt(suggestion, 0);
             if (!settingsValues.isWordSeparator(firstChar)
                     || settingsValues.isUsuallyPrecededBySpace(firstChar)) {
-                promotePhantomSpace(settingsValues);
+                insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
             }
         }
 
@@ -584,7 +584,9 @@
                 if (candidate.mSourceDict.shouldAutoCommit(candidate)) {
                     final String[] commitParts = candidate.mWord.split(Constants.WORD_SEPARATOR, 2);
                     batchPointers.shift(candidate.mIndexOfTouchPointOfSecondWord);
-                    promotePhantomSpace(settingsValues);
+                    if (SpaceState.PHANTOM == mSpaceState) {
+                        insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
+                    }
                     mConnection.commitText(commitParts[0], 0);
                     StatsUtils.onWordCommitUserTyped(commitParts[0], mWordComposer.isBatchMode());
                     mSpaceState = SpaceState.PHANTOM;
@@ -861,7 +863,7 @@
                 // Sanity check
                 throw new RuntimeException("Should not be composing here");
             }
-            promotePhantomSpace(settingsValues);
+            insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
         }
 
         if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
@@ -972,7 +974,7 @@
         }
 
         if (needsPrecedingSpace) {
-            promotePhantomSpace(settingsValues);
+            insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
         }
 
         if (tryPerformDoubleSpacePeriod(event, inputTransaction)) {
@@ -1882,8 +1884,9 @@
         final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
                 SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
         return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
-                false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
-                true /* isObsoleteSuggestions */, oldSuggestedWords.mInputStyle);
+                typedWord, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
+                true /* isObsoleteSuggestions */, oldSuggestedWords.mInputStyle,
+                SuggestedWords.NOT_A_SEQUENCE_NUMBER);
     }
 
     /**
@@ -1960,14 +1963,14 @@
     }
 
     /**
-     * Promote a phantom space to an actual space.
+     * Insert an automatic space, if the options allow it.
      *
-     * This essentially inserts a space, and that's it. It just checks the options and the text
-     * before the cursor are appropriate before doing it.
+     * This checks the options and the text before the cursor are appropriate before inserting
+     * an automatic space.
      *
      * @param settingsValues the current values of the settings.
      */
-    private void promotePhantomSpace(final SettingsValues settingsValues) {
+    private void insertAutomaticSpaceIfOptionsAndTextAllow(final SettingsValues settingsValues) {
         if (settingsValues.shouldInsertSpacesAutomatically()
                 && settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
                 && !mConnection.textBeforeCursorLooksLikeURL()) {
@@ -1990,7 +1993,7 @@
         }
         mConnection.beginBatchEdit();
         if (SpaceState.PHANTOM == mSpaceState) {
-            promotePhantomSpace(settingsValues);
+            insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
         }
         final SuggestedWordInfo autoCommitCandidate = mSuggestedWords.getAutoCommitCandidate();
         // Commit except the last word for phrase gesture if the top suggestion is eligible for auto
diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
index 013f024..0e7f471 100644
--- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
@@ -34,6 +34,7 @@
 import java.util.Locale;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 /**
  * A helper class to deal with subtype locales.
@@ -273,7 +274,7 @@
     }
 
     @Nonnull
-    public static String getSubtypeNameForLogging(@Nonnull final InputMethodSubtype subtype) {
+    public static String getSubtypeNameForLogging(@Nullable final InputMethodSubtype subtype) {
         if (subtype == null) {
             return "<null subtype>";
         }
diff --git a/tests/src/com/android/inputmethod/compat/SuggestionSpanUtilsTest.java b/tests/src/com/android/inputmethod/compat/SuggestionSpanUtilsTest.java
index 1c320db..7bbf965 100644
--- a/tests/src/com/android/inputmethod/compat/SuggestionSpanUtilsTest.java
+++ b/tests/src/com/android/inputmethod/compat/SuggestionSpanUtilsTest.java
@@ -102,11 +102,11 @@
     }
 
     public void testGetTextWithSuggestionSpan() {
-        final SuggestedWordInfo predicition1 =
+        final SuggestedWordInfo prediction1 =
                 createWordInfo("Quality", SuggestedWordInfo.KIND_PREDICTION);
-        final SuggestedWordInfo predicition2 =
+        final SuggestedWordInfo prediction2 =
                 createWordInfo("Speed", SuggestedWordInfo.KIND_PREDICTION);
-        final SuggestedWordInfo predicition3 =
+        final SuggestedWordInfo prediction3 =
                 createWordInfo("Price", SuggestedWordInfo.KIND_PREDICTION);
 
         final SuggestedWordInfo typed =
@@ -122,13 +122,15 @@
         // is specified.
         {
             final SuggestedWords predictedWords = new SuggestedWords(
-                    new ArrayList<>(Arrays.asList(predicition1, predicition2, predicition3)),
+                    new ArrayList<>(Arrays.asList(prediction1, prediction2, prediction3)),
                     null /* rawSuggestions */,
+                    null /* typedWord */,
                     false /* typedWordValid */,
                     false /* willAutoCorrect */,
                     false /* isObsoleteSuggestions */,
-                    SuggestedWords.INPUT_STYLE_PREDICTION);
-            final String PICKED_WORD = predicition2.mWord;
+                    SuggestedWords.INPUT_STYLE_PREDICTION,
+                    SuggestedWords.NOT_A_SEQUENCE_NUMBER);
+            final String PICKED_WORD = prediction2.mWord;
             assertNotSuggestionSpan(
                     PICKED_WORD,
                     SuggestionSpanUtils.getTextWithSuggestionSpan(getContext(), PICKED_WORD,
@@ -137,17 +139,19 @@
 
         final ArrayList<SuggestedWordInfo> suggestedWordList = new ArrayList<>();
         suggestedWordList.add(typed);
-        suggestedWordList.add(predicition1);
-        suggestedWordList.add(predicition2);
-        suggestedWordList.add(predicition3);
+        suggestedWordList.add(prediction1);
+        suggestedWordList.add(prediction2);
+        suggestedWordList.add(prediction3);
         suggestedWordList.addAll(Arrays.asList(corrections));
         final SuggestedWords typedAndCollectedWords = new SuggestedWords(
                 suggestedWordList,
                 null /* rawSuggestions */,
+                null /* typedWord */,
                 false /* typedWordValid */,
                 false /* willAutoCorrect */,
                 false /* isObsoleteSuggestions */,
-                SuggestedWords.INPUT_STYLE_TYPING);
+                SuggestedWords.INPUT_STYLE_TYPING,
+                SuggestedWords.NOT_A_SEQUENCE_NUMBER);
 
         for (final SuggestedWordInfo pickedWord : suggestedWordList) {
             final String PICKED_WORD = pickedWord.mWord;
diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
index 90db75e..7a7edf0 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
@@ -99,10 +99,12 @@
         // Make sure getTypedWordInfoOrNull() returns non-null object.
         final SuggestedWords wordsWithTypedWord = new SuggestedWords(
                 list, null /* rawSuggestions */,
+                TYPED_WORD,
                 false /* typedWordValid */,
                 false /* willAutoCorrect */,
                 false /* isObsoleteSuggestions */,
-                SuggestedWords.INPUT_STYLE_NONE);
+                SuggestedWords.INPUT_STYLE_NONE,
+                SuggestedWords.NOT_A_SEQUENCE_NUMBER);
         final SuggestedWordInfo typedWord = wordsWithTypedWord.getTypedWordInfoOrNull();
         assertNotNull(typedWord);
         assertEquals(TYPED_WORD, typedWord.mWord);
@@ -111,10 +113,12 @@
         list.remove(0);
         final SuggestedWords wordsWithoutTypedWord = new SuggestedWords(
                 list, null /* rawSuggestions */,
+                null /* typedWord */,
                 false /* typedWordValid */,
                 false /* willAutoCorrect */,
                 false /* isObsoleteSuggestions */,
-                SuggestedWords.INPUT_STYLE_NONE);
+                SuggestedWords.INPUT_STYLE_NONE,
+                SuggestedWords.NOT_A_SEQUENCE_NUMBER);
         assertNull(wordsWithoutTypedWord.getTypedWordInfoOrNull());
 
         // Make sure getTypedWordInfoOrNull() returns null.
@@ -122,10 +126,12 @@
 
         final SuggestedWords emptySuggestedWords = new SuggestedWords(
                 new ArrayList<SuggestedWordInfo>(), null /* rawSuggestions */,
+                null /* typedWord */,
                 false /* typedWordValid */,
                 false /* willAutoCorrect */,
                 false /* isObsoleteSuggestions */,
-                SuggestedWords.INPUT_STYLE_NONE);
+                SuggestedWords.INPUT_STYLE_NONE,
+                SuggestedWords.NOT_A_SEQUENCE_NUMBER);
         assertNull(emptySuggestedWords.getTypedWordInfoOrNull());
 
         assertNull(SuggestedWords.getEmptyInstance().getTypedWordInfoOrNull());