Accessibility shortcut secondary action - handle all preferred shortcut type key
- save and restore all preferredShortcutType: SOFTWARE, HARDWARE, TRIPLETAP Bug: 142530063 Test: manual Change-Id: I7dd714d1516f49e89c42822241f9cb2b41ae2d2e
This commit is contained in:
@@ -27,6 +27,7 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -160,41 +161,76 @@ final class AccessibilityUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opts in component name into colon-separated {@code shortcutType} key's string in Settings.
|
* Opts in component name into multiple {@code shortcutTypes} colon-separated string in
|
||||||
|
* Settings.
|
||||||
|
*
|
||||||
|
* @param context The current context.
|
||||||
|
* @param shortcutTypes A combination of {@link UserShortcutType}.
|
||||||
|
* @param componentName The component name that need to be opted in Settings.
|
||||||
|
*/
|
||||||
|
static void optInAllValuesToSettings(Context context, int shortcutTypes,
|
||||||
|
@NonNull ComponentName componentName) {
|
||||||
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
|
optInValueToSettings(context, UserShortcutType.SOFTWARE, componentName);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
||||||
|
optInValueToSettings(context, UserShortcutType.HARDWARE, componentName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opts in component name into {@code shortcutType} colon-separated string in Settings.
|
||||||
*
|
*
|
||||||
* @param context The current context.
|
* @param context The current context.
|
||||||
* @param shortcutType The preferred shortcut type user selected.
|
* @param shortcutType The preferred shortcut type user selected.
|
||||||
* @param componentName The component name that need to be opted in Settings.
|
* @param componentName The component name that need to be opted in Settings.
|
||||||
*/
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
static void optInValueToSettings(Context context, @UserShortcutType int shortcutType,
|
static void optInValueToSettings(Context context, @UserShortcutType int shortcutType,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
final String targetKey = convertKeyFromSettings(shortcutType);
|
final String targetKey = convertKeyFromSettings(shortcutType);
|
||||||
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
||||||
targetKey);
|
targetKey);
|
||||||
|
|
||||||
if (TextUtils.isEmpty(targetString)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasValueInSettings(context, shortcutType, componentName)) {
|
if (hasValueInSettings(context, shortcutType, componentName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||||
|
if (!TextUtils.isEmpty(targetString)) {
|
||||||
joiner.add(targetString);
|
joiner.add(targetString);
|
||||||
|
}
|
||||||
joiner.add(componentName.flattenToString());
|
joiner.add(componentName.flattenToString());
|
||||||
|
|
||||||
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opts out component name into colon-separated {@code shortcutType} key's string in Settings.
|
* Opts out component name into multiple {@code shortcutTypes} colon-separated string in
|
||||||
|
* Settings.
|
||||||
|
*
|
||||||
|
* @param context The current context.
|
||||||
|
* @param shortcutTypes A combination of {@link UserShortcutType}.
|
||||||
|
* @param componentName The component name that need to be opted out from Settings.
|
||||||
|
*/
|
||||||
|
static void optOutAllValuesFromSettings(Context context, int shortcutTypes,
|
||||||
|
@NonNull ComponentName componentName) {
|
||||||
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
|
optOutValueFromSettings(context, UserShortcutType.SOFTWARE, componentName);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
||||||
|
optOutValueFromSettings(context, UserShortcutType.HARDWARE, componentName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opts out component name into {@code shortcutType} colon-separated string in Settings.
|
||||||
*
|
*
|
||||||
* @param context The current context.
|
* @param context The current context.
|
||||||
* @param shortcutType The preferred shortcut type user selected.
|
* @param shortcutType The preferred shortcut type user selected.
|
||||||
* @param componentName The component name that need to be opted out from Settings.
|
* @param componentName The component name that need to be opted out from Settings.
|
||||||
*/
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
static void optOutValueFromSettings(Context context, @UserShortcutType int shortcutType,
|
static void optOutValueFromSettings(Context context, @UserShortcutType int shortcutType,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||||
@@ -219,13 +255,34 @@ final class AccessibilityUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if component name existed in Settings.
|
* Returns if component name existed in one of {@code shortcutTypes} string in Settings.
|
||||||
|
*
|
||||||
|
* @param context The current context.
|
||||||
|
* @param shortcutTypes A combination of {@link UserShortcutType}.
|
||||||
|
* @param componentName The component name that need to be checked existed in Settings.
|
||||||
|
* @return {@code true} if componentName existed in Settings.
|
||||||
|
*/
|
||||||
|
static boolean hasValuesInSettings(Context context, int shortcutTypes,
|
||||||
|
@NonNull ComponentName componentName) {
|
||||||
|
boolean exist = false;
|
||||||
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
|
exist = hasValueInSettings(context, UserShortcutType.SOFTWARE, componentName);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
||||||
|
exist |= hasValueInSettings(context, UserShortcutType.HARDWARE, componentName);
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if component name existed in {@code shortcutType} string Settings.
|
||||||
*
|
*
|
||||||
* @param context The current context.
|
* @param context The current context.
|
||||||
* @param shortcutType The preferred shortcut type user selected.
|
* @param shortcutType The preferred shortcut type user selected.
|
||||||
* @param componentName The component name that need to be checked existed in Settings.
|
* @param componentName The component name that need to be checked existed in Settings.
|
||||||
* @return {@code true} if componentName existed in Settings.
|
* @return {@code true} if componentName existed in Settings.
|
||||||
*/
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
static boolean hasValueInSettings(Context context, @UserShortcutType int shortcutType,
|
static boolean hasValueInSettings(Context context, @UserShortcutType int shortcutType,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
final String targetKey = convertKeyFromSettings(shortcutType);
|
final String targetKey = convertKeyFromSettings(shortcutType);
|
||||||
|
@@ -317,6 +317,12 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
updateUserShortcutType(/* saveChanges= */ true);
|
updateUserShortcutType(/* saveChanges= */ true);
|
||||||
mShortcutPreference.setSummary(
|
mShortcutPreference.setSummary(
|
||||||
getShortcutTypeSummary(getPrefContext()));
|
getShortcutTypeSummary(getPrefContext()));
|
||||||
|
if (mShortcutPreference.getChecked()) {
|
||||||
|
AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
|
||||||
|
mComponentName);
|
||||||
|
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
|
||||||
|
mComponentName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -346,8 +352,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initShortcutPreference(Bundle savedInstanceState) {
|
private void initShortcutPreference(Bundle savedInstanceState) {
|
||||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||||
UserShortcutType.SOFTWARE);
|
|
||||||
|
|
||||||
// Restore the user shortcut type
|
// Restore the user shortcut type
|
||||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||||
@@ -366,7 +371,6 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
mShortcutPreference.setOnClickListener(this);
|
mShortcutPreference.setOnClickListener(this);
|
||||||
// Put the shortcutPreference before settingsPreference.
|
// Put the shortcutPreference before settingsPreference.
|
||||||
mShortcutPreference.setOrder(-1);
|
mShortcutPreference.setOrder(-1);
|
||||||
// TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
|
|
||||||
preferenceScreen.addPreference(mShortcutPreference);
|
preferenceScreen.addPreference(mShortcutPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,11 +380,9 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
getShortcutPreferenceKey());
|
getShortcutPreferenceKey());
|
||||||
|
|
||||||
if (shortcutPreference != null) {
|
if (shortcutPreference != null) {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
// preferred key.
|
|
||||||
shortcutPreference.setChecked(
|
shortcutPreference.setChecked(
|
||||||
AccessibilityUtil.hasValueInSettings(getContext(),
|
AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
|
||||||
UserShortcutType.SOFTWARE,
|
|
||||||
mComponentName));
|
mComponentName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,20 +475,17 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckboxClicked(ShortcutPreference preference) {
|
public void onCheckboxClicked(ShortcutPreference preference) {
|
||||||
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
if (preference.getChecked()) {
|
if (preference.getChecked()) {
|
||||||
if (!getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)) {
|
if (!getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)) {
|
||||||
preference.setChecked(false);
|
preference.setChecked(false);
|
||||||
showPopupDialog(DialogType.ENABLE_WARNING_FROM_SHORTCUT);
|
showPopupDialog(DialogType.ENABLE_WARNING_FROM_SHORTCUT);
|
||||||
} else {
|
} else {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog
|
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes,
|
||||||
// shortcut preferred key.
|
|
||||||
AccessibilityUtil.optInValueToSettings(getContext(), UserShortcutType.SOFTWARE,
|
|
||||||
mComponentName);
|
mComponentName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), shortcutTypes,
|
||||||
// preferred key.
|
|
||||||
AccessibilityUtil.optOutValueFromSettings(getContext(), UserShortcutType.SOFTWARE,
|
|
||||||
mComponentName);
|
mComponentName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -578,10 +577,9 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
private void onAllowButtonFromShortcutClicked() {
|
private void onAllowButtonFromShortcutClicked() {
|
||||||
final ShortcutPreference shortcutPreference = findPreference(getShortcutPreferenceKey());
|
final ShortcutPreference shortcutPreference = findPreference(getShortcutPreferenceKey());
|
||||||
shortcutPreference.setChecked(true);
|
shortcutPreference.setChecked(true);
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
|
||||||
// preferred key.
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
AccessibilityUtil.optInValueToSettings(getContext(), UserShortcutType.SOFTWARE,
|
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes, mComponentName);
|
||||||
mComponentName);
|
|
||||||
|
|
||||||
mDialog.dismiss();
|
mDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@@ -273,6 +273,12 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
|||||||
updateUserShortcutType(/* saveChanges= */ true);
|
updateUserShortcutType(/* saveChanges= */ true);
|
||||||
mShortcutPreference.setSummary(
|
mShortcutPreference.setSummary(
|
||||||
getShortcutTypeSummary(getPrefContext()));
|
getShortcutTypeSummary(getPrefContext()));
|
||||||
|
if (mShortcutPreference.getChecked()) {
|
||||||
|
AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
|
||||||
|
getComponentName());
|
||||||
|
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
|
||||||
|
getComponentName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -315,11 +321,9 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
|||||||
getShortcutPreferenceKey());
|
getShortcutPreferenceKey());
|
||||||
|
|
||||||
if (shortcutPreference != null) {
|
if (shortcutPreference != null) {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
// preferred key.
|
|
||||||
shortcutPreference.setChecked(
|
shortcutPreference.setChecked(
|
||||||
AccessibilityUtil.hasValueInSettings(getContext(),
|
AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
|
||||||
UserShortcutType.SOFTWARE,
|
|
||||||
getComponentName()));
|
getComponentName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,15 +338,12 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckboxClicked(ShortcutPreference preference) {
|
public void onCheckboxClicked(ShortcutPreference preference) {
|
||||||
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
if (preference.getChecked()) {
|
if (preference.getChecked()) {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes,
|
||||||
// preferred key.
|
|
||||||
AccessibilityUtil.optInValueToSettings(getContext(), UserShortcutType.SOFTWARE,
|
|
||||||
getComponentName());
|
getComponentName());
|
||||||
} else {
|
} else {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), shortcutTypes,
|
||||||
// preferred key.
|
|
||||||
AccessibilityUtil.optOutValueFromSettings(getContext(), UserShortcutType.SOFTWARE,
|
|
||||||
getComponentName());
|
getComponentName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -245,6 +245,12 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
|||||||
updateUserShortcutType(/* saveChanges= */ true);
|
updateUserShortcutType(/* saveChanges= */ true);
|
||||||
mShortcutPreference.setSummary(
|
mShortcutPreference.setSummary(
|
||||||
getShortcutTypeSummary(getPrefContext()));
|
getShortcutTypeSummary(getPrefContext()));
|
||||||
|
if (mShortcutPreference.getChecked()) {
|
||||||
|
AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
|
||||||
|
getComponentName());
|
||||||
|
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
|
||||||
|
getComponentName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -303,15 +309,12 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckboxClicked(ShortcutPreference preference) {
|
public void onCheckboxClicked(ShortcutPreference preference) {
|
||||||
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
if (preference.getChecked()) {
|
if (preference.getChecked()) {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes,
|
||||||
// preferred key.
|
|
||||||
AccessibilityUtil.optInValueToSettings(getContext(), UserShortcutType.SOFTWARE,
|
|
||||||
getComponentName());
|
getComponentName());
|
||||||
} else {
|
} else {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), shortcutTypes,
|
||||||
// preferred key.
|
|
||||||
AccessibilityUtil.optOutValueFromSettings(getContext(), UserShortcutType.SOFTWARE,
|
|
||||||
getComponentName());
|
getComponentName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,11 +358,9 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
|||||||
getShortcutPreferenceKey());
|
getShortcutPreferenceKey());
|
||||||
|
|
||||||
if (shortcutPreference != null) {
|
if (shortcutPreference != null) {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
// preferred key.
|
|
||||||
shortcutPreference.setChecked(
|
shortcutPreference.setChecked(
|
||||||
AccessibilityUtil.hasValueInSettings(getContext(),
|
AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
|
||||||
UserShortcutType.SOFTWARE,
|
|
||||||
getComponentName()));
|
getComponentName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -372,6 +372,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
updateUserShortcutType(/* saveChanges= */ true);
|
updateUserShortcutType(/* saveChanges= */ true);
|
||||||
mShortcutPreference.setSummary(
|
mShortcutPreference.setSummary(
|
||||||
getShortcutTypeSummary(getPrefContext()));
|
getShortcutTypeSummary(getPrefContext()));
|
||||||
|
if (mShortcutPreference.getChecked()) {
|
||||||
|
optInAllMagnificationValuesToSettings(getContext(), mUserShortcutType);
|
||||||
|
optOutAllMagnificationValuesFromSettings(getContext(), ~mUserShortcutType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getComponentName() {
|
private String getComponentName() {
|
||||||
@@ -435,38 +439,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckboxClicked(ShortcutPreference preference) {
|
public void onCheckboxClicked(ShortcutPreference preference) {
|
||||||
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
if (preference.getChecked()) {
|
if (preference.getChecked()) {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
optInAllMagnificationValuesToSettings(getContext(), shortcutTypes);
|
||||||
// preferred key.
|
|
||||||
optInMagnificationValueToSettings(getContext(), UserShortcutType.SOFTWARE);
|
|
||||||
|
|
||||||
// TODO(b/142531156): ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED need to be treated
|
|
||||||
// as special case in this file.
|
|
||||||
if ((mUserShortcutType & UserShortcutType.SOFTWARE)
|
|
||||||
== UserShortcutType.SOFTWARE) {
|
|
||||||
MagnificationPreferenceFragment.setChecked(getContentResolver(),
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
|
|
||||||
/* isChecked= */ true);
|
|
||||||
}
|
|
||||||
if ((mUserShortcutType & UserShortcutType.TRIPLETAP)
|
|
||||||
== UserShortcutType.TRIPLETAP) {
|
|
||||||
MagnificationPreferenceFragment.setChecked(getContentResolver(),
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
|
||||||
/* isChecked= */ true);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
optOutAllMagnificationValuesFromSettings(getContext(), shortcutTypes);
|
||||||
// preferred key.
|
|
||||||
optOutMagnificationValueFromSettings(getContext(), UserShortcutType.SOFTWARE);
|
|
||||||
|
|
||||||
// TODO(b/142531156): ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED need to be treated
|
|
||||||
// as special case in this file.
|
|
||||||
MagnificationPreferenceFragment.setChecked(getContentResolver(),
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
|
|
||||||
/* isChecked= */ false);
|
|
||||||
MagnificationPreferenceFragment.setChecked(getContentResolver(),
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
|
||||||
/* isChecked= */ false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,11 +482,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
getShortcutPreferenceKey());
|
getShortcutPreferenceKey());
|
||||||
|
|
||||||
if (shortcutPreference != null) {
|
if (shortcutPreference != null) {
|
||||||
// TODO(b/142531156): Replace UserShortcutType.SOFTWARE value with dialog shortcut
|
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||||
// preferred key.
|
|
||||||
shortcutPreference.setChecked(
|
shortcutPreference.setChecked(
|
||||||
hasMagnificationValueInSettings(getContext(),
|
hasMagnificationValuesInSettings(getContext(), shortcutTypes));
|
||||||
UserShortcutType.SOFTWARE));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,28 +509,50 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
int EDIT_SHORTCUT = 3;
|
int EDIT_SHORTCUT = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
|
||||||
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
|
optInMagnificationValueToSettings(context, UserShortcutType.SOFTWARE);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
||||||
|
optInMagnificationValueToSettings(context, UserShortcutType.HARDWARE);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
|
||||||
|
optInMagnificationValueToSettings(context, UserShortcutType.TRIPLETAP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void optInMagnificationValueToSettings(Context context,
|
private static void optInMagnificationValueToSettings(Context context,
|
||||||
@UserShortcutType int shortcutType) {
|
@UserShortcutType int shortcutType) {
|
||||||
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);
|
||||||
|
|
||||||
if (TextUtils.isEmpty(targetString)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasMagnificationValueInSettings(context, shortcutType)) {
|
if (hasMagnificationValueInSettings(context, shortcutType)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||||
|
if (TextUtils.isEmpty(targetString)) {
|
||||||
joiner.add(Settings.Secure.getString(context.getContentResolver(), targetKey));
|
joiner.add(targetString);
|
||||||
|
}
|
||||||
joiner.add(MAGNIFICATION_CONTROLLER_NAME);
|
joiner.add(MAGNIFICATION_CONTROLLER_NAME);
|
||||||
|
|
||||||
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void optOutAllMagnificationValuesFromSettings(Context context,
|
||||||
|
int shortcutTypes) {
|
||||||
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
|
optOutMagnificationValueFromSettings(context, UserShortcutType.SOFTWARE);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
||||||
|
optOutMagnificationValueFromSettings(context, UserShortcutType.HARDWARE);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
|
||||||
|
optOutMagnificationValueFromSettings(context, UserShortcutType.TRIPLETAP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||||
@@ -579,6 +576,21 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean hasMagnificationValuesInSettings(Context context, int shortcutTypes) {
|
||||||
|
boolean exist = false;
|
||||||
|
|
||||||
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
|
exist = hasMagnificationValueInSettings(context, UserShortcutType.SOFTWARE);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
||||||
|
exist |= hasMagnificationValueInSettings(context, UserShortcutType.HARDWARE);
|
||||||
|
}
|
||||||
|
if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
|
||||||
|
exist |= hasMagnificationValueInSettings(context, UserShortcutType.TRIPLETAP);
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean hasMagnificationValueInSettings(Context context,
|
private static boolean hasMagnificationValueInSettings(Context context,
|
||||||
@UserShortcutType int shortcutType) {
|
@UserShortcutType int shortcutType) {
|
||||||
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
|
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
|
||||||
|
@@ -53,6 +53,8 @@ public final class AccessibilityUtilTest {
|
|||||||
DUMMY_CLASS_NAME2);
|
DUMMY_CLASS_NAME2);
|
||||||
private static final String SOFTWARE_SHORTCUT_KEY =
|
private static final String SOFTWARE_SHORTCUT_KEY =
|
||||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
|
||||||
|
private static final String HARDWARE_SHORTCUT_KEY =
|
||||||
|
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@@ -133,7 +135,7 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hasValueInSettings_dummyComponentName_hasValue() {
|
public void hasValueInSettings_putValue_hasValue() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
assertThat(AccessibilityUtil.hasValueInSettings(mContext, UserShortcutType.SOFTWARE,
|
assertThat(AccessibilityUtil.hasValueInSettings(mContext, UserShortcutType.SOFTWARE,
|
||||||
@@ -141,7 +143,20 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void optInValueToSettings_optInDummyComponentName2_haveDummyComponentName2String() {
|
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
||||||
|
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE;
|
||||||
|
|
||||||
|
AccessibilityUtil.optInAllValuesToSettings(mContext, shortcutTypes, DUMMY_COMPONENT_NAME);
|
||||||
|
|
||||||
|
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
|
||||||
|
DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
|
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEqualTo(
|
||||||
|
DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void optInValueToSettings_optInValue_haveMatchString() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
AccessibilityUtil.optInValueToSettings(mContext, UserShortcutType.SOFTWARE,
|
AccessibilityUtil.optInValueToSettings(mContext, UserShortcutType.SOFTWARE,
|
||||||
DUMMY_COMPONENT_NAME2);
|
DUMMY_COMPONENT_NAME2);
|
||||||
@@ -152,7 +167,7 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void optInValueToSettings_optInTwoDummyComponentName_haveOneDummyComponentName2String() {
|
public void optInValueToSettings_optInTwoValues_haveMatchString() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
AccessibilityUtil.optInValueToSettings(mContext, UserShortcutType.SOFTWARE,
|
AccessibilityUtil.optInValueToSettings(mContext, UserShortcutType.SOFTWARE,
|
||||||
DUMMY_COMPONENT_NAME2);
|
DUMMY_COMPONENT_NAME2);
|
||||||
@@ -165,7 +180,21 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void optOutValueFromSettings_optOutDummyComponentName_emptyValue() {
|
public void optOutAllValuesToSettings_optOutValue_emptyString() {
|
||||||
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
|
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
|
int shortcutTypes =
|
||||||
|
UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP;
|
||||||
|
|
||||||
|
AccessibilityUtil.optOutAllValuesFromSettings(mContext, shortcutTypes,
|
||||||
|
DUMMY_COMPONENT_NAME);
|
||||||
|
|
||||||
|
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty();
|
||||||
|
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void optOutValueFromSettings_optOutValue_emptyString() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||||
AccessibilityUtil.optOutValueFromSettings(mContext, UserShortcutType.SOFTWARE,
|
AccessibilityUtil.optOutValueFromSettings(mContext, UserShortcutType.SOFTWARE,
|
||||||
DUMMY_COMPONENT_NAME);
|
DUMMY_COMPONENT_NAME);
|
||||||
@@ -174,7 +203,7 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void optOutValueFromSettings_optOutDummyComponentName2_haveDummyComponentName() {
|
public void optOutValueFromSettings_optOutValue_haveMatchString() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString() + ":"
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString() + ":"
|
||||||
+ DUMMY_COMPONENT_NAME2.flattenToString());
|
+ DUMMY_COMPONENT_NAME2.flattenToString());
|
||||||
AccessibilityUtil.optOutValueFromSettings(mContext, UserShortcutType.SOFTWARE,
|
AccessibilityUtil.optOutValueFromSettings(mContext, UserShortcutType.SOFTWARE,
|
||||||
|
Reference in New Issue
Block a user