Example usage for java.util Calendar SHORT

List of usage examples for java.util Calendar SHORT

Introduction

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

Prototype

int SHORT

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

Click Source Link

Document

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

Usage

From source file:de.linuxwhatelse.android.notify.activities.MainActivity.java

private void handleSnoozedNotification() {
    this.initChannels(this, getString(R.string.notification_channel_snooze));

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    boolean notificationsSnoozed = preferences.getBoolean(Notify.PREFERENCE_KEY_NOTIFICATIONS_SNOOZED, false);
    boolean eventsSnoozed = preferences.getBoolean(Notify.PREFERENCE_KEY_EVENTS_SNOOZED, false);
    long snoozeUntil = preferences.getLong(Notify.PREFERENCE_KEY_SNOOZED_UNTIL, -1);

    if (!notificationsSnoozed && !eventsSnoozed) {
        notificationManager.cancel(Notify.NOTIFICATION_ID_SNOOZE);
        return;//from  w w w  . j  a  v  a2  s .com
    }

    String title = getString(R.string.snoozed_notifications_title);
    if (notificationsSnoozed && eventsSnoozed) {
        title = getString(R.string.snoozed_all_title);
    }

    String body = getString(R.string.snoozed_text_resume_indefinitely);
    if (snoozeUntil != -1) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(snoozeUntil);
        String day = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault());
        String time = (new SimpleDateFormat("HH:mm", getResources().getConfiguration().locale))
                .format(cal.getTime());

        body = getString(R.string.snoozed_text_resume_at) + " " + day + " " + time;
    }

    Intent activityIntent = new Intent(context, MainActivity.class);
    activityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0, activityIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, Notify.NOTIFICATION_CHANNEL)
            .setContentTitle(title).setContentText(body).setSmallIcon(R.drawable.ic_notifications_paused)
            .setPriority(NotificationCompat.PRIORITY_LOW).setContentIntent(activityPendingIntent)
            .setOngoing(true);

    Intent intent = new Intent(getApplicationContext(), SnoozeEndReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_notifications_active,
            getString(R.string.snoozed_action_resume), pendingIntent).build();
    mBuilder.addAction(action);

    notificationManager.notify(Notify.NOTIFICATION_ID_SNOOZE, mBuilder.build());
}

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

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView//w w w  . j  a  v a 2 s  .com
                .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:mirko.android.datetimepicker.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView//from   w ww  .j av  a 2s  . com
                .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.kunze.androidlocaltodo.TaskActivityFragment.java

private static void SetFriendlyDueDateText(TextView dueDateView, Calendar dueDate) {
    SimpleDateFormat dateFormatDisplay = new SimpleDateFormat("MM-dd-yyyy", Locale.US);
    Calendar now = Calendar.getInstance();
    int nowDay = TaskDatabase.ConvertDateToInt(now);
    int dueDay = TaskDatabase.ConvertDateToInt(dueDate);
    int dayDiff = nowDay - dueDay;
    if (dayDiff == 0) {
        dueDateView.setText("Today");
        dueDateView.setTextColor(Color.RED);
    } else if (dueDate.before(now)) {
        dueDateView.setText("+ " + dayDiff + " days!");
        dueDateView.setTextColor(Color.RED);
    } else if (dayDiff > -7) {
        dueDateView.setText(dueDate.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.US));
        dueDateView.setTextColor(Color.BLACK);
    } else if (dayDiff > -14) {
        dueDateView.setText("Next " + dueDate.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.US));
        dueDateView.setTextColor(Color.BLACK);
    } else {/*from w w w  .  j  av a  2s  . c  o  m*/
        dueDateView.setText(dateFormatDisplay.format(dueDate.getTime()));
        dueDateView.setTextColor(Color.BLACK);
    }
}

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 {/*w  w w .ja  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:org.holoeverywhere.widget.datetimepicker.date.SimpleMonthView.java

private void drawMonthDayLabels(Canvas canvas) {
    int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
    int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);

    for (int i = 0; i < mNumDays; i++) {
        int calendarDay = (i + mWeekStart) % mNumDays;
        int x = (2 * i + 1) * dayWidthHalf + mPadding;
        mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
        canvas.drawText(DatePickerDialog
                .getDisplayName(mDayLabelCalendar, Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())
                .toUpperCase(Locale.getDefault()), x, y, mMonthDayLabelPaint);
    }/*from   w w  w  .  ja v  a2 s.c  o  m*/
}

From source file:app.android.datetimepicker.date.SimpleMonthView.java

private void drawMonthDayLabels(Canvas canvas) {
    int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
    int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);

    for (int i = 0; i < mNumDays; i++) {
        int calendarDay = (i + mWeekStart) % mNumDays;
        int x = (2 * i + 1) * dayWidthHalf + mPadding;
        mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
        canvas.drawText(/*  ww w  . java2s .c om*/
                mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()),
                x, y, mMonthDayLabelPaint);
    }
}

From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.SimpleMonthView.java

private void drawMonthDayLabels(Canvas canvas) {
    int y = sMonthHeaderSize - (sMonthDayLabelTextSize / 2);
    int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);

    for (int i = 0; i < mNumDays; i++) {
        int calendarDay = (i + mWeekStart) % mNumDays;
        int x = (2 * i + 1) * dayWidthHalf + mPadding;
        mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
        canvas.drawText(/*from  w  ww . j a v a 2s. c o m*/
                mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()),
                x, y, mMonthDayLabelPaint);
    }
}

From source file:com.android.datetimepicker.date.MonthView.java

protected void drawMonthDayLabels(Canvas canvas) {
    int y = getMonthHeaderSize() - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
    int dayWidthHalf = (mWidth - mEdgePadding * 2) / (mNumDays * 2);

    for (int i = 0; i < mNumDays; i++) {
        int calendarDay = (i + mWeekStart) % mNumDays;
        int x = (2 * i + 1) * dayWidthHalf + mEdgePadding;
        mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
        canvas.drawText(//  w w  w .  j a  v  a 2s .  c  o  m
                mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()),
                x, y, mMonthDayLabelPaint);
    }
}

From source file:edu.hawaii.android.datetimepickermaterial.date.MonthView.java

protected void drawMonthDayLabels(Canvas canvas) {
    int y = getMonthHeaderSize() - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
    int dayWidthHalf = (mWidth - mEdgePadding * 2) / (mNumDays * 2);

    for (int i = 0; i < mNumDays; i++) {
        int calendarDay = (i + mWeekStart) % mNumDays;
        int x = (2 * i + 1) * dayWidthHalf + mEdgePadding;
        mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);

        canvas.drawText(//from   w  w w.  java2 s  .c  o  m
                mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()).substring(0, 1),
                x, y, mMonthDayLabelPaint);
    }
}