Save the user preferred shortcut on Edit A11yShortcut screen
We saved the user preferred shortcut in the a11y feature's detail page. Since now the Edit A11yShortcut screen is a standalone screen, we might want to keep the existing behavior to update the user preferred shortcut types when the edit screen is shown or when the shortcut settings are updated. Bug: 300302098 Test: atest Test: manual - Go to an a11y feature page and open the Edit shortcut screen - Remove all selected shortcut option - Select volume key shortcut option, and deselect volume key shortcut option - Go to home page and close the Settings app - Go to the same a11y feature page and click on the shortcut toggle - Expect the volume key shortcut is turned on Flag: ACONFIG com.android.settings.accessibility.edit_shortcuts_in_full_screen TRUNKFOOD Change-Id: I2c92ec56d6e45317406f3a4b8ef8f076c398df7f
This commit is contained in:
@@ -19,10 +19,17 @@ package com.android.settings.accessibility;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.UserHandle;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Static utility methods relating to {@link PreferredShortcut} */
|
||||
@@ -80,6 +87,41 @@ public final class PreferredShortcuts {
|
||||
saveToSharedPreferences(context, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user preferred shortcut from Settings data
|
||||
*
|
||||
* @param context {@link Context} to access the {@link SharedPreferences}
|
||||
* @param components contains a set of {@link ComponentName} the service or activity. The
|
||||
* string
|
||||
* representation of the ComponentName should be in the format of
|
||||
* {@link ComponentName#flattenToString()}.
|
||||
*/
|
||||
public static void updatePreferredShortcutsFromSettings(
|
||||
@NonNull Context context, @NonNull Set<String> components) {
|
||||
final Map<Integer, Set<String>> shortcutTypeToTargets = new ArrayMap<>();
|
||||
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
|
||||
shortcutTypeToTargets.put(
|
||||
shortcutType,
|
||||
ShortcutUtils.getShortcutTargetsFromSettings(
|
||||
context, shortcutType, UserHandle.myUserId()));
|
||||
}
|
||||
|
||||
for (String target : components) {
|
||||
int shortcutTypes = ShortcutConstants.UserShortcutType.DEFAULT;
|
||||
for (Map.Entry<Integer, Set<String>> entry : shortcutTypeToTargets.entrySet()) {
|
||||
if (entry.getValue().contains(target)) {
|
||||
shortcutTypes |= entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
if (shortcutTypes != ShortcutConstants.UserShortcutType.DEFAULT) {
|
||||
final PreferredShortcut shortcut = new PreferredShortcut(
|
||||
target, shortcutTypes);
|
||||
PreferredShortcuts.saveUserShortcutType(context, shortcut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a immutable set of {@link PreferredShortcut#toString()} list from
|
||||
* SharedPreferences.
|
||||
|
@@ -51,6 +51,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SetupWizardUtils;
|
||||
import com.android.settings.accessibility.AccessibilitySetupWizardUtils;
|
||||
import com.android.settings.accessibility.PreferredShortcuts;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -161,6 +162,9 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
|
||||
} else if (TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING.equals(uri)) {
|
||||
refreshPreferenceController(TwoFingersDoubleTapShortcutOptionController.class);
|
||||
}
|
||||
|
||||
PreferredShortcuts.updatePreferredShortcutsFromSettings(
|
||||
getContext(), mShortcutTargets);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -212,6 +216,7 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
|
||||
final AccessibilityManager am = getSystemService(
|
||||
AccessibilityManager.class);
|
||||
am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
|
||||
PreferredShortcuts.updatePreferredShortcutsFromSettings(getContext(), mShortcutTargets);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user