Merge "ShortcutPreference Toggle design (2/n)" into rvc-dev am: 42dcad9b2b am: 888ebb0dbb

Change-Id: I153875309898060c908bc90b6cbb72d9d5f0dda8
This commit is contained in:
Automerger Merge Worker
2020-03-09 08:29:56 +00:00
6 changed files with 53 additions and 74 deletions

View File

@@ -44,19 +44,21 @@
android:id="@+id/advanced_shortcut" android:id="@+id/advanced_shortcut"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:scaleType="fitCenter" android:layout_gravity="center"
android:contentDescription="@null"
android:scaleType="centerCrop"
android:src="@drawable/ic_keyboard_arrow_down" /> android:src="@drawable/ic_keyboard_arrow_down" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingStart="12dp" android:paddingStart="12dp"
android:text="@string/accessibility_shortcut_edit_dialog_title_advance" android:text="@string/accessibility_shortcut_edit_dialog_title_advance"
android:textAppearance="?android:attr/textAppearanceListItem" android:textAppearance="?android:attr/textAppearanceListItem"

View File

@@ -73,7 +73,7 @@ final class AccessibilityUtil {
/** /**
* Annotation for different user shortcut type UI type. * Annotation for different user shortcut type UI type.
* *
* {@code DEFAULT} for displaying default value. * {@code EMPTY} for displaying default value.
* {@code SOFTWARE} for displaying specifying the accessibility services or features which * {@code SOFTWARE} for displaying specifying the accessibility services or features which
* choose accessibility button in the navigation bar as preferred shortcut. * choose accessibility button in the navigation bar as preferred shortcut.
* {@code HARDWARE} for displaying specifying the accessibility services or features which * {@code HARDWARE} for displaying specifying the accessibility services or features which
@@ -83,7 +83,7 @@ final class AccessibilityUtil {
*/ */
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({ @IntDef({
UserShortcutType.DEFAULT, UserShortcutType.EMPTY,
UserShortcutType.SOFTWARE, UserShortcutType.SOFTWARE,
UserShortcutType.HARDWARE, UserShortcutType.HARDWARE,
UserShortcutType.TRIPLETAP, UserShortcutType.TRIPLETAP,
@@ -91,7 +91,7 @@ final class AccessibilityUtil {
/** Denotes the user shortcut type. */ /** Denotes the user shortcut type. */
public @interface UserShortcutType { public @interface UserShortcutType {
int DEFAULT = 0; int EMPTY = 0;
int SOFTWARE = 1; // 1 << 0 int SOFTWARE = 1; // 1 << 0
int HARDWARE = 2; // 1 << 1 int HARDWARE = 2; // 1 << 1
int TRIPLETAP = 4; // 1 << 2 int TRIPLETAP = 4; // 1 << 2
@@ -323,7 +323,7 @@ final class AccessibilityUtil {
*/ */
static int getUserShortcutTypesFromSettings(Context context, static int getUserShortcutTypesFromSettings(Context context,
@NonNull ComponentName componentName) { @NonNull ComponentName componentName) {
int shortcutTypes = UserShortcutType.DEFAULT; int shortcutTypes = UserShortcutType.EMPTY;
if (hasValuesInSettings(context, UserShortcutType.SOFTWARE, componentName)) { if (hasValuesInSettings(context, UserShortcutType.SOFTWARE, componentName)) {
shortcutTypes |= UserShortcutType.SOFTWARE; shortcutTypes |= UserShortcutType.SOFTWARE;
} }

View File

@@ -417,6 +417,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName); AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mDialog.dismiss(); mDialog.dismiss();
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
} }
private void onDenyButtonFromShortcutToggleClicked() { private void onDenyButtonFromShortcutToggleClicked() {

View File

@@ -90,9 +90,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference"; private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private int mUserShortcutType = UserShortcutType.DEFAULT; private int mUserShortcutType = UserShortcutType.EMPTY;
// Used to restore the edit dialog status. // Used to restore the edit dialog status.
private int mUserShortcutTypeCache = UserShortcutType.DEFAULT; private int mUserShortcutTypeCache = UserShortcutType.EMPTY;
private CheckBox mSoftwareTypeCheckBox; private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox; private CheckBox mHardwareTypeCheckBox;
@@ -413,18 +413,18 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR); new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
private String mComponentName; private String mComponentName;
private int mUserShortcutType; private int mType;
AccessibilityUserShortcutType(String componentName, int userShortcutType) { AccessibilityUserShortcutType(String componentName, int type) {
this.mComponentName = componentName; this.mComponentName = componentName;
this.mUserShortcutType = userShortcutType; this.mType = type;
} }
AccessibilityUserShortcutType(String flattenedString) { AccessibilityUserShortcutType(String flattenedString) {
sStringColonSplitter.setString(flattenedString); sStringColonSplitter.setString(flattenedString);
if (sStringColonSplitter.hasNext()) { if (sStringColonSplitter.hasNext()) {
this.mComponentName = sStringColonSplitter.next(); this.mComponentName = sStringColonSplitter.next();
this.mUserShortcutType = Integer.parseInt(sStringColonSplitter.next()); this.mType = Integer.parseInt(sStringColonSplitter.next());
} }
} }
@@ -436,18 +436,18 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
this.mComponentName = componentName; this.mComponentName = componentName;
} }
int getUserShortcutType() { int getType() {
return mUserShortcutType; return mType;
} }
void setUserShortcutType(int userShortcutType) { void setType(int type) {
this.mUserShortcutType = userShortcutType; this.mType = type;
} }
String flattenToString() { String flattenToString() {
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR)); final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
joiner.add(mComponentName); joiner.add(mComponentName);
joiner.add(String.valueOf(mUserShortcutType)); joiner.add(String.valueOf(mType));
return joiner.toString(); return joiner.toString();
} }
} }
@@ -459,7 +459,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut); final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox); mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
updateAlertDialogCheckState(); updateAlertDialogCheckState();
updateAlertDialogEnableState();
} }
private void updateAlertDialogCheckState() { private void updateAlertDialogCheckState() {
@@ -467,36 +466,28 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE); updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
} }
private void updateAlertDialogEnableState() {
if (!mSoftwareTypeCheckBox.isChecked()) {
mHardwareTypeCheckBox.setEnabled(false);
} else if (!mHardwareTypeCheckBox.isChecked()) {
mSoftwareTypeCheckBox.setEnabled(false);
} else {
mSoftwareTypeCheckBox.setEnabled(true);
mHardwareTypeCheckBox.setEnabled(true);
}
}
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) { private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
checkBox.setChecked((mUserShortcutTypeCache & type) == type); checkBox.setChecked((mUserShortcutTypeCache & type) == type);
checkBox.setOnClickListener(v -> { checkBox.setOnClickListener(v -> {
updateUserShortcutType(/* saveChanges= */ false); updateUserShortcutType(/* saveChanges= */ false);
updateAlertDialogEnableState();
}); });
} }
private void updateUserShortcutType(boolean saveChanges) { private void updateUserShortcutType(boolean saveChanges) {
mUserShortcutTypeCache = UserShortcutType.DEFAULT; mUserShortcutTypeCache = UserShortcutType.EMPTY;
if (mSoftwareTypeCheckBox.isChecked()) { if (mSoftwareTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE; mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
} }
if (mHardwareTypeCheckBox.isChecked()) { if (mHardwareTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.HARDWARE; mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
} }
if (saveChanges) { if (saveChanges) {
final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY);
if (isChanged) {
setUserShortcutType(getPrefContext(), mUserShortcutTypeCache);
}
mUserShortcutType = mUserShortcutTypeCache; mUserShortcutType = mUserShortcutTypeCache;
setUserShortcutType(getPrefContext(), mUserShortcutType);
} }
} }
@@ -573,7 +564,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final String str = (String) filtered.toArray()[0]; final String str = (String) filtered.toArray()[0];
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str); final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
return shortcut.getUserShortcutType(); return shortcut.getType();
} }
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) { private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
@@ -582,13 +573,11 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
updateUserShortcutType(/* saveChanges= */ true); updateUserShortcutType(/* saveChanges= */ true);
if (mShortcutPreference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType, AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType,
mComponentName); mComponentName);
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType, AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType,
mComponentName); mComponentName);
} mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY);
mShortcutPreference.setChecked(true);
mShortcutPreference.setSummary( mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext())); getShortcutTypeSummary(getPrefContext()));
} }
@@ -601,7 +590,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// Get the user shortcut type from settings provider. // Get the user shortcut type from settings provider.
mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(), mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
mComponentName); mComponentName);
if (mUserShortcutType != UserShortcutType.DEFAULT) { if (mUserShortcutType != UserShortcutType.EMPTY) {
setUserShortcutType(getPrefContext(), mUserShortcutType); setUserShortcutType(getPrefContext(), mUserShortcutType);
} else { } else {
// Get the user shortcut type from shared_prefs if cannot get from settings provider. // Get the user shortcut type from shared_prefs if cannot get from settings provider.
@@ -613,7 +602,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// Restore the user shortcut type. // Restore the user shortcut type.
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) { if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
UserShortcutType.DEFAULT); UserShortcutType.EMPTY);
} }
// Initial the shortcut preference. // Initial the shortcut preference.

View File

@@ -70,9 +70,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference"; private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private int mUserShortcutType = UserShortcutType.DEFAULT; private int mUserShortcutType = UserShortcutType.EMPTY;
// Used to restore the edit dialog status. // Used to restore the edit dialog status.
private int mUserShortcutTypeCache = UserShortcutType.DEFAULT; private int mUserShortcutTypeCache = UserShortcutType.EMPTY;
private CheckBox mSoftwareTypeCheckBox; private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox; private CheckBox mHardwareTypeCheckBox;
private CheckBox mTripleTapTypeCheckBox; private CheckBox mTripleTapTypeCheckBox;
@@ -255,7 +255,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox); mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox);
final View advancedView = dialog.findViewById(R.id.advanced_shortcut); final View advancedView = dialog.findViewById(R.id.advanced_shortcut);
updateAlertDialogCheckState(); updateAlertDialogCheckState();
updateAlertDialogEnableState();
// Window magnification mode doesn't support advancedView. // Window magnification mode doesn't support advancedView.
if (isWindowMagnification(getPrefContext())) { if (isWindowMagnification(getPrefContext())) {
@@ -275,30 +274,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends
updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP); updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP);
} }
private void updateAlertDialogEnableState() {
if (!mSoftwareTypeCheckBox.isChecked() && !mTripleTapTypeCheckBox.isChecked()) {
mHardwareTypeCheckBox.setEnabled(false);
} else if (!mHardwareTypeCheckBox.isChecked() && !mTripleTapTypeCheckBox.isChecked()) {
mSoftwareTypeCheckBox.setEnabled(false);
} else if (!mSoftwareTypeCheckBox.isChecked() && !mHardwareTypeCheckBox.isChecked()) {
mTripleTapTypeCheckBox.setEnabled(false);
} else {
mSoftwareTypeCheckBox.setEnabled(true);
mHardwareTypeCheckBox.setEnabled(true);
mTripleTapTypeCheckBox.setEnabled(true);
}
}
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) { private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
checkBox.setChecked((mUserShortcutTypeCache & type) == type); checkBox.setChecked((mUserShortcutTypeCache & type) == type);
checkBox.setOnClickListener(v -> { checkBox.setOnClickListener(v -> {
updateUserShortcutType(/* saveChanges= */ false); updateUserShortcutType(/* saveChanges= */ false);
updateAlertDialogEnableState();
}); });
} }
private void updateUserShortcutType(boolean saveChanges) { private void updateUserShortcutType(boolean saveChanges) {
mUserShortcutTypeCache = UserShortcutType.DEFAULT; mUserShortcutTypeCache = UserShortcutType.EMPTY;
if (mSoftwareTypeCheckBox.isChecked()) { if (mSoftwareTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.SOFTWARE; mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
} }
@@ -308,9 +292,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends
if (mTripleTapTypeCheckBox.isChecked()) { if (mTripleTapTypeCheckBox.isChecked()) {
mUserShortcutTypeCache |= UserShortcutType.TRIPLETAP; mUserShortcutTypeCache |= UserShortcutType.TRIPLETAP;
} }
if (saveChanges) { if (saveChanges) {
final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY);
if (isChanged) {
setUserShortcutType(getPrefContext(), mUserShortcutTypeCache);
}
mUserShortcutType = mUserShortcutTypeCache; mUserShortcutType = mUserShortcutTypeCache;
setUserShortcutType(getPrefContext(), mUserShortcutType);
} }
} }
@@ -336,7 +324,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return context.getText(R.string.switch_off_text); return context.getText(R.string.switch_off_text);
} }
final int shortcutType = getUserShortcutType(context, UserShortcutType.DEFAULT); final int shortcutType = getUserShortcutType(context, UserShortcutType.EMPTY);
int resId = R.string.accessibility_shortcut_edit_summary_software; int resId = R.string.accessibility_shortcut_edit_summary_software;
if (AccessibilityUtil.isGestureNavigateEnabled(context)) { if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
resId = AccessibilityUtil.isTouchExploreEnabled(context) resId = AccessibilityUtil.isTouchExploreEnabled(context)
@@ -381,16 +369,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends
final String str = (String) filtered.toArray()[0]; final String str = (String) filtered.toArray()[0];
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str); final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
return shortcut.getUserShortcutType(); return shortcut.getType();
} }
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) { private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
updateUserShortcutType(/* saveChanges= */ true); updateUserShortcutType(/* saveChanges= */ true);
if (mShortcutPreference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType); optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType); optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
} mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY);
mShortcutPreference.setChecked(true);
mShortcutPreference.setSummary( mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext())); getShortcutTypeSummary(getPrefContext()));
} }
@@ -467,7 +453,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private void updateShortcutPreferenceData() { private void updateShortcutPreferenceData() {
// Get the user shortcut type from settings provider. // Get the user shortcut type from settings provider.
mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext()); mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
if (mUserShortcutType != UserShortcutType.DEFAULT) { if (mUserShortcutType != UserShortcutType.EMPTY) {
setUserShortcutType(getPrefContext(), mUserShortcutType); setUserShortcutType(getPrefContext(), mUserShortcutType);
} else { } else {
// Get the user shortcut type from shared_prefs if cannot get from settings provider. // Get the user shortcut type from shared_prefs if cannot get from settings provider.
@@ -626,7 +612,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
} }
private static int getUserShortcutTypeFromSettings(Context context) { private static int getUserShortcutTypeFromSettings(Context context) {
int shortcutTypes = UserShortcutType.DEFAULT; int shortcutTypes = UserShortcutType.EMPTY;
if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) { if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) {
shortcutTypes |= UserShortcutType.SOFTWARE; shortcutTypes |= UserShortcutType.SOFTWARE;
} }

View File

@@ -60,7 +60,7 @@ public class ToggleFeaturePreferenceFragmentTest {
TEST_SERVICE_KEY_1); TEST_SERVICE_KEY_1);
assertThat(shortcut.getComponentName()).isEqualTo(TEST_SERVICE_NAME_1); assertThat(shortcut.getComponentName()).isEqualTo(TEST_SERVICE_NAME_1);
assertThat(shortcut.getUserShortcutType()).isEqualTo(TEST_SERVICE_VALUE_1); assertThat(shortcut.getType()).isEqualTo(TEST_SERVICE_VALUE_1);
} }
@Test @Test
@@ -69,7 +69,7 @@ public class ToggleFeaturePreferenceFragmentTest {
TEST_SERVICE_KEY_2); TEST_SERVICE_KEY_2);
shortcut.setComponentName(TEST_SERVICE_NAME_1); shortcut.setComponentName(TEST_SERVICE_NAME_1);
shortcut.setUserShortcutType(TEST_SERVICE_VALUE_1); shortcut.setType(TEST_SERVICE_VALUE_1);
assertThat(shortcut.flattenToString()).isEqualTo(TEST_SERVICE_KEY_1); assertThat(shortcut.flattenToString()).isEqualTo(TEST_SERVICE_KEY_1);
} }
@@ -103,7 +103,7 @@ public class ToggleFeaturePreferenceFragmentTest {
final String str = (String) filtered.toArray()[0]; final String str = (String) filtered.toArray()[0];
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str); final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
final int type = shortcut.getUserShortcutType(); final int type = shortcut.getType();
assertThat(type).isEqualTo(TEST_SERVICE_VALUE_1); assertThat(type).isEqualTo(TEST_SERVICE_VALUE_1);
} }