Search in sources :

Example 21 with DateFormatSymbols

use of java.text.DateFormatSymbols in project checker-framework by typetools.

the class Calendar method getDisplayNamesImpl.

private Map<String, Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
    DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
    String[] strings = getFieldStrings(field, style, symbols);
    if (strings != null) {
        Map<String, Integer> names = new HashMap<String, Integer>();
        for (int i = 0; i < strings.length; i++) {
            if (strings[i].length() == 0) {
                continue;
            }
            names.put(strings[i], i);
        }
        return names;
    }
    return null;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DateFormatSymbols(java.text.DateFormatSymbols)

Example 22 with DateFormatSymbols

use of java.text.DateFormatSymbols in project checker-framework by typetools.

the class Calendar method getDisplayName.

/**
 * Returns the string representation of the calendar
 * <code>field</code> value in the given <code>style</code> and
 * <code>locale</code>.  If no string representation is
 * applicable, <code>null</code> is returned. This method calls
 * {@link Calendar#get(int) get(field)} to get the calendar
 * <code>field</code> value if the string representation is
 * applicable to the given calendar <code>field</code>.
 * <p>
 * <p>For example, if this <code>Calendar</code> is a
 * <code>GregorianCalendar</code> and its date is 2005-01-01, then
 * the string representation of the {@link #MONTH} field would be
 * "January" in the long style in an English locale or "Jan" in
 * the short style. However, no string representation would be
 * available for the {@link #DAY_OF_MONTH} field, and this method
 * would return <code>null</code>.
 * <p>
 * <p>The default implementation supports the calendar fields for
 * which a {@link DateFormatSymbols} has names in the given
 * <code>locale</code>.
 *
 * @param field  the calendar field for which the string representation
 *               is returned
 * @param style  the style applied to the string representation; one of
 *               {@link #SHORT} or {@link #LONG}.
 * @param locale the locale for the string representation
 * @return the string representation of the given
 * <code>field</code> in the given <code>style</code>, or
 * <code>null</code> if no string representation is
 * applicable.
 * @throws IllegalArgumentException if <code>field</code> or <code>style</code> is invalid,
 *                                  or if this <code>Calendar</code> is non-lenient and any
 *                                  of the calendar fields have invalid values
 * @throws NullPointerException     if <code>locale</code> is null
 * @since 1.6
 */
public String getDisplayName(@NonNegative int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, ALL_STYLES, LONG, locale, ERA_MASK | MONTH_MASK | DAY_OF_WEEK_MASK | AM_PM_MASK)) {
        return null;
    }
    DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
    String[] strings = getFieldStrings(field, style, symbols);
    if (strings != null) {
        int fieldValue = get(field);
        if (fieldValue < strings.length) {
            return strings[fieldValue];
        }
    }
    return null;
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols)

Example 23 with DateFormatSymbols

use of java.text.DateFormatSymbols in project android_packages_apps_OmniClock by omnirom.

the class DaysOfWeek method toString.

private String toString(Context context, boolean showNever, boolean forAccessibility, int... daysOfWeek) {
    StringBuilder ret = new StringBuilder();
    // no days
    if (mBitSet == NO_DAYS_SET) {
        return showNever ? context.getText(org.omnirom.deskclock.R.string.never).toString() : "";
    }
    // every day
    if (mBitSet == ALL_DAYS_SET) {
        return context.getText(org.omnirom.deskclock.R.string.every_day).toString();
    }
    // count selected days
    int dayCount = 0;
    int bitSet = mBitSet;
    while (bitSet > 0) {
        if ((bitSet & 1) == 1)
            dayCount++;
        bitSet >>= 1;
    }
    // short or long form?
    DateFormatSymbols dfs = new DateFormatSymbols();
    String[] dayList = (forAccessibility || dayCount <= 1) ? dfs.getWeekdays() : dfs.getShortWeekdays();
    // selected days
    for (int day : daysOfWeek) {
        int bitIndex = convertDayToBitIndex(day);
        if ((mBitSet & (1 << bitIndex)) != 0) {
            ret.append(dayList[convertBitIndexToDay(bitIndex)]);
            dayCount -= 1;
            if (dayCount > 0)
                ret.append(context.getText(org.omnirom.deskclock.R.string.day_concat));
        }
    }
    return ret.toString();
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols)

Example 24 with DateFormatSymbols

use of java.text.DateFormatSymbols in project android_packages_apps_OmniClock by omnirom.

the class AmPmCirclesView method initialize.

public void initialize(Context context, TimePickerController controller, int amOrPm) {
    if (mIsInitialized) {
        Log.e(TAG, "AmPmCirclesView may only be initialized once.");
        return;
    }
    Resources res = context.getResources();
    if (controller.isThemeDark()) {
        mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_circle_background_dark_theme);
        mAmPmTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
        mAmPmDisabledTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled_dark_theme);
        mSelectedAlpha = SELECTED_ALPHA_THEME_DARK;
    } else {
        mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_circle_color);
        mAmPmTextColor = ContextCompat.getColor(context, R.color.mdtp_ampm_text_color);
        mAmPmDisabledTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled);
        mSelectedAlpha = SELECTED_ALPHA;
    }
    mSelectedColor = controller.getAccentColor();
    mTouchedColor = Utils.darkenColor(mSelectedColor);
    mAmPmSelectedTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
    String typefaceFamily = res.getString(R.string.mdtp_sans_serif);
    Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
    mPaint.setTypeface(tf);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);
    mCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.mdtp_circle_radius_multiplier));
    mAmPmCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.mdtp_ampm_circle_radius_multiplier));
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];
    mAmDisabled = controller.isAmDisabled();
    mPmDisabled = controller.isPmDisabled();
    setAmOrPm(amOrPm);
    mAmOrPmPressed = -1;
    mIsInitialized = true;
}
Also used : Typeface(android.graphics.Typeface) DateFormatSymbols(java.text.DateFormatSymbols) Resources(android.content.res.Resources)

Example 25 with DateFormatSymbols

use of java.text.DateFormatSymbols in project android_packages_apps_OmniClock by omnirom.

the class SettingsActivity method getWeekdays.

private String[] getWeekdays() {
    DateFormatSymbols dfs = new DateFormatSymbols();
    List<String> weekDayList = new ArrayList<String>();
    weekDayList.addAll(Arrays.asList(dfs.getWeekdays()));
    weekDayList.set(0, getResources().getString(R.string.default_week_start));
    return weekDayList.toArray(new String[weekDayList.size()]);
}
Also used : ArrayList(java.util.ArrayList) DateFormatSymbols(java.text.DateFormatSymbols)

Aggregations

DateFormatSymbols (java.text.DateFormatSymbols)140 SimpleDateFormat (java.text.SimpleDateFormat)38 Date (java.util.Date)26 ArrayList (java.util.ArrayList)23 Locale (java.util.Locale)21 Resources (android.content.res.Resources)15 View (android.view.View)14 TextView (android.widget.TextView)12 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)9 List (java.util.List)8 OnClickListener (android.view.View.OnClickListener)7 Test (org.junit.Test)7 Typeface (android.graphics.Typeface)6 RelativeLayout (android.widget.RelativeLayout)6 LayoutParams (android.app.ActionBar.LayoutParams)5 IOException (java.io.IOException)5 TypedArray (android.content.res.TypedArray)4 AdapterView (android.widget.AdapterView)4 Button (android.widget.Button)4