Пример #1
0
  /**
   * A convenience method to set an alarm in the Alarms content provider.
   *
   * @return Time when the alarm will fire.
   */
  public static long setAlarm(Context context, Alarm alarm) {
    int c1 = count(context);
    ContentValues values = createContentValues(alarm);
    ContentResolver resolver = context.getContentResolver();
    resolver.update(
        ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarm.id), values, null, null);

    int c2 = count(context);
    long timeInMillis = calculateAlarm(alarm);

    if (alarm.enabled) {
      // Disable the snooze if we just changed the snoozed alarm. This
      // only does work if the snoozed alarm is the same as the given
      // alarm.
      // TODO: disableSnoozeAlert should have a better name.
      disableSnoozeAlert(context, alarm.id);

      // Disable the snooze if this alarm fires before the snoozed alarm.
      // This works on every alarm since the user most likely intends to
      // have the modified alarm fire next.
      clearSnoozeIfNeeded(context, timeInMillis);
    }

    updateStatusBarIcon(c1, c2, context);
    setNextAlert(context);

    return timeInMillis;
  }
Пример #2
0
  private static void enableAlarmInternal(
      final Context context, final Alarm alarm, boolean enabled) {
    if (alarm == null) {
      return;
    }
    int c1 = count(context);
    ContentResolver resolver = context.getContentResolver();

    ContentValues values = new ContentValues(2);
    values.put(Alarm.Columns.ENABLED, enabled ? 1 : 0);

    // If we are enabling the alarm, calculate alarm time since the time
    // value in Alarm may be old.
    if (enabled) {
      long time = 0;
      if (!alarm.daysOfWeek.isRepeatSet()) {
        time = calculateAlarm(alarm);
      }
      values.put(Alarm.Columns.ALARM_TIME, time);
    } else {
      // Clear the snooze if the id matches.
      disableSnoozeAlert(context, alarm.id);
    }

    resolver.update(
        ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarm.id), values, null, null);
    int c2 = count(context);
    // �޸�״̬��
    updateStatusBarIcon(c1, c2, context);
  }
Пример #3
0
  /** Removes an existing Alarm. If this alarm is snoozing, disables snooze. Sets next alert. */
  public static void deleteAlarm(Context context, int alarmId) {

    ContentResolver contentResolver = context.getContentResolver();
    /* If alarm is snoozing, lose it */
    disableSnoozeAlert(context, alarmId);

    // �޸�----------------
    int c1 = count(context);
    setNextAlert(context);
    // ----------------------------------

    Uri uri = ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId);
    contentResolver.delete(uri, "", null);
    int c2 = count(context);
    // ״̬������
    updateStatusBarIcon(c1, c2, context);
  }