Android Open Source - Tree-Task Main List Item






From Project

Back to project page Tree-Task.

License

The source code is released under:

Apache License

If you think the Android project Tree-Task listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ghsoft.treetaskapp;
//w  w  w  .jav  a 2 s.  c o m
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ghsoft.treetask.R;
import com.ghsoft.treetask.TaskHead;

public class MainListItem extends BaseAdapter {
  private LayoutInflater inflater;
  private TextView name, description, percent, subcount;
  private TreeTaskProgressBar completion;
  private ArrayList<TaskHead> tasks;
  private String type;
  private LinearLayout listItemBase;

  public MainListItem(Context context, ArrayList<TaskHead> tasks, String type) {
    this.inflater = LayoutInflater.from(context);
    this.tasks = tasks;
    this.type = type;
  }

  public String getType() {
    return type;
  }

  public TaskHead getItem(int position) throws IndexOutOfBoundsException {
    return tasks.get(position);
  }

  public long getItemId(int position) throws IndexOutOfBoundsException {
    if (position < getCount() && position >= 0) {
      return position;
    }
    return 0;
  }

  public int getViewTypeCount() {
    return 1;
  }

  @Override
  public int getCount() {
    return tasks.size();
  }

  public ArrayList<TaskHead> getData() {
    return tasks;
  }

  @SuppressLint("SimpleDateFormat")
  @SuppressWarnings("deprecation")
  public View getView(int position, View convertView, ViewGroup parent) {

    convertView = this.inflater.inflate(R.layout.main_list_item, null);

    name = (TextView) convertView.findViewById(R.id.name);
    description = (TextView) convertView.findViewById(R.id.description);
    completion = (TreeTaskProgressBar) convertView.findViewById(R.id.completion);
    percent = (TextView) convertView.findViewById(R.id.percent);
    subcount = (TextView) convertView.findViewById(R.id.subcount);
    listItemBase = (LinearLayout) convertView.findViewById(R.id.list_item_base);
    TextView timeStamp = (TextView) convertView.findViewById(R.id.timestamp);

    if (tasks.get(position).getTask().getTimeStamp() != null) {
      DateFormat df = new SimpleDateFormat("MM/dd/yyyy h:mm a");
      String timeString = df.format(tasks.get(position).getTask().getTimeStamp());
      timeStamp.setText(timeString);
    }

    name.setText(tasks.get(position).getTask().getName());
    description.setText(tasks.get(position).getTask().getDescription());
    completion.setMax(100);
    completion.setProgress(tasks.get(position).getTask().completion());
    percent.setText(tasks.get(position).getTask().completion() + "%");

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_pressed }, convertView.getResources().getDrawable(R.color.menu_select));
    states.addState(new int[] { android.R.attr.state_focused }, convertView.getResources().getDrawable(R.color.menu_select));
    if (tasks.get(position).getTask().getUseColor()) {
      states.addState(new int[] {}, new ColorDrawable(tasks.get(position).getTask().getColor()));
    } else {
      states.addState(new int[] {}, convertView.getResources().getDrawable(R.color.nselect));
    }
    listItemBase.setBackgroundDrawable(states);

    if (tasks.get(position).getTask().subTaskCount() > 1) {
      subcount.setText(String.valueOf(tasks.get(position).getTask().subTaskCount()) + " " + convertView.getResources().getString(R.string.subtasks));
    } else {
      subcount.setText(String.valueOf(tasks.get(position).getTask().subTaskCount()) + " " + convertView.getResources().getString(R.string.subtask));
    }

    return convertView;
  }

}




Java Source Code List

com.ghsoft.treetask.MetaData.java
com.ghsoft.treetask.TaskDummy.java
com.ghsoft.treetask.TaskHead.java
com.ghsoft.treetask.TaskLeaf.java
com.ghsoft.treetask.TaskManager.java
com.ghsoft.treetask.TaskNode.java
com.ghsoft.treetask.Task.java
com.ghsoft.treetask.TextTreeBuilder.java
com.ghsoft.treetaskapp.About.java
com.ghsoft.treetaskapp.EditTask.java
com.ghsoft.treetaskapp.ExportView.java
com.ghsoft.treetaskapp.HtmlTreeBuilder.java
com.ghsoft.treetaskapp.MainListItem.java
com.ghsoft.treetaskapp.MainViewFragment.java
com.ghsoft.treetaskapp.Main.java
com.ghsoft.treetaskapp.ModifyTaskActivity.java
com.ghsoft.treetaskapp.NewTask.java
com.ghsoft.treetaskapp.NewTreeTask.java
com.ghsoft.treetaskapp.NewTreeView.java
com.ghsoft.treetaskapp.Settings.java
com.ghsoft.treetaskapp.TaskViewListItem.java
com.ghsoft.treetaskapp.TaskView.java
com.ghsoft.treetaskapp.TreeTaskProgressBar.java
com.ghsoft.treetaskapp.TreeView.java