LocaleListCompat
public final class LocaleListCompat
Helper for accessing features in LocaleList.
Summary
Public methods |
|
|---|---|
static @NonNull LocaleListCompat |
Creates a new instance of |
boolean |
|
static @NonNull LocaleListCompat |
forLanguageTags(@Nullable String list)Generates a new LocaleList with the given language tags. |
@Nullable Locale |
get(int index)Retrieves the |
static @Size(min = 1) @NonNull LocaleListCompat |
Returns the default locale list, adjusted by moving the default locale to its first position. |
static @Size(min = 1) @NonNull LocaleListCompat |
The result is guaranteed to include the default Locale returned by Locale.getDefault(), but not necessarily at the top of the list. |
static @NonNull LocaleListCompat |
Retrieve an empty instance of |
@Nullable Locale |
getFirstMatch(@NonNull String[] supportedLocales)Returns the first match in the locale list given an unordered array of supported locales in BCP 47 format. |
int |
hashCode() |
@IntRange(from = "-1") int |
Searches this |
boolean |
isEmpty()Returns whether the |
static boolean |
@RequiresApi(value = 21)Determine whether two locales are considered a match, even if they are not exactly equal. |
@IntRange(from = 0) int |
size()Returns the number of |
@NonNull String |
Retrieves a String representation of the language tags in this list. |
@NonNull String |
toString() |
@Nullable Object |
unwrap()Gets the underlying framework object. |
static LocaleListCompat |
@RequiresApi(value = 24)This method is deprecated. Use |
static @NonNull LocaleListCompat |
@RequiresApi(value = 24)Creates a new instance of |
Public methods
create
public static @NonNull LocaleListCompat create(@NonNull Locale[] localeList)
Creates a new instance of LocaleListCompat from the Locale array.
forLanguageTags
public static @NonNull LocaleListCompat forLanguageTags(@Nullable String list)
Generates a new LocaleList with the given language tags.
Note that for API <24 only the first language tag will be used.
| Parameters | |
|---|---|
@Nullable String list |
The language tags to be included as a single |
| Returns | |
|---|---|
@NonNull LocaleListCompat |
A new instance with the |
get
public @Nullable Locale get(int index)
Retrieves the Locale at the specified index.
| Parameters | |
|---|---|
int index |
The position to retrieve. |
getAdjustedDefault
public static @Size(min = 1) @NonNull LocaleListCompat getAdjustedDefault()
Returns the default locale list, adjusted by moving the default locale to its first position.
getDefault
public static @Size(min = 1) @NonNull LocaleListCompat getDefault()
The result is guaranteed to include the default Locale returned by Locale.getDefault(), but not necessarily at the top of the list. The default locale not being at the top of the list is an indication that the system has set the default locale to one of the user's other preferred locales, having concluded that the primary preference is not supported but a secondary preference is.
Note that for API >= 24 the default LocaleList would change if Locale.setDefault() is called. This method takes that into account by always checking the output of Locale.getDefault() and recalculating the default LocaleList if needed.
getEmptyLocaleList
public static @NonNull LocaleListCompat getEmptyLocaleList()
Retrieve an empty instance of LocaleListCompat.
getFirstMatch
public @Nullable Locale getFirstMatch(@NonNull String[] supportedLocales)
Returns the first match in the locale list given an unordered array of supported locales in BCP 47 format.
| Returns | |
|---|---|
@Nullable Locale |
The first |
indexOf
public @IntRange(from = "-1") int indexOf(@Nullable Locale locale)
Searches this LocaleListCompat for the specified Locale and returns the index of the first occurrence.
isEmpty
public boolean isEmpty()
Returns whether the LocaleListCompat contains no Locale items.
| Returns | |
|---|---|
boolean |
|
matchesLanguageAndScript
@RequiresApi(value = 21)
public static boolean matchesLanguageAndScript(
@NonNull Locale supported,
@NonNull Locale desired
)
Determine whether two locales are considered a match, even if they are not exactly equal. They are considered as a match when both of their languages and scripts (explicit or inferred) are identical. This means that a user would be able to understand the content written in the supported locale even if they say they prefer the desired locale. E.g. [zh-HK] matches [zh-Hant]; [en-US] matches [en-CA].
| Parameters | |
|---|---|
@NonNull Locale supported |
The supported |
@NonNull Locale desired |
The desired |
| Returns | |
|---|---|
boolean |
True if they match, false otherwise. |
size
public @IntRange(from = 0) int size()
Returns the number of Locale items in this LocaleListCompat.
toLanguageTags
public @NonNull String toLanguageTags()
Retrieves a String representation of the language tags in this list.
wrap
@RequiresApi(value = 24)
public static @NonNull LocaleListCompat wrap(@NonNull LocaleList localeList)
Creates a new instance of LocaleListCompat from the Locale list.