Example usage for android.text.format DateFormat is24HourFormat

List of usage examples for android.text.format DateFormat is24HourFormat

Introduction

In this page you can find the example usage for android.text.format DateFormat is24HourFormat.

Prototype

public static boolean is24HourFormat(Context context) 

Source Link

Document

Returns true if times should be formatted as 24 hour times, false if times should be formatted as 12 hour (AM/PM) times.

Usage

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;/*  w w w .  jav  a 2 s.c  o 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 ww  w.  ja v a  2  s  .  com
    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();
}