@Override
 public void onReceive(Context context, Intent intent) {
   super.onReceive(context, intent);
   if (CLOCK_WIDGET_UPDATE.equals(intent.getAction())) {
     Log.d("TIME", "TIME");
     Log.d("CONTEXT: ", context + "");
     sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
     ComponentName thisAppWidget =
         new ComponentName(context.getPackageName(), getClass().getName());
     AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
     int ids[] = appWidgetManager.getAppWidgetIds(thisAppWidget);
     for (int appWidgetId : ids) {
       updateAppWidget(context, appWidgetManager, appWidgetId);
     }
   } else if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(intent.getAction())) {
     this.onEnabled(context);
   } else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(intent.getAction())) {
     this.onDisabled(context);
   }
 }
  @Override
  public void onReceive(Context context, Intent intent) {
    final String actionText = intent.getAction();
    manager = AppWidgetManager.getInstance(context);

    Log.d(Constants.LogTag, "HomeScreenWidgetProvider::onReceive(" + actionText + ")");

    final ComponentName componentName = new ComponentName(context, HomeScreenWidgetProvider.class);

    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(actionText)) {
      final Bundle bundle = intent.getExtras();
      if (bundle == null) {
        Log.d(Constants.LogTag, "onReceive(ACTION_APPWIDGET_ENABLED).....No Extras !!!");
        return;
      }

      int wid = bundle.getInt(AppWidgetManager.EXTRA_APPWIDGET_IDS, -1);
      Log.d(
          Constants.LogTag,
          String.format("onReceive(ACTION_APPWIDGET_ENABLED, 'EXTRA_APPWIDGET_IDS').....%d", wid));

      wid = bundle.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
      Log.d(
          Constants.LogTag,
          String.format("onReceive(ACTION_APPWIDGET_ENABLED, EXTRA_APPWIDGET_ID).....%d", wid));

    } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(actionText)) {
      // final int[] appWidgetIds =
      // intent.getExtras().getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
      final int[] appWidgetIds =
          AppWidgetManager.getInstance(context).getAppWidgetIds(componentName);
      for (int widgetId : appWidgetIds) {
        refreshWidget(context, widgetId);
      }
    } else if (ACTION_REFRESH.equals(actionText)) {
      final int[] appWidgetIds =
          AppWidgetManager.getInstance(context).getAppWidgetIds(componentName);
      final Bundle bundle = intent.getExtras();

      int taskId = bundle.getInt(TASK_ID);
      final String taskName = bundle.getString(TASK_NAME);
      boolean taskDone = bundle.getBoolean(TASK_MARKED);

      for (int appWidgetId : appWidgetIds) {
        updateSharedPrefs(context, appWidgetId, taskId, taskName, taskDone);
      }
    } else if (ACTION_DATE_CHANGED.equals(actionText) || ACTION_TIME_SET.equals(actionText)) {
      Log.d(
          Constants.LogTag,
          String.format("HomeScreenWidgetProvider.onReceive(%s) - Date Changed!", actionText));

      final int[] appWidgetIds =
          AppWidgetManager.getInstance(context).getAppWidgetIds(componentName);
      initDBManager(context);

      try {
        TaskSnippet taskInfo;
        Task task;
        boolean isDone;
        final Date today = new Date();

        for (int widgetId : appWidgetIds) {
          taskInfo = getFromSharedPrefs(context, widgetId);
          task = dbManager.getTaskDetails(taskInfo.taskId);
          isDone = task.isAccomplishedDate(today);
          Log.w(
              Constants.LogTag,
              String.format(
                  "!!! TimeChanged !!! %s. %s", task.getText(), isDone ? "TRUE" : "FALSE"));

          updateSharedPrefs(context, widgetId, isDone);
          refreshWidget(context, widgetId);
        }
      } finally {
        dbManager.close();
      }
    } else if (ACTION_SELECT.equals(actionText) || ACTION_DESELECT.equals(actionText)) {

      final int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_IDS);
      final Bundle bundle = intent.getExtras();
      final int taskId = bundle.getInt(TASK_ID);
      final boolean marked = ACTION_SELECT.equals(actionText);

      initDBManager(context);
      dbManager.updateTaskCalendar(taskId, new Date(), marked);
      updateSharedPrefs(context, appWidgetId, marked);
      refreshWidget(context, appWidgetId);
      dbManager.close();
    } else if (ACTION_UPDATE_DATE.equals(actionText)) {
      final int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_IDS);
      // Clear done flag for the next day
      updateSharedPrefs(context, appWidgetId, false);
      refreshWidget(context, appWidgetId);

      /* final int[] widgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(componentName);
         for (int wid : widgetIds)
         {
      updateSharedPrefs(context, wid, false);
      refreshWidget(context, wid);
         }*/
    } else if (ACTION_DELETE.equals(actionText)) {
      SharedPreferences config = context.getSharedPreferences(WidgetConfiguration.PREFS_NAME, 0);
      int[] appWidgetIds =
          AppWidgetManager.getInstance(context)
              .getAppWidgetIds(new ComponentName(context, HomeScreenWidgetProvider.class));
      Bundle bundle = intent.getExtras();
      int taskId = bundle.getInt(TASK_ID);
      for (int widgetId : appWidgetIds) {
        int widgetTaskId =
            config.getInt(String.format(WidgetConfiguration.TASK_ID_SHR, widgetId), -1);
        if (widgetTaskId == taskId) {
          RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.home_widget);
          view.setTextViewText(R.id.taskName, "Deleted!!!");
          view.setViewVisibility(R.id.currentDate, View.GONE);
          view.setViewVisibility(R.id.currentDateSelected, View.GONE);
          manager.updateAppWidget(widgetId, view);
        }
      }
    } else {
      super.onReceive(context, intent);
    }
  }