/** * @param context * @param disablePoweroffAlarm */ public static void setNextAlert(final Context context, boolean disablePoweroffAlarm) { final Alarm alarm = calculateNextAlert(context); if (alarm != null) { enableAlert(context, alarm, alarm.time, disablePoweroffAlarm); } else { disableAlert(context); } Intent i = new Intent(NEXT_ALARM_TIME_SET); context.sendBroadcast(i); }
/** * 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) { // add by niezhong for NEWMS00134096 11-02-11 start // if (!enableSnoozeAlert(context)) { // Alarm alarm = calculateNextAlert(context); // if (alarm != null) { // enableAlert(context, alarm, alarm.time); // } else { // disableAlert(context); // } // } Alarm alarm = calculateNextAlert(context); long time = getSnoozeAlert(context); if ((alarm != null && alarm.time <= time) || (alarm != null && time == -1)) { enableAlert(context, alarm, alarm.time); } else if ((alarm != null && time < alarm.time) || (alarm == null && time != -1)) { enableSnoozeAlert(context); } else { disableAlert(context); } // add by niezhong for NEWMS00134096 11-02-11 end }
/** * 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(AlarmClock.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, 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; }