Android Open Source - droid-counter Counter Model






From Project

Back to project page droid-counter.

License

The source code is released under:

MIT License

If you think the Android project droid-counter 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 cs.aaclark.droidcounter;
/*ww  w .j  a  v a  2s .  c o m*/
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;

public class CounterModel implements Serializable {
  
  private String name;
  private int count;
  private Date modified;
  
  //Constructor
  public CounterModel(String newName, int init){
    this.name = newName;
    this.count = init;
    this.modified = new Date();
  }
  
  //Incrementor
  public void increment(){
    this.count++;
    this.modified = new Date();
  }
  
  // Always WriteOut and ReadIn in same order
  public void writeObject(java.io.ObjectOutputStream out) throws IOException{
    out.writeUTF(name);    
    out.writeInt(count);
    out.writeLong(modified.getTime());
    
  }
  
  public void readObject(java.io.ObjectInputStream in) throws IOException{
    name = in.readUTF();
    count = in.readInt();
    modified = new Date(in.readLong());  
  }
  
  //implement/override toString
  public String toString(){
    return "["+this.count+"] - "+this.name;
  }
  
  //easier to just get the Name for ListView
  public String getName(){
    return name;
  }

}




Java Source Code List

cs.aaclark.droidcounter.CounterModel.java
cs.aaclark.droidcounter.DroidCounter.java
cs.aaclark.droidcounter.EditCounterActivity.java
cs.aaclark.droidcounter.ReadWriteHandler.java