Search in sources :

Example 6 with AlarmInstance

use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.

the class AlarmStateManager method deleteAllInstances.

/**
 * This will delete and unregister all instances associated with alarmId, without affect
 * the alarm itself. This should be used whenever modifying or deleting an alarm.
 *
 * @param context application context
 * @param alarmId to find instances to delete.
 */
public static void deleteAllInstances(Context context, long alarmId) {
    sSnoozeCount = 0;
    ContentResolver cr = context.getContentResolver();
    List<AlarmInstance> instances = AlarmInstance.getInstancesByAlarmId(cr, alarmId);
    for (AlarmInstance instance : instances) {
        unregisterInstance(context, instance);
        AlarmInstance.deleteInstance(context.getContentResolver(), instance.mId);
    }
    updateNextAlarm(context);
}
Also used : AlarmInstance(org.omnirom.deskclock.provider.AlarmInstance) ContentResolver(android.content.ContentResolver)

Example 7 with AlarmInstance

use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.

the class AlarmStateManager method updateParentAlarm.

/**
 * Used by dismissed and missed states, to update parent alarm. This will either
 * disable, delete or reschedule parent alarm.
 *
 * @param context application context
 * @param instance to update parent for
 */
private static void updateParentAlarm(Context context, AlarmInstance instance) {
    ContentResolver cr = context.getContentResolver();
    Alarm alarm = Alarm.getAlarm(cr, instance.mAlarmId);
    if (alarm == null) {
        LogUtils.e("Parent has been deleted with instance: " + instance.toString());
        return;
    }
    if (!alarm.daysOfWeek.isRepeating()) {
        if (alarm.deleteAfterUse) {
            LogUtils.i("Deleting parent alarm: " + alarm.id);
            Alarm.deleteAlarm(cr, alarm.id);
        } else {
            LogUtils.i("Disabling parent alarm: " + alarm.id);
            alarm.enabled = false;
            Alarm.updateAlarm(cr, alarm);
        }
    } else {
        // This is a optimization for really old alarm instances. This prevent us
        // from scheduling and dismissing alarms up to current time.
        Calendar currentTime = Calendar.getInstance();
        Calendar alarmTime = instance.getAlarmTime();
        if (currentTime.after(alarmTime)) {
            alarmTime = currentTime;
        }
        AlarmInstance nextRepeatedInstance = alarm.createInstanceAfter(alarmTime);
        LogUtils.i("Creating new instance for repeating alarm " + alarm.id + " at " + sdf.format(nextRepeatedInstance.getAlarmTime().getTime()));
        AlarmInstance.addInstance(cr, nextRepeatedInstance);
        registerInstance(context, nextRepeatedInstance, true);
    }
}
Also used : AlarmInstance(org.omnirom.deskclock.provider.AlarmInstance) Alarm(org.omnirom.deskclock.provider.Alarm) Calendar(java.util.Calendar) ContentResolver(android.content.ContentResolver)

Example 8 with AlarmInstance

use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.

the class AlarmStateManager method updateNextAlarm.

/**
 * Find and notify system what the next alarm that will fire. This is used
 * to update text in the system and widgets.
 *
 * @param context application context
 */
public static void updateNextAlarm(Context context) {
    AlarmInstance nextAlarm = null;
    ContentResolver cr = context.getContentResolver();
    String activeAlarmQuery = AlarmInstance.ALARM_STATE + "<" + AlarmInstance.PRE_ALARM_STATE;
    for (AlarmInstance instance : AlarmInstance.getInstances(cr, activeAlarmQuery)) {
        if (nextAlarm == null || instance.getAlarmTime().before(nextAlarm.getAlarmTime())) {
            nextAlarm = instance;
        }
    }
    AlarmNotifications.registerNextAlarmWithAlarmManager(context, nextAlarm);
}
Also used : AlarmInstance(org.omnirom.deskclock.provider.AlarmInstance) ContentResolver(android.content.ContentResolver)

Example 9 with AlarmInstance

use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.

the class AlarmStateManager method fixAlarmInstances.

/**
 * Fix and update all alarm instance when a time change event occurs.
 *
 * @param context application context
 */
public static void fixAlarmInstances(Context context) {
    // Register all instances after major time changes or when phone restarts
    // TODO: Refactor this code to not use the overloaded registerInstance method.
    ContentResolver contentResolver = context.getContentResolver();
    for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
        AlarmStateManager.registerInstance(context, instance, false);
    }
    AlarmStateManager.updateNextAlarm(context);
}
Also used : AlarmInstance(org.omnirom.deskclock.provider.AlarmInstance) ContentResolver(android.content.ContentResolver)

Aggregations

AlarmInstance (org.omnirom.deskclock.provider.AlarmInstance)9 ContentResolver (android.content.ContentResolver)8 Context (android.content.Context)2 Uri (android.net.Uri)2 AsyncTask (android.os.AsyncTask)2 Alarm (org.omnirom.deskclock.provider.Alarm)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Calendar (java.util.Calendar)1 DeskClock (org.omnirom.deskclock.DeskClock)1