List of usage examples for android.text.format DateUtils FORMAT_SHOW_YEAR
int FORMAT_SHOW_YEAR
To view the source code for android.text.format DateUtils FORMAT_SHOW_YEAR.
Click Source Link
From source file:com.dwdesign.tweetings.util.Utils.java
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 av a 2 s . c om*/ 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:com.kenmeidearu.materialdatetimepicker.date.DatePickerDialog.java
private void updateDisplay(boolean announce) { if (mDayOfWeekView != null) { if (mTitle != null) mDayOfWeekView.setText(mTitle.toUpperCase(Locale.getDefault())); else {/* ww w .j ava 2 s . c o m*/ 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:com.code44.finance.ui.dialogs.recurrencepicker.RecurrencePickerDialogFragment.java
public void updateDialog() { // Interval// w w w . j av a2s.c om // Checking before setting because this causes infinite recursion // in afterTextWatcher final String intervalStr = Integer.toString(mModel.interval); if (!intervalStr.equals(mInterval.getText().toString())) { mInterval.setText(intervalStr); } mFreqSpinner.setSelection(mModel.freq); mWeekGroup.setVisibility(mModel.freq == RecurrenceModel.FREQ_WEEKLY ? View.VISIBLE : View.GONE); mWeekGroup2.setVisibility(mModel.freq == RecurrenceModel.FREQ_WEEKLY ? View.VISIBLE : View.GONE); mMonthGroup.setVisibility(mModel.freq == RecurrenceModel.FREQ_MONTHLY ? View.VISIBLE : View.GONE); mEndGroup.setVisibility(mModel.freq != RecurrenceModel.FREQ_ONCE ? View.VISIBLE : View.GONE); switch (mModel.freq) { case RecurrenceModel.FREQ_ONCE: mIntervalResId = -1; mStartDateResId = R.string.on; break; case RecurrenceModel.FREQ_DAILY: mIntervalResId = R.plurals.recurrence_interval_daily; mStartDateResId = R.string.from; break; case RecurrenceModel.FREQ_WEEKLY: mIntervalResId = R.plurals.recurrence_interval_weekly; for (int i = 0; i < 7; i++) { mWeekByDayButtons[i].setChecked(mModel.weeklyByDayOfWeek[i]); } mStartDateResId = R.string.from; break; case RecurrenceModel.FREQ_MONTHLY: mIntervalResId = R.plurals.recurrence_interval_monthly; if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_DATE) { mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfMonth); } else if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) { mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfTheWeek); } if (mMonthRepeatByDayOfWeekStr == null) { if (mModel.monthlyByNthDayOfWeek == 0) { mModel.monthlyByNthDayOfWeek = (mTime.monthDay + 6) / 7; // Since not all months have 5 weeks, we convert 5th NthDayOfWeek to // -1 for last monthly day of the week if (mModel.monthlyByNthDayOfWeek >= FIFTH_WEEK_IN_A_MONTH) { mModel.monthlyByNthDayOfWeek = LAST_NTH_DAY_OF_WEEK; } mModel.monthlyByDayOfWeek = mTime.weekDay; } String[] monthlyByNthDayOfWeekStrs = mMonthRepeatByDayOfWeekStrs[mModel.monthlyByDayOfWeek]; // TODO(psliwowski): Find a better way handle -1 indexes int msgIndex = mModel.monthlyByNthDayOfWeek < 0 ? FIFTH_WEEK_IN_A_MONTH : mModel.monthlyByNthDayOfWeek; mMonthRepeatByDayOfWeekStr = monthlyByNthDayOfWeekStrs[msgIndex - 1]; mRepeatMonthlyByNthDayOfWeek.setText(mMonthRepeatByDayOfWeekStr); } mStartDateResId = R.string.from; break; case RecurrenceModel.FREQ_YEARLY: mIntervalResId = R.plurals.recurrence_interval_yearly; mStartDateResId = R.string.from; break; } updateIntervalText(); updateStartDateText(); updateDoneButtonState(); final String startDateStr = DateUtils.formatDateTime(getActivity(), mModel.startDate.toMillis(false), DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_YEAR); mStartDateTextView.setText(startDateStr); mEndSpinner.setSelection(mModel.end); if (mModel.end == RecurrenceModel.END_BY_DATE) { final String endDateStr = DateUtils.formatDateTime(getActivity(), mModel.endDate.toMillis(false), DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_YEAR); mEndDateTextView.setText(endDateStr); } else { if (mModel.end == RecurrenceModel.END_BY_COUNT) { // Checking before setting because this causes infinite // recursion // in afterTextWatcher final String countStr = Integer.toString(mModel.endCount); if (!countStr.equals(mEndCount.getText().toString())) { mEndCount.setText(countStr); } } } }
From source file:org.uguess.android.sysinfo.ApplicationManager.java
void handleAction(final AppInfoHolder ai, int action) { Activity ctx = getActivity();/* w ww. jav a 2s . co m*/ 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 formatTimeStampString(final Context context, final long timestamp) { if (context == null) return null; final Time then = new Time(); then.set(timestamp);/*from w w w . java 2 s.c om*/ 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: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. *///from w w w . j a v 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.android.mms.ui.MessageUtils.java
public static String formatTimeStampStringExtend(Context context, long when) { Time then = new Time(); then.set(when);//from ww w .jav a 2 s. c o 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);/*www . jav a 2 s . c om*/ 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); }
From source file:cgeo.geocaching.cgBase.java
/** * Generate a date string according to system-wide settings (locale, date format) * such as "20 December 2010". The year will always be included, making it suitable * to generate long-lived log entries./* w w w. java 2 s .c o m*/ * * @param date * milliseconds since the epoch * @return the formatted string */ public String formatFullDate(long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR); }