Exemple #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) {
    ContentValues values = createContentValues(alarm);
    ContentResolver resolver = context.getContentResolver();
    resolver.update(
        ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarm.id), values, null, null);

    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);
    }

    setNextAlert(context);

    return timeInMillis;
  }
Exemple #2
0
  /** Creates a new Alarm and fills in the given alarm's id. */
  public static long addAlarm(Context context, Alarm alarm) {
    ContentValues values = createContentValues(alarm);
    Uri uri = context.getContentResolver().insert(Alarm.Columns.CONTENT_URI, values);
    alarm.id = (int) ContentUris.parseId(uri);

    long timeInMillis = calculateAlarm(alarm);
    if (alarm.enabled) {
      clearSnoozeIfNeeded(context, timeInMillis);
    }
    setNextAlert(context);
    return timeInMillis;
  }
Exemple #3
0
  /** Creates a new Alarm and fills in the given alarm's id. */
  public static long addAlarm(Context context, Alarm alarm) {
    ContentValues values = createContentValues(context, alarm);
    Uri uri = context.getContentResolver().insert(Alarm.Columns.CONTENT_URI, values);
    alarm.id = (int) ContentUris.parseId(uri);

    // begin Click cancel, don't set the alarm clock fanmengke,2013-08-08
    short_clock_id = alarm.id;
    // end modified by fanmengke,2013-08-02
    long timeInMillis = calculateAlarm(alarm);
    if (alarm.enabled) {
      clearSnoozeIfNeeded(context, timeInMillis);
    }
    setNextAlert(context);
    return timeInMillis;
  }