[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -57,6 +57,7 @@ import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.utils.CustomDialogHelper;
|
||||
import com.android.settingslib.utils.StringUtil;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
@@ -69,6 +70,8 @@ import java.util.Locale;
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class LocaleListEditor extends RestrictedSettingsFragment implements View.OnTouchListener {
|
||||
public static final int REQUEST_LOCALE_PICKER = 0;
|
||||
|
||||
protected static final String INTENT_LOCALE_KEY = "localeInfo";
|
||||
protected static final String EXTRA_SYSTEM_LOCALE_DIALOG_TYPE = "system_locale_dialog_type";
|
||||
protected static final String EXTRA_RESULT_LOCALE = "result_locale";
|
||||
@@ -85,12 +88,10 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
private static final String TAG_DIALOG_NOT_AVAILABLE = "dialog_not_available_locale";
|
||||
private static final String TAG_DIALOG_ADD_SYSTEM_LOCALE = "dialog_add_system_locale";
|
||||
private static final int MENU_ID_REMOVE = Menu.FIRST + 1;
|
||||
private static final int REQUEST_LOCALE_PICKER = 0;
|
||||
|
||||
private LocaleDragAndDropAdapter mAdapter;
|
||||
private Menu mMenu;
|
||||
private View mAddLanguage;
|
||||
private AlertDialog mSuggestionDialog = null;
|
||||
private boolean mRemoveMode;
|
||||
private boolean mShowingRemoveDialog;
|
||||
private boolean mLocaleAdditionMode = false;
|
||||
@@ -330,7 +331,6 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
private void showDialogForAddedLocale() {
|
||||
Log.d(TAG, "show confirmation dialog");
|
||||
Intent intent = this.getIntent();
|
||||
String dialogType = intent.getStringExtra(EXTRA_SYSTEM_LOCALE_DIALOG_TYPE);
|
||||
String appLocaleTag = intent.getStringExtra(EXTRA_APP_LOCALE);
|
||||
|
||||
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(
|
||||
@@ -344,17 +344,6 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
localeDialogFragment.show(mFragmentManager, TAG_DIALOG_ADD_SYSTEM_LOCALE);
|
||||
}
|
||||
|
||||
private void customizeLayout(AlertDialog.Builder dialogBuilder, String language) {
|
||||
View dialogView = getLocaleDialogView();
|
||||
dialogBuilder.setView(dialogView);
|
||||
TextView title = dialogView.findViewById(R.id.dialog_title);
|
||||
title.setText(
|
||||
String.format(getContext().getResources().getString(
|
||||
R.string.title_system_locale_addition), language));
|
||||
TextView message = dialogView.findViewById(R.id.dialog_msg);
|
||||
message.setText(R.string.desc_system_locale_addition);
|
||||
}
|
||||
|
||||
protected View getLocaleDialogView() {
|
||||
LayoutInflater inflater = this.getLayoutInflater();
|
||||
return inflater.inflate(R.layout.locale_dialog, null);
|
||||
@@ -374,25 +363,33 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
return;
|
||||
}
|
||||
|
||||
int messagePaddingLeftRight = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_message_padding_left_right);
|
||||
int messagePaddingBottom = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.locale_picker_dialog_message_padding_bottom);
|
||||
// All locales selected, warning dialog, can't remove them all
|
||||
if (checkedCount == mAdapter.getItemCount()) {
|
||||
mShowingRemoveDialog = true;
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.dlg_remove_locales_error_title)
|
||||
.setMessage(R.string.dlg_remove_locales_error_message)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
mShowingRemoveDialog = false;
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
|
||||
CustomDialogHelper dialogHelper = createRegionDialog(getContext(),
|
||||
getContext().getString(R.string.dlg_remove_locales_error_title));
|
||||
dialogHelper.setMessage(R.string.dlg_remove_locales_error_message)
|
||||
.setMessagePadding(messagePaddingLeftRight, 0, messagePaddingLeftRight,
|
||||
messagePaddingBottom)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
view -> {
|
||||
dialogHelper.getDialog().dismiss();
|
||||
})
|
||||
.setBackButton(R.string.cancel, view -> {
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
dialogHelper.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
mShowingRemoveDialog = false;
|
||||
}
|
||||
});
|
||||
dialogHelper.getDialog().show();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -400,54 +397,63 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
R.string.dlg_remove_locales_title);
|
||||
mShowingRemoveDialog = true;
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
CustomDialogHelper dialogHelper = createRegionDialog(getContext(), title);
|
||||
if (mAdapter.isFirstLocaleChecked()) {
|
||||
builder.setMessage(R.string.dlg_remove_locales_message);
|
||||
dialogHelper.setMessage(R.string.dlg_remove_locales_message)
|
||||
.setMessagePadding(messagePaddingLeftRight, 0, messagePaddingLeftRight,
|
||||
messagePaddingBottom);
|
||||
}
|
||||
|
||||
builder.setTitle(title)
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setRemoveMode(false);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.locale_remove_menu,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// This is a sensitive area to change.
|
||||
// removeChecked() triggers a system update and "kills" the frame.
|
||||
// This means that saveState + restoreState are called before
|
||||
// setRemoveMode is called.
|
||||
// So we want that mRemoveMode and dialog status have the right
|
||||
// values
|
||||
// before that save.
|
||||
// We can't just call setRemoveMode(false) before calling
|
||||
// removeCheched
|
||||
// because that unchecks all items and removeChecked would have
|
||||
// nothing
|
||||
// to remove.
|
||||
mRemoveMode = false;
|
||||
mShowingRemoveDialog = false;
|
||||
LocaleStore.LocaleInfo firstLocale =
|
||||
mAdapter.getFeedItemList().get(0);
|
||||
mAdapter.removeChecked();
|
||||
boolean isFirstRemoved =
|
||||
firstLocale != mAdapter.getFeedItemList().get(0);
|
||||
showConfirmDialog(isFirstRemoved, isFirstRemoved ? firstLocale
|
||||
: mAdapter.getFeedItemList().get(0));
|
||||
setRemoveMode(false);
|
||||
}
|
||||
dialogHelper.setPositiveButton(R.string.locale_remove_menu,
|
||||
view -> {
|
||||
// This is a sensitive area to change.
|
||||
// removeChecked() triggers a system update and "kills" the frame.
|
||||
// This means that saveState + restoreState are called before
|
||||
// setRemoveMode is called.
|
||||
// So we want that mRemoveMode and dialog status have the right
|
||||
// values
|
||||
// before that save.
|
||||
// We can't just call setRemoveMode(false) before calling
|
||||
// removeCheched
|
||||
// because that unchecks all items and removeChecked would have
|
||||
// nothing
|
||||
// to remove.
|
||||
mRemoveMode = false;
|
||||
mShowingRemoveDialog = false;
|
||||
LocaleStore.LocaleInfo firstLocale =
|
||||
mAdapter.getFeedItemList().get(0);
|
||||
mAdapter.removeChecked();
|
||||
boolean isFirstRemoved =
|
||||
firstLocale != mAdapter.getFeedItemList().get(0);
|
||||
showConfirmDialog(isFirstRemoved, isFirstRemoved ? firstLocale
|
||||
: mAdapter.getFeedItemList().get(0));
|
||||
setRemoveMode(false);
|
||||
dialogHelper.getDialog().dismiss();
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
mShowingRemoveDialog = false;
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
.setBackButton(R.string.cancel, view -> {
|
||||
setRemoveMode(false);
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
dialogHelper.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
mShowingRemoveDialog = false;
|
||||
}
|
||||
});
|
||||
dialogHelper.getDialog().show();
|
||||
}
|
||||
|
||||
private CustomDialogHelper createRegionDialog(Context context, String title) {
|
||||
CustomDialogHelper dialogHelper = new CustomDialogHelper(context);
|
||||
dialogHelper.setIcon(context.getDrawable(R.drawable.ic_settings_language_32dp))
|
||||
.setTitle(title)
|
||||
.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));
|
||||
return dialogHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -483,7 +489,6 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
list.setAdapter(mAdapter);
|
||||
list.setOnTouchListener(this);
|
||||
list.requestFocus();
|
||||
|
||||
mAddLanguage = layout.findViewById(R.id.add_language);
|
||||
mAddLanguage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user