am 76d6673b: Merge "Fix checking if subtype belongs to this ime" into jb-dev

* commit '76d6673b2aa7b7ae0511169e4cc576b7c51440ac':
  Fix checking if subtype belongs to this ime
diff --git a/java/src/com/android/inputmethod/latin/ImfUtils.java b/java/src/com/android/inputmethod/latin/ImfUtils.java
index af46a02..36f6d8b 100644
--- a/java/src/com/android/inputmethod/latin/ImfUtils.java
+++ b/java/src/com/android/inputmethod/latin/ImfUtils.java
@@ -63,7 +63,8 @@
         return getInputMethodInfoOfThisIme(context).getId();
     }
 
-    public static boolean checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) {
+    public static boolean checkIfSubtypeBelongsToThisImeAndEnabled(Context context,
+            InputMethodSubtype ims) {
         final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context);
         final InputMethodManager imm = getInputMethodManager(context);
         // TODO: Cache all subtypes of this IME for optimization
@@ -76,6 +77,19 @@
         return false;
     }
 
+    public static boolean checkIfSubtypeBelongsToThisIme(Context context,
+            InputMethodSubtype ims) {
+        final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context);
+        final int count = myImi.getSubtypeCount();
+        for (int i = 0; i < count; i++) {
+            final InputMethodSubtype subtype = myImi.getSubtypeAt(i);
+            if (subtype.equals(ims)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     public static boolean hasMultipleEnabledIMEsOrSubtypes(Context context,
             final boolean shouldIncludeAuxiliarySubtypes) {
         final InputMethodManager imm = getInputMethodManager(context);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index c638118..7efdef9 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1148,8 +1148,8 @@
         final IBinder token = getWindow().getWindow().getAttributes().token;
         if (mShouldSwitchToLastSubtype) {
             final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype();
-            final boolean lastSubtypeBelongsToThisIme = ImfUtils.checkIfSubtypeBelongsToThisIme(
-                    this, lastSubtype);
+            final boolean lastSubtypeBelongsToThisIme =
+                    ImfUtils.checkIfSubtypeBelongsToThisImeAndEnabled(this, lastSubtype);
             if ((includesOtherImes || lastSubtypeBelongsToThisIme)
                     && mImm.switchToLastInputMethod(token)) {
                 mShouldSwitchToLastSubtype = false;