Skip to content

Instantly share code, notes, and snippets.

@kasparsj
Created April 13, 2014 19:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kasparsj/10599789 to your computer and use it in GitHub Desktop.
Save kasparsj/10599789 to your computer and use it in GitHub Desktop.
An infinite timer
import android.os.CountDownTimer;
abstract public class CountUpTimer
{
private CountDownTimer countDownTimer;
private int countDownCycle;
public CountUpTimer(long countUpInterval) {
countDownTimer = new CountDownTimer(Long.MAX_VALUE, countUpInterval) {
@Override
public void onTick(long millisUntilFinished) {
CountUpTimer.this.onTick(Long.MAX_VALUE * countDownCycle - millisUntilFinished);
}
@Override
public void onFinish() {
countDownCycle++;
CountUpTimer.this.start();
}
};
countDownCycle = 1;
}
public void start() {
countDownTimer.start();
}
public void stop() {
countDownTimer.cancel();
}
public void cancel() {
stop();
countDownCycle = 1;
}
public abstract void onTick(long millisElapsed);
}
@sethu443
Copy link

Hi. What is the need for the int variable countDownCycle?

@ArasApps
Copy link

This is nicely done, thank you. It did saved me the effort of making one. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment