Support accessibility shortcut secondary action (8/n)
Integrate with the multiple shortcut selections and change the behavior as below: - Get the shortcut type from system provider or shared_prefs if this is first time to use. - Update the shared_prefs for what user seen. Bug: 142530063 Bug: 142531156 Test: make RunSettingsRoboTests2 Test: make RunSettingsRoboTests ROBOTEST_FILTER=AccessibilityUtilTest Change-Id: I58aeb960e2c4aa0bc2432be34c1372c0de89117a
This commit is contained in:
@@ -304,6 +304,26 @@ final class AccessibilityUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the corresponding user shortcut type of a given accessibility service.
|
||||
*
|
||||
* @param context The current context.
|
||||
* @param componentName The component name that need to be checked existed in Settings.
|
||||
* @return The user shortcut type if component name existed in {@code UserShortcutType} string
|
||||
* Settings.
|
||||
*/
|
||||
static int getUserShortcutTypesFromSettings(Context context,
|
||||
@NonNull ComponentName componentName) {
|
||||
int shortcutTypes = UserShortcutType.DEFAULT;
|
||||
if (hasValuesInSettings(context, UserShortcutType.SOFTWARE, componentName)) {
|
||||
shortcutTypes |= UserShortcutType.SOFTWARE;
|
||||
}
|
||||
if (hasValuesInSettings(context, UserShortcutType.HARDWARE, componentName)) {
|
||||
shortcutTypes |= UserShortcutType.HARDWARE;
|
||||
}
|
||||
return shortcutTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts {@link UserShortcutType} to key in Settings.
|
||||
*
|
||||
|
@@ -68,6 +68,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
|
||||
private ShortcutPreference mShortcutPreference;
|
||||
private int mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
// Used to restore the edit dialog status.
|
||||
private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
private CheckBox mSoftwareTypeCheckBox;
|
||||
private CheckBox mHardwareTypeCheckBox;
|
||||
|
||||
@@ -115,12 +117,17 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
initShortcutPreference(savedInstanceState);
|
||||
// Restore the user shortcut type.
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.DEFAULT);
|
||||
}
|
||||
initShortcutPreference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutType);
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@@ -129,6 +136,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
super.onResume();
|
||||
mSettingsContentObserver.register(getContentResolver());
|
||||
updateSwitchBarToggleSwitch();
|
||||
updateShortcutPreferenceData();
|
||||
updateShortcutPreference();
|
||||
}
|
||||
|
||||
@@ -237,7 +245,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
}
|
||||
|
||||
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
||||
checkBox.setChecked((mUserShortcutType & type) == type);
|
||||
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
||||
checkBox.setOnClickListener(v -> {
|
||||
updateUserShortcutType(/* saveChanges= */ false);
|
||||
updateAlertDialogEnableState();
|
||||
@@ -245,14 +253,15 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
}
|
||||
|
||||
private void updateUserShortcutType(boolean saveChanges) {
|
||||
mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
if (mSoftwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.SOFTWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
|
||||
}
|
||||
if (mHardwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.HARDWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
|
||||
}
|
||||
if (saveChanges) {
|
||||
mUserShortcutType = mUserShortcutTypeCache;
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
}
|
||||
}
|
||||
@@ -315,14 +324,14 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
|
||||
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
|
||||
updateUserShortcutType(/* saveChanges= */ true);
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
if (mShortcutPreference.getChecked()) {
|
||||
AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
|
||||
mComponentName);
|
||||
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
|
||||
mComponentName);
|
||||
}
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -351,23 +360,25 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
switchBar.setSwitchBarText(switchBarText, switchBarText);
|
||||
}
|
||||
|
||||
private void initShortcutPreference(Bundle savedInstanceState) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
|
||||
// Restore the user shortcut type
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.SOFTWARE);
|
||||
private void updateShortcutPreferenceData() {
|
||||
// Get the user shortcut type from settings provider.
|
||||
mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
|
||||
getComponentName());
|
||||
if (mUserShortcutType != UserShortcutType.DEFAULT) {
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
} else {
|
||||
// Get the user shortcut type from shared_prefs if cannot get from settings provider.
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
}
|
||||
}
|
||||
|
||||
// Initial ShortcutPreference widget
|
||||
private void initShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
mShortcutPreference = new ShortcutPreference(
|
||||
preferenceScreen.getContext(), null);
|
||||
mShortcutPreference.setPersistent(false);
|
||||
mShortcutPreference.setKey(getShortcutPreferenceKey());
|
||||
mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
|
||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||
mShortcutPreference.setOnClickListener(this);
|
||||
// Put the shortcutPreference before settingsPreference.
|
||||
mShortcutPreference.setOrder(-1);
|
||||
@@ -384,6 +395,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
shortcutPreference.setChecked(
|
||||
AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
|
||||
mComponentName));
|
||||
shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,8 +504,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
|
||||
@Override
|
||||
public void onSettingsClicked(ShortcutPreference preference) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
||||
UserShortcutType.SOFTWARE);
|
||||
mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
showPopupDialog(DialogType.EDIT_SHORTCUT);
|
||||
}
|
||||
|
||||
|
@@ -65,6 +65,8 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
private ShortcutPreference mShortcutPreference;
|
||||
private SettingsContentObserver mSettingsContentObserver;
|
||||
private int mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
// Used to restore the edit dialog status.
|
||||
private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
private CheckBox mSoftwareTypeCheckBox;
|
||||
private CheckBox mHardwareTypeCheckBox;
|
||||
|
||||
@@ -125,7 +127,13 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
initShortcutPreference(savedInstanceState);
|
||||
// Restore the user shortcut type.
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.DEFAULT);
|
||||
}
|
||||
initShortcutPreference();
|
||||
|
||||
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
|
||||
enableServiceFeatureKeys.add(ENABLED);
|
||||
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
|
||||
@@ -141,13 +149,14 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutType);
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateShortcutPreferenceData();
|
||||
updateShortcutPreference();
|
||||
}
|
||||
|
||||
@@ -191,7 +200,7 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
}
|
||||
|
||||
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
||||
checkBox.setChecked((mUserShortcutType & type) == type);
|
||||
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
||||
checkBox.setOnClickListener(v -> {
|
||||
updateUserShortcutType(/* saveChanges= */ false);
|
||||
updateAlertDialogEnableState();
|
||||
@@ -199,14 +208,15 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
}
|
||||
|
||||
private void updateUserShortcutType(boolean saveChanges) {
|
||||
mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
if (mSoftwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.SOFTWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
|
||||
}
|
||||
if (mHardwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.HARDWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
|
||||
}
|
||||
if (saveChanges) {
|
||||
mUserShortcutType = mUserShortcutTypeCache;
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
}
|
||||
}
|
||||
@@ -269,14 +279,14 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
|
||||
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
|
||||
updateUserShortcutType(/* saveChanges= */ true);
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
if (mShortcutPreference.getChecked()) {
|
||||
AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
|
||||
getComponentName());
|
||||
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
|
||||
getComponentName());
|
||||
}
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -287,17 +297,19 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void initShortcutPreference(Bundle savedInstanceState) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
||||
UserShortcutType.SOFTWARE);
|
||||
|
||||
// Restore the user shortcut type
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.SOFTWARE);
|
||||
private void updateShortcutPreferenceData() {
|
||||
// Get the user shortcut type from settings provider.
|
||||
mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
|
||||
getComponentName());
|
||||
if (mUserShortcutType != UserShortcutType.DEFAULT) {
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
} else {
|
||||
// Get the user shortcut type from shared_prefs if cannot get from settings provider.
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
}
|
||||
}
|
||||
|
||||
// Initial ShortcutPreference widget
|
||||
private void initShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
mShortcutPreference = new ShortcutPreference(
|
||||
preferenceScreen.getContext(), null);
|
||||
@@ -305,11 +317,9 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
mShortcutPreference.setPersistent(false);
|
||||
mShortcutPreference.setKey(getShortcutPreferenceKey());
|
||||
mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
|
||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||
mShortcutPreference.setOnClickListener(this);
|
||||
// Put the shortcutPreference before previewPreference.
|
||||
mShortcutPreference.setOrder(previewPreference.getOrder() - 1);
|
||||
// TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
|
||||
preferenceScreen.addPreference(mShortcutPreference);
|
||||
}
|
||||
|
||||
@@ -323,6 +333,7 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
shortcutPreference.setChecked(
|
||||
AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
|
||||
getComponentName()));
|
||||
shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,8 +359,7 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
|
||||
@Override
|
||||
public void onSettingsClicked(ShortcutPreference preference) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
||||
UserShortcutType.SOFTWARE);
|
||||
mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
showDialog(DIALOG_ID_EDIT_SHORTCUT);
|
||||
}
|
||||
|
||||
|
@@ -70,6 +70,8 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
private ShortcutPreference mShortcutPreference;
|
||||
private SettingsContentObserver mSettingsContentObserver;
|
||||
private int mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
// Used to restore the edit dialog status.
|
||||
private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
private CheckBox mSoftwareTypeCheckBox;
|
||||
private CheckBox mHardwareTypeCheckBox;
|
||||
|
||||
@@ -98,7 +100,13 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
initShortcutPreference(savedInstanceState);
|
||||
// Restore the user shortcut type.
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.DEFAULT);
|
||||
}
|
||||
initShortcutPreference();
|
||||
|
||||
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
|
||||
enableServiceFeatureKeys.add(ENABLED);
|
||||
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
|
||||
@@ -114,7 +122,7 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutType);
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@@ -127,6 +135,7 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
((DaltonizerRadioButtonPreferenceController) controller).displayPreference(
|
||||
getPreferenceScreen());
|
||||
}
|
||||
updateShortcutPreferenceData();
|
||||
updateShortcutPreference();
|
||||
}
|
||||
|
||||
@@ -179,7 +188,7 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
}
|
||||
|
||||
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
||||
checkBox.setChecked((mUserShortcutType & type) == type);
|
||||
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
||||
checkBox.setOnClickListener(v -> {
|
||||
updateUserShortcutType(/* saveChanges= */ false);
|
||||
updateAlertDialogEnableState();
|
||||
@@ -187,14 +196,15 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
}
|
||||
|
||||
private void updateUserShortcutType(boolean saveChanges) {
|
||||
mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
if (mSoftwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.SOFTWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
|
||||
}
|
||||
if (mHardwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.HARDWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
|
||||
}
|
||||
if (saveChanges) {
|
||||
mUserShortcutType = mUserShortcutTypeCache;
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
}
|
||||
}
|
||||
@@ -257,14 +267,14 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
|
||||
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
|
||||
updateUserShortcutType(/* saveChanges= */ true);
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
if (mShortcutPreference.getChecked()) {
|
||||
AccessibilityUtil.optInAllValuesToSettings(getContext(), mUserShortcutType,
|
||||
getComponentName());
|
||||
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), ~mUserShortcutType,
|
||||
getComponentName());
|
||||
}
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -347,22 +357,11 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
|
||||
@Override
|
||||
public void onSettingsClicked(ShortcutPreference preference) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
||||
UserShortcutType.SOFTWARE);
|
||||
mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
showDialog(DIALOG_ID_EDIT_SHORTCUT);
|
||||
}
|
||||
|
||||
private void initShortcutPreference(Bundle savedInstanceState) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
||||
UserShortcutType.SOFTWARE);
|
||||
|
||||
// Restore the user shortcut type
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.SOFTWARE);
|
||||
}
|
||||
|
||||
// Initial ShortcutPreference widget
|
||||
private void initShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
mShortcutPreference = new ShortcutPreference(
|
||||
preferenceScreen.getContext(), null);
|
||||
@@ -374,10 +373,21 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
final RadioButtonPreference radioButtonPreference = findPreference(PREFERENCE_KEY);
|
||||
// Put the shortcutPreference before radioButtonPreference.
|
||||
mShortcutPreference.setOrder(radioButtonPreference.getOrder() - 1);
|
||||
// TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
|
||||
preferenceScreen.addPreference(mShortcutPreference);
|
||||
}
|
||||
|
||||
private void updateShortcutPreferenceData() {
|
||||
// Get the user shortcut type from settings provider.
|
||||
mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
|
||||
getComponentName());
|
||||
if (mUserShortcutType != UserShortcutType.DEFAULT) {
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
} else {
|
||||
// Get the user shortcut type from shared_prefs if cannot get from settings provider.
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
|
||||
@@ -388,6 +398,7 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
shortcutPreference.setChecked(
|
||||
AccessibilityUtil.hasValuesInSettings(getContext(), shortcutTypes,
|
||||
getComponentName()));
|
||||
shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -69,6 +69,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
|
||||
private ShortcutPreference mShortcutPreference;
|
||||
private int mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
// Used to restore the edit dialog status.
|
||||
private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
private CheckBox mSoftwareTypeCheckBox;
|
||||
private CheckBox mHardwareTypeCheckBox;
|
||||
private CheckBox mTripleTapTypeCheckBox;
|
||||
@@ -176,7 +178,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
final PreferenceCategory optionCategory = new PreferenceCategory(getPrefContext());
|
||||
optionCategory.setTitle(R.string.accessibility_screen_option);
|
||||
|
||||
initShortcutPreference(savedInstanceState);
|
||||
// Restore the user shortcut type.
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.DEFAULT);
|
||||
}
|
||||
initShortcutPreference();
|
||||
|
||||
final Preference settingsPreference = new Preference(getPrefContext());
|
||||
settingsPreference.setTitle(R.string.accessibility_magnification_service_settings_title);
|
||||
@@ -210,7 +217,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutType);
|
||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@@ -224,6 +231,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
}
|
||||
|
||||
updateConfigurationWarningIfNeeded();
|
||||
updateShortcutPreferenceData();
|
||||
updateShortcutPreference();
|
||||
}
|
||||
|
||||
@@ -292,7 +300,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
}
|
||||
|
||||
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
||||
checkBox.setChecked((mUserShortcutType & type) == type);
|
||||
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
||||
checkBox.setOnClickListener(v -> {
|
||||
updateUserShortcutType(/* saveChanges= */ false);
|
||||
updateAlertDialogEnableState();
|
||||
@@ -300,17 +308,18 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
}
|
||||
|
||||
private void updateUserShortcutType(boolean saveChanges) {
|
||||
mUserShortcutType = UserShortcutType.DEFAULT;
|
||||
mUserShortcutTypeCache = UserShortcutType.DEFAULT;
|
||||
if (mSoftwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.SOFTWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
|
||||
}
|
||||
if (mHardwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.HARDWARE;
|
||||
mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
|
||||
}
|
||||
if (mTripleTapTypeCheckBox.isChecked()) {
|
||||
mUserShortcutType |= UserShortcutType.TRIPLETAP;
|
||||
mUserShortcutTypeCache |= UserShortcutType.TRIPLETAP;
|
||||
}
|
||||
if (saveChanges) {
|
||||
mUserShortcutType = mUserShortcutTypeCache;
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
}
|
||||
}
|
||||
@@ -378,12 +387,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
|
||||
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
|
||||
updateUserShortcutType(/* saveChanges= */ true);
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
if (mShortcutPreference.getChecked()) {
|
||||
optInAllMagnificationValuesToSettings(getContext(), mUserShortcutType);
|
||||
optOutAllMagnificationValuesFromSettings(getContext(), ~mUserShortcutType);
|
||||
}
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
private String getComponentName() {
|
||||
@@ -457,22 +466,22 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
|
||||
@Override
|
||||
public void onSettingsClicked(ShortcutPreference preference) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
||||
UserShortcutType.SOFTWARE);
|
||||
mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
showDialog(DialogType.EDIT_SHORTCUT);
|
||||
}
|
||||
|
||||
private void initShortcutPreference(Bundle savedInstanceState) {
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(),
|
||||
UserShortcutType.SOFTWARE);
|
||||
|
||||
// Restore the user shortcut type
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||
mUserShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||
UserShortcutType.SOFTWARE);
|
||||
private void updateShortcutPreferenceData() {
|
||||
// Get the user shortcut type from settings provider.
|
||||
mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
|
||||
if (mUserShortcutType != UserShortcutType.DEFAULT) {
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
} else {
|
||||
// Get the user shortcut type from shared_prefs if cannot get from settings provider.
|
||||
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
}
|
||||
}
|
||||
|
||||
// Initial ShortcutPreference widget
|
||||
private void initShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
mShortcutPreference = new ShortcutPreference(
|
||||
preferenceScreen.getContext(), null);
|
||||
@@ -481,7 +490,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
mShortcutPreference.setTitle(R.string.accessibility_magnification_shortcut_title);
|
||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||
mShortcutPreference.setOnClickListener(this);
|
||||
// TODO(b/142530063): Check the new setting key to decide which summary should be shown.
|
||||
}
|
||||
|
||||
private void updateShortcutPreference() {
|
||||
@@ -493,6 +501,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||
shortcutPreference.setChecked(
|
||||
hasMagnificationValuesInSettings(getContext(), shortcutTypes));
|
||||
shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,4 +657,18 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
context.getContentResolver().getUserId());
|
||||
return mode == Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
|
||||
}
|
||||
|
||||
private static int getUserShortcutTypeFromSettings(Context context) {
|
||||
int shortcutTypes = UserShortcutType.DEFAULT;
|
||||
if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) {
|
||||
shortcutTypes |= UserShortcutType.SOFTWARE;
|
||||
}
|
||||
if (hasMagnificationValuesInSettings(context, UserShortcutType.HARDWARE)) {
|
||||
shortcutTypes |= UserShortcutType.HARDWARE;
|
||||
}
|
||||
if (hasMagnificationValuesInSettings(context, UserShortcutType.TRIPLETAP)) {
|
||||
shortcutTypes |= UserShortcutType.TRIPLETAP;
|
||||
}
|
||||
return shortcutTypes;
|
||||
}
|
||||
}
|
||||
|
@@ -142,6 +142,29 @@ public final class AccessibilityUtilTest {
|
||||
DUMMY_COMPONENT_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserShortcutTypeFromSettings_putOneValue_hasValue() {
|
||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||
|
||||
final int shortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||
DUMMY_COMPONENT_NAME);
|
||||
assertThat(
|
||||
(shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserShortcutTypeFromSettings_putTwoValues_hasValue() {
|
||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||
|
||||
final int shortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||
DUMMY_COMPONENT_NAME);
|
||||
assertThat(
|
||||
(shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE).isTrue();
|
||||
assertThat(
|
||||
(shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
||||
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE;
|
||||
|
Reference in New Issue
Block a user