ShortcutPreference Toggle design.

- For target SDK < 30 app show as preference item to trigger shortcut on/off.
- For target SDK >= 30 app show two item: the left one can edit shortcut and the right one be a on/off trigger button.

The design is reference from WIFI setting which has similar comportment.

Bug: 148989269
Test: Test result in Buganizer.

Change-Id: I815206d9e885c01bf3e6445820176aed4a743323
This commit is contained in:
menghanli
2020-02-18 23:05:38 +08:00
parent 4d59bce21b
commit 919e555a51
9 changed files with 182 additions and 170 deletions

View File

@@ -29,27 +29,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:gravity="start|center_vertical" android:gravity="start|center_vertical"
android:focusable="true" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:clickable="true" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
android:background="?android:attr/selectableItemBackground">
<FrameLayout <FrameLayout
android:layout_width="wrap_content" android:id="@+id/icon_frame"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:minWidth="56dp"
android:orientation="horizontal"
android:focusable="false"
android:clickable="false">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:minWidth="56dp"
android:focusable="false" android:paddingEnd="12dp"
android:clickable="false" android:paddingTop="16dp"
android:background="@null"/> android:paddingBottom="4dp">
<ImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout> </FrameLayout>
@@ -94,7 +89,6 @@
android:id="@android:id/widget_frame" android:id="@android:id/widget_frame"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@string/accessibility_shortcut_settings"
android:gravity="end|center_vertical" android:gravity="end|center_vertical"
android:minWidth="58dp" android:minWidth="58dp"
android:orientation="vertical" /> android:orientation="vertical" />

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License
-->
<!-- Layout used by ShortcutPreference. This is inflated inside android.R.layout.preference. -->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/settings_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackground"
android:scaleType="center"
android:src="@drawable/ic_mode_edit"
android:contentDescription="@string/settings_button" />

View File

@@ -32,7 +32,7 @@ import com.android.settingslib.accessibility.AccessibilityUtils;
* {@link AccessibilityServiceInfo#FLAG_REQUEST_ACCESSIBILITY_BUTTON} is set. * {@link AccessibilityServiceInfo#FLAG_REQUEST_ACCESSIBILITY_BUTTON} is set.
*/ */
public class InvisibleToggleAccessibilityServicePreferenceFragment extends public class InvisibleToggleAccessibilityServicePreferenceFragment extends
ToggleAccessibilityServicePreferenceFragment implements ShortcutPreference.OnClickListener{ ToggleAccessibilityServicePreferenceFragment implements ShortcutPreference.OnClickCallback {
@Override @Override
protected void onInstallSwitchPreferenceToggleSwitch() { protected void onInstallSwitchPreferenceToggleSwitch() {
@@ -47,10 +47,10 @@ public class InvisibleToggleAccessibilityServicePreferenceFragment extends
* accessibility service when shortcutPreference is unchecked. * accessibility service when shortcutPreference is unchecked.
*/ */
@Override @Override
public void onCheckboxClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
super.onCheckboxClicked(preference); super.onToggleClicked(preference);
boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED) boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)
&& preference.getChecked(); && preference.isChecked();
AccessibilityUtils.setAccessibilityServiceState(getContext(), mComponentName, enabled); AccessibilityUtils.setAccessibilityServiceState(getContext(), mComponentName, enabled);
} }
@@ -61,8 +61,8 @@ public class InvisibleToggleAccessibilityServicePreferenceFragment extends
* Enables accessibility service when user clicks permission allow button. * Enables accessibility service when user clicks permission allow button.
*/ */
@Override @Override
void onDialogButtonFromShortcutClicked(View view) { void onDialogButtonFromShortcutToggleClicked(View view) {
super.onDialogButtonFromShortcutClicked(view); super.onDialogButtonFromShortcutToggleClicked(view);
if (view.getId() == R.id.permission_enable_allow_button) { if (view.getId() == R.id.permission_enable_allow_button) {
AccessibilityUtils.setAccessibilityServiceState(getContext(), mComponentName, AccessibilityUtils.setAccessibilityServiceState(getContext(), mComponentName,
true); true);

View File

@@ -43,7 +43,7 @@ public class LegacyAccessibilityServicePreferenceFragment extends
final CharSequence hardwareTitle = getPrefContext().getText( final CharSequence hardwareTitle = getPrefContext().getText(
R.string.accessibility_shortcut_edit_dialog_title_hardware); R.string.accessibility_shortcut_edit_dialog_title_hardware);
mShortcutPreference.setSummary(hardwareTitle); mShortcutPreference.setSummary(hardwareTitle);
mShortcutPreference.setSettingsVisibility(View.GONE); mShortcutPreference.setSettingsEditable(false);
setAllowedPreferredShortcutType(UserShortcutType.HARDWARE); setAllowedPreferredShortcutType(UserShortcutType.HARDWARE);
} }

View File

@@ -18,9 +18,11 @@ package com.android.settings.accessibility;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Switch;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
@@ -34,77 +36,84 @@ import com.android.settings.R;
public class ShortcutPreference extends Preference { public class ShortcutPreference extends Preference {
/** /**
* Interface definition for a callback to be invoked when the checkbox or settings has been * Interface definition for a callback to be invoked when the toggle or settings has been
* clicked. * clicked.
*/ */
public interface OnClickListener { public interface OnClickCallback {
/**
* Called when the checkbox in ShortcutPreference has been clicked.
*
* @param preference The clicked preference
*/
void onCheckboxClicked(ShortcutPreference preference);
/** /**
* Called when the settings view has been clicked. * Called when the settings view has been clicked.
* *
* @param preference The clicked preference * @param preference The clicked preference
*/ */
void onSettingsClicked(ShortcutPreference preference); void onSettingsClicked(ShortcutPreference preference);
}
private OnClickListener mListener = null;
private static final float DISABLED_ALPHA = 0.77f; /**
private static final float ENABLED_ALPHA = 1.0f; * Called when the toggle in ShortcutPreference has been clicked.
private int mSettingsVisibility = View.VISIBLE; *
private boolean mAutoEnabledSettings; * @param preference The clicked preference
*/
void onToggleClicked(ShortcutPreference preference);
}
private OnClickCallback mClickCallback = null;
private boolean mChecked = false; private boolean mChecked = false;
private boolean mSettingsEditable = true;
ShortcutPreference(Context context, AttributeSet attrs) { ShortcutPreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(); setLayoutResource(R.layout.accessibility_shortcut_secondary_action);
setWidgetLayoutResource(R.layout.preference_widget_master_switch);
setIconSpaceReserved(true);
setSelectable(false);
} }
@Override @Override
public void onBindViewHolder(PreferenceViewHolder holder) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder); super.onBindViewHolder(holder);
final TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true);
final LinearLayout mainFrame = holder.itemView.findViewById(R.id.main_frame); final LinearLayout mainFrame = holder.itemView.findViewById(R.id.main_frame);
if (mainFrame != null) { if (mainFrame != null) {
mainFrame.setOnClickListener(view -> callOnCheckboxClicked()); mainFrame.setOnClickListener(view -> callOnSettingsClicked());
mainFrame.setClickable(mSettingsEditable);
mainFrame.setFocusable(mSettingsEditable);
mainFrame.setBackgroundResource(
mSettingsEditable ? outValue.resourceId : /* Remove background */ 0);
} }
final CheckBox checkBox = holder.itemView.findViewById(R.id.checkbox); Switch switchWidget = holder.itemView.findViewById(R.id.switchWidget);
if (checkBox != null) { if (switchWidget != null) {
checkBox.setChecked(mChecked); // Consumes move events to ignore drag actions.
} switchWidget.setOnTouchListener((v, event) -> {
return event.getActionMasked() == MotionEvent.ACTION_MOVE;
});
final View settings = holder.itemView.findViewById(android.R.id.widget_frame); switchWidget.setContentDescription(
if (settings != null) { getContext().getText(R.string.accessibility_shortcut_settings));
settings.setOnClickListener(view -> callOnSettingsClicked()); switchWidget.setChecked(mChecked);
settings.setEnabled(mAutoEnabledSettings ? mChecked : /* enabled */ true); switchWidget.setOnClickListener(view -> callOnToggleClicked());
switchWidget.setClickable(mSettingsEditable);
float alpha; switchWidget.setFocusable(mSettingsEditable);
if (mAutoEnabledSettings) { switchWidget.setBackgroundResource(
alpha = mChecked ? ENABLED_ALPHA : DISABLED_ALPHA; mSettingsEditable ? outValue.resourceId : /* Remove background */ 0);
} else {
alpha = ENABLED_ALPHA;
}
settings.setAlpha(alpha);
settings.setVisibility(mSettingsVisibility);
} }
final View divider = holder.itemView.findViewById(R.id.divider); final View divider = holder.itemView.findViewById(R.id.divider);
if (divider != null) { if (divider != null) {
divider.setVisibility(mSettingsVisibility); divider.setVisibility(mSettingsEditable ? View.VISIBLE : View.GONE);
} }
holder.itemView.setOnClickListener(view -> callOnToggleClicked());
holder.itemView.setClickable(!mSettingsEditable);
holder.itemView.setFocusable(!mSettingsEditable);
} }
/** /**
* Sets the shortcut checkbox according to checked value. * Sets the shortcut toggle according to checked value.
* *
* @param checked the state value of shortcut checkbox * @param checked the state value of shortcut toggle
*/ */
public void setChecked(boolean checked) { public void setChecked(boolean checked) {
if (mChecked != checked) { if (mChecked != checked) {
@@ -114,72 +123,50 @@ public class ShortcutPreference extends Preference {
} }
/** /**
* Gets the checked value of shortcut checkbox. * Gets the checked value of shortcut toggle.
* *
* @return the checked value of shortcut checkbox * @return the checked value of shortcut toggle
*/ */
public boolean getChecked() { public boolean isChecked() {
return mChecked; return mChecked;
} }
/** /**
* Automatically/Manually enable settings according to checkbox click status. * Sets the editable state of Settings view. If the view cannot edited, it makes the settings
* * and toggle be not touchable. The main ui handles touch event directly by {@link #onClick}.
* Automatically enable settings means settings view enabled when checkbox is clicked, and
* disabled when checkbox is not clicked.
* Manually enable settings means settings view always enabled.
*
* @param autoEnabled True will automatically enable settings, false will let settings view
* always enabled.
*/ */
public void setAutoEnabledSettings(boolean autoEnabled) { public void setSettingsEditable(boolean enabled) {
if (mAutoEnabledSettings != autoEnabled) { if (mSettingsEditable != enabled) {
mAutoEnabledSettings = autoEnabled; mSettingsEditable = enabled;
// Disable whole component to let each child component can be addressed.
setSelectable(!mSettingsEditable);
notifyChanged(); notifyChanged();
} }
} }
/** public boolean isSettingsEditable() {
* Sets the visibility state of Settings view. return mSettingsEditable;
*
* @param visibility one of {@link View#VISIBLE}, {@link View#INVISIBLE}, or {@link View#GONE}.
*/
public void setSettingsVisibility(@View.Visibility int visibility) {
if (mSettingsVisibility != visibility) {
mSettingsVisibility = visibility;
notifyChanged();
}
} }
/** /**
* Sets the callback to be invoked when this preference is clicked by the user. * Sets the callback to be invoked when this preference is clicked by the user.
* *
* @param listener the callback to be invoked * @param callback the callback to be invoked
*/ */
public void setOnClickListener(OnClickListener listener) { public void setOnClickCallback(OnClickCallback callback) {
mListener = listener; mClickCallback = callback;
}
private void init() {
setLayoutResource(R.layout.accessibility_shortcut_secondary_action);
setWidgetLayoutResource(R.layout.preference_widget_settings);
setIconSpaceReserved(false);
mAutoEnabledSettings = true;
// Disable whole component to let each child component can be addressed.
setSelectable(false);
} }
private void callOnSettingsClicked() { private void callOnSettingsClicked() {
if (mListener != null) { if (mClickCallback != null) {
mListener.onSettingsClicked(this); mClickCallback.onSettingsClicked(this);
} }
} }
private void callOnCheckboxClicked() { private void callOnToggleClicked() {
setChecked(!mChecked); setChecked(!mChecked);
if (mListener != null) { if (mClickCallback != null) {
mListener.onCheckboxClicked(this); mClickCallback.onToggleClicked(this);
} }
} }
} }

View File

@@ -134,6 +134,16 @@ public class ToggleAccessibilityServicePreferenceFragment extends
this::onDialogButtonFromEnableToggleClicked); this::onDialogButtonFromEnableToggleClicked);
break; break;
} }
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT_TOGGLE: {
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
if (info == null) {
return null;
}
mDialog = AccessibilityServiceWarning
.createCapabilitiesDialog(getPrefContext(), info,
this::onDialogButtonFromShortcutToggleClicked);
break;
}
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT: { case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT: {
final AccessibilityServiceInfo info = getAccessibilityServiceInfo(); final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
if (info == null) { if (info == null) {
@@ -176,6 +186,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
switch (dialogId) { switch (dialogId) {
case DialogEnums.ENABLE_WARNING_FROM_TOGGLE: case DialogEnums.ENABLE_WARNING_FROM_TOGGLE:
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT: case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT:
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT_TOGGLE:
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_ENABLE; return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_ENABLE;
case DialogEnums.DISABLE_WARNING_FROM_TOGGLE: case DialogEnums.DISABLE_WARNING_FROM_TOGGLE:
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_DISABLE; return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_DISABLE;
@@ -283,12 +294,12 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} }
@Override @Override
public void onCheckboxClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
if (preference.getChecked()) { if (preference.isChecked()) {
if (!getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)) { if (!mToggleServiceDividerSwitchPreference.isChecked()) {
preference.setChecked(false); preference.setChecked(false);
showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_SHORTCUT); showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_SHORTCUT_TOGGLE);
} else { } else {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName); mComponentName);
@@ -296,14 +307,17 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} else { } else {
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
mComponentName); mComponentName);
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, false);
} }
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
} }
@Override @Override
public void onSettingsClicked(ShortcutPreference preference) { public void onSettingsClicked(ShortcutPreference preference) {
super.onSettingsClicked(preference); super.onSettingsClicked(preference);
showPopupDialog(DialogEnums.EDIT_SHORTCUT); final boolean isServiceOnOrShortcutAdded = mShortcutPreference.isChecked()
|| mToggleServiceDividerSwitchPreference.isChecked();
showPopupDialog(isServiceOnOrShortcutAdded ? DialogEnums.EDIT_SHORTCUT
: DialogEnums.ENABLE_WARNING_FROM_SHORTCUT);
} }
@Override @Override
@@ -385,6 +399,32 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mDialog.dismiss(); mDialog.dismiss();
} }
void onDialogButtonFromShortcutToggleClicked(View view) {
final int viewId = view.getId();
if (viewId == R.id.permission_enable_allow_button) {
onAllowButtonFromShortcutToggleClicked();
} else if (viewId == R.id.permission_enable_deny_button) {
onDenyButtonFromShortcutToggleClicked();
} else {
throw new IllegalArgumentException("Unexpected view id");
}
}
private void onAllowButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(true);
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mDialog.dismiss();
}
private void onDenyButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(false);
mDialog.dismiss();
}
void onDialogButtonFromShortcutClicked(View view) { void onDialogButtonFromShortcutClicked(View view) {
final int viewId = view.getId(); final int viewId = view.getId();
if (viewId == R.id.permission_enable_allow_button) { if (viewId == R.id.permission_enable_allow_button) {
@@ -397,17 +437,13 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} }
private void onAllowButtonFromShortcutClicked() { private void onAllowButtonFromShortcutClicked() {
mShortcutPreference.setChecked(true); mIsDialogShown.set(false);
showPopupDialog(DialogEnums.EDIT_SHORTCUT);
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mDialog.dismiss(); mDialog.dismiss();
} }
private void onDenyButtonFromShortcutClicked() { private void onDenyButtonFromShortcutClicked() {
mShortcutPreference.setChecked(false);
mDialog.dismiss(); mDialog.dismiss();
} }
@@ -417,7 +453,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mToggleServiceDividerSwitchPreference.setChecked(false); mToggleServiceDividerSwitchPreference.setChecked(false);
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
/* disableService */ false); /* disableService */ false);
if (!mShortcutPreference.getChecked()) { if (!mShortcutPreference.isChecked()) {
showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_TOGGLE); showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_TOGGLE);
} else { } else {
handleConfirmServiceEnabled(/* confirmed= */ true); handleConfirmServiceEnabled(/* confirmed= */ true);

View File

@@ -69,7 +69,7 @@ import java.util.stream.Collectors;
* and dialog management. * and dialog management.
*/ */
public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment
implements ShortcutPreference.OnClickListener { implements ShortcutPreference.OnClickCallback {
protected DividerSwitchPreference mToggleServiceDividerSwitchPreference; protected DividerSwitchPreference mToggleServiceDividerSwitchPreference;
protected ShortcutPreference mShortcutPreference; protected ShortcutPreference mShortcutPreference;
@@ -277,33 +277,38 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
*/ */
int ENABLE_WARNING_FROM_TOGGLE = 1002; int ENABLE_WARNING_FROM_TOGGLE = 1002;
/** OPEN: Settings > Accessibility > Downloaded toggle service > Shortcut checkbox. */ /** OPEN: Settings > Accessibility > Downloaded toggle service > Shortcut checkbox. */
int ENABLE_WARNING_FROM_SHORTCUT = 1003; int ENABLE_WARNING_FROM_SHORTCUT = 1003;
/**
* OPEN: Settings > Accessibility > Downloaded toggle service > Shortcut checkbox
* toggle.
*/
int ENABLE_WARNING_FROM_SHORTCUT_TOGGLE = 1004;
/** /**
* OPEN: Settings > Accessibility > Downloaded toggle service > Toggle use service to * OPEN: Settings > Accessibility > Downloaded toggle service > Toggle use service to
* disable service. * disable service.
*/ */
int DISABLE_WARNING_FROM_TOGGLE = 1004; int DISABLE_WARNING_FROM_TOGGLE = 1005;
/** /**
* OPEN: Settings > Accessibility > Magnification > Toggle user service in button * OPEN: Settings > Accessibility > Magnification > Toggle user service in button
* navigation. * navigation.
*/ */
int ACCESSIBILITY_BUTTON_TUTORIAL = 1005; int ACCESSIBILITY_BUTTON_TUTORIAL = 1006;
/** /**
* OPEN: Settings > Accessibility > Magnification > Toggle user service in gesture * OPEN: Settings > Accessibility > Magnification > Toggle user service in gesture
* navigation. * navigation.
*/ */
int GESTURE_NAVIGATION_TUTORIAL = 1006; int GESTURE_NAVIGATION_TUTORIAL = 1007;
/** /**
* OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service > Show * OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service > Show
* launch tutorial. * launch tutorial.
*/ */
int LAUNCH_ACCESSIBILITY_TUTORIAL = 1007; int LAUNCH_ACCESSIBILITY_TUTORIAL = 1008;
} }
@Override @Override
@@ -516,7 +521,15 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
SharedPreferenceUtils.setUserShortcutType(context, info); SharedPreferenceUtils.setUserShortcutType(context, info);
} }
private String getShortcutTypeSummary(Context context) { protected CharSequence getShortcutTypeSummary(Context context) {
if (!mShortcutPreference.isSettingsEditable()) {
return context.getText(R.string.accessibility_shortcut_edit_dialog_title_hardware);
}
if (!mShortcutPreference.isChecked()) {
return context.getText(R.string.switch_off_text);
}
final int shortcutType = getUserShortcutType(context, UserShortcutType.SOFTWARE); final int shortcutType = getUserShortcutType(context, UserShortcutType.SOFTWARE);
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)) {
@@ -569,12 +582,13 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
updateUserShortcutType(/* saveChanges= */ true); updateUserShortcutType(/* saveChanges= */ true);
if (mShortcutPreference.getChecked()) { 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(true);
mShortcutPreference.setSummary( mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext())); getShortcutTypeSummary(getPrefContext()));
} }
@@ -606,7 +620,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
mShortcutPreference = new ShortcutPreference(getPrefContext(), null); mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
mShortcutPreference.setPersistent(false); mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey()); mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setOnClickListener(this); mShortcutPreference.setOnClickCallback(this);
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName); final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
mShortcutPreference.setTitle(title); mShortcutPreference.setTitle(title);
@@ -629,19 +643,20 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
@Override @Override
public void onCheckboxClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
if (mComponentName == null) { if (mComponentName == null) {
return; return;
} }
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
if (preference.getChecked()) { if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName); mComponentName);
} else { } else {
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes, AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
mComponentName); mComponentName);
} }
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
} }
@Override @Override

View File

@@ -330,7 +330,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends
SharedPreferenceUtils.setUserShortcutType(context, info); SharedPreferenceUtils.setUserShortcutType(context, info);
} }
private String getShortcutTypeSummary(Context context) { @Override
protected CharSequence getShortcutTypeSummary(Context context) {
if (!mShortcutPreference.isChecked()) {
return context.getText(R.string.switch_off_text);
}
final int shortcutType = getUserShortcutType(context, UserShortcutType.DEFAULT); final int shortcutType = getUserShortcutType(context, UserShortcutType.DEFAULT);
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)) {
@@ -381,10 +386,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) { private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
updateUserShortcutType(/* saveChanges= */ true); updateUserShortcutType(/* saveChanges= */ true);
if (mShortcutPreference.getChecked()) { if (mShortcutPreference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType); optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType); optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
} }
mShortcutPreference.setChecked(true);
mShortcutPreference.setSummary( mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext())); getShortcutTypeSummary(getPrefContext()));
} }
@@ -442,13 +448,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends
} }
@Override @Override
public void onCheckboxClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
if (preference.getChecked()) { if (preference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes); optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
} else { } else {
optOutAllMagnificationValuesFromSettings(getPrefContext(), shortcutTypes); optOutAllMagnificationValuesFromSettings(getPrefContext(), shortcutTypes);
} }
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
} }
@Override @Override
@@ -473,7 +480,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
mShortcutPreference.setPersistent(false); mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(KEY_SHORTCUT_PREFERENCE); mShortcutPreference.setKey(KEY_SHORTCUT_PREFERENCE);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
mShortcutPreference.setOnClickListener(this); mShortcutPreference.setOnClickCallback(this);
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName); final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
mShortcutPreference.setTitle(title); mShortcutPreference.setTitle(title);

View File

@@ -44,10 +44,10 @@ public class ShortcutPreferenceTest {
private PreferenceViewHolder mPreferenceViewHolder; private PreferenceViewHolder mPreferenceViewHolder;
private String mResult; private String mResult;
private ShortcutPreference.OnClickListener mListener = private ShortcutPreference.OnClickCallback mListener =
new ShortcutPreference.OnClickListener() { new ShortcutPreference.OnClickCallback() {
@Override @Override
public void onCheckboxClicked(ShortcutPreference preference) { public void onToggleClicked(ShortcutPreference preference) {
mResult = CHECKBOX_CLICKED; mResult = CHECKBOX_CLICKED;
} }
@@ -71,19 +71,19 @@ public class ShortcutPreferenceTest {
@Test @Test
public void clickLinearLayout_checkboxClicked() { public void clickLinearLayout_checkboxClicked() {
mShortcutPreference.onBindViewHolder(mPreferenceViewHolder); mShortcutPreference.onBindViewHolder(mPreferenceViewHolder);
mShortcutPreference.setOnClickListener(mListener); mShortcutPreference.setOnClickCallback(mListener);
LinearLayout mainFrame = mPreferenceViewHolder.itemView.findViewById(R.id.main_frame); LinearLayout mainFrame = mPreferenceViewHolder.itemView.findViewById(R.id.main_frame);
mainFrame.performClick(); mainFrame.performClick();
assertThat(mResult).isEqualTo(CHECKBOX_CLICKED); assertThat(mResult).isEqualTo(CHECKBOX_CLICKED);
assertThat(mShortcutPreference.getChecked()).isTrue(); assertThat(mShortcutPreference.isChecked()).isTrue();
} }
@Test @Test
public void clickSettings_settingsClicked() { public void clickSettings_settingsClicked() {
mShortcutPreference.onBindViewHolder(mPreferenceViewHolder); mShortcutPreference.onBindViewHolder(mPreferenceViewHolder);
mShortcutPreference.setOnClickListener(mListener); mShortcutPreference.setOnClickCallback(mListener);
View settings = mPreferenceViewHolder.itemView.findViewById(android.R.id.widget_frame); View settings = mPreferenceViewHolder.itemView.findViewById(android.R.id.widget_frame);
settings.performClick(); settings.performClick();
@@ -95,6 +95,6 @@ public class ShortcutPreferenceTest {
public void setCheckedTrue_getCheckedIsTrue() { public void setCheckedTrue_getCheckedIsTrue() {
mShortcutPreference.setChecked(true); mShortcutPreference.setChecked(true);
assertThat(mShortcutPreference.getChecked()).isEqualTo(true); assertThat(mShortcutPreference.isChecked()).isEqualTo(true);
} }
} }