Android Open Source - Android-Counter-App Counter Model






From Project

Back to project page Android-Counter-App.

License

The source code is released under:

Apache License

If you think the Android project Android-Counter-App 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

/*
  Counter Model/*  w  w  w  .  j  a v a2  s  . c om*/
  
  This class defines the main data structure of the program.
  The counter model contains information pertinent to each 
  counter used in the application. Such information includes: 
  the name of the counter, the current number of counts, and 
  an array of dates which is used to provide statistics about 
  the counts.
  
  Copyright 2014 David Yee

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

package ca.ualberta.cs.asn1;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;

/*
 * CounterModel is the basic class that stores the data.
 * It implements Serializable to allow storage via JSON as well as to 
 * allow object data to be sent to new activities.
 * 
 * It implements Comparator to allow sorting for the ListView when the 
 * user hits the sort button.
 * 
 * The time is stamped every time the counter is incremented, being 
 * stored in a list of calendar objects.
 */
public class CounterModel implements Serializable, Comparator<CounterModel> {
  private String name;
  private Integer count;
  private ArrayList<Calendar> date; // each increment needs a timestamp
  private static final long serialVersionUID = 45012345; 

  public CounterModel(String name){
    super();
    this.name = name;
    this.count = 0;
    this.date = new ArrayList<Calendar>();
  }
  public CounterModel(){
    super();
    this.name = "Counter";
    this.count = 0;
    this.date = new ArrayList<Calendar>();
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Integer getCount() {
    return count;
  }
  
  public void setCount(Integer value) {
    this.count = value;
  }

  public void addCount() {
    this.count += 1;
    Calendar current = Calendar.getInstance();
    this.date.add(current); // keep track of the time incremented
  }  

  public ArrayList<Calendar> getDate() {
    return this.date;
  }
    @Override
    public int compare(CounterModel lhs, CounterModel rhs)
    {
        return rhs.count - lhs.count;
    }
}




Java Source Code List

ca.ualberta.cs.asn1.CounterActivity.java
ca.ualberta.cs.asn1.CounterListAdapter.java
ca.ualberta.cs.asn1.CounterModel.java
ca.ualberta.cs.asn1.CounterSaveModel.java
ca.ualberta.cs.asn1.StatisticActivity.java
ca.ualberta.cs.asn1.StatisticModel.java