Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58cc3ea7 authored by Peter_Liang's avatar Peter_Liang
Browse files

Revising the function name related to user shortcut type.

Should add 's' into the name.

Bug: 148989018
Test: manual test
Change-Id: I46aadb80f4f28dc1794fc3313563c79be149e847
parent 6585f794
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ public final class SharedPreferenceUtils {
    }

    /** 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)
                .getStringSet(USER_SHORTCUT_TYPE, ImmutableSet.of());
    }
+2 −2
Original line number Diff line number Diff line
@@ -295,7 +295,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends

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

        final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
        final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
        AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);

        mDialog.dismiss();
+29 −29
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
    protected Uri mImageUri;
    protected CharSequence mHtmlDescription;
    // Used to restore the edit dialog status.
    protected int mUserShortcutTypeCache = UserShortcutType.EMPTY;
    protected int mUserShortcutTypesCache = UserShortcutType.EMPTY;
    private static final String DRAWABLE_FOLDER = "drawable";
    protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
    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 EXTRA_SHORTCUT_TYPE = "shortcut_type";
    private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
    private int mUserShortcutType = UserShortcutType.EMPTY;
    private int mUserShortcutTypes = UserShortcutType.EMPTY;
    private CheckBox mSoftwareTypeCheckBox;
    private CheckBox mHardwareTypeCheckBox;

@@ -233,7 +233,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
        outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache);
        super.onSaveInstanceState(outState);
    }

@@ -474,31 +474,31 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
    }

    private void updateAlertDialogCheckState() {
        if (mUserShortcutTypeCache != UserShortcutType.EMPTY) {
        if (mUserShortcutTypesCache != UserShortcutType.EMPTY) {
            updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
            updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
        }
    }

    private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
        checkBox.setChecked((mUserShortcutTypeCache & type) == type);
        checkBox.setChecked((mUserShortcutTypesCache & type) == type);
    }

    private void updateUserShortcutType(boolean saveChanges) {
        mUserShortcutTypeCache = UserShortcutType.EMPTY;
        mUserShortcutTypesCache = UserShortcutType.EMPTY;
        if (mSoftwareTypeCheckBox.isChecked()) {
            mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
            mUserShortcutTypesCache |= UserShortcutType.SOFTWARE;
        }
        if (mHardwareTypeCheckBox.isChecked()) {
            mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
            mUserShortcutTypesCache |= UserShortcutType.HARDWARE;
        }

        if (saveChanges) {
            final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY);
            final boolean isChanged = (mUserShortcutTypesCache != UserShortcutType.EMPTY);
            if (isChanged) {
                setUserShortcutType(getPrefContext(), mUserShortcutTypeCache);
                setUserShortcutType(getPrefContext(), mUserShortcutTypesCache);
            }
            mUserShortcutType = mUserShortcutTypeCache;
            mUserShortcutTypes = mUserShortcutTypesCache;
        }
    }

@@ -507,7 +507,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
            return;
        }

        Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
        Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
        final String componentName = mComponentName.flattenToString();
        if (info.isEmpty()) {
            info = new HashSet<>();
@@ -532,7 +532,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
            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;
        if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
            resId = AccessibilityUtil.isTouchExploreEnabled(context)
@@ -542,10 +542,10 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        final CharSequence softwareTitle = context.getText(resId);

        List<CharSequence> list = new ArrayList<>();
        if ((shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
        if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
            list.add(softwareTitle);
        }
        if ((shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
        if ((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
            final CharSequence hardwareTitle = context.getText(
                    R.string.accessibility_shortcut_edit_dialog_title_hardware);
            list.add(hardwareTitle);
@@ -559,12 +559,12 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        return AccessibilityUtil.capitalize(joinStrings);
    }

    protected int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
    protected int getUserShortcutTypes(Context context, @UserShortcutType int defaultValue) {
        if (mComponentName == null) {
            return defaultValue;
        }

        final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
        final Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
        final String componentName = mComponentName.flattenToString();
        final Set<String> filtered = info.stream()
                .filter(str -> str.contains(componentName))
@@ -584,11 +584,11 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        }

        updateUserShortcutType(/* saveChanges= */ true);
        AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType,
        AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutTypes,
                mComponentName);
        AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType,
        AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutTypes,
                mComponentName);
        mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY);
        mShortcutPreference.setChecked(mUserShortcutTypes != UserShortcutType.EMPTY);
        mShortcutPreference.setSummary(
                getShortcutTypeSummary(getPrefContext()));
    }
@@ -599,20 +599,20 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        }

        // Get the user shortcut type from settings provider.
        mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
        mUserShortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
                mComponentName);
        if (mUserShortcutType != UserShortcutType.EMPTY) {
            setUserShortcutType(getPrefContext(), mUserShortcutType);
        if (mUserShortcutTypes != UserShortcutType.EMPTY) {
            setUserShortcutType(getPrefContext(), mUserShortcutTypes);
        } else {
            //  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) {
        // Restore the user shortcut type.
        if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
            mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
            mUserShortcutTypesCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
                    UserShortcutType.EMPTY);
        }

@@ -631,7 +631,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
            return;
        }

        final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
        final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
        mShortcutPreference.setChecked(
                    AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
                            mComponentName));
@@ -648,7 +648,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
            return;
        }

        final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
        final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
        if (preference.isChecked()) {
            AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
                    mComponentName);
@@ -662,8 +662,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
    @Override
    public void onSettingsClicked(ShortcutPreference preference) {
        // Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off.
        mUserShortcutTypeCache = mShortcutPreference.isChecked()
                ? getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE)
        mUserShortcutTypesCache = mShortcutPreference.isChecked()
                ? getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE)
                : UserShortcutType.EMPTY;
    }

+19 −19
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
        outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache);
        super.onSaveInstanceState(outState);
    }

@@ -281,7 +281,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
    }

    private void updateAlertDialogCheckState() {
        if (mUserShortcutTypeCache != UserShortcutType.EMPTY) {
        if (mUserShortcutTypesCache != UserShortcutType.EMPTY) {
            updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
            updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
            updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP);
@@ -289,32 +289,32 @@ public class ToggleScreenMagnificationPreferenceFragment extends
    }

    private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
        checkBox.setChecked((mUserShortcutTypeCache & type) == type);
        checkBox.setChecked((mUserShortcutTypesCache & type) == type);
    }

    private void updateUserShortcutType(boolean saveChanges) {
        mUserShortcutTypeCache = UserShortcutType.EMPTY;
        mUserShortcutTypesCache = UserShortcutType.EMPTY;
        if (mSoftwareTypeCheckBox.isChecked()) {
            mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
            mUserShortcutTypesCache |= UserShortcutType.SOFTWARE;
        }
        if (mHardwareTypeCheckBox.isChecked()) {
            mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
            mUserShortcutTypesCache |= UserShortcutType.HARDWARE;
        }
        if (mTripleTapTypeCheckBox.isChecked()) {
            mUserShortcutTypeCache |= UserShortcutType.TRIPLETAP;
            mUserShortcutTypesCache |= UserShortcutType.TRIPLETAP;
        }

        if (saveChanges) {
            final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY);
            final boolean isChanged = (mUserShortcutTypesCache != UserShortcutType.EMPTY);
            if (isChanged) {
                setUserShortcutType(getPrefContext(), mUserShortcutTypeCache);
                setUserShortcutType(getPrefContext(), mUserShortcutTypesCache);
            }
            mUserShortcutType = mUserShortcutTypeCache;
            mUserShortcutType = mUserShortcutTypesCache;
        }
    }

    private void setUserShortcutType(Context context, int type) {
        Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
        Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
        if (info.isEmpty()) {
            info = new HashSet<>();
        } else {
@@ -335,7 +335,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
            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;
        if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
            resId = AccessibilityUtil.isTouchExploreEnabled(context)
@@ -369,8 +369,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
    }

    @Override
    protected int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
        final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
    protected int getUserShortcutTypes(Context context, @UserShortcutType int defaultValue) {
        final Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
        final Set<String> filtered = info.stream().filter(
                str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
                Collectors.toSet());
@@ -446,7 +446,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends

    @Override
    public void onToggleClicked(ShortcutPreference preference) {
        final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
        final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
        if (preference.isChecked()) {
            optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
        } else {
@@ -458,8 +458,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
    @Override
    public void onSettingsClicked(ShortcutPreference preference) {
        // Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off.
        mUserShortcutTypeCache = mShortcutPreference.isChecked()
                ? getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE)
        mUserShortcutTypesCache = mShortcutPreference.isChecked()
                ? getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE)
                : UserShortcutType.EMPTY;
        showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
    }
@@ -471,7 +471,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
            setUserShortcutType(getPrefContext(), mUserShortcutType);
        } else {
            //  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() {
        final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
        final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
        mShortcutPreference.setChecked(
                hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
        mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));