Support accessibility shortcut secondary action (11/n)
Refactor current shortcut design to base fragment and provide
protected function to customize the legacy design,
magnification or no need shortcut app.
Bug: 142530063
Bug: 142531156
Test: make RunSettingsRoboTests2
Change-Id: I51c951ef8f819a1940ddfe33b009b40ed5ec0530
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index d6c2a09..55edf50 100644
--- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
@@ -26,6 +26,7 @@
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
+import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.Switch;
@@ -84,6 +85,12 @@
}
@Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ mShortcutPreference.setVisible(false);
+ }
+
+ @Override
public void onResume() {
super.onResume();
updatePreferences();
diff --git a/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java
index 13397a2..0a65709 100644
--- a/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java
@@ -21,8 +21,6 @@
import android.os.Bundle;
import android.view.View;
-import androidx.preference.PreferenceScreen;
-
import com.android.settings.R;
import com.google.common.collect.ImmutableSet;
@@ -35,22 +33,18 @@
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
- getShortcutPreferenceKey());
- if (shortcutPreference != null) {
- final CharSequence hardwareTitle = getPrefContext().getText(
- R.string.accessibility_shortcut_edit_dialog_title_hardware);
- shortcutPreference.setSummary(hardwareTitle);
- shortcutPreference.setSettingsVisibility(View.GONE);
- }
+ final CharSequence hardwareTitle = getPrefContext().getText(
+ R.string.accessibility_shortcut_edit_dialog_title_hardware);
+ mShortcutPreference.setSummary(hardwareTitle);
+ mShortcutPreference.setSettingsVisibility(View.GONE);
+
// Only allowed hardware PreferredShortcutType in this fragment.
setAllowedPreferredShortcutType(UserShortcutType.HARDWARE);
}
private void setAllowedPreferredShortcutType(int type) {
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
- getComponentName().flattenToString(), type);
+ mComponentName.flattenToString(), type);
SharedPreferenceUtils.setUserShortcutType(getPrefContext(),
ImmutableSet.of(shortcut.flattenToString()));
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index 87c1bf8..bae6775 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -24,7 +24,6 @@
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
@@ -35,17 +34,10 @@
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.text.TextUtils;
-import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
-import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
-import android.widget.CheckBox;
-
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
@@ -55,30 +47,14 @@
import com.android.settings.widget.ToggleSwitch;
import com.android.settingslib.accessibility.AccessibilityUtils;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.stream.Collectors;
/** Fragment for providing toggle bar and basic accessibility service setup. */
public class ToggleAccessibilityServicePreferenceFragment extends
- ToggleFeaturePreferenceFragment implements ShortcutPreference.OnClickListener {
-
- private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
- private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
- private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
- private int mUserShortcutType = UserShortcutType.DEFAULT;
- // Used to restore the edit dialog status.
- private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
- private CheckBox mSoftwareTypeCheckBox;
- private CheckBox mHardwareTypeCheckBox;
+ ToggleFeaturePreferenceFragment {
public static final int ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION = 1;
- private CharSequence mDialogTitle;
private LockPatternUtils mLockPatternUtils;
private AtomicBoolean mIsDialogShown = new AtomicBoolean(/* initialValue= */ false);
@@ -92,14 +68,6 @@
private Dialog mDialog;
- @Retention(RetentionPolicy.SOURCE)
- private @interface DialogType {
- int ENABLE_WARNING_FROM_TOGGLE = 1;
- int ENABLE_WARNING_FROM_SHORTCUT = 2;
- int LAUNCH_ACCESSIBILITY_TUTORIAL = 3;
- int EDIT_SHORTCUT = 4;
- }
-
@Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_SERVICE;
@@ -119,55 +87,12 @@
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
- removeDialog(DialogType.EDIT_SHORTCUT);
- mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
- };
- return super.onCreateView(inflater, container, savedInstanceState);
- }
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- // Restore the user shortcut type.
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
- mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
- UserShortcutType.DEFAULT);
- }
- initShortcutPreference();
-
- super.onViewCreated(view, savedInstanceState);
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
- super.onSaveInstanceState(outState);
- }
-
- @Override
public void onResume() {
super.onResume();
mSettingsContentObserver.register(getContentResolver());
- final AccessibilityManager am = getPrefContext().getSystemService(
- AccessibilityManager.class);
- am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
updateSwitchBarToggleSwitch();
- updateShortcutPreferenceData();
- updateShortcutPreference();
- }
-
- @Override
- public void onPause() {
- mSettingsContentObserver.unregister(getContentResolver());
- final AccessibilityManager am = getPrefContext().getSystemService(
- AccessibilityManager.class);
- am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
-
- super.onPause();
}
@Override
@@ -198,7 +123,7 @@
@Override
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
- case DialogType.ENABLE_WARNING_FROM_TOGGLE: {
+ case DialogEnums.ENABLE_WARNING_FROM_TOGGLE: {
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
if (info == null) {
return null;
@@ -208,7 +133,7 @@
this::onDialogButtonFromToggleClicked);
break;
}
- case DialogType.ENABLE_WARNING_FROM_SHORTCUT: {
+ case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT: {
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
if (info == null) {
return null;
@@ -218,7 +143,7 @@
this::onDialogButtonFromShortcutClicked);
break;
}
- case DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL: {
+ case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL: {
if (AccessibilityUtil.isGestureNavigateEnabled(getContext())) {
mDialog = AccessibilityGestureNavigationTutorial
.showGestureNavigationTutorialDialog(getActivity());
@@ -228,153 +153,25 @@
}
break;
}
- case DialogType.EDIT_SHORTCUT: {
- final CharSequence dialogTitle = getActivity().getString(
- R.string.accessibility_shortcut_edit_dialog_title, mDialogTitle);
- mDialog = AccessibilityEditDialogUtils.showEditShortcutDialog(getActivity(),
- dialogTitle, this::callOnAlertDialogCheckboxClicked);
- initializeDialogCheckBox(mDialog);
- break;
- }
default: {
- throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
+ mDialog = super.onCreateDialog(dialogId);
}
}
return mDialog;
}
- private void initializeDialogCheckBox(Dialog dialog) {
- final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
- mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
- final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
- mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
- updateAlertDialogCheckState();
- updateAlertDialogEnableState();
- }
-
- private void updateAlertDialogCheckState() {
- updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
- updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
- }
-
- private void updateAlertDialogEnableState() {
- if (!mSoftwareTypeCheckBox.isChecked()) {
- mHardwareTypeCheckBox.setEnabled(false);
- } else if (!mHardwareTypeCheckBox.isChecked()) {
- mSoftwareTypeCheckBox.setEnabled(false);
- } else {
- mSoftwareTypeCheckBox.setEnabled(true);
- mHardwareTypeCheckBox.setEnabled(true);
- }
- }
-
- private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
- checkBox.setChecked((mUserShortcutTypeCache & type) == type);
- checkBox.setOnClickListener(v -> {
- updateUserShortcutType(/* saveChanges= */ false);
- updateAlertDialogEnableState();
- });
- }
-
- private void updateUserShortcutType(boolean saveChanges) {
- mUserShortcutTypeCache = UserShortcutType.DEFAULT;
- if (mSoftwareTypeCheckBox.isChecked()) {
- mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
- }
- if (mHardwareTypeCheckBox.isChecked()) {
- mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
- }
- if (saveChanges) {
- mUserShortcutType = mUserShortcutTypeCache;
- setUserShortcutType(getPrefContext(), mUserShortcutType);
- }
- }
-
- private void setUserShortcutType(Context context, int type) {
- Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
- final String componentName = getComponentName().flattenToString();
- if (info.isEmpty()) {
- info = new HashSet<>();
- } else {
- final Set<String> filtered = info.stream().filter(
- str -> str.contains(componentName)).collect(Collectors.toSet());
- info.removeAll(filtered);
- }
- final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
- getComponentName().flattenToString(), type);
- info.add(shortcut.flattenToString());
- SharedPreferenceUtils.setUserShortcutType(context, info);
- }
-
- private String getShortcutTypeSummary(Context context) {
- final int shortcutType = getUserShortcutType(context, UserShortcutType.SOFTWARE);
- int resId = R.string.accessibility_shortcut_edit_dialog_title_software;
- if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
- resId = AccessibilityUtil.isTouchExploreEnabled(context)
- ? R.string.accessibility_shortcut_edit_dialog_title_software_gesture_talkback
- : R.string.accessibility_shortcut_edit_dialog_title_software_gesture;
- }
- final CharSequence softwareTitle = context.getText(resId);
-
- List<CharSequence> list = new ArrayList<>();
- if ((shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
- list.add(softwareTitle);
- }
- if ((shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
- final CharSequence hardwareTitle = context.getText(
- R.string.accessibility_shortcut_edit_dialog_title_hardware);
- list.add(hardwareTitle);
- }
-
- // Show software shortcut if first time to use.
- if (list.isEmpty()) {
- list.add(softwareTitle);
- }
- final String joinStrings = TextUtils.join(/* delimiter= */", ", list);
- return AccessibilityUtil.capitalize(joinStrings);
- }
-
- private int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
- final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
- final String componentName = getComponentName().flattenToString();
- final Set<String> filtered = info.stream().filter(
- str -> str.contains(componentName)).collect(
- Collectors.toSet());
- if (filtered.isEmpty()) {
- return defaultValue;
- }
-
- final String str = (String) filtered.toArray()[0];
- final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
- return shortcut.getUserShortcutType();
- }
-
- private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
- updateUserShortcutType(/* saveChanges= */ true);
- if (mShortcutPreference.getChecked()) {
- AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
- mComponentName);
- AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
- mComponentName);
- }
- mShortcutPreference.setSummary(
- getShortcutTypeSummary(getPrefContext()));
- }
-
@Override
public int getDialogMetricsCategory(int dialogId) {
switch (dialogId) {
- case DialogType.ENABLE_WARNING_FROM_TOGGLE:
- case DialogType.ENABLE_WARNING_FROM_SHORTCUT:
+ case DialogEnums.ENABLE_WARNING_FROM_TOGGLE:
+ case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT:
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_ENABLE;
- case DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL:
- return AccessibilityUtil.isGestureNavigateEnabled(getContext())
+ case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
+ return AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())
? SettingsEnums.DIALOG_TOGGLE_SCREEN_GESTURE_NAVIGATION
: SettingsEnums.DIALOG_TOGGLE_SCREEN_ACCESSIBILITY_BUTTON;
- case DialogType.EDIT_SHORTCUT:
- return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_EDIT_SHORTCUT;
default:
- return 0;
+ return super.getDialogMetricsCategory(dialogId);
}
}
@@ -387,55 +184,6 @@
switchBar.setSwitchBarText(switchBarText, switchBarText);
}
- private void updateShortcutPreferenceData() {
- // Get the user shortcut type from settings provider.
- mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
- getComponentName());
- if (mUserShortcutType != UserShortcutType.DEFAULT) {
- setUserShortcutType(getPrefContext(), mUserShortcutType);
- } else {
- // Get the user shortcut type from shared_prefs if cannot get from settings provider.
- mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
- }
- }
-
- @Override
- protected void updateFooterTitle(PreferenceCategory category) {
- final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
- final String titleText = (info == null) ? "" :
- getString(R.string.accessibility_footer_title,
- info.getResolveInfo().loadLabel(getPackageManager()));
- category.setTitle(titleText);
- }
-
- private void initShortcutPreference() {
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- mShortcutPreference = new ShortcutPreference(
- preferenceScreen.getContext(), null);
- mShortcutPreference.setPersistent(false);
- mShortcutPreference.setKey(getShortcutPreferenceKey());
- mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
- mShortcutPreference.setOnClickListener(this);
- }
-
- private void updateShortcutPreference() {
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
- getShortcutPreferenceKey());
-
- if (shortcutPreference != null) {
- final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
- shortcutPreference.setChecked(
- AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
- mComponentName));
- shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
- }
- }
-
- protected String getShortcutPreferenceKey() {
- return KEY_SHORTCUT_PREFERENCE;
- }
-
private void updateSwitchBarToggleSwitch() {
final boolean checked = AccessibilityUtils.getEnabledServicesFromSettings(getActivity())
.contains(mComponentName);
@@ -524,7 +272,7 @@
if (preference.getChecked()) {
if (!getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)) {
preference.setChecked(false);
- showPopupDialog(DialogType.ENABLE_WARNING_FROM_SHORTCUT);
+ showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_SHORTCUT);
} else {
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes,
mComponentName);
@@ -538,8 +286,8 @@
@Override
public void onSettingsClicked(ShortcutPreference preference) {
- mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
- showPopupDialog(DialogType.EDIT_SHORTCUT);
+ super.onSettingsClicked(preference);
+ showPopupDialog(DialogEnums.EDIT_SHORTCUT);
}
@Override
@@ -572,7 +320,7 @@
mHtmlDescription = arguments.getCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION);
// Get Accessibility service name.
- mDialogTitle = getAccessibilityServiceInfo().getResolveInfo().loadLabel(
+ mPackageName = getAccessibilityServiceInfo().getResolveInfo().loadLabel(
getPackageManager());
}
@@ -597,7 +345,7 @@
handleConfirmServiceEnabled(/* confirmed= */ true);
if (isServiceSupportAccessibilityButton()) {
mIsDialogShown.set(false);
- showPopupDialog(DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL);
+ showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
}
}
@@ -620,8 +368,7 @@
}
private void onAllowButtonFromShortcutClicked() {
- final ShortcutPreference shortcutPreference = findPreference(getShortcutPreferenceKey());
- shortcutPreference.setChecked(true);
+ mShortcutPreference.setChecked(true);
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes, mComponentName);
@@ -630,8 +377,7 @@
}
private void onDenyButtonFromShortcutClicked() {
- final ShortcutPreference shortcutPreference = findPreference(getShortcutPreferenceKey());
- shortcutPreference.setChecked(false);
+ mShortcutPreference.setChecked(false);
mDialog.dismiss();
}
@@ -640,15 +386,12 @@
if (checked) {
mSwitchBar.setCheckedInternal(false);
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, false);
-
- final ShortcutPreference shortcutPreference = findPreference(
- getShortcutPreferenceKey());
- if (!shortcutPreference.getChecked()) {
- showPopupDialog(DialogType.ENABLE_WARNING_FROM_TOGGLE);
+ if (!mShortcutPreference.getChecked()) {
+ showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_TOGGLE);
} else {
handleConfirmServiceEnabled(/* confirmed= */ true);
if (isServiceSupportAccessibilityButton()) {
- showPopupDialog(DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL);
+ showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
}
}
} else {
@@ -665,8 +408,4 @@
false));
}
}
-
- ComponentName getComponentName() {
- return mComponentName;
- }
}
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index 80fd92f..283fa90 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -18,61 +18,38 @@
import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME;
-import android.app.Dialog;
import android.app.settings.SettingsEnums;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
-import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.accessibility.AccessibilityManager;
-import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
-import android.widget.CheckBox;
import android.widget.Switch;
-import androidx.appcompat.app.AlertDialog;
-import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.State;
-import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
/** Settings page for color inversion. */
@SearchIndexable
public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment
- implements SwitchBar.OnSwitchChangeListener, ShortcutPreference.OnClickListener {
+ implements SwitchBar.OnSwitchChangeListener {
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
- private static final String PREVIEW_PREFERENCE_KEY = "color_inversion_preview";
private static final String CATEGORY_FOOTER_KEY = "color_inversion_footer_category";
- private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private static final int DIALOG_ID_EDIT_SHORTCUT = 1;
- private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private final Handler mHandler = new Handler();
- private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private SettingsContentObserver mSettingsContentObserver;
- private int mUserShortcutType = UserShortcutType.DEFAULT;
- // Used to restore the edit dialog status.
- private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
- private CheckBox mSoftwareTypeCheckBox;
- private CheckBox mHardwareTypeCheckBox;
@Override
public int getMetricsCategory() {
@@ -102,13 +79,6 @@
}
@Override
- protected void updateFooterTitle(PreferenceCategory category) {
- final String titleText = getString(R.string.accessibility_footer_title,
- getString(R.string.accessibility_display_inversion_preference_title));
- category.setTitle(titleText);
- }
-
- @Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
Settings.Secure.putInt(getContentResolver(), ENABLED, isChecked ? State.ON : State.OFF);
}
@@ -124,6 +94,8 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+ mComponentName = COLOR_INVERSION_COMPONENT_NAME;
+ mPackageName = getString(R.string.accessibility_display_inversion_preference_title);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@@ -134,262 +106,35 @@
== State.ON);
}
};
-
- mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
- removeDialog(DIALOG_ID_EDIT_SHORTCUT);
- mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
- };
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
- // Restore the user shortcut type.
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
- mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
- UserShortcutType.DEFAULT);
- }
- initShortcutPreference();
-
super.onViewCreated(view, savedInstanceState);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false);
final PreferenceCategory footerCategory = preferenceScreen.findPreference(
CATEGORY_FOOTER_KEY);
- updateFooterTitle(footerCategory);
footerCategory.setOrder(Integer.MAX_VALUE);
}
@Override
- public void onSaveInstanceState(Bundle outState) {
- outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
- super.onSaveInstanceState(outState);
- }
-
- @Override
public void onResume() {
super.onResume();
-
mSettingsContentObserver.register(getContentResolver());
- final AccessibilityManager am = getPrefContext().getSystemService(
- AccessibilityManager.class);
- am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
-
- updateShortcutPreferenceData();
- updateShortcutPreference();
}
@Override
public void onPause() {
mSettingsContentObserver.unregister(getContentResolver());
- final AccessibilityManager am = getPrefContext().getSystemService(
- AccessibilityManager.class);
- am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
-
super.onPause();
}
@Override
- public Dialog onCreateDialog(int dialogId) {
- if (dialogId == DIALOG_ID_EDIT_SHORTCUT) {
- final CharSequence dialogTitle = getActivity().getText(
- R.string.accessibility_shortcut_edit_dialog_title_daltonizer);
- final AlertDialog dialog = AccessibilityEditDialogUtils.showEditShortcutDialog(
- getActivity(),
- dialogTitle, this::callOnAlertDialogCheckboxClicked);
- initializeDialogCheckBox(dialog);
- return dialog;
- }
- throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
- }
-
- private void initializeDialogCheckBox(AlertDialog dialog) {
- final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
- mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
- final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
- mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
- updateAlertDialogCheckState();
- updateAlertDialogEnableState();
- }
-
- private void updateAlertDialogCheckState() {
- updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
- updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
- }
-
- private void updateAlertDialogEnableState() {
- if (!mSoftwareTypeCheckBox.isChecked()) {
- mHardwareTypeCheckBox.setEnabled(false);
- } else if (!mHardwareTypeCheckBox.isChecked()) {
- mSoftwareTypeCheckBox.setEnabled(false);
- } else {
- mSoftwareTypeCheckBox.setEnabled(true);
- mHardwareTypeCheckBox.setEnabled(true);
- }
- }
-
- private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
- checkBox.setChecked((mUserShortcutTypeCache & type) == type);
- checkBox.setOnClickListener(v -> {
- updateUserShortcutType(/* saveChanges= */ false);
- updateAlertDialogEnableState();
- });
- }
-
- private void updateUserShortcutType(boolean saveChanges) {
- mUserShortcutTypeCache = UserShortcutType.DEFAULT;
- if (mSoftwareTypeCheckBox.isChecked()) {
- mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
- }
- if (mHardwareTypeCheckBox.isChecked()) {
- mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
- }
- if (saveChanges) {
- mUserShortcutType = mUserShortcutTypeCache;
- setUserShortcutType(getPrefContext(), mUserShortcutType);
- }
- }
-
- private void setUserShortcutType(Context context, int type) {
- Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
- if (info.isEmpty()) {
- info = new HashSet<>();
- } else {
- final Set<String> filtered = info.stream().filter(
- str -> str.contains(getComponentName().flattenToString())).collect(
- Collectors.toSet());
- info.removeAll(filtered);
- }
- final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
- getComponentName().flattenToString(), type);
- info.add(shortcut.flattenToString());
- SharedPreferenceUtils.setUserShortcutType(context, info);
- }
-
- private String getShortcutTypeSummary(Context context) {
- final int shortcutType = getUserShortcutType(context, UserShortcutType.SOFTWARE);
- int resId = R.string.accessibility_shortcut_edit_dialog_title_software;
- if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
- resId = AccessibilityUtil.isTouchExploreEnabled(context)
- ? R.string.accessibility_shortcut_edit_dialog_title_software_gesture_talkback
- : R.string.accessibility_shortcut_edit_dialog_title_software_gesture;
- }
- final CharSequence softwareTitle = context.getText(resId);
-
- List<CharSequence> list = new ArrayList<>();
- if ((shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
- list.add(softwareTitle);
- }
- if ((shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
- final CharSequence hardwareTitle = context.getText(
- R.string.accessibility_shortcut_edit_dialog_title_hardware);
- list.add(hardwareTitle);
- }
-
- // Show software shortcut if first time to use.
- if (list.isEmpty()) {
- list.add(softwareTitle);
- }
- final String joinStrings = TextUtils.join(/* delimiter= */", ", list);
- return AccessibilityUtil.capitalize(joinStrings);
- }
-
- private int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
- final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
- final String componentName = getComponentName().flattenToString();
- final Set<String> filtered = info.stream().filter(
- str -> str.contains(componentName)).collect(
- Collectors.toSet());
- if (filtered.isEmpty()) {
- return defaultValue;
- }
-
- final String str = (String) filtered.toArray()[0];
- final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
- return shortcut.getUserShortcutType();
- }
-
- private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
- updateUserShortcutType(/* saveChanges= */ true);
- if (mShortcutPreference.getChecked()) {
- AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
- getComponentName());
- AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
- getComponentName());
- }
- mShortcutPreference.setSummary(
- getShortcutTypeSummary(getPrefContext()));
- }
-
- @Override
- public int getDialogMetricsCategory(int dialogId) {
- if (dialogId == DIALOG_ID_EDIT_SHORTCUT) {
- return SettingsEnums.DIALOG_COLOR_INVERSION_EDIT_SHORTCUT;
- }
- return 0;
- }
-
- private void updateShortcutPreferenceData() {
- // Get the user shortcut type from settings provider.
- mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
- getComponentName());
- if (mUserShortcutType != UserShortcutType.DEFAULT) {
- setUserShortcutType(getPrefContext(), mUserShortcutType);
- } else {
- // Get the user shortcut type from shared_prefs if cannot get from settings provider.
- mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
- }
- }
-
- private void initShortcutPreference() {
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- mShortcutPreference = new ShortcutPreference(
- preferenceScreen.getContext(), null);
- final Preference previewPreference = findPreference(PREVIEW_PREFERENCE_KEY);
- mShortcutPreference.setPersistent(false);
- mShortcutPreference.setKey(getShortcutPreferenceKey());
- mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
- mShortcutPreference.setOnClickListener(this);
- }
-
- private void updateShortcutPreference() {
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
- getShortcutPreferenceKey());
-
- if (shortcutPreference != null) {
- final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
- shortcutPreference.setChecked(
- AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
- getComponentName()));
- shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
- }
- }
-
- private String getShortcutPreferenceKey() {
- return KEY_SHORTCUT_PREFERENCE;
- }
-
- private ComponentName getComponentName() {
- return COLOR_INVERSION_COMPONENT_NAME;
- }
-
- @Override
- public void onCheckboxClicked(ShortcutPreference preference) {
- final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
- if (preference.getChecked()) {
- AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes,
- getComponentName());
- } else {
- AccessibilityUtil.optOutAllValuesFromSettings(getContext(), shortcutTypes,
- getComponentName());
- }
- }
-
- @Override
public void onSettingsClicked(ShortcutPreference preference) {
- mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
+ super.onSettingsClicked(preference);
showDialog(DIALOG_ID_EDIT_SHORTCUT);
}
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index ca95241..493140c 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -18,33 +18,24 @@
import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME;
-import android.app.Dialog;
import android.app.settings.SettingsEnums;
-import android.content.ComponentName;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
-import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.accessibility.AccessibilityManager;
-import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
-import android.widget.CheckBox;
import android.widget.Switch;
-import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.State;
-import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -52,30 +43,18 @@
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
@SearchIndexable
public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceFragment
implements DaltonizerRadioButtonPreferenceController.OnChangeListener,
- SwitchBar.OnSwitchChangeListener, ShortcutPreference.OnClickListener {
+ SwitchBar.OnSwitchChangeListener{
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED;
private static final String CATEGORY_FOOTER_KEY = "daltonizer_footer_category";
- private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
- private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
- private static final int DIALOG_ID_EDIT_SHORTCUT = 1;
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
private final Handler mHandler = new Handler();
- private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private SettingsContentObserver mSettingsContentObserver;
- private int mUserShortcutType = UserShortcutType.DEFAULT;
- // Used to restore the edit dialog status.
- private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
- private CheckBox mSoftwareTypeCheckBox;
- private CheckBox mHardwareTypeCheckBox;
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
@@ -102,6 +81,8 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+ mComponentName = DALTONIZER_COMPONENT_NAME;
+ mPackageName = getString(R.string.accessibility_display_daltonizer_preference_title);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@@ -112,219 +93,47 @@
== State.ON);
}
};
-
- mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
- removeDialog(DIALOG_ID_EDIT_SHORTCUT);
- mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
- };
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
- // Restore the user shortcut type.
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
- mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
- UserShortcutType.DEFAULT);
- }
- initShortcutPreference();
-
super.onViewCreated(view, savedInstanceState);
-
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false);
final PreferenceCategory footerCategory = preferenceScreen.findPreference(
CATEGORY_FOOTER_KEY);
- updateFooterTitle(footerCategory);
footerCategory.setOrder(Integer.MAX_VALUE);
}
@Override
- public void onSaveInstanceState(Bundle outState) {
- outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
- super.onSaveInstanceState(outState);
- }
-
- @Override
public void onResume() {
super.onResume();
-
mSettingsContentObserver.register(getContentResolver());
- final AccessibilityManager am = getPrefContext().getSystemService(
- AccessibilityManager.class);
- am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
-
for (AbstractPreferenceController controller :
buildPreferenceControllers(getPrefContext(), getSettingsLifecycle())) {
((DaltonizerRadioButtonPreferenceController) controller).setOnChangeListener(this);
((DaltonizerRadioButtonPreferenceController) controller).displayPreference(
getPreferenceScreen());
}
- updateShortcutPreferenceData();
- updateShortcutPreference();
}
@Override
public void onPause() {
mSettingsContentObserver.unregister(getContentResolver());
- final AccessibilityManager am = getPrefContext().getSystemService(
- AccessibilityManager.class);
- am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
-
for (AbstractPreferenceController controller :
buildPreferenceControllers(getPrefContext(), getSettingsLifecycle())) {
((DaltonizerRadioButtonPreferenceController) controller).setOnChangeListener(null);
}
-
super.onPause();
}
@Override
- public Dialog onCreateDialog(int dialogId) {
- if (dialogId == DIALOG_ID_EDIT_SHORTCUT) {
- final CharSequence dialogTitle = getActivity().getText(
- R.string.accessibility_shortcut_edit_dialog_title_daltonizer);
- final AlertDialog dialog = AccessibilityEditDialogUtils.showEditShortcutDialog(
- getActivity(),
- dialogTitle, this::callOnAlertDialogCheckboxClicked);
- initializeDialogCheckBox(dialog);
- return dialog;
- }
- throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
- }
-
- private void initializeDialogCheckBox(AlertDialog dialog) {
- final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
- mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
- final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
- mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
- updateAlertDialogCheckState();
- updateAlertDialogEnableState();
- }
-
- private void updateAlertDialogCheckState() {
- updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
- updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
- }
-
- private void updateAlertDialogEnableState() {
- if (!mSoftwareTypeCheckBox.isChecked()) {
- mHardwareTypeCheckBox.setEnabled(false);
- } else if (!mHardwareTypeCheckBox.isChecked()) {
- mSoftwareTypeCheckBox.setEnabled(false);
- } else {
- mSoftwareTypeCheckBox.setEnabled(true);
- mHardwareTypeCheckBox.setEnabled(true);
- }
- }
-
- private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
- checkBox.setChecked((mUserShortcutTypeCache & type) == type);
- checkBox.setOnClickListener(v -> {
- updateUserShortcutType(/* saveChanges= */ false);
- updateAlertDialogEnableState();
- });
- }
-
- private void updateUserShortcutType(boolean saveChanges) {
- mUserShortcutTypeCache = UserShortcutType.DEFAULT;
- if (mSoftwareTypeCheckBox.isChecked()) {
- mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
- }
- if (mHardwareTypeCheckBox.isChecked()) {
- mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
- }
- if (saveChanges) {
- mUserShortcutType = mUserShortcutTypeCache;
- setUserShortcutType(getPrefContext(), mUserShortcutType);
- }
- }
-
- private void setUserShortcutType(Context context, int type) {
- Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
- if (info.isEmpty()) {
- info = new HashSet<>();
- } else {
- final Set<String> filtered = info.stream().filter(
- str -> str.contains(getComponentName().flattenToString())).collect(
- Collectors.toSet());
- info.removeAll(filtered);
- }
- final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
- getComponentName().flattenToString(), type);
- info.add(shortcut.flattenToString());
- SharedPreferenceUtils.setUserShortcutType(context, info);
- }
-
- private String getShortcutTypeSummary(Context context) {
- final int shortcutType = getUserShortcutType(context, UserShortcutType.SOFTWARE);
- int resId = R.string.accessibility_shortcut_edit_dialog_title_software;
- if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
- resId = AccessibilityUtil.isTouchExploreEnabled(context)
- ? R.string.accessibility_shortcut_edit_dialog_title_software_gesture_talkback
- : R.string.accessibility_shortcut_edit_dialog_title_software_gesture;
- }
- final CharSequence softwareTitle = context.getText(resId);
-
- List<CharSequence> list = new ArrayList<>();
- if ((shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
- list.add(softwareTitle);
- }
- if ((shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
- final CharSequence hardwareTitle = context.getText(
- R.string.accessibility_shortcut_edit_dialog_title_hardware);
- list.add(hardwareTitle);
- }
-
- // Show software shortcut if first time to use.
- if (list.isEmpty()) {
- list.add(softwareTitle);
- }
- final String joinStrings = TextUtils.join(/* delimiter= */", ", list);
- return AccessibilityUtil.capitalize(joinStrings);
- }
-
- private int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
- final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
- final String componentName = getComponentName().flattenToString();
- final Set<String> filtered = info.stream().filter(
- str -> str.contains(componentName)).collect(
- Collectors.toSet());
- if (filtered.isEmpty()) {
- return defaultValue;
- }
-
- final String str = (String) filtered.toArray()[0];
- final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
- return shortcut.getUserShortcutType();
- }
-
- private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
- updateUserShortcutType(/* saveChanges= */ true);
- if (mShortcutPreference.getChecked()) {
- AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
- getComponentName());
- AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
- getComponentName());
- }
- mShortcutPreference.setSummary(
- getShortcutTypeSummary(getPrefContext()));
- }
-
- @Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_TOGGLE_DALTONIZER;
}
@Override
- public int getDialogMetricsCategory(int dialogId) {
- if (dialogId == DIALOG_ID_EDIT_SHORTCUT) {
- return SettingsEnums.DIALOG_DALTONIZER_EDIT_SHORTCUT;
- }
- return 0;
- }
-
- @Override
public int getHelpResource() {
return R.string.help_url_color_correction;
}
@@ -352,13 +161,6 @@
}
@Override
- protected void updateFooterTitle(PreferenceCategory category) {
- final String titleText = getString(R.string.accessibility_footer_title,
- getString(R.string.accessibility_display_daltonizer_preference_title));
- category.setTitle(titleText);
- }
-
- @Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
Settings.Secure.putInt(getContentResolver(), ENABLED, isChecked ? State.ON : State.OFF);
}
@@ -372,67 +174,9 @@
}
@Override
- public void onCheckboxClicked(ShortcutPreference preference) {
- final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
- if (preference.getChecked()) {
- AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes,
- getComponentName());
- } else {
- AccessibilityUtil.optOutAllValuesFromSettings(getContext(), shortcutTypes,
- getComponentName());
- }
- }
-
- @Override
public void onSettingsClicked(ShortcutPreference preference) {
- mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
- showDialog(DIALOG_ID_EDIT_SHORTCUT);
- }
-
- private void initShortcutPreference() {
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- mShortcutPreference = new ShortcutPreference(
- preferenceScreen.getContext(), null);
- mShortcutPreference.setPersistent(false);
- mShortcutPreference.setKey(getShortcutPreferenceKey());
- mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
- mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
- mShortcutPreference.setOnClickListener(this);
- }
-
- private void updateShortcutPreferenceData() {
- // Get the user shortcut type from settings provider.
- mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
- getComponentName());
- if (mUserShortcutType != UserShortcutType.DEFAULT) {
- setUserShortcutType(getPrefContext(), mUserShortcutType);
- } else {
- // Get the user shortcut type from shared_prefs if cannot get from settings provider.
- mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
- }
- }
-
- private void updateShortcutPreference() {
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
- getShortcutPreferenceKey());
-
- if (shortcutPreference != null) {
- final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
- shortcutPreference.setChecked(
- AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
- getComponentName()));
- shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
- }
-
- }
-
- private String getShortcutPreferenceKey() {
- return KEY_SHORTCUT_PREFERENCE;
- }
-
- private ComponentName getComponentName() {
- return DALTONIZER_COMPONENT_NAME;
+ super.onSettingsClicked(preference);
+ showDialog(DialogEnums.EDIT_SHORTCUT);
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 28c1e1c..ddc9424 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -16,8 +16,12 @@
package com.android.settings.accessibility;
+import android.app.Dialog;
+import android.app.settings.SettingsEnums;
import android.content.ComponentName;
import android.content.ContentResolver;
+import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
@@ -25,7 +29,12 @@
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
+import android.widget.CheckBox;
import android.widget.ImageView;
import androidx.preference.Preference;
@@ -35,14 +44,25 @@
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.StringJoiner;
+import java.util.stream.Collectors;
-public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment {
+/**
+ * Base class for accessibility fragments with toggle, shortcut, some helper functions
+ * and dialog management.
+ */
+public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment
+ implements ShortcutPreference.OnClickListener {
protected SwitchBar mSwitchBar;
protected ToggleSwitch mToggleSwitch;
@@ -52,13 +72,24 @@
protected CharSequence mSettingsTitle;
protected Intent mSettingsIntent;
+ // The mComponentName maybe null, such as Magnify
protected ComponentName mComponentName;
+ protected CharSequence mPackageName;
protected Uri mImageUri;
protected CharSequence mStaticDescription;
protected CharSequence mHtmlDescription;
private static final String ANCHOR_TAG = "a";
private static final String DRAWABLE_FOLDER = "drawable";
+ private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
+ private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
+ private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
+ private int mUserShortcutType = UserShortcutType.DEFAULT;
+ // Used to restore the edit dialog status.
+ private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
+ private CheckBox mSoftwareTypeCheckBox;
+ private CheckBox mHardwareTypeCheckBox;
+
// For html description of accessibility service, third party developer must follow the rule,
// such as <img src="R.drawable.fileName"/>, a11y settings will get third party resources
// by this.
@@ -89,6 +120,16 @@
}
@Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
+ removeDialog(DialogEnums.EDIT_SHORTCUT);
+ mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
+ };
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
+ @Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@@ -108,6 +149,13 @@
preferenceScreen.addPreference(animatedImagePreference);
}
+ final PreferenceCategory category = new PreferenceCategory(getPrefContext());
+ category.setTitle(R.string.accessibility_screen_option);
+ preferenceScreen.addPreference(category);
+
+ initShortcutPreference(savedInstanceState);
+ category.addPreference(mShortcutPreference);
+
// Show the "Settings" menu as if it were a preference screen.
if (mSettingsTitle != null && mSettingsIntent != null) {
mSettingsPreference = new Preference(preferenceScreen.getContext());
@@ -116,23 +164,15 @@
mSettingsPreference.setIntent(mSettingsIntent);
}
- if (mSettingsPreference != null || mShortcutPreference != null) {
- final PreferenceCategory category = new PreferenceCategory(getPrefContext());
- category.setTitle(R.string.accessibility_screen_option);
- preferenceScreen.addPreference(category);
-
- if (mShortcutPreference != null) {
- category.addPreference(mShortcutPreference);
- }
-
- if (mSettingsPreference != null) {
- category.addPreference(mSettingsPreference);
- }
+ // The downloaded app may not show Settings. The framework app has Settings.
+ if (mSettingsPreference != null) {
+ category.addPreference(mSettingsPreference);
}
if (mStaticDescription != null || mHtmlDescription != null) {
final PreferenceCategory footerCategory = new PreferenceCategory(getPrefContext());
- updateFooterTitle(footerCategory);
+ final CharSequence title = getString(R.string.accessibility_footer_title, mPackageName);
+ footerCategory.setTitle(title);
preferenceScreen.addPreference(footerCategory);
if (mStaticDescription != null) {
@@ -167,6 +207,96 @@
}
@Override
+ public void onResume() {
+ super.onResume();
+ final AccessibilityManager am = getPrefContext().getSystemService(
+ AccessibilityManager.class);
+ am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
+ updateShortcutPreferenceData();
+ updateShortcutPreference();
+ }
+
+ @Override
+ public void onPause() {
+ final AccessibilityManager am = getPrefContext().getSystemService(
+ AccessibilityManager.class);
+ am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
+ super.onPause();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
+ super.onSaveInstanceState(outState);
+ }
+
+ @Override
+ public Dialog onCreateDialog(int dialogId) {
+ switch (dialogId) {
+ case DialogEnums.EDIT_SHORTCUT:
+ final CharSequence dialogTitle = getActivity().getString(
+ R.string.accessibility_shortcut_edit_dialog_title, mPackageName);
+ Dialog dialog = AccessibilityEditDialogUtils.showEditShortcutDialog(getActivity(),
+ dialogTitle, this::callOnAlertDialogCheckboxClicked);
+ initializeDialogCheckBox(dialog);
+ return dialog;
+ default:
+ throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
+ }
+ }
+
+ @Override
+ public int getDialogMetricsCategory(int dialogId) {
+ switch (dialogId) {
+ case DialogEnums.EDIT_SHORTCUT:
+ return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_EDIT_SHORTCUT;
+ default:
+ return SettingsEnums.ACTION_UNKNOWN;
+ }
+ }
+
+ /** Denotes the dialog emuns for show dialog */
+ @Retention(RetentionPolicy.SOURCE)
+ protected @interface DialogEnums {
+ int UNKNOWN = 0;
+
+ /** OPEN: Settings > Accessibility > Any toggle service > Shortcut > Settings. */
+ int EDIT_SHORTCUT = 1;
+
+ /** OPEN: Settings > Accessibility > Magnification > Shortcut > Settings. */
+ int MAGNIFICATION_EDIT_SHORTCUT = 2;
+
+ /**
+ * OPEN: Settings > Accessibility > Magnification > Toggle user service in gesture
+ * navigation.
+ */
+ int GESTURE_NAVIGATION_TUTORIAL = 1001;
+
+ /**
+ * OPEN: Settings > Accessibility > Magnification > Toggle user service in button
+ * navigation.
+ */
+ int ACCESSIBILITY_BUTTON_TUTORIAL = 1002;
+
+ /** OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service. */
+ int ENABLE_WARNING_FROM_TOGGLE = 1003;
+
+ /** OPEN: Settings > Accessibility > Downloaded toggle service > Shortcut checkbox. */
+ int ENABLE_WARNING_FROM_SHORTCUT = 1004;
+
+ /**
+ * OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service > Show
+ * launch tutorial.
+ */
+ int LAUNCH_ACCESSIBILITY_TUTORIAL = 1005;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.ACCESSIBILITY_SERVICE;
+ }
+
+ @Override
public void onDestroyView() {
super.onDestroyView();
removeActionBarToggleSwitch();
@@ -178,14 +308,6 @@
R.string.accessibility_service_master_switch_title);
}
- protected void updateFooterTitle(PreferenceCategory category) {
- // Implement this to provide meaningful text in the footer.
- if (category != null) {
- category.setTitle(getString(R.string.accessibility_footer_title,
- mComponentName.getPackageName()));
- }
- }
-
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
protected void onInstallSwitchBarToggleSwitch() {
@@ -303,4 +425,203 @@
return joiner.toString();
}
}
+
+
+ private void initializeDialogCheckBox(Dialog dialog) {
+ final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
+ mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
+ final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
+ mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
+ updateAlertDialogCheckState();
+ updateAlertDialogEnableState();
+ }
+
+ private void updateAlertDialogCheckState() {
+ updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
+ updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
+ }
+
+ private void updateAlertDialogEnableState() {
+ if (!mSoftwareTypeCheckBox.isChecked()) {
+ mHardwareTypeCheckBox.setEnabled(false);
+ } else if (!mHardwareTypeCheckBox.isChecked()) {
+ mSoftwareTypeCheckBox.setEnabled(false);
+ } else {
+ mSoftwareTypeCheckBox.setEnabled(true);
+ mHardwareTypeCheckBox.setEnabled(true);
+ }
+ }
+
+ private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
+ checkBox.setChecked((mUserShortcutTypeCache & type) == type);
+ checkBox.setOnClickListener(v -> {
+ updateUserShortcutType(/* saveChanges= */ false);
+ updateAlertDialogEnableState();
+ });
+ }
+
+ private void updateUserShortcutType(boolean saveChanges) {
+ mUserShortcutTypeCache = UserShortcutType.DEFAULT;
+ if (mSoftwareTypeCheckBox.isChecked()) {
+ mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
+ }
+ if (mHardwareTypeCheckBox.isChecked()) {
+ mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
+ }
+ if (saveChanges) {
+ mUserShortcutType = mUserShortcutTypeCache;
+ setUserShortcutType(getPrefContext(), mUserShortcutType);
+ }
+ }
+
+ private void setUserShortcutType(Context context, int type) {
+ if (mComponentName == null) {
+ return;
+ }
+
+ Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
+ final String componentName = mComponentName.flattenToString();
+ if (info.isEmpty()) {
+ info = new HashSet<>();
+ } else {
+ final Set<String> filtered = info.stream().filter(
+ str -> str.contains(componentName)).collect(Collectors.toSet());
+ info.removeAll(filtered);
+ }
+ final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
+ componentName, type);
+ info.add(shortcut.flattenToString());
+ SharedPreferenceUtils.setUserShortcutType(context, info);
+ }
+
+ private String getShortcutTypeSummary(Context context) {
+ final int shortcutType = getUserShortcutType(context, UserShortcutType.SOFTWARE);
+ int resId = R.string.accessibility_shortcut_edit_dialog_title_software;
+ if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
+ resId = AccessibilityUtil.isTouchExploreEnabled(context)
+ ? R.string.accessibility_shortcut_edit_dialog_title_software_gesture_talkback
+ : R.string.accessibility_shortcut_edit_dialog_title_software_gesture;
+ }
+ final CharSequence softwareTitle = context.getText(resId);
+
+ List<CharSequence> list = new ArrayList<>();
+ if ((shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
+ list.add(softwareTitle);
+ }
+ if ((shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
+ final CharSequence hardwareTitle = context.getText(
+ R.string.accessibility_shortcut_edit_dialog_title_hardware);
+ list.add(hardwareTitle);
+ }
+
+ // Show software shortcut if first time to use.
+ if (list.isEmpty()) {
+ list.add(softwareTitle);
+ }
+ final String joinStrings = TextUtils.join(/* delimiter= */", ", list);
+ return AccessibilityUtil.capitalize(joinStrings);
+ }
+
+ protected int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
+ if (mComponentName == null) {
+ return defaultValue;
+ }
+
+ final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
+ final String componentName = mComponentName.flattenToString();
+ final Set<String> filtered = info.stream().filter(
+ str -> str.contains(componentName)).collect(
+ Collectors.toSet());
+ if (filtered.isEmpty()) {
+ return defaultValue;
+ }
+
+ final String str = (String) filtered.toArray()[0];
+ final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
+ return shortcut.getUserShortcutType();
+ }
+
+ private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
+ if (mComponentName == null) {
+ return;
+ }
+
+ updateUserShortcutType(/* saveChanges= */ true);
+ if (mShortcutPreference.getChecked()) {
+ AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType,
+ mComponentName);
+ AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType,
+ mComponentName);
+ }
+ mShortcutPreference.setSummary(
+ getShortcutTypeSummary(getPrefContext()));
+ }
+
+ private void updateShortcutPreferenceData() {
+ if (mComponentName == null) {
+ return;
+ }
+
+ // Get the user shortcut type from settings provider.
+ mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+ mComponentName);
+ if (mUserShortcutType != UserShortcutType.DEFAULT) {
+ setUserShortcutType(getPrefContext(), mUserShortcutType);
+ } else {
+ // Get the user shortcut type from shared_prefs if cannot get from settings provider.
+ mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
+ }
+ }
+
+ private void initShortcutPreference(Bundle savedInstanceState) {
+ // Restore the user shortcut type.
+ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
+ mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
+ UserShortcutType.DEFAULT);
+ }
+
+ // Initial the shortcut preference.
+ mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
+ mShortcutPreference.setPersistent(false);
+ mShortcutPreference.setKey(getShortcutPreferenceKey());
+ mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
+ mShortcutPreference.setOnClickListener(this);
+ }
+
+ private void updateShortcutPreference() {
+ if (mComponentName == null) {
+ return;
+ }
+
+ final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
+ mShortcutPreference.setChecked(
+ AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
+ mComponentName));
+ mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
+ }
+
+ private String getShortcutPreferenceKey() {
+ return KEY_SHORTCUT_PREFERENCE;
+ }
+
+ @Override
+ public void onCheckboxClicked(ShortcutPreference preference) {
+ if (mComponentName == null) {
+ return;
+ }
+
+ final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
+ if (preference.getChecked()) {
+ AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
+ mComponentName);
+ } else {
+ AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
+ mComponentName);
+ }
+ }
+
+ @Override
+ public void onSettingsClicked(ShortcutPreference preference) {
+ mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
+ }
}
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 8e4da9d..8873da1 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -46,7 +46,6 @@
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
@@ -54,8 +53,6 @@
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -64,7 +61,7 @@
import java.util.stream.Collectors;
public class ToggleScreenMagnificationPreferenceFragment extends
- ToggleFeaturePreferenceFragment implements ShortcutPreference.OnClickListener {
+ ToggleFeaturePreferenceFragment {
private static final String SETTINGS_KEY = "screen_magnification_settings";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
@@ -172,8 +169,9 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+ mPackageName = getString(R.string.accessibility_screen_magnification_title);
mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
- removeDialog(DialogType.EDIT_SHORTCUT);
+ removeDialog(DialogEnums.EDIT_SHORTCUT);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
};
return super.onCreateView(inflater, container, savedInstanceState);
@@ -181,7 +179,7 @@
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
- final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
+ final PreferenceScreen preferenceScreen = getPreferenceScreen();
mVideoPreference = new VideoPreference(getPrefContext());
mVideoPreference.setSelectable(false);
mVideoPreference.setPersistent(false);
@@ -206,13 +204,6 @@
}
@Override
- protected void updateFooterTitle(PreferenceCategory category) {
- final String titleText = getString(R.string.accessibility_footer_title,
- getString(R.string.accessibility_screen_magnification_title));
- category.setTitle(titleText);
- }
-
- @Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
super.onSaveInstanceState(outState);
@@ -248,13 +239,13 @@
@Override
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
- case DialogType.GESTURE_NAVIGATION_TUTORIAL:
+ case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
return AccessibilityGestureNavigationTutorial
.showGestureNavigationTutorialDialog(getActivity());
- case DialogType.ACCESSIBILITY_BUTTON_TUTORIAL:
+ case DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL:
return AccessibilityGestureNavigationTutorial
.showAccessibilityButtonTutorialDialog(getActivity());
- case DialogType.EDIT_SHORTCUT:
+ case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
final CharSequence dialogTitle = getActivity().getText(
R.string.accessibility_shortcut_edit_dialog_title_magnification);
final AlertDialog dialog =
@@ -340,12 +331,12 @@
info = new HashSet<>();
} else {
final Set<String> filtered = info.stream().filter(
- str -> str.contains(getComponentName())).collect(
+ str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
Collectors.toSet());
info.removeAll(filtered);
}
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
- getComponentName(), type);
+ MAGNIFICATION_CONTROLLER_NAME, type);
info.add(shortcut.flattenToString());
SharedPreferenceUtils.setUserShortcutType(context, info);
}
@@ -384,10 +375,11 @@
return AccessibilityUtil.capitalize(joinStrings);
}
- private int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
+ @Override
+ protected int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
final Set<String> filtered = info.stream().filter(
- str -> str.contains(getComponentName())).collect(
+ str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
Collectors.toSet());
if (filtered.isEmpty()) {
return defaultValue;
@@ -401,17 +393,13 @@
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
updateUserShortcutType(/* saveChanges= */ true);
if (mShortcutPreference.getChecked()) {
- optInAllMagnificationValuesToSettings(getContext(), mUserShortcutType);
- optOutAllMagnificationValuesFromSettings(getContext(), ~mUserShortcutType);
+ optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
+ optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
}
mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext()));
}
- private String getComponentName() {
- return MAGNIFICATION_CONTROLLER_NAME;
- }
-
@Override
public int getMetricsCategory() {
// TODO: Distinguish between magnification modes
@@ -421,11 +409,11 @@
@Override
public int getDialogMetricsCategory(int dialogId) {
switch (dialogId) {
- case DialogType.GESTURE_NAVIGATION_TUTORIAL:
+ case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
return SettingsEnums.DIALOG_TOGGLE_SCREEN_MAGNIFICATION_GESTURE_NAVIGATION;
- case DialogType.ACCESSIBILITY_BUTTON_TUTORIAL:
+ case DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL:
return SettingsEnums.DIALOG_TOGGLE_SCREEN_MAGNIFICATION_ACCESSIBILITY_BUTTON;
- case DialogType.EDIT_SHORTCUT:
+ case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
return SettingsEnums.DIALOG_MAGNIFICATION_EDIT_SHORTCUT;
default:
return 0;
@@ -438,8 +426,8 @@
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
preferenceKey)) {
showDialog(AccessibilityUtil.isGestureNavigateEnabled(getContext())
- ? DialogType.GESTURE_NAVIGATION_TUTORIAL
- : DialogType.ACCESSIBILITY_BUTTON_TUTORIAL);
+ ? DialogEnums.GESTURE_NAVIGATION_TUTORIAL
+ : DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL);
}
MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled);
updateConfigurationWarningIfNeeded();
@@ -480,7 +468,7 @@
@Override
public void onSettingsClicked(ShortcutPreference preference) {
mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
- showDialog(DialogType.EDIT_SHORTCUT);
+ showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
}
private void updateShortcutPreferenceData() {
@@ -532,13 +520,6 @@
mConfigWarningPreference.setVisible(warningMessage != null);
}
- @Retention(RetentionPolicy.SOURCE)
- private @interface DialogType {
- int GESTURE_NAVIGATION_TUTORIAL = 1;
- int ACCESSIBILITY_BUTTON_TUTORIAL = 2;
- int EDIT_SHORTCUT = 3;
- }
-
@VisibleForTesting
static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {