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) {
    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;
  }
Exemple #2
0
  /** Creates a new Alarm and fills in the given alarm's id. */
  public static long addAlarm(Context context, Alarm alarm) {
    // int c1 = count(context);
    // ContentValues values = createContentValues(alarm);
    // Uri uri =
    // context.getContentResolver().insert(Alarm.Columns.CONTENT_URI,
    // values);
    // alarm.id = (int) ContentUris.parseId(uri);
    //
    // int c2 = count(context);
    // long timeInMillis = calculateAlarm(alarm);
    // if (alarm.enabled) {
    // clearSnoozeIfNeeded(context, timeInMillis);
    // }
    // // �޸�
    // // ״̬������
    // updateStatusBarIcon(c1, c2, context);
    // setNextAlert(context);
    // return timeInMillis;

    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
 public static void saveSnoozeAlert(final Context context, final int id, final long time) {
   SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, 0);
   if (id == -1) {
     clearSnoozePreference(context, prefs);
   } else {
     SharedPreferences.Editor ed = prefs.edit();
     ed.putInt(PREF_SNOOZE_ID, id);
     ed.putLong(PREF_SNOOZE_TIME, time);
     ed.commit();
   }
   // Set the next alert after updating the snooze.
   setNextAlert(context);
 }
Exemple #4
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);
  }
Exemple #5
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);
 }