Merge "Disable mic key on more keys when voice IME is disabled"
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index f815190..4bc9481 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -423,7 +423,7 @@
         <attr name="navigatePrevious" format="boolean" />
         <attr name="passwordInput" format="boolean" />
         <attr name="clobberSettingsKey" format="boolean" />
-        <attr name="shortcutKeyEnabled" format="boolean" />
+        <attr name="supportsSwitchingToShortcutIme" format="boolean" />
         <attr name="hasShortcutKey" format="boolean" />
         <attr name="languageSwitchKeyEnabled" format="boolean" />
         <attr name="isMultiLine" format="boolean" />
diff --git a/java/res/xml-sw600dp/key_shortcut.xml b/java/res/xml-sw600dp/key_shortcut.xml
index 87fc75c..c869e74 100644
--- a/java/res/xml-sw600dp/key_shortcut.xml
+++ b/java/res/xml-sw600dp/key_shortcut.xml
@@ -23,7 +23,7 @@
 >
     <switch>
         <case
-            latin:shortcutKeyEnabled="true"
+            latin:supportsSwitchingToShortcutIme="true"
             latin:clobberSettingsKey="false"
         >
             <Key
@@ -32,20 +32,20 @@
                 latin:moreKeys="!text/settings_as_more_key" />
         </case>
         <case
-            latin:shortcutKeyEnabled="true"
+            latin:supportsSwitchingToShortcutIme="true"
             latin:clobberSettingsKey="true"
         >
             <Key
                 latin:keyStyle="shortcutKeyStyle" />
         </case>
         <case
-            latin:shortcutKeyEnabled="false"
+            latin:supportsSwitchingToShortcutIme="false"
             latin:clobberSettingsKey="false"
         >
             <Key
                 latin:keyStyle="settingsKeyStyle" />
         </case>
-        <!-- shortcutKeyEnabled="false" clobberSettingsKey="true" -->
+        <!-- supportsSwitchingToShortcutIme="false" clobberSettingsKey="true" -->
         <default>
             <Spacer />
         </default>
diff --git a/java/res/xml/key_f1.xml b/java/res/xml/key_f1.xml
index 72e38cb..0e9d497 100644
--- a/java/res/xml/key_f1.xml
+++ b/java/res/xml/key_f1.xml
@@ -37,6 +37,16 @@
                 latin:keyStyle="f1MoreKeysStyle" />
         </case>
         <case
+            latin:supportsSwitchingToShortcutIme="false"
+        >
+            <Key
+                latin:keyLabel="!text/keylabel_for_comma"
+                latin:keyLabelFlags="hasPopupHint"
+                latin:additionalMoreKeys="!text/more_keys_for_comma"
+                latin:keyStyle="f1MoreKeysStyle" />
+        </case>
+        <!-- latin:supportsSwitchingToShortcutIme="true" -->
+        <case
             latin:hasShortcutKey="true"
         >
             <Key
diff --git a/java/res/xml/row_pcqwerty5.xml b/java/res/xml/row_pcqwerty5.xml
index 4ec908b..0a3f4d2 100644
--- a/java/res/xml/row_pcqwerty5.xml
+++ b/java/res/xml/row_pcqwerty5.xml
@@ -28,7 +28,7 @@
             latin:keyWidth="11.538%p" />
         <switch>
             <case
-                latin:shortcutKeyEnabled="true"
+                latin:supportsSwitchingToShortcutIme="true"
             >
                 <Key
                     latin:keyStyle="shortcutKeyStyle"
diff --git a/java/res/xml/row_symbols4.xml b/java/res/xml/row_symbols4.xml
index fbfdc5f..73d93c8 100644
--- a/java/res/xml/row_symbols4.xml
+++ b/java/res/xml/row_symbols4.xml
@@ -27,15 +27,6 @@
         latin:backgroundType="functional"
         latin:keyLabel="/" />
 
-    <switch>
-        <case latin:hasShortcutKey="true" >
-            <Key latin:keyStyle="shortcutKeyStyle" />
-        </case>
-        <!-- latin:hasShortcutKey="false" -->
-        <default>
-        </default>
-    </switch>
-
     <include latin:keyboardLayout="@xml/key_space_symbols" />
     <include latin:keyboardLayout="@xml/keys_comma_period" />
 
diff --git a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
index ec7b48a..561a801 100644
--- a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
+++ b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
@@ -412,7 +412,8 @@
         builder.setSubtype(SubtypeSwitcher.getInstance().getEmojiSubtype());
         builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res),
                 mEmojiLayoutParams.mEmojiKeyboardHeight);
-        builder.setOptions(false /* voiceKeyEnabled */, false /* lanuageSwitchKeyEnabled */);
+        builder.setOptions(false /* shortcutImeEnabled */, false /* showsVoiceInputKey */,
+                false /* languageSwitchKeyEnabled */);
         mEmojiCategory = new EmojiCategory(PreferenceManager.getDefaultSharedPreferences(context),
                 context.getResources(), builder.build());
         mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener(context);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 0159599..02beb3f 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -70,7 +70,7 @@
     public final int mElementId;
     private final EditorInfo mEditorInfo;
     public final boolean mClobberSettingsKey;
-    public final boolean mShortcutKeyEnabled;
+    public final boolean mSupportsSwitchingToShortcutIme;
     public final boolean mLanguageSwitchKeyEnabled;
     public final String mCustomActionLabel;
     public final boolean mHasShortcutKey;
@@ -86,11 +86,11 @@
         mElementId = elementId;
         mEditorInfo = params.mEditorInfo;
         mClobberSettingsKey = params.mNoSettingsKey;
-        mShortcutKeyEnabled = params.mVoiceKeyEnabled;
+        mSupportsSwitchingToShortcutIme = params.mSupportsSwitchingToShortcutIme;
         mLanguageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled;
         mCustomActionLabel = (mEditorInfo.actionLabel != null)
                 ? mEditorInfo.actionLabel.toString() : null;
-        mHasShortcutKey = mShortcutKeyEnabled && isAlphabetKeyboard(elementId);
+        mHasShortcutKey = mSupportsSwitchingToShortcutIme && params.mShowsVoiceInputKey;
 
         mHashCode = computeHashCode(this);
     }
@@ -103,7 +103,8 @@
                 id.mHeight,
                 id.passwordInput(),
                 id.mClobberSettingsKey,
-                id.mShortcutKeyEnabled,
+                id.mSupportsSwitchingToShortcutIme,
+                id.mHasShortcutKey,
                 id.mLanguageSwitchKeyEnabled,
                 id.isMultiLine(),
                 id.imeAction(),
@@ -123,7 +124,8 @@
                 && other.mHeight == mHeight
                 && other.passwordInput() == passwordInput()
                 && other.mClobberSettingsKey == mClobberSettingsKey
-                && other.mShortcutKeyEnabled == mShortcutKeyEnabled
+                && other.mSupportsSwitchingToShortcutIme == mSupportsSwitchingToShortcutIme
+                && other.mHasShortcutKey == mHasShortcutKey
                 && other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled
                 && other.isMultiLine() == isMultiLine()
                 && other.imeAction() == imeAction()
@@ -177,17 +179,17 @@
 
     @Override
     public String toString() {
-        return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s %s%s%s%s%s%s%s%s]",
+        return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s%s]",
                 elementIdToName(mElementId),
                 mLocale, mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
                 mWidth, mHeight,
                 modeName(mMode),
-                imeAction(),
-                (navigateNext() ? "navigateNext" : ""),
-                (navigatePrevious() ? "navigatePrevious" : ""),
+                actionName(imeAction()),
+                (navigateNext() ? " navigateNext" : ""),
+                (navigatePrevious() ? " navigatePrevious" : ""),
                 (mClobberSettingsKey ? " clobberSettingsKey" : ""),
                 (passwordInput() ? " passwordInput" : ""),
-                (mShortcutKeyEnabled ? " shortcutKeyEnabled" : ""),
+                (mSupportsSwitchingToShortcutIme ? " supportsSwitchingToShortcutIme" : ""),
                 (mHasShortcutKey ? " hasShortcutKey" : ""),
                 (mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""),
                 (isMultiLine() ? " isMultiLine" : "")
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index b3edd27..e5b814f 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -105,7 +105,10 @@
         int mMode;
         EditorInfo mEditorInfo;
         boolean mDisableTouchPositionCorrectionDataForTest;
-        boolean mVoiceKeyEnabled;
+        boolean mIsPasswordField;
+        boolean mSupportsSwitchingToShortcutIme;
+        boolean mShowsVoiceInputKey;
+        boolean mNoMicrophoneKey;
         boolean mNoSettingsKey;
         boolean mLanguageSwitchKeyEnabled;
         InputMethodSubtype mSubtype;
@@ -218,16 +221,24 @@
 
         private static final EditorInfo EMPTY_EDITOR_INFO = new EditorInfo();
 
-        public Builder(final Context context, final EditorInfo editorInfo) {
+        public Builder(final Context context, final EditorInfo ei) {
             mContext = context;
             mPackageName = context.getPackageName();
             mResources = context.getResources();
             final Params params = mParams;
 
+            final EditorInfo editorInfo = (ei != null) ? ei : EMPTY_EDITOR_INFO;
             params.mMode = getKeyboardMode(editorInfo);
-            params.mEditorInfo = (editorInfo != null) ? editorInfo : EMPTY_EDITOR_INFO;
+            params.mEditorInfo = editorInfo;
+            params.mIsPasswordField = InputTypeUtils.isPasswordInputType(editorInfo.inputType);
+            @SuppressWarnings("deprecation")
+            final boolean deprecatedNoMicrophone = InputAttributes.inPrivateImeOptions(
+                    null, NO_MICROPHONE_COMPAT, editorInfo);
+            params.mNoMicrophoneKey = InputAttributes.inPrivateImeOptions(
+                    mPackageName, NO_MICROPHONE, editorInfo)
+                    || deprecatedNoMicrophone;
             params.mNoSettingsKey = InputAttributes.inPrivateImeOptions(
-                    mPackageName, NO_SETTINGS_KEY, params.mEditorInfo);
+                    mPackageName, NO_SETTINGS_KEY, editorInfo);
         }
 
         public Builder setKeyboardGeometry(final int keyboardWidth, final int keyboardHeight) {
@@ -258,15 +269,11 @@
             return this;
         }
 
-        public Builder setOptions(final boolean voiceKeyEnabled,
-                final boolean languageSwitchKeyEnabled) {
-            @SuppressWarnings("deprecation")
-            final boolean deprecatedNoMicrophone = InputAttributes.inPrivateImeOptions(
-                    null, NO_MICROPHONE_COMPAT, mParams.mEditorInfo);
-            final boolean noMicrophone = InputAttributes.inPrivateImeOptions(
-                    mPackageName, NO_MICROPHONE, mParams.mEditorInfo)
-                    || deprecatedNoMicrophone;
-            mParams.mVoiceKeyEnabled = voiceKeyEnabled && !noMicrophone;
+        public Builder setOptions(final boolean isShortcutImeEnabled,
+                final boolean showsVoiceInputKey, final boolean languageSwitchKeyEnabled) {
+            mParams.mSupportsSwitchingToShortcutIme =
+                    isShortcutImeEnabled && !mParams.mNoMicrophoneKey && !mParams.mIsPasswordField;
+            mParams.mShowsVoiceInputKey = showsVoiceInputKey;
             mParams.mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled;
             return this;
         }
@@ -362,9 +369,6 @@
         }
 
         private static int getKeyboardMode(final EditorInfo editorInfo) {
-            if (editorInfo == null)
-                return KeyboardId.MODE_TEXT;
-
             final int inputType = editorInfo.inputType;
             final int variation = inputType & InputType.TYPE_MASK_VARIATION;
 
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index baea6bf..fb84f1d 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -154,7 +154,8 @@
         builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
         builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
         builder.setOptions(
-                settingsValues.isVoiceKeyEnabled(editorInfo),
+                mSubtypeSwitcher.isShortcutImeEnabled(),
+                settingsValues.mShowsVoiceInputKey,
                 settingsValues.isLanguageSwitchKeyEnabled());
         mKeyboardLayoutSet = builder.build();
         try {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index a8d7d9d..b31358f 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -649,8 +649,9 @@
                     R.styleable.Keyboard_Case_passwordInput, id.passwordInput());
             final boolean clobberSettingsKeyMatched = matchBoolean(caseAttr,
                     R.styleable.Keyboard_Case_clobberSettingsKey, id.mClobberSettingsKey);
-            final boolean shortcutKeyEnabledMatched = matchBoolean(caseAttr,
-                    R.styleable.Keyboard_Case_shortcutKeyEnabled, id.mShortcutKeyEnabled);
+            final boolean supportsSwitchingToShortcutImeMatched = matchBoolean(caseAttr,
+                    R.styleable.Keyboard_Case_supportsSwitchingToShortcutIme,
+                    id.mSupportsSwitchingToShortcutIme);
             final boolean hasShortcutKeyMatched = matchBoolean(caseAttr,
                     R.styleable.Keyboard_Case_hasShortcutKey, id.mHasShortcutKey);
             final boolean languageSwitchKeyEnabledMatched = matchBoolean(caseAttr,
@@ -669,7 +670,7 @@
             final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched
                     && modeMatched && navigateNextMatched && navigatePreviousMatched
                     && passwordInputMatched && clobberSettingsKeyMatched
-                    && shortcutKeyEnabledMatched && hasShortcutKeyMatched
+                    && supportsSwitchingToShortcutImeMatched && hasShortcutKeyMatched
                     && languageSwitchKeyEnabledMatched && isMultiLineMatched && imeActionMatched
                     && localeCodeMatched && languageCodeMatched && countryCodeMatched;
 
@@ -691,8 +692,9 @@
                                 "clobberSettingsKey"),
                         booleanAttr(caseAttr, R.styleable.Keyboard_Case_passwordInput,
                                 "passwordInput"),
-                        booleanAttr(caseAttr, R.styleable.Keyboard_Case_shortcutKeyEnabled,
-                                "shortcutKeyEnabled"),
+                        booleanAttr(
+                                caseAttr, R.styleable.Keyboard_Case_supportsSwitchingToShortcutIme,
+                                "supportsSwitchingToShortcutIme"),
                         booleanAttr(caseAttr, R.styleable.Keyboard_Case_hasShortcutKey,
                                 "hasShortcutKey"),
                         booleanAttr(caseAttr, R.styleable.Keyboard_Case_languageSwitchKeyEnabled,
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 032d44d..06406c1 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -67,7 +67,7 @@
     public final boolean mVibrateOn;
     public final boolean mSoundOn;
     public final boolean mKeyPreviewPopupOn;
-    private final boolean mShowsVoiceInputKey;
+    public final boolean mShowsVoiceInputKey;
     public final boolean mIncludesOtherImesInLanguageSwitchList;
     public final boolean mShowsLanguageSwitchKey;
     public final boolean mUseContactsDict;
@@ -271,13 +271,6 @@
         return mInputAttributes.mShouldInsertSpacesAutomatically;
     }
 
-    public boolean isVoiceKeyEnabled(final EditorInfo editorInfo) {
-        final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
-        final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
-        return shortcutImeEnabled && mShowsVoiceInputKey
-                && !InputTypeUtils.isPasswordInputType(inputType);
-    }
-
     public boolean isLanguageSwitchKeyEnabled() {
         if (!mShowsLanguageSwitchKey) {
             return false;
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index ad50992..28a647b 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -1357,8 +1357,9 @@
     private static final LogStatement LOGSTATEMENT_MAINKEYBOARDVIEW_SETKEYBOARD =
             new LogStatement("MainKeyboardViewSetKeyboard", false, false, "elementId", "locale",
                     "orientation", "width", "modeName", "action", "navigateNext",
-                    "navigatePrevious", "clobberSettingsKey", "passwordInput", "shortcutKeyEnabled",
-                    "hasShortcutKey", "languageSwitchKeyEnabled", "isMultiLine", "tw", "th",
+                    "navigatePrevious", "clobberSettingsKey", "passwordInput",
+                    "supportsSwitchingToShortcutIme", "hasShortcutKey", "languageSwitchKeyEnabled",
+                    "isMultiLine", "tw", "th",
                     "keys");
     public static void mainKeyboardView_setKeyboard(final Keyboard keyboard,
             final int orientation) {
@@ -1371,7 +1372,7 @@
                 kid.mLocale + ":" + kid.mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
                 orientation, kid.mWidth, KeyboardId.modeName(kid.mMode), kid.imeAction(),
                 kid.navigateNext(), kid.navigatePrevious(), kid.mClobberSettingsKey,
-                isPasswordView, kid.mShortcutKeyEnabled, kid.mHasShortcutKey,
+                isPasswordView, kid.mSupportsSwitchingToShortcutIme, kid.mHasShortcutKey,
                 kid.mLanguageSwitchKeyEnabled, kid.isMultiLine(), keyboard.mOccupiedWidth,
                 keyboard.mOccupiedHeight, keyboard.getKeys());
     }