Revising the function name related to user shortcut type.

Should add 's' into the name.

Bug: 148989018
Test: manual test
Change-Id: I46aadb80f4f28dc1794fc3313563c79be149e847
This commit is contained in:
Peter_Liang
2020-04-15 17:19:18 +08:00
parent 6585f79439
commit 58cc3ea7f9
4 changed files with 51 additions and 51 deletions

View File

@@ -35,7 +35,7 @@ public final class SharedPreferenceUtils {
} }
/** Returns a set of user shortcuts list to determine user preferred service shortcut. */ /** Returns a set of user shortcuts list to determine user preferred service shortcut. */
public static Set<String> getUserShortcutType(Context context) { public static Set<String> getUserShortcutTypes(Context context) {
return getSharedPreferences(context, ACCESSIBILITY_PERF) return getSharedPreferences(context, ACCESSIBILITY_PERF)
.getStringSet(USER_SHORTCUT_TYPE, ImmutableSet.of()); .getStringSet(USER_SHORTCUT_TYPE, ImmutableSet.of());
} }

View File

@@ -295,7 +295,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
@Override @Override
public void onToggleClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
if (preference.isChecked()) { if (preference.isChecked()) {
if (!mToggleServiceDividerSwitchPreference.isChecked()) { if (!mToggleServiceDividerSwitchPreference.isChecked()) {
preference.setChecked(false); preference.setChecked(false);
@@ -413,7 +413,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
private void onAllowButtonFromShortcutToggleClicked() { private void onAllowButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(true); mShortcutPreference.setChecked(true);
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName); AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mDialog.dismiss(); mDialog.dismiss();

View File

@@ -85,7 +85,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected Uri mImageUri; protected Uri mImageUri;
protected CharSequence mHtmlDescription; protected CharSequence mHtmlDescription;
// Used to restore the edit dialog status. // Used to restore the edit dialog status.
protected int mUserShortcutTypeCache = UserShortcutType.EMPTY; protected int mUserShortcutTypesCache = UserShortcutType.EMPTY;
private static final String DRAWABLE_FOLDER = "drawable"; private static final String DRAWABLE_FOLDER = "drawable";
protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service"; protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
protected static final String KEY_GENERAL_CATEGORY = "general_categories"; protected static final String KEY_GENERAL_CATEGORY = "general_categories";
@@ -93,7 +93,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference"; private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private int mUserShortcutType = UserShortcutType.EMPTY; private int mUserShortcutTypes = UserShortcutType.EMPTY;
private CheckBox mSoftwareTypeCheckBox; private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox; private CheckBox mHardwareTypeCheckBox;
@@ -233,7 +233,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache); outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@@ -474,31 +474,31 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
private void updateAlertDialogCheckState() { private void updateAlertDialogCheckState() {
if (mUserShortcutTypeCache != UserShortcutType.EMPTY) { if (mUserShortcutTypesCache != UserShortcutType.EMPTY) {
updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE); updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE); updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
} }
} }
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) { private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
checkBox.setChecked((mUserShortcutTypeCache & type) == type); checkBox.setChecked((mUserShortcutTypesCache & type) == type);
} }
private void updateUserShortcutType(boolean saveChanges) { private void updateUserShortcutType(boolean saveChanges) {
mUserShortcutTypeCache = UserShortcutType.EMPTY; mUserShortcutTypesCache = UserShortcutType.EMPTY;
if (mSoftwareTypeCheckBox.isChecked()) { if (mSoftwareTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE; mUserShortcutTypesCache |= UserShortcutType.SOFTWARE;
} }
if (mHardwareTypeCheckBox.isChecked()) { if (mHardwareTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.HARDWARE; mUserShortcutTypesCache |= UserShortcutType.HARDWARE;
} }
if (saveChanges) { if (saveChanges) {
final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY); final boolean isChanged = (mUserShortcutTypesCache != UserShortcutType.EMPTY);
if (isChanged) { if (isChanged) {
setUserShortcutType(getPrefContext(), mUserShortcutTypeCache); setUserShortcutType(getPrefContext(), mUserShortcutTypesCache);
} }
mUserShortcutType = mUserShortcutTypeCache; mUserShortcutTypes = mUserShortcutTypesCache;
} }
} }
@@ -507,7 +507,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return; return;
} }
Set<String> info = SharedPreferenceUtils.getUserShortcutType(context); Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
final String componentName = mComponentName.flattenToString(); final String componentName = mComponentName.flattenToString();
if (info.isEmpty()) { if (info.isEmpty()) {
info = new HashSet<>(); info = new HashSet<>();
@@ -532,7 +532,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return context.getText(R.string.switch_off_text); return context.getText(R.string.switch_off_text);
} }
final int shortcutType = getUserShortcutType(context, UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(context, UserShortcutType.SOFTWARE);
int resId = R.string.accessibility_shortcut_edit_summary_software; int resId = R.string.accessibility_shortcut_edit_summary_software;
if (AccessibilityUtil.isGestureNavigateEnabled(context)) { if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
resId = AccessibilityUtil.isTouchExploreEnabled(context) resId = AccessibilityUtil.isTouchExploreEnabled(context)
@@ -542,10 +542,10 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final CharSequence softwareTitle = context.getText(resId); final CharSequence softwareTitle = context.getText(resId);
List<CharSequence> list = new ArrayList<>(); List<CharSequence> list = new ArrayList<>();
if ((shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) { if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
list.add(softwareTitle); list.add(softwareTitle);
} }
if ((shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) { if ((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
final CharSequence hardwareTitle = context.getText( final CharSequence hardwareTitle = context.getText(
R.string.accessibility_shortcut_edit_dialog_title_hardware); R.string.accessibility_shortcut_edit_dialog_title_hardware);
list.add(hardwareTitle); list.add(hardwareTitle);
@@ -559,12 +559,12 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return AccessibilityUtil.capitalize(joinStrings); return AccessibilityUtil.capitalize(joinStrings);
} }
protected int getUserShortcutType(Context context, @UserShortcutType int defaultValue) { protected int getUserShortcutTypes(Context context, @UserShortcutType int defaultValue) {
if (mComponentName == null) { if (mComponentName == null) {
return defaultValue; return defaultValue;
} }
final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context); final Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
final String componentName = mComponentName.flattenToString(); final String componentName = mComponentName.flattenToString();
final Set<String> filtered = info.stream() final Set<String> filtered = info.stream()
.filter(str -> str.contains(componentName)) .filter(str -> str.contains(componentName))
@@ -584,11 +584,11 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
updateUserShortcutType(/* saveChanges= */ true); updateUserShortcutType(/* saveChanges= */ true);
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType, AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutTypes,
mComponentName); mComponentName);
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType, AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutTypes,
mComponentName); mComponentName);
mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY); mShortcutPreference.setChecked(mUserShortcutTypes != UserShortcutType.EMPTY);
mShortcutPreference.setSummary( mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext())); getShortcutTypeSummary(getPrefContext()));
} }
@@ -599,20 +599,20 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
// Get the user shortcut type from settings provider. // Get the user shortcut type from settings provider.
mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(), mUserShortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
mComponentName); mComponentName);
if (mUserShortcutType != UserShortcutType.EMPTY) { if (mUserShortcutTypes != UserShortcutType.EMPTY) {
setUserShortcutType(getPrefContext(), mUserShortcutType); setUserShortcutType(getPrefContext(), mUserShortcutTypes);
} else { } else {
// Get the user shortcut type from shared_prefs if cannot get from settings provider. // Get the user shortcut type from shared_prefs if cannot get from settings provider.
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); mUserShortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
} }
} }
private void initShortcutPreference(Bundle savedInstanceState) { private void initShortcutPreference(Bundle savedInstanceState) {
// 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)) {
mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
UserShortcutType.EMPTY); UserShortcutType.EMPTY);
} }
@@ -631,7 +631,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return; return;
} }
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
mShortcutPreference.setChecked( mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
mComponentName)); mComponentName));
@@ -648,7 +648,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return; return;
} }
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
if (preference.isChecked()) { if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName); mComponentName);
@@ -662,8 +662,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
@Override @Override
public void onSettingsClicked(ShortcutPreference preference) { public void onSettingsClicked(ShortcutPreference preference) {
// Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off. // Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off.
mUserShortcutTypeCache = mShortcutPreference.isChecked() mUserShortcutTypesCache = mShortcutPreference.isChecked()
? getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE) ? getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE)
: UserShortcutType.EMPTY; : UserShortcutType.EMPTY;
} }

View File

@@ -192,7 +192,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache); outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@@ -281,7 +281,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
} }
private void updateAlertDialogCheckState() { private void updateAlertDialogCheckState() {
if (mUserShortcutTypeCache != UserShortcutType.EMPTY) { if (mUserShortcutTypesCache != UserShortcutType.EMPTY) {
updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE); updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE); updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP); updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP);
@@ -289,32 +289,32 @@ public class ToggleScreenMagnificationPreferenceFragment extends
} }
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) { private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
checkBox.setChecked((mUserShortcutTypeCache & type) == type); checkBox.setChecked((mUserShortcutTypesCache & type) == type);
} }
private void updateUserShortcutType(boolean saveChanges) { private void updateUserShortcutType(boolean saveChanges) {
mUserShortcutTypeCache = UserShortcutType.EMPTY; mUserShortcutTypesCache = UserShortcutType.EMPTY;
if (mSoftwareTypeCheckBox.isChecked()) { if (mSoftwareTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE; mUserShortcutTypesCache |= UserShortcutType.SOFTWARE;
} }
if (mHardwareTypeCheckBox.isChecked()) { if (mHardwareTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.HARDWARE; mUserShortcutTypesCache |= UserShortcutType.HARDWARE;
} }
if (mTripleTapTypeCheckBox.isChecked()) { if (mTripleTapTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.TRIPLETAP; mUserShortcutTypesCache |= UserShortcutType.TRIPLETAP;
} }
if (saveChanges) { if (saveChanges) {
final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY); final boolean isChanged = (mUserShortcutTypesCache != UserShortcutType.EMPTY);
if (isChanged) { if (isChanged) {
setUserShortcutType(getPrefContext(), mUserShortcutTypeCache); setUserShortcutType(getPrefContext(), mUserShortcutTypesCache);
} }
mUserShortcutType = mUserShortcutTypeCache; mUserShortcutType = mUserShortcutTypesCache;
} }
} }
private void setUserShortcutType(Context context, int type) { private void setUserShortcutType(Context context, int type) {
Set<String> info = SharedPreferenceUtils.getUserShortcutType(context); Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
if (info.isEmpty()) { if (info.isEmpty()) {
info = new HashSet<>(); info = new HashSet<>();
} else { } else {
@@ -335,7 +335,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return context.getText(R.string.switch_off_text); return context.getText(R.string.switch_off_text);
} }
final int shortcutType = getUserShortcutType(context, UserShortcutType.EMPTY); final int shortcutType = getUserShortcutTypes(context, UserShortcutType.EMPTY);
int resId = R.string.accessibility_shortcut_edit_summary_software; int resId = R.string.accessibility_shortcut_edit_summary_software;
if (AccessibilityUtil.isGestureNavigateEnabled(context)) { if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
resId = AccessibilityUtil.isTouchExploreEnabled(context) resId = AccessibilityUtil.isTouchExploreEnabled(context)
@@ -369,8 +369,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
} }
@Override @Override
protected int getUserShortcutType(Context context, @UserShortcutType int defaultValue) { protected int getUserShortcutTypes(Context context, @UserShortcutType int defaultValue) {
final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context); final Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
final Set<String> filtered = info.stream().filter( final Set<String> filtered = info.stream().filter(
str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect( str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
Collectors.toSet()); Collectors.toSet());
@@ -446,7 +446,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override @Override
public void onToggleClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
if (preference.isChecked()) { if (preference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes); optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
} else { } else {
@@ -458,8 +458,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override @Override
public void onSettingsClicked(ShortcutPreference preference) { public void onSettingsClicked(ShortcutPreference preference) {
// Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off. // Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off.
mUserShortcutTypeCache = mShortcutPreference.isChecked() mUserShortcutTypesCache = mShortcutPreference.isChecked()
? getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE) ? getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE)
: UserShortcutType.EMPTY; : UserShortcutType.EMPTY;
showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT); showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
} }
@@ -471,7 +471,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
setUserShortcutType(getPrefContext(), mUserShortcutType); setUserShortcutType(getPrefContext(), mUserShortcutType);
} else { } else {
// Get the user shortcut type from shared_prefs if cannot get from settings provider. // Get the user shortcut type from shared_prefs if cannot get from settings provider.
mUserShortcutType = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); mUserShortcutType = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
} }
} }
@@ -487,7 +487,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
} }
private void updateShortcutPreference() { private void updateShortcutPreference() {
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
mShortcutPreference.setChecked( mShortcutPreference.setChecked(
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes)); hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));