Support accessibility shortcut secondary action (11/n)

Refactor current shortcut design to base fragment and provide
protected function to customize the legacy design,
magnification or no need shortcut app.

Bug: 142530063
Bug: 142531156
Test: make RunSettingsRoboTests2

Change-Id: I51c951ef8f819a1940ddfe33b009b40ed5ec0530
This commit is contained in:
menghanli
2020-01-03 14:10:50 +08:00
parent d737601a66
commit b82931520f
7 changed files with 405 additions and 874 deletions

View File

@@ -46,7 +46,6 @@ import android.widget.VideoView;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
@@ -54,8 +53,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -64,7 +61,7 @@ import java.util.StringJoiner;
import java.util.stream.Collectors;
public class ToggleScreenMagnificationPreferenceFragment extends
ToggleFeaturePreferenceFragment implements ShortcutPreference.OnClickListener {
ToggleFeaturePreferenceFragment {
private static final String SETTINGS_KEY = "screen_magnification_settings";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
@@ -172,8 +169,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mPackageName = getString(R.string.accessibility_screen_magnification_title);
mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
removeDialog(DialogType.EDIT_SHORTCUT);
removeDialog(DialogEnums.EDIT_SHORTCUT);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
};
return super.onCreateView(inflater, container, savedInstanceState);
@@ -181,7 +179,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
final PreferenceScreen preferenceScreen = getPreferenceScreen();
mVideoPreference = new VideoPreference(getPrefContext());
mVideoPreference.setSelectable(false);
mVideoPreference.setPersistent(false);
@@ -205,13 +203,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
preferenceScreen.addPreference(mConfigWarningPreference);
}
@Override
protected void updateFooterTitle(PreferenceCategory category) {
final String titleText = getString(R.string.accessibility_footer_title,
getString(R.string.accessibility_screen_magnification_title));
category.setTitle(titleText);
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache);
@@ -248,13 +239,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
case DialogType.GESTURE_NAVIGATION_TUTORIAL:
case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
return AccessibilityGestureNavigationTutorial
.showGestureNavigationTutorialDialog(getActivity());
case DialogType.ACCESSIBILITY_BUTTON_TUTORIAL:
case DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL:
return AccessibilityGestureNavigationTutorial
.showAccessibilityButtonTutorialDialog(getActivity());
case DialogType.EDIT_SHORTCUT:
case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
final CharSequence dialogTitle = getActivity().getText(
R.string.accessibility_shortcut_edit_dialog_title_magnification);
final AlertDialog dialog =
@@ -340,12 +331,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends
info = new HashSet<>();
} else {
final Set<String> filtered = info.stream().filter(
str -> str.contains(getComponentName())).collect(
str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
Collectors.toSet());
info.removeAll(filtered);
}
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
getComponentName(), type);
MAGNIFICATION_CONTROLLER_NAME, type);
info.add(shortcut.flattenToString());
SharedPreferenceUtils.setUserShortcutType(context, info);
}
@@ -384,10 +375,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return AccessibilityUtil.capitalize(joinStrings);
}
private int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
@Override
protected int getUserShortcutType(Context context, @UserShortcutType int defaultValue) {
final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
final Set<String> filtered = info.stream().filter(
str -> str.contains(getComponentName())).collect(
str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
Collectors.toSet());
if (filtered.isEmpty()) {
return defaultValue;
@@ -401,17 +393,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
updateUserShortcutType(/* saveChanges= */ true);
if (mShortcutPreference.getChecked()) {
optInAllMagnificationValuesToSettings(getContext(), mUserShortcutType);
optOutAllMagnificationValuesFromSettings(getContext(), ~mUserShortcutType);
optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
}
mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext()));
}
private String getComponentName() {
return MAGNIFICATION_CONTROLLER_NAME;
}
@Override
public int getMetricsCategory() {
// TODO: Distinguish between magnification modes
@@ -421,11 +409,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
public int getDialogMetricsCategory(int dialogId) {
switch (dialogId) {
case DialogType.GESTURE_NAVIGATION_TUTORIAL:
case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
return SettingsEnums.DIALOG_TOGGLE_SCREEN_MAGNIFICATION_GESTURE_NAVIGATION;
case DialogType.ACCESSIBILITY_BUTTON_TUTORIAL:
case DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL:
return SettingsEnums.DIALOG_TOGGLE_SCREEN_MAGNIFICATION_ACCESSIBILITY_BUTTON;
case DialogType.EDIT_SHORTCUT:
case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
return SettingsEnums.DIALOG_MAGNIFICATION_EDIT_SHORTCUT;
default:
return 0;
@@ -438,8 +426,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
preferenceKey)) {
showDialog(AccessibilityUtil.isGestureNavigateEnabled(getContext())
? DialogType.GESTURE_NAVIGATION_TUTORIAL
: DialogType.ACCESSIBILITY_BUTTON_TUTORIAL);
? DialogEnums.GESTURE_NAVIGATION_TUTORIAL
: DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL);
}
MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled);
updateConfigurationWarningIfNeeded();
@@ -480,7 +468,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
public void onSettingsClicked(ShortcutPreference preference) {
mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
showDialog(DialogType.EDIT_SHORTCUT);
showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
}
private void updateShortcutPreferenceData() {
@@ -532,13 +520,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
mConfigWarningPreference.setVisible(warningMessage != null);
}
@Retention(RetentionPolicy.SOURCE)
private @interface DialogType {
int GESTURE_NAVIGATION_TUTORIAL = 1;
int ACCESSIBILITY_BUTTON_TUTORIAL = 2;
int EDIT_SHORTCUT = 3;
}
@VisibleForTesting
static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {