Rewrites the setPercentComplete function to greatly simplify the logic and fix a few issues.
@@ -90,35 +90,28 @@ public class LoadingBar extends Component {
* @param percentComplete
* The new percent complete.
*/
- public void setPercentComplete(final int percentComplete) {
- boolean isWithinRange = percentComplete >= 0;
- isWithinRange &= percentComplete <= 100;
+ public void setPercentComplete(int percentComplete) {
+ if (percentComplete < 0) {
+ percentComplete = 0;
+ }
- if (isWithinRange == false || this.percentComplete == percentComplete) {
- return;
+ if (percentComplete > 100) {
+ percentComplete = 100;
}
- final boolean increased = this.percentComplete < percentComplete;
- final int totalCompleteChars_prev = (int) (getWidth() * (percentComplete / 100f));
- final int totalCompleteChars_curr = (int) (getWidth() * (this.percentComplete / 100f));
+ final int numberOfCompleteChars = (int) (super.getWidth() * (percentComplete / 100f));
+ final IntRange range = new IntRange(0, numberOfCompleteChars);
for (final AsciiString string : super.getStrings()) {
- IntRange range;
+ string.setBackgroundAndForegroundColor(backgroundColor_incomplete, foregroundColor_incomplete);
+ string.setAllCharacters(incompleteCharacter);
- if (increased) {
- range = new IntRange(totalCompleteChars_curr, totalCompleteChars_prev);
+ string.setBackgroundAndForegroundColor(backgroundColor_complete, foregroundColor_complete, range);
string.setCharacters(completeCharacter, range);
- } else {
- range = new IntRange(totalCompleteChars_prev, totalCompleteChars_curr);
- string.setCharacters(incompleteCharacter, range);
- }
-
- string.setBackgroundColor(backgroundColor_complete, range);
- string.setForegroundColor(foregroundColor_complete, range);
}
this.percentComplete = percentComplete;
- super.getRadio().transmit("DRAW");
+ super.transmitDraw();
}
}
