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:can.yrt.onebusaway.TripInfoActivity.java
static String getDepartureTime(Context ctx, long departure) { return ctx.getString(R.string.trip_info_depart, DateUtils.formatDateTime(ctx, departure, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT)); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java
/** * Create an {@link AsyncQueryHandler} for use with the * {@link MapInfoWindowAdapter}.//w w w .j av a 2s .c o m */ private AsyncQueryHandler createInfowindowHandler(ContentResolver contentResolver) { return new AsyncQueryHandler(contentResolver) { StringBuilder mBuffer = new StringBuilder(); Formatter mFormatter = new Formatter(mBuffer, Locale.getDefault()); @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { MarkerModel model = mMarkers.get(cookie); mInfoAdapter.clearData(); if (model == null || cursor == null) { // query did not complete or incorrect data was loaded return; } final long time = UIUtils.getCurrentTime(getActivity()); switch (token) { case SessionAfterQuery._TOKEN: { extractSession(cursor, model, time); } break; case SandboxCompaniesAtQuery._TOKEN: { extractSandbox(cursor, model, time); } } // update the displayed window model.marker.showInfoWindow(); } private void extractSandbox(Cursor cursor, MarkerModel model, long time) { // get tracks data from cache: icon and color TrackModel track = mTracks.get(model.track); int color = (track != null) ? track.color : 0; int iconResId = 0; if (track != null) { iconResId = getResources().getIdentifier("track_" + ParserUtils.sanitizeId(track.name), "drawable", getActivity().getPackageName()); } if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); StringBuilder sb = new StringBuilder(); int count = 0; final int maxCompaniesDisplay = getResources() .getInteger(R.integer.sandbox_company_list_max_display); while (!cursor.isAfterLast() && count < maxCompaniesDisplay) { if (sb.length() > 0) { sb.append(", "); } sb.append(cursor.getString(SandboxCompaniesAtQuery.COMPANY_NAME)); count++; cursor.moveToNext(); } if (count >= maxCompaniesDisplay && !cursor.isAfterLast()) { // Additional sandbox companies to display sb.append(", …"); } mInfoAdapter.setSandbox(model.marker, model.label, color, iconResId, sb.length() > 0 ? sb.toString() : null); } else { // No active sandbox companies mInfoAdapter.setSandbox(model.marker, model.label, color, iconResId, null); } model.marker.showInfoWindow(); } private static final long SHOW_UPCOMING_TIME = 24 * 60 * 60 * 1000; // 24 hours private void extractSession(Cursor cursor, MarkerModel model, long time) { if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); String currentTitle = null; String nextTitle = null; String nextTime = null; final long blockStart = cursor.getLong(SessionAfterQuery.BLOCK_START); final long blockEnd = cursor.getLong(SessionAfterQuery.BLOCK_END); boolean inProgress = time >= blockStart && time <= blockEnd; if (inProgress) { // A session is running, display its name and optionally // the next session currentTitle = cursor.getString(SessionAfterQuery.SESSION_TITLE); //move to the next entry cursor.moveToNext(); } if (!cursor.isAfterLast()) { //There is a session coming up next, display only it if it's within 24 hours of the current time final long nextStart = cursor.getLong(SessionAfterQuery.BLOCK_START); if (nextStart < time + SHOW_UPCOMING_TIME) { nextTitle = cursor.getString(SessionAfterQuery.SESSION_TITLE); mBuffer.setLength(0); boolean showWeekday = !DateUtils.isToday(blockStart) && !UIUtils.isSameDayDisplay(UIUtils.getCurrentTime(getActivity()), blockStart, getActivity()); nextTime = DateUtils.formatDateRange(getActivity(), mFormatter, blockStart, blockStart, DateUtils.FORMAT_SHOW_TIME | (showWeekday ? DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY : 0), PrefUtils.getDisplayTimeZone(getActivity()).getID()).toString(); } } // populate the info window adapter mInfoAdapter.setSessionData(model.marker, model.label, currentTitle, nextTitle, nextTime, inProgress); } else { // No entries, display name of room only mInfoAdapter.setMarker(model.marker, model.label); } } }; }
From source file:com.android.mms.ui.MessageUtils.java
public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when);/*from ww w . ja v 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 | /// M: Fix ALPS00419488 to show 12:00, so mark DateUtils.FORMAT_ABBREV_ALL //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. format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } // If the caller has asked for full details, make sure to show the date // and time no matter what we've determined above (but still make showing // the year only happen if it is a different year from today). if (fullFormat) { format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } String dateTime = sOpMessageUtilsExt.formatTimeStampString(context, when, format_flags); if (dateTime != null) { return dateTime; } return DateUtils.formatDateTime(context, when, format_flags); }
From source file:org.voidsink.anewjkuapp.utils.AppUtils.java
public static String getTimeString(Context c, Date dtStart, Date dtEnd, boolean allDay) { int flags = 0; String tzString = TimeZone.getDefault().getID(); if (allDay) { tzString = "UTC"; } else {/* ww w.ja v a 2 s . c om*/ flags = DateUtils.FORMAT_SHOW_TIME; } return DateUtils.formatDateRange(c, new Formatter(Locale.getDefault()), dtStart.getTime(), dtEnd.getTime(), flags, tzString).toString(); }
From source file:com.a.mirko.android.datetimepicker.time.RadialPickerLayout.java
/** * Announce the currently-selected time when launched. *//*www .j a va 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(); Time time = new Time(); time.hour = getHours(); time.minute = getMinutes(); long millis = time.normalize(true); int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourMode) { flags |= DateUtils.FORMAT_24HOUR; } String timeString = DateUtils.formatDateTime(getContext(), millis, flags); event.getText().add(timeString); return true; } return super.dispatchPopulateAccessibilityEvent(event); }
From source file:com.redinput.datetimepickercompat.time.RadialPickerLayout.java
private void installAccessibilityDelegate() { // The accessibility delegate enables customizing accessibility behavior // via composition as opposed as inheritance. The main benefit is that // one can write a backwards compatible application by setting the delegate // only if the API level is high enough i.e. the delegate is part of the APIs. // The easiest way to achieve that is by using the support library which // takes the burden of checking API version and knowing which API version // introduced the delegate off the developer. ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() { @Override//from w ww .java2 s . c om public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); // Note that View.onInitializeAccessibilityNodeInfo was introduced in // ICS and we would like to tweak a bit the text that is reported to // accessibility services via the AccessibilityNodeInfo. info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD); info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD); } @Override public boolean dispatchPopulateAccessibilityEvent(View host, 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(); Time time = new Time(); time.hour = getHours(); time.minute = getMinutes(); long millis = time.normalize(true); int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourMode) { flags |= DateUtils.FORMAT_24HOUR; } String timeString = DateUtils.formatDateTime(getContext(), millis, flags); event.getText().add(timeString); return true; } return super.dispatchPopulateAccessibilityEvent(host, event); } @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { if (super.performAccessibilityAction(host, action, args)) { return true; } int changeMultiplier = 0; if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) { changeMultiplier = 1; } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) { changeMultiplier = -1; } if (changeMultiplier != 0) { int value = getCurrentlyShowingValue(); int stepSize = 0; int currentItemShowing = getCurrentItemShowing(); if (currentItemShowing == HOUR_INDEX) { stepSize = HOUR_VALUE_TO_DEGREES_STEP_SIZE; value %= 12; } else if (currentItemShowing == MINUTE_INDEX) { stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE; } int degrees = value * stepSize; degrees = snapOnly30s(degrees, changeMultiplier); value = degrees / stepSize; int maxValue = 0; int minValue = 0; if (currentItemShowing == HOUR_INDEX) { if (mIs24HourMode) { maxValue = 23; } else { maxValue = 12; minValue = 1; } } else { maxValue = 55; } if (value > maxValue) { // If we scrolled forward past the highest number, wrap around to the // lowest. value = minValue; } else if (value < minValue) { // If we scrolled backward past the lowest number, wrap around to the // highest. value = maxValue; } setItem(currentItemShowing, value); mListener.onValueSelected(currentItemShowing, value, false); return true; } return false; } }); }
From source file:com.dwdesign.tweetings.util.Utils.java
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: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 a va2s. 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:com.dwdesign.tweetings.util.Utils.java
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 w w. java2 s . c o m final Time now = new Time(); now.setToNow(); int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_CAP_AMPM; format_flags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME; return DateUtils.formatDateTime(context, timestamp, format_flags); }
From source file:com.borax12.materialdaterangepicker.single.time.RadialPickerLayout.java
/** * Announce the currently-selected time when launched. *//*from w w w. j ava 2s . com*/ @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 = DateUtils.formatDateTime(getContext(), millis, flags); event.getText().add(timeString); return true; } return super.dispatchPopulateAccessibilityEvent(event); }