Support accessibility shorcut secondary action (3/n)
Combine the UI with both shortcut preference and edit dialog. This CL only contains UI and related connections. Related logic implementation will be added in next CL. Since the drawable resources are not ready, put the mock drawables as temporary. Once the drawbles are provided by UX, create a CL to replace the related resources. Bug: 142530063 Bug: 142531156 Test: Maunal Change-Id: I21e4c6e99c2d1731c15d7c9553594160b8809eb5
This commit is contained in:
@@ -16,13 +16,21 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
@@ -30,6 +38,7 @@ import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.widget.RadioButtonPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -42,6 +51,8 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.accessibility_daltonizer_settings);
|
||||
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED;
|
||||
private static final String RADIOPREFERENCE_KEY = "daltonizer_mode_deuteranomaly";
|
||||
private static final int DIALOG_ID_EDIT_SHORTCUT = 1;
|
||||
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
@@ -59,6 +70,27 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
return sControllers;
|
||||
}
|
||||
|
||||
private final DialogInterface.OnClickListener mDialogListener =
|
||||
(DialogInterface dialog, int id) -> {
|
||||
if (id == DialogInterface.BUTTON_POSITIVE) {
|
||||
// TODO(b/142531156): Save the shortcut type preference.
|
||||
}
|
||||
};
|
||||
|
||||
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 Dialog mDialog;
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(Preference preference) {
|
||||
for (AbstractPreferenceController controller : sControllers) {
|
||||
@@ -66,6 +98,13 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
initShortcutPreference();
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@@ -86,11 +125,32 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(int dialogId) {
|
||||
if (dialogId == DIALOG_ID_EDIT_SHORTCUT) {
|
||||
final CharSequence dialogTitle = getActivity().getString(
|
||||
R.string.accessibility_shortcut_edit_dialog_title_daltonizer);
|
||||
mDialog = AccessibilityEditDialogUtils.showEditShortcutDialog(getActivity(),
|
||||
dialogTitle, mDialogListener);
|
||||
}
|
||||
|
||||
return mDialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.ACCESSIBILITY_TOGGLE_DALTONIZER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
if (dialogId == DIALOG_ID_EDIT_SHORTCUT) {
|
||||
return SettingsEnums.ACCESSIBILITY_TOGGLE_DALTONIZER;
|
||||
// TODO(b/142531156): Create a settings enum to replace it.
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return R.string.help_url_color_correction;
|
||||
@@ -131,4 +191,20 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1);
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
}
|
||||
|
||||
private void initShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
final ShortcutPreference shortcutPreference = new ShortcutPreference(
|
||||
preferenceScreen.getContext(), null);
|
||||
final RadioButtonPreference radioButtonPreference = findPreference(RADIOPREFERENCE_KEY);
|
||||
// Put the shortcutPreference before radioButtonPreference.
|
||||
shortcutPreference.setOrder(radioButtonPreference.getOrder() - 1);
|
||||
shortcutPreference.setTitle(R.string.accessibility_shortcut_title);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user