libcore.icu.LocaleData Java Examples

The following examples show how to use libcore.icu.LocaleData. 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 vote down vote up
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: LocaleDataTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testDecimalFormatSymbols_es() throws Exception {
  LocaleData es = LocaleData.get(new Locale("es"));
  assertEquals(',', es.decimalSeparator);
  assertEquals('.', es.groupingSeparator);

  LocaleData es_419 = LocaleData.get(new Locale("es", "419"));
  assertEquals('.', es_419.decimalSeparator);
  assertEquals(',', es_419.groupingSeparator);

  LocaleData es_US = LocaleData.get(new Locale("es", "US"));
  assertEquals('.', es_US.decimalSeparator);
  assertEquals(',', es_US.groupingSeparator);

  LocaleData es_MX = LocaleData.get(new Locale("es", "MX"));
  assertEquals('.', es_MX.decimalSeparator);
  assertEquals(',', es_MX.groupingSeparator);

  LocaleData es_AR = LocaleData.get(new Locale("es", "AR"));
  assertEquals(',', es_AR.decimalSeparator);
  assertEquals('.', es_AR.groupingSeparator);
}
 
Example #3
Source File: Calendar.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: TextClock.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * 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: NumberKeyListener.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: DateFormatSymbols.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: DateSorter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @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 #8
Source File: LocaleDataTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: LocaleDataTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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 #10
Source File: LocaleDataTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: LocaleDataTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_de_DE() throws Exception {
  LocaleData l = LocaleData.get(new Locale("de", "DE"));

  assertEquals("Gestern", l.yesterday);
  assertEquals("Heute", l.today);
  assertEquals("Morgen", l.tomorrow);
}
 
Example #12
Source File: LocaleDataTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_en_US() throws Exception {
  LocaleData l = LocaleData.get(Locale.US);
  assertEquals("AM", l.amPm[0]);
  // narrowAm not available in J2ObjC.
  //assertEquals("a", l.narrowAm);

  assertEquals("BC", l.eras[0]);

  assertEquals("January", l.longMonthNames[0]);
  assertEquals("Jan", l.shortMonthNames[0]);
  assertEquals("J", l.tinyMonthNames[0]);

  assertEquals("January", l.longStandAloneMonthNames[0]);
  assertEquals("Jan", l.shortStandAloneMonthNames[0]);
  assertEquals("J", l.tinyStandAloneMonthNames[0]);

  assertEquals("Sunday", l.longWeekdayNames[1]);
  assertEquals("Sun", l.shortWeekdayNames[1]);
  assertEquals("S", l.tinyWeekdayNames[1]);

  assertEquals("Sunday", l.longStandAloneWeekdayNames[1]);
  assertEquals("Sun", l.shortStandAloneWeekdayNames[1]);
  assertEquals("S", l.tinyStandAloneWeekdayNames[1]);

  assertEquals("Yesterday", l.yesterday);
  assertEquals("Today", l.today);
  assertEquals("Tomorrow", l.tomorrow);
}
 
Example #13
Source File: LocaleDataTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: DateUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #15
Source File: Currency.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the symbol of this currency for the specified locale.
 * For example, for the US Dollar, the symbol is "$" if the specified
 * locale is the US, while for other locales it may be "US$". If no
 * symbol can be determined, the ISO 4217 currency code is returned.
 *
 * @param locale the locale for which a display name for this currency is
 * needed
 * @return the symbol of this currency for the specified locale
 * @exception NullPointerException if <code>locale</code> is null
 */
public String getSymbol(Locale locale) {
    if (locale == null) {
        throw new NullPointerException("locale == null");
    }
    // Check the locale first, in case the locale has the same currency.
    LocaleData localeData = LocaleData.get(locale);
    if (localeData.internationalCurrencySymbol.equals(currencyCode)) {
        return localeData.currencySymbol;
    }

    // Try ICU, and fall back to the currency code if ICU has nothing.
    String symbol = ICU.getCurrencySymbol(locale, currencyCode);
    return symbol != null ? symbol : currencyCode;
}
 
Example #16
Source File: DateFormatSymbols.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();

    if (serialVersionOnStream < 1) {
        LocaleData localeData = LocaleData.get(locale);
        initializeSupplementaryData(localeData);
    }

    serialVersionOnStream = currentSerialVersion;
}
 
Example #17
Source File: DateFormatSymbols.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void initializeSupplementaryData(LocaleData localeData) {
    // Tiny weekdays and months.
    tinyMonths = localeData.tinyMonthNames;
    tinyWeekdays = localeData.tinyWeekdayNames;

    // Standalone month names.
    standAloneMonths = localeData.longStandAloneMonthNames;
    shortStandAloneMonths = localeData.shortStandAloneMonthNames;
    tinyStandAloneMonths = localeData.tinyStandAloneMonthNames;

    // Standalone weekdays.
    standAloneWeekdays = localeData.longStandAloneWeekdayNames;
    shortStandAloneWeekdays = localeData.shortStandAloneWeekdayNames;
    tinyStandAloneWeekdays = localeData.tinyStandAloneWeekdayNames;
}
 
Example #18
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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 #19
Source File: TimePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static String[] getAmPmStrings(Context context) {
    String[] result = new String[2];
    LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
    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 #20
Source File: TimePicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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 #21
Source File: TextClock.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: DateUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Return a localized string for the month of the year.
 * @param month One of {@link Calendar#JANUARY Calendar.JANUARY},
 *               {@link Calendar#FEBRUARY Calendar.FEBRUARY}, etc.
 * @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_MEDIUM},
 *               or {@link #LENGTH_SHORTEST}.
 *               Undefined lengths will return {@link #LENGTH_MEDIUM}
 *               but may return something different in the future.
 * @return Localized month of the year.
 * @deprecated Use {@link java.text.SimpleDateFormat} instead.
 */
@Deprecated
public static String getMonthString(int month, int abbrev) {
    LocaleData d = LocaleData.get(Locale.getDefault());
    String[] names;
    switch (abbrev) {
        case LENGTH_LONG:       names = d.longMonthNames;  break;
        case LENGTH_MEDIUM:     names = d.shortMonthNames; break;
        case LENGTH_SHORT:      names = d.shortMonthNames; break;
        case LENGTH_SHORTER:    names = d.shortMonthNames; break;
        case LENGTH_SHORTEST:   names = d.tinyMonthNames;  break;
        default:                names = d.shortMonthNames; break;
    }
    return names[month];
}
 
Example #23
Source File: DateFormat.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static String getMonthString(LocaleData ld, int month, int count, int kind) {
    boolean standalone = (kind == 'L');
    if (count == 5) {
        return standalone ? ld.tinyStandAloneMonthNames[month] : ld.tinyMonthNames[month];
    } else if (count == 4) {
        return standalone ? ld.longStandAloneMonthNames[month] : ld.longMonthNames[month];
    } else if (count == 3) {
        return standalone ? ld.shortStandAloneMonthNames[month] : ld.shortMonthNames[month];
    } else {
        // Calendar.JANUARY == 0, so add 1 to month.
        return zeroPad(month+1, count);
    }
}
 
Example #24
Source File: DateFormat.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static String getDayOfWeekString(LocaleData ld, int day, int count, int kind) {
    boolean standalone = (kind == 'c');
    if (count == 5) {
        return standalone ? ld.tinyStandAloneWeekdayNames[day] : ld.tinyWeekdayNames[day];
    } else if (count == 4) {
        return standalone ? ld.longStandAloneWeekdayNames[day] : ld.longWeekdayNames[day];
    } else {
        return standalone ? ld.shortStandAloneWeekdayNames[day] : ld.shortWeekdayNames[day];
    }
}
 
Example #25
Source File: NumberFormat.java    From j2objc with Apache License 2.0 4 votes vote down vote up
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 #26
Source File: SimpleDateFormat.java    From j2objc with Apache License 2.0 4 votes vote down vote up
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 #27
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static char getZeroDigit(Locale locale) {
    return LocaleData.get(locale).zeroDigit;
}
 
Example #28
Source File: CalendarViewLegacyDelegate.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
CalendarViewLegacyDelegate(CalendarView delegator, Context context, AttributeSet attrs,
        int defStyleAttr, int defStyleRes) {
    super(delegator, context);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.CalendarView, defStyleAttr, defStyleRes);
    mShowWeekNumber = a.getBoolean(R.styleable.CalendarView_showWeekNumber,
            DEFAULT_SHOW_WEEK_NUMBER);
    mFirstDayOfWeek = a.getInt(R.styleable.CalendarView_firstDayOfWeek,
            LocaleData.get(Locale.getDefault()).firstDayOfWeek);
    final String minDate = a.getString(R.styleable.CalendarView_minDate);
    if (!CalendarView.parseDate(minDate, mMinDate)) {
        CalendarView.parseDate(DEFAULT_MIN_DATE, mMinDate);
    }
    final String maxDate = a.getString(R.styleable.CalendarView_maxDate);
    if (!CalendarView.parseDate(maxDate, mMaxDate)) {
        CalendarView.parseDate(DEFAULT_MAX_DATE, mMaxDate);
    }
    if (mMaxDate.before(mMinDate)) {
        throw new IllegalArgumentException("Max date cannot be before min date.");
    }
    mShownWeekCount = a.getInt(R.styleable.CalendarView_shownWeekCount,
            DEFAULT_SHOWN_WEEK_COUNT);
    mSelectedWeekBackgroundColor = a.getColor(
            R.styleable.CalendarView_selectedWeekBackgroundColor, 0);
    mFocusedMonthDateColor = a.getColor(
            R.styleable.CalendarView_focusedMonthDateColor, 0);
    mUnfocusedMonthDateColor = a.getColor(
            R.styleable.CalendarView_unfocusedMonthDateColor, 0);
    mWeekSeparatorLineColor = a.getColor(
            R.styleable.CalendarView_weekSeparatorLineColor, 0);
    mWeekNumberColor = a.getColor(R.styleable.CalendarView_weekNumberColor, 0);
    mSelectedDateVerticalBar = a.getDrawable(
            R.styleable.CalendarView_selectedDateVerticalBar);

    mDateTextAppearanceResId = a.getResourceId(
            R.styleable.CalendarView_dateTextAppearance, R.style.TextAppearance_Small);
    updateDateTextSize();

    mWeekDayTextAppearanceResId = a.getResourceId(
            R.styleable.CalendarView_weekDayTextAppearance,
            DEFAULT_WEEK_DAY_TEXT_APPEARANCE_RES_ID);
    a.recycle();

    DisplayMetrics displayMetrics = mDelegator.getResources().getDisplayMetrics();
    mWeekMinVisibleHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            UNSCALED_WEEK_MIN_VISIBLE_HEIGHT, displayMetrics);
    mListScrollTopOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            UNSCALED_LIST_SCROLL_TOP_OFFSET, displayMetrics);
    mBottomBuffer = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            UNSCALED_BOTTOM_BUFFER, displayMetrics);
    mSelectedDateVerticalBarWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            UNSCALED_SELECTED_DATE_VERTICAL_BAR_WIDTH, displayMetrics);
    mWeekSeparatorLineWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            UNSCALED_WEEK_SEPARATOR_LINE_WIDTH, displayMetrics);

    LayoutInflater layoutInflater = (LayoutInflater) mContext
            .getSystemService(Service.LAYOUT_INFLATER_SERVICE);
    View content = layoutInflater.inflate(R.layout.calendar_view, null, false);
    mDelegator.addView(content);

    mListView = mDelegator.findViewById(R.id.list);
    mDayNamesHeader = content.findViewById(R.id.day_names);
    mMonthName = content.findViewById(R.id.month_name);

    setUpHeader();
    setUpListView();
    setUpAdapter();

    // go to today or whichever is close to today min or max date
    mTempDate.setTimeInMillis(System.currentTimeMillis());
    if (mTempDate.before(mMinDate)) {
        goTo(mMinDate, false, true, true);
    } else if (mMaxDate.before(mTempDate)) {
        goTo(mMaxDate, false, true, true);
    } else {
        goTo(mTempDate, false, true, true);
    }

    mDelegator.invalidate();
}
 
Example #29
Source File: DecimalFormat.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a DecimalFormat using the default pattern and symbols
 * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
 * This is a convenient way to obtain a
 * DecimalFormat when internationalization is not the main concern.
 * <p>
 * To obtain standard formats for a given locale, use the factory methods
 * on NumberFormat such as getNumberInstance. These factories will
 * return the most appropriate sub-class of NumberFormat for a given
 * locale.
 *
 * @see java.text.NumberFormat#getInstance
 * @see java.text.NumberFormat#getNumberInstance
 * @see java.text.NumberFormat#getCurrencyInstance
 * @see java.text.NumberFormat#getPercentInstance
 */
public DecimalFormat() {
    // Get the pattern for the default locale.
    Locale def = Locale.getDefault(Locale.Category.FORMAT);
    /* J2ObjC: java.text.spi is not provided.
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def);
    if (!(adapter instanceof ResourceBundleBasedAdapter)) {
        adapter = LocaleProviderAdapter.getResourceBundleBased();
    }
    String[] all = adapter.getLocaleResources(def).getNumberPatterns();*/

    // Always applyPattern after the symbols are set
    this.symbols = DecimalFormatSymbols.getInstance(def);
    applyPattern(LocaleData.get(def).numberPattern, false);
}
 
Example #30
Source File: DateFormat.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}