當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。