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
This commit is contained in:
@@ -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(),
|
||||
|
@@ -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
|
||||
|
@@ -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(),
|
||||
|
@@ -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(),
|
||||
|
@@ -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) {
|
||||
|
@@ -62,7 +62,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
|
||||
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
|
||||
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
|
||||
private int mUserShortcutType = UserShortcutType.EMPTY;
|
||||
|
||||
private CheckBox mSoftwareTypeCheckBox;
|
||||
private CheckBox mHardwareTypeCheckBox;
|
||||
private CheckBox mTripleTapTypeCheckBox;
|
||||
@@ -158,7 +158,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
generalCategory.addPreference(mSettingsPreference);
|
||||
}
|
||||
|
||||
private void initializeDialogCheckBox(AlertDialog dialog) {
|
||||
@VisibleForTesting
|
||||
void initializeDialogCheckBox(AlertDialog dialog) {
|
||||
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
|
||||
mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
|
||||
setDialogTextAreaClickListener(dialogSoftwareView, mSoftwareTypeCheckBox);
|
||||
@@ -193,7 +194,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
checkBox.setChecked((mUserShortcutTypesCache & type) == type);
|
||||
}
|
||||
|
||||
private void updateUserShortcutType(boolean saveChanges) {
|
||||
@VisibleForTesting
|
||||
void updateUserShortcutType(boolean saveChanges) {
|
||||
mUserShortcutTypesCache = UserShortcutType.EMPTY;
|
||||
if (mSoftwareTypeCheckBox.isChecked()) {
|
||||
mUserShortcutTypesCache |= UserShortcutType.SOFTWARE;
|
||||
@@ -210,7 +212,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
if (isChanged) {
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutTypesCache);
|
||||
}
|
||||
mUserShortcutType = mUserShortcutTypesCache;
|
||||
mUserShortcutTypes = mUserShortcutTypesCache;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,9 +291,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
@Override
|
||||
protected void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
|
||||
updateUserShortcutType(/* saveChanges= */ true);
|
||||
optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
|
||||
optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
|
||||
mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY);
|
||||
optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutTypes);
|
||||
optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutTypes);
|
||||
mShortcutPreference.setChecked(mUserShortcutTypes != UserShortcutType.EMPTY);
|
||||
mShortcutPreference.setSummary(
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
@@ -361,17 +363,17 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
@Override
|
||||
protected void updateShortcutPreferenceData() {
|
||||
// Get the user shortcut type from settings provider.
|
||||
mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
|
||||
if (mUserShortcutType != UserShortcutType.EMPTY) {
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutType);
|
||||
mUserShortcutTypes = getUserShortcutTypeFromSettings(getPrefContext());
|
||||
if (mUserShortcutTypes != UserShortcutType.EMPTY) {
|
||||
setUserShortcutType(getPrefContext(), mUserShortcutTypes);
|
||||
} else {
|
||||
// Get the user shortcut type from shared_prefs if cannot get from settings provider.
|
||||
mUserShortcutType = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
mUserShortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initShortcutPreference(Bundle savedInstanceState) {
|
||||
protected void initShortcutPreference() {
|
||||
mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
|
||||
mShortcutPreference.setPersistent(false);
|
||||
mShortcutPreference.setKey(getShortcutPreferenceKey());
|
||||
|
Reference in New Issue
Block a user