LocaleListCompat

class LocaleListCompat
kotlin.Any
   ↳ androidx.core.os.LocaleListCompat

Helper for accessing features in LocaleList.

Summary

Public methods
Int

Int
indexOf(locale: Locale!)

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

Boolean
equals(other: Any?)

Boolean

Returns whether the LocaleListCompat contains no Locale items.

String

Int

Returns the number of Locale items in this LocaleListCompat.

Locale!
get(index: Int)

Retrieves the Locale at the specified index.

String

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

Any?

Gets the underlying framework object.

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

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

static LocaleListCompat!
wrap(localeList: Any!)

static LocaleListCompat
wrap(@NonNull localeList: LocaleList)

Creates a new instance of LocaleListCompat from the Locale list.

static LocaleListCompat
create(@NonNull vararg localeList: Locale!)

Creates a new instance of LocaleListCompat from the Locale array.

static LocaleListCompat

Retrieve an empty instance of LocaleListCompat.

static LocaleListCompat
forLanguageTags(@Nullable list: String?)

Generates a new LocaleList with the given language tags.

static LocaleListCompat

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

static LocaleListCompat

The result is guaranteed to include the default Locale returned by Locale.

Public methods

hashCode

fun hashCode(): Int

indexOf

fun indexOf(locale: Locale!): Int

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

Parameters
locale Locale!: The Locale to search for.
Return
Int: The index of the first occurrence of the Locale or -1 if the item wasn't found

equals

fun equals(other: Any?): Boolean

isEmpty

fun isEmpty(): Boolean

Returns whether the LocaleListCompat contains no Locale items.

Return
Boolean: true if this LocaleListCompat has no Locale items, false otherwise

toString

fun toString(): String

size

fun size(): Int

Returns the number of Locale items in this LocaleListCompat.

get

fun get(index: Int): Locale!

Retrieves the Locale at the specified index.

Parameters
index Int: The position to retrieve.
Return
Locale!: The Locale in the given index

toLanguageTags

@NonNull fun toLanguageTags(): String

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

unwrap

@Nullable fun unwrap(): Any?

Gets the underlying framework object.

Return
Any?: an android.os.LocaleList object if API >= 24 , or null if not.

getFirstMatch

@Nullable fun getFirstMatch(@NonNull supportedLocales: Array<String!>): Locale?

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

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

wrap

static fun wrap(localeList: Any!): LocaleListCompat!

wrap

@NonNull static fun wrap(@NonNull localeList: LocaleList): LocaleListCompat

Creates a new instance of LocaleListCompat from the Locale list.

create

@NonNull static fun create(@NonNull vararg localeList: Locale!): LocaleListCompat

Creates a new instance of LocaleListCompat from the Locale array.

getEmptyLocaleList

@NonNull static fun getEmptyLocaleList(): LocaleListCompat

Retrieve an empty instance of LocaleListCompat.

forLanguageTags

@NonNull static fun forLanguageTags(@Nullable 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.
Return
LocaleListCompat: A new instance with the Locale items identified by the given tags.

getAdjustedDefault

@NonNull static fun getAdjustedDefault(): LocaleListCompat

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

getDefault

@NonNull static fun getDefault(): 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.