Accessibility shortcut secondary action - fix magnification triple tap logic

- triple tap in settings is boolean status, not string.

Bug: 142530063
Test: make RunSettingsRoboTests -j52 ROBOTEST_FILTER=ToggleScreenMagnificationPreferenceFragmentTest
Change-Id: Ieec9879f7ef55b694245c6f9143575ba933855e5
This commit is contained in:
jasonwshsu
2020-01-16 17:16:55 +08:00
parent 8b1bf8a477
commit 620aec5f8c
2 changed files with 41 additions and 10 deletions

View File

@@ -17,6 +17,8 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME; import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.app.Dialog; import android.app.Dialog;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
@@ -64,12 +66,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static final String SETTINGS_KEY = "screen_magnification_settings"; private static final String SETTINGS_KEY = "screen_magnification_settings";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private ShortcutPreference mShortcutPreference; private ShortcutPreference mShortcutPreference;
private int mUserShortcutType = UserShortcutType.DEFAULT; private int mUserShortcutType = UserShortcutType.DEFAULT;
private CheckBox mSoftwareTypeCheckBox; private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox; private CheckBox mHardwareTypeCheckBox;
private CheckBox mTripleTapTypeCheckBox; private CheckBox mTripleTapTypeCheckBox;
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
// TODO(b/147021230): Will move common functions and variables to // TODO(b/147021230): Will move common functions and variables to
// android/internal/accessibility folder. For now, magnification need to be treated // android/internal/accessibility folder. For now, magnification need to be treated
@@ -530,15 +532,21 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static void optInMagnificationValueToSettings(Context context, private static void optInMagnificationValueToSettings(Context context,
@UserShortcutType int shortcutType) { @UserShortcutType int shortcutType) {
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType); if (shortcutType == UserShortcutType.TRIPLETAP) {
final String targetString = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.putInt(context.getContentResolver(),
targetKey); Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
return;
}
if (hasMagnificationValueInSettings(context, shortcutType)) { if (hasMagnificationValueInSettings(context, shortcutType)) {
return; return;
} }
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
final String targetString = Settings.Secure.getString(context.getContentResolver(),
targetKey);
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR)); final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
if (!TextUtils.isEmpty(targetString)) { if (!TextUtils.isEmpty(targetString)) {
joiner.add(targetString); joiner.add(targetString);
} }
@@ -563,7 +571,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static void optOutMagnificationValueFromSettings(Context context, private static void optOutMagnificationValueFromSettings(Context context,
@UserShortcutType int shortcutType) { @UserShortcutType int shortcutType) {
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR)); if (shortcutType == UserShortcutType.TRIPLETAP) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
return;
}
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType); final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
final String targetString = Settings.Secure.getString(context.getContentResolver(), final String targetString = Settings.Secure.getString(context.getContentResolver(),
targetKey); targetKey);
@@ -572,6 +585,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return; return;
} }
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
sStringColonSplitter.setString(targetString); sStringColonSplitter.setString(targetString);
while (sStringColonSplitter.hasNext()) { while (sStringColonSplitter.hasNext()) {
final String name = sStringColonSplitter.next(); final String name = sStringColonSplitter.next();
@@ -602,6 +617,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static boolean hasMagnificationValueInSettings(Context context, private static boolean hasMagnificationValueInSettings(Context context,
@UserShortcutType int shortcutType) { @UserShortcutType int shortcutType) {
if (shortcutType == UserShortcutType.TRIPLETAP) {
return Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF) == ON;
}
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType); final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
final String targetString = Settings.Secure.getString(context.getContentResolver(), final String targetString = Settings.Secure.getString(context.getContentResolver(),
targetKey); targetKey);

View File

@@ -16,6 +16,8 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import static com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; import static com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -55,7 +57,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
@Test @Test
public void hasValueInSettings_putValue_hasValue() { public void hasValueInSettings_putValue_hasValue() {
putStringIntoSettings(TRIPLETAP_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); setMagnificationTripleTapEnabled(/* enabled= */ true);
assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings( assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings(
mContext, UserShortcutType.TRIPLETAP)).isTrue(); mContext, UserShortcutType.TRIPLETAP)).isTrue();
@@ -70,8 +72,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo( assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
MAGNIFICATION_CONTROLLER_NAME); MAGNIFICATION_CONTROLLER_NAME);
assertThat(getStringFromSettings(TRIPLETAP_SHORTCUT_KEY)).isEqualTo( assertThat(getMagnificationTripleTapStatus()).isTrue();
MAGNIFICATION_CONTROLLER_NAME);
} }
@@ -91,7 +92,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
public void optOutAllValuesToSettings_optOutValue_emptyString() { public void optOutAllValuesToSettings_optOutValue_emptyString() {
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
putStringIntoSettings(TRIPLETAP_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); setMagnificationTripleTapEnabled(/* enabled= */ true);
int shortcutTypes = int shortcutTypes =
UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP; UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP;
@@ -100,7 +101,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty(); assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty();
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEmpty(); assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEmpty();
assertThat(getStringFromSettings(TRIPLETAP_SHORTCUT_KEY)).isEmpty(); assertThat(getMagnificationTripleTapStatus()).isFalse();
} }
@Test @Test
@@ -124,7 +125,17 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
Settings.Secure.putString(mContext.getContentResolver(), key, componentName); Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
} }
private void setMagnificationTripleTapEnabled(boolean enabled) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, enabled ? ON : OFF);
}
private String getStringFromSettings(String key) { private String getStringFromSettings(String key) {
return Settings.Secure.getString(mContext.getContentResolver(), key); return Settings.Secure.getString(mContext.getContentResolver(), key);
} }
private boolean getMagnificationTripleTapStatus() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF) == ON;
}
} }