Java Code Examples for android.text.format.DateUtils#DAY_IN_MILLIS
The following examples show how to use
android.text.format.DateUtils#DAY_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: DataReductionStatsPreference.java From 365browser with Apache License 2.0 | 6 votes |
/** * Updates the preference screen to convey current statistics on data reduction. */ public void updateReductionStatistics() { long original[] = DataReductionProxySettings.getInstance().getOriginalNetworkStatsHistory(); long received[] = DataReductionProxySettings.getInstance().getReceivedNetworkStatsHistory(); mCurrentTime = DataReductionProxySettings.getInstance().getDataReductionLastUpdateTime(); mRightPosition = mCurrentTime + DateUtils.HOUR_IN_MILLIS - TimeZone.getDefault().getOffset(mCurrentTime); mLeftPosition = mCurrentTime - DateUtils.DAY_IN_MILLIS * DAYS_IN_CHART; mOriginalNetworkStatsHistory = getNetworkStatsHistory(original, DAYS_IN_CHART); mReceivedNetworkStatsHistory = getNetworkStatsHistory(received, DAYS_IN_CHART); if (mDataReductionBreakdownView != null) { DataReductionProxySettings.getInstance().queryDataUsage( DAYS_IN_CHART, new Callback<List<DataReductionDataUseItem>>() { @Override public void onResult(List<DataReductionDataUseItem> result) { mDataReductionBreakdownView.onQueryDataUsageComplete(result); } }); } }
Example 2
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 3
Source File: DataReductionPreferences.java From AndroidChromium with Apache License 2.0 | 6 votes |
private static NetworkStatsHistory getNetworkStatsHistory(long[] history, int days) { if (days > history.length) days = history.length; NetworkStatsHistory networkStatsHistory = new NetworkStatsHistory( DateUtils.DAY_IN_MILLIS, days, NetworkStatsHistory.FIELD_RX_BYTES); DataReductionProxySettings config = DataReductionProxySettings.getInstance(); long time = config.getDataReductionLastUpdateTime() - days * DateUtils.DAY_IN_MILLIS; for (int i = history.length - days, bucket = 0; i < history.length; i++, bucket++) { NetworkStats.Entry entry = new NetworkStats.Entry(); entry.rxBytes = history[i]; long startTime = time + (DateUtils.DAY_IN_MILLIS * bucket); // Spread each day's record over the first hour of the day. networkStatsHistory.recordData( startTime, startTime + DateUtils.HOUR_IN_MILLIS, entry); } return networkStatsHistory; }
Example 4
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 5
Source File: PendingCalcs.java From commcare-android with Apache License 2.0 | 6 votes |
/** * @return True if there is a sync action pending. */ public static boolean getPendingSyncStatus() { SharedPreferences prefs = CommCareApplication.instance().getCurrentApp().getAppPreferences(); long period = -1; // new flag, read what it is. String periodic = prefs.getString(HiddenPreferences.AUTO_SYNC_FREQUENCY, PrefValues.FREQUENCY_NEVER); if (!periodic.equals(PrefValues.FREQUENCY_NEVER)) { period = DateUtils.DAY_IN_MILLIS * (periodic.equals(PrefValues.FREQUENCY_DAILY) ? 1 : 7); } else { // Old flag, use a day by default if ("true".equals(prefs.getString("cc-auto-update", "false"))) { period = DateUtils.DAY_IN_MILLIS; } } // If we didn't find a period, bail if (period == -1) { return false; } return PendingCalcs.isPending(HiddenPreferences.getLastUploadSyncAttempt(), period); }
Example 6
Source File: MarketStat.java From bitshares_wallet with MIT License | 5 votes |
private HistoryPrice[] getMarketHistory() { // 服务器每次最多返回200个bucket对象 /*final int maxBucketCount = 200; Date startDate1 = new Date( System.currentTimeMillis() - bucketSecs * maxBucketCount * 1000); Date startDate2 = new Date( System.currentTimeMillis() - bucketSecs * maxBucketCount * 2000); Date endDate = new Date(System.currentTimeMillis() + DateUtils.DAY_IN_MILLIS); List<bucket_object> buckets1 = getMarketHistory(startDate2, startDate1); List<bucket_object> buckets2 = getMarketHistory(startDate1, endDate); int numBuckets = (buckets1 != null ? buckets1.size() : 0) + (buckets2 != null ? buckets2.size() : 0); HistoryPrice[] prices = new HistoryPrice[numBuckets]; int priceIndex = 0; if (buckets1 != null) { for (int i = 0; i < buckets1.size(); i++) { bucket_object bucket = buckets1.get(i); prices[priceIndex++] = priceFromBucket(bucket); } } if (buckets2 != null) { for (int i = 0; i < buckets2.size(); i++) { bucket_object bucket = buckets2.get(i); prices[priceIndex++] = priceFromBucket(bucket); } } return prices;*/ Date startDate = new Date(System.currentTimeMillis() - 24 * 3600 * 7 * 1000); Date endDate = new Date(System.currentTimeMillis() + DateUtils.DAY_IN_MILLIS); List<bucket_object> bucketObjectList = getMarketHistory(startDate, endDate); if (bucketObjectList != null) { HistoryPrice[] prices = new HistoryPrice[bucketObjectList.size()]; for (int i = 0; i < prices.length; ++i) { prices[i] = priceFromBucket(bucketObjectList.get(i)); } return prices; } return null; }
Example 7
Source File: DataReductionStatsPreference.java From delion with Apache License 2.0 | 5 votes |
/** * Sets the current statistics for viewing. These include the original total daily size of * received resources before compression, and the actual total daily size of received * resources after compression. The last update time is specified in milliseconds since the * epoch. * @param lastUpdateTimeMillis The last time the statistics were updated. * @param networkStatsHistoryOriginal The history of original content lengths. * @param networkStatsHistoryReceived The history of received content lengths. */ public void setReductionStats( long lastUpdateTimeMillis, NetworkStatsHistory networkStatsHistoryOriginal, NetworkStatsHistory networkStatsHistoryReceived) { mCurrentTime = lastUpdateTimeMillis; mRightPosition = mCurrentTime + DateUtils.HOUR_IN_MILLIS - TimeZone.getDefault().getOffset(mCurrentTime); mLeftPosition = lastUpdateTimeMillis - DateUtils.DAY_IN_MILLIS * DAYS_IN_CHART; mOriginalNetworkStatsHistory = networkStatsHistoryOriginal; mReceivedNetworkStatsHistory = networkStatsHistoryReceived; }
Example 8
Source File: FileUtil.java From LockDemo with Apache License 2.0 | 5 votes |
public static int clearCacheFolder(final File dir, final int numDays) { int deletedFiles = 0; if (dir != null && dir.isDirectory()) { try { for (File child : dir.listFiles()) { // first delete subdirectories recursively if (child.isDirectory()) { deletedFiles += clearCacheFolder(child, numDays); } // then delete the files and subdirectories in this dir // only empty directories can be deleted, so subDirs have // been done first if (child.lastModified() < new Date().getTime() - numDays * DateUtils.DAY_IN_MILLIS) { if (child.delete()) { deletedFiles++; } } } } catch (Exception e) { } } return deletedFiles; }
Example 9
Source File: BusinessInterval.java From android with MIT License | 5 votes |
public void joinOvernight(BusinessInterval another) { if (abutsOvernight(this, another)) { this.endMillis = another.getEndMillis() + DateUtils.DAY_IN_MILLIS; } else if (abutsOvernight(another, this)) { this.dayOfWeek = another.dayOfWeek; this.startMillis = another.getStartMillis(); this.endMillis += DateUtils.DAY_IN_MILLIS; this.mainPrice = another.mainPrice; this.hourlyPrice = another.hourlyPrice; } }
Example 10
Source File: ToDayAdapter.java From ToDay with MIT License | 5 votes |
private void setDisplayType() { if (mIsAllDay) { mDisplayType = DISPLAY_TYPE_ALL_DAY; } else if (mStartTimeMillis >= mTimeMillis) { // start within agenda date mDisplayType = DISPLAY_TYPE_START_TIME; } else if (mEndTimeMillis < mTimeMillis + DateUtils.DAY_IN_MILLIS) { // start before, end within agenda date mDisplayType = DISPLAY_TYPE_END_TIME; } else { // start before, end after agenda date mDisplayType = DISPLAY_TYPE_ALL_DAY; } }
Example 11
Source File: OrgCalendarEntry.java From mOrgAnd with GNU General Public License v2.0 | 5 votes |
public OrgCalendarEntry(String date) throws IllegalArgumentException { Matcher schedule = schedulePattern.matcher(date); if (schedule.find()) { try { if(schedule.group(BEGIN_TIME) == null) { // event is an entire day event this.beginTime = CalendarUtils.dateformatter.parse(schedule.group(DATE)).getTime(); // All day events need to be in UTC and end time is exactly one day after this.beginTime = CalendarUtils.getDayInUTC(beginTime); this.endTime = this.beginTime + DateUtils.DAY_IN_MILLIS; this.allDay = 1; } else if (schedule.group(BEGIN_TIME) != null && schedule.group(END_TIME) != null) { this.beginTime = CalendarUtils.dateTimeformatter.parse(schedule.group(DATE) + " " + schedule.group(BEGIN_TIME)).getTime(); this.endTime = CalendarUtils.dateTimeformatter.parse(schedule.group(DATE) + " " + schedule.group(END_TIME)).getTime(); this.allDay = 0; } else if(schedule.group(BEGIN_TIME) != null) { this.beginTime = CalendarUtils.dateTimeformatter.parse(schedule.group(DATE) + " " + schedule.group(BEGIN_TIME)).getTime(); this.endTime = beginTime + DateUtils.HOUR_IN_MILLIS; this.allDay = 0; } return; } catch (ParseException e) { Log.w("MobileOrg", "Unable to parse schedule: " + date); } } else throw new IllegalArgumentException("Could not create date out of entry"); }
Example 12
Source File: TweetDateUtilsTest.java From twitter-kit-android with Apache License 2.0 | 4 votes |
@Test public void testGetRelativeTimeString_daysAgo() { final long twoDaysAgo = NOW_IN_MILLIS - DateUtils.DAY_IN_MILLIS * 2; assertEquals("Mar 18", TweetDateUtils.getRelativeTimeString(resources, NOW_IN_MILLIS, twoDaysAgo)); }
Example 13
Source File: SunshineSyncTask.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * Performs the network request for updated weather, parses the JSON from that request, and * inserts the new weather information into our ContentProvider. Will notify the user that new * weather has been loaded if the user hasn't been notified of the weather within the last day * AND they haven't disabled notifications in the preferences screen. * * @param context Used to access utility methods and the ContentResolver */ synchronized public static void syncWeather(Context context) { try { /* * The getUrl method will return the URL that we need to get the forecast JSON for the * weather. It will decide whether to create a URL based off of the latitude and * longitude or off of a simple location as a String. */ URL weatherRequestUrl = NetworkUtils.getUrl(context); /* Use the URL to retrieve the JSON */ String jsonWeatherResponse = NetworkUtils.getResponseFromHttpUrl(weatherRequestUrl); /* Parse the JSON into a list of weather values */ ContentValues[] weatherValues = OpenWeatherJsonUtils .getWeatherContentValuesFromJson(context, jsonWeatherResponse); /* * In cases where our JSON contained an error code, getWeatherContentValuesFromJson * would have returned null. We need to check for those cases here to prevent any * NullPointerExceptions being thrown. We also have no reason to insert fresh data if * there isn't any to insert. */ if (weatherValues != null && weatherValues.length != 0) { /* Get a handle on the ContentResolver to delete and insert data */ ContentResolver sunshineContentResolver = context.getContentResolver(); /* Delete old weather data because we don't need to keep multiple days' data */ sunshineContentResolver.delete( WeatherContract.WeatherEntry.CONTENT_URI, null, null); /* Insert our new weather data into Sunshine's ContentProvider */ sunshineContentResolver.bulkInsert( WeatherContract.WeatherEntry.CONTENT_URI, weatherValues); /* * Finally, after we insert data into the ContentProvider, determine whether or not * we should notify the user that the weather has been refreshed. */ boolean notificationsEnabled = SunshinePreferences.areNotificationsEnabled(context); /* * If the last notification was shown was more than 1 day ago, we want to send * another notification to the user that the weather has been updated. Remember, * it's important that you shouldn't spam your users with notifications. */ long timeSinceLastNotification = SunshinePreferences .getEllapsedTimeSinceLastNotification(context); boolean oneDayPassedSinceLastNotification = false; if (timeSinceLastNotification >= DateUtils.DAY_IN_MILLIS) { oneDayPassedSinceLastNotification = true; } /* * We only want to show the notification if the user wants them shown and we * haven't shown a notification in the past day. */ if (notificationsEnabled && oneDayPassedSinceLastNotification) { NotificationUtils.notifyUserOfNewWeather(context); } /* If the code reaches this point, we have successfully performed our sync */ } } catch (Exception e) { /* Server probably invalid */ e.printStackTrace(); } }
Example 14
Source File: SunshineSyncTask.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * Performs the network request for updated weather, parses the JSON from that request, and * inserts the new weather information into our ContentProvider. Will notify the user that new * weather has been loaded if the user hasn't been notified of the weather within the last day * AND they haven't disabled notifications in the preferences screen. * * @param context Used to access utility methods and the ContentResolver */ synchronized public static void syncWeather(Context context) { try { /* * The getUrl method will return the URL that we need to get the forecast JSON for the * weather. It will decide whether to create a URL based off of the latitude and * longitude or off of a simple location as a String. */ URL weatherRequestUrl = NetworkUtils.getUrl(context); /* Use the URL to retrieve the JSON */ String jsonWeatherResponse = NetworkUtils.getResponseFromHttpUrl(weatherRequestUrl); /* Parse the JSON into a list of weather values */ ContentValues[] weatherValues = OpenWeatherJsonUtils .getWeatherContentValuesFromJson(context, jsonWeatherResponse); /* * In cases where our JSON contained an error code, getWeatherContentValuesFromJson * would have returned null. We need to check for those cases here to prevent any * NullPointerExceptions being thrown. We also have no reason to insert fresh data if * there isn't any to insert. */ if (weatherValues != null && weatherValues.length != 0) { /* Get a handle on the ContentResolver to delete and insert data */ ContentResolver sunshineContentResolver = context.getContentResolver(); /* Delete old weather data because we don't need to keep multiple days' data */ sunshineContentResolver.delete( WeatherContract.WeatherEntry.CONTENT_URI, null, null); /* Insert our new weather data into Sunshine's ContentProvider */ sunshineContentResolver.bulkInsert( WeatherContract.WeatherEntry.CONTENT_URI, weatherValues); /* * Finally, after we insert data into the ContentProvider, determine whether or not * we should notify the user that the weather has been refreshed. */ boolean notificationsEnabled = SunshinePreferences.areNotificationsEnabled(context); /* * If the last notification was shown was more than 1 day ago, we want to send * another notification to the user that the weather has been updated. Remember, * it's important that you shouldn't spam your users with notifications. */ long timeSinceLastNotification = SunshinePreferences .getEllapsedTimeSinceLastNotification(context); boolean oneDayPassedSinceLastNotification = false; if (timeSinceLastNotification >= DateUtils.DAY_IN_MILLIS) { oneDayPassedSinceLastNotification = true; } /* * We only want to show the notification if the user wants them shown and we * haven't shown a notification in the past day. */ if (notificationsEnabled && oneDayPassedSinceLastNotification) { NotificationUtils.notifyUserOfNewWeather(context); } /* If the code reaches this point, we have successfully performed our sync */ } } catch (Exception e) { /* Server probably invalid */ e.printStackTrace(); } }
Example 15
Source File: SunshineSyncTask.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * Performs the network request for updated weather, parses the JSON from that request, and * inserts the new weather information into our ContentProvider. Will notify the user that new * weather has been loaded if the user hasn't been notified of the weather within the last day * AND they haven't disabled notifications in the preferences screen. * * @param context Used to access utility methods and the ContentResolver */ synchronized public static void syncWeather(Context context) { try { /* * The getUrl method will return the URL that we need to get the forecast JSON for the * weather. It will decide whether to create a URL based off of the latitude and * longitude or off of a simple location as a String. */ URL weatherRequestUrl = NetworkUtils.getUrl(context); /* Use the URL to retrieve the JSON */ String jsonWeatherResponse = NetworkUtils.getResponseFromHttpUrl(weatherRequestUrl); /* Parse the JSON into a list of weather values */ ContentValues[] weatherValues = OpenWeatherJsonUtils .getWeatherContentValuesFromJson(context, jsonWeatherResponse); /* * In cases where our JSON contained an error code, getWeatherContentValuesFromJson * would have returned null. We need to check for those cases here to prevent any * NullPointerExceptions being thrown. We also have no reason to insert fresh data if * there isn't any to insert. */ if (weatherValues != null && weatherValues.length != 0) { /* Get a handle on the ContentResolver to delete and insert data */ ContentResolver sunshineContentResolver = context.getContentResolver(); /* Delete old weather data because we don't need to keep multiple days' data */ sunshineContentResolver.delete( WeatherContract.WeatherEntry.CONTENT_URI, null, null); /* Insert our new weather data into Sunshine's ContentProvider */ sunshineContentResolver.bulkInsert( WeatherContract.WeatherEntry.CONTENT_URI, weatherValues); /* * Finally, after we insert data into the ContentProvider, determine whether or not * we should notify the user that the weather has been refreshed. */ boolean notificationsEnabled = SunshinePreferences.areNotificationsEnabled(context); /* * If the last notification was shown was more than 1 day ago, we want to send * another notification to the user that the weather has been updated. Remember, * it's important that you shouldn't spam your users with notifications. */ long timeSinceLastNotification = SunshinePreferences .getEllapsedTimeSinceLastNotification(context); boolean oneDayPassedSinceLastNotification = false; if (timeSinceLastNotification >= DateUtils.DAY_IN_MILLIS) { oneDayPassedSinceLastNotification = true; } /* * We only want to show the notification if the user wants them shown and we * haven't shown a notification in the past day. */ if (notificationsEnabled && oneDayPassedSinceLastNotification) { NotificationUtils.notifyUserOfNewWeather(context); } /* If the code reaches this point, we have successfully performed our sync */ } } catch (Exception e) { /* Server probably invalid */ e.printStackTrace(); } }
Example 16
Source File: SunshineSyncTask.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * Performs the network request for updated weather, parses the JSON from that request, and * inserts the new weather information into our ContentProvider. Will notify the user that new * weather has been loaded if the user hasn't been notified of the weather within the last day * AND they haven't disabled notifications in the preferences screen. * * @param context Used to access utility methods and the ContentResolver */ synchronized public static void syncWeather(Context context) { try { /* * The getUrl method will return the URL that we need to get the forecast JSON for the * weather. It will decide whether to create a URL based off of the latitude and * longitude or off of a simple location as a String. */ URL weatherRequestUrl = NetworkUtils.getUrl(context); /* Use the URL to retrieve the JSON */ String jsonWeatherResponse = NetworkUtils.getResponseFromHttpUrl(weatherRequestUrl); /* Parse the JSON into a list of weather values */ ContentValues[] weatherValues = OpenWeatherJsonUtils .getWeatherContentValuesFromJson(context, jsonWeatherResponse); /* * In cases where our JSON contained an error code, getWeatherContentValuesFromJson * would have returned null. We need to check for those cases here to prevent any * NullPointerExceptions being thrown. We also have no reason to insert fresh data if * there isn't any to insert. */ if (weatherValues != null && weatherValues.length != 0) { /* Get a handle on the ContentResolver to delete and insert data */ ContentResolver sunshineContentResolver = context.getContentResolver(); /* Delete old weather data because we don't need to keep multiple days' data */ sunshineContentResolver.delete( WeatherContract.WeatherEntry.CONTENT_URI, null, null); /* Insert our new weather data into Sunshine's ContentProvider */ sunshineContentResolver.bulkInsert( WeatherContract.WeatherEntry.CONTENT_URI, weatherValues); /* * Finally, after we insert data into the ContentProvider, determine whether or not * we should notify the user that the weather has been refreshed. */ boolean notificationsEnabled = SunshinePreferences.areNotificationsEnabled(context); /* * If the last notification was shown was more than 1 day ago, we want to send * another notification to the user that the weather has been updated. Remember, * it's important that you shouldn't spam your users with notifications. */ long timeSinceLastNotification = SunshinePreferences .getEllapsedTimeSinceLastNotification(context); boolean oneDayPassedSinceLastNotification = false; if (timeSinceLastNotification >= DateUtils.DAY_IN_MILLIS) { oneDayPassedSinceLastNotification = true; } /* * We only want to show the notification if the user wants them shown and we * haven't shown a notification in the past day. */ if (notificationsEnabled && oneDayPassedSinceLastNotification) { NotificationUtils.notifyUserOfNewWeather(context); } /* If the code reaches this point, we have successfully performed our sync */ } } catch (Exception e) { /* Server probably invalid */ e.printStackTrace(); } }
Example 17
Source File: BusinessInterval.java From android with MIT License | 4 votes |
public Builder allDay() { this.startMillis = 0; this.endMillis = DateUtils.DAY_IN_MILLIS; return this; }
Example 18
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 19
Source File: TweetDateUtilsTest.java From twitter-kit-android with Apache License 2.0 | 4 votes |
@Test public void testGetRelativeTimeString_moreThanAYearAgo() { final long twoYearsAgo = NOW_IN_MILLIS - DateUtils.DAY_IN_MILLIS * 730; assertEquals("03/20/12", TweetDateUtils.getRelativeTimeString(resources, NOW_IN_MILLIS, twoYearsAgo)); }
Example 20
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; }