Merge "Tweak vertical corrections for more keys in the "ICS" theme"
diff --git a/java/res/xml-sw600dp/rows_symbols.xml b/java/res/xml-sw600dp/rows_symbols.xml
index 96695e8..96503e8 100644
--- a/java/res/xml-sw600dp/rows_symbols.xml
+++ b/java/res/xml-sw600dp/rows_symbols.xml
@@ -89,9 +89,11 @@
         <Key
             latin:keyLabel="*"
             latin:moreKeys="@string/more_keys_for_star" />
+        <!-- U+2013: "–" EN DASH
+             U+2014: "—" EM DASH -->
         <Key
             latin:keyLabel="-"
-            latin:moreKeys="_,–,—" />
+            latin:moreKeys="_,&#x2013;,&#x2014;" />
         <Key
             latin:keyLabel="+"
             latin:moreKeys="@string/more_keys_for_plus" />
@@ -110,9 +112,11 @@
             latin:keyWidth="10.0%p" />
         <include
             latin:keyboardLayout="@xml/keys_less_greater" />
+        <!-- U+2260: "≠" NOT EQUAL TO
+             U+2248: "≈" ALMOST EQUAL TO -->
         <Key
             latin:keyLabel="="
-            latin:moreKeys="≠,≈" />
+            latin:moreKeys="&#x2260;,&#x2248;" />
         <switch>
             <case
                 latin:mode="url"
diff --git a/java/res/xml-sw768dp/rows_symbols.xml b/java/res/xml-sw768dp/rows_symbols.xml
index 96a86ec..a19af22 100644
--- a/java/res/xml-sw768dp/rows_symbols.xml
+++ b/java/res/xml-sw768dp/rows_symbols.xml
@@ -96,9 +96,11 @@
         <Key
             latin:keyLabel="*"
             latin:moreKeys="@string/more_keys_for_star" />
+        <!-- U+2013: "–" EN DASH
+             U+2014: "—" EM DASH -->
         <Key
             latin:keyLabel="-"
-            latin:moreKeys="_,–,—" />
+            latin:moreKeys="_,&#x2013;,&#x2014;" />
         <Key
             latin:keyLabel="+"
             latin:moreKeys="@string/more_keys_for_plus" />
@@ -117,9 +119,11 @@
             latin:keyWidth="13.829%p" />
         <include
             latin:keyboardLayout="@xml/keys_less_greater" />
+        <!-- U+2260: "≠" NOT EQUAL TO
+             U+2248: "≈" ALMOST EQUAL TO -->
         <Key
             latin:keyLabel="="
-            latin:moreKeys="≠,≈" />
+            latin:moreKeys="&#x2260;,&#x2248;" />
         <switch>
             <case
                 latin:mode="url"
diff --git a/java/res/xml/rows_symbols.xml b/java/res/xml/rows_symbols.xml
index 21f7d1d..6d0467c 100644
--- a/java/res/xml/rows_symbols.xml
+++ b/java/res/xml/rows_symbols.xml
@@ -87,9 +87,11 @@
         <Key
             latin:keyLabel="*"
             latin:moreKeys="@string/more_keys_for_star" />
+        <!-- U+2013: "–" EN DASH
+             U+2014: "—" EM DASH -->
         <Key
             latin:keyLabel="-"
-            latin:moreKeys="_,–,—" />
+            latin:moreKeys="_,&#x2013;,&#x2014;" />
         <Key
             latin:keyLabel="+"
             latin:moreKeys="@string/more_keys_for_plus" />
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 79c7ce0..f392383 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -108,8 +108,8 @@
     private static final int MORE_KEYS_COLUMN_MASK = 0x000000ff;
     private static final int MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER = 0x80000000;
     private static final int MORE_KEYS_FLAGS_HAS_LABELS = 0x40000000;
-    private static final int MORE_KEYS_FLAGS_NEEDS_DIVIDERS = 0x40000000;
-    private static final int MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY = 0x20000000;
+    private static final int MORE_KEYS_FLAGS_NEEDS_DIVIDERS = 0x20000000;
+    private static final int MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY = 0x10000000;
     private static final String MORE_KEYS_AUTO_COLUMN_ORDER = "!autoColumnOrder!";
     private static final String MORE_KEYS_FIXED_COLUMN_ORDER = "!fixedColumnOrder!";
     private static final String MORE_KEYS_HAS_LABELS = "!hasLabels!";
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index cb2a275..2042364 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1922,6 +1922,14 @@
         mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
                 mSettingsValues.mWordSeparators);
 
+        if (SPACE_STATE_PHANTOM == mSpaceState && suggestion.length() > 0) {
+            int firstChar = Character.codePointAt(suggestion, 0);
+            if ((!mSettingsValues.isWeakSpaceStripper(firstChar))
+                    && (!mSettingsValues.isWeakSpaceSwapper(firstChar))) {
+                sendKeyCodePoint(Keyboard.CODE_SPACE);
+            }
+        }
+
         if (mInputAttributes.mApplicationSpecifiedCompletionOn
                 && mApplicationSpecifiedCompletions != null
                 && index >= 0 && index < mApplicationSpecifiedCompletions.length) {
@@ -2293,6 +2301,14 @@
         }
         initSuggest();
         loadSettings();
+        // Since we just changed languages, we should re-evaluate suggestions with whatever word
+        // we are currently composing. If we are not composing anything, we may want to display
+        // predictions or punctuation signs (which is done by updateBigramPredictions anyway).
+        if (isCursorTouchingWord()) {
+            mHandler.postUpdateSuggestions();
+        } else {
+            mHandler.postUpdateBigramPredictions();
+        }
     }
 
     public void hapticAndAudioFeedback(int primaryCode) {
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index e3911f2..50aba7b 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -404,7 +404,32 @@
         type(WORD1_TO_TYPE);
         mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
         type(WORD2_TO_TYPE);
-        assertEquals("manual pick then space then type", WORD1_TO_TYPE + WORD2_TO_TYPE,
+        assertEquals("manual pick then space then type", EXPECTED_RESULT,
+                mTextView.getText().toString());
+    }
+
+    public void testManualPickThenManualPick() {
+        final String WORD1_TO_TYPE = "this";
+        final String WORD2_TO_PICK = "is";
+        final String EXPECTED_RESULT = "this is";
+        type(WORD1_TO_TYPE);
+        mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
+        // Here we fake picking a word through bigram prediction. This test is taking
+        // advantage of the fact that Latin IME blindly trusts the caller of #pickSuggestionManually
+        // to actually pass the right string.
+        mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK);
+        assertEquals("manual pick then manual pick", EXPECTED_RESULT,
+                mTextView.getText().toString());
+    }
+
+    public void testManualPickThenManualPickWithPunctAtStart() {
+        final String WORD1_TO_TYPE = "this";
+        final String WORD2_TO_PICK = "!is";
+        final String EXPECTED_RESULT = "this!is";
+        type(WORD1_TO_TYPE);
+        mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
+        mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK);
+        assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT,
                 mTextView.getText().toString());
     }