Java Code Examples for android.text.format.DateUtils#WEEK_IN_MILLIS
The following examples show how to use
android.text.format.DateUtils#WEEK_IN_MILLIS .
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: LocalNotificationSchedule.java From OsmGo with MIT License | 6 votes |
/** * Get constant long value representing specific interval of time (weeks, days etc.) */ public Long getEveryInterval() { switch (every) { case "year": return DateUtils.YEAR_IN_MILLIS; case "month": // This case is just approximation as months have different number of days return 30 * DateUtils.DAY_IN_MILLIS; case "two-weeks": return 2 * DateUtils.WEEK_IN_MILLIS; case "week": return DateUtils.WEEK_IN_MILLIS; case "day": return DateUtils.DAY_IN_MILLIS; case "hour": return DateUtils.HOUR_IN_MILLIS; case "minute": return DateUtils.MINUTE_IN_MILLIS; case "second": return DateUtils.SECOND_IN_MILLIS; default: return null; } }
Example 2
Source File: AppUtils.java From materialistic with Apache License 2.0 | 6 votes |
public static String getAbbreviatedTimeSpan(long timeMillis) { long span = Math.max(System.currentTimeMillis() - timeMillis, 0); if (span >= DateUtils.YEAR_IN_MILLIS) { return (span / DateUtils.YEAR_IN_MILLIS) + ABBR_YEAR; } if (span >= DateUtils.WEEK_IN_MILLIS) { return (span / DateUtils.WEEK_IN_MILLIS) + ABBR_WEEK; } if (span >= DateUtils.DAY_IN_MILLIS) { return (span / DateUtils.DAY_IN_MILLIS) + ABBR_DAY; } if (span >= DateUtils.HOUR_IN_MILLIS) { return (span / DateUtils.HOUR_IN_MILLIS) + ABBR_HOUR; } return (span / DateUtils.MINUTE_IN_MILLIS) + ABBR_MINUTE; }
Example 3
Source File: AlgoliaPopularClient.java From materialistic with Apache License 2.0 | 6 votes |
private long toTimestamp(@Range String filter) { long timestamp = System.currentTimeMillis(); switch (filter) { case LAST_24H: default: timestamp -= DateUtils.DAY_IN_MILLIS; break; case PAST_WEEK: timestamp -= DateUtils.WEEK_IN_MILLIS; break; case PAST_MONTH: timestamp -= DateUtils.WEEK_IN_MILLIS * 4; break; case PAST_YEAR: timestamp -= DateUtils.YEAR_IN_MILLIS; break; } return timestamp; }
Example 4
Source File: SpotRules.java From android with MIT License | 6 votes |
/** * For a 24/7 interval, return remaining parking time. * For NONE and PAID, duration is a full week. * For time-based restrictions, duration is TimeMax. * * @param intervals The agenda's intervals, sorted and starting today * @return Millis remaining following the 24/7 interval rule */ private static long getFullWeekRemainingTime(RestrIntervalsList intervals) { final RestrInterval interval = intervals.get(0); switch (interval.getType()) { case Const.ParkingRestrType.ALL_TIMES: // Special case when viewing a NoParking spot. // UX doesn't normally display SpotInfo for such spots. return 0; case Const.ParkingRestrType.TIME_MAX: case Const.ParkingRestrType.TIME_MAX_PAID: return interval.getTimeMaxMillis(); case Const.ParkingRestrType.PAID: case Const.ParkingRestrType.NONE: default: return DateUtils.WEEK_IN_MILLIS; } }
Example 5
Source File: DateTimeUtils.java From Qiitanium with MIT License | 6 votes |
public static String timeAgo(Date d) { final long referenceTime = d.getTime(); final long nowTime = System.currentTimeMillis(); final long diffTime = Math.abs(nowTime - referenceTime); if (diffTime > DateUtils.WEEK_IN_MILLIS) { return format(d, TIMEFORMAT_DEFAULT); } else if (diffTime > DateUtils.DAY_IN_MILLIS) { return String.format(TIMEAGO_DAYS_AGO, diffTime / DateUtils.DAY_IN_MILLIS); } else if (diffTime > DateUtils.HOUR_IN_MILLIS) { return String.format(TIMEAGO_HOURS_AGO, diffTime / DateUtils.HOUR_IN_MILLIS); } else if (diffTime > DateUtils.MINUTE_IN_MILLIS) { return String.format(TIMEAGO_MINUTES_AGO, diffTime / DateUtils.MINUTE_IN_MILLIS); } else { return TIMEAGO_JUST_NOW; } }
Example 6
Source File: StorageManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private String scrubPath(String path) { if (path.startsWith(Environment.getDataDirectory().getAbsolutePath())) { return "internal"; } final VolumeRecord rec = findRecordForPath(path); if (rec == null || rec.createdMillis == 0) { return "unknown"; } else { return "ext:" + (int) ((System.currentTimeMillis() - rec.createdMillis) / DateUtils.WEEK_IN_MILLIS) + "w"; } }
Example 7
Source File: FdroidListTask.java From YalpStore with GNU General Public License v2.0 | 5 votes |
@Override protected Void doInBackground(Void... voids) { if (localXmlFile.exists() && localXmlFile.lastModified() + DateUtils.WEEK_IN_MILLIS < System.currentTimeMillis()) { localXmlFile.delete(); } if (!localXmlFile.exists()) { downloadXml(); } parseXml(); Log.i(getClass().getSimpleName(), "F-Droid app list size: " + YalpStoreApplication.fdroidPackageNames.size()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { localXmlFile.delete(); } return null; }
Example 8
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 9
Source File: RelativeTimeTextView.java From Ninja with Apache License 2.0 | 5 votes |
@Override public void run() { long difference = Math.abs(System.currentTimeMillis() - mRefTime); long interval = DateUtils.MINUTE_IN_MILLIS; if (difference > DateUtils.WEEK_IN_MILLIS) { interval = DateUtils.WEEK_IN_MILLIS; } else if (difference > DateUtils.DAY_IN_MILLIS) { interval = DateUtils.DAY_IN_MILLIS; } else if (difference > DateUtils.HOUR_IN_MILLIS) { interval = DateUtils.HOUR_IN_MILLIS; } updateTextDisplay(); mHandler.postDelayed(this, interval); }
Example 10
Source File: RelativeTimeTextView.java From Cracker with Apache License 2.0 | 5 votes |
@Override public void run() { long difference = Math.abs(System.currentTimeMillis() - mRefTime); long interval = DateUtils.MINUTE_IN_MILLIS; if (difference > DateUtils.WEEK_IN_MILLIS) { interval = DateUtils.WEEK_IN_MILLIS; } else if (difference > DateUtils.DAY_IN_MILLIS) { interval = DateUtils.DAY_IN_MILLIS; } else if (difference > DateUtils.HOUR_IN_MILLIS) { interval = DateUtils.HOUR_IN_MILLIS; } updateTextDisplay(); mHandler.postDelayed(this, interval); }
Example 11
Source File: RelativeTimeTextView.java From Tweetin with Apache License 2.0 | 5 votes |
@Override public void run() { long difference = Math.abs(System.currentTimeMillis() - mRefTime); long interval = DateUtils.MINUTE_IN_MILLIS; if (difference > DateUtils.WEEK_IN_MILLIS) { interval = DateUtils.WEEK_IN_MILLIS; } else if (difference > DateUtils.DAY_IN_MILLIS) { interval = DateUtils.DAY_IN_MILLIS; } else if (difference > DateUtils.HOUR_IN_MILLIS) { interval = DateUtils.HOUR_IN_MILLIS; } updateTextDisplay(); mHandler.postDelayed(this, interval); }
Example 12
Source File: RelativeTimeTextView.java From v2ex-daily-android with Apache License 2.0 | 5 votes |
public void run() { long difference = Math.abs(System.currentTimeMillis() - mReferenceTime); long interval = DateUtils.MINUTE_IN_MILLIS; if (difference > DateUtils.WEEK_IN_MILLIS) { interval = DateUtils.WEEK_IN_MILLIS; } else if (difference > DateUtils.DAY_IN_MILLIS) { interval = DateUtils.DAY_IN_MILLIS; } else if (difference > DateUtils.HOUR_IN_MILLIS) { interval = DateUtils.HOUR_IN_MILLIS; } updateTextDisplay(); mHandler.postDelayed(this, interval); }
Example 13
Source File: RelativeTimeTextView.java From WaniKani-for-Android with GNU General Public License v3.0 | 5 votes |
@Override public void run() { long difference = Math.abs(System.currentTimeMillis() - mRefTime); long interval = DateUtils.MINUTE_IN_MILLIS; if (difference > DateUtils.WEEK_IN_MILLIS) { interval = DateUtils.WEEK_IN_MILLIS; } else if (difference > DateUtils.DAY_IN_MILLIS) { interval = DateUtils.DAY_IN_MILLIS; } else if (difference > DateUtils.HOUR_IN_MILLIS) { interval = DateUtils.HOUR_IN_MILLIS; } updateTextDisplay(); mHandler.postDelayed(this, interval); }
Example 14
Source File: LotAgenda.java From android with MIT License | 4 votes |
/** * @param now * @return */ public LotCurrentStatus getLotCurrentStatus(long now) { final int today = CalendarUtils.getIsoDayOfWeek(); buildBusinessIntervalsIfNecessary(today); int index = 0; for (BusinessInterval interval : businessIntervals) { if (interval.contains(now)) { switch (interval.getType()) { case Const.BusinnessHourType.CLOSED: return null; case Const.BusinnessHourType.FREE: return getFreeLotStatus( interval, 1 + index, now); case Const.BusinnessHourType.OPEN: final long remainingMillis; if (businessIntervals.isTwentyFourSevenRestr()) { remainingMillis = DateUtils.WEEK_IN_MILLIS; } else { final BusinessInterval currentInterval = businessIntervals.get( businessIntervals.findLastAbuttingInterval(index) ); remainingMillis = (currentInterval.getEndMillis() - now) + (CalendarUtils.subtractDaysOfWeekLooped(currentInterval.getDayOfWeek(), today) * DateUtils.DAY_IN_MILLIS ); } return new LotCurrentStatus( interval.getMainPrice(), interval.getHourlyPrice(), remainingMillis, interval.isFree() ); } } index++; } return null; }
Example 15
Source File: SpotRules.java From android with MIT License | 4 votes |
/** * Get the time remaining (in millis) before the end of the current interval, * or the beginning of the next restriction interval. * The duration takes handles multi-day intervals and the looping week. * * @param intervals The agenda's intervals, sorted and starting today * @param now the daytime current timestamp * @return Millis remaining before the end of current interval. Max is WEEK_IN_MILLIS */ public static long getRemainingTime(RestrIntervalsList intervals, long now) { if (intervals == null || intervals.isEmpty()) { return DateUtils.WEEK_IN_MILLIS; } if (intervals.isTwentyFourSevenRestr()) { return getFullWeekRemainingTime(intervals); } final int today = CalendarUtils.getIsoDayOfWeek(); int index = intervals.findLastAbuttingInterval( intervals.findContainingIntervalToday(now, today) ); if (index != Const.UNKNOWN_VALUE) { final RestrInterval currentInterval = intervals.get(index); // Time between now/today and the interval's end final long timeRemaining = (currentInterval.getEndMillis() - now) + (CalendarUtils.subtractDaysOfWeekLooped(currentInterval.getDayOfWeek(), today) * DateUtils.DAY_IN_MILLIS ); switch (currentInterval.getType()) { case Const.ParkingRestrType.PAID: return timeRemaining; case Const.ParkingRestrType.NONE: return getFreeParkingRemainingTime(intervals, today, now); case Const.ParkingRestrType.TIME_MAX: final Long timeMaxMillis = currentInterval.getTimeMaxMillis(); if (timeMaxMillis.compareTo(timeRemaining) < 0) { return timeMaxMillis; } else { return getFreeParkingRemainingTime(intervals, today, now); } case Const.ParkingRestrType.TIME_MAX_PAID: // For TimeMaxPaid, time cannot be greater than TimeMax duration return Math.min(timeRemaining, currentInterval.getTimeMaxMillis()); case Const.ParkingRestrType.ALL_TIMES: // Special case when viewing a NoParking spot. // UX doesn't normally display SpotInfo for such spots. return 0; } } else { return getFreeParkingRemainingTime(intervals, today, now); } // Free parking all week long! return DateUtils.WEEK_IN_MILLIS; }
Example 16
Source File: ItemRequestHandler.java From cathode with Apache License 2.0 | 4 votes |
private boolean needsUpdate(long lastUpdated) { return lastUpdated + DateUtils.WEEK_IN_MILLIS < System.currentTimeMillis(); }