示例#1
0
  @Override
  public void onCreate() {
    DependencyInjectionService.getInstance().inject(this);

    database.openForReading();
    cursor = getCursor();
  }
示例#2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    preferences.applyThemeAndStatusBarColor();

    setContentView(R.layout.custom_filter_activity);
    ButterKnife.inject(this);

    setSupportActionBar(toolbar);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
      supportActionBar.setDisplayHomeAsUpEnabled(true);
      supportActionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
      supportActionBar.setTitle(R.string.FLA_new_filter);
    }

    listView = (ListView) findViewById(android.R.id.list);

    database.openForReading();

    List<CriterionInstance> startingCriteria = new ArrayList<>();
    startingCriteria.add(getStartingUniverse());
    adapter = new CustomFilterAdapter(this, dialogBuilder, startingCriteria);
    listView.setAdapter(adapter);
    updateList();

    setUpListeners();
  }
示例#3
0
  /**
   * Loads action item from the given intent
   *
   * @param intent
   */
  @SuppressWarnings("nls")
  protected void loadItem(Intent intent) {
    if (model != null) {
      // came from bundle
      isNewTask = (model.getValue(Task.TITLE).length() == 0);
      return;
    }

    long idParam = intent.getLongExtra(TOKEN_ID, -1L);

    database.openForReading();
    if (idParam > -1L) {
      model = taskService.fetchById(idParam, Task.PROPERTIES);
    }

    // not found by id or was never passed an id
    if (model == null) {
      String valuesAsString = intent.getStringExtra(TOKEN_VALUES);
      ContentValues values = null;
      try {
        if (valuesAsString != null)
          values = AndroidUtilities.contentValuesFromSerializedString(valuesAsString);
      } catch (Exception e) {
        // oops, can't serialize
      }
      model = TaskListActivity.createWithValues(values, null, taskService, metadataService);
    }

    if (model.getValue(Task.TITLE).length() == 0) {
      StatisticsService.reportEvent("create-task");
      isNewTask = true;

      // set deletion date until task gets a title
      model.setValue(Task.DELETION_DATE, DateUtilities.now());
    } else {
      StatisticsService.reportEvent("edit-task");
    }

    if (model == null) {
      exceptionService.reportError("task-edit-no-task", new NullPointerException("model"));
      finish();
      return;
    }

    // clear notification
    Notifications.cancelNotifications(model.getId());
  }
示例#4
0
    @SuppressWarnings("nls")
    public RemoteViews buildUpdate(Context context, int widgetId) {
      DependencyInjectionService.getInstance().inject(this);

      RemoteViews views = null;

      views = new RemoteViews(context.getPackageName(), R.layout.widget_initialized);

      int[] textIDs = TEXT_IDS;
      int[] separatorIDs = SEPARATOR_IDS;
      int numberOfTasks = 5;

      for (int i = 0; i < textIDs.length; i++) views.setTextViewText(textIDs[i], "");

      TodorooCursor<Task> cursor = null;
      Filter filter = null;
      try {
        filter = getFilter(widgetId);
        views.setTextViewText(R.id.widget_title, filter.title);

        SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(this);
        int flags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0);
        int sort = publicPrefs.getInt(SortHelper.PREF_SORT_SORT, 0);
        String query =
            SortHelper.adjustQueryForFlagsAndSort(filter.sqlQuery, flags, sort)
                    .replaceAll("LIMIT \\d+", "")
                + " LIMIT "
                + numberOfTasks;

        database.openForReading();
        cursor =
            taskService.fetchFiltered(
                query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE);
        Task task = new Task();
        for (int i = 0; i < cursor.getCount() && i < numberOfTasks; i++) {
          cursor.moveToPosition(i);
          task.readFromCursor(cursor);

          String textContent = "";
          int textColor = Color.WHITE;

          textContent = task.getValue(Task.TITLE);

          if (task.isCompleted())
            textColor = context.getResources().getColor(R.color.task_list_done);
          else if (task.hasDueDate() && task.getValue(Task.DUE_DATE) < DateUtilities.now())
            textColor = context.getResources().getColor(R.color.task_list_overdue);

          if (i > 0) views.setViewVisibility(separatorIDs[i - 1], View.VISIBLE);
          views.setTextViewText(textIDs[i], textContent);
          views.setTextColor(textIDs[i], textColor);
        }

        for (int i = cursor.getCount() - 1; i < separatorIDs.length; i++) {
          if (i >= 0) views.setViewVisibility(separatorIDs[i], View.INVISIBLE);
        }
      } catch (Exception e) {
        // can happen if database is not ready
        Log.e("WIDGET-UPDATE", "Error updating widget", e);
      } finally {
        if (cursor != null) cursor.close();
      }

      updateForScreenSize(views);

      Intent listIntent = new Intent(context, TaskListActivity.class);
      String customIntent =
          Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT + widgetId);
      if (customIntent != null) {
        listIntent.setComponent(ComponentName.unflattenFromString(customIntent));
        String serializedExtras =
            Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS + widgetId);
        Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
        listIntent.putExtras(extras);
      }
      listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET);
      listIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
      if (filter != null) {
        listIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
        listIntent.setAction("L" + widgetId + filter.sqlQuery);
      }
      PendingIntent pendingIntent =
          PendingIntent.getActivity(
              context, widgetId, listIntent, PendingIntent.FLAG_CANCEL_CURRENT);
      views.setOnClickPendingIntent(R.id.taskbody, pendingIntent);

      Intent editIntent = new Intent(context, TaskEditActivity.class);
      editIntent.setFlags(
          Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
      if (filter != null && filter.valuesForNewTasks != null) {
        String values = AndroidUtilities.contentValuesToSerializedString(filter.valuesForNewTasks);
        editIntent.putExtra(TaskEditActivity.TOKEN_VALUES, values);
        editIntent.setType(values);
      }
      pendingIntent = PendingIntent.getActivity(context, 0, editIntent, 0);
      views.setOnClickPendingIntent(R.id.widget_button, pendingIntent);

      return views;
    }