# LocalePreferences

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/text/util/LocalePreferences.java+class:androidx.core.text.util.LocalePreferences) Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

*** ** * ** ***


```
public final class LocalePreferences
```

<br />

*** ** * ** ***

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

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.CalendarType` APIs to get the user's preference of Calendar. |
| `public class https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.FirstDayOfWeek` APIs to get the user's preference of the first day of week. |
| `public class https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.HourCycle` APIs to get the user's preference of the hour cycle. |
| `public class https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.TemperatureUnit` APIs to get the user's preference of temperature unit. |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getCalendarType()()` Return the user's preference of the calendar type which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getCalendarType(java.util.Locale)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale)` Return the calendar type of the inputted `https://developer.android.com/reference/java/util/Locale.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getCalendarType(boolean)(boolean resolved)` Return the user's preference of the calendar type which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, e.g. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getCalendarType(java.util.Locale,boolean)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale, boolean resolved)` Return the calendar type of the inputted `https://developer.android.com/reference/java/util/Locale.html`, e.g. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getFirstDayOfWeek()()` Return the user's preference of the first day of week which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getFirstDayOfWeek(java.util.Locale)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale)` Return the first day of week of the inputted `https://developer.android.com/reference/java/util/Locale.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getFirstDayOfWeek(boolean)(boolean resolved)` Return the user's preference of the first day of week which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, e.g. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getFirstDayOfWeek(java.util.Locale,boolean)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale, boolean resolved)` Return the first day of week of the inputted `https://developer.android.com/reference/java/util/Locale.html`, e.g. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getHourCycle()()` Return the user's preference of the hour cycle which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getHourCycle(java.util.Locale)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale)` Return the hour cycle setting of the inputted `https://developer.android.com/reference/java/util/Locale.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getHourCycle(boolean)(boolean resolved)` Return the user's preference of the hour cycle which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, e.g. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getHourCycle(java.util.Locale,boolean)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale, boolean resolved)` Return the hour cycle setting of the inputted `https://developer.android.com/reference/java/util/Locale.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getTemperatureUnit()()` Return the user's preference of the temperature unit which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getTemperatureUnit(java.util.Locale)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale)` Return the temperature unit of the inputted `https://developer.android.com/reference/java/util/Locale.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getTemperatureUnit(boolean)(boolean resolved)` Return the user's preference of the temperature unit which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, e.g. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences#getTemperatureUnit(java.util.Locale,boolean)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale, boolean resolved)` Return the temperature unit of the inputted `https://developer.android.com/reference/java/util/Locale.html`. |

## Public methods

### getCalendarType

Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getCalendarType()
```

Return the user's preference of the calendar type which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. 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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getCalendarType(@NonNull Locale locale)
```

Return the calendar type of the inputted `https://developer.android.com/reference/java/util/Locale.html`. The returned result is resolved and based on the input `https://developer.android.com/reference/java/util/Locale.html` settings. It is one of the strings defined in {@see CalendarType}, e.g. `CalendarType#CHINESE`.

### getCalendarType

Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getCalendarType(boolean resolved)
```

Return the user's preference of the calendar type which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

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

Return the calendar type of the inputted `https://developer.android.com/reference/java/util/Locale.html`, e.g. `CalendarType#CHINESE`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale` | The `https://developer.android.com/reference/java/util/Locale.html` 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getFirstDayOfWeek()
```

Return the user's preference of the first day of week which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. 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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getFirstDayOfWeek(@NonNull Locale locale)
```

Return the first day of week of the inputted `https://developer.android.com/reference/java/util/Locale.html`. 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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getFirstDayOfWeek(boolean resolved)
```

Return the user's preference of the first day of week which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

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

Return the first day of week of the inputted `https://developer.android.com/reference/java/util/Locale.html`, e.g. `FirstDayOfWeek#SUNDAY`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale` | The `https://developer.android.com/reference/java/util/Locale.html` 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getHourCycle()
```

Return the user's preference of the hour cycle which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. 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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getHourCycle(@NonNull Locale locale)
```

Return the hour cycle setting of the inputted `https://developer.android.com/reference/java/util/Locale.html`. 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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getHourCycle(boolean resolved)
```

Return the user's preference of the hour cycle which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

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

Return the hour cycle setting of the inputted `https://developer.android.com/reference/java/util/Locale.html`. E.g. "en-US-u-hc-h23".

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getTemperatureUnit()
```

Return the user's preference of the temperature unit which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`. 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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getTemperatureUnit(@NonNull Locale locale)
```

Return the temperature unit of the inputted `https://developer.android.com/reference/java/util/Locale.html`. It is one of the strings defined in {@see TemperatureUnit}, e.g. `TemperatureUnit#FAHRENHEIT`.

### getTemperatureUnit

Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

```
public static @NonNull String getTemperatureUnit(boolean resolved)
```

Return the user's preference of the temperature unit which is from `https://developer.android.com/reference/java/util/Locale.html#getDefault(java.util.Locale.Category)`, 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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](https://developer.android.com/jetpack/androidx/releases/core#1.12.0)

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

Return the temperature unit of the inputted `https://developer.android.com/reference/java/util/Locale.html`. E.g. "fahrenheit"

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html locale` | The `https://developer.android.com/reference/java/util/Locale.html` 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/text/util/LocalePreferences.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`. |