Example usage for android.text.format DateUtils FORMAT_SHOW_TIME

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

Introduction

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

Prototype

int FORMAT_SHOW_TIME

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

Click Source Link

Usage

From source file:org.yammp.MusicPlaybackService.java

private void startSleepTimer(long milliseconds, boolean gentle) {

    Calendar now = Calendar.getInstance();
    mCurrentTimestamp = now.getTimeInMillis();
    mStopTimestamp = mCurrentTimestamp + milliseconds;

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    format_flags |= DateUtils.FORMAT_SHOW_TIME;
    String time = DateUtils.formatDateTime(this, mStopTimestamp, format_flags);

    CharSequence contentTitle = getString(R.string.sleep_timer_enabled);
    CharSequence contentText = getString(R.string.notification_sleep_timer, time);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setOngoing(true);/*from  ww  w  .  j a  v a2s  .c  o  m*/
    builder.setSmallIcon(R.drawable.ic_stat_sleeptimer);
    builder.setContentIntent(contentIntent);
    builder.setContentTitle(contentTitle);
    builder.setContentText(contentText);

    mGentleSleepTimer = gentle;
    mNotificationManager.notify(ID_NOTIFICATION_SLEEPTIMER, builder.getNotification());
    mSleepTimerHandler.sendEmptyMessageDelayed(START_SLEEP_TIMER, milliseconds);
    Toast.makeText(this, getResources().getQuantityString(R.plurals.NNNminutes_notif,
            Integer.valueOf((int) milliseconds / 60 / 1000), Integer.valueOf((int) milliseconds / 60 / 1000)),
            Toast.LENGTH_SHORT).show();
}

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

public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    MenuItem item;// ww w .jav  a  2  s .c  o m

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

From source file:com.android.mms.ui.MessageUtils.java

public static String formatTimeStampStringExtend(Context context, long when) {
    Time then = new Time();
    then.set(when);//from   w w w.  j a v  a  2s  .  co m
    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        if ((now.yearDay - then.yearDay) == 1) {
            return context.getString(R.string.str_ipmsg_yesterday);
        } else {
            format_flags |= DateUtils.FORMAT_SHOW_DATE;
        }
    } else if ((now.toMillis(false) - then.toMillis(false)) < 60000) {
        return context.getString(R.string.time_now);
    } else {
        // Otherwise, if the message is from today, show the time.
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }
    sOpMessageUtilsExt.formatTimeStampStringExtend(context, when, format_flags);
    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:com.android.mms.ui.MessageUtils.java

public static String getShortTimeString(Context context, long time) {
    int formatFlags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_CAP_AMPM;
    formatFlags |= DateUtils.FORMAT_SHOW_TIME;
    return DateUtils.formatDateTime(context, time, formatFlags);

}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void showErrorToast(final Context context, final String action, final Throwable t,
        final boolean long_message) {
    if (context == null)
        return;//from   ww w.  j a va2s  .  co  m
    final String message;
    if (t != null) {
        final String t_message = trimLineBreak(unescape(t.getMessage()));
        if (action != null) {
            if (t instanceof TwitterException && ((TwitterException) t).exceededRateLimitation()) {
                final RateLimitStatus status = ((TwitterException) t).getRateLimitStatus();
                final String next_reset_time_string = DateUtils.formatDateTime(context,
                        status.getResetTime().getTime(),
                        DateFormat.is24HourFormat(context)
                                ? DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR
                                : DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_12HOUR);
                message = context.getString(R.string.error_message_rate_limit, action, next_reset_time_string);
            } else {
                message = context.getString(R.string.error_message_with_action, action, t_message);
            }
        } else {
            message = context.getString(R.string.error_message, t_message);
        }
    } else {
        message = context.getString(R.string.error_unknown_error);
    }
    final int length = long_message ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    final Toast toast = Toast.makeText(context, message, length);
    toast.show();
}

From source file:org.mariotaku.twidere.util.Utils.java

@SuppressWarnings("deprecation")
public static void showErrorToast(final Context context, final String action, final Throwable t,
        final boolean long_message) {
    if (context == null)
        return;/*from w  w w. ja  v  a  2s. co  m*/
    final String message;
    if (t != null) {
        t.printStackTrace();
        final String t_message = trimLineBreak(t.getMessage());
        if (action != null) {
            if (t instanceof TwitterException) {
                final TwitterException te = (TwitterException) t;
                if (te.exceededRateLimitation()) {
                    final RateLimitStatus status = te.getRateLimitStatus();
                    final String next_reset_time_string = DateUtils.formatDateTime(context,
                            status.getResetTime().getTime(),
                            DateFormat.is24HourFormat(context)
                                    ? DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR
                                    : DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_12HOUR);
                    message = context.getString(R.string.error_message_rate_limit, action,
                            next_reset_time_string);
                } else {
                    message = context.getString(R.string.error_message_with_action, action, t_message);
                }
            } else {
                message = context.getString(R.string.error_message_with_action, action, t_message);
            }
        } else {
            message = context.getString(R.string.error_message, t_message);
        }
    } else {
        message = context.getString(R.string.error_unknown_error);
    }
    final int length = long_message ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    final Toast toast = Toast.makeText(context, message, length);
    toast.show();
}

From source file:cgeo.geocaching.cgBase.java

/**
 * Generate a time string according to system-wide settings (locale, 12/24 hour)
 * such as "13:24"./*  w w  w .  ja  va  2  s .  co  m*/
 *
 * @param date
 *            milliseconds since the epoch
 * @return the formatted string
 */
public String formatTime(long date) {
    return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_TIME);
}

From source file:cgeo.geocaching.cgBase.java

/**
 * Generate a numeric date and time string according to system-wide settings (locale,
 * date format) such as "7 sept.  12:35".
 *
 * @param context/*from w  ww . j av a2s .com*/
 *            a Context
 * @param date
 *            milliseconds since the epoch
 * @return the formatted string
 */
public static String formatShortDateTime(Context context, long date) {
    return DateUtils.formatDateTime(context, date,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL);
}