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:
Phil Weaver
2017-05-19 16:19:41 -07:00
parent 0a53489248
commit 8fcf4d8349
3 changed files with 51 additions and 22 deletions

View File

@@ -4229,14 +4229,14 @@
<string name="accessibility_screen_magnification_navbar_summary">When magnification is turned on, use the Accessibility button at the bottom of the screen to quickly magnify.\n\n<b>To zoom</b>, tap the Accessibility button, then tap anywhere on the screen.\n<ul><li>Drag 2 or more fingers to scroll</li>\n<li>Pinch 2 or more fingers to adjust zoom</li></ul>\n\n<b>To zoom temporarily</b>, tap the Accessibility button, then touch &amp; hold anywhere on the screen.\n<ul><li>Drag to move around the screen</li>\n<li>Lift finger to zoom out</li></ul>\n\nYou cant zoom in on the keyboard or navigation bar.</string> <string name="accessibility_screen_magnification_navbar_summary">When magnification is turned on, use the Accessibility button at the bottom of the screen to quickly magnify.\n\n<b>To zoom</b>, tap the Accessibility button, then tap anywhere on the screen.\n<ul><li>Drag 2 or more fingers to scroll</li>\n<li>Pinch 2 or more fingers to adjust zoom</li></ul>\n\n<b>To zoom temporarily</b>, tap the Accessibility button, then touch &amp; hold anywhere on the screen.\n<ul><li>Drag to move around the screen</li>\n<li>Lift finger to zoom out</li></ul>\n\nYou cant zoom in on the keyboard or navigation bar.</string>
<!-- Summary text appearing on the accessibility preference screen to enable screen magnification from the nav bar when the feature is enabled, but the accessibility button is not configured correctly for the feature to be used [CHAR LIMIT=none] --> <!-- Summary text appearing on the accessibility preference screen to enable screen magnification from the nav bar when the feature is enabled, but the accessibility button is not configured correctly for the feature to be used [CHAR LIMIT=none] -->
<string name="accessibility_screen_magnification_navbar_configuration_warning">The Accessibility button is set to <xliff:g id="service" example="Select to Speak">%1$s</xliff:g>. To use magnification, touch &amp; hold the Accessibility button, then select magnification.</string> <string name="accessibility_screen_magnification_navbar_configuration_warning">The Accessibility button is set to <xliff:g id="service" example="Select to Speak">%1$s</xliff:g>. To use magnification, touch &amp; hold the Accessibility button, then select magnification.</string>
<!-- Title for the preference to configure the accessibility shortcut. [CHAR LIMIT=35] --> <!-- Title for the preference to configure the accessibility shortcut, which uses the volume keys. [CHAR LIMIT=35] -->
<string name="accessibility_global_gesture_preference_title">Accessibility shortcut</string> <string name="accessibility_global_gesture_preference_title">Volume key shortcut</string>
<!-- Title for the preference to choose the service that is turned on and off by the accessibility shortcut. [CHAR LIMIT=35] --> <!-- Title for the preference to choose the service that is turned on and off by the accessibility shortcut. [CHAR LIMIT=35] -->
<string name="accessibility_shortcut_service_title">Shortcut service</string> <string name="accessibility_shortcut_service_title">Shortcut service</string>
<!-- Title for the switch preference that controls whether or not the accessibility shortcut works on the lock screen. [CHAR LIMIT=35] --> <!-- Title for the switch preference that controls whether or not the accessibility shortcut works on the lock screen. [CHAR LIMIT=35] -->
<string name="accessibility_shortcut_service_on_lock_screen_title">Allow from lock screen</string> <string name="accessibility_shortcut_service_on_lock_screen_title">Allow from lock screen</string>
<!-- Description of accessibility shortcut. [CHAR LIMIT=NONE] --> <!-- Description of accessibility shortcut. [CHAR LIMIT=NONE] -->
<string name="accessibility_shortcut_description">When the shortcut is on, you can press both volume buttons for 3 seconds to start an accessibility feature.</string> <string name="accessibility_shortcut_description">When the shortcut is on, you can press both volume keys for 3 seconds to start an accessibility feature.</string>
<!-- Title for the accessibility preference to high contrast text. [CHAR LIMIT=35] --> <!-- Title for the accessibility preference to high contrast text. [CHAR LIMIT=35] -->
<string name="accessibility_toggle_high_text_contrast_preference_title">High contrast text</string> <string name="accessibility_toggle_high_text_contrast_preference_title">High contrast text</string>
<!-- Title for the accessibility preference to auto update screen magnification. [CHAR LIMIT=35] --> <!-- Title for the accessibility preference to auto update screen magnification. [CHAR LIMIT=35] -->

View File

@@ -78,34 +78,43 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
protected void onInstallSwitchBarToggleSwitch() { protected void onInstallSwitchBarToggleSwitch() {
super.onInstallSwitchBarToggleSwitch(); super.onInstallSwitchBarToggleSwitch();
mSwitchBar.addOnSwitchChangeListener((Switch switchView, boolean enabled) -> { 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 @Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) { protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? 1 : 0); Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? 1 : 0);
updatePreferences();
} }
private void updatePreferences() { private void updatePreferences() {
ContentResolver cr = getContentResolver(); 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 boolean isEnabled = Settings.Secure
.getInt(cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1) == 1; .getInt(cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1) == 1;
mToggleSwitch.setChecked(isEnabled); mSwitchBar.setChecked(isEnabled);
CharSequence serviceName = getServiceName(getContext());
mServicePreference.setSummary(serviceName);
mOnLockScreenSwitchPreference.setChecked(Settings.Secure.getInt( mOnLockScreenSwitchPreference.setChecked(Settings.Secure.getInt(
cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 0) == 1); cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 0) == 1);
if (TextUtils.equals(serviceName, getString(R.string.accessibility_no_service_selected))) { // Only enable changing the service and lock screen behavior if the shortcut is on
// If there's no service configured, enabling the shortcut will have no effect mServicePreference.setEnabled(mToggleSwitch.isChecked());
// It should already be disabled, but force the switch to off just in case mOnLockScreenSwitchPreference.setEnabled(mToggleSwitch.isChecked());
mToggleSwitch.setChecked(false);
mToggleSwitch.setEnabled(false);
mSwitchBar.setEnabled(false);
} else {
mToggleSwitch.setEnabled(true);
mSwitchBar.setEnabled(true);
}
} }
/** /**
@@ -115,17 +124,21 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
* @return The name of the service or a string saying that none is selected. * @return The name of the service or a string saying that none is selected.
*/ */
public static CharSequence getServiceName(Context context) { public static CharSequence getServiceName(Context context) {
ComponentName shortcutServiceName = ComponentName.unflattenFromString( AccessibilityServiceInfo shortcutServiceInfo = getServiceInfo(context);
AccessibilityUtils.getShortcutTargetServiceComponentNameString(
context, UserHandle.myUserId()));
AccessibilityServiceInfo shortcutServiceInfo = AccessibilityManager.getInstance(context)
.getInstalledServiceInfoWithComponentName(shortcutServiceName);
if (shortcutServiceInfo != null) { if (shortcutServiceInfo != null) {
return shortcutServiceInfo.getResolveInfo().loadLabel(context.getPackageManager()); return shortcutServiceInfo.getResolveInfo().loadLabel(context.getPackageManager());
} }
return context.getString(R.string.accessibility_no_service_selected); 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 = public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() { new BaseSearchIndexProvider() {
// This fragment is for details of the shortcut. Only the shortcut itself needs // This fragment is for details of the shortcut. Only the shortcut itself needs

View File

@@ -1,3 +1,19 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.accessibility; package com.android.settings.accessibility;
import android.content.Context; import android.content.Context;