Java Code Examples for android.text.format.DateUtils#FORMAT_SHOW_YEAR

The following examples show how to use android.text.format.DateUtils#FORMAT_SHOW_YEAR . 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: DatePickerCalendarDelegate.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
private void onCurrentDateChanged(boolean announce) {
    if (mHeaderYear == null) {
        // Abort, we haven't initialized yet. This method will get called
        // again later after everything has been set up.
        return;
    }

    final String year = mYearFormat.format(mCurrentDate.getTime());
    mHeaderYear.setText(year);

    final String monthDay = mMonthDayFormat.format(mCurrentDate.getTime());
    mHeaderMonthDay.setText(monthDay);

    // TODO: This should use live regions.
    if (announce) {
        final long millis = mCurrentDate.getTimeInMillis();
        final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        final String fullDateText = DateUtils.formatDateTime(mContext, millis, flags);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mAnimator.announceForAccessibility(fullDateText); // FIXME we need this on pre-16 devices
        }
    }
}
 
Example 2
Source File: Utils.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static String formatTime(Context context, long when) {
	// TODO: DateUtils should make this easier
	Time then = new Time();
	then.set(when);
	Time now = new Time();
	now.setToNow();

	int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL;

	if (then.year != now.year) {
		flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
	} else if (then.yearDay != now.yearDay) {
		flags |= DateUtils.FORMAT_SHOW_DATE;
	} else {
		flags |= DateUtils.FORMAT_SHOW_TIME;
	}

	return DateUtils.formatDateTime(context, when, flags);
}
 
Example 3
Source File: Utils.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static String formatTime(Context context, long when) {
	// TODO: DateUtils should make this easier
	Time then = new Time();
	then.set(when);
	Time now = new Time();
	now.setToNow();

	int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL;

	if (then.year != now.year) {
		flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
	} else if (then.yearDay != now.yearDay) {
		flags |= DateUtils.FORMAT_SHOW_DATE;
	} else {
		flags |= DateUtils.FORMAT_SHOW_TIME;
	}

	return DateUtils.formatDateTime(context, when, flags);
}
 
Example 4
Source File: DatePickerDialog.java    From MaterialDateRangePicker with Apache License 2.0 5 votes vote down vote up
private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
                Locale.getDefault()).toUpperCase(Locale.getDefault()));
    }

    mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT,
            Locale.getDefault()).toUpperCase(Locale.getDefault()));
    mSelectedMonthTextViewEnd.setText(mCalendarEnd.getDisplayName(Calendar.MONTH, Calendar.SHORT,
            Locale.getDefault()).toUpperCase(Locale.getDefault()));
    mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    mSelectedDayTextViewEnd.setText(DAY_FORMAT.format(mCalendarEnd.getTime()));
    mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));
    mYearViewEnd.setText(YEAR_FORMAT.format(mCalendarEnd.getTime()));

    // Accessibility.
    long millis = mCalendar.getTimeInMillis();
    long millisEnd = mCalendarEnd.getTimeInMillis();
    mAnimator.setDateMillis(millis);
    mAnimatorEnd.setDateMillis(millisEnd);
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
    String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags);
    String monthAndDayTextEnd = DateUtils.formatDateTime(getActivity(), millisEnd, flags);
    mMonthAndDayView.setContentDescription(monthAndDayText);
    mMonthAndDayViewEnd.setContentDescription(monthAndDayTextEnd);

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        String fullDateTextEnd = DateUtils.formatDateTime(getActivity(), millisEnd, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
        Utils.tryAccessibilityAnnounce(mAnimatorEnd, fullDateTextEnd);
    }
}
 
Example 5
Source File: SimpleMonthView.java    From CalendarView with Apache License 2.0 5 votes vote down vote up
/**
 * 获取年份和月份
 *
 * @return
 */
private String getMonthAndYearString() {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
    mStringBuilder.setLength(0);
    long millis = mCalendar.getTimeInMillis();
    return DateUtils.formatDateRange(getContext(), millis, millis, flags);
}
 
Example 6
Source File: AccessibleDateAnimator.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Announce the currently-selected date when launched.
 */
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current date will be spoken.
        event.getText().clear();
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
                DateUtils.FORMAT_SHOW_WEEKDAY;

        String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
        event.getText().add(dateString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
Example 7
Source File: DatePickerSpinnerDelegate.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
    String selectedDateUtterance = DateUtils.formatDateTime(mContext,
            mCurrentDate.getTimeInMillis(), flags);
    event.getText().add(selectedDateUtterance);
}
 
Example 8
Source File: MonthView.java    From StyleableDateTimePicker with MIT License 5 votes vote down vote up
private String getMonthAndYearString() {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
            | DateUtils.FORMAT_NO_MONTH_DAY;
    mStringBuilder.setLength(0);
    long millis = mCalendar.getTimeInMillis();
    return DateUtils.formatDateRange(getContext(), mFormatter, millis, millis, flags,
            Time.getCurrentTimezone()).toString();
}
 
Example 9
Source File: AirMonthView.java    From AirCalendar with MIT License 5 votes vote down vote up
private String getMonthAndYearString() {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
    mStringBuilder.setLength(0);

    long millis = mCalendar.getTimeInMillis();
    return DateUtils.formatDateRange(getContext(), millis, millis, flags);    // 지역화된 포멧으로 출력
}
 
Example 10
Source File: AccessibleDateAnimator.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
/**
 * Announce the currently-selected date when launched.
 */
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current date will be spoken.
        event.getText().clear();
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
                DateUtils.FORMAT_SHOW_WEEKDAY;

        String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
        event.getText().add(dateString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
Example 11
Source File: DatePickerDialog.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        if(mTitle != null) mDayOfWeekView.setText(mTitle.toUpperCase(Locale.getDefault()));
        else {
            mDayOfWeekView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
                    Locale.getDefault()).toUpperCase(Locale.getDefault()));
        }
    }

    mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT,
            Locale.getDefault()).toUpperCase(Locale.getDefault()));
    mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));

    // Accessibility.
    long millis = mCalendar.getTimeInMillis();
    mAnimator.setDateMillis(millis);
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
    String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags);
    mMonthAndDayView.setContentDescription(monthAndDayText);

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
    }
}
 
Example 12
Source File: DateFormatter.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public int getDateUtilsFlags(Time now, Time date)
{
    int result = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH;
    if (!date.allDay)
    {
        result |= FORMAT_SHOW_TIME;
    }
    if (now.year != date.year)
    {
        result |= DateUtils.FORMAT_SHOW_YEAR;
    }
    return result;
}
 
Example 13
Source File: TimeUtils.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String getNoMonthDay(Context context, Date date) {
    if (date == null) return "";
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    int flags = DateUtils.FORMAT_ABBREV_MONTH;
    flags |= DateUtils.FORMAT_NO_MONTH_DAY;
    flags = flags | DateUtils.FORMAT_SHOW_YEAR;
    return DateUtils.formatDateTime(context, date.getTime(), flags);
}
 
Example 14
Source File: RecurrenceEndDatePicker.java    From SublimePicker with Apache License 2.0 5 votes vote down vote up
private void onCurrentDateChanged(boolean announce) {
    if (mDayPickerView == null) {
        // Abort, we haven't initialized yet. This method will get called
        // again later after everything has been set up.
        return;
    }

    // TODO: This should use live regions.
    if (announce) {
        final long millis = mCurrentDate.getStartDate().getTimeInMillis();
        final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        final String fullDateText = DateUtils.formatDateTime(mContext, millis, flags);
        AccessibilityUtils.makeAnnouncement(mDayPickerView, fullDateText);
    }
}
 
Example 15
Source File: TwoFieldDatePicker.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);

    final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
    String selectedDateUtterance = DateUtils.formatDateTime(getContext(),
            mCurrentDate.getTimeInMillis(), flags);
    event.getText().add(selectedDateUtterance);
}
 
Example 16
Source File: AccessibleDateAnimator.java    From DateTimepicker with Apache License 2.0 5 votes vote down vote up
/**
 * Announce the currently-selected date when launched.
 */
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current date will be spoken.
        event.getText().clear();
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
                DateUtils.FORMAT_SHOW_WEEKDAY;

        String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
        event.getText().add(dateString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
Example 17
Source File: DatePickerDialog.java    From date_picker_converter with Apache License 2.0 4 votes vote down vote up
private void updateDisplay(boolean announce) {
    mYearView.setText(String.valueOf(mCalendar.getYear()));

    if (mVersion == Version.VERSION_1) {
        if (mDatePickerHeaderView != null) {
            if (mTitle != null)
                mDatePickerHeaderView.setText(mTitle.toUpperCase(mLocale));
            else {
                mDatePickerHeaderView.setText(Utils.getDayOfWeek(mCalendar.getDayOfWeek()).toUpperCase());
            }
        }
        mSelectedMonthTextView.setText(getResources().getString(DateConverter.getNepaliMonthString(mCalendar.getMonth())));
        mSelectedDayTextView.setText(String.valueOf(mCalendar.getDay()));
    }

    if (mVersion == Version.VERSION_2) {
        //        mSelectedDayTextView.setText(VERSION_2_FORMAT.format(mCalendar.getTime()));

        String mText = (Utils.getDayOfWeek((dc.getWeekDay(mCalendar.getYear(), mCalendar.getMonth() + 1, mCalendar.getDay())))).substring(0, 3) + ", "
                + getResources().getString(DateConverter.getNepaliMonthString(mCalendar.getMonth())) + " " + mCalendar.getDay();
        mSelectedDayTextView.setText(mText);

        if (mTitle != null)
            mDatePickerHeaderView.setText(mTitle.toUpperCase(mLocale));
        else
            mDatePickerHeaderView.setVisibility(View.GONE);
    }


     /*
     mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT,
            Locale.getDefault()).toUpperCase(Locale.getDefault()));
      */


    // Accessibility.
    long millis = Calendar.getInstance().getTimeInMillis();
    mAnimator.setDateMillis(millis);
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
    String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags);
    mMonthAndDayView.setContentDescription(monthAndDayText);

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
    }
}
 
Example 18
Source File: MainActivity.java    From samples with MIT License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    final long min;
    switch (item.getItemId()) {
        case R.id.min_0:
            min = 0l;
            break;
        case R.id.min_min:
            min = DateUtils.MINUTE_IN_MILLIS;
            break;
        case R.id.min_hour:
            min = DateUtils.HOUR_IN_MILLIS;
            break;
        case R.id.min_day:
            min = DateUtils.DAY_IN_MILLIS;
            break;
        default:
            min = -1;
            break;
    }

    if (min >= 0) {
        item.setChecked(true);
        mAdapter.setMinResolution(min);
        return true;
    }

    item.setChecked(!item.isChecked());
    final int flag;
    switch (item.getItemId()) {
        case R.id.FORMAT_SHOW_TIME:
            flag = DateUtils.FORMAT_SHOW_TIME;
            break;
        case R.id.FORMAT_SHOW_WEEKDAY:
            flag = DateUtils.FORMAT_SHOW_WEEKDAY;
            break;
        case R.id.FORMAT_SHOW_YEAR:
            flag = DateUtils.FORMAT_SHOW_YEAR;
            break;
        case R.id.FORMAT_NO_YEAR:
            flag = DateUtils.FORMAT_NO_YEAR;
            break;
        case R.id.FORMAT_SHOW_DATE:
            flag = DateUtils.FORMAT_SHOW_DATE;
            break;
        case R.id.FORMAT_NO_MONTH_DAY:
            flag = DateUtils.FORMAT_NO_MONTH_DAY;
            break;
        case R.id.FORMAT_NO_NOON:
            flag = DateUtils.FORMAT_NO_NOON;
            break;
        case R.id.FORMAT_NO_MIDNIGHT:
            flag = DateUtils.FORMAT_NO_MIDNIGHT;
            break;
        case R.id.FORMAT_ABBREV_TIME:
            flag = DateUtils.FORMAT_ABBREV_TIME;
            break;
        case R.id.FORMAT_ABBREV_WEEKDAY:
            flag = DateUtils.FORMAT_ABBREV_WEEKDAY;
            break;
        case R.id.FORMAT_ABBREV_MONTH:
            flag = DateUtils.FORMAT_ABBREV_MONTH;
            break;
        case R.id.FORMAT_NUMERIC_DATE:
            flag = DateUtils.FORMAT_NUMERIC_DATE;
            break;
        case R.id.FORMAT_ABBREV_RELATIVE:
            flag = DateUtils.FORMAT_ABBREV_RELATIVE;
            break;
        case R.id.FORMAT_ABBREV_ALL:
            flag = DateUtils.FORMAT_ABBREV_ALL;
            break;
        default:
            throw new UnsupportedOperationException("unknown id");
    }

    if (item.isChecked()) {
        mAdapter.addFlag(flag);
    } else {
        mAdapter.removeFlag(flag);
    }

    return true;
}
 
Example 19
Source File: DatePickerDialog.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
private static String formatMonthDayYear(Calendar calendar) {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_YEAR;
    return formatDate(calendar, flags);
}
 
Example 20
Source File: SublimeDatePicker.java    From SublimePicker with Apache License 2.0 4 votes vote down vote up
private void onCurrentDateChanged(boolean announce) {
    if (mHeaderYear == null) {
        // Abort, we haven't initialized yet. This method will get called
        // again later after everything has been set up.
        return;
    }

    final String year = mYearFormat.format(mCurrentDate.getStartDate().getTime());
    mHeaderYear.setText(year);

    final String monthDay = mMonthDayFormat.format(mCurrentDate.getStartDate().getTime());
    mHeaderMonthDay.setText(monthDay);

    final String yearStrStart = mYearFormat.format(mCurrentDate.getStartDate().getTime());
    final String monthDayStrStart = mMonthDayFormat.format(mCurrentDate.getStartDate().getTime());
    final String dateStrStart = yearStrStart + "\n" + monthDayStrStart;

    final String yearStrEnd = mYearFormat.format(mCurrentDate.getEndDate().getTime());
    final String monthDayStrEnd = mMonthDayFormat.format(mCurrentDate.getEndDate().getTime());
    final String dateStrEnd = yearStrEnd + "\n" + monthDayStrEnd;

    SpannableString spDateStart = new SpannableString(dateStrStart);
    // If textSize is 34dp for land, use 0.47f
    //spDateStart.setSpan(new RelativeSizeSpan(mIsInLandscapeMode ? 0.47f : 0.7f),
    spDateStart.setSpan(new RelativeSizeSpan(0.7f),
            0, yearStrStart.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    SpannableString spDateEnd = new SpannableString(dateStrEnd);
    spDateEnd.setSpan(new RelativeSizeSpan(0.7f),
            0, yearStrEnd.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // API <= 16
    if (!mIsInLandscapeMode && !SUtils.isApi_17_OrHigher()) {
        spDateEnd.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE),
                0, dateStrEnd.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    tvHeaderDateStart.setText(spDateStart);
    tvHeaderDateEnd.setText(spDateEnd);

    // TODO: This should use live regions.
    if (announce) {
        final long millis = mCurrentDate.getStartDate().getTimeInMillis();
        final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        final String fullDateText = DateUtils.formatDateTime(mContext, millis, flags);
        AccessibilityUtils.makeAnnouncement(mAnimator, fullDateText);
    }
}