Refactoring Accessibility settings to use ShortcutConstants.UserShortcutType

This removes AccessibilityUtil.UserShortcutType,
replacing all mention of it with ShortcutConstants.UserShortcutType

NO_IFTTT=UI order not changed
Test: atest com.android.settings.accessibility
Bug: 322014084
Flag: EXEMPT internal refactoring

Change-Id: I18695d040c4bd08a455143594e770adda2b1a8de
This commit is contained in:
Riley Jones
2024-06-29 02:52:34 +00:00
parent ac7236ec0f
commit 8f313621aa
14 changed files with 339 additions and 319 deletions

View File

@@ -18,6 +18,12 @@ package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_COMPONENT_NAME;
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.DEFAULT;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.QUICK_SETTINGS;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.TRIPLETAP;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.TWOFINGER_DOUBLETAP;
import static com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums;
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
@@ -50,13 +56,13 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.SwitchPreferenceCompat;
import androidx.preference.TwoStatePreference;
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.Flags;
import com.android.settings.DialogCreatable;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment;
import com.android.settings.utils.LocaleUtils;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -360,19 +366,19 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return NOT_SET;
}
int value = UserShortcutType.EMPTY;
int value = DEFAULT;
if (mSoftwareTypeCheckBox.isChecked()) {
value |= UserShortcutType.SOFTWARE;
value |= SOFTWARE;
}
if (mHardwareTypeCheckBox.isChecked()) {
value |= UserShortcutType.HARDWARE;
value |= HARDWARE;
}
if (mTripleTapTypeCheckBox.isChecked()) {
value |= UserShortcutType.TRIPLETAP;
value |= TRIPLETAP;
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (mTwoFingerTripleTapTypeCheckBox.isChecked()) {
value |= UserShortcutType.TWOFINGER_DOUBLETAP;
value |= TWOFINGER_DOUBLETAP;
}
}
return value;
@@ -422,18 +428,18 @@ public class ToggleScreenMagnificationPreferenceFragment extends
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = getUserPreferredShortcutTypes();
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY;
: DEFAULT;
}
mSoftwareTypeCheckBox.setChecked(
hasShortcutType(value, UserShortcutType.SOFTWARE));
hasShortcutType(value, SOFTWARE));
mHardwareTypeCheckBox.setChecked(
hasShortcutType(value, UserShortcutType.HARDWARE));
hasShortcutType(value, HARDWARE));
mTripleTapTypeCheckBox.setChecked(
hasShortcutType(value, UserShortcutType.TRIPLETAP));
hasShortcutType(value, TRIPLETAP));
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
mTwoFingerTripleTapTypeCheckBox.setChecked(
hasShortcutType(value, UserShortcutType.TWOFINGER_DOUBLETAP));
hasShortcutType(value, TWOFINGER_DOUBLETAP));
}
}
@@ -499,28 +505,28 @@ public class ToggleScreenMagnificationPreferenceFragment extends
// LINT.IfChange(shortcut_type_ui_order)
final List<CharSequence> list = new ArrayList<>();
if (android.view.accessibility.Flags.a11yQsShortcut()) {
if (hasShortcutType(shortcutTypes, UserShortcutType.QUICK_SETTINGS)) {
if (hasShortcutType(shortcutTypes, QUICK_SETTINGS)) {
final CharSequence qsTitle = context.getText(
R.string.accessibility_feature_shortcut_setting_summary_quick_settings);
list.add(qsTitle);
}
}
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
if (hasShortcutType(shortcutTypes, SOFTWARE)) {
list.add(getSoftwareShortcutTypeSummary(context));
}
if (hasShortcutType(shortcutTypes, UserShortcutType.HARDWARE)) {
if (hasShortcutType(shortcutTypes, HARDWARE)) {
final CharSequence hardwareTitle = context.getText(
R.string.accessibility_shortcut_hardware_keyword);
list.add(hardwareTitle);
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (hasShortcutType(shortcutTypes, UserShortcutType.TWOFINGER_DOUBLETAP)) {
if (hasShortcutType(shortcutTypes, TWOFINGER_DOUBLETAP)) {
final CharSequence twoFingerDoubleTapTitle = context.getString(
R.string.accessibility_shortcut_two_finger_double_tap_keyword, 2);
list.add(twoFingerDoubleTapTitle);
}
}
if (hasShortcutType(shortcutTypes, UserShortcutType.TRIPLETAP)) {
if (hasShortcutType(shortcutTypes, TRIPLETAP)) {
final CharSequence tripleTapTitle = context.getText(
R.string.accessibility_shortcut_triple_tap_keyword);
list.add(tripleTapTitle);
@@ -543,7 +549,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
saveNonEmptyUserShortcutType(value);
optInAllMagnificationValuesToSettings(getPrefContext(), value);
optOutAllMagnificationValuesFromSettings(getPrefContext(), ~value);
mShortcutPreference.setChecked(value != UserShortcutType.EMPTY);
mShortcutPreference.setChecked(value != DEFAULT);
mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext()));
@@ -643,7 +649,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
protected void updateShortcutPreferenceData() {
final int shortcutTypes = getUserShortcutTypeFromSettings(getPrefContext());
if (shortcutTypes != UserShortcutType.EMPTY) {
if (shortcutTypes != DEFAULT) {
final PreferredShortcut shortcut = new PreferredShortcut(
MAGNIFICATION_CONTROLLER_NAME, shortcutTypes);
PreferredShortcuts.saveUserShortcutType(getPrefContext(), shortcut);
@@ -678,7 +684,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@VisibleForTesting
void saveNonEmptyUserShortcutType(int type) {
if (type == UserShortcutType.EMPTY) {
if (type == DEFAULT) {
return;
}
@@ -689,25 +695,25 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@VisibleForTesting
static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
optInMagnificationValueToSettings(context, UserShortcutType.SOFTWARE);
if ((shortcutTypes & SOFTWARE) == SOFTWARE) {
optInMagnificationValueToSettings(context, SOFTWARE);
}
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
optInMagnificationValueToSettings(context, UserShortcutType.HARDWARE);
if (((shortcutTypes & HARDWARE) == HARDWARE)) {
optInMagnificationValueToSettings(context, HARDWARE);
}
if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
optInMagnificationValueToSettings(context, UserShortcutType.TRIPLETAP);
if (((shortcutTypes & TRIPLETAP) == TRIPLETAP)) {
optInMagnificationValueToSettings(context, TRIPLETAP);
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (((shortcutTypes & UserShortcutType.TWOFINGER_DOUBLETAP)
== UserShortcutType.TWOFINGER_DOUBLETAP)) {
optInMagnificationValueToSettings(context, UserShortcutType.TWOFINGER_DOUBLETAP);
if (((shortcutTypes & TWOFINGER_DOUBLETAP)
== TWOFINGER_DOUBLETAP)) {
optInMagnificationValueToSettings(context, TWOFINGER_DOUBLETAP);
}
}
if (android.view.accessibility.Flags.a11yQsShortcut()) {
if (((shortcutTypes & UserShortcutType.QUICK_SETTINGS)
== UserShortcutType.QUICK_SETTINGS)) {
optInMagnificationValueToSettings(context, UserShortcutType.QUICK_SETTINGS);
if (((shortcutTypes & QUICK_SETTINGS)
== QUICK_SETTINGS)) {
optInMagnificationValueToSettings(context, QUICK_SETTINGS);
}
}
}
@@ -727,14 +733,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return;
}
if (shortcutType == UserShortcutType.TRIPLETAP) {
if (shortcutType == TRIPLETAP) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
return;
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (shortcutType == UserShortcutType.TWOFINGER_DOUBLETAP) {
if (shortcutType == TWOFINGER_DOUBLETAP) {
Settings.Secure.putInt(
context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
@@ -760,7 +766,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
// The size setting defaults to unknown. If the user has ever manually changed the size
// before, we do not automatically change it.
if (shortcutType == UserShortcutType.SOFTWARE
if (shortcutType == SOFTWARE
&& Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.UNKNOWN)
@@ -774,25 +780,25 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@VisibleForTesting
static void optOutAllMagnificationValuesFromSettings(Context context,
int shortcutTypes) {
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
optOutMagnificationValueFromSettings(context, UserShortcutType.SOFTWARE);
if ((shortcutTypes & SOFTWARE) == SOFTWARE) {
optOutMagnificationValueFromSettings(context, SOFTWARE);
}
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
optOutMagnificationValueFromSettings(context, UserShortcutType.HARDWARE);
if (((shortcutTypes & HARDWARE) == HARDWARE)) {
optOutMagnificationValueFromSettings(context, HARDWARE);
}
if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
optOutMagnificationValueFromSettings(context, UserShortcutType.TRIPLETAP);
if (((shortcutTypes & TRIPLETAP) == TRIPLETAP)) {
optOutMagnificationValueFromSettings(context, TRIPLETAP);
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (((shortcutTypes & UserShortcutType.TWOFINGER_DOUBLETAP)
== UserShortcutType.TWOFINGER_DOUBLETAP)) {
optOutMagnificationValueFromSettings(context, UserShortcutType.TWOFINGER_DOUBLETAP);
if (((shortcutTypes & TWOFINGER_DOUBLETAP)
== TWOFINGER_DOUBLETAP)) {
optOutMagnificationValueFromSettings(context, TWOFINGER_DOUBLETAP);
}
}
if (android.view.accessibility.Flags.a11yQsShortcut()) {
if (((shortcutTypes & UserShortcutType.QUICK_SETTINGS)
== UserShortcutType.QUICK_SETTINGS)) {
optOutMagnificationValueFromSettings(context, UserShortcutType.QUICK_SETTINGS);
if (((shortcutTypes & QUICK_SETTINGS)
== QUICK_SETTINGS)) {
optOutMagnificationValueFromSettings(context, QUICK_SETTINGS);
}
}
}
@@ -812,14 +818,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return;
}
if (shortcutType == UserShortcutType.TRIPLETAP) {
if (shortcutType == TRIPLETAP) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
return;
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (shortcutType == UserShortcutType.TWOFINGER_DOUBLETAP) {
if (shortcutType == TWOFINGER_DOUBLETAP) {
Settings.Secure.putInt(
context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
@@ -854,20 +860,20 @@ public class ToggleScreenMagnificationPreferenceFragment extends
static boolean hasMagnificationValuesInSettings(Context context, int shortcutTypes) {
boolean exist = false;
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
exist = hasMagnificationValueInSettings(context, UserShortcutType.SOFTWARE);
if ((shortcutTypes & SOFTWARE) == SOFTWARE) {
exist = hasMagnificationValueInSettings(context, SOFTWARE);
}
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
exist |= hasMagnificationValueInSettings(context, UserShortcutType.HARDWARE);
if (((shortcutTypes & HARDWARE) == HARDWARE)) {
exist |= hasMagnificationValueInSettings(context, HARDWARE);
}
if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
exist |= hasMagnificationValueInSettings(context, UserShortcutType.TRIPLETAP);
if (((shortcutTypes & TRIPLETAP) == TRIPLETAP)) {
exist |= hasMagnificationValueInSettings(context, TRIPLETAP);
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (((shortcutTypes & UserShortcutType.TWOFINGER_DOUBLETAP)
== UserShortcutType.TWOFINGER_DOUBLETAP)) {
if (((shortcutTypes & TWOFINGER_DOUBLETAP)
== TWOFINGER_DOUBLETAP)) {
exist |= hasMagnificationValueInSettings(context,
UserShortcutType.TWOFINGER_DOUBLETAP);
TWOFINGER_DOUBLETAP);
}
}
return exist;
@@ -875,13 +881,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static boolean hasMagnificationValueInSettings(Context context,
@UserShortcutType int shortcutType) {
if (shortcutType == UserShortcutType.TRIPLETAP) {
if (shortcutType == TRIPLETAP) {
return Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF) == ON;
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (shortcutType == UserShortcutType.TWOFINGER_DOUBLETAP) {
if (shortcutType == TWOFINGER_DOUBLETAP) {
return Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
OFF) == ON;
@@ -907,19 +913,19 @@ public class ToggleScreenMagnificationPreferenceFragment extends
}
private static int getUserShortcutTypeFromSettings(Context context) {
int shortcutTypes = UserShortcutType.EMPTY;
if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) {
shortcutTypes |= UserShortcutType.SOFTWARE;
int shortcutTypes = DEFAULT;
if (hasMagnificationValuesInSettings(context, SOFTWARE)) {
shortcutTypes |= SOFTWARE;
}
if (hasMagnificationValuesInSettings(context, UserShortcutType.HARDWARE)) {
shortcutTypes |= UserShortcutType.HARDWARE;
if (hasMagnificationValuesInSettings(context, HARDWARE)) {
shortcutTypes |= HARDWARE;
}
if (hasMagnificationValuesInSettings(context, UserShortcutType.TRIPLETAP)) {
shortcutTypes |= UserShortcutType.TRIPLETAP;
if (hasMagnificationValuesInSettings(context, TRIPLETAP)) {
shortcutTypes |= TRIPLETAP;
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (hasMagnificationValuesInSettings(context, UserShortcutType.TWOFINGER_DOUBLETAP)) {
shortcutTypes |= UserShortcutType.TWOFINGER_DOUBLETAP;
if (hasMagnificationValuesInSettings(context, TWOFINGER_DOUBLETAP)) {
shortcutTypes |= TWOFINGER_DOUBLETAP;
}
}
return shortcutTypes;
@@ -934,7 +940,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
// Get the user shortcut type from settings provider.
final int userShortcutType = getUserShortcutTypeFromSettings(context);
final CharSequence featureState =
(userShortcutType != AccessibilityUtil.UserShortcutType.EMPTY)
(userShortcutType != DEFAULT)
? context.getText(R.string.accessibility_summary_shortcut_enabled)
: context.getText(R.string.generic_accessibility_feature_shortcut_off);
final CharSequence featureSummary = context.getText(R.string.magnification_feature_summary);