Java Code Examples for android.text.format.DateUtils#isToday()
The following examples show how to use
android.text.format.DateUtils#isToday() .
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: TimelineView.java From datepicker-timeline with MIT License | 6 votes |
@Override public void onBindViewHolder(TimelineViewHolder holder, int position) { // Set calendar resetCalendar(); calendar.add(Calendar.DAY_OF_YEAR, position); // Get values int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); int day = calendar.get(Calendar.DAY_OF_MONTH); boolean isToday = DateUtils.isToday(calendar.getTimeInMillis()); holder.bind(position, year, month, day, dayOfWeek, dateLabelAdapter != null ? dateLabelAdapter.getLabel(calendar, position) : "", position == selectedPosition, isToday); }
Example 2
Source File: ListItemUtils.java From mytracks with Apache License 2.0 | 6 votes |
/** * Gets the date and time as an array of two strings. * * @param isRecording true if recording * @param context the context * @param time the start time */ private static String[] getDateTime( boolean isRecording, Context context, long time, boolean useRelativeTime) { if (isRecording || time == 0L) { return new String[] { null, null }; } boolean isToday = DateUtils.isToday(time); int timeFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL; if (isToday) { if (useRelativeTime) { return new String[] { DateUtils.getRelativeTimeSpanString( time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString(), null }; } else { return new String[] { DateUtils.formatDateTime(context, time, timeFlags), null }; } } return new String[] { DateUtils.formatDateTime( context, time, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL), DateUtils.formatDateTime(context, time, timeFlags) }; }
Example 3
Source File: HistoryPresenter.java From iroha-android with Apache License 2.0 | 5 votes |
private String getHeader(Date date, SimpleDateFormat dateFormat, Date today, Date yesterday) { if (DateUtils.isToday(date.getTime())) { return "Today"; } else if (date.before(today) && date.after(yesterday)) { return "Yesterday"; } else { return dateFormat.format(date); } }
Example 4
Source File: WeatherView.java From TabletClock with MIT License | 5 votes |
public void setWeather(Weather weather) { String when = ""; if (weather.getDatePeriodHours() == 0) { when = getContext().getText(R.string.now).toString(); } else if (weather.getDatePeriodHours() >= 24) { if (DateUtils.isToday(weather.getDate().getTime())) { when = getResources().getString(R.string.today); } else { SimpleDateFormat sdf = new SimpleDateFormat("d, EEEE", Locale.getDefault()); when = sdf.format(weather.getDate()); } } else if (weather.getDatePeriodHours() < 12) { Calendar cal = Calendar.getInstance(); cal.setTime(weather.getDate()); int h = cal.get(Calendar.HOUR_OF_DAY); when = cal.get(Calendar.DAY_OF_MONTH) + ", "; if (h < 6) { when += getContext().getText(R.string.night); } else if (h >= 6 && h < 12) { when += getContext().getText(R.string.morning); } else if (h >= 12 && h < 18) { when += getContext().getText(R.string.day); } if (h >= 18) { when += getContext().getText(R.string.evening); } } when += ":"; mWhenView.setTextSize(mFontSize); Style.adjustFontSizeForWidth(mWhenView, when, mIconViewWidth + ICON_PADDING * 2); mWhenView.setText(when); setIcon(weather); mDescriptionView.setText(getDesribeString(weather)); }
Example 5
Source File: Utils.java From react-native-date-picker with MIT License | 4 votes |
public static boolean isToday(Calendar cal){ return DateUtils.isToday(cal.getTimeInMillis()); }
Example 6
Source File: FeatureTestActivity.java From calendarview2 with MIT License | 4 votes |
@Override public boolean shouldDecorate(CalendarDay day) { boolean result = DateUtils.isToday(day.getDate().getTime()); isSelected = view.getSelectedDates().contains(day); return result; }
Example 7
Source File: DateUtil.java From talk-android with MIT License | 4 votes |
public static boolean isToday(Date date) { return DateUtils.isToday(date.getTime()); }
Example 8
Source File: DateUtil.java From talk-android with MIT License | 4 votes |
public static boolean isTodayOrBefore(Date date) { return DateUtils.isToday(date.getTime()) || date.before(new Date()); }
Example 9
Source File: DateUtility.java From Loop with Apache License 2.0 | 4 votes |
public static boolean isToday(Calendar calendar){ return DateUtils.isToday(calendar.getTimeInMillis()); }
Example 10
Source File: DateUtility.java From Loop with Apache License 2.0 | 4 votes |
public static boolean isTomorrow(Calendar calendar){ Calendar cal = (Calendar) calendar.clone(); cal.add(Calendar.DAY_OF_YEAR, -1); return DateUtils.isToday(cal.getTimeInMillis()); }
Example 11
Source File: ObservationListAdapter.java From mage-android with Apache License 2.0 | 4 votes |
private void bindObservationViewHolder(RecyclerView.ViewHolder holder, int position) { if (cursor == null) return; cursor.moveToPosition(position); ObservationViewHolder vh = (ObservationViewHolder) holder; try { final Observation observation = query.mapRow(new AndroidDatabaseResults(cursor, null, false)); vh.bind(observation, observationActionListener); Drawable markerPlaceholder = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_place_white_48dp)); DrawableCompat.setTint(markerPlaceholder, ContextCompat.getColor(context, R.color.icon)); DrawableCompat.setTintMode(markerPlaceholder, PorterDuff.Mode.SRC_IN); vh.markerView.setImageDrawable(markerPlaceholder); vh.iconTask = new IconTask(vh.markerView); vh.iconTask.execute(observation); vh.primaryView.setText(""); vh.primaryPropertyTask = new PropertyTask(PropertyTask.Type.PRIMARY, vh.primaryView); vh.primaryPropertyTask.execute(observation); vh.secondaryView.setText(""); vh.secondaryPropertyTask = new PropertyTask(PropertyTask.Type.SECONDARY, vh.secondaryView); vh.secondaryPropertyTask.execute(observation); Date timestamp = observation.getTimestamp(); String pattern = DateUtils.isToday(timestamp.getTime()) ? SHORT_TIME_PATTERN : SHORT_DATE_PATTERN; DateFormat dateFormat = new SimpleDateFormat(pattern, Locale.getDefault()); vh.timeView.setText(dateFormat.format(timestamp)); vh.userView.setText(""); vh.userTask = new UserTask(vh.userView); vh.userTask.execute(observation); vh.importantButton.setOnClickListener(v -> observationActionListener.onObservationImportant(observation)); setImportantView(observation.getImportant(), vh); ObservationError error = observation.getError(); if (error != null) { boolean hasValidationError = error.getStatusCode() != null; vh.syncBadge.setVisibility(hasValidationError ? View.GONE : View.VISIBLE); vh.errorBadge.setVisibility(hasValidationError ? View.VISIBLE : View.GONE); } else { vh.syncBadge.setVisibility(View.GONE); vh.errorBadge.setVisibility(View.GONE); } vh.attachmentLayout.removeAllViews(); if (observation.getAttachments().size() == 0) { vh.attachmentLayout.setVisibility(View.GONE); } else { vh.attachmentLayout.setVisibility(View.VISIBLE); attachmentGallery.addAttachments(vh.attachmentLayout, observation.getAttachments()); } vh.favoriteButton.setOnClickListener(v -> toggleFavorite(observation, vh)); setFavoriteImage(observation.getFavorites(), vh, isFavorite(observation)); vh.directionsButton.setOnClickListener(v -> getDirections(observation)); } catch (SQLException e) { e.printStackTrace(); } }
Example 12
Source File: DateFormatterUtil.java From msdkui-android with Apache License 2.0 | 3 votes |
/** * Converts {@link Date} to a short string representation using abbreviations. * * <p>In general, times are abbreviated by not showing the minutes if they are 0. * For example, instead of "3:00pm" the time would be abbreviated to "3pm". * If date is not today, month is shown as a 3-letter string.</p> * * @param context * the required context. * @param date * the {@link Date} to be converted to string representation. * * @return a string containing the formatted date. */ public static String format(final Context context, final Date date) { if (DateUtils.isToday(date.getTime())) { return DateUtils.formatDateTime(context, date.getTime(), FORMAT_SHORT_TIME); } return DateUtils.formatDateTime(context, date.getTime(), DateUtils.FORMAT_SHOW_TIME | FORMAT_DAY_AND_SHORT_MONTH); }
Example 13
Source File: DateTimeUtils.java From DateTimeUtils with MIT License | 2 votes |
/** * Tell whether or not a given date is today date * @param date Date object * @return True if date is today False otherwise */ public static boolean isToday(Date date){ return DateUtils.isToday(date.getTime()); }