Merge "[Settings] Apply new style to dialog" into main
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp"
|
||||
android:height="24dp" android:viewportWidth="960" android:viewportHeight="960"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path android:fillColor="@android:color/white"
|
||||
android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,473 799.5,465.5Q799,458 799,453Q794,482 772,501Q750,520 720,520L640,520Q607,520 583.5,496.5Q560,473 560,440L560,400L400,400L400,320Q400,287 423.5,263.5Q447,240 480,240L520,240L520,240Q520,217 532.5,199.5Q545,182 563,171Q543,166 522.5,163Q502,160 480,160Q346,160 253,253Q160,346 160,480Q160,480 160,480Q160,480 160,480L360,480Q426,480 473,527Q520,574 520,640L520,680L400,680L400,790Q420,795 439.5,797.5Q459,800 480,800Z"/>
|
||||
</vector>
|
25
res/drawable/ic_settings_language_32dp.xml
Normal file
25
res/drawable/ic_settings_language_32dp.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright (C) 2025 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="32dp"
|
||||
android:height="32dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M480,880Q396.67,880 323.67,848.5Q250.67,817 196.5,762.83Q142.33,708.67 111.17,635.33Q80,562 80,478.67Q80,395 111.17,322.5Q142.33,250 196.5,195.83Q250.67,141.67 323.67,110.83Q396.67,80 480,80Q563.67,80 636.5,110.83Q709.33,141.67 763.5,195.83Q817.67,250 848.83,322.5Q880,395 880,478.67Q880,562 848.83,635.33Q817.67,708.67 763.5,762.83Q709.33,817 636.5,848.5Q563.67,880 480,880ZM480,814Q512,778 534,734Q556,690 570,632.67L390.67,632.67Q404,687.33 426,732.33Q448,777.33 480,814ZM388.67,800.67Q366,764.33 349.5,723.17Q333,682 322,632.67L182.67,632.67Q217.67,696.67 265.5,736Q313.33,775.33 388.67,800.67ZM572,800Q638.67,778.67 691.5,735.67Q744.33,692.67 777.33,632.67L638.67,632.67Q627,681.33 610.83,722.5Q594.67,763.67 572,800ZM158,566L309.33,566Q306.33,541.33 305.5,520.5Q304.67,499.67 304.67,478.67Q304.67,455 305.83,435.5Q307,416 310,393.33L158,393.33Q151.67,416 149.17,435.17Q146.67,454.33 146.67,478.67Q146.67,503 149.17,523.17Q151.67,543.33 158,566ZM377.33,566L583.33,566Q587,538.67 588.17,519.17Q589.33,499.67 589.33,478.67Q589.33,458.33 588.17,439.5Q587,420.67 583.33,393.33L377.33,393.33Q373.67,420.67 372.5,439.5Q371.33,458.33 371.33,478.67Q371.33,499.67 372.5,519.17Q373.67,538.67 377.33,566ZM650,566L802,566Q808.33,543.33 810.83,523.17Q813.33,503 813.33,478.67Q813.33,454.33 810.83,435.17Q808.33,416 802,393.33L650.67,393.33Q653.67,423.33 654.83,442.17Q656,461 656,478.67Q656,500.33 654.5,519.83Q653,539.33 650,566ZM638,326.67L777.33,326.67Q745.67,264 692.83,221Q640,178 571.33,159.33Q594,195 610.17,235.5Q626.33,276 638,326.67ZM390.67,326.67L570.67,326.67Q559.33,276.67 535.67,230.67Q512,184.67 480,147.33Q450,177.33 429,219.67Q408,262 390.67,326.67ZM182.67,326.67L322.67,326.67Q333,278 348.83,237.83Q364.67,197.67 388,160Q319.33,178.67 267.5,221Q215.67,263.33 182.67,326.67Z"/>
|
||||
</vector>
|
@@ -555,4 +555,10 @@
|
||||
<dimen name="display_block_padding">5dp</dimen>
|
||||
<dimen name="display_block_highlight_width">2dp</dimen>
|
||||
<dimen name="display_block_corner_radius">10dp</dimen>
|
||||
|
||||
<!-- Locale Picker -->
|
||||
<dimen name="locale_picker_dialog_icon_padding">10dp</dimen>
|
||||
<dimen name="locale_picker_dialog_title_padding">16dp</dimen>
|
||||
<dimen name="locale_picker_dialog_message_padding_left_right">24dp</dimen>
|
||||
<dimen name="locale_picker_dialog_message_padding_bottom">32dp</dimen>
|
||||
</resources>
|
||||
|
@@ -502,7 +502,7 @@
|
||||
<!-- The text of the confirmation dialog showing the system locale will be changed. [CHAR LIMIT=NONE]-->
|
||||
<string name="desc_notice_device_locale_settings_change">Your device settings and regional preferences will change.</string>
|
||||
|
||||
<!-- A dialog button for confirmmation of system locale change. [CHAR LIMIT=25]-->
|
||||
<!-- A dialog button for confirmation of system locale change. [CHAR LIMIT=25]-->
|
||||
<string name="button_label_confirmation_of_system_locale_change">Change</string>
|
||||
|
||||
<!-- Title for saying this selected locale is unavailable to use. [CHAR LIMIT=50]-->
|
||||
@@ -530,10 +530,11 @@
|
||||
<!-- Category for more language settings. [CHAR LIMIT=NONE]-->
|
||||
<string name="more_language_settings_category">More language settings</string>
|
||||
<!-- Title for asking to change system locale region or not. [CHAR LIMIT=50]-->
|
||||
<string name="title_change_system_locale_region">Change region to %s ?</string>
|
||||
<string name="title_change_system_locale_region">Change region to <xliff:g id="system_language_region" example="Canada">%1$s</xliff:g> ?</string>
|
||||
<!-- Message for asking to change system locale region or not. [CHAR LIMIT=50]-->
|
||||
<string name="body_change_system_locale_region">Your device will keep %s as a system language</string>
|
||||
<string name="top_intro_numbering_system_title">The digits used will be dependent on the numbering system</string>
|
||||
<string name="body_change_system_locale_region">Your device will keep <xliff:g id="system_language" example="English">%1$s</xliff:g> as a system language</string>
|
||||
<!-- Description for the numbering system language. [CHAR LIMIT=NONE]-->
|
||||
<string name="top_intro_numbering_system_title">Most apps will use your regional preferences</string>
|
||||
|
||||
<!-- Regional Preferences begin -->
|
||||
<!-- The title of the menu entry of regional preferences. [CHAR LIMIT=50] -->
|
||||
|
@@ -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(
|
||||
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) {
|
||||
}
|
||||
|
||||
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();
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
.setBackButton(R.string.cancel, view -> {
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
dialogHelper.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
mShowingRemoveDialog = false;
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
});
|
||||
dialogHelper.getDialog().show();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -400,22 +397,15 @@ 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) {
|
||||
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
|
||||
@@ -438,16 +428,32 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
showConfirmDialog(isFirstRemoved, isFirstRemoved ? firstLocale
|
||||
: mAdapter.getFeedItemList().get(0));
|
||||
setRemoveMode(false);
|
||||
}
|
||||
dialogHelper.getDialog().dismiss();
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
.setBackButton(R.string.cancel, view -> {
|
||||
setRemoveMode(false);
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
dialogHelper.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
mShowingRemoveDialog = false;
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
});
|
||||
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
|
||||
|
@@ -26,10 +26,10 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.window.OnBackInvokedDispatcher;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
@@ -92,17 +92,17 @@ public class LocaleDialogFragmentTest {
|
||||
@Test
|
||||
public void onBackInvoked_dialogIsStillDisplaying() {
|
||||
mDialogFragment.setBackDispatcher(mOnBackInvokedDispatcher);
|
||||
AlertDialog alertDialog = (AlertDialog) mDialogFragment.onCreateDialog(null);
|
||||
alertDialog.show();
|
||||
assertThat(alertDialog).isNotNull();
|
||||
assertThat(alertDialog.isShowing()).isTrue();
|
||||
Dialog dialog = mDialogFragment.onCreateDialog(null);
|
||||
dialog.show();
|
||||
assertThat(dialog).isNotNull();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
|
||||
mOnBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
eq(OnBackInvokedDispatcher.PRIORITY_DEFAULT), any());
|
||||
|
||||
mDialogFragment.getBackInvokedCallback().onBackInvoked();
|
||||
|
||||
assertThat(alertDialog.isShowing()).isTrue();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.IActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -53,7 +54,6 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
@@ -78,6 +78,7 @@ import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowDialog;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@@ -87,6 +88,7 @@ import java.util.Locale;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowDialog.class,
|
||||
ShadowAlertDialogCompat.class,
|
||||
ShadowActivityManager.class,
|
||||
com.android.settings.testutils.shadow.ShadowFragment.class,
|
||||
@@ -178,7 +180,7 @@ public class LocaleListEditorTest {
|
||||
ReflectionHelpers.setField(mLocaleListEditor, "mRemoveMode", false);
|
||||
ReflectionHelpers.setField(mLocaleListEditor, "mShowingRemoveDialog", false);
|
||||
ReflectionHelpers.setField(mLocaleListEditor, "mLocaleAdditionMode", false);
|
||||
ShadowAlertDialogCompat.reset();
|
||||
ShadowDialog.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,14 +211,13 @@ public class LocaleListEditorTest {
|
||||
//launch dialog
|
||||
mLocaleListEditor.showRemoveLocaleWarningDialog();
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
final Dialog dialog = ShadowDialog.getLatestDialog();
|
||||
|
||||
assertThat(dialog).isNotNull();
|
||||
|
||||
final ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||
|
||||
assertThat(shadowDialog.getTitle()).isEqualTo(
|
||||
mContext.getString(R.string.dlg_remove_locales_error_title));
|
||||
TextView dialogTitle = dialog.findViewById(R.id.dialog_with_icon_title);
|
||||
assertThat(dialogTitle.getText().toString())
|
||||
.isEqualTo(mContext.getString(R.string.dlg_remove_locales_error_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -231,14 +232,13 @@ public class LocaleListEditorTest {
|
||||
//launch dialog
|
||||
mLocaleListEditor.showRemoveLocaleWarningDialog();
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
final Dialog dialog = ShadowDialog.getLatestDialog();
|
||||
|
||||
assertThat(dialog).isNotNull();
|
||||
|
||||
final ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||
|
||||
assertThat(shadowDialog.getMessage()).isEqualTo(
|
||||
mContext.getString(R.string.dlg_remove_locales_message));
|
||||
TextView dialogMessage = dialog.findViewById(R.id.dialog_with_icon_message);
|
||||
assertThat(dialogMessage.getText().toString())
|
||||
.isEqualTo(mContext.getString(R.string.dlg_remove_locales_message));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -253,13 +253,12 @@ public class LocaleListEditorTest {
|
||||
//launch dialog
|
||||
mLocaleListEditor.showRemoveLocaleWarningDialog();
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
final Dialog dialog = ShadowDialog.getLatestDialog();
|
||||
|
||||
assertThat(dialog).isNotNull();
|
||||
|
||||
final ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||
|
||||
assertThat(shadowDialog.getMessage()).isNull();
|
||||
TextView dialogMessage = dialog.findViewById(R.id.dialog_with_icon_message);
|
||||
assertThat(dialogMessage.getText().isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -280,12 +279,12 @@ public class LocaleListEditorTest {
|
||||
//launch the first dialog
|
||||
mLocaleListEditor.showRemoveLocaleWarningDialog();
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
final Dialog dialog = ShadowDialog.getLatestDialog();
|
||||
|
||||
assertThat(dialog).isNotNull();
|
||||
|
||||
// click the remove button
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
|
||||
dialog.findViewById(R.id.button_ok).performClick();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(dialog.isShowing()).isFalse();
|
||||
|
@@ -35,6 +35,7 @@ import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
@@ -82,11 +83,9 @@ public class LocaleDialogFragmentTest {
|
||||
LocaleDialogFragment.LocaleDialogController.DialogContent dialogContent =
|
||||
controller.getDialogContent();
|
||||
|
||||
assertEquals(ResourcesUtils.getResourcesString(
|
||||
mContext, "button_label_confirmation_of_system_locale_change"),
|
||||
assertEquals(R.string.button_label_confirmation_of_system_locale_change,
|
||||
dialogContent.mPositiveButton);
|
||||
assertEquals(ResourcesUtils.getResourcesString(mContext, "cancel"),
|
||||
dialogContent.mNegativeButton);
|
||||
assertEquals(R.string.cancel, dialogContent.mNegativeButton);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,9 +98,8 @@ public class LocaleDialogFragmentTest {
|
||||
LocaleDialogFragment.LocaleDialogController.DialogContent dialogContent =
|
||||
controller.getDialogContent();
|
||||
|
||||
assertEquals(ResourcesUtils.getResourcesString(mContext, "okay"),
|
||||
dialogContent.mPositiveButton);
|
||||
assertTrue(dialogContent.mNegativeButton.isEmpty());
|
||||
assertEquals(R.string.okay, dialogContent.mPositiveButton);
|
||||
assertTrue(dialogContent.mNegativeButton == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user