/**
   * This will set the alarm instance to the SILENT_STATE and update the application notifications
   * and schedule any state changes that need to occur in the future.
   *
   * @param context application context
   * @param instance to set state to
   */
  public static void setSilentState(Context context, AlarmInstance instance) {
    LogUtils.v("Setting silent state to instance " + instance.mId);

    // Update alarm in db
    ContentResolver contentResolver = context.getContentResolver();
    instance.mAlarmState = AlarmInstance.SILENT_STATE;
    AlarmInstance.updateInstance(contentResolver, instance);

    // Setup instance notification and scheduling timers
    AlarmNotifications.clearNotification(context, instance);
    scheduleInstanceStateChange(
        context, instance.getLowNotificationTime(), instance, AlarmInstance.LOW_NOTIFICATION_STATE);
  }
  /**
   * This will set the alarm instance to the HIDE_NOTIFICATION_STATE and update the application
   * notifications and schedule any state changes that need to occur in the future.
   *
   * @param context application context
   * @param instance to set state to
   */
  public static void setHideNotificationState(Context context, AlarmInstance instance) {
    LogUtils.v("Setting hide notification state to instance " + instance.mId);

    // Update alarm state in db
    ContentResolver contentResolver = context.getContentResolver();
    instance.mAlarmState = AlarmInstance.HIDE_NOTIFICATION_STATE;
    AlarmInstance.updateInstance(contentResolver, instance);

    // Setup instance notification and scheduling timers
    AlarmNotifications.clearNotification(context, instance);
    scheduleInstanceStateChange(
        context,
        instance.getHighNotificationTime(),
        instance,
        AlarmInstance.HIGH_NOTIFICATION_STATE);
  }
  /**
   * This will set the alarm instance to the PREDISMISSED_STATE and schedule an instance state
   * change to DISMISSED_STATE at the regularly scheduled firing time.
   *
   * @param context
   * @param instance
   */
  public static void setPreDismissState(Context context, AlarmInstance instance) {
    LogUtils.v("Setting predismissed state to instance " + instance.mId);

    // Update alarm in db
    final ContentResolver contentResolver = context.getContentResolver();
    instance.mAlarmState = AlarmInstance.PREDISMISSED_STATE;
    AlarmInstance.updateInstance(contentResolver, instance);

    // Setup instance notification and scheduling timers
    AlarmNotifications.clearNotification(context, instance);
    scheduleInstanceStateChange(
        context, instance.getAlarmTime(), instance, AlarmInstance.DISMISSED_STATE);

    final Alarm alarm = Alarm.getAlarm(contentResolver, instance.mAlarmId);
    // if it's a one time alarm set the toggle to off
    if (alarm != null && !alarm.daysOfWeek.isRepeating()) {
      // Check parent if it needs to reschedule, disable or delete itself
      if (instance.mAlarmId != null) {
        updateParentAlarm(context, instance);
      }
    }
  }
 /**
  * This will not change the state of instance, but remove it's notifications and alarm timers.
  *
  * @param context application context
  * @param instance to unregister
  */
 public static void unregisterInstance(Context context, AlarmInstance instance) {
   // Stop alarm if this instance is firing it
   AlarmService.stopAlarm(context, instance);
   AlarmNotifications.clearNotification(context, instance);
   cancelScheduledInstanceStateChange(context, instance);
 }