Java Code Examples for android.text.format.DateUtils#getDayOfWeekString()

The following examples show how to use android.text.format.DateUtils#getDayOfWeekString() . 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: CalendarViewLegacyDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the strings to be used by the header.
 */
private void setUpHeader() {
    mDayNamesShort = new String[mDaysPerWeek];
    mDayNamesLong = new String[mDaysPerWeek];
    for (int i = mFirstDayOfWeek, count = mFirstDayOfWeek + mDaysPerWeek; i < count; i++) {
        int calendarDay = (i > Calendar.SATURDAY) ? i - Calendar.SATURDAY : i;
        mDayNamesShort[i - mFirstDayOfWeek] = DateUtils.getDayOfWeekString(calendarDay,
                DateUtils.LENGTH_SHORTEST);
        mDayNamesLong[i - mFirstDayOfWeek] = DateUtils.getDayOfWeekString(calendarDay,
                DateUtils.LENGTH_LONG);
    }

    TextView label = (TextView) mDayNamesHeader.getChildAt(0);
    if (mShowWeekNumber) {
        label.setVisibility(View.VISIBLE);
    } else {
        label.setVisibility(View.GONE);
    }
    for (int i = 1, count = mDayNamesHeader.getChildCount(); i < count; i++) {
        label = (TextView) mDayNamesHeader.getChildAt(i);
        if (mWeekDayTextAppearanceResId > -1) {
            label.setTextAppearance(mWeekDayTextAppearanceResId);
        }
        if (i < mDaysPerWeek + 1) {
            label.setText(mDayNamesShort[i - 1]);
            label.setContentDescription(mDayNamesLong[i - 1]);
            label.setVisibility(View.VISIBLE);
        } else {
            label.setVisibility(View.GONE);
        }
    }
    mDayNamesHeader.invalidate();
}
 
Example 2
Source File: DateFormatUtils.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
public static String formatDayOfWeek(SimpleDateFormat formatter, Calendar calendar) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return formatter.format(calendar.getTime());
    } else {
        // Use DateUtils on older devices (Saturday = 7)
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        return DateUtils.getDayOfWeekString((dayOfWeek == 0) ? 7 : dayOfWeek, DateUtils.LENGTH_SHORTEST);
    }
}
 
Example 3
Source File: EventRecurrenceFormatter.java    From SublimePicker with Apache License 2.0 2 votes vote down vote up
/**
 * Converts day of week to a String.
 * @param day a EventRecurrence constant
 * @return day of week as a string
 */
private static String dayToString(int day, int dayOfWeekLength) {
    return DateUtils.getDayOfWeekString(dayToUtilDay(day), dayOfWeekLength);
}
 
Example 4
Source File: SuntimesUtils.java    From SuntimesWidget with GNU General Public License v3.0 2 votes vote down vote up
/**
 * getDayString
 * @param context Context
 * @param day e.g. Calendar.SUNDAY
 * @return "Sunday"
 */
public String getDayString(Context context, int day)
{
    return DateUtils.getDayOfWeekString(day, DateUtils.LENGTH_LONG);
}
 
Example 5
Source File: EventRecurrenceFormatter.java    From Android-RecurrencePicker with Apache License 2.0 2 votes vote down vote up
/**
 * Converts day of week to a String.
 * @param day a EventRecurrence constant
 * @return day of week as a string
 */
private static String dayToString(int day, int dayOfWeekLength) {
    return DateUtils.getDayOfWeekString(dayToUtilDay(day), dayOfWeekLength);
}