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
This commit is contained in:
Allen Su
2025-03-18 10:37:37 +00:00
parent 56397ab5b3
commit e8bd9e66b8
5 changed files with 15 additions and 10 deletions

View File

@@ -529,7 +529,11 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
@Nullable Locale defaultLocaleBeforeRemoval) { @Nullable Locale defaultLocaleBeforeRemoval) {
Locale currentSystemLocale = LocalePicker.getLocales().get(0); Locale currentSystemLocale = LocalePicker.getLocales().get(0);
if (!localeInfo.getLocale().equals(currentSystemLocale)) { if (!localeInfo.getLocale().equals(currentSystemLocale)) {
displayDialogFragment(localeInfo, true); if (Locale.getDefault().equals(localeInfo.getLocale())) {
mAdapter.doTheUpdate();
} else {
displayDialogFragment(localeInfo, true);
}
} else { } else {
if (!localeInfo.isTranslated()) { if (!localeInfo.isTranslated()) {
if (defaultLocaleBeforeRemoval == null) { if (defaultLocaleBeforeRemoval == null) {

View File

@@ -18,7 +18,6 @@ package com.android.settings.regionalpreferences;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.LocaleList;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@@ -92,7 +91,7 @@ public abstract class RegionPickerBaseListPreferenceController extends BasePrefe
? getSuggestedLocaleList() ? getSuggestedLocaleList()
: getSupportedLocaleList(); : getSupportedLocaleList();
if (getPreferenceCategoryKey().contains(KEY_SUGGESTED)) { if (getPreferenceCategoryKey().contains(KEY_SUGGESTED)) {
Locale systemLocale = LocaleList.getDefault().get(0); Locale systemLocale = Locale.getDefault();
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(systemLocale); LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(systemLocale);
result.add(localeInfo); result.add(localeInfo);
} }
@@ -106,7 +105,7 @@ public abstract class RegionPickerBaseListPreferenceController extends BasePrefe
mPreferenceCategory.addPreference(pref); mPreferenceCategory.addPreference(pref);
pref.setTitle(locale.getFullCountryNameNative()); pref.setTitle(locale.getFullCountryNameNative());
pref.setKey(locale.toString()); pref.setKey(locale.toString());
if (locale.getLocale().equals(LocaleList.getDefault().get(0))) { if (locale.getLocale().equals(Locale.getDefault())) {
pref.setChecked(true); pref.setChecked(true);
} else { } else {
pref.setChecked(false); pref.setChecked(false);
@@ -154,7 +153,7 @@ public abstract class RegionPickerBaseListPreferenceController extends BasePrefe
private List<LocaleStore.LocaleInfo> getSortedLocaleList( private List<LocaleStore.LocaleInfo> getSortedLocaleList(
List<LocaleStore.LocaleInfo> localeInfos) { List<LocaleStore.LocaleInfo> localeInfos) {
final Locale sortingLocale = LocaleList.getDefault().get(0); final Locale sortingLocale = Locale.getDefault();
final LocaleHelper.LocaleInfoComparator comp = final LocaleHelper.LocaleInfoComparator comp =
new LocaleHelper.LocaleInfoComparator(sortingLocale, true); new LocaleHelper.LocaleInfoComparator(sortingLocale, true);
Collections.sort(localeInfos, comp); Collections.sort(localeInfos, comp);
@@ -162,7 +161,7 @@ public abstract class RegionPickerBaseListPreferenceController extends BasePrefe
} }
private void switchRegion(LocaleStore.LocaleInfo localeInfo) { private void switchRegion(LocaleStore.LocaleInfo localeInfo) {
if (localeInfo.getLocale().equals(LocaleList.getDefault().get(0))) { if (localeInfo.getLocale().equals(Locale.getDefault())) {
return; return;
} }

View File

@@ -19,7 +19,6 @@ package com.android.settings.regionalpreferences;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.LocaleList;
import android.provider.Settings; import android.provider.Settings;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@@ -84,7 +83,7 @@ public class RegionPickerFragment extends DashboardFragment{
private List<AbstractPreferenceController> buildPreferenceControllers( private List<AbstractPreferenceController> buildPreferenceControllers(
@NonNull Context context) { @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); LocaleStore.LocaleInfo parentLocaleInfo = LocaleStore.getLocaleInfo(parentLocale);
SystemRegionSuggestedListPreferenceController mSuggestedListPreferenceController = SystemRegionSuggestedListPreferenceController mSuggestedListPreferenceController =
new SystemRegionSuggestedListPreferenceController( new SystemRegionSuggestedListPreferenceController(

View File

@@ -17,7 +17,6 @@
package com.android.settings.regionalpreferences; package com.android.settings.regionalpreferences;
import android.content.Context; import android.content.Context;
import android.os.LocaleList;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -27,6 +26,8 @@ import com.android.internal.app.LocaleStore;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags; import com.android.settings.flags.Flags;
import java.util.Locale;
/** A controller for the entry of region picker page */ /** A controller for the entry of region picker page */
public class RegionPreferenceController extends BasePreferenceController { public class RegionPreferenceController extends BasePreferenceController {
@@ -39,7 +40,7 @@ public class RegionPreferenceController extends BasePreferenceController {
super.displayPreference(screen); super.displayPreference(screen);
Preference preference = screen.findPreference(getPreferenceKey()); Preference preference = screen.findPreference(getPreferenceKey());
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo( LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(
LocaleList.getDefault().get(0)); Locale.getDefault());
preference.setSummary(localeInfo.getFullCountryNameNative()); preference.setSummary(localeInfo.getFullCountryNameNative());
} }

View File

@@ -275,6 +275,7 @@ public class LocaleListEditorTest {
public void showConfirmDialog_systemLocaleSelected_shouldShowLocaleChangeDialog() public void showConfirmDialog_systemLocaleSelected_shouldShowLocaleChangeDialog()
throws Exception { throws Exception {
//pre-condition //pre-condition
Locale.setDefault(Locale.forLanguageTag("zh-TW"));
setUpLocaleConditions(true); setUpLocaleConditions(true);
final Configuration config = new Configuration(); final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US"))); config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));
@@ -379,6 +380,7 @@ public class LocaleListEditorTest {
@Test @Test
public void onTouch_dragDifferentLocaleToTop_showConfirmDialog() throws Exception { public void onTouch_dragDifferentLocaleToTop_showConfirmDialog() throws Exception {
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0); MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
Locale.setDefault(Locale.forLanguageTag("zh-TW"));
setUpLocaleConditions(true); setUpLocaleConditions(true);
final Configuration config = new Configuration(); final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US"))); config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));