Merge "Add RunInLocale class to guard locale switching"
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
index af10e75..667b109 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
@@ -28,8 +28,8 @@
 import android.view.inputmethod.EditorInfo;
 
 import com.android.inputmethod.compat.AudioManagerCompatWrapper;
-import com.android.inputmethod.compat.InputTypeCompatUtils;
 import com.android.inputmethod.compat.SettingsSecureCompatUtils;
+import com.android.inputmethod.latin.InputTypeUtils;
 import com.android.inputmethod.latin.R;
 
 public class AccessibilityUtils {
@@ -132,7 +132,7 @@
             return false;
 
         // Don't speak if the IME is connected to a password field.
-        return InputTypeCompatUtils.isPasswordInputType(editorInfo.inputType);
+        return InputTypeUtils.isPasswordInputType(editorInfo.inputType);
     }
 
     /**
diff --git a/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java b/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java
deleted file mode 100644
index 6c2f0f7..0000000
--- a/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.android.inputmethod.compat;
-
-import android.text.InputType;
-
-import java.lang.reflect.Field;
-
-public class InputTypeCompatUtils {
-    private static final Field FIELD_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS =
-            CompatUtils.getField(InputType.class, "TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS");
-    private static final Field FIELD_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD = CompatUtils
-            .getField(InputType.class, "TYPE_TEXT_VARIATION_WEB_PASSWORD");
-    private static final Field FIELD_InputType_TYPE_NUMBER_VARIATION_PASSWORD = CompatUtils
-            .getField(InputType.class, "TYPE_NUMBER_VARIATION_PASSWORD");
-    private static final Integer OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS =
-            (Integer) CompatUtils.getFieldValue(null, null,
-                    FIELD_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
-    private static final Integer OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD =
-            (Integer) CompatUtils.getFieldValue(null, null,
-                    FIELD_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD);
-    private static final Integer OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD =
-            (Integer) CompatUtils.getFieldValue(null, null,
-                    FIELD_InputType_TYPE_NUMBER_VARIATION_PASSWORD);
-    private static final int WEB_TEXT_PASSWORD_INPUT_TYPE;
-    private static final int WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
-    private static final int NUMBER_PASSWORD_INPUT_TYPE;
-    private static final int TEXT_PASSWORD_INPUT_TYPE =
-            InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
-    private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
-            InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
-
-    static {
-        WEB_TEXT_PASSWORD_INPUT_TYPE =
-            OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD != null
-                    ? InputType.TYPE_CLASS_TEXT | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD
-                    : 0;
-        WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE =
-            OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != null
-                    ? InputType.TYPE_CLASS_TEXT
-                            | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
-                    : 0;
-        NUMBER_PASSWORD_INPUT_TYPE =
-                OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD != null
-                        ? InputType.TYPE_CLASS_NUMBER | OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD
-                        : 0;
-    }
-
-    private static boolean isWebEditTextInputType(int inputType) {
-        return inputType == (InputType.TYPE_CLASS_TEXT
-                | InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
-    }
-
-    private static boolean isWebPasswordInputType(int inputType) {
-        return WEB_TEXT_PASSWORD_INPUT_TYPE != 0
-                && inputType == WEB_TEXT_PASSWORD_INPUT_TYPE;
-    }
-
-    private static boolean isWebEmailAddressInputType(int inputType) {
-        return WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE != 0
-                && inputType == WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
-    }
-
-    private static boolean isNumberPasswordInputType(int inputType) {
-        return NUMBER_PASSWORD_INPUT_TYPE != 0
-                && inputType == NUMBER_PASSWORD_INPUT_TYPE;
-    }
-
-    private static boolean isTextPasswordInputType(int inputType) {
-        return inputType == TEXT_PASSWORD_INPUT_TYPE;
-    }
-
-    private static boolean isWebEmailAddressVariation(int variation) {
-        return OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != null
-                && variation == OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
-    }
-
-    public static boolean isEmailVariation(int variation) {
-        return variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
-                || isWebEmailAddressVariation(variation);
-    }
-
-    public static boolean isWebInputType(int inputType) {
-        final int maskedInputType =
-                inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
-        return isWebEditTextInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
-                || isWebEmailAddressInputType(maskedInputType);
-    }
-
-    // Please refer to TextView.isPasswordInputType
-    public static boolean isPasswordInputType(int inputType) {
-        final int maskedInputType =
-                inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
-        return isTextPasswordInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
-                || isNumberPasswordInputType(maskedInputType);
-    }
-
-    // Please refer to TextView.isVisiblePasswordInputType
-    public static boolean isVisiblePasswordInputType(int inputType) {
-        final int maskedInputType =
-                inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
-        return maskedInputType == TEXT_VISIBLE_PASSWORD_INPUT_TYPE;
-    }
-}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index eef065f..e350818 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -21,7 +21,7 @@
 import android.view.inputmethod.EditorInfo;
 
 import com.android.inputmethod.compat.EditorInfoCompatUtils;
-import com.android.inputmethod.compat.InputTypeCompatUtils;
+import com.android.inputmethod.latin.InputTypeUtils;
 
 import java.util.Arrays;
 import java.util.Locale;
@@ -140,8 +140,8 @@
 
     public boolean passwordInput() {
         final int inputType = mEditorInfo.inputType;
-        return InputTypeCompatUtils.isPasswordInputType(inputType)
-                || InputTypeCompatUtils.isVisiblePasswordInputType(inputType);
+        return InputTypeUtils.isPasswordInputType(inputType)
+                || InputTypeUtils.isVisiblePasswordInputType(inputType);
     }
 
     public boolean isMultiLine() {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
index 0f3ae2f..263f17f 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -27,8 +27,8 @@
 import android.view.inputmethod.EditorInfo;
 
 import com.android.inputmethod.compat.EditorInfoCompatUtils;
-import com.android.inputmethod.compat.InputTypeCompatUtils;
 import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams;
+import com.android.inputmethod.latin.InputTypeUtils;
 import com.android.inputmethod.latin.LatinIME;
 import com.android.inputmethod.latin.LatinImeLogger;
 import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
@@ -387,7 +387,7 @@
             case InputType.TYPE_CLASS_PHONE:
                 return KeyboardId.MODE_PHONE;
             case InputType.TYPE_CLASS_TEXT:
-                if (InputTypeCompatUtils.isEmailVariation(variation)) {
+                if (InputTypeUtils.isEmailVariation(variation)) {
                     return KeyboardId.MODE_EMAIL;
                 } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) {
                     return KeyboardId.MODE_URL;
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
index 06c70c4..a6ce040 100644
--- a/java/src/com/android/inputmethod/latin/InputAttributes.java
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -20,8 +20,6 @@
 import android.util.Log;
 import android.view.inputmethod.EditorInfo;
 
-import com.android.inputmethod.compat.InputTypeCompatUtils;
-
 /**
  * Class to hold attributes of the input field.
  */
@@ -66,9 +64,9 @@
                     0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
 
             // Make sure that passwords are not displayed in {@link SuggestionsView}.
-            if (InputTypeCompatUtils.isPasswordInputType(inputType)
-                    || InputTypeCompatUtils.isVisiblePasswordInputType(inputType)
-                    || InputTypeCompatUtils.isEmailVariation(variation)
+            if (InputTypeUtils.isPasswordInputType(inputType)
+                    || InputTypeUtils.isVisiblePasswordInputType(inputType)
+                    || InputTypeUtils.isEmailVariation(variation)
                     || InputType.TYPE_TEXT_VARIATION_URI == variation
                     || InputType.TYPE_TEXT_VARIATION_FILTER == variation
                     || flagNoSuggestions
diff --git a/java/src/com/android/inputmethod/latin/InputTypeUtils.java b/java/src/com/android/inputmethod/latin/InputTypeUtils.java
new file mode 100644
index 0000000..40c3b76
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/InputTypeUtils.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin;
+
+import android.text.InputType;
+
+public class InputTypeUtils implements InputType {
+    private static final int WEB_TEXT_PASSWORD_INPUT_TYPE =
+            TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD;
+    private static final int WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE =
+            TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
+    private static final int NUMBER_PASSWORD_INPUT_TYPE =
+            TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD;
+    private static final int TEXT_PASSWORD_INPUT_TYPE =
+            TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD;
+    private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
+            TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+
+    private InputTypeUtils() {
+        // This utility class is not publicly instantiable.
+    }
+
+    private static boolean isWebEditTextInputType(int inputType) {
+        return inputType == (TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
+    }
+
+    private static boolean isWebPasswordInputType(int inputType) {
+        return WEB_TEXT_PASSWORD_INPUT_TYPE != 0
+                && inputType == WEB_TEXT_PASSWORD_INPUT_TYPE;
+    }
+
+    private static boolean isWebEmailAddressInputType(int inputType) {
+        return WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE != 0
+                && inputType == WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
+    }
+
+    private static boolean isNumberPasswordInputType(int inputType) {
+        return NUMBER_PASSWORD_INPUT_TYPE != 0
+                && inputType == NUMBER_PASSWORD_INPUT_TYPE;
+    }
+
+    private static boolean isTextPasswordInputType(int inputType) {
+        return inputType == TEXT_PASSWORD_INPUT_TYPE;
+    }
+
+    private static boolean isWebEmailAddressVariation(int variation) {
+        return variation == TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
+    }
+
+    public static boolean isEmailVariation(int variation) {
+        return variation == TYPE_TEXT_VARIATION_EMAIL_ADDRESS
+                || isWebEmailAddressVariation(variation);
+    }
+
+    public static boolean isWebInputType(int inputType) {
+        final int maskedInputType =
+                inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
+        return isWebEditTextInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
+                || isWebEmailAddressInputType(maskedInputType);
+    }
+
+    // Please refer to TextView.isPasswordInputType
+    public static boolean isPasswordInputType(int inputType) {
+        final int maskedInputType =
+                inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
+        return isTextPasswordInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
+                || isNumberPasswordInputType(maskedInputType);
+    }
+
+    // Please refer to TextView.isVisiblePasswordInputType
+    public static boolean isVisiblePasswordInputType(int inputType) {
+        final int maskedInputType =
+                inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
+        return maskedInputType == TEXT_VISIBLE_PASSWORD_INPUT_TYPE;
+    }
+}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 1eb9c8d..db57044 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1186,7 +1186,7 @@
         return keyboard != null ? keyboard.mId.imeActionId() : EditorInfo.IME_ACTION_NONE;
     }
 
-    private void performeEditorAction(int actionId) {
+    private void performEditorAction(int actionId) {
         final InputConnection ic = getCurrentInputConnection();
         if (ic != null) {
             ic.performEditorAction(actionId);
@@ -1277,13 +1277,13 @@
             mSubtypeSwitcher.switchToShortcutIME();
             break;
         case Keyboard.CODE_ACTION_ENTER:
-            performeEditorAction(getActionId(switcher.getKeyboard()));
+            performEditorAction(getActionId(switcher.getKeyboard()));
             break;
         case Keyboard.CODE_ACTION_NEXT:
-            performeEditorAction(EditorInfo.IME_ACTION_NEXT);
+            performEditorAction(EditorInfo.IME_ACTION_NEXT);
             break;
         case Keyboard.CODE_ACTION_PREVIOUS:
-            performeEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
+            performEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
             break;
         case Keyboard.CODE_LANGUAGE_SWITCH:
             handleLanguageSwitchKey();
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index f2abb9c..1036784 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -22,7 +22,6 @@
 import android.util.Log;
 import android.view.inputmethod.EditorInfo;
 
-import com.android.inputmethod.compat.InputTypeCompatUtils;
 import com.android.inputmethod.keyboard.internal.KeySpecParser;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 
@@ -278,7 +277,7 @@
         final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
         final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
         return shortcutImeEnabled && mVoiceKeyEnabled
-                && !InputTypeCompatUtils.isPasswordInputType(inputType);
+                && !InputTypeUtils.isPasswordInputType(inputType);
     }
 
     public boolean isVoiceKeyOnMain() {