Example usage for java.util Calendar LONG

List of usage examples for java.util Calendar LONG

Introduction

In this page you can find the example usage for java.util Calendar LONG.

Prototype

int LONG

To view the source code for java.util Calendar LONG.

Click Source Link

Document

A style specifier for #getDisplayName(int,int,Locale) getDisplayName and #getDisplayNames(int,int,Locale) getDisplayNames equivalent to #LONG_FORMAT .

Usage

From source file:mirko.android.datetimepicker.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView/*www .j a  v a  2 s.  c o  m*/
                .setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()));
    }

    if (mSelectedMonthTextView == null) {
        Log.i(TAG, "mSelectedMonthTextView is null updateDisplay");
    }

    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);
    }
}

From source file:com.philliphsu.bottomsheetpickers.date.PagingDayPickerView.java

private static String getMonthAndYearString(CalendarDay day) {
    Calendar cal = Calendar.getInstance();
    cal.set(day.year, day.month, day.day);

    StringBuffer sbuf = new StringBuffer();
    sbuf.append(cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()));
    sbuf.append(" ");
    sbuf.append(YEAR_FORMAT.format(cal.getTime()));
    return sbuf.toString();
}

From source file:com.philliphsu.bottomsheetpickers.date.BottomSheetDatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView/* w w  w .ja  v a  2 s . c om*/
                .setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()));
    }
    String monthAndDay = formatMonthAndDay(mCalendar);
    String year = extractYearFromFormattedDate(formatMonthDayYear(mCalendar), monthAndDay);
    mFirstTextView.setText(mLocaleMonthDayIndex == 0 ? monthAndDay : year);
    mSecondTextView.setText(mLocaleMonthDayIndex == 0 ? year : monthAndDay);

    // 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);
    mMonthDayYearView.setContentDescription(monthAndDayText);

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
    }
}

From source file:org.apache.cordova.core.Globalization.java

@TargetApi(9)
private JSONObject getDateNames(JSONArray options) throws GlobalizationError {
    JSONObject obj = new JSONObject();
    //String[] value;
    JSONArray value = new JSONArray();
    List<String> namesList = new ArrayList<String>();
    final Map<String, Integer> namesMap; // final needed for sorting with anonymous comparator
    try {/*from   ww  w.j a v a2 s.c  om*/
        int type = 0; //default wide
        int item = 0; //default months

        //get options if available
        if (options.getJSONObject(0).length() > 0) {
            //get type if available
            if (!((JSONObject) options.getJSONObject(0).get(OPTIONS)).isNull(TYPE)) {
                String t = (String) ((JSONObject) options.getJSONObject(0).get(OPTIONS)).get(TYPE);
                if (t.equalsIgnoreCase(NARROW)) {
                    type++;
                } //DateUtils.LENGTH_MEDIUM
            }
            //get item if available
            if (!((JSONObject) options.getJSONObject(0).get(OPTIONS)).isNull(ITEM)) {
                String t = (String) ((JSONObject) options.getJSONObject(0).get(OPTIONS)).get(ITEM);
                if (t.equalsIgnoreCase(DAYS)) {
                    item += 10;
                } //Days of week start at 1
            }
        }
        //determine return value
        int method = item + type;
        if (method == 1) { //months and narrow
            namesMap = Calendar.getInstance().getDisplayNames(Calendar.MONTH, Calendar.SHORT,
                    Locale.getDefault());
        } else if (method == 10) { //days and wide
            namesMap = Calendar.getInstance().getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG,
                    Locale.getDefault());
        } else if (method == 11) { //days and narrow
            namesMap = Calendar.getInstance().getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.SHORT,
                    Locale.getDefault());
        } else { //default: months and wide
            namesMap = Calendar.getInstance().getDisplayNames(Calendar.MONTH, Calendar.LONG,
                    Locale.getDefault());
        }

        // save names as a list
        for (String name : namesMap.keySet()) {
            namesList.add(name);
        }

        // sort the list according to values in namesMap
        Collections.sort(namesList, new Comparator<String>() {
            public int compare(String arg0, String arg1) {
                return namesMap.get(arg0).compareTo(namesMap.get(arg1));
            }
        });

        // convert nameList into JSONArray of String objects
        for (int i = 0; i < namesList.size(); i++) {
            value.put(namesList.get(i));
        }

        //return array of names
        return obj.put("value", value);
    } catch (Exception ge) {
        throw new GlobalizationError(GlobalizationError.UNKNOWN_ERROR);
    }
}

From source file:com.borax12.materialdaterangepicker.single.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        if (mTitle != null)
            mDayOfWeekView.setText(mTitle.toUpperCase(Locale.getDefault()));
        else {/*w w  w. ja  v a  2s.c o m*/
            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);
    }
}

From source file:com.example.reedme.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        if (mTitle != null)
            mDayOfWeekView.setText(mTitle.toUpperCase(Locale.getDefault()));
        else {//w w  w  .  ja  v a 2s.  com
            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);
        Util.tryAccessibilityAnnounce(mAnimator, fullDateText);
    }
}

From source file:com.layernet.thaidatetimepicker.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        if (mTitle != null)
            mDayOfWeekView.setText(mTitle.toUpperCase(locale));
        else {/*from  w w w  . j a v  a  2s . co  m*/
            mDayOfWeekView.setText(
                    mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, locale).toUpperCase(locale));
        }
    }

    mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale));
    mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));

    /** thai calender edit */
    int Year = mCalendar.get(Calendar.YEAR) + BUDDHIST_OFFSET;
    mYearView.setText(String.valueOf(Year));
    /** end thai calendar edit */

    // 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 + 5555);

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
    }
}

From source file:com.jarklee.materialdatetimepicker.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        if (mTitle != null)
            mDayOfWeekView.setText(mTitle.toUpperCase(getLocale()));
        else {/*from ww w  . j ava2s  .com*/
            mDayOfWeekView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, getLocale())
                    .toUpperCase(getLocale()));
        }
    }

    mSelectedMonthTextView.setText(
            mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, getLocale()).toUpperCase(getLocale()));
    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);
    }
}

From source file:com.customdatepicker.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));

    if (mVersion == Version.VERSION_1) {
        if (mDatePickerHeaderView != null) {
            if (mTitle != null)
                mDatePickerHeaderView.setText(mTitle.toUpperCase(Locale.getDefault()));
            else {
                mDatePickerHeaderView.setText(
                        mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())
                                .toUpperCase(Locale.getDefault()));
            }//  www  .  j a v a2  s  . co  m
        }
        mSelectedMonthTextView.setText(MONTH_FORMAT.format(mCalendar.getTime()));
        mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    }

    if (mVersion == Version.VERSION_2) {
        mSelectedDayTextView.setText(VERSION_2_FORMAT.format(mCalendar.getTime()));
        if (mTitle != null)
            mDatePickerHeaderView.setText(mTitle.toUpperCase(Locale.getDefault()));
        else
            mDatePickerHeaderView.setVisibility(View.GONE);
    }

    // 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);
    }
}

From source file:com.leavjenn.smoothdaterangepicker.date.SmoothDateRangePickerFragment.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null && mDayOfWeekViewEnd != null) {
        mDayOfWeekView/*from www .  j  a  v  a 2 s.c o m*/
                .setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()));
        mDayOfWeekViewEnd
                .setText(mCalendarEnd.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()));
    mDuration = Utils.daysBetween(mCalendar, mCalendarEnd);
    mDurationTextView.setText(String.valueOf(mDuration));
    mDurationDayTextView.setText(mDuration > 1 ? getString(R.string.days) : getString(R.string.day));

    // Accessibility.
    long millis = mCalendar.getTimeInMillis();
    long millisEnd = mCalendarEnd.getTimeInMillis();
    mAnimator.setDateMillis(millis);
    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);
    }
}