From 48d73aa3f3dcd46f495498ebfe2375007f5a765b Mon Sep 17 00:00:00 2001 From: Jean Chen Date: Wed, 18 Oct 2023 23:11:54 +0800 Subject: [PATCH] feat(MultiFingerMultiTap): Add two-finger triple-tap shortcut on magnification dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The shortcut is separate from single-finger triple-tap. It’s under hardware shortcut and above/outside of Advanced section. Bug: 297805269 Test: manual Test: atest ToggleScreenMagnificationPreferenceFragmentTest Change-Id: Id74cf3e457c04e167f3100d977b6c70c5d601026 --- Android.bp | 1 + ...essibility_edit_shortcut_magnification.xml | 8 + res/values/strings.xml | 6 + .../AccessibilityDialogUtils.java | 24 +++ .../accessibility/AccessibilityUtil.java | 2 + ...ScreenMagnificationPreferenceFragment.java | 78 +++++++++ tests/robotests/Android.bp | 1 + ...enMagnificationPreferenceFragmentTest.java | 149 ++++++++++++++++++ 8 files changed, 269 insertions(+) diff --git a/Android.bp b/Android.bp index 54137ec1e00..03f9c1064f6 100644 --- a/Android.bp +++ b/Android.bp @@ -99,6 +99,7 @@ android_library { "settings-logtags", "settings-telephony-protos-lite", "statslog-settings", + "com_android_server_accessibility_flags_lib", ], plugins: ["androidx.room_room-compiler-plugin"], diff --git a/res/layout/accessibility_edit_shortcut_magnification.xml b/res/layout/accessibility_edit_shortcut_magnification.xml index 725c4c77d79..0f30a01d92e 100644 --- a/res/layout/accessibility_edit_shortcut_magnification.xml +++ b/res/layout/accessibility_edit_shortcut_magnification.xml @@ -46,6 +46,14 @@ android:layout_height="wrap_content" android:layout_marginBottom="32dp" /> + + hold volume keys Press & hold both volume keys + + Two-finger triple-tap screen + + two-finger triple-tap screen + + Quickly tap screen {0,number,integer} times with two fingers Triple-tap screen diff --git a/src/com/android/settings/accessibility/AccessibilityDialogUtils.java b/src/com/android/settings/accessibility/AccessibilityDialogUtils.java index f7449842499..c429e0b0d55 100644 --- a/src/com/android/settings/accessibility/AccessibilityDialogUtils.java +++ b/src/com/android/settings/accessibility/AccessibilityDialogUtils.java @@ -52,6 +52,7 @@ import androidx.annotation.RawRes; import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; +import com.android.server.accessibility.Flags; import com.android.settings.R; import com.android.settings.core.SubSettingLauncher; import com.android.settings.utils.AnnotationSpan; @@ -247,6 +248,9 @@ public class AccessibilityDialogUtils { R.layout.accessibility_edit_shortcut_magnification, null); initSoftwareShortcut(context, contentView); initHardwareShortcut(context, contentView); + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + initTwoFingerTripleTapMagnificationShortcut(context, contentView); + } initMagnifyShortcut(context, contentView); initAdvancedWidget(contentView); break; @@ -255,6 +259,9 @@ public class AccessibilityDialogUtils { R.layout.accessibility_edit_shortcut_magnification, null); initSoftwareShortcutForSUW(context, contentView); initHardwareShortcut(context, contentView); + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + initTwoFingerTripleTapMagnificationShortcut(context, contentView); + } initMagnifyShortcut(context, contentView); initAdvancedWidget(contentView); break; @@ -358,6 +365,23 @@ public class AccessibilityDialogUtils { R.raw.a11y_shortcut_type_triple_tap); } + private static void initTwoFingerTripleTapMagnificationShortcut(Context context, View view) { + // TODO(b/306153204): Update shortcut string and image when UX provides them + final View dialogView = view.findViewById(R.id.two_finger_triple_tap_shortcut); + final CharSequence title = context.getText( + R.string.accessibility_shortcut_edit_dialog_title_two_finger_triple_tap); + String summary = context.getString( + R.string.accessibility_shortcut_edit_dialog_summary_two_finger_triple_tap); + // Format the number '3' in the summary. + final Object[] arguments = {3}; + summary = MessageFormat.format(summary, arguments); + + setupShortcutWidgetWithImageRawResource(context, dialogView, title, summary, + R.raw.a11y_shortcut_type_triple_tap); + + dialogView.setVisibility(View.VISIBLE); + } + private static void initAdvancedWidget(View view) { final LinearLayout advanced = view.findViewById(R.id.advanced_shortcut); final View tripleTap = view.findViewById(R.id.triple_tap_shortcut); diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java index 36c99f1bf72..3b81bdb5110 100644 --- a/src/com/android/settings/accessibility/AccessibilityUtil.java +++ b/src/com/android/settings/accessibility/AccessibilityUtil.java @@ -94,6 +94,7 @@ public final class AccessibilityUtil { UserShortcutType.SOFTWARE, UserShortcutType.HARDWARE, UserShortcutType.TRIPLETAP, + UserShortcutType.TWOFINGERTRIPLETAP, }) /** Denotes the user shortcut type. */ @@ -102,6 +103,7 @@ public final class AccessibilityUtil { int SOFTWARE = 1; // 1 << 0 int HARDWARE = 2; // 1 << 1 int TRIPLETAP = 4; // 1 << 2 + int TWOFINGERTRIPLETAP = 8; // 1 << 3 } /** diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 16cf85dfb20..886719da5a1 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -42,12 +42,14 @@ import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener; import android.widget.CheckBox; +import androidx.annotation.Nullable; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.SwitchPreferenceCompat; import androidx.preference.TwoStatePreference; import com.android.internal.annotations.VisibleForTesting; +import com.android.server.accessibility.Flags; import com.android.settings.DialogCreatable; import com.android.settings.R; import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType; @@ -83,6 +85,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends private CheckBox mSoftwareTypeCheckBox; private CheckBox mHardwareTypeCheckBox; private CheckBox mTripleTapTypeCheckBox; + @Nullable private CheckBox mTwoFingerTripleTapTypeCheckBox; private DialogCreatable mDialogDelegate; private MagnificationFollowTypingPreferenceController mFollowTypingPreferenceController; @@ -330,6 +333,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends if (mTripleTapTypeCheckBox.isChecked()) { value |= UserShortcutType.TRIPLETAP; } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (mTwoFingerTripleTapTypeCheckBox.isChecked()) { + value |= UserShortcutType.TWOFINGERTRIPLETAP; + } + } return value; } @@ -343,6 +351,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox); setDialogTextAreaClickListener(dialogHardwareView, mHardwareTypeCheckBox); + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + final View dialogTwoFignerTripleTapView = + dialog.findViewById(R.id.two_finger_triple_tap_shortcut); + mTwoFingerTripleTapTypeCheckBox = dialogTwoFignerTripleTapView.findViewById( + R.id.checkbox); + setDialogTextAreaClickListener( + dialogTwoFignerTripleTapView, mTwoFingerTripleTapTypeCheckBox); + } + final View dialogTripleTapView = dialog.findViewById(R.id.triple_tap_shortcut); mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox); setDialogTextAreaClickListener(dialogTripleTapView, mTripleTapTypeCheckBox); @@ -378,6 +395,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends hasShortcutType(value, UserShortcutType.HARDWARE)); mTripleTapTypeCheckBox.setChecked( hasShortcutType(value, UserShortcutType.TRIPLETAP)); + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + mTwoFingerTripleTapTypeCheckBox.setChecked( + hasShortcutType(value, UserShortcutType.TWOFINGERTRIPLETAP)); + } } private int restoreOnConfigChangedValue() { @@ -453,6 +474,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends R.string.accessibility_shortcut_triple_tap_keyword); list.add(tripleTapTitle); } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (hasShortcutType(shortcutTypes, UserShortcutType.TWOFINGERTRIPLETAP)) { + final CharSequence twoFingerTripleTapTitle = context.getText( + R.string.accessibility_shortcut_two_finger_triple_tap_keyword); + list.add(twoFingerTripleTapTitle); + } + } // Show software shortcut if first time to use. if (list.isEmpty()) { @@ -618,6 +646,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) { optInMagnificationValueToSettings(context, UserShortcutType.TRIPLETAP); } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (((shortcutTypes & UserShortcutType.TWOFINGERTRIPLETAP) + == UserShortcutType.TWOFINGERTRIPLETAP)) { + optInMagnificationValueToSettings(context, UserShortcutType.TWOFINGERTRIPLETAP); + } + } } private static void optInMagnificationValueToSettings(Context context, @@ -628,6 +662,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends return; } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (shortcutType == UserShortcutType.TWOFINGERTRIPLETAP) { + Settings.Secure.putInt(context.getContentResolver(), + Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED, + ON); + return; + } + } + if (hasMagnificationValueInSettings(context, shortcutType)) { return; } @@ -668,6 +711,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) { optOutMagnificationValueFromSettings(context, UserShortcutType.TRIPLETAP); } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (((shortcutTypes & UserShortcutType.TWOFINGERTRIPLETAP) + == UserShortcutType.TWOFINGERTRIPLETAP)) { + optOutMagnificationValueFromSettings(context, UserShortcutType.TWOFINGERTRIPLETAP); + } + } } private static void optOutMagnificationValueFromSettings(Context context, @@ -678,6 +727,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends return; } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (shortcutType == UserShortcutType.TWOFINGERTRIPLETAP) { + Settings.Secure.putInt(context.getContentResolver(), + Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED, + OFF); + return; + } + } + final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType); final String targetString = Settings.Secure.getString(context.getContentResolver(), targetKey); @@ -713,6 +771,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) { exist |= hasMagnificationValueInSettings(context, UserShortcutType.TRIPLETAP); } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (((shortcutTypes & UserShortcutType.TWOFINGERTRIPLETAP) + == UserShortcutType.TWOFINGERTRIPLETAP)) { + exist |= hasMagnificationValueInSettings(context, + UserShortcutType.TWOFINGERTRIPLETAP); + } + } return exist; } @@ -723,6 +788,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF) == ON; } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (shortcutType == UserShortcutType.TWOFINGERTRIPLETAP) { + return Settings.Secure.getInt(context.getContentResolver(), + Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED, + OFF) == ON; + } + } + final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType); final String targetString = Settings.Secure.getString(context.getContentResolver(), targetKey); @@ -752,6 +825,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends if (hasMagnificationValuesInSettings(context, UserShortcutType.TRIPLETAP)) { shortcutTypes |= UserShortcutType.TRIPLETAP; } + if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { + if (hasMagnificationValuesInSettings(context, UserShortcutType.TWOFINGERTRIPLETAP)) { + shortcutTypes |= UserShortcutType.TWOFINGERTRIPLETAP; + } + } return shortcutTypes; } diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp index 68793a1d554..fa55f35f52d 100644 --- a/tests/robotests/Android.bp +++ b/tests/robotests/Android.bp @@ -66,6 +66,7 @@ android_robolectric_test { "platform-test-annotations", "Settings-testutils2", "notification_flags_lib", + "com_android_server_accessibility_flags_lib", ], libs: [ diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java index 539c50327d2..e5ac7932b1e 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java @@ -40,12 +40,16 @@ import android.content.res.Resources; import android.database.ContentObserver; import android.net.Uri; import android.os.Bundle; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.provider.Settings; import androidx.appcompat.app.AlertDialog; import androidx.preference.TwoStatePreference; import androidx.test.core.app.ApplicationProvider; +import com.android.server.accessibility.Flags; import com.android.settings.DialogCreatable; import com.android.settings.R; import com.android.settings.SettingsActivity; @@ -57,6 +61,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.google.common.truth.Correspondence; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -80,6 +85,9 @@ import java.util.List; }) public class ToggleScreenMagnificationPreferenceFragmentTest { + @Rule + public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); + private static final String PLACEHOLDER_PACKAGE_NAME = "com.mock.example"; private static final String PLACEHOLDER_CLASS_NAME = PLACEHOLDER_PACKAGE_NAME + ".mock_a11y_service"; @@ -93,6 +101,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE; private static final String TRIPLETAP_SHORTCUT_KEY = Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED; + private static final String TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY = + Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED; private static final String MAGNIFICATION_CONTROLLER_NAME = "com.android.server.accessibility.MagnificationController"; @@ -189,6 +199,26 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { mContext, UserShortcutType.TRIPLETAP)).isTrue(); } + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOn_isTrue() { + Settings.Secure.putInt( + mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON); + + assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings( + mContext, UserShortcutType.TWOFINGERTRIPLETAP)).isTrue(); + } + + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOff_isFalse() { + Settings.Secure.putInt( + mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF); + + assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings( + mContext, UserShortcutType.TWOFINGERTRIPLETAP)).isFalse(); + } + @Test public void optInAllValuesToSettings_optInValue_haveMatchString() { int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.TRIPLETAP; @@ -199,7 +229,18 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo( MAGNIFICATION_CONTROLLER_NAME); assertThat(getMagnificationTripleTapStatus()).isTrue(); + } + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void optInAllValuesToSettings_twoFingerTripleTap_haveMatchString() { + int shortcutTypes = UserShortcutType.TWOFINGERTRIPLETAP; + + ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext, + shortcutTypes); + + assertThat(Settings.Secure.getInt(mContext.getContentResolver(), + TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF)).isEqualTo(ON); } @Test @@ -296,6 +337,19 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { assertThat(getMagnificationTripleTapStatus()).isFalse(); } + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void optOutAllValuesToSettings_twoFingerTripleTap_settingsValueIsOff() { + Settings.Secure.putInt(mContext.getContentResolver(), + TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON); + + ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings( + mContext, UserShortcutType.TWOFINGERTRIPLETAP); + + assertThat(Settings.Secure.getInt(mContext.getContentResolver(), + TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON)).isEqualTo(OFF); + } + @Test public void optOutValueFromSettings_existOtherValue_optOutValue_haveMatchString() { putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, @@ -352,6 +406,35 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { assertThat(expectedType).isEqualTo(UserShortcutType.TRIPLETAP); } + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void updateShortcutPreferenceData_hasTwoFingerTripleTapInSettings_assignToVariable() { + Settings.Secure.putInt( + mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON); + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + mFragController.get().updateShortcutPreferenceData(); + + final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext, + MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE); + assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP); + } + + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void updateShortcutPreferenceData_hasTwoFingerTripleTapInSharedPref_assignToVariable() { + final PreferredShortcut tripleTapShortcut = new PreferredShortcut( + MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.TWOFINGERTRIPLETAP); + putUserShortcutTypeIntoSharedPreference(mContext, tripleTapShortcut); + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + mFragController.get().updateShortcutPreferenceData(); + + final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext, + MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE); + assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP); + } + @Test public void setupMagnificationEditShortcutDialog_shortcutPreferenceOff_checkboxIsEmptyValue() { ToggleScreenMagnificationPreferenceFragment fragment = @@ -387,6 +470,27 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { assertThat(checkboxValue).isEqualTo(UserShortcutType.TRIPLETAP); } + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void setupMagnificationEditShortcutDialog_twoFingerTripleTapOn_checkboxIsSavedValue() { + ToggleScreenMagnificationPreferenceFragment fragment = + mFragController.create(R.id.main_content, /* bundle= */ + null).start().resume().get(); + final ShortcutPreference shortcutPreference = new ShortcutPreference(mContext, /* attrs= */ + null); + final PreferredShortcut twoFingerTripleTapShortcut = new PreferredShortcut( + MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.TWOFINGERTRIPLETAP); + fragment.mShortcutPreference = shortcutPreference; + + PreferredShortcuts.saveUserShortcutType(mContext, twoFingerTripleTapShortcut); + fragment.mShortcutPreference.setChecked(true); + fragment.setupMagnificationEditShortcutDialog( + createEditShortcutDialog(fragment.getActivity())); + + final int checkboxValue = fragment.getShortcutTypeCheckBoxValue(); + assertThat(checkboxValue).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP); + } + @Test public void restoreValueFromSavedInstanceState_assignToVariable() { final Bundle fragmentState = createFragmentSavedInstanceState( @@ -408,6 +512,28 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP); } + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void restoreValueFromSavedInstanceState_twoFingerTripleTap_assignToVariable() { + final Bundle fragmentState = + createFragmentSavedInstanceState(UserShortcutType.TWOFINGERTRIPLETAP); + ToggleScreenMagnificationPreferenceFragment fragment = mFragController.get(); + // Had to use reflection to pass the savedInstanceState when launching the fragment + ReflectionHelpers.setField(fragment, "mSavedFragmentState", fragmentState); + + FragmentController.of(fragment, SettingsActivity.class).create( + R.id.main_content, /* bundle= */ null).start().resume().get(); + fragment.setupMagnificationEditShortcutDialog( + createEditShortcutDialog(fragment.getActivity())); + final int value = fragment.getShortcutTypeCheckBoxValue(); + fragment.saveNonEmptyUserShortcutType(value); + + final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext, + MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE); + assertThat(value).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP); + assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP); + } + @Test public void onCreateView_magnificationAreaNotSupported_settingsPreferenceIsNull() { setWindowMagnificationSupported( @@ -516,6 +642,29 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { mContext.getString(R.string.generic_accessibility_feature_shortcut_off)); } + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void getSummary_magnificationGestureEnabled_returnShortcutOnWithSummary() { + Settings.Secure.putInt( + mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON); + + assertThat( + ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) + .isEqualTo(mContext.getString(R.string.accessibility_summary_shortcut_enabled)); + } + + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) + public void getSummary_magnificationGestureDisabled_returnShortcutOffWithSummary() { + Settings.Secure.putInt( + mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF); + + assertThat( + ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) + .isEqualTo( + mContext.getString(R.string.generic_accessibility_feature_shortcut_off)); + } + private void putStringIntoSettings(String key, String componentName) { Settings.Secure.putString(mContext.getContentResolver(), key, componentName); }