@Override
  public RemoteViews getViewAt(final int position) {
    if (position >= this.tasks.size()) {
      return null;
    }
    final Task task = this.tasks.get(position);
    // Get The Task
    final boolean isMinimalistic = WidgetHelper.isMinimalistic(this.mContext, this.widgetId);
    RemoteViews rv =
        new RemoteViews(
            this.mContext.getPackageName(),
            isMinimalistic ? R.layout.widget_row_minimal : R.layout.widget_row);

    // Set the Contents of the Row
    rv =
        WidgetHelper.configureItem(
            rv, task, this.mContext, this.list.getId(), isMinimalistic, this.widgetId);

    // Set the Click–Intent
    // We need to do so, because we can not start the Activity directly from
    // the Service

    final Bundle extras = new Bundle();
    extras.putInt(MainWidgetProvider.EXTRA_TASKID, (int) task.getId());
    final Intent fillInIntent = new Intent(MainWidgetProvider.CLICK_TASK);
    fillInIntent.putExtras(extras);
    rv.setOnClickFillInIntent(R.id.tasks_row, fillInIntent);
    return rv;
  }
 private void handleCommand(Intent intent) {
   Task task = TaskHelper.getTaskFromIntent(intent);
   if (task == null) return;
   if (intent.getAction() == TASK_DONE) {
     task.setDone(true);
     task.safeSave();
     Toast.makeText(
             this, getString(R.string.reminder_notification_done_confirm), Toast.LENGTH_LONG)
         .show();
   } else if (intent.getAction() == TASK_LATER && !task.hasRecurringReminder()) {
     GregorianCalendar reminder = new GregorianCalendar();
     int addMinutes = MirakelCommonPreferences.getAlarmLater();
     reminder.add(Calendar.MINUTE, addMinutes);
     task.setReminder(reminder);
     task.safeSave();
     Toast.makeText(
             this,
             getString(R.string.reminder_notification_later_confirm, addMinutes),
             Toast.LENGTH_LONG)
         .show();
   }
   ReminderAlarm.closeNotificationFor(this, task.getId());
   ReminderAlarm.updateAlarms(this);
   stopSelf();
 }
Example #3
0
 /**
  * Get all Tasks
  *
  * @param showDone
  * @return
  */
 @Override
 public List<Task> tasks(final boolean showDone) {
   return Task.getTasks(this, getSortBy(), showDone, getWhereQueryForTasks());
 }
Example #4
0
 /**
  * Get all Tasks
  *
  * @return
  */
 @Override
 public List<Task> tasks() {
   return Task.getTasks(this, getSortBy(), false, getWhereQueryForTasks());
 }
  public static RemoteViews configureItem(
      RemoteViews rv, Task task, Context context, int listId, boolean isMinimal, int widgetId) {
    Intent openIntent = new Intent(context, MainActivity.class);
    openIntent.setAction(MainActivity.SHOW_TASK);
    openIntent.putExtra(MainActivity.EXTRA_ID, task.getId());
    openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME)));
    PendingIntent pOpenIntent = PendingIntent.getActivity(context, 0, openIntent, 0);

    rv.setOnClickPendingIntent(R.id.tasks_row, pOpenIntent);
    rv.setOnClickPendingIntent(R.id.tasks_row_name, pOpenIntent);
    if (isMinimal) {
      if (task.getDue() != null) {
        rv.setTextViewText(R.id.tasks_row_due, DateTimeHelper.formatDate(context, task.getDue()));
      } else {
        rv.setViewVisibility(R.id.tasks_row_due, View.GONE);
      }
      rv.setInt(
          R.id.tasks_row_priority,
          "setBackgroundColor",
          TaskHelper.getPrioColor(task.getPriority(), context));
    }
    rv.setTextColor(R.id.tasks_row_name, WidgetHelper.getFontColor(context, widgetId));
    rv.setTextColor(R.id.tasks_row_due, WidgetHelper.getFontColor(context, widgetId));
    rv.setTextViewText(R.id.tasks_row_name, task.getName());
    if (task.isDone()) {
      rv.setTextColor(R.id.tasks_row_name, context.getResources().getColor(R.color.Grey));
    } else {
      /*
       * Is this meaningful? I mean the widget is transparent…
       * rv.setTextColor( R.id.tasks_row_name, context.getResources()
       * .getColor( preferences.getBoolean("darkWidget", false) ?
       * R.color.White : R.color.Black));
       */
    }
    if (!isMinimal) {

      rv.setTextViewText(R.id.tasks_row_priority, task.getPriority() + "");
      rv.setTextColor(R.id.tasks_row_priority, context.getResources().getColor(R.color.Black));
      GradientDrawable drawable =
          (GradientDrawable) context.getResources().getDrawable(R.drawable.priority_rectangle);
      drawable.setColor(TaskHelper.getPrioColor(task.getPriority(), context));
      Bitmap bitmap = Bitmap.createBitmap(40, 40, Config.ARGB_8888);
      Canvas canvas = new Canvas(bitmap);
      drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
      drawable.draw(canvas);
      rv.setImageViewBitmap(R.id.label_bg, bitmap);

      if (listId <= 0) {
        rv.setViewVisibility(R.id.tasks_row_list_name, View.VISIBLE);
        rv.setTextViewText(R.id.tasks_row_list_name, task.getList().getName());
      } else {
        rv.setViewVisibility(R.id.tasks_row_list_name, View.GONE);
      }
      if (task.getContent().length() != 0
          || task.getSubtaskCount() > 0
          || task.getFiles().size() > 0) {
        rv.setViewVisibility(R.id.tasks_row_has_content, View.VISIBLE);
      } else {
        rv.setViewVisibility(R.id.tasks_row_has_content, View.GONE);
      }

      if (task.getDue() != null) {
        rv.setViewVisibility(R.id.tasks_row_due, View.VISIBLE);

        rv.setTextViewText(R.id.tasks_row_due, DateTimeHelper.formatDate(context, task.getDue()));
        if (!isMinimal) {
          rv.setTextColor(
              R.id.tasks_row_due,
              context
                  .getResources()
                  .getColor(TaskHelper.getTaskDueColor(task.getDue(), task.isDone())));
        }
      } else {
        rv.setViewVisibility(R.id.tasks_row_due, View.GONE);
      }
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      rv.setTextColor(
          R.id.tasks_row_name,
          context
              .getResources()
              .getColor(WidgetHelper.isDark(context, widgetId) ? R.color.White : R.color.Black));
    }
    return rv;
  }
  public static void undoLast() {
    String last = MirakelCommonPreferences.getFromLog(0);
    if (last != null && !last.equals("")) {
      short type = Short.parseShort(last.charAt(0) + "");
      if (last.charAt(1) != '{') {
        try {
          long id = Long.parseLong(last.substring(1));
          switch (type) {
            case TASK:
              Task.get(id).destroy(true);
              break;
            case LIST:
              ListMirakel.getList((int) id).destroy(true);
              break;
            default:
              Log.wtf(TAG, "unkown Type");
              break;
          }
        } catch (Exception e) {
          Log.e(TAG, "cannot parse String");
        }

      } else {
        JsonObject json = new JsonParser().parse(last.substring(1)).getAsJsonObject();
        switch (type) {
          case TASK:
            Task t = Task.parse_json(json, AccountMirakel.getLocal(), false);
            if (Task.get(t.getId()) != null) {
              t.safeSave(false);
            } else {
              try {
                MirakelContentProvider.getWritableDatabase()
                    .insert(Task.TABLE, null, t.getContentValues());
              } catch (Exception e) {
                Log.e(TAG, "cannot restore Task");
              }
            }
            break;
          case LIST:
            ListMirakel l = ListMirakel.parseJson(json);
            if (ListMirakel.getList(l.getId()) != null) {
              l.save(false);
            } else {
              try {
                MirakelContentProvider.getWritableDatabase()
                    .insert(ListMirakel.TABLE, null, l.getContentValues());
              } catch (Exception e) {
                Log.e(TAG, "cannot restore List");
              }
            }
            break;
          default:
            Log.wtf(TAG, "unkown Type");
            break;
        }
      }
    }
    SharedPreferences.Editor editor = MirakelCommonPreferences.getEditor();
    for (int i = 0; i < MirakelCommonPreferences.getUndoNumber(); i++) {
      String old = MirakelCommonPreferences.getFromLog(i + 1);
      editor.putString(UNDO + i, old);
    }
    editor.putString(UNDO + 10, "");
    editor.commit();
  }
 public static void logCreate(Task newTask, Context ctx) {
   updateLog(TASK, newTask.getId() + "", ctx);
 }
 public static void updateLog(Task task, Context ctx) {
   if (task != null) {
     updateLog(TASK, task.toJson(), ctx);
   }
 }