Example usage for android.text.format DateUtils FORMAT_CAP_NOON_MIDNIGHT

List of usage examples for android.text.format DateUtils FORMAT_CAP_NOON_MIDNIGHT

Introduction

In this page you can find the example usage for android.text.format DateUtils FORMAT_CAP_NOON_MIDNIGHT.

Prototype

int FORMAT_CAP_NOON_MIDNIGHT

To view the source code for android.text.format DateUtils FORMAT_CAP_NOON_MIDNIGHT.

Click Source Link

Usage

From source file:Main.java

public static void setTime(Activity activity, TextView view, long millis) {
    int flags = DateUtils.FORMAT_SHOW_TIME;
    flags |= DateUtils.FORMAT_CAP_NOON_MIDNIGHT;
    if (DateFormat.is24HourFormat(activity)) {
        flags |= DateUtils.FORMAT_24HOUR;
    }/*from ww  w  .ja v a 2  s .  c o  m*/

    // Unfortunately, DateUtils doesn't support a timezone other than the
    // default timezone provided by the system, so we have this ugly hack
    // here to trick it into formatting our time correctly. In order to
    // prevent all sorts of craziness, we synchronize on the TimeZone class
    // to prevent other threads from reading an incorrect timezone from
    // calls to TimeZone#getDefault()
    // TODO fix this if/when DateUtils allows for passing in a timezone
    String timeString;
    synchronized (TimeZone.class) {
        timeString = DateUtils.formatDateTime(activity, millis, flags);
        TimeZone.setDefault(null);
    }

    view.setTag(millis);
    view.setText(timeString);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    MenuItem item;/*from   w ww. j a  va  2s . com*/

    // If the trackball is held down, then the context menu pops up and
    // we never get onKeyUp() for the long-press. So check for it here
    // and change the selection to the long-press state.
    /*if (mSelectionMode != SELECTION_LONGPRESS) {
    mSelectionMode = SELECTION_LONGPRESS;
    invalidate();
    }*/

    final long startMillis = getSelectedTimeInMillis();
    int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_NOON_MIDNIGHT | DateUtils.FORMAT_SHOW_WEEKDAY;
    final String title = DayUtils.formatDateRange(mContext, startMillis, startMillis, flags);
    menu.setHeaderTitle(title);

    int numSelectedEvents = mSelectedEvents.size();
    if (mNumDays == 1) {
        // Day view.

        // If there is a selected event, then allow it to be viewed and
        // edited.
        if (numSelectedEvents >= 1) {
            item = menu.add(0, MENU_EVENT_VIEW, 0, "View event");
            item.setOnMenuItemClickListener(mContextMenuHandler);
            item.setIcon(android.R.drawable.ic_menu_info_details);
        }
    } else {
        // Week view.

        // If there is a selected event, then allow it to be viewed and
        // edited.
        if (numSelectedEvents >= 1) {
            item = menu.add(0, MENU_EVENT_VIEW, 0, "View event");
            item.setOnMenuItemClickListener(mContextMenuHandler);
            item.setIcon(android.R.drawable.ic_menu_info_details);
        }

        item = menu.add(0, MENU_DAY, 0, "Show day");
        item.setOnMenuItemClickListener(mContextMenuHandler);
        item.setIcon(android.R.drawable.ic_menu_day);
        item.setAlphabeticShortcut('d');
    }
}