Example #1
0
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) menuInfo;
    Task task = ((ViewHolder) adapterInfo.targetView.getTag()).task;
    int id = (int) task.getId();
    menu.setHeaderTitle(task.getTitle());

    if (task.isDeleted()) {
      menu.add(id, CONTEXT_MENU_UNDELETE_TASK_ID, Menu.NONE, R.string.TAd_contextUndeleteTask);
      menu.add(id, CONTEXT_MENU_PURGE_TASK_ID, Menu.NONE, R.string.TAd_contextPurgeTask);
    } else {
      menu.add(id, CONTEXT_MENU_EDIT_TASK_ID, Menu.NONE, R.string.TAd_contextEditTask);
      menu.add(id, CONTEXT_MENU_COPY_TASK_ID, Menu.NONE, R.string.TAd_contextCopyTask);
      menu.add(id, CONTEXT_MENU_DELETE_TASK_ID, Menu.NONE, R.string.TAd_contextDeleteTask);
    }
  }
Example #2
0
  public void delete(Task item) {
    if (!item.isSaved()) {
      return;
    }

    if (item.containsValue(Task.TITLE) && item.getTitle().length() == 0) {
      taskDao.delete(item.getId());
      item.setId(Task.NO_ID);
    } else {
      long id = item.getId();
      item.clear();
      item.setId(id);
      gcalHelper.deleteTaskEvent(item);
      item.setDeletionDate(DateUtilities.now());
      taskService.save(item);
    }
  }
  public RemoteViews buildUpdate(int position) {
    try {
      Task task = getTask(position);

      String textContent;
      Resources r = context.getResources();
      int textColor =
          r.getColor(dark ? R.color.widget_text_color_dark : R.color.widget_text_color_light);

      textContent = task.getTitle();

      RemoteViews row = new RemoteViews(Constants.PACKAGE, R.layout.widget_row);

      if (task.isCompleted()) {
        textColor = r.getColor(R.color.task_list_done);
        row.setInt(R.id.text, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
      } else {
        row.setInt(R.id.text, "setPaintFlags", Paint.ANTI_ALIAS_FLAG);
        if (task.hasDueDate() && task.isOverdue()) {
          textColor = r.getColor(R.color.task_list_overdue);
        }
      }

      row.setTextViewText(R.id.text, textContent);
      row.setTextColor(R.id.text, textColor);
      row.setImageViewResource(R.id.completeBox, getCheckbox(task));

      Intent editIntent = new Intent();
      editIntent.setAction(TasksWidget.EDIT_TASK);
      editIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId());
      editIntent.putExtra(TaskListActivity.OPEN_TASK, task.getId());
      row.setOnClickFillInIntent(R.id.text, editIntent);

      Intent completeIntent = new Intent();
      completeIntent.setAction(TasksWidget.COMPLETE_TASK);
      completeIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId());
      row.setOnClickFillInIntent(R.id.completeBox, completeIntent);

      return row;
    } catch (Exception e) {
      // can happen if database is not ready
      Log.e("WIDGET-UPDATE", "Error updating widget", e);
    }

    return null;
  }
Example #4
0
  public Uri createTaskEvent(
      Task task, ContentResolver cr, ContentValues values, boolean deleteEventIfExists) {
    String eventuri = getTaskEventUri(task);

    if (!TextUtils.isEmpty(eventuri) && deleteEventIfExists) {
      deleteTaskEvent(task);
    }

    try {
      Uri uri = getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
      values.put("title", task.getTitle());
      values.put("description", task.getNotes());
      values.put("hasAlarm", 0);
      if (preIceCreamSandwich()) {
        values.put("transparency", 0);
        values.put("visibility", 0);
      }
      boolean valuesContainCalendarId =
          (values.containsKey(CALENDAR_ID_COLUMN)
              && !TextUtils.isEmpty(values.getAsString(CALENDAR_ID_COLUMN)));
      if (!valuesContainCalendarId) {
        String calendarId = preferences.getDefaultCalendar();
        if (!TextUtils.isEmpty(calendarId)) {
          values.put("calendar_id", calendarId);
        }
      }

      createStartAndEndDate(task, values);

      Uri eventUri = cr.insert(uri, values);
      cr.notifyChange(eventUri, null);

      return eventUri;

    } catch (Exception e) {
      // won't work on emulator
      log.error(e.getMessage(), e);
    }

    return null;
  }