Java Code Examples for android.text.format.DateUtils#YEAR_IN_MILLIS

The following examples show how to use android.text.format.DateUtils#YEAR_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 vote down vote up
/**
 * 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 vote down vote up
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 vote down vote up
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: CacheQuotaStrategy.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list of CacheQuotaHints which do not have their quotas filled out for apps
 * which have been used in the last year.
 */
private List<CacheQuotaHint> getUnfulfilledRequests() {
    long timeNow = System.currentTimeMillis();
    long oneYearAgo = timeNow - DateUtils.YEAR_IN_MILLIS;

    List<CacheQuotaHint> requests = new ArrayList<>();
    UserManager um = mContext.getSystemService(UserManager.class);
    final List<UserInfo> users = um.getUsers();
    final int userCount = users.size();
    final PackageManager packageManager = mContext.getPackageManager();
    for (int i = 0; i < userCount; i++) {
        UserInfo info = users.get(i);
        List<UsageStats> stats =
                mUsageStats.queryUsageStatsForUser(info.id, UsageStatsManager.INTERVAL_BEST,
                        oneYearAgo, timeNow, /*obfuscateInstantApps=*/ false);
        if (stats == null) {
            continue;
        }

        for (UsageStats stat : stats) {
            String packageName = stat.getPackageName();
            try {
                // We need the app info to determine the uid and the uuid of the volume
                // where the app is installed.
                ApplicationInfo appInfo = packageManager.getApplicationInfoAsUser(
                        packageName, 0, info.id);
                requests.add(
                        new CacheQuotaHint.Builder()
                                .setVolumeUuid(appInfo.volumeUuid)
                                .setUid(appInfo.uid)
                                .setUsageStats(stat)
                                .setQuota(CacheQuotaHint.QUOTA_NOT_SET)
                                .build());
            } catch (PackageManager.NameNotFoundException e) {
                // This may happen if an app has a recorded usage, but has been uninstalled.
                continue;
            }
        }
    }
    return requests;
}