Merge "Fix checkbox in magnification mode dialog does not have ripple effect" am: f164cf8539

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/12369338

Change-Id: Icc0a14fe60c49fe621d0e48f61878ad7a5c87b2e
This commit is contained in:
Jason Hsu
2020-08-19 05:15:44 +00:00
committed by Automerger Merge Worker

View File

@@ -23,6 +23,7 @@ import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@@ -149,13 +150,33 @@ public class MagnificationSettingsFragment extends DashboardFragment {
private void initializeDialogCheckBox(AlertDialog dialog) { private void initializeDialogCheckBox(AlertDialog dialog) {
final View dialogFullScreenView = dialog.findViewById(R.id.magnify_full_screen); final View dialogFullScreenView = dialog.findViewById(R.id.magnify_full_screen);
final View dialogFullScreenTextArea = dialogFullScreenView.findViewById(R.id.container);
mMagnifyFullScreenCheckBox = dialogFullScreenView.findViewById(R.id.checkbox); mMagnifyFullScreenCheckBox = dialogFullScreenView.findViewById(R.id.checkbox);
final View dialogWidowView = dialog.findViewById(R.id.magnify_window_screen); final View dialogWidowView = dialog.findViewById(R.id.magnify_window_screen);
final View dialogWindowTextArea = dialogWidowView.findViewById(R.id.container);
mMagnifyWindowCheckBox = dialogWidowView.findViewById(R.id.checkbox); mMagnifyWindowCheckBox = dialogWidowView.findViewById(R.id.checkbox);
setTextAreasClickListener(dialogFullScreenTextArea, mMagnifyFullScreenCheckBox,
dialogWindowTextArea, mMagnifyWindowCheckBox);
updateAlertDialogCheckState(); updateAlertDialogCheckState();
updateAlertDialogEnableState(); updateAlertDialogEnableState(dialogFullScreenTextArea, dialogWindowTextArea);
}
private void setTextAreasClickListener(View fullScreenTextArea, CheckBox fullScreenCheckBox,
View windowTextArea, CheckBox windowCheckBox) {
fullScreenTextArea.setOnClickListener(v -> {
fullScreenCheckBox.toggle();
updateCapabilities(false);
updateAlertDialogEnableState(fullScreenTextArea, windowTextArea);
});
windowTextArea.setOnClickListener(v -> {
windowCheckBox.toggle();
updateCapabilities(false);
updateAlertDialogEnableState(fullScreenTextArea, windowTextArea);
});
} }
private void updateAlertDialogCheckState() { private void updateAlertDialogCheckState() {
@@ -168,30 +189,34 @@ public class MagnificationSettingsFragment extends DashboardFragment {
private void updateCheckStatus(CheckBox checkBox, int mode) { private void updateCheckStatus(CheckBox checkBox, int mode) {
checkBox.setChecked((mode & mCapabilities) != 0); checkBox.setChecked((mode & mCapabilities) != 0);
checkBox.setOnClickListener(v -> {
updateCapabilities(false);
updateAlertDialogEnableState();
});
} }
private void updateAlertDialogEnableState() { private void updateAlertDialogEnableState(View fullScreenTextArea, View windowTextArea) {
if (mCapabilities != Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL) { switch (mCapabilities) {
disableEnabledMagnificationModePreference(); case Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN:
} else { setViewAndChildrenEnabled(fullScreenTextArea, false);
enableAllPreference(); break;
case Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW:
setViewAndChildrenEnabled(windowTextArea, false);
break;
case Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL:
setViewAndChildrenEnabled(fullScreenTextArea, true);
setViewAndChildrenEnabled(windowTextArea, true);
break;
default:
throw new IllegalArgumentException(
"Unsupported ACCESSIBILITY_MAGNIFICATION_CAPABILITY " + mCapabilities);
} }
} }
private void enableAllPreference() { private void setViewAndChildrenEnabled(View view, boolean enabled) {
mMagnifyFullScreenCheckBox.setEnabled(true); view.setEnabled(enabled);
mMagnifyWindowCheckBox.setEnabled(true); if (view instanceof ViewGroup) {
} final ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
private void disableEnabledMagnificationModePreference() { View child = viewGroup.getChildAt(i);
if (!mMagnifyFullScreenCheckBox.isChecked()) { setViewAndChildrenEnabled(child, enabled);
mMagnifyWindowCheckBox.setEnabled(false); }
} else if (!mMagnifyWindowCheckBox.isChecked()) {
mMagnifyFullScreenCheckBox.setEnabled(false);
} }
} }