diff --git a/library/src/main/java/com/github/jorgecastillo/FillableLoader.java b/library/src/main/java/com/github/jorgecastillo/FillableLoader.java index aeee279..3c24d3e 100644 --- a/library/src/main/java/com/github/jorgecastillo/FillableLoader.java +++ b/library/src/main/java/com/github/jorgecastillo/FillableLoader.java @@ -248,11 +248,20 @@ public void setToFinishedFrame() { if (hasToKeepDrawing(elapsedTime)) { ViewCompat.postInvalidateOnAnimation(this); + checkState(); } else { changeState(State.FINISHED); } } + private void checkState() { + if (drawingState != State.FILL_FINISHED + && percentageEnabled + && previousFramePercentage >= percentage) { + changeState(State.FILL_FINISHED); + } + } + private void drawStroke(Canvas canvas, long elapsedTime) { float phase = MathUtil.constrain(0, 1, elapsedTime * 1f / strokeDrawingDuration); float distance = animInterpolator.getInterpolation(phase) * pathData.length; @@ -356,7 +365,9 @@ public void setPercentage(float percentage) { } else if (drawingState == State.STROKE_STARTED) { this.percentageEnabled = true; this.percentage = percentage; - } else if (drawingState == State.FILL_STARTED) { + } else if (drawingState == State.FILL_STARTED || drawingState == State.FILL_FINISHED) { + drawingState = State.FILL_STARTED; + if (percentageEnabled) { this.percentage = percentage; } else { diff --git a/library/src/main/java/com/github/jorgecastillo/State.java b/library/src/main/java/com/github/jorgecastillo/State.java index 4f32478..a4cce3b 100644 --- a/library/src/main/java/com/github/jorgecastillo/State.java +++ b/library/src/main/java/com/github/jorgecastillo/State.java @@ -26,4 +26,5 @@ public class State { public static final int STROKE_STARTED = 1; public static final int FILL_STARTED = 2; public static final int FINISHED = 3; + public static final int FILL_FINISHED = 4; }