当前位置: 首页>>代码示例>>Java>>正文


Java AlarmManager.INTERVAL_HOUR属性代码示例

本文整理汇总了Java中android.app.AlarmManager.INTERVAL_HOUR属性的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.INTERVAL_HOUR属性的具体用法?Java AlarmManager.INTERVAL_HOUR怎么用?Java AlarmManager.INTERVAL_HOUR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.app.AlarmManager的用法示例。


在下文中一共展示了AlarmManager.INTERVAL_HOUR属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSharedPreferenceChanged

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    final String remindersKey = getString(R.string.pref_key_reminders);
    if (key.equals(remindersKey)) {
        boolean enabled = sharedPreferences.getBoolean(remindersKey, false);
        JobScheduler jobScheduler =
                (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);

        if (!enabled) {
            jobScheduler.cancel(JOB_ID);
            Log.d(TAG, "cancelling scheduled job");
        } else {
            long interval = AlarmManager.INTERVAL_HOUR;
            JobInfo job = new JobInfo.Builder(JOB_ID,
                    new ComponentName(getPackageName(),
                            ScheduledJobService.class.getName()))
                    .setPersisted(true)
                    .setPeriodic(interval)
                    .build();
            jobScheduler.schedule(job);
            Log.d(TAG, "setting scheduled job for: " + interval);
        }
    }
}
 
开发者ID:talCrafts,项目名称:Udhari,代码行数:24,代码来源:SettingsActivity.java

示例2: intervalMillisForRecurringAlarm

private static long intervalMillisForRecurringAlarm(String intervalPref) {
    int interval = Integer.parseInt(intervalPref);
    switch (interval) {
        case 0:
            return 0; // special case for cancel
        case 15:
            return AlarmManager.INTERVAL_FIFTEEN_MINUTES;
        case 30:
            return AlarmManager.INTERVAL_HALF_HOUR;
        case 1:
            return AlarmManager.INTERVAL_HOUR;
        case 12:
            return AlarmManager.INTERVAL_HALF_DAY;
        case 24:
            return AlarmManager.INTERVAL_DAY;
        default: // cases 2 and 6 (or any number of hours)
            return interval * 3600000;
    }
}
 
开发者ID:hichemcesar24,项目名称:Weather-Android,代码行数:19,代码来源:AlarmReceiver.java

示例3: formatSomeAgo

/**
 * 时间友好显示
 * 刚刚-%s分钟前-%s小时前-昨天-前天-%s天前
 */
public static String formatSomeAgo(long timeInMillis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timeInMillis);
    Calendar mCurrentDate = Calendar.getInstance();
    long crim = mCurrentDate.getTimeInMillis(); // current
    long trim = calendar.getTimeInMillis(); // target
    long diff = crim - trim;

    int year = mCurrentDate.get(Calendar.YEAR);
    int month = mCurrentDate.get(Calendar.MONTH);
    int day = mCurrentDate.get(Calendar.DATE);

    if (diff < 60 * 1000) {
        return "刚刚";
    }
    if (diff >= 60 * 1000 && diff < AlarmManager.INTERVAL_HOUR) {
        return String.format("%s分钟前", diff / 60 / 1000);
    }
    mCurrentDate.set(year, month, day, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return String.format("%s小时前", diff / AlarmManager.INTERVAL_HOUR);
    }
    mCurrentDate.set(year, month, day - 1, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "昨天";
    }
    mCurrentDate.set(year, month, day - 2, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "前天";
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30) {
        return String.format("%s天前", diff / AlarmManager.INTERVAL_DAY);
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30 * 12) {
        return String.format("%s月前", diff / (AlarmManager.INTERVAL_DAY * 30));
    }
    return String.format("%s年前", mCurrentDate.get(Calendar.YEAR) - calendar.get(Calendar.YEAR));
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:42,代码来源:DateUtil.java

示例4: parseInterval

/**
 * Parse repeat interval.
 */
private void parseInterval() {
    String every = options.optString("every").toLowerCase();

    if (every.isEmpty()) {
        interval = 0;
    } else
    if (every.equals("second")) {
        interval = 1000;
    } else
    if (every.equals("minute")) {
        interval = AlarmManager.INTERVAL_FIFTEEN_MINUTES / 15;
    } else
    if (every.equals("hour")) {
        interval = AlarmManager.INTERVAL_HOUR;
    } else
    if (every.equals("day")) {
        interval = AlarmManager.INTERVAL_DAY;
    } else
    if (every.equals("week")) {
        interval = AlarmManager.INTERVAL_DAY * 7;
    } else
    if (every.equals("month")) {
        interval = AlarmManager.INTERVAL_DAY * 31;
    } else
    if (every.equals("quarter")) {
        interval = AlarmManager.INTERVAL_HOUR * 2190;
    } else
    if (every.equals("year")) {
        interval = AlarmManager.INTERVAL_DAY * 365;
    } else {
        try {
            interval = Integer.parseInt(every) * 60000;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:40,代码来源:Options.java

示例5: persistUpdateIntervalIndex

public static void persistUpdateIntervalIndex(int intervalIndex, Context context) {
    long intervalValue;
    switch(intervalIndex) {
        case 0:
            intervalValue = 0;
            break;
        case 1:
            intervalValue = AlarmManager.INTERVAL_HOUR;
            break;
        case 2:
            intervalValue = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 3:
            intervalValue = AlarmManager.INTERVAL_DAY;
            break;
        default:
            intervalValue = OTAListener.DEFAULT_INTERVAL_VALUE;
            break;
    }

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    sharedPreferences.edit().putLong(UPDATE_INTERVAL, intervalValue).apply();
    if (intervalValue > 0) {
        WakefulIntentService.cancelAlarms(context);
        WakefulIntentService.scheduleAlarms(new OTAListener(), context, true);
        OTAUtils.toast(R.string.autoupdate_enabled, context);
    } else {
        WakefulIntentService.cancelAlarms(context);
        OTAUtils.toast(R.string.autoupdate_disabled, context);
    }
}
 
开发者ID:DroidThug,项目名称:VulcanOTA,代码行数:31,代码来源:AppConfig.java

示例6: getUpdateIntervalIndex

public static int getUpdateIntervalIndex(Context context) {
    long value = getUpdateIntervalTime(context);
    int index;
    if (value == 0) {
        index = 0;
    } else if (value == AlarmManager.INTERVAL_HOUR) {
        index = 1;
    } else if (value == AlarmManager.INTERVAL_HALF_DAY) {
        index = 2;
    } else {
        index = 3;
    }
    return index;
}
 
开发者ID:DroidThug,项目名称:VulcanOTA,代码行数:14,代码来源:AppConfig.java

示例7: formatSomeAgo

/**
 * format time friendly
 *
 * @param sdate YYYY-MM-DD HH:mm:ss
 * @return n分钟前, n小时前, 昨天, 前天, n天前, n个月前
 */
public static String formatSomeAgo(String sdate) {
    if (sdate == null) return "";
    Calendar calendar = parseCalendar(sdate);
    if (calendar == null) return sdate;

    Calendar mCurrentDate = Calendar.getInstance();
    long crim = mCurrentDate.getTimeInMillis(); // current
    long trim = calendar.getTimeInMillis(); // target
    long diff = crim - trim;

    int year = mCurrentDate.get(Calendar.YEAR);
    int month = mCurrentDate.get(Calendar.MONTH);
    int day = mCurrentDate.get(Calendar.DATE);

    if (diff < 60 * 1000) {
        return "刚刚";
    }
    if (diff >= 60 * 1000 && diff < AlarmManager.INTERVAL_HOUR) {
        return String.format("%s分钟前", diff / 60 / 1000);
    }
    mCurrentDate.set(year, month, day, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return String.format("%s小时前", diff / AlarmManager.INTERVAL_HOUR);
    }
    mCurrentDate.set(year, month, day - 1, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "昨天";
    }
    mCurrentDate.set(year, month, day - 2, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "前天";
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30) {
        return String.format("%s天前", diff / AlarmManager.INTERVAL_DAY);
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30 * 12) {
        return String.format("%s月前", diff / (AlarmManager.INTERVAL_DAY * 30));
    }
    return String.format("%s年前", mCurrentDate.get(Calendar.YEAR) - calendar.get(Calendar.YEAR));
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:46,代码来源:StringUtils.java


注:本文中的android.app.AlarmManager.INTERVAL_HOUR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。