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

Commit 1a1ae824 authored by jasonwshsu's avatar jasonwshsu Committed by Jason Hsu
Browse files

Modify flow in ToggleFeaturePreferenceFragment

* Show edit shortcut dialog should belong to the basic feature, so move
them back to ToggleFeaturePreferenceFragment
* Add test cases for UserShortcutType to prepare to further refactor

Bug: 158540780
Test: atest ToggleFeaturePreferenceFragmentTest
Change-Id: Ia84bea5581f85d199f395b2065652ce69738abbf
parent 1044467d
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -97,12 +97,6 @@ public class LaunchAccessibilityActivityPreferenceFragment extends
        mSettingsTitle = (mSettingsIntent == null) ? null : settingsTitle;
    }

    @Override
    public void onSettingsClicked(ShortcutPreference preference) {
        super.onSettingsClicked(preference);
        showDialog(DialogEnums.EDIT_SHORTCUT);
    }

    @Override
    int getUserShortcutTypes() {
        return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+5 −1
Original line number Diff line number Diff line
@@ -311,7 +311,11 @@ public class ToggleAccessibilityServicePreferenceFragment extends

    @Override
    public void onSettingsClicked(ShortcutPreference preference) {
        super.onSettingsClicked(preference);
        // Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off.
        mUserShortcutTypesCache = mShortcutPreference.isChecked()
                ? getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE)
                : UserShortcutType.EMPTY;

        final boolean isServiceOnOrShortcutAdded = mShortcutPreference.isChecked()
                || mToggleServiceDividerSwitchPreference.isChecked();
        showPopupDialog(isServiceOnOrShortcutAdded ? DialogEnums.EDIT_SHORTCUT
+0 −6
Original line number Diff line number Diff line
@@ -122,12 +122,6 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
        return R.string.help_url_color_inversion;
    }

    @Override
    public void onSettingsClicked(ShortcutPreference preference) {
        super.onSettingsClicked(preference);
        showDialog(DialogEnums.EDIT_SHORTCUT);
    }

    @Override
    int getUserShortcutTypes() {
        return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+0 −6
Original line number Diff line number Diff line
@@ -194,12 +194,6 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
        });
    }

    @Override
    public void onSettingsClicked(ShortcutPreference preference) {
        super.onSettingsClicked(preference);
        showDialog(DialogEnums.EDIT_SHORTCUT);
    }

    @Override
    int getUserShortcutTypes() {
        return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+25 −15
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ import com.android.settings.widget.SwitchBar;
import com.android.settingslib.accessibility.AccessibilityUtils;
import com.android.settingslib.widget.FooterPreference;

import com.google.common.annotations.VisibleForTesting;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -87,19 +89,24 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
    protected Uri mImageUri;
    private CharSequence mDescription;
    protected CharSequence mHtmlDescription;
    // Used to restore the edit dialog status.
    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";
    protected static final String KEY_INTRODUCTION_CATEGORY = "introduction_categories";
    private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
    private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
    @VisibleForTesting
    static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";

    private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
    private int mUserShortcutTypes = UserShortcutType.EMPTY;
    private SettingsContentObserver mSettingsContentObserver;

    private CheckBox mSoftwareTypeCheckBox;
    private CheckBox mHardwareTypeCheckBox;
    private SettingsContentObserver mSettingsContentObserver;

    // Used to restore the edit dialog status.
    protected int mUserShortcutTypesCache = UserShortcutType.EMPTY;
    protected int mUserShortcutTypes = UserShortcutType.EMPTY;

    // For html description of accessibility service, must follow the rule, such as
    // <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully.
@@ -121,6 +128,12 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Restore the user shortcut type.
        if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
            mUserShortcutTypesCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
                    UserShortcutType.EMPTY);
        }

        setupDefaultShortcutIfNecessary(getPrefContext());
        final int resId = getPreferenceScreenResId();
        if (resId <= 0) {
@@ -150,7 +163,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        initAnimatedImagePreference();
        initToggleServiceDividerSwitchPreference();
        initGeneralCategory();
        initShortcutPreference(savedInstanceState);
        initShortcutPreference();
        initSettingsPreference();
        initHtmlTextPreference();
        initFooterPreference();
@@ -521,7 +534,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        });
    }

    private void initializeDialogCheckBox(Dialog dialog) {
    @VisibleForTesting
    void initializeDialogCheckBox(Dialog dialog) {
        final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
        mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
        setDialogTextAreaClickListener(dialogSoftwareView, mSoftwareTypeCheckBox);
@@ -544,7 +558,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        checkBox.setChecked((mUserShortcutTypesCache & type) == type);
    }

    private void updateUserShortcutType(boolean saveChanges) {
    @VisibleForTesting
    void updateUserShortcutType(boolean saveChanges) {
        mUserShortcutTypesCache = UserShortcutType.EMPTY;
        if (mSoftwareTypeCheckBox.isChecked()) {
            mUserShortcutTypesCache |= UserShortcutType.SOFTWARE;
@@ -677,13 +692,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        }
    }

    protected void initShortcutPreference(Bundle savedInstanceState) {
        // Restore the user shortcut type.
        if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
            mUserShortcutTypesCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
                    UserShortcutType.EMPTY);
        }

    protected void initShortcutPreference() {
        // Initial the shortcut preference.
        mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
        mShortcutPreference.setPersistent(false);
@@ -737,6 +746,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
        mUserShortcutTypesCache = mShortcutPreference.isChecked()
                ? getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE)
                : UserShortcutType.EMPTY;
        showDialog(DialogEnums.EDIT_SHORTCUT);
    }

    private void createFooterPreference(CharSequence title) {
Loading