Merge "Move the default shortcut types in a separate utility method." into main

This commit is contained in:
Chun-Ku Lin
2024-01-29 21:15:53 +00:00
committed by Android (Google) Code Review
10 changed files with 60 additions and 54 deletions

View File

@@ -272,7 +272,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
getComponentName().flattenToString(), AccessibilityUtil.UserShortcutType.SOFTWARE);
getComponentName().flattenToString());
if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
getComponentName());
@@ -449,7 +449,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context,
getComponentName().flattenToString(), AccessibilityUtil.UserShortcutType.SOFTWARE);
getComponentName().flattenToString());
final List<CharSequence> list = new ArrayList<>();
@@ -477,8 +477,8 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), getComponentName().flattenToString(),
AccessibilityUtil.UserShortcutType.SOFTWARE);
getPrefContext(), getComponentName().flattenToString()
);
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: AccessibilityUtil.UserShortcutType.EMPTY;
}
@@ -519,7 +519,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
getComponentName().flattenToString(), AccessibilityUtil.UserShortcutType.SOFTWARE);
getComponentName().flattenToString());
mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
getComponentName()));

View File

@@ -39,27 +39,25 @@ public final class PreferredShortcuts {
private static final String USER_SHORTCUT_TYPE = "user_shortcut_type";
/**
* Retrieves {@link UserShortcutType} for the given {@code componentName} from
* Retrieves the user preferred shortcut types for the given {@code componentName} from
* SharedPreferences.
*
* @param context {@link Context} to access the {@link SharedPreferences}
* @param componentName Name of the service or activity, should be the format of {@link
* ComponentName#flattenToString()}.
* @param defaultType See {@link UserShortcutType}
* @return {@link UserShortcutType}
* @return {@link ShortcutConstants.UserShortcutType}
*/
public static int retrieveUserShortcutType(Context context, String componentName,
int defaultType) {
if (componentName == null) {
return defaultType;
}
@ShortcutConstants.UserShortcutType
public static int retrieveUserShortcutType(
@NonNull Context context, @NonNull String componentName) {
final int defaultTypes = getDefaultPreferredShortcutTypesForTarget(componentName);
// Create a mutable set to modify
final Set<String> info = new HashSet<>(getFromSharedPreferences(context));
info.removeIf(str -> !str.contains(componentName));
if (info.isEmpty()) {
return defaultType;
return defaultTypes;
}
final String str = info.stream().findFirst().get();
@@ -140,5 +138,14 @@ public final class PreferredShortcuts {
return context.getSharedPreferences(ACCESSIBILITY_PERF, Context.MODE_PRIVATE);
}
/**
* Returns the default shortcut types for the given accessibility feature.
*/
@ShortcutConstants.UserShortcutType
private static int getDefaultPreferredShortcutTypesForTarget(@NonNull String componentName) {
// TODO (b/322712028): return different default shortcut types for the given component
return ShortcutConstants.UserShortcutType.SOFTWARE;
}
private PreferredShortcuts() {}
}

View File

@@ -47,7 +47,6 @@ import androidx.annotation.Nullable;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment;
import com.android.settingslib.accessibility.AccessibilityUtils;
@@ -331,7 +330,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
@Override
public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
mComponentName.flattenToString());
if (preference.isChecked()) {
final boolean isWarningRequired;
if (android.view.accessibility.Flags.cleanupAccessibilityWarningDialog()) {
@@ -508,7 +507,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mShortcutPreference.setChecked(true);
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
mComponentName.flattenToString());
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mIsDialogShown.set(false);

View File

@@ -658,7 +658,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
getPrefContext(), mComponentName.flattenToString());
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY;
}
@@ -708,7 +708,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context,
mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
mComponentName.flattenToString());
final List<CharSequence> list = new ArrayList<>();
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
@@ -801,7 +801,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
mComponentName.flattenToString());
mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
mComponentName));
@@ -819,7 +819,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
mComponentName.flattenToString());
if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName);

View File

@@ -386,7 +386,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
getPrefContext(), MAGNIFICATION_CONTROLLER_NAME);
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY;
}
@@ -460,7 +460,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context,
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
MAGNIFICATION_CONTROLLER_NAME);
final List<CharSequence> list = new ArrayList<>();
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
@@ -574,7 +574,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
MAGNIFICATION_CONTROLLER_NAME);
if (preference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
@@ -629,7 +629,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
protected void updateShortcutPreference() {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
MAGNIFICATION_CONTROLLER_NAME);
mShortcutPreference.setChecked(
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));