Improve dialog popup
1. Disable dialog when the sys language doesn't change
2. Associate region with system locale
Bug: 402600866
Test: atest LocaleListEditTest
Flag: EXEMPT bugfix
Change-Id: I2c7ddbf89b6caa02a35e247ebe97086f5880adee
diff --git a/src/com/android/settings/localepicker/LocaleListEditor.java b/src/com/android/settings/localepicker/LocaleListEditor.java
index 2f8d203..87deea1 100644
--- a/src/com/android/settings/localepicker/LocaleListEditor.java
+++ b/src/com/android/settings/localepicker/LocaleListEditor.java
@@ -529,7 +529,11 @@
@Nullable Locale defaultLocaleBeforeRemoval) {
Locale currentSystemLocale = LocalePicker.getLocales().get(0);
if (!localeInfo.getLocale().equals(currentSystemLocale)) {
- displayDialogFragment(localeInfo, true);
+ if (Locale.getDefault().equals(localeInfo.getLocale())) {
+ mAdapter.doTheUpdate();
+ } else {
+ displayDialogFragment(localeInfo, true);
+ }
} else {
if (!localeInfo.isTranslated()) {
if (defaultLocaleBeforeRemoval == null) {
diff --git a/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java b/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java
index fc12d1b..5768421 100644
--- a/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java
+++ b/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java
@@ -18,7 +18,6 @@
import android.content.Context;
import android.os.Bundle;
-import android.os.LocaleList;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -92,7 +91,7 @@
? getSuggestedLocaleList()
: getSupportedLocaleList();
if (getPreferenceCategoryKey().contains(KEY_SUGGESTED)) {
- Locale systemLocale = LocaleList.getDefault().get(0);
+ Locale systemLocale = Locale.getDefault();
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(systemLocale);
result.add(localeInfo);
}
@@ -106,7 +105,7 @@
mPreferenceCategory.addPreference(pref);
pref.setTitle(locale.getFullCountryNameNative());
pref.setKey(locale.toString());
- if (locale.getLocale().equals(LocaleList.getDefault().get(0))) {
+ if (locale.getLocale().equals(Locale.getDefault())) {
pref.setChecked(true);
} else {
pref.setChecked(false);
@@ -154,7 +153,7 @@
private List<LocaleStore.LocaleInfo> getSortedLocaleList(
List<LocaleStore.LocaleInfo> localeInfos) {
- final Locale sortingLocale = LocaleList.getDefault().get(0);
+ final Locale sortingLocale = Locale.getDefault();
final LocaleHelper.LocaleInfoComparator comp =
new LocaleHelper.LocaleInfoComparator(sortingLocale, true);
Collections.sort(localeInfos, comp);
@@ -162,7 +161,7 @@
}
private void switchRegion(LocaleStore.LocaleInfo localeInfo) {
- if (localeInfo.getLocale().equals(LocaleList.getDefault().get(0))) {
+ if (localeInfo.getLocale().equals(Locale.getDefault())) {
return;
}
diff --git a/src/com/android/settings/regionalpreferences/RegionPickerFragment.java b/src/com/android/settings/regionalpreferences/RegionPickerFragment.java
index c064565..cf4d9b9 100644
--- a/src/com/android/settings/regionalpreferences/RegionPickerFragment.java
+++ b/src/com/android/settings/regionalpreferences/RegionPickerFragment.java
@@ -19,7 +19,6 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
-import android.os.LocaleList;
import android.provider.Settings;
import androidx.annotation.NonNull;
@@ -84,7 +83,7 @@
private List<AbstractPreferenceController> buildPreferenceControllers(
@NonNull Context context) {
- Locale parentLocale = LocaleStore.getLocaleInfo(LocaleList.getDefault().get(0)).getParent();
+ Locale parentLocale = LocaleStore.getLocaleInfo(Locale.getDefault()).getParent();
LocaleStore.LocaleInfo parentLocaleInfo = LocaleStore.getLocaleInfo(parentLocale);
SystemRegionSuggestedListPreferenceController mSuggestedListPreferenceController =
new SystemRegionSuggestedListPreferenceController(
diff --git a/src/com/android/settings/regionalpreferences/RegionPreferenceController.java b/src/com/android/settings/regionalpreferences/RegionPreferenceController.java
index 345bd75..a9ce120 100644
--- a/src/com/android/settings/regionalpreferences/RegionPreferenceController.java
+++ b/src/com/android/settings/regionalpreferences/RegionPreferenceController.java
@@ -17,7 +17,6 @@
package com.android.settings.regionalpreferences;
import android.content.Context;
-import android.os.LocaleList;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
@@ -27,6 +26,8 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;
+import java.util.Locale;
+
/** A controller for the entry of region picker page */
public class RegionPreferenceController extends BasePreferenceController {
@@ -39,7 +40,7 @@
super.displayPreference(screen);
Preference preference = screen.findPreference(getPreferenceKey());
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(
- LocaleList.getDefault().get(0));
+ Locale.getDefault());
preference.setSummary(localeInfo.getFullCountryNameNative());
}
diff --git a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
index 22d39e3..5f5b8f6 100644
--- a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
@@ -275,6 +275,7 @@
public void showConfirmDialog_systemLocaleSelected_shouldShowLocaleChangeDialog()
throws Exception {
//pre-condition
+ Locale.setDefault(Locale.forLanguageTag("zh-TW"));
setUpLocaleConditions(true);
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));
@@ -379,6 +380,7 @@
@Test
public void onTouch_dragDifferentLocaleToTop_showConfirmDialog() throws Exception {
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
+ Locale.setDefault(Locale.forLanguageTag("zh-TW"));
setUpLocaleConditions(true);
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));