Example usage for android.text.format DateUtils FORMAT_SHOW_DATE

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

Introduction

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

Prototype

int FORMAT_SHOW_DATE

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

Click Source Link

Usage

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

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

    if (mSelectedMonthTextView != null)
        mSelectedMonthTextView
                .setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()));
    if (mSelectedDayTextView != null)
        mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    if (mYearView != null)
        mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));
    setHour(mInitialTime.getHour());
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());
    //mHourView.setText(HOUR_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);
    mDayOfWeekView.setContentDescription(monthAndDayText);//tadinya month and day view

    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.uguess.android.sysinfo.ApplicationManager.java

void handleAction(final AppInfoHolder ai, int action) {
    Activity ctx = getActivity();/*  w ww  .java2s. com*/
    String pkgName = ai.appInfo.packageName;

    switch (action) {
    case ACTION_MENU:

        OnClickListener listener = new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                // bypass the 'showMenu' action offset
                int action = which + 1;

                handleAction(ai, action);
            }
        };

        new AlertDialog.Builder(ctx).setTitle(R.string.actions)
                .setItems(new CharSequence[] { getString(R.string.manage), getString(R.string.run),
                        getString(R.string.search_market), getString(R.string.details) }, listener)
                .create().show();

        break;
    case ACTION_MANAGE:

        Intent it = new Intent(Intent.ACTION_VIEW);

        it.setClassName("com.android.settings", //$NON-NLS-1$
                "com.android.settings.InstalledAppDetails"); //$NON-NLS-1$
        it.putExtra("com.android.settings.ApplicationPkgName", pkgName); //$NON-NLS-1$
        // this is for Froyo
        it.putExtra("pkg", pkgName); //$NON-NLS-1$

        List<ResolveInfo> acts = ctx.getPackageManager().queryIntentActivities(it, 0);

        if (acts.size() > 0) {
            startActivity(it);
        } else {
            // for ginger bread
            it = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS", //$NON-NLS-1$
                    Uri.fromParts("package", pkgName, null)); //$NON-NLS-1$

            acts = ctx.getPackageManager().queryIntentActivities(it, 0);

            if (acts.size() > 0) {
                startActivity(it);
            } else {
                Log.d(ApplicationManager.class.getName(), "Failed to resolve activity for InstalledAppDetails"); //$NON-NLS-1$
            }
        }

        break;
    case ACTION_LAUNCH:

        if (!pkgName.equals(ctx.getPackageName())) {
            it = new Intent("android.intent.action.MAIN"); //$NON-NLS-1$
            it.addCategory(Intent.CATEGORY_LAUNCHER);

            acts = ctx.getPackageManager().queryIntentActivities(it, 0);

            if (acts != null) {
                boolean started = false;

                for (int i = 0, size = acts.size(); i < size; i++) {
                    ResolveInfo ri = acts.get(i);

                    if (pkgName.equals(ri.activityInfo.packageName)) {
                        it.setClassName(ri.activityInfo.packageName, ri.activityInfo.name);

                        it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                        try {
                            startActivity(it);

                            started = true;

                        } catch (Exception e) {
                            Log.e(ApplicationManager.class.getName(), "Cannot start activity: " + pkgName, //$NON-NLS-1$
                                    e);
                        }

                        break;
                    }
                }

                if (!started) {
                    Util.shortToast(ctx, R.string.run_failed);
                }
            }
        }

        break;
    case ACTION_SEARCH:

        it = new Intent(Intent.ACTION_VIEW);

        it.setData(Uri.parse("market://search?q=pname:" + pkgName)); //$NON-NLS-1$

        it = Intent.createChooser(it, null);

        startActivity(it);

        break;
    case ACTION_DETAILS:

        ApplicationInfo appInfo = ai.appInfo;

        String installDate;
        String fileSize;

        if (appInfo.sourceDir != null) {
            File f = new File(appInfo.sourceDir);
            installDate = DateUtils.formatDateTime(ctx, f.lastModified(),
                    DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
            fileSize = Formatter.formatFileSize(ctx, f.length());
        } else {
            installDate = fileSize = getString(R.string.unknown);
        }

        StringBuffer sb = new StringBuffer().append("<small>") //$NON-NLS-1$
                .append(getString(R.string.pkg_name)).append(": ") //$NON-NLS-1$
                .append(appInfo.packageName).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.version_code)).append(": ") //$NON-NLS-1$
                .append(ai.versionCode).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.target_sdk)).append(": ") //$NON-NLS-1$
                .append(Util.getTargetSdkVersion(ctx, appInfo)).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.uid)).append(": ") //$NON-NLS-1$
                .append(appInfo.uid).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.file_size)).append(": ") //$NON-NLS-1$
                .append(fileSize).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.public_source)).append(": ") //$NON-NLS-1$
                .append(appInfo.publicSourceDir).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.source)).append(": ") //$NON-NLS-1$
                .append(appInfo.sourceDir).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.data)).append(": ") //$NON-NLS-1$
                .append(appInfo.dataDir).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.installed_date)).append(": ") //$NON-NLS-1$
                .append(installDate).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.process)).append(": ") //$NON-NLS-1$
                .append(appInfo.processName).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.app_class)).append(": ") //$NON-NLS-1$
                .append(appInfo.className == null ? "" //$NON-NLS-1$
                        : appInfo.className)
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.task_affinity)).append(": ") //$NON-NLS-1$
                .append(appInfo.taskAffinity).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.permission)).append(": ") //$NON-NLS-1$
                .append(appInfo.permission == null ? "" //$NON-NLS-1$
                        : appInfo.permission)
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.flags)).append(": ") //$NON-NLS-1$
                .append(appInfo.flags).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.enabled)).append(": ") //$NON-NLS-1$
                .append(appInfo.enabled).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.manage_space_ac)).append(": ") //$NON-NLS-1$
                .append(appInfo.manageSpaceActivityName == null ? "" //$NON-NLS-1$
                        : appInfo.manageSpaceActivityName)
                .append("</small>"); //$NON-NLS-1$

        new AlertDialog.Builder(ctx).setTitle(ai.label == null ? appInfo.packageName : ai.label)
                .setNeutralButton(R.string.close, null).setMessage(Html.fromHtml(sb.toString())).create()
                .show();

        break;
    }
}

From source file:de.vanita5.twittnuker.util.Utils.java

@SuppressWarnings("deprecation")
public static String formatSameDayTime(final Context context, final long timestamp) {
    if (context == null)
        return null;
    if (DateUtils.isToday(timestamp))
        return DateUtils.formatDateTime(context, timestamp,
                DateFormat.is24HourFormat(context) ? DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR
                        : DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_12HOUR);
    return DateUtils.formatDateTime(context, timestamp, DateUtils.FORMAT_SHOW_DATE);
}

From source file:de.vanita5.twittnuker.util.Utils.java

@SuppressWarnings("deprecation")
public static String formatTimeStampString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);//from   w w  w.j  ava2 s. com
    final Time now = new Time();
    now.setToNow();

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

    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    return DateUtils.formatDateTime(context, timestamp, format_flags);
}

From source file:de.vanita5.twittnuker.util.Utils.java

@SuppressWarnings("deprecation")
public static String formatToLongTimeString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);/*  w w w.ja  va2  s .  com*/
    final Time now = new Time();
    now.setToNow();

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

    format_flags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME;

    return DateUtils.formatDateTime(context, timestamp, format_flags);
}

From source file:cn.suishen.email.activity.MessageViewFragmentBase.java

/**
 * @return the given date/time in a human readable form.  The returned string always have
 *     month and day (and year if {@code withYear} is set), so is usually long.
 *     Use {@link DateUtils#getRelativeTimeSpanString} instead to save the screen real estate.
 *//* w  ww  .j  av  a  2  s . c  om*/
private String formatDate(long millis, boolean withYear) {
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb);
    DateUtils.formatDateRange(mContext, formatter, millis, millis,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME
                    | (withYear ? DateUtils.FORMAT_SHOW_YEAR : DateUtils.FORMAT_NO_YEAR));
    return sb.toString();
}

From source file:com.tct.mail.ui.ConversationListFragment.java

private String getElapseTime(long time) {
    long now = System.currentTimeMillis();
    long elapseTime = now - time;
    String displayTime;/*from w  w w .  ja v  a 2 s  . c o  m*/
    if (elapseTime < 0) {
        // abnormal time, this may occur when user change system time to a wrong time
        displayTime = (String) DateUtils.getRelativeTimeSpanString(mActivity.getActivityContext(), time);
    } else if (elapseTime < DateUtils.DAY_IN_MILLIS) {
        //within one day
        displayTime = (String) DateUtils.getRelativeTimeSpanString(mActivity.getActivityContext(), time);
        displayTime = mActivity.getActivityContext().getString(R.string.conversation_time_elapse_today) + ", "
                + displayTime;
    } else {
        //beyond one day
        java.text.DateFormat timeFormat = DateFormat.getTimeFormat(mActivity.getActivityContext());
        Date date = new Date(time);
        String dateText = DateUtils.formatDateTime(mActivity.getActivityContext(), time,
                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH);
        displayTime = dateText + ", " + timeFormat.format(date);
    }

    return displayTime;
}

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

public static String formatTimeStampStringExtend(Context context, long when) {
    Time then = new Time();
    then.set(when);/* w  w  w.  j  a v  a2  s .  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 getTimeDividerString(Context context, long when) {
    Time then = new Time();
    then.set(when);/*from w ww.  j a v a2s .co  m*/
    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int formatFlags = 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) {
        formatFlags |= 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.
        formatFlags |= DateUtils.FORMAT_SHOW_DATE;
        Date curDate = new Date();
        Date cur = new Date(curDate.getYear(), curDate.getMonth(), curDate.getDate(), 0, 0, 0);
        long oneDay = 24 * 60 * 60 * 1000;
        long elapsedTime = cur.getTime() - when;
        if (elapsedTime < oneDay && elapsedTime > 0) {
            return context.getResources().getString(R.string.str_ipmsg_yesterday);
        }
    } else {
        return context.getString(R.string.str_ipmsg_today);
    }
    return DateUtils.formatDateTime(context, when, formatFlags);
}