Fix inconsistent shortcut strings on accessibility setting and edit dialog
Root cause: Base class provides an override function for accessibility settings shortcut preference. But, it cannot update to the edit dialog.
Solution: Refine the resilience function and base class apply into accessibility settings shortcut preference and edit dailog.
Bug: 228830417
Test: Manual testing on all accessibility page and edit dialog
Change-Id: I84bc63a39cd9cfa7e12944dff20ee6b92879008d
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index 34e1fb0..5546ba6 100644
--- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
@@ -132,8 +132,8 @@
mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setOnClickCallback(this);
+ mShortcutPreference.setTitle(getShortcutTitle());
- updateShortcutTitle(mShortcutPreference);
getPreferenceScreen().addPreference(mShortcutPreference);
mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
@@ -192,13 +192,11 @@
final Dialog dialog;
switch (dialogId) {
case DialogEnums.EDIT_SHORTCUT:
- final CharSequence dialogTitle = getPrefContext().getString(
- R.string.accessibility_shortcut_title, getLabelName());
final int dialogType = WizardManagerHelper.isAnySetupWizard(getIntent())
? AccessibilityDialogUtils.DialogType.EDIT_SHORTCUT_GENERIC_SUW :
AccessibilityDialogUtils.DialogType.EDIT_SHORTCUT_GENERIC;
dialog = AccessibilityDialogUtils.showEditShortcutDialog(
- getPrefContext(), dialogType, dialogTitle,
+ getPrefContext(), dialogType, getShortcutTitle(),
this::callOnAlertDialogCheckboxClicked);
setupEditShortcutDialog(dialog);
return dialog;
@@ -213,9 +211,8 @@
}
}
- protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
- final CharSequence title = getString(R.string.accessibility_shortcut_title, getLabelName());
- shortcutPreference.setTitle(title);
+ protected CharSequence getShortcutTitle() {
+ return getString(R.string.accessibility_shortcut_title, getLabelName());
}
@Override
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index 5883714..71f47cc 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -75,8 +75,8 @@
}
@Override
- protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
- shortcutPreference.setTitle(R.string.accessibility_display_inversion_shortcut_title);
+ protected CharSequence getShortcutTitle() {
+ return getText(R.string.accessibility_display_inversion_shortcut_title);
}
@Override
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 183da96..ac4408f 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -185,8 +185,8 @@
}
@Override
- protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
- shortcutPreference.setTitle(R.string.accessibility_daltonizer_shortcut_title);
+ protected CharSequence getShortcutTitle() {
+ return getText(R.string.accessibility_daltonizer_shortcut_title);
}
@Override
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index bd8ee66..43687a5 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -270,12 +270,10 @@
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
case DialogEnums.EDIT_SHORTCUT:
- final CharSequence dialogTitle = getPrefContext().getString(
- R.string.accessibility_shortcut_title, mPackageName);
final int dialogType = WizardManagerHelper.isAnySetupWizard(getIntent())
? DialogType.EDIT_SHORTCUT_GENERIC_SUW : DialogType.EDIT_SHORTCUT_GENERIC;
mDialog = AccessibilityDialogUtils.showEditShortcutDialog(
- getPrefContext(), dialogType, dialogTitle,
+ getPrefContext(), dialogType, getShortcutTitle(),
this::callOnAlertDialogCheckboxClicked);
setupEditShortcutDialog(mDialog);
return mDialog;
@@ -340,9 +338,8 @@
switchPreference.setTitle(title);
}
- protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
- final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
- shortcutPreference.setTitle(title);
+ protected CharSequence getShortcutTitle() {
+ return getString(R.string.accessibility_shortcut_title, mPackageName);
}
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
@@ -515,8 +512,7 @@
mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setOnClickCallback(this);
-
- updateShortcutTitle(mShortcutPreference);
+ mShortcutPreference.setTitle(getShortcutTitle());
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
generalCategory.addPreference(mShortcutPreference);
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index 93884b7..4e990f4 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -168,8 +168,8 @@
}
@Override
- protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
- shortcutPreference.setTitle(R.string.reduce_bright_colors_shortcut_title);
+ protected CharSequence getShortcutTitle() {
+ return getText(R.string.reduce_bright_colors_shortcut_title);
}
@Override
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index bf47658..d9a02c0 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -479,8 +479,8 @@
}
@Override
- protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
- shortcutPreference.setTitle(R.string.accessibility_screen_magnification_shortcut_title);
+ protected CharSequence getShortcutTitle() {
+ return getText(R.string.accessibility_screen_magnification_shortcut_title);
}
@Override
diff --git a/src/com/android/settings/gestures/OneHandedSettings.java b/src/com/android/settings/gestures/OneHandedSettings.java
index 13ccbd6..e1b9b81 100644
--- a/src/com/android/settings/gestures/OneHandedSettings.java
+++ b/src/com/android/settings/gestures/OneHandedSettings.java
@@ -27,7 +27,6 @@
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
-import com.android.settings.accessibility.ShortcutPreference;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.widget.IllustrationPreference;
import com.android.settingslib.widget.MainSwitchPreference;
@@ -88,8 +87,8 @@
}
@Override
- protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
- shortcutPreference.setTitle(R.string.one_handed_mode_shortcut_title);
+ protected CharSequence getShortcutTitle() {
+ return getText(R.string.one_handed_mode_shortcut_title);
}
@Override