Skip to content

Instantly share code, notes, and snippets.

@policante
Created July 13, 2017 11:57
Show Gist options
  • Save policante/e991e59b40ac67a2068a02ac23995497 to your computer and use it in GitHub Desktop.
Save policante/e991e59b40ac67a2068a02ac23995497 to your computer and use it in GitHub Desktop.
CountDown timer
public class CountDown {
private CountDownTimer countDownTimer;
private int timeSeconds = 30;
public CountDown(){
countDownTimer = new CountDownTimer(timeSeconds * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
String v = String.format("%02d", millisUntilFinished / 60000);
int va = (int) ((millisUntilFinished % 60000) / 1000);
System.out.println(v + ":" + String.format("%02d", va));
}
@Override
public void onFinish() {
System.out.println("Finished");
}
};
}
public void startTimer(){
countDownTimer.start();
}
public void stopTimer(){
if (countDownTimer != null){
countDownTimer.cancel();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment