LocaleListCompat

Added in 1.1.0

class LocaleListCompat


Helper for accessing features in LocaleList.

Summary

Public functions

java-static LocaleListCompat
create(localeList: Array<Locale!>)

Creates a new instance of LocaleListCompat from the Locale array.

Boolean
equals(other: Any!)
java-static LocaleListCompat

Generates a new LocaleList with the given language tags.

Locale?
get(index: Int)

Retrieves the Locale at the specified index.

java-static @Size(min = 1) LocaleListCompat

Returns the default locale list, adjusted by moving the default locale to its first position.

java-static @Size(min = 1) LocaleListCompat

The result is guaranteed to include the default Locale returned by Locale.getDefault(), but not necessarily at the top of the list.

java-static LocaleListCompat

Retrieve an empty instance of LocaleListCompat.

Locale?
getFirstMatch(supportedLocales: Array<String!>)

Returns the first match in the locale list given an unordered array of supported locales in BCP 47 format.

Int
@IntRange(from = "-1") Int
indexOf(locale: Locale?)

Searches this LocaleListCompat for the specified Locale and returns the index of the first occurrence.

Boolean

Returns whether the LocaleListCompat contains no Locale items.

java-static Boolean
@RequiresApi(value = 21)
matchesLanguageAndScript(supported: Locale, desired: Locale)

Determine whether two locales are considered a match, even if they are not exactly equal.

@IntRange(from = 0) Int

Returns the number of Locale items in this LocaleListCompat.

String

Retrieves a String representation of the language tags in this list.

String
Any?

Gets the underlying framework object.

java-static LocaleListCompat!
@RequiresApi(value = 24)
wrap(localeList: Any!)

This function is deprecated.

Use wrap

java-static LocaleListCompat
@RequiresApi(value = 24)
wrap(localeList: LocaleList)

Creates a new instance of LocaleListCompat from the Locale list.

Public functions

create

java-static fun create(localeList: Array<Locale!>): LocaleListCompat

Creates a new instance of LocaleListCompat from the Locale array.

equals

fun equals(other: Any!): Boolean

forLanguageTags

Added in 1.1.0
java-static fun forLanguageTags(list: String?): LocaleListCompat

Generates a new LocaleList with the given language tags.

Note that for API <24 only the first language tag will be used.

Parameters
list: String?

The language tags to be included as a single String separated by commas.

Returns
LocaleListCompat

A new instance with the Locale items identified by the given tags.

get

Added in 1.1.0
fun get(index: Int): Locale?

Retrieves the Locale at the specified index.

Parameters
index: Int

The position to retrieve.

Returns
Locale?

The Locale in the given index

getAdjustedDefault

Added in 1.1.0
java-static fun getAdjustedDefault(): @Size(min = 1) LocaleListCompat

Returns the default locale list, adjusted by moving the default locale to its first position.

getDefault

Added in 1.1.0
java-static fun getDefault(): @Size(min = 1) LocaleListCompat

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

Added in 1.1.0
java-static fun getEmptyLocaleList(): LocaleListCompat

Retrieve an empty instance of LocaleListCompat.

getFirstMatch

Added in 1.1.0
fun getFirstMatch(supportedLocales: Array<String!>): Locale?

Returns the first match in the locale list given an unordered array of supported locales in BCP 47 format.

Returns
Locale?

The first Locale from this list that appears in the given array, or null if the LocaleListCompat is empty.

hashCode

fun hashCode(): Int

indexOf

Added in 1.1.0
fun indexOf(locale: Locale?): @IntRange(from = "-1") Int

Searches this LocaleListCompat for the specified Locale and returns the index of the first occurrence.

Parameters
locale: Locale?

The Locale to search for.

Returns
@IntRange(from = "-1") Int

The index of the first occurrence of the Locale or -1 if the item wasn't found

isEmpty

Added in 1.1.0
fun isEmpty(): Boolean

Returns whether the LocaleListCompat contains no Locale items.

Returns
Boolean

true if this LocaleListCompat has no Locale items, false otherwise

matchesLanguageAndScript

Added in 1.9.0
@RequiresApi(value = 21)
java-static fun matchesLanguageAndScript(supported: Locale, desired: Locale): Boolean

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
supported: Locale

The supported Locale to be compared.

desired: Locale

The desired Locale to be compared.

Returns
Boolean

True if they match, false otherwise.

size

Added in 1.1.0
fun size(): @IntRange(from = 0) Int

Returns the number of Locale items in this LocaleListCompat.

toLanguageTags

Added in 1.1.0
fun toLanguageTags(): String

Retrieves a String representation of the language tags in this list.

toString

fun toString(): String

unwrap

Added in 1.1.0
fun unwrap(): Any?

Gets the underlying framework object.

Returns
Any?

an android.os.LocaleList object if API >= 24 , or null if not.

wrap

Added in 1.1.0
Deprecated in 1.1.0
@RequiresApi(value = 24)
java-static fun wrap(localeList: Any!): LocaleListCompat!

wrap

Added in 1.1.0
@RequiresApi(value = 24)
java-static fun wrap(localeList: LocaleList): LocaleListCompat

Creates a new instance of LocaleListCompat from the Locale list.