List of usage examples for android.text.format DateUtils FORMAT_SHOW_TIME
int FORMAT_SHOW_TIME
To view the source code for android.text.format DateUtils FORMAT_SHOW_TIME.
Click Source Link
From source file:com.mojtaba.materialdatetimepicker.time.RadialPickerLayout.java
/** * Announce the currently-selected time when launched. *///from w w w. j av a 2 s .c o m @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { // Clear the event's current text so that only the current time will be spoken. event.getText().clear(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR, getHours()); time.set(Calendar.MINUTE, getMinutes()); time.set(Calendar.SECOND, getSeconds()); long millis = time.getTimeInMillis(); int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourMode) { flags |= DateUtils.FORMAT_24HOUR; } String timeString = LanguageUtils .getPersianNumbers(DateUtils.formatDateTime(getContext(), millis, flags)); //TODO: Changed Here. event.getText().add(timeString); return true; } return super.dispatchPopulateAccessibilityEvent(event); }
From source file:org.uguess.android.sysinfo.ApplicationManager.java
void handleAction(final AppInfoHolder ai, int action) { Activity ctx = getActivity();/*from w ww . j a v a 2 s . 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:com.songcode.materialnotes.ui.NoteEditActivity.java
private String getSubTitle() { String dateStr = DateUtils.formatDateTime(this, mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_TIME); if (mWorkingNote.hasClockAlert()) { long time = System.currentTimeMillis(); String alertStr = ""; if (time > mWorkingNote.getAlertDate()) { alertStr = getString(R.string.note_alert_expired); } else {/*w w w . j av a 2 s .c o m*/ alertStr = (String) DateUtils.getRelativeTimeSpanString(mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS); } //emoji return dateStr + " | ???" + alertStr; } return dateStr; }
From source file:com.android.calendar.AllInOneActivity.java
private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) { mShowWeekNum = Utils.getShowWeekNumber(this); mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); if (visibleMillisSinceEpoch != -1) { int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this); mWeekNum = weekNum;//from w w w .j a v a2 s. co m } if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig && mWeekTextView != null) { String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum, mWeekNum); mWeekTextView.setText(weekString); mWeekTextView.setVisibility(View.VISIBLE); } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null && mCurrentView == ViewType.DAY && mIsTabletConfig) { Time time = new Time(mTimeZone); time.set(visibleMillisSinceEpoch); int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff); time.setToNow(); int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff); String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay, visibleMillisSinceEpoch, this); mWeekTextView.setText(dayString); mWeekTextView.setVisibility(View.VISIBLE); } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) { mWeekTextView.setVisibility(View.GONE); } if (mHomeTime != null && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK || mCurrentView == ViewType.AGENDA) && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) { Time time = new Time(mTimeZone); time.setToNow(); long millis = time.toMillis(true); boolean isDST = time.isDst != 0; int flags = DateUtils.FORMAT_SHOW_TIME; if (DateFormat.is24HourFormat(this)) { flags |= DateUtils.FORMAT_24HOUR; } // Formats the time as String timeString = (new StringBuilder(Utils.formatDateRange(this, millis, millis, flags))).append(" ") .append(TimeZone.getTimeZone(mTimeZone).getDisplayName(isDST, TimeZone.SHORT, Locale.getDefault())) .toString(); mHomeTime.setText(timeString); mHomeTime.setVisibility(View.VISIBLE); // Update when the minute changes mHomeTime.removeCallbacks(mHomeTimeUpdater); mHomeTime.postDelayed(mHomeTimeUpdater, DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS)); } else if (mHomeTime != null) { mHomeTime.setVisibility(View.GONE); } }
From source file:cx.ring.service.LocalService.java
public void updateTextNotifications() { Log.d(TAG, "updateTextNotifications()"); for (Conversation c : conversations.values()) { TreeMap<Long, TextMessage> texts = c.getUnreadTextMessages(); if (texts.isEmpty() || texts.lastEntry().getValue().isNotified()) { continue; } else/* w w w. ja v a 2 s.co m*/ notificationManager.cancel(c.notificationId); CallContact contact = c.getContact(); if (c.notificationBuilder == null) { c.notificationBuilder = new NotificationCompat.Builder(getApplicationContext()); c.notificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH).setDefaults(NotificationCompat.DEFAULT_ALL) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(contact.getDisplayName()); } NotificationCompat.Builder noti = c.notificationBuilder; Intent c_intent = new Intent(Intent.ACTION_VIEW).setClass(this, ConversationActivity.class) .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, contact.getIds().get(0))); Intent d_intent = new Intent(ACTION_CONV_READ).setClass(this, LocalService.class) .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, contact.getIds().get(0))); noti.setContentIntent(PendingIntent.getActivity(this, new Random().nextInt(), c_intent, 0)) .setDeleteIntent(PendingIntent.getService(this, new Random().nextInt(), d_intent, 0)); if (contact.getPhoto() != null) { Resources res = getResources(); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width); noti.setLargeIcon(Bitmap.createScaledBitmap(contact.getPhoto(), width, height, false)); } if (texts.size() == 1) { TextMessage txt = texts.firstEntry().getValue(); txt.setNotified(true); noti.setContentText(txt.getMessage()); noti.setStyle(null); noti.setWhen(txt.getTimestamp()); } else { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); for (TextMessage s : texts.values()) { inboxStyle.addLine(Html.fromHtml("<b>" + DateUtils.formatDateTime(this, s.getTimestamp(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL) + "</b> " + s.getMessage())); s.setNotified(true); } noti.setContentText(texts.lastEntry().getValue().getMessage()); noti.setStyle(inboxStyle); noti.setWhen(texts.lastEntry().getValue().getTimestamp()); } notificationManager.notify(c.notificationId, noti.build()); } }
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 a v a 2 s . c o m*/ 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);/*from w ww. ja v a 2s. co m*/ 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:org.mariotaku.harmony.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); Notification notification = new Notification(R.drawable.ic_stat_playback, null, 0); notification.flags = Notification.FLAG_ONGOING_EVENT; notification.icon = R.drawable.ic_stat_sleeptimer; notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); mGentleSleepTimer = gentle;//from w w w .j a v a 2 s. c o m mNotificationManager.notify(ID_NOTIFICATION_SLEEPTIMER, notification); mSleepTimerHandler.sendEmptyMessageDelayed(START_SLEEP_TIMER, milliseconds); final int nmin = (int) milliseconds / 60 / 1000; Toast.makeText(this, getResources().getQuantityString(R.plurals.NNNminutes_notif, nmin, nmin), Toast.LENGTH_SHORT).show(); }
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. *///www . j ava2 s . com 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(); }