From 5d7083a1035b675ed1f186f8579d204abc9b6295 Mon Sep 17 00:00:00 2001 From: menghanli Date: Wed, 4 Mar 2020 21:47:57 +0800 Subject: [PATCH] ShortcutPreference Toggle design (2/n) - Removes edit shortcut disable condition. - Shows "off" if user removes all items in edit dialog. - Restores last time what user chosen options when show edit dialog. Bug: 148989269 Test: Manually test Change-Id: I105abda782999d38c92e3de9811e2fd378869e73 --- ...essibility_edit_shortcut_magnification.xml | 6 +- .../accessibility/AccessibilityUtil.java | 8 +-- ...ccessibilityServicePreferenceFragment.java | 2 + .../ToggleFeaturePreferenceFragment.java | 61 ++++++++----------- ...ScreenMagnificationPreferenceFragment.java | 44 +++++-------- .../ToggleFeaturePreferenceFragmentTest.java | 6 +- 6 files changed, 53 insertions(+), 74 deletions(-) diff --git a/res/layout/accessibility_edit_shortcut_magnification.xml b/res/layout/accessibility_edit_shortcut_magnification.xml index afb1ec88412..0253edfdaa1 100644 --- a/res/layout/accessibility_edit_shortcut_magnification.xml +++ b/res/layout/accessibility_edit_shortcut_magnification.xml @@ -44,19 +44,21 @@ android:id="@+id/advanced_shortcut" android:layout_width="match_parent" android:layout_height="wrap_content" + android:minHeight="?android:attr/listPreferredItemHeightSmall" android:orientation="horizontal"> { updateUserShortcutType(/* saveChanges= */ false); - updateAlertDialogEnableState(); }); } private void updateUserShortcutType(boolean saveChanges) { - mUserShortcutTypeCache = UserShortcutType.DEFAULT; + mUserShortcutTypeCache = UserShortcutType.EMPTY; if (mSoftwareTypeCheckBox.isChecked()) { mUserShortcutTypeCache |= UserShortcutType.SOFTWARE; } if (mHardwareTypeCheckBox.isChecked()) { mUserShortcutTypeCache |= UserShortcutType.HARDWARE; } + if (saveChanges) { + final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY); + if (isChanged) { + setUserShortcutType(getPrefContext(), mUserShortcutTypeCache); + } mUserShortcutType = mUserShortcutTypeCache; - setUserShortcutType(getPrefContext(), mUserShortcutType); } } @@ -573,7 +564,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference final String str = (String) filtered.toArray()[0]; final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str); - return shortcut.getUserShortcutType(); + return shortcut.getType(); } private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) { @@ -582,13 +573,11 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference } updateUserShortcutType(/* saveChanges= */ true); - if (mShortcutPreference.isChecked()) { - AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType, - mComponentName); - AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType, - mComponentName); - } - mShortcutPreference.setChecked(true); + AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType, + mComponentName); + AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType, + mComponentName); + mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY); mShortcutPreference.setSummary( getShortcutTypeSummary(getPrefContext())); } @@ -601,7 +590,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference // Get the user shortcut type from settings provider. mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(), mComponentName); - if (mUserShortcutType != UserShortcutType.DEFAULT) { + if (mUserShortcutType != UserShortcutType.EMPTY) { setUserShortcutType(getPrefContext(), mUserShortcutType); } else { // Get the user shortcut type from shared_prefs if cannot get from settings provider. @@ -613,7 +602,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference // Restore the user shortcut type. if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) { mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE, - UserShortcutType.DEFAULT); + UserShortcutType.EMPTY); } // Initial the shortcut preference. diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 671623494f9..292e93138d5 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -70,9 +70,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference"; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; - private int mUserShortcutType = UserShortcutType.DEFAULT; + private int mUserShortcutType = UserShortcutType.EMPTY; // Used to restore the edit dialog status. - private int mUserShortcutTypeCache = UserShortcutType.DEFAULT; + private int mUserShortcutTypeCache = UserShortcutType.EMPTY; private CheckBox mSoftwareTypeCheckBox; private CheckBox mHardwareTypeCheckBox; private CheckBox mTripleTapTypeCheckBox; @@ -255,7 +255,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox); final View advancedView = dialog.findViewById(R.id.advanced_shortcut); updateAlertDialogCheckState(); - updateAlertDialogEnableState(); // Window magnification mode doesn't support advancedView. if (isWindowMagnification(getPrefContext())) { @@ -275,30 +274,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP); } - private void updateAlertDialogEnableState() { - if (!mSoftwareTypeCheckBox.isChecked() && !mTripleTapTypeCheckBox.isChecked()) { - mHardwareTypeCheckBox.setEnabled(false); - } else if (!mHardwareTypeCheckBox.isChecked() && !mTripleTapTypeCheckBox.isChecked()) { - mSoftwareTypeCheckBox.setEnabled(false); - } else if (!mSoftwareTypeCheckBox.isChecked() && !mHardwareTypeCheckBox.isChecked()) { - mTripleTapTypeCheckBox.setEnabled(false); - } else { - mSoftwareTypeCheckBox.setEnabled(true); - mHardwareTypeCheckBox.setEnabled(true); - mTripleTapTypeCheckBox.setEnabled(true); - } - } - private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) { checkBox.setChecked((mUserShortcutTypeCache & type) == type); checkBox.setOnClickListener(v -> { updateUserShortcutType(/* saveChanges= */ false); - updateAlertDialogEnableState(); }); } private void updateUserShortcutType(boolean saveChanges) { - mUserShortcutTypeCache = UserShortcutType.DEFAULT; + mUserShortcutTypeCache = UserShortcutType.EMPTY; if (mSoftwareTypeCheckBox.isChecked()) { mUserShortcutTypeCache |= UserShortcutType.SOFTWARE; } @@ -308,9 +292,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends if (mTripleTapTypeCheckBox.isChecked()) { mUserShortcutTypeCache |= UserShortcutType.TRIPLETAP; } + if (saveChanges) { + final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY); + if (isChanged) { + setUserShortcutType(getPrefContext(), mUserShortcutTypeCache); + } mUserShortcutType = mUserShortcutTypeCache; - setUserShortcutType(getPrefContext(), mUserShortcutType); } } @@ -336,7 +324,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends return context.getText(R.string.switch_off_text); } - final int shortcutType = getUserShortcutType(context, UserShortcutType.DEFAULT); + final int shortcutType = getUserShortcutType(context, UserShortcutType.EMPTY); int resId = R.string.accessibility_shortcut_edit_summary_software; if (AccessibilityUtil.isGestureNavigateEnabled(context)) { resId = AccessibilityUtil.isTouchExploreEnabled(context) @@ -381,16 +369,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends final String str = (String) filtered.toArray()[0]; final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str); - return shortcut.getUserShortcutType(); + return shortcut.getType(); } private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) { updateUserShortcutType(/* saveChanges= */ true); - if (mShortcutPreference.isChecked()) { - optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType); - optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType); - } - mShortcutPreference.setChecked(true); + optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType); + optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType); + mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY); mShortcutPreference.setSummary( getShortcutTypeSummary(getPrefContext())); } @@ -467,7 +453,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends private void updateShortcutPreferenceData() { // Get the user shortcut type from settings provider. mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext()); - if (mUserShortcutType != UserShortcutType.DEFAULT) { + if (mUserShortcutType != UserShortcutType.EMPTY) { setUserShortcutType(getPrefContext(), mUserShortcutType); } else { // Get the user shortcut type from shared_prefs if cannot get from settings provider. @@ -626,7 +612,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends } private static int getUserShortcutTypeFromSettings(Context context) { - int shortcutTypes = UserShortcutType.DEFAULT; + int shortcutTypes = UserShortcutType.EMPTY; if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) { shortcutTypes |= UserShortcutType.SOFTWARE; } diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java index 35a2d19ca8b..e476c21f37d 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java @@ -60,7 +60,7 @@ public class ToggleFeaturePreferenceFragmentTest { TEST_SERVICE_KEY_1); assertThat(shortcut.getComponentName()).isEqualTo(TEST_SERVICE_NAME_1); - assertThat(shortcut.getUserShortcutType()).isEqualTo(TEST_SERVICE_VALUE_1); + assertThat(shortcut.getType()).isEqualTo(TEST_SERVICE_VALUE_1); } @Test @@ -69,7 +69,7 @@ public class ToggleFeaturePreferenceFragmentTest { TEST_SERVICE_KEY_2); shortcut.setComponentName(TEST_SERVICE_NAME_1); - shortcut.setUserShortcutType(TEST_SERVICE_VALUE_1); + shortcut.setType(TEST_SERVICE_VALUE_1); assertThat(shortcut.flattenToString()).isEqualTo(TEST_SERVICE_KEY_1); } @@ -103,7 +103,7 @@ public class ToggleFeaturePreferenceFragmentTest { final String str = (String) filtered.toArray()[0]; final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str); - final int type = shortcut.getUserShortcutType(); + final int type = shortcut.getType(); assertThat(type).isEqualTo(TEST_SERVICE_VALUE_1); }