/** * Called at system startup, on time/timezone change, and whenever the user changes alarm * settings. Activates snooze if set, otherwise loads all alarms, activates next alert. */ public static void setNextAlert(final Context context) { if (!enableSnoozeAlert(context)) { Alarm alarm = calculateNextAlert(context); if (alarm != null) { enableAlert(context, alarm, alarm.time); } else { disableAlert(context); } } }
/** * If there is a snooze set, enable it in AlarmManager * * @return true if snooze is set */ private static boolean enableSnoozeAlert(final Context context) { SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, 0); int id = prefs.getInt(PREF_SNOOZE_ID, -1); if (id == -1) { return false; } long time = prefs.getLong(PREF_SNOOZE_TIME, -1); // Get the alarm from the db. final Alarm alarm = getAlarm(context.getContentResolver(), id); if (alarm == null) { return false; } // The time in the database is either 0 (repeating) or a specific time // for a non-repeating alarm. Update this value so the AlarmReceiver // has the right time to compare. alarm.time = time; enableAlert(context, alarm, time); return true; }