hide voice input key and disable setting if not available

This commit is contained in:
Helium 2022-03-21 08:57:14 +01:00
parent e9393dfab0
commit 7fdb5954d0
3 changed files with 8 additions and 3 deletions

View file

@ -584,6 +584,10 @@ public class RichInputMethodManager {
switchToTargetIME(imiId, mShortcutSubtype, context);
}
public boolean hasShortcutIme() {
return mShortcutInputMethodInfo != null;
}
private void switchToTargetIME(final String imiId, final InputMethodSubtype subtype,
final InputMethodService context) {
final IBinder token = context.getWindow().getWindow().getAttributes().token;

View file

@ -70,8 +70,9 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
final Preference voiceInputKeyOption = findPreference(Settings.PREF_VOICE_INPUT_KEY);
if (voiceInputKeyOption != null) {
RichInputMethodManager.getInstance().refreshSubtypeCaches();
voiceInputKeyOption.setEnabled(VOICE_IME_ENABLED);
voiceInputKeyOption.setSummary(VOICE_IME_ENABLED
boolean voiceKeyEnabled = VOICE_IME_ENABLED && RichInputMethodManager.getInstance().hasShortcutIme();
voiceInputKeyOption.setEnabled(voiceKeyEnabled);
voiceInputKeyOption.setSummary(voiceKeyEnabled
? null : getText(R.string.voice_input_disabled_summary));
}
}

View file

@ -149,7 +149,7 @@ public class SettingsValues {
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res) && mInputAttributes.mShouldShowVoiceInputKey;
mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res) && mInputAttributes.mShouldShowVoiceInputKey && RichInputMethodManager.getInstance().hasShortcutIme();
mIncludesOtherImesInLanguageSwitchList = !Settings.ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS || prefs.getBoolean(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false) /* forcibly */;
mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false);
mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, true);