diff options
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | src/com/android/localepicker/LocaleHelper.java | 44 | ||||
-rw-r--r-- | src/com/android/localepicker/LocaleStore.java | 21 | ||||
-rw-r--r-- | src/com/android/localepicker/SuggestedLocaleAdapter.java | 7 |
4 files changed, 23 insertions, 53 deletions
@@ -15,6 +15,10 @@ android_library { name: "localepicker", manifest: "AndroidManifest.xml", + sdk_version: "system_current", + static_libs: [ + "androidx.annotation_annotation", + ], resource_dirs: [ "res", ], diff --git a/src/com/android/localepicker/LocaleHelper.java b/src/com/android/localepicker/LocaleHelper.java index 7fd598f..ed2c543 100644 --- a/src/com/android/localepicker/LocaleHelper.java +++ b/src/com/android/localepicker/LocaleHelper.java @@ -16,12 +16,13 @@ package com.android.localepicker; -import android.annotation.IntRange; import android.icu.text.ListFormatter; import android.icu.util.ULocale; import android.os.LocaleList; import android.text.TextUtils; +import androidx.annotation.IntRange; + import java.text.Collator; import java.util.Comparator; import java.util.Locale; @@ -159,52 +160,13 @@ public class LocaleHelper { } /** - * Returns the locale list localized for display in the provided locale. - * - * @param locales the list of locales whose names is to be displayed. - * @param displayLocale the locale in which to display the names. - * If this is null, it will use the default locale. - * @param maxLocales maximum number of locales to display. Generates ellipsis after that. - * @return the locale aware list of locale names - */ - public static String getDisplayLocaleList( - LocaleList locales, Locale displayLocale, @IntRange(from=1) int maxLocales) { - - final Locale dispLocale = displayLocale == null ? Locale.getDefault() : displayLocale; - - final boolean ellipsisNeeded = locales.size() > maxLocales; - final int localeCount, listCount; - if (ellipsisNeeded) { - localeCount = maxLocales; - listCount = maxLocales + 1; // One extra slot for the ellipsis - } else { - listCount = localeCount = locales.size(); - } - final String[] localeNames = new String[listCount]; - for (int i = 0; i < localeCount; i++) { - localeNames[i] = LocaleHelper.getDisplayName(locales.get(i), dispLocale, false); - } - if (ellipsisNeeded) { - // Theoretically, we want to extract this from ICU's Resource Bundle for - // "Ellipsis/final", which seeAms to have different strings than the normal ellipsis for - // Hong Kong Traditional Chinese (zh_Hant_HK) and Dzongkha (dz). But that has two - // problems: it's expensive to extract it, and in case the output string becomes - // automatically ellipsized, it can result in weird output. - localeNames[maxLocales] = TextUtils.getEllipsisString(TextUtils.TruncateAt.END); - } - - ListFormatter lfn = ListFormatter.getInstance(dispLocale); - return lfn.format((Object[]) localeNames); - } - - /** * Adds the likely subtags for a provided locale ID. * * @param locale the locale to maximize. * @return the maximized Locale instance. */ public static Locale addLikelySubtags(Locale locale) { - return libcore.icu.ICU.addLikelySubtags(locale); + return ULocale.addLikelySubtags(ULocale.forLocale(locale)).toLocale(); } /** diff --git a/src/com/android/localepicker/LocaleStore.java b/src/com/android/localepicker/LocaleStore.java index 5d07ff2..ff4f85a 100644 --- a/src/com/android/localepicker/LocaleStore.java +++ b/src/com/android/localepicker/LocaleStore.java @@ -16,13 +16,15 @@ package com.android.localepicker; +import android.app.ActivityManager; import android.content.Context; +import android.content.res.Resources; +import android.icu.util.ULocale; import android.os.LocaleList; import android.provider.Settings; import android.telephony.TelephonyManager; -import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.app.LocalePicker; +import androidx.annotation.VisibleForTesting; import java.io.Serializable; import java.util.HashMap; @@ -191,7 +193,7 @@ public class LocaleStore { private static Set<String> getSimCountries(Context context) { Set<String> result = new HashSet<>(); - TelephonyManager tm = TelephonyManager.from(context); + TelephonyManager tm = context.getSystemService(TelephonyManager.class); if (tm != null) { String iso = tm.getSimCountryIso().toUpperCase(Locale.US); @@ -266,13 +268,14 @@ public class LocaleStore { final boolean isInDeveloperMode = Settings.Global.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; - for (String localeId : LocalePicker.getSupportedLocales(context)) { - if (localeId.isEmpty()) { - throw new IllformedLocaleException("Bad locale entry in locale_config.xml"); + ActivityManager activityManager = context.getSystemService(ActivityManager.class); + for (Locale locale : activityManager.getSupportedLocales()) { + if (locale == null) { + throw new NullPointerException("Bad locale entry in locale_config.xml"); } - LocaleInfo li = new LocaleInfo(localeId); + LocaleInfo li = new LocaleInfo(locale); - if (LocaleList.isPseudoLocale(li.getLocale())) { + if (LocaleList.isPseudoLocale(ULocale.forLocale(li.getLocale()))) { if (isInDeveloperMode) { li.setTranslated(true); li.mIsPseudo = true; @@ -298,7 +301,7 @@ public class LocaleStore { // TODO: See if we can reuse what LocaleList.matchScore does final HashSet<String> localizedLocales = new HashSet<>(); - for (String localeId : LocalePicker.getSystemAssetLocales()) { + for (String localeId : Resources.getSystem().getAssets().getLocales()) { LocaleInfo li = new LocaleInfo(localeId); final String country = li.getLocale().getCountry(); // All this is to figure out if we should suggest a country diff --git a/src/com/android/localepicker/SuggestedLocaleAdapter.java b/src/com/android/localepicker/SuggestedLocaleAdapter.java index 97e2971..c012263 100644 --- a/src/com/android/localepicker/SuggestedLocaleAdapter.java +++ b/src/com/android/localepicker/SuggestedLocaleAdapter.java @@ -16,8 +16,6 @@ package com.android.localepicker; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.content.Context; import android.content.res.Configuration; import android.text.TextUtils; @@ -29,7 +27,10 @@ import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView; -import com.android.internal.annotations.VisibleForTesting; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; + import com.android.localepicker.R; import java.util.ArrayList; |