Skip to content

Instantly share code, notes, and snippets.

@kasparsj
Created April 13, 2014 19:57
Show Gist options
  • 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);
}
@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