From fffbcd69068f987823442257b9611725ed5435de Mon Sep 17 00:00:00 2001 From: "germano.oliveira" Date: Fri, 5 Jan 2018 22:06:55 -0200 Subject: [PATCH] :bug: Fixed bug that called animationComplete() twice --- .../lineartimer/ArcProgressAnimation.java | 10 ++++---- .../krtkush/lineartimer/LinearTimer.java | 24 +++++++++---------- .../LinearTimerCountDownTimer.java | 2 +- .../lineartimer/LinearTimerCountUpTimer.java | 2 +- .../lineartimer/LinearTimerStates.java | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lineartimer/src/main/java/io/github/krtkush/lineartimer/ArcProgressAnimation.java b/lineartimer/src/main/java/io/github/krtkush/lineartimer/ArcProgressAnimation.java index 78bafce..3e5a3a7 100644 --- a/lineartimer/src/main/java/io/github/krtkush/lineartimer/ArcProgressAnimation.java +++ b/lineartimer/src/main/java/io/github/krtkush/lineartimer/ArcProgressAnimation.java @@ -13,6 +13,7 @@ public class ArcProgressAnimation extends Animation { private float startingAngle; private float endingAngle; private TimerListener timerListener; + private boolean isFinished; /** * Instantiates a new Arc progress animation. @@ -31,16 +32,17 @@ public ArcProgressAnimation(LinearTimerView linearTimerView, int endingAngle, @Override protected void applyTransformation(float interpolatedTime, Transformation transformation) { - float finalAngle = startingAngle + ((endingAngle - startingAngle) * interpolatedTime); - linearTimerView.setPreFillAngle(finalAngle); linearTimerView.requestLayout(); // If interpolatedTime = 0.0 -> Animation has started. // If interpolatedTime = 1.0 -> Animation has completed. - if(interpolatedTime == 1.0) - timerListener.animationComplete(); + if(interpolatedTime == 1.0){ + if(isFinished) timerListener.animationComplete(); + isFinished = true; + } + } /** diff --git a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimer.java b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimer.java index 00f55c3..7f90aee 100644 --- a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimer.java +++ b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimer.java @@ -73,7 +73,7 @@ private LinearTimer(Builder builder) { linearTimerView.setPreFillAngle(preFillAngle); // Store the current status code in intStatusCode integer - intStatusCode = LinearTimerStates.INITIALIZED.getStaus(); + intStatusCode = LinearTimerStates.INITIALIZED.getStatus(); // If the user wants to show the progress in counter clock wise manner, // we flip the view on its Y-Axis and let it function as is. @@ -102,9 +102,9 @@ private void determinePreFillAngle() { public void startTimer() { if (basicParametersCheck()) { - if (intStatusCode == LinearTimerStates.INITIALIZED.getStaus()) { + if (intStatusCode == LinearTimerStates.INITIALIZED.getStatus()) { // Store the current status code in intStatusCode integer - intStatusCode = LinearTimerStates.ACTIVE.getStaus(); + intStatusCode = LinearTimerStates.ACTIVE.getStatus(); arcProgressAnimation = new ArcProgressAnimation(linearTimerView, endingAngle, this); arcProgressAnimation.setDuration(animationDuration); linearTimerView.startAnimation(arcProgressAnimation); @@ -124,10 +124,10 @@ public void startTimer() { public void pauseTimer() throws IllegalStateException { if (basicParametersCheck()) { // Timer may be paused only in active state. - if (intStatusCode == LinearTimerStates.ACTIVE.getStaus()) { + if (intStatusCode == LinearTimerStates.ACTIVE.getStatus()) { // Store the current status code in intStatusCode integer. - intStatusCode = LinearTimerStates.PAUSED.getStaus(); + intStatusCode = LinearTimerStates.PAUSED.getStatus(); // Clear animations off of linearTimerView, set prefillAngle to current // state and refresh view. @@ -152,7 +152,7 @@ else if (countType == COUNT_UP_TIMER) */ public void resumeTimer() throws IllegalStateException { if (basicParametersCheck()) { - if (intStatusCode == LinearTimerStates.PAUSED.getStaus()) { + if (intStatusCode == LinearTimerStates.PAUSED.getStatus()) { // Reinitialize the animations as it may not be simply continued. // The animation is reinitialized with the linearTimerView, @@ -178,7 +178,7 @@ else if (countType == COUNT_UP_TIMER) linearTimerView.startAnimation(arcProgressAnimation); // Store the current status code in intStatusCode integer - intStatusCode = LinearTimerStates.ACTIVE.getStaus(); + intStatusCode = LinearTimerStates.ACTIVE.getStatus(); } else throw new IllegalStateException("LinearTimer is not in paused state right now."); } @@ -191,7 +191,7 @@ public void restartTimer() { if (basicParametersCheck()) { if (arcProgressAnimation != null) { // Store the current status code in intStatusCode integer - intStatusCode = LinearTimerStates.ACTIVE.getStaus(); + intStatusCode = LinearTimerStates.ACTIVE.getStatus(); // Reset the pre filling angle as passed by user during initialization linearTimerView.setPreFillAngle(preFillAngle); @@ -213,10 +213,10 @@ public void restartTimer() { */ public void resetTimer() { if (basicParametersCheck()) { - if (intStatusCode == LinearTimerStates.PAUSED.getStaus() - || intStatusCode == LinearTimerStates.FINISHED.getStaus()) { + if (intStatusCode == LinearTimerStates.PAUSED.getStatus() + || intStatusCode == LinearTimerStates.FINISHED.getStatus()) { //Store the current status code in intStatusCode integer - intStatusCode = LinearTimerStates.INITIALIZED.getStaus(); + intStatusCode = LinearTimerStates.INITIALIZED.getStatus(); //Cancel the circle animation arcProgressAnimation.cancel(); @@ -270,7 +270,7 @@ public void animationComplete() { try { if (listenerCheck()) { // Store the current status code in intStatusCode integer - intStatusCode = LinearTimerStates.FINISHED.getStaus(); + intStatusCode = LinearTimerStates.FINISHED.getStatus(); timerListener.animationComplete(); } } catch (LinearTimerListenerMissingException ex) { diff --git a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountDownTimer.java b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountDownTimer.java index 8d428d9..9c3e817 100644 --- a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountDownTimer.java +++ b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountDownTimer.java @@ -29,7 +29,7 @@ public void onTick(long millisUntilFinished) { @Override public void onFinish() { - if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStaus()) + if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStatus()) timerListener.timerTick(0); } diff --git a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountUpTimer.java b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountUpTimer.java index 3552d1e..c78485c 100644 --- a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountUpTimer.java +++ b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerCountUpTimer.java @@ -25,7 +25,7 @@ public void onTick(long elapsedTime) { @Override public void onFinish() { - if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStaus()) + if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStatus()) if (timerListener != null) timerListener.timerTick(timerDuration); } diff --git a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerStates.java b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerStates.java index bf906f9..2d18130 100644 --- a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerStates.java +++ b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimerStates.java @@ -49,7 +49,7 @@ public enum LinearTimerStates { * A method to return the affixed integer representation of the Status codes. * @return An integer that represents the LinearTimer current status */ - public int getStaus() { + public int getStatus() { return intStatusCode; } }