Search in sources :

Example 6 with LocaleData

use of libcore.icu.LocaleData in project android_frameworks_base by ResurrectionRemix.

the class TimePicker method getAmPmStrings.

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;
}
Also used : Locale(java.util.Locale) LocaleData(libcore.icu.LocaleData)

Example 7 with LocaleData

use of libcore.icu.LocaleData in project android_frameworks_base by ResurrectionRemix.

the class TextClock method init.

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);
    // Wait until registering for events to handle the ticker
    chooseFormat(false);
}
Also used : LocaleData(libcore.icu.LocaleData)

Example 8 with LocaleData

use of libcore.icu.LocaleData in project android_frameworks_base by ResurrectionRemix.

the class TextClock method chooseFormat.

/**
     * Selects either one of {@link #getFormat12Hour()} or {@link #getFormat24Hour()}
     * depending on whether the user has selected 24-hour format.
     *
     * @param handleTicker true if calling this method should schedule/unschedule the
     *                     time ticker, false otherwise
     */
private void chooseFormat(boolean handleTicker) {
    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 (handleTicker && mRegistered && hadSeconds != mHasSeconds) {
        if (hadSeconds)
            getHandler().removeCallbacks(mTicker);
        else
            mTicker.run();
    }
}
Also used : LocaleData(libcore.icu.LocaleData)

Example 9 with LocaleData

use of libcore.icu.LocaleData in project android_frameworks_base by ResurrectionRemix.

the class DateUtils method getDayOfWeekString.

/**
     * 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;
        // TODO
        case LENGTH_SHORT:
            names = d.shortWeekdayNames;
            break;
        // TODO
        case LENGTH_SHORTER:
            names = d.shortWeekdayNames;
            break;
        case LENGTH_SHORTEST:
            names = d.tinyWeekdayNames;
            break;
        default:
            names = d.shortWeekdayNames;
            break;
    }
    return names[dayOfWeek];
}
Also used : LocaleData(libcore.icu.LocaleData)

Example 10 with LocaleData

use of libcore.icu.LocaleData in project android_frameworks_base by ResurrectionRemix.

the class DateUtils method getMonthString.

/**
     * 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];
}
Also used : LocaleData(libcore.icu.LocaleData)

Aggregations

LocaleData (libcore.icu.LocaleData)78 SpannableStringBuilder (android.text.SpannableStringBuilder)12 Locale (java.util.Locale)11 Test (org.junit.Test)8 Context (android.content.Context)6 Spanned (android.text.Spanned)6 SpannedString (android.text.SpannedString)6 CharacterStyle (android.text.style.CharacterStyle)6 RelativeSizeSpan (android.text.style.RelativeSizeSpan)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Config (org.robolectric.annotation.Config)6 Date (java.util.Date)3 Resources (android.content.res.Resources)1 Implementation (org.robolectric.annotation.Implementation)1