diff --git a/res/values/strings.xml b/res/values/strings.xml index 4cefbd623d6..9a2c7620a46 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4233,14 +4233,14 @@ When magnification is turned on, use the Accessibility button at the bottom of the screen to quickly magnify.\n\nTo zoom, tap the Accessibility button, then tap anywhere on the screen.\n\n\nTo zoom temporarily, tap the Accessibility button, then touch & hold anywhere on the screen.\n\n\nYou can’t zoom in on the keyboard or navigation bar. The Accessibility button is set to %1$s. To use magnification, touch & hold the Accessibility button, then select magnification. - - Accessibility shortcut + + Volume key shortcut Shortcut service Allow from lock screen - When the shortcut is on, you can press both volume buttons for 3 seconds to start an accessibility feature. + When the shortcut is on, you can press both volume keys for 3 seconds to start an accessibility feature. High contrast text diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java index da47a95d653..4e95cadc1e0 100644 --- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java +++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java @@ -83,34 +83,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()); } /** @@ -120,17 +129,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 diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java index 01afdf8f88d..fb32da11ccd 100644 --- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java @@ -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; import android.content.Context;