Adjust a11y shortcut settings based on UX input
Disabling the shortcut if no service is configured, so we users won't see an "On" unless the shortcut will have an effect. If no service is configured and the user tries to enable the shortcut, the service picking UI is shown. If the user chooses a service, the shortcut turns on. If not, the shortcut remains off. Service selection is disabled when the shortcut is disabled (except for the specific case above). Lock screen behavior selection is disabled when the shortcut is disabled. Also updating a couple of strings based on UX input. Adding an AOSP header to a file that somehow got checked in without one. Fixes: 37443184 Fixes: 38030853 Test: Manually went through the various combinations of shortcut on and service enabled. I turned off the default selection of TalkBack as the shortcut service to ensure that we show a dialog when no service is selected. Change-Id: Iac5cff12edea91a496fc81781518db4ae49ef334
This commit is contained in:
@@ -78,34 +78,43 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
|
||||
protected void onInstallSwitchBarToggleSwitch() {
|
||||
super.onInstallSwitchBarToggleSwitch();
|
||||
mSwitchBar.addOnSwitchChangeListener((Switch switchView, boolean enabled) -> {
|
||||
onPreferenceToggled(Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, enabled);
|
||||
Context context = getContext();
|
||||
if (enabled && (getServiceInfo(context) == null)) {
|
||||
// If no service is configured, we'll disable the shortcut shortly. Give the
|
||||
// user a chance to select a service. We'll update the preferences when we resume.
|
||||
Settings.Secure.putInt(
|
||||
getContentResolver(), Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1);
|
||||
mServicePreference.setEnabled(true);
|
||||
mServicePreference.performClick();
|
||||
} else {
|
||||
onPreferenceToggled(Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, enabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? 1 : 0);
|
||||
updatePreferences();
|
||||
}
|
||||
|
||||
private void updatePreferences() {
|
||||
ContentResolver cr = getContentResolver();
|
||||
Context context = getContext();
|
||||
mServicePreference.setSummary(getServiceName(context));
|
||||
if (getServiceInfo(context) == null) {
|
||||
// If no service is configured, make sure the overall shortcut is turned off
|
||||
Settings.Secure.putInt(
|
||||
getContentResolver(), Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 0);
|
||||
}
|
||||
boolean isEnabled = Settings.Secure
|
||||
.getInt(cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1) == 1;
|
||||
mToggleSwitch.setChecked(isEnabled);
|
||||
CharSequence serviceName = getServiceName(getContext());
|
||||
mServicePreference.setSummary(serviceName);
|
||||
mSwitchBar.setChecked(isEnabled);
|
||||
mOnLockScreenSwitchPreference.setChecked(Settings.Secure.getInt(
|
||||
cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 0) == 1);
|
||||
if (TextUtils.equals(serviceName, getString(R.string.accessibility_no_service_selected))) {
|
||||
// If there's no service configured, enabling the shortcut will have no effect
|
||||
// It should already be disabled, but force the switch to off just in case
|
||||
mToggleSwitch.setChecked(false);
|
||||
mToggleSwitch.setEnabled(false);
|
||||
mSwitchBar.setEnabled(false);
|
||||
} else {
|
||||
mToggleSwitch.setEnabled(true);
|
||||
mSwitchBar.setEnabled(true);
|
||||
}
|
||||
// Only enable changing the service and lock screen behavior if the shortcut is on
|
||||
mServicePreference.setEnabled(mToggleSwitch.isChecked());
|
||||
mOnLockScreenSwitchPreference.setEnabled(mToggleSwitch.isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,17 +124,21 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
|
||||
* @return The name of the service or a string saying that none is selected.
|
||||
*/
|
||||
public static CharSequence getServiceName(Context context) {
|
||||
ComponentName shortcutServiceName = ComponentName.unflattenFromString(
|
||||
AccessibilityUtils.getShortcutTargetServiceComponentNameString(
|
||||
context, UserHandle.myUserId()));
|
||||
AccessibilityServiceInfo shortcutServiceInfo = AccessibilityManager.getInstance(context)
|
||||
.getInstalledServiceInfoWithComponentName(shortcutServiceName);
|
||||
AccessibilityServiceInfo shortcutServiceInfo = getServiceInfo(context);
|
||||
if (shortcutServiceInfo != null) {
|
||||
return shortcutServiceInfo.getResolveInfo().loadLabel(context.getPackageManager());
|
||||
}
|
||||
return context.getString(R.string.accessibility_no_service_selected);
|
||||
}
|
||||
|
||||
private static AccessibilityServiceInfo getServiceInfo(Context context) {
|
||||
ComponentName shortcutServiceName = ComponentName.unflattenFromString(
|
||||
AccessibilityUtils.getShortcutTargetServiceComponentNameString(
|
||||
context, UserHandle.myUserId()));
|
||||
return AccessibilityManager.getInstance(context)
|
||||
.getInstalledServiceInfoWithComponentName(shortcutServiceName);
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
// This fragment is for details of the shortcut. Only the shortcut itself needs
|
||||
|
Reference in New Issue
Block a user