List of usage examples for android.text.format DateUtils formatDateRange
public static String formatDateRange(Context context, long startMillis, long endMillis, int flags)
From source file:Main.java
public static String formatDateRange(Context context, Date start, Date end) { if (start != null && end != null) { return DateUtils.formatDateRange(context, start.getTime(), end.getTime(), DateUtils.FORMAT_ABBREV_ALL); }//from w w w . j a v a2 s. c om return ""; }
From source file:Main.java
private static void getFormatTime(Context context, Time time, int i, boolean flag, CharBuffer charbuffer) { long l = time.toMillis(true); boolean flag1; if ((i & 1) != 0) flag1 = true;/*from ww w . j a va 2 s . c o m*/ else flag1 = false; if (flag) charbuffer.append(DateUtils.formatDateRange(context, l, l, i)); else if (flag1) { if ((i ^ 1) != 0) { charbuffer.append(DateUtils.formatDateRange(context, l, l, i ^ 1)); charbuffer.append(" "); } String s = getDetailedAmPm(time.hour); if (time.hour > 12) time.hour = -12 + time.hour; long l1 = time.toMillis(true); String s1 = DateUtils.formatDateRange(context, l1, l1, 129); Resources resources = Resources.getSystem(); Object aobj[] = new Object[2]; aobj[0] = s1; aobj[1] = s; charbuffer.append(resources.getString(0x60c01f7, aobj)); } else { charbuffer.append(DateUtils.formatDateRange(context, l, l, i)); } }
From source file:Main.java
/** * Returns a String formatted in the default locale of the device. Looks like "Ddd, Mmm dd, H:MMTT - H:MMTT * @param context the {@link android.content.Context} that this is running within. * @param start the starting date and time of this entry. * @param end the ending date and time of this entry. *//*from w w w.j a v a 2s .c o m*/ public static String buildTimeEntryDateAndTime(Context context, Calendar start, Calendar end) { return DateUtils.formatDateRange(context, start.getTimeInMillis(), end.getTimeInMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_NO_YEAR); }
From source file:net.peterkuterna.android.apps.devoxxsched.util.UIUtils.java
/** * Format and return the given {@link Blocks} and {@link Rooms} values using * {@link #CONFERENCE_TIME_ZONE}./*from w w w .j av a 2 s. c o m*/ */ public static String formatSessionSubtitle(long blockStart, long blockEnd, String roomName, Context context) { TimeZone.setDefault(CONFERENCE_TIME_ZONE); final CharSequence dayString = DateUtils.formatDateRange(context, blockStart, blockEnd, DAY_FLAGS); final CharSequence timeString = DateUtils.formatDateRange(context, blockStart, blockEnd, TIME_FLAGS); return context.getString(R.string.session_subtitle, dayString, timeString, roomName); }
From source file:edu.mit.mobile.android.locast.ver2.events.EventDetail.java
private void loadFromCursor(Cursor c) { if (c.moveToFirst()) { ((TextView) findViewById(R.id.title)).setText(c.getString(c.getColumnIndex(Event._TITLE))); ((TextView) findViewById(R.id.description)).setText(c.getString(c.getColumnIndex(Event._DESCRIPTION))); ((TextView) findViewById(R.id.author)).setText(c.getString(c.getColumnIndex(Event._AUTHOR))); final long start = c.getLong(c.getColumnIndex(Event._START_DATE)), end = c.getLong(c.getColumnIndex(Event._END_DATE)); ((TextView) findViewById(R.id.author)).setText(DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY)); setPointerFromCursor(c);// w w w. ja va2s . co m mEventOverlay.swapCursor(c); } else { Toast.makeText(this, R.string.error_loading_event, Toast.LENGTH_LONG).show(); Log.e(TAG, "cursor has no content"); finish(); } }
From source file:com.google.android.apps.iosched.util.UIUtils.java
/** * Format and return the given {@link Blocks} values using * {@link #CONFERENCE_TIME_ZONE}./*from ww w . j a v a2 s . c o m*/ */ public static String formatBlockTimeString(long blockStart, long blockEnd, Context context) { TimeZone.setDefault(CONFERENCE_TIME_ZONE); // NOTE: There is an efficient version of formatDateRange in Eclair and // beyond that allows you to recycle a StringBuilder. return DateUtils.formatDateRange(context, blockStart, blockEnd, TIME_FLAGS); }
From source file:com.tum.atse.Utils.java
/** * Returns a user-friendly localized data range. * * @param context/* ww w.j a v a 2 s .c o m*/ * @param dateTimeStart * @param dateTimeEnd * @return */ public static String getFormattedDateRange(Context context, DateTime dateTimeStart, DateTime dateTimeEnd) { Calendar cal1 = Calendar.getInstance(); cal1.setTimeInMillis(dateTimeStart.getValue()); Calendar cal2 = Calendar.getInstance(); cal2.setTimeInMillis(dateTimeEnd.getValue()); return DateUtils.formatDateRange(context, cal1.getTimeInMillis(), cal2.getTimeInMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH); }
From source file:edu.cens.loci.ui.VisitDetailActivity.java
private void updateData(Uri visitUri) { ContentResolver resolver = getContentResolver(); Cursor visitCursor = resolver.query(visitUri, VISIT_LOG_PROJECTION, null, null, null); try {/*from w w w.j av a 2 s.c om*/ if (visitCursor != null && visitCursor.moveToFirst()) { long placeId = visitCursor.getLong(PLACE_ID_INDEX); long enter = visitCursor.getLong(ENTER_INDEX); long exit = visitCursor.getLong(EXIT_INDEX); int type = visitCursor.getInt(TYPE); String extra1 = visitCursor.getString(EXTRA1_INDEX); String extra2 = visitCursor.getString(EXTRA2_INDEX); MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placeId=%d enter=%s exit=%s type=%d extra1=%s extra2=%s", placeId, MyDateUtils.getTimeFormatLong(enter), MyDateUtils.getTimeFormatLong(exit), type, extra1, extra2)); // Place name String place_name = ""; int place_state = 0; if (placeId > 0) { String placeSelection = Places._ID + "=" + placeId; Uri placeUri = ContentUris.withAppendedId(Places.CONTENT_URI, placeId); Cursor placeCursor = resolver.query(placeUri, PLACE_PROJECTION, placeSelection, null, null); if (placeCursor != null && placeCursor.moveToFirst()) { place_name = placeCursor.getString(PLACE_NAME_INDEX); place_state = placeCursor.getInt(PLACE_STATE_INDEX); placeCursor.close(); } else { place_name = "Unknown"; } } else { place_name = "Unknown"; } mPlaceName.setText(place_name); // Pull out string in format [relative], [date] CharSequence dateClause = DateUtils.formatDateRange(this, enter, enter, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); mVisitTime.setText(dateClause); // Set the duration mVisitDuration.setText(formatDuration((exit - enter) / 1000)); switch (type) { case Visits.TYPE_GPS: mPlaceTypeIcon.setImageResource(R.drawable.icon_satellite); break; case Visits.TYPE_WIFI: mPlaceTypeIcon.setImageResource(R.drawable.icon_wifi); break; } List<ViewEntry> actions = new ArrayList<ViewEntry>(); // View place Intent viewPlaceIntent = new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId(Places.CONTENT_URI, placeId)); String placeViewLabel = ""; MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placename=%s placestate=%d", place_name, place_state)); switch (place_state) { case Places.STATE_SUGGESTED: placeViewLabel = "Handle Suggested Place"; break; case Places.STATE_REGISTERED: placeViewLabel = "View " + place_name; break; default: placeViewLabel = null;//place_name + " state " + place_state; } if (placeViewLabel != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_VIEW_PLACE, R.drawable.sym_action_map, placeViewLabel, null, null); entry.intent = viewPlaceIntent; actions.add(entry); } // View Wifi APs if (type == Visits.TYPE_WIFI && extra1 != null) { LociWifiFingerprint wifi; String apsAbstract = "Not available"; try { wifi = new LociWifiFingerprint(extra1); apsAbstract = wifi.getWifiInfoSubstring(5); ViewEntry wifiEntry = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless, "View Wi-Fi APs", apsAbstract, null); wifiEntry.extra_string = extra1; actions.add(wifiEntry); } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "wifi json failed : " + extra1); e.printStackTrace(); } } // Additional Actions if (placeId > 0) { if (place_state == Places.STATE_REGISTERED || place_state == Places.STATE_BLOCKED) { if (type == Visits.TYPE_WIFI && extra1 != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_CHANGE_PLACE, android.R.drawable.ic_menu_edit, "Change Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_OVERWRITE_WRONG_RECOGNITION); actions.add(entry); } } } else { ViewEntry entry = new ViewEntry(LIST_ACTION_ADD_PLACE, R.drawable.sym_action_add, "Add Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_USE_SHORT_VISIT); actions.add(entry); } // View Recognition Results //Log.d(TAG, "recog: " + extra2); if (extra2 != null && !TextUtils.isEmpty(extra2)) { ViewEntry recogEntry = new ViewEntry(LIST_ACTION_VIEW_RECOGNITION, R.drawable.ic_clock_strip_desk_clock, "View Recogntion Results", "", null); recogEntry.extra_string = extra2; actions.add(recogEntry); } ViewAdapter adapter = new ViewAdapter(this, actions); setListAdapter(adapter); //Log.d(TAG, String.format("placeId=%d enter=%s exit=%s", placeId, MyDateUtils.getDateFormatLong(enter), MyDateUtils.getDateFormatLong(exit))); //Log.d(TAG, String.format("extra1=%s", extra1)); //Log.d(TAG, String.format("extra2=%s", extra2)); } } finally { if (visitCursor != null) { visitCursor.close(); } } }
From source file:com.androzic.track.TrackDetails.java
private void updateTrackDetails() { AppCompatActivity activity = (AppCompatActivity) getActivity(); Resources resources = getResources(); activity.getSupportActionBar().setTitle(track.name); View view = getView();//from w ww . j a va2 s.c om int pointCount = track.getPointCount(); ((TextView) view.findViewById(R.id.point_count)) .setText(resources.getQuantityString(R.plurals.numberOfPoints, pointCount, pointCount)); String distance = StringFormatter.distanceH(track.distance); ((TextView) view.findViewById(R.id.distance)).setText(distance); Track.TrackPoint ftp = track.getPoint(0); Track.TrackPoint ltp = track.getLastPoint(); String start_coords = StringFormatter.coordinates(" ", ftp.latitude, ftp.longitude); ((TextView) view.findViewById(R.id.start_coordinates)).setText(start_coords); String finish_coords = StringFormatter.coordinates(" ", ltp.latitude, ltp.longitude); ((TextView) view.findViewById(R.id.finish_coordinates)).setText(finish_coords); Date start_date = new Date(ftp.time); ((TextView) view.findViewById(R.id.start_date)) .setText(DateFormat.getDateFormat(activity).format(start_date) + " " + DateFormat.getTimeFormat(activity).format(start_date)); Date finish_date = new Date(ltp.time); ((TextView) view.findViewById(R.id.finish_date)) .setText(DateFormat.getDateFormat(activity).format(finish_date) + " " + DateFormat.getTimeFormat(activity).format(finish_date)); long elapsed = (ltp.time - ftp.time) / 1000; String timeSpan; if (elapsed < 24 * 60 * 60 * 3) { timeSpan = DateUtils.formatElapsedTime(elapsed); } else { timeSpan = DateUtils.formatDateRange(activity, ftp.time, ltp.time, DateUtils.FORMAT_ABBREV_MONTH); } ((TextView) view.findViewById(R.id.time_span)).setText(timeSpan); // Gather statistics int segmentCount = 0; double minElevation = Double.MAX_VALUE; double maxElevation = Double.MIN_VALUE; double maxSpeed = 0; MeanValue mv = new MeanValue(); for (Track.TrackSegment segment : track.getSegments()) { Track.TrackPoint ptp = null; if (segment.independent) segmentCount++; for (Track.TrackPoint tp : segment.getPoints()) { if (ptp != null) { double d = Geo.distance(tp.latitude, tp.longitude, ptp.latitude, ptp.longitude); double speed = d / ((tp.time - ptp.time) / 1000); if (speed == Double.POSITIVE_INFINITY) continue; mv.addValue(speed); if (speed > maxSpeed) maxSpeed = speed; } ptp = tp; if (tp.elevation < minElevation && tp.elevation != 0) minElevation = tp.elevation; if (tp.elevation > maxElevation) maxElevation = tp.elevation; } } double averageSpeed = mv.getMeanValue(); ((TextView) view.findViewById(R.id.segment_count)) .setText(resources.getQuantityString(R.plurals.numberOfSegments, segmentCount, segmentCount)); ((TextView) view.findViewById(R.id.max_elevation)).setText(StringFormatter.elevationH(maxElevation)); ((TextView) view.findViewById(R.id.min_elevation)).setText(StringFormatter.elevationH(minElevation)); ((TextView) view.findViewById(R.id.max_speed)).setText(String.format(Locale.getDefault(), "%s: %s", resources.getString(R.string.max_speed), StringFormatter.speedH(maxSpeed))); ((TextView) view.findViewById(R.id.average_speed)).setText(String.format(Locale.getDefault(), "%s: %s", resources.getString(R.string.average_speed), StringFormatter.speedH(averageSpeed))); }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
private String getMonthAndYearString() { int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY; mStringBuilder.setLength(0);/* ww w. ja v a2 s . c o m*/ long millis = mCalendar.getTimeInMillis(); return DateUtils.formatDateRange(getContext(), millis, millis, flags); }