Merge "Fix that the user has no way of knowing if the reset was successful." into tm-dev
This commit is contained in:
@@ -118,6 +118,11 @@ public class AccessibilityDialogUtils {
|
||||
* launch tutorial.
|
||||
*/
|
||||
int LAUNCH_ACCESSIBILITY_TUTORIAL = 1008;
|
||||
|
||||
/**
|
||||
* OPEN: Settings > Accessibility > Display size and text > Click 'Reset settings' button.
|
||||
*/
|
||||
int DIALOG_RESET_SETTINGS = 1009;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,10 +18,15 @@ package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.TextReadingResetController.ResetStateListener;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -88,16 +93,54 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
new HighTextContrastPreferenceController(context, HIGHT_TEXT_CONTRAST_KEY);
|
||||
controllers.add(highTextContrastController);
|
||||
|
||||
final List<ResetStateListener> resetStateListeners =
|
||||
controllers.stream().filter(c -> c instanceof ResetStateListener).map(
|
||||
c -> (ResetStateListener) c).collect(Collectors.toList());
|
||||
final TextReadingResetController resetController =
|
||||
new TextReadingResetController(context, RESET_KEY, resetStateListeners);
|
||||
new TextReadingResetController(context, RESET_KEY,
|
||||
v -> showDialog(DialogEnums.DIALOG_RESET_SETTINGS));
|
||||
controllers.add(resetController);
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(int dialogId) {
|
||||
if (dialogId == DialogEnums.DIALOG_RESET_SETTINGS) {
|
||||
return new AlertDialog.Builder(getPrefContext())
|
||||
.setTitle(R.string.accessibility_text_reading_confirm_dialog_title)
|
||||
.setMessage(R.string.accessibility_text_reading_confirm_dialog_message)
|
||||
.setPositiveButton(
|
||||
R.string.accessibility_text_reading_confirm_dialog_reset_button,
|
||||
this::onPositiveButtonClicked)
|
||||
.setNegativeButton(R.string.cancel, /* listener= */ null)
|
||||
.create();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
if (dialogId == DialogEnums.DIALOG_RESET_SETTINGS) {
|
||||
return SettingsEnums.DIALOG_RESET_SETTINGS;
|
||||
}
|
||||
|
||||
return super.getDialogMetricsCategory(dialogId);
|
||||
}
|
||||
|
||||
private void onPositiveButtonClicked(DialogInterface dialog, int which) {
|
||||
// To avoid showing the dialog again, probably the onDetach() of SettingsDialogFragment
|
||||
// was interrupted by unexpectedly recreating the activity.
|
||||
removeDialog(DialogEnums.DIALOG_RESET_SETTINGS);
|
||||
|
||||
getResetStateListeners().forEach(ResetStateListener::resetState);
|
||||
}
|
||||
|
||||
private List<ResetStateListener> getResetStateListeners() {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
getPreferenceControllers().forEach(controllers::addAll);
|
||||
return controllers.stream().filter(c -> c instanceof ResetStateListener).map(
|
||||
c -> (ResetStateListener) c).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.accessibility_text_reading_options);
|
||||
}
|
||||
|
@@ -19,25 +19,23 @@ package com.android.settings.accessibility;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The controller of the reset button in the text and reading options page.
|
||||
*/
|
||||
class TextReadingResetController extends BasePreferenceController {
|
||||
private final List<ResetStateListener> mListeners;
|
||||
private final View.OnClickListener mOnResetClickListener;
|
||||
|
||||
TextReadingResetController(Context context, String preferenceKey,
|
||||
@NonNull List<ResetStateListener> listeners) {
|
||||
@Nullable View.OnClickListener listener) {
|
||||
super(context, preferenceKey);
|
||||
mListeners = listeners;
|
||||
mOnResetClickListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,7 +49,11 @@ class TextReadingResetController extends BasePreferenceController {
|
||||
|
||||
final LayoutPreference layoutPreference = screen.findPreference(getPreferenceKey());
|
||||
final View view = layoutPreference.findViewById(R.id.reset_button);
|
||||
view.setOnClickListener(v -> mListeners.forEach(ResetStateListener::resetState));
|
||||
view.setOnClickListener(v -> {
|
||||
if (mOnResetClickListener != null) {
|
||||
mOnResetClickListener.onClick(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user