/**
   * The IntentService calls this method from the default worker thread with the intent that started
   * the service. When this method returns, IntentService stops the service, as appropriate.
   */
  @Override
  protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras == null) {
      Log.e(Constants.TAG, "Extras bundle is null!");
      return;
    }

    if (intent.getAction() == null) {
      Log.e(Constants.TAG, "Intent must contain an action!");
      return;
    }

    if (extras.containsKey(EXTRA_MESSENGER)) {
      mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
    }

    String action = intent.getAction();

    setProgressCircleWithHandler(true);

    // execute action
    if (ACTION_CHANGE_COLOR.equals(action)) {
      // update calendar color if enabled
      if (new AccountHelper(this).isAccountActivated()) {
        CalendarSyncAdapterService.updateCalendarColor(this);
      }
    } else if (ACTION_MANUAL_COMPLETE_SYNC.equals(action)) {
      // perform blocking sync
      CalendarSyncAdapterService.performSync(this);
    }

    setProgressCircleWithHandler(false);
  }
  /**
   * The IntentService calls this method from the default worker thread with the intent that started
   * the service. When this method returns, IntentService stops the service, as appropriate.
   */
  @Override
  protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras == null) {
      Log.e(Constants.TAG, "Extras bundle is null!");
      return;
    }

    if (!(extras.containsKey(EXTRA_ACTION))) {
      Log.e(Constants.TAG, "Extra bundle must contain an action!");
      return;
    }

    if (extras.containsKey(EXTRA_MESSENGER)) {
      mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
    }
    Bundle data = extras.getBundle(EXTRA_DATA);

    int action = extras.getInt(EXTRA_ACTION);

    setProgressCircleWithHandler(true);

    // execute action from extra bundle
    switch (action) {
      case ACTION_CHANGE_COLOR:
        int newColor = data.getInt(CHANGE_COLOR_NEW_COLOR);

        // only if enabled
        if (new AccountHelper(this).isAccountActivated()) {
          // update calendar color
          CalendarSyncAdapterService.updateCalendarColor(this, newColor);
        }

        break;

      case ACTION_CHANGE_REMINDER:
        int newMinutes = data.getInt(CHANGE_REMINDER_NEW_MINUTES);
        int reminderNo = data.getInt(CHANGE_REMINDER_NO);

        // only if enabled
        if (new AccountHelper(this).isAccountActivated()) {
          // Update all reminders to new minutes
          CalendarSyncAdapterService.updateAllReminders(this, reminderNo, newMinutes);
        }

        break;

      case ACTION_MANUAL_SYNC:

        // Force synchronous sync
        CalendarSyncAdapterService.performSync(this);

        break;

      default:
        break;
    }

    setProgressCircleWithHandler(false);
  }