Android Open Source - Tree-Task Task Node






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.treetask;
// w w w. j av  a  2 s  .c o  m
import java.io.Serializable;
import java.util.ArrayList;

public class TaskNode extends Task implements Serializable {

  private static final long serialVersionUID = 1L;
  private ArrayList<Task> children;

  public TaskNode(Task parent) {
    super(parent);
    this.children = new ArrayList<Task>();

  }

  public TaskNode(TaskHead head) {
    super(head);
    this.children = new ArrayList<Task>();
    head.setTreeHead(this);

  }

  public static TaskNode fromLeaf(TaskLeaf from) {
    TaskNode tn = new TaskNode(from.getParent());
    tn.setName(from.getName());
    tn.setDescription(from.getDescription());
    tn.setColor(from.getColor());
    tn.setTimeStamp(from.getTimeStamp());
    tn.setWeight(from.getWeight());
    tn.setDeadline(from.getDeadline());
    return tn;
  }

  @Override
  public int subTaskCount() {
    int out = numChildren();

    for (Task child : children) {
      out += child.subTaskCount();
    }

    return out;
  }

  @Override
  public int completion() {

    int count = 0;
    int sum = 0;

    for (int i = 0; i < this.numChildren(); i++) {
      sum += getChild(i).completion() * getChild(i).getWeight();
      count += getChild(i).getWeight();
    }

    return Math.round(sum / count);

  }

  public int numChildren() {
    return children.size();
  }

  public boolean hasCildren() {
    return numChildren() > 0;
  }

  public Task getChild(int i) {

    if (children.get(i) instanceof TaskNode) {
      TaskNode tn = (TaskNode) children.get(i);
      if (tn.numChildren() < 1) {
        TaskLeaf tl = TaskLeaf.fromNode(tn);
        children.set(i, tl);
      }
    }

    return children.get(i);
  }

  public ArrayList<Task> getChildren() {
    return children;
  }

  public void setChild(int i, Task t) {
    children.set(i, t);
  }

  public void deleteChild(int i) {
    children.remove(i);
  }

  public void deleteChild(Task t) {
    children.remove(t);
  }

  public void addSubTask(Task t) {
    children.add(t);
  }

  public void replaceChild(int pos, Task t) {
    children.set(pos, t);
  }
  
  public void moveChild(int from, int to) {
    Task t = children.get(from);
    children.remove(from);
    children.add(to, t);
  }

}




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