Beispiel #1
0
 public static Alarm calculateNextAlert(final Context context) {
   Alarm alarm = null;
   long minTime = Long.MAX_VALUE;
   long now = System.currentTimeMillis();
   Cursor cursor = getFilteredAlarmsCursor(context.getContentResolver());
   if (cursor != null) {
     if (cursor.moveToFirst()) {
       do {
         Alarm a = new Alarm(cursor);
         // A time of 0 indicates this is a repeating alarm, so
         // calculate the time to get the next alert.
         if (a.time == 0) {
           a.time = calculateAlarm(a);
         } else if (a.time < now) {
           // Expired alarm, disable it and move along.
           enableAlarmInternal(context, a, false);
           continue;
         }
         if (a.time < minTime) {
           minTime = a.time;
           alarm = a;
         }
       } while (cursor.moveToNext());
     }
     cursor.close();
   }
   return alarm;
 }
Beispiel #2
0
  /** Disables non-repeating alarms that have passed. Called at boot. */
  public static void disableExpiredAlarms(final Context context) {
    Cursor cur = getFilteredAlarmsCursor(context.getContentResolver());
    long now = System.currentTimeMillis();
    boolean status = false;
    if (cur.moveToFirst()) {
      do {
        Alarm alarm = new Alarm(cur);
        // A time of 0 means this alarm repeats. If the time is
        // non-zero, check if the time is before now.
        if (alarm.time != 0 && alarm.time < now) {
          enableAlarmInternal(context, alarm, false);
        } else {
          status = true;
        }
      } while (cur.moveToNext());
    }
    cur.close();

    if (status) setStatusBarIcon(context, true);
  }
Beispiel #3
0
 private static void enableAlarmInternal(final Context context, final int id, boolean enabled) {
   enableAlarmInternal(context, getAlarm(context.getContentResolver(), id), enabled);
 }
Beispiel #4
0
 /**
  * A convenience method to enable or disable an alarm.
  *
  * @param id corresponds to the _id column
  * @param enabled corresponds to the ENABLED column
  */
 public static void enableAlarm(final Context context, final int id, boolean enabled) {
   enableAlarmInternal(context, id, enabled);
   setNextAlert(context);
 }