Merge pull request #573 from Helium314/fix_voice_key

Hide voice input key and disable setting if no voice input available
This commit is contained in:
Majeur 2022-03-21 11:18:23 +01:00 committed by GitHub
commit c71aceaf01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View file

@ -112,7 +112,8 @@ public final class InputAttributes {
final boolean noMicrophone = mIsPasswordField
|| InputTypeUtils.isEmailVariation(variation)
|| InputType.TYPE_TEXT_VARIATION_URI == variation
|| hasNoMicrophoneKeyOption();
|| hasNoMicrophoneKeyOption()
|| !RichInputMethodManager.getInstance().hasShortcutIme();
mShouldShowVoiceInputKey = !noMicrophone;
mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions(

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));
}
}