LocalePreferences


@RequiresApi(value = VERSION_CODES.LOLLIPOP)
public final 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 methods

static @NonNull String

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

static @NonNull String

Return the calendar type of the inputted Locale.

static @NonNull String
getCalendarType(boolean resolved)

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

static @NonNull String
getCalendarType(@NonNull Locale locale, boolean resolved)

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

static @NonNull String

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

static @NonNull String

Return the first day of week of the inputted Locale.

static @NonNull String
getFirstDayOfWeek(boolean resolved)

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

static @NonNull String
getFirstDayOfWeek(@NonNull Locale locale, boolean resolved)

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

static @NonNull String

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

static @NonNull String

Return the hour cycle setting of the inputted Locale.

static @NonNull String
getHourCycle(boolean resolved)

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

static @NonNull String
getHourCycle(@NonNull Locale locale, boolean resolved)

Return the hour cycle setting of the inputted Locale.

static @NonNull String

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

static @NonNull String

Return the temperature unit of the inputted Locale.

static @NonNull String
getTemperatureUnit(boolean resolved)

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

static @NonNull String
getTemperatureUnit(@NonNull Locale locale, boolean resolved)

Return the temperature unit of the inputted Locale.

Public methods

getCalendarType

Added in 1.12.0
public static @NonNull String getCalendarType()

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
public static @NonNull String getCalendarType(@NonNull Locale locale)

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
public static @NonNull String getCalendarType(boolean resolved)

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

Parameters
boolean resolved

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
@NonNull 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
public static @NonNull String getCalendarType(@NonNull Locale locale, boolean resolved)

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

Parameters
@NonNull Locale locale

The Locale to get the calendar type.

boolean resolved

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
@NonNull 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
public static @NonNull String getFirstDayOfWeek()

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
public static @NonNull String getFirstDayOfWeek(@NonNull Locale locale)

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
public static @NonNull String getFirstDayOfWeek(boolean resolved)

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

Parameters
boolean resolved

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
@NonNull 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
public static @NonNull String getFirstDayOfWeek(@NonNull Locale locale, boolean resolved)

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

Parameters
@NonNull Locale locale

The Locale to get the first day of week.

boolean resolved

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
@NonNull 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
public static @NonNull String getHourCycle()

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
public static @NonNull String getHourCycle(@NonNull Locale locale)

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
public static @NonNull String getHourCycle(boolean resolved)

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

Parameters
boolean resolved

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
@NonNull 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
public static @NonNull String getHourCycle(@NonNull Locale locale, boolean resolved)

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

Parameters
@NonNull Locale locale

The Locale to get the hour cycle.

boolean resolved

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
@NonNull 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
public static @NonNull String getTemperatureUnit()

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
public static @NonNull String getTemperatureUnit(@NonNull Locale locale)

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
public static @NonNull String getTemperatureUnit(boolean resolved)

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

Parameters
boolean resolved

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
@NonNull 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
public static @NonNull String getTemperatureUnit(@NonNull Locale locale, boolean resolved)

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

Parameters
@NonNull Locale locale

The Locale to get the temperature unit.

boolean resolved

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
@NonNull 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.