Esempio n. 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;
  }
Esempio n. 2
0
  /** Removes an existing Alarm. If this alarm is snoozing, disables snooze. Sets next alert. */
  public static void deleteAlarm(Context context, int alarmId) {
    if (alarmId == -1) return;

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

    Uri uri = ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId);
    contentResolver.delete(uri, "", null);

    setNextAlert(context);
  }
Esempio n. 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(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;
  }
Esempio n. 4
0
 static void saveSnoozeAlert(final Context context, final int id, final long time) {
   SharedPreferences prefs = context.getSharedPreferences(AlarmClock.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.apply();
   }
   // Set the next alert after updating the snooze.
   setNextAlert(context);
 }
Esempio n. 5
0
 public static void deleteAllAlarm(Context context) {
   ContentResolver contentResolver = context.getContentResolver();
   Cursor cursor =
       contentResolver.query(Alarm.Columns.CONTENT_URI, new String[] {}, null, null, null);
   if (cursor != null && cursor.getCount() > 0) {
     while (cursor.moveToNext()) {
       int alarm_id = cursor.getInt(0);
       disableSnoozeAlert(context, alarm_id);
     }
   }
   contentResolver.delete(Alarm.Columns.CONTENT_URI, "", null);
   setNextAlert(context);
 }
Esempio n. 6
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;
  }
Esempio n. 7
0
 static void saveSnoozeAlert(final Context context, final int id, final long time) {
   SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, 0);
   if (id == INVALID_ALARM_ID) {
     if (!android.util.KpFeatures.DESKCLOCK_SNZOOZE) {
       clearAllSnoozePreferences(context, prefs);
     }
   } else {
     final Set<String> snoozedIds = prefs.getStringSet(PREF_SNOOZE_IDS, new HashSet<String>());
     snoozedIds.add(Integer.toString(id));
     final SharedPreferences.Editor ed = prefs.edit();
     ed.putStringSet(PREF_SNOOZE_IDS, snoozedIds);
     ed.putLong(getAlarmPrefSnoozeTimeKey(id), time);
     ed.apply();
   }
   // Set the next alert after updating the snooze.
   setNextAlert(context);
 }
Esempio n. 8
0
  /** Removes an existing Alarm. If this alarm is snoozing, disables snooze. Sets next alert. */
  public static void deleteAlarm(Context context, int alarmId) {
    if (alarmId == INVALID_ALARM_ID) return;
    if (AlarmKlaxon.mCurrentPlayingAlarmId != -1 && alarmId == AlarmKlaxon.mCurrentPlayingAlarmId) {
      final Alarm a = getAlarm(context.getContentResolver(), alarmId);
      Intent disableSnoozeNotification = new Intent(DISABLE_OR_ENABLE_SNOOZE_NOTIFICATION);
      disableSnoozeNotification.putExtra(Alarms.ALARM_INTENT_EXTRA, a);
      disableSnoozeNotification.putExtra("enable", false);
      disableSnoozeNotification.putExtra("alarmID", alarmId);
      disableSnoozeNotification.putExtra("alarm", a);
      context.sendBroadcast(disableSnoozeNotification);
    }

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

    Uri uri = ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId);
    contentResolver.delete(uri, "", null);

    setNextAlert(context);
  }
Esempio n. 9
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);
 }