Back to project page Android-Counter-Application.
The source code is released under:
GNU General Public License
If you think the Android project Android-Counter-Application listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package ca.ualberta.cs.artem_counter; // w ww. j av a 2s .c o m import java.util.ArrayList; import java.util.Comparator; import java.util.Date; //Basic counter object public class Counter { private int count; private Date timestamp; private ArrayList<Date> clicks; private String name; //Constructor public Counter(String name) { super(); this.setName(name); setTimestamp(new Date()); setCount(0); setClicks(new ArrayList<Date>()); } //Getters and Setters public String getName() { return name; } public void setName(String name) { this.name = name; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public ArrayList<Date> getClicks() { return clicks; } public void setClicks(ArrayList<Date> clicks) { this.clicks = clicks; } public Date getTimestamp() { return timestamp; } public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } // method required by the sorting functor public boolean equals(Counter rhs){ if(this.getName().equals(rhs.getName())){ return true; } else{ return false; } } public void addClick() { clicks.add(new Date()); } //The '+' button method public void increment() { setCount(count+1); addClick(); } //The 'reset' button method public void reset() { setCount(0); clicks.clear(); setTimestamp(new Date()); } // return the # of clicks in the specified date range public int getClicksInRange(Date from, Date to) { int count = 0; for(Date date : clicks) { if(date.before(to) && date.after(from)) { ++count; } } return count; } // Functor used for sorting the counters by decreasing count. public static class CounterFunctor implements Comparator<Counter> { public int compare(Counter arg0,Counter arg1) { return arg1.getCount()-arg0.getCount(); } } }