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.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment; import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment;
@@ -222,12 +223,12 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
if (WizardManagerHelper.isAnySetupWizard(getIntent())) { if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
mDialog = AccessibilityShortcutsTutorial mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialogForSetupWizard( .createAccessibilityTutorialDialogForSetupWizard(
getPrefContext(), getUserShortcutTypes(), getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, getLabelName()); this::callOnTutorialDialogButtonClicked, getLabelName());
} else { } else {
mDialog = AccessibilityShortcutsTutorial mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialog( .createAccessibilityTutorialDialog(
getPrefContext(), getUserShortcutTypes(), getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, getLabelName()); this::callOnTutorialDialogButtonClicked, getLabelName());
} }
mDialog.setCanceledOnTouchOutside(false); mDialog.setCanceledOnTouchOutside(false);
@@ -274,8 +275,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
return; return;
} }
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
getComponentName().flattenToString());
if (preference.isChecked()) { if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
getComponentName()); getComponentName());
@@ -451,8 +451,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
return context.getText(R.string.accessibility_shortcut_state_off); return context.getText(R.string.accessibility_shortcut_state_off);
} }
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context, final int shortcutTypes = getUserPreferredShortcutTypes();
getComponentName().flattenToString());
// LINT.IfChange(shortcut_type_ui_order) // LINT.IfChange(shortcut_type_ui_order)
final List<CharSequence> list = new ArrayList<>(); final List<CharSequence> list = new ArrayList<>();
@@ -487,9 +486,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
// when shortcutPreference is checked. // when shortcutPreference is checked.
int value = restoreOnConfigChangedValue(); int value = restoreOnConfigChangedValue();
if (value == NOT_SET) { if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType( final int lastNonEmptyUserShortcutType = getUserPreferredShortcutTypes();
getPrefContext(), getComponentName().flattenToString()
);
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: AccessibilityUtil.UserShortcutType.EMPTY; : AccessibilityUtil.UserShortcutType.EMPTY;
} }
@@ -529,8 +526,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
return; return;
} }
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
getComponentName().flattenToString());
mShortcutPreference.setChecked( mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
getComponentName())); getComponentName()));
@@ -581,4 +577,14 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
tileComponentName); tileComponentName);
mNeedsQSTooltipReshow = false; 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.AccessibilityDialogUtils.DialogEnums;
import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled; import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled;
import static com.android.settings.accessibility.PreferredShortcuts.retrieveUserShortcutType;
import android.accessibilityservice.AccessibilityServiceInfo; import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.AlertDialog; import android.app.AlertDialog;
@@ -327,8 +326,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
@Override @Override
public void onToggleClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
mComponentName.flattenToString(), getDefaultShortcutTypes());
if (preference.isChecked()) { if (preference.isChecked()) {
final boolean isWarningRequired = final boolean isWarningRequired =
getPrefContext().getSystemService(AccessibilityManager.class) getPrefContext().getSystemService(AccessibilityManager.class)
@@ -507,8 +505,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
void onAllowButtonFromShortcutToggleClicked() { void onAllowButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(true); mShortcutPreference.setChecked(true);
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
mComponentName.flattenToString(), getDefaultShortcutTypes());
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName); AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mIsDialogShown.set(false); mIsDialogShown.set(false);

View File

@@ -227,12 +227,12 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
if (isAnySetupWizard()) { if (isAnySetupWizard()) {
mDialog = AccessibilityShortcutsTutorial mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialogForSetupWizard( .createAccessibilityTutorialDialogForSetupWizard(
getPrefContext(), getUserShortcutTypes(), getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, mPackageName); this::callOnTutorialDialogButtonClicked, mPackageName);
} else { } else {
mDialog = AccessibilityShortcutsTutorial mDialog = AccessibilityShortcutsTutorial
.createAccessibilityTutorialDialog( .createAccessibilityTutorialDialog(
getPrefContext(), getUserShortcutTypes(), getPrefContext(), getUserPreferredShortcutTypes(),
this::callOnTutorialDialogButtonClicked, mPackageName); this::callOnTutorialDialogButtonClicked, mPackageName);
} }
mDialog.setCanceledOnTouchOutside(false); mDialog.setCanceledOnTouchOutside(false);
@@ -662,8 +662,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
// when shortcutPreference is checked. // when shortcutPreference is checked.
int value = restoreOnConfigChangedValue(); int value = restoreOnConfigChangedValue();
if (value == NOT_SET) { if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType( final int lastNonEmptyUserShortcutType = getUserPreferredShortcutTypes();
getPrefContext(), mComponentName.flattenToString(), getDefaultShortcutTypes());
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY; : UserShortcutType.EMPTY;
} }
@@ -814,8 +813,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
return; return;
} }
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
mComponentName.flattenToString(), getDefaultShortcutTypes());
mShortcutPreference.setChecked( mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
mComponentName)); mComponentName));
@@ -832,8 +830,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
return; return;
} }
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
mComponentName.flattenToString(), getDefaultShortcutTypes());
if (preference.isChecked()) { if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName); mComponentName);
@@ -988,4 +985,13 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
protected int getDefaultShortcutTypes() { protected int getDefaultShortcutTypes() {
return ShortcutConstants.UserShortcutType.SOFTWARE; 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. // when shortcutPreference is checked.
int value = restoreOnConfigChangedValue(); int value = restoreOnConfigChangedValue();
if (value == NOT_SET) { if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType( final int lastNonEmptyUserShortcutType = getUserPreferredShortcutTypes();
getPrefContext(), MAGNIFICATION_CONTROLLER_NAME);
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY; : UserShortcutType.EMPTY;
} }
@@ -611,8 +610,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override @Override
public void onToggleClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
MAGNIFICATION_CONTROLLER_NAME);
if (preference.isChecked()) { if (preference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes); optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL); showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
@@ -666,8 +664,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override @Override
protected void updateShortcutPreference() { protected void updateShortcutPreference() {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(), final int shortcutTypes = getUserPreferredShortcutTypes();
MAGNIFICATION_CONTROLLER_NAME);
mShortcutPreference.setChecked( mShortcutPreference.setChecked(
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes)); hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
@@ -938,4 +935,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return context.getString(R.string.preference_summary_default_combination, return context.getString(R.string.preference_summary_default_combination,
featureState, featureSummary); featureState, featureSummary);
} }
@Override
protected int getUserPreferredShortcutTypes() {
return PreferredShortcuts.retrieveUserShortcutType(
getPrefContext(), MAGNIFICATION_CONTROLLER_NAME);
}
} }