Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Timer {
- private boolean isActivated;
- private boolean isStopped;
- private CountDownTimer timer;
- private String name;
- private long timeToGo;
- Timer(){
- isActivated = false;
- isStopped = false;
- name = "Activate";
- }
- public void activate(long future, long interval,final TextView text,String _name){
- SystemClock.uptimeMillis();
- timeToGo = future;
- timer = new CountDownTimer(future, interval){
- public void onTick(long millisUntilFinished) {
- if(!isStopped){
- Time time = new Time(millisUntilFinished - 3 * 3600000);
- String textTime = "";
- Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
- calendar.setTime(time); // assigns calendar to given date
- int hrs = calendar.get(Calendar.HOUR_OF_DAY); // gets hour in 24h format
- int min = calendar.get(Calendar.MINUTE);
- int sec = calendar.get(Calendar.SECOND);
- if(millisUntilFinished > 3600000){
- text.setTextSize(36);
- }
- if(hrs!=0)
- textTime+=String.format("%02d",hrs)+":";
- if(min!=0||hrs!=0)
- textTime+=String.format("%02d",min)+":";
- textTime+=String.format("%02d",sec);
- text.setText(textTime);
- }
- }
- public void onFinish() {
- if(!isStopped)
- text.setText("DONE!");
- }
- };
- name = _name;
- isActivated = true;
- timer.start();
- }
- public boolean isActivated(){
- return isActivated;
- }
- public String getTime(){
- return "00:00";
- }
- public String getName() {
- return name;
- }
- public void stop() {
- timer.cancel();
- timer = null;
- isStopped = true;
- }
- public boolean isStopped() {
- return isStopped;
- }
- public long getTimer() {
- return timeToGo;
- }
- public void start() {
- isStopped = false;
- }
- }
- if(timers[id].isStopped()){
- timers[id].start();
- timers[id].activate(timers[id].getTimer(), 1000, clocks[id*2], timers[id].getName());
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement