Java Code Examples for android.text.format.DateUtils#formatDateRange()
The following examples show how to use
android.text.format.DateUtils#formatDateRange() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuleViewModel.java From Jockey with Apache License 2.0 | 6 votes |
@Bindable public String getValueText() { if ((mEnumeratedRule.getInputType() & InputType.TYPE_CLASS_DATETIME) != 0) { long dateAsUnixTimestamp; try { dateAsUnixTimestamp = Long.parseLong(mFactory.getValue()) * 1000; } catch (NumberFormatException e) { dateAsUnixTimestamp = System.currentTimeMillis(); } int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; Formatter date = DateUtils.formatDateRange(mContext, new Formatter(), dateAsUnixTimestamp, dateAsUnixTimestamp, flags, "UTC"); return date.toString(); } else { return mFactory.getValue(); } }
Example 2
Source File: TrackInformation.java From trekarta with GNU General Public License v3.0 | 6 votes |
private void updateTrackInformation(Activity activity, Resources resources) { Track.TrackPoint ftp = mTrack.points.get(0); Track.TrackPoint ltp = mTrack.getLastPoint(); int pointCount = mTrack.points.size(); mPointCountView.setText(resources.getQuantityString(R.plurals.numberOfPoints, pointCount, pointCount)); String distance = StringFormatter.distanceHP(mTrack.getDistance()); mDistanceView.setText(distance); String finish_coords = StringFormatter.coordinates(ltp); mFinishCoordinatesView.setText(finish_coords); Date finishDate = new Date(ltp.time); mFinishDateView.setText(String.format("%s %s", DateFormat.getDateFormat(activity).format(finishDate), DateFormat.getTimeFormat(activity).format(finishDate))); long elapsed = (ltp.time - ftp.time) / 1000; String timeSpan; if (elapsed < 24 * 3600 * 3) { // 3 days timeSpan = DateUtils.formatElapsedTime(elapsed); } else { timeSpan = DateUtils.formatDateRange(activity, ftp.time, ltp.time, DateUtils.FORMAT_ABBREV_MONTH); } mTimeSpanView.setText(timeSpan); }
Example 3
Source File: CalendarUtils.java From ToDay with MIT License | 5 votes |
/** * Formats given time to a readable month string, e.g. March 2016 * @param context resources provider * @param timeMillis time in milliseconds * @return formatted month string */ public static String toMonthString(Context context, long timeMillis) { return DateUtils.formatDateRange(context, timeMillis, timeMillis, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_MONTH_DAY | DateUtils.FORMAT_SHOW_YEAR); }
Example 4
Source File: AirMonthView.java From AirCalendar with MIT License | 5 votes |
private String getMonthAndYearString() { int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY; mStringBuilder.setLength(0); long millis = mCalendar.getTimeInMillis(); return DateUtils.formatDateRange(getContext(), millis, millis, flags); // 지역화된 포멧으로 출력 }
Example 5
Source File: AgendaFragment.java From white-label-event-app with Apache License 2.0 | 5 votes |
public void bindTimeGroupHeader(TimeGroupHeader item) { sb.setLength(0); DateUtils.formatDateRange( itemView.getContext(), formatter, item.start, item.end, DateUtils.FORMAT_SHOW_TIME, tz.getID() ); tvTimeRange.setText(formatter.toString()); }
Example 6
Source File: AgendaFragment.java From white-label-event-app with Apache License 2.0 | 5 votes |
public void bindDateHeader(DateHeader item) { sb.setLength(0); DateUtils.formatDateRange( itemView.getContext(), formatter, item.date, item.date, DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR, tz.getID() ); tvDate.setText(formatter.toString()); }
Example 7
Source File: SimpleMonthView.java From CalendarView with Apache License 2.0 | 5 votes |
/** * 获取年份和月份 * * @return */ private String getMonthAndYearString() { int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY; mStringBuilder.setLength(0); long millis = mCalendar.getTimeInMillis(); return DateUtils.formatDateRange(getContext(), millis, millis, flags); }
Example 8
Source File: Utils.java From conference-central-android-app with GNU General Public License v2.0 | 5 votes |
/** * Returns a user-friendly localized data range. * * @param context * @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); }
Example 9
Source File: LocationService.java From trekarta with GNU General Public License v3.0 | 5 votes |
public void tryToSaveTrack() { mLastTrack = getTrack(); if (mLastTrack.points.size() == 0) return; long startTime = mLastTrack.points.get(0).time; long stopTime = mLastTrack.getLastPoint().time; long period = stopTime - startTime; int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT; if (period < DateUtils.WEEK_IN_MILLIS) flags |= DateUtils.FORMAT_SHOW_TIME; if (period < DateUtils.WEEK_IN_MILLIS * 4) flags |= DateUtils.FORMAT_SHOW_WEEKDAY; //TODO Try to 'guess' starting and ending location name mLastTrack.description = DateUtils.formatDateRange(this, startTime, stopTime, flags) + " \u2014 " + StringFormatter.distanceH(mLastTrack.getDistance()); flags |= DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; mLastTrack.name = DateUtils.formatDateRange(this, startTime, stopTime, flags); if (period < TOO_SMALL_PERIOD) { sendBroadcast(new Intent(BROADCAST_TRACK_SAVE) .putExtra("saved", false) .putExtra("reason", "period")); clearTrack(); return; } if (mLastTrack.getDistance() < TOO_SMALL_DISTANCE) { sendBroadcast(new Intent(BROADCAST_TRACK_SAVE) .putExtra("saved", false) .putExtra("reason", "distance")); clearTrack(); return; } saveTrack(); }
Example 10
Source File: HomeFragment.java From white-label-event-app with Apache License 2.0 | 5 votes |
private void populateTimeGroups(SortedMap<DateRange, List<AgendaItem>> groups, ViewGroup time_groups) { final LayoutInflater inflater = getActivity().getLayoutInflater(); for (Map.Entry<DateRange, List<AgendaItem>> entry : groups.entrySet()) { final ViewGroup sessions_group = (ViewGroup) inflater.inflate(R.layout.item_time_group_sessions, time_groups, false); time_groups.addView(sessions_group); final TextView tv_time = (TextView) sessions_group.findViewById(R.id.tv_time); final DateRange range = entry.getKey(); sb.setLength(0); DateUtils.formatDateRange( tv_time.getContext(), formatter, range.start, range.end, DateUtils.FORMAT_SHOW_TIME, event.getTimezoneName() ); tv_time.setText(formatter.toString()); final ViewGroup vg_sessions = (ViewGroup) sessions_group.findViewById(R.id.vg_sessions); vg_sessions.removeAllViews(); for (final AgendaItem item : entry.getValue()) { final View session = inflater.inflate(R.layout.item_time_group_session, vg_sessions, false); vg_sessions.addView(session); final TextView tv_topic = (TextView) session.findViewById(R.id.tv_topic); tv_topic.setText(item.getTopic()); } } }
Example 11
Source File: DateTimeUtils.java From MongoExplorer with MIT License | 4 votes |
public static String formatDate(Context context, long value) { mStringBuilder.setLength(0); DateUtils.formatDateRange(context, mFormatter, value, value, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, "GMT"); return mStringBuilder.toString(); }
Example 12
Source File: DateTimeUtils.java From MongoExplorer with MIT License | 4 votes |
public static String formatDateWeekday(Context context, long value) { mStringBuilder.setLength(0); DateUtils.formatDateRange(context, mFormatter, value, value, DateUtils.FORMAT_SHOW_WEEKDAY, "GMT"); return mStringBuilder.toString(); }
Example 13
Source File: SessionDetailFragment.java From white-label-event-app with Apache License 2.0 | 4 votes |
private void updateSessionDetail() { tvTopic.setText(agendaItem.getTopic()); host.setTitle(agendaItem.getTopic()); final StringBuilder sb = new StringBuilder(); final Formatter formatter = new Formatter(sb); final long start_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochStartTime()); final long end_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochEndTime()); sb.setLength(0); DateUtils.formatDateRange( getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, tz.getID() ); tvDate.setText(formatter.toString()); sb.setLength(0); DateUtils.formatDateRange( getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_TIME, tz.getID() ); tvTime.setText(formatter.toString()); final String location = agendaItem.getLocation(); if (!Strings.isNullOrEmpty(location)) { tvLocation.setText(agendaItem.getLocation()); } else { tvLocation.setVisibility(View.GONE); } tvDescription.setText(agendaItem.getDescription()); // Only sessions with speakers can have feedback final View feedback = vgActions.findViewById(R.id.tv_session_feedback); if (speakerItems.size() > 0) { feedback.setOnClickListener(new SessionFeedbackOnClickListener()); vgActions.setVisibility(View.VISIBLE); } else { vgActions.setVisibility(View.GONE); } if (speakerItems.size() > 0) { vgSpeakers.setVisibility(View.VISIBLE); vgSpeakers.removeAllViews(); final LayoutInflater inflater = getActivity().getLayoutInflater(); for (final SpeakerItem item : speakerItems) { final View view = inflater.inflate(R.layout.item_session_speaker, vgSpeakers, false); ImageView iv = (ImageView) view.findViewById(R.id.iv_pic); Glide .with(SessionDetailFragment.this) .load(item.getImage100()) .placeholder(R.drawable.nopic) .into(iv); ((TextView) view.findViewById(R.id.tv_name)).setText(item.getName()); if (host != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment next = SpeakerDetailFragment.instantiate(item.getId()); host.pushFragment(next, "speaker_detail"); } }); } vgSpeakers.addView(view); } } }
Example 14
Source File: SpeakerDetailFragment.java From white-label-event-app with Apache License 2.0 | 4 votes |
private void updateSpeaker() { tvName.setText(speakerItem.getName()); host.setTitle(speakerItem.getName()); final String company = speakerItem.getCompanyName(); tvCompany.setVisibility(Strings.isNullOrEmpty(company) ? View.GONE : View.VISIBLE); tvCompany.setText(company); final String title = speakerItem.getTitle(); tvTitle.setVisibility(Strings.isNullOrEmpty(title) ? View.GONE : View.VISIBLE); tvTitle.setText(title); Glide .with(SpeakerDetailFragment.this) .load(speakerItem.getImage100()) .fitCenter() .placeholder(R.drawable.nopic) .into(ivPic); boolean links_visible = false; final String website = speakerItem.getWebsite(); if (!Strings.isNullOrEmpty(website)) { links_visible = true; tvWebsite.setVisibility(View.VISIBLE); tvWebsite.setText(website); } final String twitter = speakerItem.getTwitter(); if (!Strings.isNullOrEmpty(twitter)) { links_visible = true; tvTwitter.setVisibility(View.VISIBLE); tvTwitter.setText(twitter); } final String facebook = speakerItem.getFacebook(); if (!Strings.isNullOrEmpty(facebook)) { links_visible = true; tvFacebook.setVisibility(View.VISIBLE); tvFacebook.setText(facebook); } final String linkedin = speakerItem.getLinkedin(); if (!Strings.isNullOrEmpty(linkedin)) { links_visible = true; tvLinkedin.setVisibility(View.VISIBLE); tvLinkedin.setText(linkedin); } vgDetailLinks.setVisibility(links_visible ? View.VISIBLE : View.GONE); tvAbout.setText(speakerItem.getAbout()); if (agendaItems.size() > 0) { vgSessions.setVisibility(View.VISIBLE); vgSessions.removeAllViews(); final StringBuilder sb = new StringBuilder(); final Formatter formatter = new Formatter(sb); final LayoutInflater inflater = getActivity().getLayoutInflater(); for (final AgendaItem item : agendaItems) { final View view = inflater.inflate(R.layout.item_speaker_session, vgSessions, false); ((TextView) view.findViewById(R.id.tv_topic)).setText(item.getTopic()); sb.setLength(0); DateUtils.formatDateRange( getActivity(), formatter, item.getEpochStartTime() * 1000, item.getEpochEndTime() * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, tz.getID() ); ((TextView) view.findViewById(R.id.tv_date)).setText(formatter.toString()); sb.setLength(0); DateUtils.formatDateRange( getActivity(), formatter, item.getEpochStartTime() * 1000, item.getEpochEndTime() * 1000, DateUtils.FORMAT_SHOW_TIME, tz.getID() ); ((TextView) view.findViewById(R.id.tv_time)).setText(formatter.toString()); final String session_id = item.getId(); final ImageButton ib_favorite = (ImageButton) view.findViewById(R.id.button_favorite_session); favSessionButtonManager.attach(ib_favorite, session_id); if (host != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment next = SessionDetailFragment.instantiate(item.getId()); host.pushFragment(next, "session_detail"); } }); } vgSessions.addView(view); } } }
Example 15
Source File: ListAdapterMarvinMeal.java From intra42 with Apache License 2.0 | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (vi == null) return null; holder = new ViewHolder(); convertView = vi.inflate(R.layout.list_view_marvin_meal, parent, false); holder.textViewDateDay = convertView.findViewById(R.id.textViewDateDay); holder.textViewDateMonth = convertView.findViewById(R.id.textViewDateMonth); holder.textViewTitle = convertView.findViewById(R.id.textViewTitle); holder.textViewSummary = convertView.findViewById(R.id.textViewSummary); convertView.setTag(holder); } else holder = (ViewHolder) convertView.getTag(); MarvinMeals item = getItem(position); if (item == null) return null; String menu; holder.textViewDateDay.setText(DateTool.getDay(item.beginAt)); holder.textViewDateMonth.setText(DateTool.getMonthMedium(item.beginAt)); menu = item.menu.replace("\r", "").trim(); holder.textViewTitle.setText(menu); String summary; summary = DateUtils.formatDateRange(context, item.beginAt.getTime(), item.endAt.getTime(), DateUtils.FORMAT_SHOW_TIME); summary += " • $" + String.valueOf(item.price); holder.textViewSummary.setText(summary); return convertView; }
Example 16
Source File: ListAdapterEvents.java From intra42 with Apache License 2.0 | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (inflater == null) return null; convertView = inflater.inflate(R.layout.list_view_event, parent, false); holder.viewRegistered = convertView.findViewById(R.id.viewRegistered); holder.textViewDateDay = convertView.findViewById(R.id.textViewDateDay); holder.textViewDateMonth = convertView.findViewById(R.id.textViewDateMonth); holder.textViewName = convertView.findViewById(R.id.textViewName); holder.textViewTime = convertView.findViewById(R.id.textViewTime); holder.textViewPlace = convertView.findViewById(R.id.textViewPlace); holder.textViewFull = convertView.findViewById(R.id.textViewFull); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } Events item = getItem(position); holder.textViewDateDay.setText(DateTool.getDay(item.beginAt)); holder.textViewDateMonth.setText(DateTool.getMonthMedium(item.beginAt)); holder.textViewName.setText(item.name); SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); if (item.kind != null) { String text = context.getString(item.kind.getName()); stringBuilder.append(text); stringBuilder.append(" "); int color = ContextCompat.getColor(context, item.kind.getColorRes()); int length = text.length(); stringBuilder.setSpan(new ForegroundColorSpan(color), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // stringBuilder.setSpan(new TypefaceSpan("monospace"), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // stringBuilder.setSpan(new StyleSpan(Typeface.BOLD), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.setSpan(new TextAppearanceSpan("monospace", Typeface.BOLD, Math.round(Tools.dpToPx(context, 18)), ColorStateList.valueOf(color), ColorStateList.valueOf(color)), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } stringBuilder.append(item.name); holder.textViewName.setText(stringBuilder); holder.viewRegistered.setVisibility(View.GONE); String time; time = DateUtils.formatDateRange(context, item.beginAt.getTime(), item.endAt.getTime(), DateUtils.FORMAT_SHOW_TIME); if (time.length() > 30) time = time.replace(" – ", "\n"); holder.textViewTime.setText(time); holder.textViewPlace.setText(item.location); if (item.maxPeople != null && item.nbrSubscribers >= item.maxPeople && item.maxPeople > 0) { holder.textViewFull.setVisibility(View.VISIBLE); } else holder.textViewFull.setVisibility(View.GONE); return convertView; }
Example 17
Source File: TrackDetails.java From Androzic with GNU General Public License v3.0 | 4 votes |
private void updateTrackDetails() { AppCompatActivity activity = (AppCompatActivity) getActivity(); Resources resources = getResources(); activity.getSupportActionBar().setTitle(track.name); View view = getView(); 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))); }
Example 18
Source File: SimpleMonthView.java From CalendarListview with MIT License | 4 votes |
private String getMonthAndYearString() { int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY; mStringBuilder.setLength(0); long millis = mCalendar.getTimeInMillis(); return DateUtils.formatDateRange(getContext(), millis, millis, flags); }
Example 19
Source File: CallDetailHistoryAdapter.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { // Make sure we have a valid convertView to start with final View result = convertView == null ? mLayoutInflater.inflate(R.layout.call_detail_history_item, parent, false) : convertView; PhoneCallDetails details = (PhoneCallDetails) getItem(position); CallTypeIconsView callTypeIconView = (CallTypeIconsView) result.findViewById(R.id.call_type_icon); TextView callTypeTextView = (TextView) result.findViewById(R.id.call_type_text); TextView dateView = (TextView) result.findViewById(R.id.date); TextView durationView = (TextView) result.findViewById(R.id.duration); int callType = details.callTypes[0]; callTypeIconView.clear(); callTypeIconView.add(callType); StringBuilder typeSb = new StringBuilder(); typeSb.append(mContext.getResources().getString(getCallTypeText(callType))); // If not 200, we add text for user feedback about what went wrong if(details.statusCode != 200) { typeSb.append(" - "); typeSb.append(details.statusCode); if(!TextUtils.isEmpty(details.statusText)) { typeSb.append(" / "); typeSb.append(details.statusText); } } callTypeTextView.setText(typeSb.toString()); // Set the date. CharSequence dateValue = DateUtils.formatDateRange(mContext, details.date, details.date, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); dateView.setText(dateValue); // Set the duration if (callType == Calls.MISSED_TYPE) { durationView.setVisibility(View.GONE); } else { durationView.setVisibility(View.VISIBLE); durationView.setText(formatDuration(details.duration)); } return result; }
Example 20
Source File: DateFormatter.java From opentasks with Apache License 2.0 | 3 votes |
/** * This method is copied from Android 5.1.1 source for {@link DateUtils#getRelativeDateTimeString(Context, long, long, long, int)} * <p> * <a href="https://android.googlesource.com/platform/frameworks/base/+/android-5.1.1_r29/core/java/android/text/format/DateUtils.java">DateUtils 5.1.1 * source</a> * <p> * because newer versions don't respect the 12/24h settings of the user, they use the locale's default instead. * <p> * Be aware of the original note inside the method, too. * <p> * ------ Original javadoc: * <p> * Return string describing the elapsed time since startTime formatted like * "[relative time/date], [time]". * <p> * Example output strings for the US date format. * <ul> * <li>3 mins ago, 10:15 AM</li> * <li>yesterday, 12:20 PM</li> * <li>Dec 12, 4:12 AM</li> * <li>11/14/2007, 8:20 AM</li> * </ul> * * @param time * some time in the past. * @param minResolution * the minimum elapsed time (in milliseconds) to report when showing relative times. For example, a time 3 seconds in the past will be reported as * "0 minutes ago" if this is set to {@link DateUtils#MINUTE_IN_MILLIS}. * @param transitionResolution * the elapsed time (in milliseconds) at which to stop reporting relative measurements. Elapsed times greater than this resolution will default to * normal date formatting. For example, will transition from "6 days ago" to "Dec 12" when using {@link DateUtils#WEEK_IN_MILLIS}. */ private CharSequence oldGetRelativeDateTimeString(Context c, long time, long minResolution, long transitionResolution, int flags) { Resources r = c.getResources(); long now = System.currentTimeMillis(); long duration = Math.abs(now - time); // getRelativeTimeSpanString() doesn't correctly format relative dates // above a week or exact dates below a day, so clamp // transitionResolution as needed. if (transitionResolution > WEEK_IN_MILLIS) { transitionResolution = WEEK_IN_MILLIS; } else if (transitionResolution < DAY_IN_MILLIS) { transitionResolution = DAY_IN_MILLIS; } CharSequence timeClause = DateUtils.formatDateRange(c, time, time, FORMAT_SHOW_TIME); String result; if (duration < transitionResolution) { CharSequence relativeClause = DateUtils.getRelativeTimeSpanString(time, now, minResolution, flags); result = r.getString(R.string.opentasks_relative_time, relativeClause, timeClause); } else { CharSequence dateClause = DateUtils.getRelativeTimeSpanString(c, time, false); result = r.getString(R.string.opentasks_date_time, dateClause, timeClause); } return result; }