Created
July 13, 2017 11:57
-
-
Save policante/e991e59b40ac67a2068a02ac23995497 to your computer and use it in GitHub Desktop.
CountDown 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
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