[Settings] Apply new style to dialog
Bug: 394542699 Test: manual Test: atest SettingsRoboTests:com.android.settings.localepicker.LocaleListEditorTest Flag: EXEMPT refactor Change-Id: Idfed52722d1113e432742342fd8a56958e84406e
This commit is contained in:
@@ -29,19 +29,20 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.window.OnBackInvokedCallback;
|
||||
import android.window.OnBackInvokedDispatcher;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.utils.CustomDialogHelper;
|
||||
|
||||
/**
|
||||
* Create a dialog for system locale events.
|
||||
@@ -58,7 +59,6 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
|
||||
static final String ARG_SHOW_DIALOG = "arg_show_dialog";
|
||||
|
||||
private boolean mShouldKeepDialog;
|
||||
private AlertDialog mAlertDialog;
|
||||
private OnBackInvokedDispatcher mBackDispatcher;
|
||||
|
||||
private OnBackInvokedCallback mBackCallback = () -> {
|
||||
@@ -106,45 +106,53 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
|
||||
LocaleListEditor parentFragment = (LocaleListEditor) getParentFragment();
|
||||
LocaleDialogController controller = getLocaleDialogController(getContext(), this,
|
||||
parentFragment);
|
||||
LocaleDialogController.DialogContent dialogContent = controller.getDialogContent();
|
||||
ViewGroup viewGroup = (ViewGroup) LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.locale_dialog, null);
|
||||
setDialogTitle(viewGroup, dialogContent.mTitle);
|
||||
setDialogMessage(viewGroup, dialogContent.mMessage);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
|
||||
.setView(viewGroup);
|
||||
if (!dialogContent.mPositiveButton.isEmpty()) {
|
||||
builder.setPositiveButton(dialogContent.mPositiveButton, controller);
|
||||
}
|
||||
if (!dialogContent.mNegativeButton.isEmpty()) {
|
||||
builder.setNegativeButton(dialogContent.mNegativeButton, controller);
|
||||
}
|
||||
mAlertDialog = builder.create();
|
||||
getOnBackInvokedDispatcher().registerOnBackInvokedCallback(PRIORITY_DEFAULT, mBackCallback);
|
||||
mAlertDialog.setCanceledOnTouchOutside(false);
|
||||
mAlertDialog.setOnDismissListener(dialogInterface -> {
|
||||
mAlertDialog.getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(
|
||||
mBackCallback);
|
||||
Dialog dialog = createDialog(getContext(), controller);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
getOnBackInvokedDispatcher(dialog).registerOnBackInvokedCallback(PRIORITY_DEFAULT,
|
||||
mBackCallback);
|
||||
dialog.setOnDismissListener(dialogInterface -> {
|
||||
getOnBackInvokedDispatcher(dialog).unregisterOnBackInvokedCallback(
|
||||
mBackCallback);
|
||||
});
|
||||
|
||||
return mAlertDialog;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private static void setDialogTitle(View root, String content) {
|
||||
TextView titleView = root.findViewById(R.id.dialog_title);
|
||||
if (titleView == null) {
|
||||
return;
|
||||
private Dialog createDialog(Context context, LocaleDialogController controller) {
|
||||
CustomDialogHelper dialogHelper = new CustomDialogHelper(context);
|
||||
LocaleDialogController.DialogContent dialogContent = controller.getDialogContent();
|
||||
dialogHelper.setIcon(context.getDrawable(R.drawable.ic_settings_language_32dp))
|
||||
.setTitle(dialogContent.mTitle)
|
||||
.setMessage(dialogContent.mMessage)
|
||||
.setIconPadding(0,
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_icon_padding),
|
||||
0, 0)
|
||||
.setTitlePadding(0,
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_title_padding),
|
||||
0,
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_title_padding))
|
||||
.setMessagePadding(context.getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_message_padding_left_right), 0,
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_message_padding_left_right),
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_message_padding_bottom))
|
||||
.setPositiveButton(dialogContent.mPositiveButton,
|
||||
view -> {
|
||||
controller.onClick(dialogHelper.getDialog(),
|
||||
DialogInterface.BUTTON_POSITIVE);
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
if (dialogContent.mNegativeButton != 0) {
|
||||
dialogHelper.setBackButton(dialogContent.mNegativeButton, view -> {
|
||||
controller.onClick(dialogHelper.getDialog(), DialogInterface.BUTTON_NEGATIVE);
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
}
|
||||
titleView.setText(content);
|
||||
}
|
||||
|
||||
private static void setDialogMessage(View root, String content) {
|
||||
TextView textView = root.findViewById(R.id.dialog_msg);
|
||||
if (textView == null) {
|
||||
return;
|
||||
}
|
||||
textView.setText(content);
|
||||
return dialogHelper.getDialog();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -158,11 +166,11 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
|
||||
public @NonNull OnBackInvokedDispatcher getOnBackInvokedDispatcher(@NonNull Dialog dialog) {
|
||||
if (mBackDispatcher != null) {
|
||||
return mBackDispatcher;
|
||||
} else {
|
||||
return mAlertDialog.getOnBackInvokedDispatcher();
|
||||
return dialog.getOnBackInvokedDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,15 +231,15 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
|
||||
R.string.title_change_system_locale), mLocaleInfo.getFullNameNative());
|
||||
dialogContent.mMessage = mContext.getString(
|
||||
R.string.desc_notice_device_locale_settings_change);
|
||||
dialogContent.mPositiveButton = mContext.getString(
|
||||
R.string.button_label_confirmation_of_system_locale_change);
|
||||
dialogContent.mNegativeButton = mContext.getString(R.string.cancel);
|
||||
dialogContent.mPositiveButton =
|
||||
R.string.button_label_confirmation_of_system_locale_change;
|
||||
dialogContent.mNegativeButton = R.string.cancel;
|
||||
break;
|
||||
case DIALOG_NOT_AVAILABLE_LOCALE:
|
||||
dialogContent.mTitle = String.format(mContext.getString(
|
||||
R.string.title_unavailable_locale), mLocaleInfo.getFullNameNative());
|
||||
dialogContent.mMessage = mContext.getString(R.string.desc_unavailable_locale);
|
||||
dialogContent.mPositiveButton = mContext.getString(R.string.okay);
|
||||
dialogContent.mPositiveButton = R.string.okay;
|
||||
break;
|
||||
case DIALOG_ADD_SYSTEM_LOCALE:
|
||||
dialogContent.mTitle = String.format(mContext.getString(
|
||||
@@ -239,8 +247,8 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
|
||||
mLocaleInfo.getFullNameNative());
|
||||
dialogContent.mMessage = mContext.getString(
|
||||
R.string.desc_system_locale_addition);
|
||||
dialogContent.mPositiveButton = mContext.getString(R.string.add);
|
||||
dialogContent.mNegativeButton = mContext.getString(R.string.cancel);
|
||||
dialogContent.mPositiveButton = R.string.add;
|
||||
dialogContent.mNegativeButton = R.string.cancel;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -252,8 +260,8 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
|
||||
static class DialogContent {
|
||||
String mTitle = "";
|
||||
String mMessage = "";
|
||||
String mPositiveButton = "";
|
||||
String mNegativeButton = "";
|
||||
int mPositiveButton = 0;
|
||||
int mNegativeButton = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user