Created
April 9, 2014 19:19
-
-
Save JayNewstrom/10305041 to your computer and use it in GitHub Desktop.
Countdown Text Builder
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
StringBuilder sb = new StringBuilder(); | |
if (secondsRemaining >= 3600) { // over and hour | |
long hours = secondsRemaining / 3600; | |
secondsRemaining %= 3600; | |
sb.append(hours); | |
sb.append(":"); | |
if (secondsRemaining < 60) { | |
sb.append("00:"); // we will skip the minutes stuff, so add it here. | |
} | |
} | |
if (secondsRemaining >= 60) { // over a minute | |
long minutes = secondsRemaining / 60; | |
secondsRemaining %= 60; | |
if (minutes > 9) { | |
sb.append(minutes); | |
} else { | |
sb.append(0).append(minutes); | |
} | |
sb.append(":"); | |
} | |
if (secondsRemaining >= 0) { | |
if (secondsRemaining > 9) { | |
sb.append(secondsRemaining); | |
} else { | |
sb.append(0).append(secondsRemaining); | |
} | |
} | |
timerTextView.setText(sb.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment