Merge "Stop overriding SuggestionStripView.dispatchTouchEvent"
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index d0d5399..0043b78 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -204,19 +204,6 @@
     }
 
     /**
-     * Intercepts touch events before dispatch when touch exploration is turned on in ICS and
-     * higher.
-     *
-     * @param event The motion event being dispatched.
-     * @return {@code true} if the event is handled
-     */
-    public boolean dispatchTouchEvent(final MotionEvent event) {
-        // To avoid accidental key presses during touch exploration, always drop
-        // touch events generated by the user.
-        return false;
-    }
-
-    /**
      * Receives hover events when touch exploration is turned on in SDK versions ICS and higher.
      *
      * @param event The hover event.
diff --git a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java
index b119d6c..4ea7fb8 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java
@@ -19,7 +19,10 @@
 import android.os.Build;
 import android.view.inputmethod.InputMethodSubtype;
 
+import com.android.inputmethod.latin.Constants;
+
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 
 public final class InputMethodSubtypeCompatUtils {
     private static final String TAG = InputMethodSubtypeCompatUtils.class.getSimpleName();
@@ -37,6 +40,12 @@
             }
         }
     }
+
+    // Note that {@link InputMethodSubtype#isAsciiCapable()} has been introduced in API level 19
+    // (Build.VERSION_CODE.KITKAT).
+    private static final Method METHOD_isAsciiCapable = CompatUtils.getMethod(
+            InputMethodSubtype.class, "isAsciiCapable");
+
     private InputMethodSubtypeCompatUtils() {
         // This utility class is not publicly instantiable.
     }
@@ -53,4 +62,9 @@
                 nameId, iconId, locale, mode, extraValue, isAuxiliary,
                 overridesImplicitlyEnabledSubtype, id);
     }
+
+    public static boolean isAsciiCapable(final InputMethodSubtype subtype) {
+        return (Boolean)CompatUtils.invoke(subtype, false, METHOD_isAsciiCapable)
+                || subtype.containsExtraValueKey(Constants.Subtype.ExtraValue.ASCII_CAPABLE);
+    }
 }
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index e5b814f..cde5091 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -20,7 +20,6 @@
 import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE;
 import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT;
 import static com.android.inputmethod.latin.Constants.ImeOption.NO_SETTINGS_KEY;
-import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
 
 import android.content.Context;
 import android.content.res.Resources;
@@ -34,6 +33,7 @@
 import android.view.inputmethod.InputMethodSubtype;
 
 import com.android.inputmethod.compat.EditorInfoCompatUtils;
+import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
 import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
 import com.android.inputmethod.keyboard.internal.KeyboardParams;
 import com.android.inputmethod.keyboard.internal.KeysCache;
@@ -248,7 +248,7 @@
         }
 
         public Builder setSubtype(final InputMethodSubtype subtype) {
-            final boolean asciiCapable = subtype.containsExtraValueKey(ASCII_CAPABLE);
+            final boolean asciiCapable = InputMethodSubtypeCompatUtils.isAsciiCapable(subtype);
             @SuppressWarnings("deprecation")
             final boolean deprecatedForceAscii = InputAttributes.inPrivateImeOptions(
                     mPackageName, FORCE_ASCII, mParams.mEditorInfo);
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index bd955ae..6c56b8a 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -726,14 +726,6 @@
     }
 
     @Override
-    public boolean dispatchTouchEvent(MotionEvent event) {
-        if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
-            return AccessibleKeyboardViewProxy.getInstance().dispatchTouchEvent(event);
-        }
-        return super.dispatchTouchEvent(event);
-    }
-
-    @Override
     public boolean onTouchEvent(final MotionEvent me) {
         if (getKeyboard() == null) {
             return false;
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
index b01bc4b..01c17f2 100644
--- a/java/src/com/android/inputmethod/latin/InputAttributes.java
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -31,6 +31,7 @@
 
     final public String mTargetApplicationPackageName;
     final public boolean mInputTypeNoAutoCorrect;
+    final public boolean mIsPasswordField;
     final public boolean mIsSettingsSuggestionStripOn;
     final public boolean mApplicationSpecifiedCompletionOn;
     final public boolean mShouldInsertSpacesAutomatically;
@@ -56,6 +57,7 @@
                 Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
                         + " imeOptions=0x%08x", inputType, editorInfo.imeOptions));
             }
+            mIsPasswordField = false;
             mIsSettingsSuggestionStripOn = false;
             mInputTypeNoAutoCorrect = false;
             mApplicationSpecifiedCompletionOn = false;
@@ -71,10 +73,11 @@
             final boolean flagAutoComplete =
                     0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
 
+            mIsPasswordField = InputTypeUtils.isPasswordInputType(inputType)
+                    || InputTypeUtils.isVisiblePasswordInputType(inputType);
             // TODO: Have a helper method in InputTypeUtils
             // Make sure that passwords are not displayed in {@link SuggestionStripView}.
-            if (InputTypeUtils.isPasswordInputType(inputType)
-                    || InputTypeUtils.isVisiblePasswordInputType(inputType)
+            if (mIsPasswordField
                     || InputTypeUtils.isEmailVariation(variation)
                     || InputType.TYPE_TEXT_VARIATION_URI == variation
                     || InputType.TYPE_TEXT_VARIATION_FILTER == variation
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d69fbb1..1631a20 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1327,10 +1327,10 @@
             return false;
         if (mSuggestionStripView.isShowingAddToDictionaryHint())
             return true;
-        if (ImportantNoticeUtils.hasNewImportantNoticeAndNotInSetupWizard(this))
-            return true;
         if (null == currentSettings)
             return false;
+        if (ImportantNoticeUtils.shouldShowImportantNotice(this, currentSettings.mInputAttributes))
+            return true;
         if (!currentSettings.isSuggestionStripVisible())
             return false;
         if (currentSettings.isApplicationSpecifiedCompletionsOn())
@@ -1359,11 +1359,13 @@
     public void setSuggestedWords(final SuggestedWords suggestedWords, final boolean shouldShow) {
         mInputLogic.setSuggestedWords(suggestedWords);
         if (mSuggestionStripView != null) {
+            final SettingsValues currentSettings = mSettings.getCurrent();
             final boolean showSuggestions;
             if (SuggestedWords.EMPTY == suggestedWords
                     || suggestedWords.isPunctuationSuggestions()
-                    || !mSettings.getCurrent().isSuggestionsRequested()) {
-                showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle();
+                    || !currentSettings.isSuggestionsRequested()) {
+                showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle(
+                        currentSettings.mInputAttributes);
             } else {
                 showSuggestions = true;
             }
diff --git a/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java
index 4bf524c..6dae620 100644
--- a/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java
@@ -16,8 +16,6 @@
 
 package com.android.inputmethod.latin.settings;
 
-import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
-
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.Context;
@@ -44,6 +42,8 @@
 import android.widget.SpinnerAdapter;
 import android.widget.Toast;
 
+import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
+import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.RichInputMethodManager;
 import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
@@ -111,7 +111,7 @@
                             subtype.getLocale(), subtype.hashCode(), subtype.hashCode(),
                             SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype)));
                 }
-                if (subtype.containsExtraValueKey(ASCII_CAPABLE)) {
+                if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) {
                     items.add(createItem(context, subtype.getLocale()));
                 }
             }
@@ -287,7 +287,7 @@
                 final KeyboardLayoutSetItem layout =
                         (KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem();
                 final InputMethodSubtype subtype = AdditionalSubtypeUtils.createAdditionalSubtype(
-                        locale.first, layout.first, ASCII_CAPABLE);
+                        locale.first, layout.first, Constants.Subtype.ExtraValue.ASCII_CAPABLE);
                 setSubtype(subtype);
                 notifyChanged();
                 if (isEditing) {
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index 310771e..90b9692 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -39,11 +39,13 @@
 import com.android.inputmethod.keyboard.MoreKeysPanel;
 import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
 import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.InputAttributes;
 import com.android.inputmethod.latin.LatinImeLogger;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.SuggestedWords;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.define.ProductionFlag;
+import com.android.inputmethod.latin.settings.Settings;
 import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
 import com.android.inputmethod.latin.utils.CollectionUtils;
 import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
@@ -226,8 +228,8 @@
     // This method checks if we should show the important notice (checks on permanent storage if
     // it has been shown once already or not, and if in the setup wizard). If applicable, it shows
     // the notice. In all cases, it returns true if it was shown, false otherwise.
-    public boolean maybeShowImportantNoticeTitle() {
-        if (!ImportantNoticeUtils.hasNewImportantNoticeAndNotInSetupWizard(getContext())) {
+    public boolean maybeShowImportantNoticeTitle(final InputAttributes inputAttributes) {
+        if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext(), inputAttributes)) {
             return false;
         }
         final int width = getWidth();
@@ -430,6 +432,6 @@
     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
         // Called by the framework when the size is known. Show the important notice if applicable.
         // This may be overriden by showing suggestions later, if applicable.
-        maybeShowImportantNoticeTitle();
+        maybeShowImportantNoticeTitle(Settings.getInstance().getCurrent().mInputAttributes);
     }
 }
diff --git a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
index 604c364..50a9423 100644
--- a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
@@ -22,6 +22,7 @@
 import android.provider.Settings.SettingNotFoundException;
 import android.util.Log;
 
+import com.android.inputmethod.latin.InputAttributes;
 import com.android.inputmethod.latin.R;
 
 public final class ImportantNoticeUtils {
@@ -62,11 +63,18 @@
         return context.getResources().getInteger(R.integer.config_important_notice_version);
     }
 
-    public static boolean hasNewImportantNoticeAndNotInSetupWizard(final Context context) {
+    private static boolean hasNewImportantNotice(final Context context) {
         final SharedPreferences prefs = getImportantNoticePreferences(context);
         final int lastVersion = prefs.getInt(KEY_IMPORTANT_NOTICE_VERSION, 0);
-        return getCurrentImportantNoticeVersion(context) > lastVersion
-                && !isInSystemSetupWizard(context);
+        return getCurrentImportantNoticeVersion(context) > lastVersion;
+    }
+
+    public static boolean shouldShowImportantNotice(final Context context,
+            final InputAttributes inputAttributes) {
+        if (inputAttributes == null || inputAttributes.mIsPasswordField) {
+            return false;
+        }
+        return hasNewImportantNotice(context) && !isInSystemSetupWizard(context);
     }
 
     public static void updateLastImportantNoticeVersion(final Context context) {
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index 06b64b4..4b157e7 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -35,6 +35,7 @@
 import android.widget.EditText;
 import android.widget.FrameLayout;
 
+import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
 import com.android.inputmethod.keyboard.Key;
 import com.android.inputmethod.keyboard.Keyboard;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
@@ -290,17 +291,25 @@
 
     protected void changeLanguageWithoutWait(final String locale) {
         mEditText.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale);
-        final InputMethodSubtype subtype = new InputMethodSubtype(
-            R.string.subtype_no_language_qwerty, R.drawable.ic_ime_switcher_dark,
-            locale, "keyboard", "KeyboardLayoutSet="
-                    // TODO: this is forcing a QWERTY keyboard for all locales, which is wrong.
-                    // It's still better than using whatever keyboard is the current one, but we
-                    // should actually use the default keyboard for this locale.
-                    + SubtypeLocaleUtils.QWERTY
-                    + "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE
-                    + "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE
-                    + "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE,
-                    false /* isAuxiliary */, false /* overridesImplicitlyEnabledSubtype */);
+        // TODO: this is forcing a QWERTY keyboard for all locales, which is wrong.
+        // It's still better than using whatever keyboard is the current one, but we
+        // should actually use the default keyboard for this locale.
+        // TODO: Use {@link InputMethodSubtype.InputMethodSubtypeBuilder} directly or indirectly so
+        // that {@link InputMethodSubtype#isAsciiCapable} can return the correct value.
+        final String EXTRA_VALUE_FOR_TEST =
+                "KeyboardLayoutSet=" + SubtypeLocaleUtils.QWERTY
+                + "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE
+                + "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE
+                + "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE;
+        final InputMethodSubtype subtype = InputMethodSubtypeCompatUtils.newInputMethodSubtype(
+                R.string.subtype_no_language_qwerty,
+                R.drawable.ic_ime_switcher_dark,
+                locale,
+                Constants.Subtype.KEYBOARD_MODE,
+                EXTRA_VALUE_FOR_TEST,
+                false /* isAuxiliary */,
+                false /* overridesImplicitlyEnabledSubtype */,
+                0 /* id */);
         SubtypeSwitcher.getInstance().forceSubtype(subtype);
         mLatinIME.loadKeyboard();
         runMessages();