Accessibility shortcut secondary action - improve shortcutPreference

1. Use setWidgetLayoutResource() for the controllable widget at the
right side.
2. Improve listener structure.
3. Extend checkbox clickable area.

Bug: 142530063
Test: make -j52 RunSettingsRoboTests ROBOTEST_FILTER=ShortcutPreferenceTest
Change-Id: Iebb9f62653914a0d7200c627f01cf7953d576960
This commit is contained in:
jasonwshsu
2019-12-20 13:06:01 +08:00
parent 506b40078e
commit 0dd53520a5
7 changed files with 239 additions and 134 deletions

View File

@@ -43,7 +43,6 @@ import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.widget.CheckBox;
import androidx.preference.PreferenceScreen;
@@ -57,8 +56,11 @@ import com.android.settingslib.accessibility.AccessibilityUtils;
import java.util.List;
public class ToggleAccessibilityServicePreferenceFragment extends ToggleFeaturePreferenceFragment {
/** Fragment for providing toggle bar and basic accessibility service setup. */
public class ToggleAccessibilityServicePreferenceFragment extends
ToggleFeaturePreferenceFragment implements ShortcutPreference.OnClickListener {
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private static final int DIALOG_ID_ENABLE_WARNING = 1;
private static final int DIALOG_ID_DISABLE_WARNING = 2;
private static final int DIALOG_ID_LAUNCH_ACCESSIBILITY_TUTORIAL = 3;
@@ -77,18 +79,6 @@ public class ToggleAccessibilityServicePreferenceFragment extends ToggleFeatureP
}
};
private final View.OnClickListener mSettingButtonListener = (View view) -> showDialog(
DIALOG_ID_EDIT_SHORTCUT);
private final View.OnClickListener mCheckBoxListener = (View view) -> {
CheckBox checkBox = (CheckBox) view;
if (checkBox.isChecked()) {
// TODO(b/142530063): Enable shortcut when checkbox is checked.
} else {
// TODO(b/142530063): Disable shortcut when checkbox is unchecked.
}
};
private final SettingsContentObserver mSettingsContentObserver =
new SettingsContentObserver(new Handler()) {
@Override
@@ -275,16 +265,22 @@ public class ToggleAccessibilityServicePreferenceFragment extends ToggleFeatureP
final ShortcutPreference shortcutPreference = new ShortcutPreference(
preferenceScreen.getContext(), null);
// Put the shortcutPreference before settingsPreference.
shortcutPreference.setPersistent(false);
shortcutPreference.setKey(getShortcutPreferenceKey());
shortcutPreference.setOrder(-1);
shortcutPreference.setTitle(R.string.accessibility_shortcut_title);
shortcutPreference.setOnClickListener(this);
// TODO(b/142530063): Check the new setting key to decide which summary should be shown.
// TODO(b/142530063): Check if gesture mode is on to decide which summary should be shown.
// TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
shortcutPreference.setSettingButtonListener(mSettingButtonListener);
shortcutPreference.setCheckBoxListener(mCheckBoxListener);
preferenceScreen.addPreference(shortcutPreference);
}
public String getShortcutPreferenceKey() {
return KEY_SHORTCUT_PREFERENCE;
}
private void updateSwitchBarToggleSwitch() {
final boolean checked = AccessibilityUtils.getEnabledServicesFromSettings(getActivity())
.contains(mComponentName);
@@ -387,6 +383,20 @@ public class ToggleAccessibilityServicePreferenceFragment extends ToggleFeatureP
});
}
@Override
public void onCheckboxClicked(ShortcutPreference preference) {
if (preference.getChecked()) {
// TODO(b/142530063): Enable shortcut when checkbox is checked.
} else {
// TODO(b/142530063): Disable shortcut when checkbox is unchecked.
}
}
@Override
public void onSettingsClicked(ShortcutPreference preference) {
showDialog(DIALOG_ID_EDIT_SHORTCUT);
}
@Override
protected void onProcessArguments(Bundle arguments) {
super.onProcessArguments(arguments);