Android Open Source - Tree-Task Task View 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;
// ww  w .  j ava 2 s  .  co m
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
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.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ghsoft.treetask.R;
import com.ghsoft.treetask.Task;
import com.ghsoft.treetask.TaskNode;

public class TaskViewListItem extends BaseAdapter {
  private LayoutInflater inflater;
  private TextView name, description, percent, subcount, timeStamp;
  private TreeTaskProgressBar completion;
  private TaskNode task;
  private ImageView check;
  private LinearLayout listItemBase;

  public TaskViewListItem(Context context, TaskNode task, View header) {
    this.inflater = LayoutInflater.from(context);
    this.task = task;
  }

  public Task getItem(int position) throws IndexOutOfBoundsException {
    return task.getChild(position);
  }

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

  public int getViewTypeCount() {
    return task.numChildren();
  }

  @Override
  public int getCount() {
    return task.numChildren();
  }
  
  public void move(int from, int to) {
    task.moveChild(from, to);
  }

  public View getView(final int position, View convertView, ViewGroup parent) {

    final Task t = task.getChild(position);

    if (t.hasChildren()) {

      convertView = this.inflater.inflate(R.layout.task_view_list_item, null);
      layoutHasChildren(convertView, t);

    } else {

      convertView = this.inflater.inflate(R.layout.task_view_list_item_no_children, null);
      layoutNoChildren(convertView, t);

    }

    return convertView;
  }

  @SuppressWarnings("deprecation")
  @SuppressLint("SimpleDateFormat")
  private void layoutHasChildren(View convertView, Task t) {
    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.subcountmainlistitem);
      timeStamp = (TextView) convertView.findViewById(R.id.timestamp);
    
      listItemBase = (LinearLayout) convertView.findViewById(R.id.tv_list_item_base);
    
    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 (t.getUseColor()) {
      states.addState(new int[] {}, new ColorDrawable(t.getColor()));
    } else {
      states.addState(new int[] {}, convertView.getResources().getDrawable(R.color.nselect));
    }
    listItemBase.setBackgroundDrawable(states);
    
    if (task.getTimeStamp() != null) {
      DateFormat df = new SimpleDateFormat("MM/dd/yyyy h:mm a");
      String timeString = df.format(t.getTimeStamp());
      timeStamp.setText(timeString);
    }
    
    name.setText(t.getName());
    description.setText(t.getDescription());

    completion.setMax(100);
    completion.setProgress(t.completion());
    percent.setText(t.completion() + "%");
    
    

    if (t.subTaskCount() > 1) {
      subcount.setText(t.subTaskCount() + " " + convertView.getResources().getString(R.string.subtasks));
    } else {
      subcount.setText(t.subTaskCount() + " " + convertView.getResources().getString(R.string.subtask));
    }
    

    if (t.completion() == 100) {
      name.setTextColor(Color.parseColor("#505050"));
      description.setTextColor(Color.parseColor("#505050"));
      timeStamp.setTextColor(Color.parseColor("#505050"));
    }

  }

  @SuppressWarnings("deprecation")
  @SuppressLint("SimpleDateFormat")
  private void layoutNoChildren(View convertView, Task t) {
    name = (TextView) convertView.findViewById(R.id.name);
    description = (TextView) convertView.findViewById(R.id.description);
    check = (ImageView) convertView.findViewById(R.id.check);
    timeStamp = (TextView) convertView.findViewById(R.id.timestamp);
    
    listItemBase = (LinearLayout) convertView.findViewById(R.id.tv_list_item_base);
    
    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 (t.getUseColor()) {
      states.addState(new int[] {}, new ColorDrawable(t.getColor()));
    } else {
      states.addState(new int[] {}, convertView.getResources().getDrawable(R.color.nselect));
    }
    listItemBase.setBackgroundDrawable(states);
    
    if (task.getTimeStamp() != null) {
      DateFormat df = new SimpleDateFormat("MM/dd/yyyy h:mm a");
      String timeString = df.format(t.getTimeStamp());
      timeStamp.setText(timeString);
    }

    name.setText(t.getName());
    description.setText(t.getDescription());

    if (t.completion() == 100) {
      check.setVisibility(View.VISIBLE);
      name.setTextColor(Color.parseColor("#505050"));
      description.setTextColor(Color.parseColor("#505050"));
      timeStamp.setTextColor(Color.parseColor("#505050"));
    }

  }

}




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