Hide shortcut key when the shortcut IME is not enabled

Bug: 3398726
Change-Id: I5e1bfc1fec9047c1c4e4f29fbf79f0fdf9356ffb
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
index 2632796..feb56ab 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
@@ -447,7 +447,8 @@
                     textAttr(KeyboardId.modeName(
                             a.getInt(R.styleable.Keyboard_Case_mode, -1)), "mode"),
                     textAttr(KeyboardId.colorSchemeName(
-                            a.getInt(R.styleable.KeyboardView_colorScheme, -1)), "colorSchemeName"),
+                            viewAttr.getInt(
+                                    R.styleable.KeyboardView_colorScheme, -1)), "colorSchemeName"),
                     booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, "passwordInput"),
                     booleanAttr(a, R.styleable.Keyboard_Case_hasSettingsKey, "hasSettingsKey"),
                     booleanAttr(a, R.styleable.Keyboard_Case_voiceKeyEnabled, "voiceKeyEnabled"),
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 3d34e71..64a23ab 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -194,7 +194,7 @@
         // displayed on its spacebar, it might have had arbitrary text fade factor. In such case,
         // we should reset the text fade factor. It is also applicable to shortcut key.
         keyboard.setSpacebarTextFadeFactor(0.0f, null);
-        keyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutAvailable(), null);
+        keyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady(), null);
         return keyboard;
     }
 
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d0d0b72..feaebb9 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -547,7 +547,8 @@
         // Most such things we decide below in initializeInputAttributesAndGetMode, but we need to
         // know now whether this is a password text field, because we need to know now whether we
         // want to enable the voice button.
-        mVoiceConnector.resetVoiceStates(Utils.isPasswordInputType(attribute.inputType)
+        final VoiceIMEConnector voiceIme = mVoiceConnector;
+        voiceIme.resetVoiceStates(Utils.isPasswordInputType(attribute.inputType)
                 || Utils.isVisiblePasswordInputType(attribute.inputType));
 
         initializeInputAttributes(attribute);
@@ -562,8 +563,8 @@
         loadSettings(attribute);
         if (mSubtypeSwitcher.isKeyboardMode()) {
             switcher.loadKeyboard(attribute,
-                    mVoiceConnector.isVoiceButtonEnabled(),
-                    mVoiceConnector.isVoiceButtonOnPrimary());
+                    mSubtypeSwitcher.isShortcutImeEnabled() && voiceIme.isVoiceButtonEnabled(),
+                    voiceIme.isVoiceButtonOnPrimary());
             switcher.updateShiftState();
         }
 
@@ -583,7 +584,7 @@
         checkRecorrectionOnStart();
         inputView.setForeground(true);
 
-        mVoiceConnector.onStartInputView(inputView.getWindowToken());
+        voiceIme.onStartInputView(inputView.getWindowToken());
 
         if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
     }
@@ -1930,7 +1931,8 @@
         }
         // Reload keyboard because the current language has been changed.
         mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(),
-                mVoiceConnector.isVoiceButtonEnabled(), mVoiceConnector.isVoiceButtonOnPrimary());
+                mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceConnector.isVoiceButtonEnabled(),
+                mVoiceConnector.isVoiceButtonOnPrimary());
         initSuggest();
         mKeyboardSwitcher.updateShiftState();
     }
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 50827c6..dc14d77 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -46,7 +46,7 @@
 
 public class SubtypeSwitcher {
     private static boolean DBG = LatinImeLogger.sDBG;
-    private static final String TAG = "SubtypeSwitcher";
+    private static final String TAG = SubtypeSwitcher.class.getSimpleName();
 
     private static final char LOCALE_SEPARATER = '_';
     private static final String KEYBOARD_MODE = "keyboard";
@@ -221,7 +221,7 @@
             newMode = newSubtype.getMode();
         }
         if (DBG) {
-            Log.w(TAG, "Update subtype to:" + newLocale + "," + newSubtype.getMode()
+            Log.w(TAG, "Update subtype to:" + newLocale + "," + newMode
                     + ", from: " + mInputLocaleStr + ", " + oldMode);
         }
         boolean languageChanged = false;
@@ -355,11 +355,27 @@
         return false;
     }
 
-    public boolean isShortcutAvailable() {
+    public boolean isShortcutImeEnabled() {
         if (mShortcutInputMethodInfo == null)
             return false;
-        if (mShortcutSubtype != null && contains(mShortcutSubtype.getExtraValue().split(","),
-                    SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY)) {
+        if (mShortcutSubtype == null)
+            return true;
+        final boolean allowsImplicitlySelectedSubtypes = true;
+        for (final InputMethodSubtype enabledSubtype : mImm.getEnabledInputMethodSubtypeList(
+                mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
+            if (enabledSubtype.equals(mShortcutSubtype))
+                return true;
+        }
+        return false;
+    }
+
+    public boolean isShortcutImeReady() {
+        if (mShortcutInputMethodInfo == null)
+            return false;
+        if (mShortcutSubtype == null)
+            return true;
+        if (contains(mShortcutSubtype.getExtraValue().split(","),
+                SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY)) {
             return mIsNetworkConnected;
         }
         return true;
@@ -373,7 +389,7 @@
         final KeyboardSwitcher switcher = KeyboardSwitcher.getInstance();
         final LatinKeyboard keyboard = switcher.getLatinKeyboard();
         if (keyboard != null) {
-            keyboard.updateShortcutKey(isShortcutAvailable(), switcher.getInputView());
+            keyboard.updateShortcutKey(isShortcutImeReady(), switcher.getInputView());
         }
     }