Accessibility Service & Shortcut Redesign - Remove “volume key shortcut” setting (1/n)

Bug: 142529032
Test: Manual test
Change-Id: Icfff02b25b1c83598774dd1708e145c0cf9447d7
This commit is contained in:
menghanli
2020-02-11 22:03:29 +08:00
committed by Menghan Li
parent 23b7ca5576
commit 40f9e47bb7
5 changed files with 3 additions and 268 deletions

View File

@@ -1,52 +0,0 @@
/*
* Copyright (C) 2019 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;
import android.os.UserHandle;
import android.view.accessibility.AccessibilityManager;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.accessibility.AccessibilityUtils;
public class AccessibilityShortcutPreferenceController extends BasePreferenceController {
public AccessibilityShortcutPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return AccessibilityManager
.getInstance(mContext).getInstalledAccessibilityServiceList().isEmpty()
? DISABLED_DEPENDENT_SETTING : AVAILABLE;
}
@Override
public CharSequence getSummary() {
if (AccessibilityManager.getInstance(mContext)
.getInstalledAccessibilityServiceList().isEmpty()) {
return mContext.getString(R.string.accessibility_no_services_installed);
} else {
final boolean shortcutEnabled =
AccessibilityUtils.isShortcutEnabled(mContext, UserHandle.myUserId());
return shortcutEnabled
? AccessibilityShortcutPreferenceFragment.getServiceName(mContext)
: mContext.getString(R.string.accessibility_feature_state_off);
}
}
}

View File

@@ -50,10 +50,8 @@ import com.android.settingslib.search.SearchIndexable;
public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePreferenceFragment
implements Indexable {
public static final String SHORTCUT_SERVICE_KEY = "accessibility_shortcut_service";
public static final String ON_LOCK_SCREEN_KEY = "accessibility_shortcut_on_lock_screen";
private Preference mServicePreference;
private SwitchPreference mOnLockScreenSwitchPreference;
private final ContentObserver mContentObserver = new ContentObserver(new Handler()) {
@Override
@@ -75,8 +73,6 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mServicePreference = findPreference(SHORTCUT_SERVICE_KEY);
mOnLockScreenSwitchPreference = (SwitchPreference) findPreference(ON_LOCK_SCREEN_KEY);
mOnLockScreenSwitchPreference.setOnPreferenceChangeListener((Preference p, Object o) -> {
Settings.Secure.putInt(getContentResolver(),
@@ -94,7 +90,7 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
preferenceScreen.findPreference(KEY_GENERAL_CATEGORY).setVisible(false);
preferenceScreen.setOrderingAsAdded(false);
mToggleServiceDividerSwitchPreference.setOrder(mServicePreference.getOrder() - 1);
mToggleServiceDividerSwitchPreference.setVisible(false);
}
@Override
@@ -117,57 +113,14 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
return R.xml.accessibility_shortcut_settings;
}
@Override
protected void onRemoveSwitchPreferenceToggleSwitch() {
super.onRemoveSwitchPreferenceToggleSwitch();
mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
}
@Override
protected void onInstallSwitchPreferenceToggleSwitch() {
super.onInstallSwitchPreferenceToggleSwitch();
mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
boolean enabled = ((SwitchPreference) preference).isChecked();
Context context = getContext();
if (enabled && !shortcutFeatureAvailable(context)) {
// 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, ON);
mServicePreference.setEnabled(true);
mServicePreference.performClick();
} else {
onPreferenceToggled(Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, enabled);
}
return true;
});
}
@Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? ON : OFF);
updatePreferences();
}
@Override
protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
final String switchBarText = getString(R.string.accessibility_service_master_switch_title,
getString(R.string.accessibility_global_gesture_preference_title));
switchPreference.setTitle(switchBarText);
}
private void updatePreferences() {
ContentResolver cr = getContentResolver();
Context context = getContext();
mServicePreference.setSummary(getServiceName(context));
if (!shortcutFeatureAvailable(context)) {
// If no service is configured, make sure the overall shortcut is turned off
Settings.Secure.putInt(
getContentResolver(), Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, OFF);
}
boolean isEnabled = Settings.Secure
.getInt(cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, ON) == ON;
mToggleServiceDividerSwitchPreference.setChecked(isEnabled);
// The shortcut is enabled by default on the lock screen as long as the user has
// enabled the shortcut with the warning dialog
final int dialogShown = Settings.Secure.getInt(
@@ -175,9 +128,6 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
final boolean enabledFromLockScreen = Settings.Secure.getInt(
cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, dialogShown) == ON;
mOnLockScreenSwitchPreference.setChecked(enabledFromLockScreen);
// Only enable changing the service and lock screen behavior if the shortcut is on
mServicePreference.setEnabled(mToggleServiceDividerSwitchPreference.isChecked());
mOnLockScreenSwitchPreference.setEnabled(mToggleServiceDividerSwitchPreference.isChecked());
}
/**
@@ -214,8 +164,7 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
return getServiceInfo(context) != null;
}
private static @Nullable
ComponentName getShortcutComponent(Context context) {
private static @Nullable ComponentName getShortcutComponent(Context context) {
String componentNameString = AccessibilityUtils.getShortcutTargetServiceComponentNameString(
context, UserHandle.myUserId());
if (componentNameString == null) return null;