Merge "Fix "touch to save" colors"
diff --git a/java/res/xml/spellchecker.xml b/java/res/xml/spellchecker.xml
index ce09264..30fac5b 100644
--- a/java/res/xml/spellchecker.xml
+++ b/java/res/xml/spellchecker.xml
@@ -23,11 +23,23 @@
 <spell-checker xmlns:android="http://schemas.android.com/apk/res/android"
         android:label="@string/spell_checker_service_name">
     <subtype
-            android:label="@string/subtype_en_US"
-            android:subtypeLocale="en_US"
+            android:label="@string/subtype_generic"
+            android:subtypeLocale="en"
     />
     <subtype
-            android:label="@string/subtype_en_GB"
-            android:subtypeLocale="en_GB"
+            android:label="@string/subtype_generic"
+            android:subtypeLocale="fr"
+    />
+    <subtype
+            android:label="@string/subtype_generic"
+            android:subtypeLocale="de"
+    />
+    <subtype
+            android:label="@string/subtype_generic"
+            android:subtypeLocale="it"
+    />
+    <subtype
+            android:label="@string/subtype_generic"
+            android:subtypeLocale="es"
     />
 </spell-checker>
diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
index 2396222..c3b5825 100644
--- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
@@ -213,9 +213,10 @@
         final int pointY = parentKey.mY;
         final int miniKeyboardLeft = pointX - miniKeyboard.getDefaultCoordX()
                 + parentKeyboardView.getPaddingLeft();
-        final int x = Math.max(0, Math.min(miniKeyboardLeft,
+        final int x = wrapUp(Math.max(0, Math.min(miniKeyboardLeft,
                 parentKeyboardView.getWidth() - miniKeyboard.mOccupiedWidth))
-                - container.getPaddingLeft() + mCoordinates[0];
+                - container.getPaddingLeft() + mCoordinates[0],
+                container.getMeasuredWidth(), 0, parentKeyboardView.getWidth());
         final int y = pointY - parentKeyboard.mVerticalGap
                 - (container.getMeasuredHeight() - container.getPaddingBottom())
                 + parentKeyboardView.getPaddingTop() + mCoordinates[1];
@@ -232,6 +233,14 @@
         mOriginY = y + container.getPaddingTop() - mCoordinates[1];
     }
 
+    private static int wrapUp(int x, int width, int left, int right) {
+        if (x < left)
+            return left;
+        if (x + width > right)
+            return right - width;
+        return x;
+    }
+
     @Override
     public boolean dismissPopupPanel() {
         return mParentKeyboardView.dismissPopupPanel();
diff --git a/native/src/correction.cpp b/native/src/correction.cpp
index fcb8bea..ce4a869 100644
--- a/native/src/correction.cpp
+++ b/native/src/correction.cpp
@@ -490,8 +490,7 @@
             const uint16_t cost = (ci == co) ? 0 : 1;
             dp[(i + 1) * lo + (j + 1)] = min(dp[i * lo + (j + 1)] + 1,
                     min(dp[(i + 1) * lo + j] + 1, dp[i * lo + j] + cost));
-            if (li > 0 && lo > 0
-                    && ci == Dictionary::toBaseLowerCase(output[j - 1])
+            if (ci == Dictionary::toBaseLowerCase(output[j - 1])
                     && co == Dictionary::toBaseLowerCase(input[i - 1])) {
                 dp[(i + 1) * lo + (j + 1)] = min(
                         dp[(i + 1) * lo + (j + 1)], dp[(i - 1) * lo + (j - 1)] + cost);