LocalePreferences


@RequiresApi(value = VERSION_CODES.LOLLIPOP)
class LocalePreferences


Provides friendly APIs to get the user's locale preferences. The data can refer to external/cldr/common/main/en.xml.

Summary

Nested types

APIs to get the user's preference of Calendar.

APIs to get the user's preference of the first day of week.

APIs to get the user's preference of the hour cycle.

APIs to get the user's preference of temperature unit.

Public functions

java-static String

Return the user's preference of the calendar type which is from getDefault.

java-static String

Return the calendar type of the inputted Locale.

java-static String

Return the user's preference of the calendar type which is from getDefault, e.g.

java-static String
getCalendarType(locale: Locale, resolved: Boolean)

Return the calendar type of the inputted Locale, e.g.

java-static String

Return the user's preference of the first day of week which is from getDefault.

java-static String

Return the first day of week of the inputted Locale.

java-static String

Return the user's preference of the first day of week which is from getDefault, e.g.

java-static String
getFirstDayOfWeek(locale: Locale, resolved: Boolean)

Return the first day of week of the inputted Locale, e.g.

java-static String

Return the user's preference of the hour cycle which is from getDefault.

java-static String

Return the hour cycle setting of the inputted Locale.

java-static String
getHourCycle(resolved: Boolean)

Return the user's preference of the hour cycle which is from getDefault, e.g.

java-static String
getHourCycle(locale: Locale, resolved: Boolean)

Return the hour cycle setting of the inputted Locale.

java-static String

Return the user's preference of the temperature unit which is from getDefault.

java-static String

Return the temperature unit of the inputted Locale.

java-static String

Return the user's preference of the temperature unit which is from getDefault, e.g.

java-static String
getTemperatureUnit(locale: Locale, resolved: Boolean)

Return the temperature unit of the inputted Locale.

Public functions

getCalendarType

Added in 1.12.0
java-static fun getCalendarType(): String

Return the user's preference of the calendar type which is from getDefault. The returned result is resolved and bases on the Locale#getDefault(Locale.Category) settings. It is one of the strings defined in {@see CalendarType}, e.g. CalendarType#CHINESE.

getCalendarType

Added in 1.12.0
java-static fun getCalendarType(locale: Locale): String

Return the calendar type of the inputted Locale. The returned result is resolved and based on the input Locale settings. It is one of the strings defined in {@see CalendarType}, e.g. CalendarType#CHINESE.

getCalendarType

Added in 1.12.0
java-static fun getCalendarType(resolved: Boolean): String

Return the user's preference of the calendar type which is from getDefault, e.g. CalendarType#CHINESE.

Parameters
resolved: Boolean

If the Locale#getDefault(Locale.Category) contains calendar type subtag, this argument is ignored. If the Locale#getDefault(Locale.Category) doesn't contain calendar type subtag and the resolved argument is true, this function tries to find the default calendar type for the Locale#getDefault(Locale.Category). If the Locale#getDefault(Locale.Category) doesn't contain calendar type subtag and the resolved argument is false, this function returns empty string , i.e. CalendarType#DEFAULT.

Returns
String

CalendarType.CalendarTypes If the malformed calendar type format was specified in the calendar type subtag, e.g. en-US-u-ca-calendar, this function returns empty string, i.e. CalendarType#DEFAULT.

getCalendarType

Added in 1.12.0
java-static fun getCalendarType(locale: Locale, resolved: Boolean): String

Return the calendar type of the inputted Locale, e.g. CalendarType#CHINESE.

Parameters
locale: Locale

The Locale to get the calendar type.

resolved: Boolean

If the given Locale contains calendar type subtag, this argument is ignored. If the given Locale doesn't contain calendar type subtag and the resolved argument is true, this function tries to find the default calendar type for the given Locale. If the given Locale doesn't contain calendar type subtag and the resolved argument is false, this function return empty string, i.e. CalendarType#DEFAULT.

Returns
String

CalendarType.CalendarTypes If the malformed calendar type format was specified in the calendar type subtag, e.g. en-US-u-ca-calendar, this function returns empty string, i.e. CalendarType#DEFAULT.

getFirstDayOfWeek

Added in 1.12.0
java-static fun getFirstDayOfWeek(): String

Return the user's preference of the first day of week which is from getDefault. The returned result is resolved and bases on the Locale#getDefault(Locale.Category) settings. It is one of the strings defined in {@see FirstDayOfWeek}, e.g. FirstDayOfWeek#SUNDAY.

getFirstDayOfWeek

Added in 1.12.0
java-static fun getFirstDayOfWeek(locale: Locale): String

Return the first day of week of the inputted Locale. The returned result is resolved and based on the input Locale settings. It is one of the strings defined in {@see FirstDayOfWeek}, e.g. FirstDayOfWeek#SUNDAY.

getFirstDayOfWeek

Added in 1.12.0
java-static fun getFirstDayOfWeek(resolved: Boolean): String

Return the user's preference of the first day of week which is from getDefault, e.g. FirstDayOfWeek#SUNDAY.

Parameters
resolved: Boolean

If the Locale#getDefault(Locale.Category) contains first day of week subtag, this argument is ignored. If the Locale#getDefault(Locale.Category) doesn't contain first day of week subtag and the resolved argument is true, this function tries to find the default first day of week for the Locale#getDefault(Locale.Category). If the Locale#getDefault(Locale.Category) doesn't contain first day of week subtag and the resolved argument is false, this function returns empty string , i.e. FirstDayOfWeek#DEFAULT.

Returns
String

FirstDayOfWeek.Days If the malformed first day of week format was specified in the first day of week subtag, e.g. en-US-u-fw-days, this function returns empty string, i.e. FirstDayOfWeek#DEFAULT.

getFirstDayOfWeek

Added in 1.12.0
java-static fun getFirstDayOfWeek(locale: Locale, resolved: Boolean): String

Return the first day of week of the inputted Locale, e.g. FirstDayOfWeek#SUNDAY.

Parameters
locale: Locale

The Locale to get the first day of week.

resolved: Boolean

If the given Locale contains first day of week subtag, this argument is ignored. If the given Locale doesn't contain first day of week subtag and the resolved argument is true, this function tries to find the default first day of week for the given Locale. If the given Locale doesn't contain first day of week subtag and the resolved argument is false, this function return empty string, i.e. FirstDayOfWeek#DEFAULT.

Returns
String

FirstDayOfWeek.Days If the malformed first day of week format was specified in the first day of week subtag, e.g. en-US-u-fw-days, this function returns empty string, i.e. FirstDayOfWeek#DEFAULT.

getHourCycle

Added in 1.12.0
java-static fun getHourCycle(): String

Return the user's preference of the hour cycle which is from getDefault. The returned result is resolved and bases on the Locale#getDefault(Locale.Category). It is one of the strings defined in {@see HourCycle}, e.g. HourCycle#H11.

getHourCycle

Added in 1.12.0
java-static fun getHourCycle(locale: Locale): String

Return the hour cycle setting of the inputted Locale. The returned result is resolved and based on the input Locale. It is one of the strings defined in {@see HourCycle}, e.g. HourCycle#H11.

getHourCycle

Added in 1.12.0
java-static fun getHourCycle(resolved: Boolean): String

Return the user's preference of the hour cycle which is from getDefault, e.g. HourCycle#H11.

Parameters
resolved: Boolean

If the Locale#getDefault(Locale.Category) contains hour cycle subtag, this argument is ignored. If the Locale#getDefault(Locale.Category) doesn't contain hour cycle subtag and the resolved argument is true, this function tries to find the default hour cycle for the Locale#getDefault(Locale.Category). If the Locale#getDefault(Locale.Category) doesn't contain hour cycle subtag and the resolved argument is false, this function returns empty string , i.e. HourCycle#DEFAULT.

Returns
String

HourCycle.HourCycleTypes If the malformed hour cycle format was specified in the hour cycle subtag, e.g. en-US-u-hc-h32, this function returns empty string, i.e. HourCycle#DEFAULT.

getHourCycle

Added in 1.12.0
java-static fun getHourCycle(locale: Locale, resolved: Boolean): String

Return the hour cycle setting of the inputted Locale. E.g. "en-US-u-hc-h23".

Parameters
locale: Locale

The Locale to get the hour cycle.

resolved: Boolean

If the given Locale contains hour cycle subtag, this argument is ignored. If the given Locale doesn't contain hour cycle subtag and the resolved argument is true, this function tries to find the default hour cycle for the given Locale. If the given Locale doesn't contain hour cycle subtag and the resolved argument is false, this function return empty string, i.e. HourCycle#DEFAULT.

Returns
String

HourCycle.HourCycleTypes If the malformed hour cycle format was specified in the hour cycle subtag, e.g. en-US-u-hc-h32, this function returns empty string, i.e. HourCycle#DEFAULT.

getTemperatureUnit

Added in 1.12.0
java-static fun getTemperatureUnit(): String

Return the user's preference of the temperature unit which is from getDefault. The returned result is resolved and bases on the Locale#getDefault(Locale.Category) settings. It is one of the strings defined in {@see TemperatureUnit}, e.g. TemperatureUnit#FAHRENHEIT.

getTemperatureUnit

Added in 1.12.0
java-static fun getTemperatureUnit(locale: Locale): String

Return the temperature unit of the inputted Locale. It is one of the strings defined in {@see TemperatureUnit}, e.g. TemperatureUnit#FAHRENHEIT.

getTemperatureUnit

Added in 1.12.0
java-static fun getTemperatureUnit(resolved: Boolean): String

Return the user's preference of the temperature unit which is from getDefault, e.g. TemperatureUnit#FAHRENHEIT.

Parameters
resolved: Boolean

If the Locale#getDefault(Locale.Category) contains temperature unit subtag, this argument is ignored. If the Locale#getDefault(Locale.Category) doesn't contain temperature unit subtag and the resolved argument is true, this function tries to find the default temperature unit for the Locale#getDefault(Locale.Category). If the Locale#getDefault(Locale.Category) doesn't contain temperature unit subtag and the resolved argument is false, this function returns empty string , i.e. TemperatureUnit#DEFAULT.

Returns
String

TemperatureUnit.TemperatureUnits If the malformed temperature unit format was specified in the temperature unit subtag, e.g. en-US-u-mu-temperature, this function returns empty string, i.e. TemperatureUnit#DEFAULT.

getTemperatureUnit

Added in 1.12.0
java-static fun getTemperatureUnit(locale: Locale, resolved: Boolean): String

Return the temperature unit of the inputted Locale. E.g. "fahrenheit"

Parameters
locale: Locale

The Locale to get the temperature unit.

resolved: Boolean

If the given Locale contains temperature unit subtag, this argument is ignored. If the given Locale doesn't contain temperature unit subtag and the resolved argument is true, this function tries to find the default temperature unit for the given Locale. If the given Locale doesn't contain temperature unit subtag and the resolved argument is false, this function return empty string, i.e. TemperatureUnit#DEFAULT.

Returns
String

TemperatureUnit.TemperatureUnits If the malformed temperature unit format was specified in the temperature unit subtag, e.g. en-US-u-mu-temperature, this function returns empty string, i.e. TemperatureUnit#DEFAULT.