Created
April 13, 2014 19:57
-
-
Save kasparsj/10599789 to your computer and use it in GitHub Desktop.
An infinite timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is nicely done, thank you. It did saved me the effort of making one. Thanks.