Merge "Pass user preferred shortcut types when launching the AccessibilityShortcutsTutorial." into main

This commit is contained in:
Chun-Ku Lin
2024-05-22 23:17:50 +00:00
committed by Android (Google) Code Review
4 changed files with 42 additions and 30 deletions

View File

@@ -42,6 +42,7 @@ import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment;
@@ -222,12 +223,12 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialogForSetupWizard(
getPrefContext(), getUserShortcutTypes(),
getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, getLabelName());
} else {
mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialog(
getPrefContext(), getUserShortcutTypes(),
getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, getLabelName());
}
mDialog.setCanceledOnTouchOutside(false);
@@ -274,8 +275,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
return;
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
getComponentName().flattenToString());
final int shortcutTypes = getUserPreferredShortcutTypes();
if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
getComponentName());
@@ -451,8 +451,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
return context.getText(R.string.accessibility_shortcut_state_off);
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context,
getComponentName().flattenToString());
final int shortcutTypes = getUserPreferredShortcutTypes();
// LINT.IfChange(shortcut_type_ui_order)
final List<CharSequence> list = new ArrayList<>();
@@ -487,9 +486,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
// when shortcutPreference is checked.
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), getComponentName().flattenToString()
);
final int lastNonEmptyUserShortcutType = getUserPreferredShortcutTypes();
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: AccessibilityUtil.UserShortcutType.EMPTY;
}
@@ -529,8 +526,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
return;
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
getComponentName().flattenToString());
final int shortcutTypes = getUserPreferredShortcutTypes();
mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
getComponentName()));
@@ -581,4 +577,14 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
tileComponentName);
mNeedsQSTooltipReshow = false;
}
/**
* Returns the user preferred shortcut types or the default shortcut types if not set
*/
@ShortcutConstants.UserShortcutType
protected int getUserPreferredShortcutTypes() {
return PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(),
getComponentName().flattenToString());
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums;
import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled;
import static com.android.settings.accessibility.PreferredShortcuts.retrieveUserShortcutType;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.AlertDialog;
@@ -327,8 +326,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
@Override
public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), getDefaultShortcutTypes());
final int shortcutTypes = getUserPreferredShortcutTypes();
if (preference.isChecked()) {
final boolean isWarningRequired =
getPrefContext().getSystemService(AccessibilityManager.class)
@@ -507,8 +505,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
void onAllowButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(true);
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), getDefaultShortcutTypes());
final int shortcutTypes = getUserPreferredShortcutTypes();
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mIsDialogShown.set(false);

View File

@@ -227,12 +227,12 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
if (isAnySetupWizard()) {
mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialogForSetupWizard(
getPrefContext(), getUserShortcutTypes(),
getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, mPackageName);
} else {
mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialog(
getPrefContext(), getUserShortcutTypes(),
getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, mPackageName);
}
mDialog.setCanceledOnTouchOutside(false);
@@ -662,8 +662,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
// when shortcutPreference is checked.
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), mComponentName.flattenToString(), getDefaultShortcutTypes());
final int lastNonEmptyUserShortcutType = getUserPreferredShortcutTypes();
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY;
}
@@ -814,8 +813,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
return;
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), getDefaultShortcutTypes());
final int shortcutTypes = getUserPreferredShortcutTypes();
mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
mComponentName));
@@ -832,8 +830,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
return;
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), getDefaultShortcutTypes());
final int shortcutTypes = getUserPreferredShortcutTypes();
if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName);
@@ -988,4 +985,13 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
protected int getDefaultShortcutTypes() {
return ShortcutConstants.UserShortcutType.SOFTWARE;
}
/**
* Returns the user preferred shortcut types or the default shortcut types if not set
*/
@ShortcutConstants.UserShortcutType
protected int getUserPreferredShortcutTypes() {
return PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), mComponentName.flattenToString(), getDefaultShortcutTypes());
}
}

View File

@@ -414,8 +414,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
// when shortcutPreference is checked.
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), MAGNIFICATION_CONTROLLER_NAME);
final int lastNonEmptyUserShortcutType = getUserPreferredShortcutTypes();
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY;
}
@@ -611,8 +610,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
MAGNIFICATION_CONTROLLER_NAME);
final int shortcutTypes = getUserPreferredShortcutTypes();
if (preference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
@@ -666,8 +664,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
protected void updateShortcutPreference() {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
MAGNIFICATION_CONTROLLER_NAME);
final int shortcutTypes = getUserPreferredShortcutTypes();
mShortcutPreference.setChecked(
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
@@ -938,4 +935,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return context.getString(R.string.preference_summary_default_combination,
featureState, featureSummary);
}
@Override
protected int getUserPreferredShortcutTypes() {
return PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), MAGNIFICATION_CONTROLLER_NAME);
}
}