Java Code Examples for libcore.icu.LocaleData#get()
The following examples show how to use
libcore.icu.LocaleData#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeFormatter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public TimeFormatter() { synchronized (TimeFormatter.class) { Locale locale = Locale.getDefault(); if (sLocale == null || !(locale.equals(sLocale))) { sLocale = locale; sLocaleData = LocaleData.get(locale); Resources r = Resources.getSystem(); sTimeOnlyFormat = r.getString(com.android.internal.R.string.time_of_day); sDateOnlyFormat = r.getString(com.android.internal.R.string.month_day_year); sDateTimeFormat = r.getString(com.android.internal.R.string.date_and_time); } this.dateTimeFormat = sDateTimeFormat; this.timeOnlyFormat = sTimeOnlyFormat; this.dateOnlyFormat = sDateOnlyFormat; localeData = sLocaleData; } }
Example 2
Source File: Calendar.java From j2objc with Apache License 2.0 | 6 votes |
/** * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. * They are used to figure out the week count for a specific date for * a given locale. These must be set when a Calendar is constructed. * @param desiredLocale the given locale. */ private void setWeekCountData(Locale desiredLocale) { /* try to get the Locale data from the cache */ int[] data = cachedLocaleData.get(desiredLocale); if (data == null) { /* cache miss */ data = new int[2]; // BEGIN Android-changed: Use ICU4C to get week data. // data[0] = CalendarDataUtility.retrieveFirstDayOfWeek(desiredLocale); // data[1] = CalendarDataUtility.retrieveMinimalDaysInFirstWeek(desiredLocale); LocaleData localeData = LocaleData.get(desiredLocale); data[0] = localeData.firstDayOfWeek.intValue(); data[1] = localeData.minimalDaysInFirstWeek.intValue(); // END Android-changed: Use ICU4C to get week data. cachedLocaleData.putIfAbsent(desiredLocale, data); } firstDayOfWeek = data[0]; minimalDaysInFirstWeek = data[1]; }
Example 3
Source File: NumberKeyListener.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
static boolean addAmPmChars(@NonNull Collection<Character> collection, @Nullable Locale locale) { if (locale == null) { return false; } final String[] amPm = LocaleData.get(locale).amPm; for (int i = 0; i < amPm.length; i++) { for (int j = 0; j < amPm[i].length(); j++) { final char ch = amPm[i].charAt(j); if (Character.isBmpCodePoint(ch)) { collection.add(Character.valueOf(ch)); } else { // We don't support non-BMP characters. return false; } } } return true; }
Example 4
Source File: TextClock.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Selects either one of {@link #getFormat12Hour()} or {@link #getFormat24Hour()} * depending on whether the user has selected 24-hour format. */ private void chooseFormat() { final boolean format24Requested = is24HourModeEnabled(); LocaleData ld = LocaleData.get(getContext().getResources().getConfiguration().locale); if (format24Requested) { mFormat = abc(mFormat24, mFormat12, ld.timeFormat_Hm); mDescFormat = abc(mDescFormat24, mDescFormat12, mFormat); } else { mFormat = abc(mFormat12, mFormat24, ld.timeFormat_hm); mDescFormat = abc(mDescFormat12, mDescFormat24, mFormat); } boolean hadSeconds = mHasSeconds; mHasSeconds = DateFormat.hasSeconds(mFormat); if (mShouldRunTicker && hadSeconds != mHasSeconds) { if (hadSeconds) getHandler().removeCallbacks(mTicker); else mTicker.run(); } }
Example 5
Source File: LocaleDataTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testAll() throws Exception { // Test that we can get the locale data for all known locales. for (Locale l : Locale.getAvailableLocales()) { LocaleData d = LocaleData.get(l); // System.err.format("%20s %s %s %s\n", l, d.yesterday, d.today, d.tomorrow); // System.err.format("%20s %10s %10s\n", l, d.timeFormat_hm, d.timeFormat_Hm); } }
Example 6
Source File: DateSorter.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @param context Application context */ public DateSorter(Context context) { Resources resources = context.getResources(); Calendar c = Calendar.getInstance(); beginningOfDay(c); // Create the bins mBins[0] = c.getTimeInMillis(); // Today c.add(Calendar.DAY_OF_YEAR, -1); mBins[1] = c.getTimeInMillis(); // Yesterday c.add(Calendar.DAY_OF_YEAR, -(NUM_DAYS_AGO - 1)); mBins[2] = c.getTimeInMillis(); // Five days ago c.add(Calendar.DAY_OF_YEAR, NUM_DAYS_AGO); // move back to today c.add(Calendar.MONTH, -1); mBins[3] = c.getTimeInMillis(); // One month ago // build labels Locale locale = resources.getConfiguration().locale; if (locale == null) { locale = Locale.getDefault(); } LocaleData localeData = LocaleData.get(locale); mLabels[0] = localeData.today; mLabels[1] = localeData.yesterday; int resId = com.android.internal.R.plurals.last_num_days; String format = resources.getQuantityString(resId, NUM_DAYS_AGO); mLabels[2] = String.format(format, NUM_DAYS_AGO); mLabels[3] = context.getString(com.android.internal.R.string.last_month); mLabels[4] = context.getString(com.android.internal.R.string.older); }
Example 7
Source File: LocaleDataTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_ru_RU() throws Exception { // Russian locale strings updated in macOS 10.12 to match iOS. if (!EnvironmentUtil.onMacOSX() || EnvironmentUtil.onMinimumOSVersion("10.12")) { LocaleData l = LocaleData.get(new Locale("ru", "RU")); assertEquals("воскресенье", l.longWeekdayNames[1]); assertEquals("вс", l.shortWeekdayNames[1]); assertEquals("вс", l.tinyWeekdayNames[1]); // Russian stand-alone weekday names have no initial capital since CLDR 28/ICU 56. assertEquals("воскресенье", l.longStandAloneWeekdayNames[1]); assertEquals("вс", l.shortStandAloneWeekdayNames[1]); assertEquals("В", l.tinyStandAloneWeekdayNames[1]); } }
Example 8
Source File: DateFormatSymbols.java From j2objc with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); if (serialVersionOnStream < 1) { LocaleData localeData = LocaleData.get(locale); initializeSupplementaryData(localeData); } serialVersionOnStream = currentSerialVersion; }
Example 9
Source File: DateFormatSymbols.java From j2objc with Apache License 2.0 | 5 votes |
private void initializeData(Locale desiredLocale) { locale = desiredLocale; // Copy values of a cached instance if any. SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref != null && (dfs = ref.get()) != null) { copyMembers(dfs, this); return; } locale = LocaleData.mapInvalidAndNullLocales(locale); LocaleData localeData = LocaleData.get(locale); eras = localeData.eras; // Month names. months = localeData.longMonthNames; shortMonths = localeData.shortMonthNames; ampms = localeData.amPm; localPatternChars = patternChars; // Weekdays. weekdays = localeData.longWeekdayNames; shortWeekdays = localeData.shortWeekdayNames; initializeSupplementaryData(localeData); }
Example 10
Source File: SimpleMonthView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void updateDayOfWeekLabels() { // Use tiny (e.g. single-character) weekday names from ICU. The indices // for this list correspond to Calendar days, e.g. SUNDAY is index 1. final String[] tinyWeekdayNames = LocaleData.get(mLocale).tinyWeekdayNames; for (int i = 0; i < DAYS_IN_WEEK; i++) { mDayOfWeekLabels[i] = tinyWeekdayNames[(mWeekStart + i - 1) % DAYS_IN_WEEK + 1]; } }
Example 11
Source File: LocaleDataTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_cs_CZ() throws Exception { LocaleData l = LocaleData.get(new Locale("cs", "CZ")); assertEquals("ledna", l.longMonthNames[0]); assertEquals("led", l.shortMonthNames[0]); assertEquals("1", l.tinyMonthNames[0]); assertEquals("leden", l.longStandAloneMonthNames[0]); assertEquals("led", l.shortStandAloneMonthNames[0]); assertEquals("1", l.tinyStandAloneMonthNames[0]); }
Example 12
Source File: TimePicker.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
static String[] getAmPmStrings(Context context) { final Locale locale = context.getResources().getConfiguration().locale; final LocaleData d = LocaleData.get(locale); final String[] result = new String[2]; result[0] = d.amPm[0].length() > 4 ? d.narrowAm : d.amPm[0]; result[1] = d.amPm[1].length() > 4 ? d.narrowPm : d.amPm[1]; return result; }
Example 13
Source File: TextClock.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void init() { if (mFormat12 == null || mFormat24 == null) { LocaleData ld = LocaleData.get(getContext().getResources().getConfiguration().locale); if (mFormat12 == null) { mFormat12 = ld.timeFormat_hm; } if (mFormat24 == null) { mFormat24 = ld.timeFormat_Hm; } } createTime(mTimeZone); chooseFormat(); }
Example 14
Source File: LocaleDataTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_ko_KR() throws Exception { LocaleData l = LocaleData.get(new Locale("ko", "KR")); // Ensure the fix for http://b/14493853 doesn't mangle Hangul. assertEquals("어제", l.yesterday); assertEquals("오늘", l.today); assertEquals("내일", l.tomorrow); }
Example 15
Source File: DateUtils.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Return a string for the day of the week. * @param dayOfWeek One of {@link Calendar#SUNDAY Calendar.SUNDAY}, * {@link Calendar#MONDAY Calendar.MONDAY}, etc. * @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_SHORT}, * {@link #LENGTH_MEDIUM}, or {@link #LENGTH_SHORTEST}. * Note that in most languages, {@link #LENGTH_SHORT} * will return the same as {@link #LENGTH_MEDIUM}. * Undefined lengths will return {@link #LENGTH_MEDIUM} * but may return something different in the future. * @throws IndexOutOfBoundsException if the dayOfWeek is out of bounds. * @deprecated Use {@link java.text.SimpleDateFormat} instead. */ @Deprecated public static String getDayOfWeekString(int dayOfWeek, int abbrev) { LocaleData d = LocaleData.get(Locale.getDefault()); String[] names; switch (abbrev) { case LENGTH_LONG: names = d.longWeekdayNames; break; case LENGTH_MEDIUM: names = d.shortWeekdayNames; break; case LENGTH_SHORT: names = d.shortWeekdayNames; break; // TODO case LENGTH_SHORTER: names = d.shortWeekdayNames; break; // TODO case LENGTH_SHORTEST: names = d.tinyWeekdayNames; break; default: names = d.shortWeekdayNames; break; } return names[dayOfWeek]; }
Example 16
Source File: NumberPicker.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static char getZeroDigit(Locale locale) { return LocaleData.get(locale).zeroDigit; }
Example 17
Source File: NumberFormat.java From j2objc with Apache License 2.0 | 4 votes |
private static NumberFormat getInstance(Locale desiredLocale, int choice) { // Check whether a provider can provide an implementation that's closer // to the requested locale than what the Java runtime itself can provide. /* J2ObjC: java.text.spi is not provided. LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(NumberFormatProvider.class); if (pool.hasProviders()) { NumberFormat providersInstance = pool.getLocalizedObject( NumberFormatGetter.INSTANCE, desiredLocale, choice); if (providersInstance != null) { return providersInstance; } }*/ /* try the cache first */ String[] numberPatterns = (String[])cachedLocaleData.get(desiredLocale); if (numberPatterns == null) { /* cache miss */ LocaleData data = LocaleData.get(desiredLocale); numberPatterns = new String[4]; numberPatterns[NUMBERSTYLE] = data.numberPattern; numberPatterns[CURRENCYSTYLE] = data.currencyPattern; numberPatterns[PERCENTSTYLE] = data.percentPattern; numberPatterns[INTEGERSTYLE] = data.integerPattern; /* update cache */ cachedLocaleData.put(desiredLocale, numberPatterns); } DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(desiredLocale); int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice; DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols); if (choice == INTEGERSTYLE) { format.setMaximumFractionDigits(0); format.setDecimalSeparatorAlwaysShown(false); format.setParseIntegerOnly(true); } else if (choice == CURRENCYSTYLE) { adjustForCurrencyDefaultFractionDigits(format, symbols); } return format; }
Example 18
Source File: SimpleDateFormat.java From j2objc with Apache License 2.0 | 4 votes |
SimpleDateFormat(int timeStyle, int dateStyle, Locale loc) { if (loc == null) { throw new NullPointerException(); } this.locale = loc; // initialize calendar and related fields initializeCalendar(loc); /* try the cache first */ String[] dateTimePatterns = cachedLocaleData.get(loc); if (dateTimePatterns == null) { /* cache miss */ LocaleData localeData = LocaleData.get(loc); dateTimePatterns = new String[9]; dateTimePatterns[DateFormat.SHORT + 4] = localeData.getDateFormat(DateFormat.SHORT); dateTimePatterns[DateFormat.MEDIUM + 4] = localeData.getDateFormat(DateFormat.MEDIUM); dateTimePatterns[DateFormat.LONG + 4] = localeData.getDateFormat(DateFormat.LONG); dateTimePatterns[DateFormat.FULL + 4] = localeData.getDateFormat(DateFormat.FULL); dateTimePatterns[DateFormat.SHORT] = localeData.getTimeFormat(DateFormat.SHORT); dateTimePatterns[DateFormat.MEDIUM] = localeData.getTimeFormat(DateFormat.MEDIUM); dateTimePatterns[DateFormat.LONG] = localeData.getTimeFormat(DateFormat.LONG); dateTimePatterns[DateFormat.FULL] = localeData.getTimeFormat(DateFormat.FULL); dateTimePatterns[8] = "{0} {1}"; /* update cache */ cachedLocaleData.putIfAbsent(loc, dateTimePatterns); } formatData = DateFormatSymbols.getInstanceRef(loc); if ((timeStyle >= 0) && (dateStyle >= 0)) { Object[] dateTimeArgs = {dateTimePatterns[dateStyle + 4], dateTimePatterns[timeStyle]}; pattern = MessageFormat.format(dateTimePatterns[8], dateTimeArgs); } else if (timeStyle >= 0) { pattern = dateTimePatterns[timeStyle]; } else if (dateStyle >= 0) { pattern = dateTimePatterns[dateStyle + 4]; } else { throw new IllegalArgumentException("No date or time style specified"); } initialize(loc); }
Example 19
Source File: DateFormat.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Returns a String pattern that can be used to format the time according * to the context's locale and the user's 12-/24-hour clock preference. * @param context the application context * @param userHandle the user handle of the user to query the format for * @hide */ public static String getTimeFormatString(Context context, int userHandle) { final LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale); return is24HourFormat(context, userHandle) ? d.timeFormat_Hm : d.timeFormat_hm; }
Example 20
Source File: DateUtils.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * Return a localized string for AM or PM. * @param ampm Either {@link Calendar#AM Calendar.AM} or {@link Calendar#PM Calendar.PM}. * @throws IndexOutOfBoundsException if the ampm is out of bounds. * @return Localized version of "AM" or "PM". * @deprecated Use {@link java.text.SimpleDateFormat} instead. */ @Deprecated public static String getAMPMString(int ampm) { return LocaleData.get(Locale.getDefault()).amPm[ampm - Calendar.AM]; }