From 75ccdcc12659cea2a63b15d55845b863c0c34c25 Mon Sep 17 00:00:00 2001 From: Kartikey Kushwaha Date: Thu, 27 Apr 2017 16:11:24 +0530 Subject: [PATCH] Refactoring. --- .../lineartimeproject/MainActivity.java | 5 -- .../krtkush/lineartimer/LinearTimer.java | 65 +++++++++---------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/io/github/krtkush/lineartimeproject/MainActivity.java b/app/src/main/java/io/github/krtkush/lineartimeproject/MainActivity.java index aead9f0..617908e 100644 --- a/app/src/main/java/io/github/krtkush/lineartimeproject/MainActivity.java +++ b/app/src/main/java/io/github/krtkush/lineartimeproject/MainActivity.java @@ -42,11 +42,6 @@ protected void onCreate(Bundle savedInstanceState) { linearTimer = new LinearTimer.Builder() .linearTimerView(linearTimerView) .duration(duration) - .timerListener(this) - .progressDirection(LinearTimer.CLOCK_WISE_PROGRESSION) - .preFillAngle(0) - .endingAngle(360) - .getCountUpdate(LinearTimer.COUNT_UP_TIMER, 1000) .build(); // Start the timer. 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 c0807ba..5b7e01a 100644 --- a/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimer.java +++ b/lineartimer/src/main/java/io/github/krtkush/lineartimer/LinearTimer.java @@ -96,6 +96,25 @@ private void determinePreFillAngle() { this.preFillAngle = (timeElapsedPercentage / 100) * 360; } + /** + * Method to start the timer. + */ + public void startTimer() { + + if (basicParametersCheck()) { + if (intStatusCode == LinearTimerStates.INITIALIZED.getStaus()) { + // Store the current status code in intStatusCode integer + intStatusCode = LinearTimerStates.ACTIVE.getStaus(); + arcProgressAnimation = new ArcProgressAnimation(linearTimerView, endingAngle, this); + arcProgressAnimation.setDuration(animationDuration); + linearTimerView.startAnimation(arcProgressAnimation); + + checkForCountUpdate(); + } else + throw new IllegalStateException("LinearTimer is not in INITIALIZED state right now."); + } + } + /** * A method to pause the running timer. * @throws IllegalStateException IllegalStateException is thrown if the user tries to pause @@ -167,25 +186,6 @@ else if(countType == COUNT_UP_TIMER) } } - /** - * Method to start the timer. - */ - public void startTimer() { - - if (basicParametersCheck()) { - if (intStatusCode == LinearTimerStates.INITIALIZED.getStaus()) { - // Store the current status code in intStatusCode integer - intStatusCode = LinearTimerStates.ACTIVE.getStaus(); - arcProgressAnimation = new ArcProgressAnimation(linearTimerView, endingAngle, this); - arcProgressAnimation.setDuration(animationDuration); - linearTimerView.startAnimation(arcProgressAnimation); - - checkForCountUpdate(); - } else - throw new IllegalStateException("LinearTimer is not in INITIALIZED state right now."); - } - } - /** * Reset the timer to start angle and then start the progress again. */ @@ -351,23 +351,20 @@ private boolean listenerCheck() throws LinearTimerListenerMissingException { */ private void checkForCountUpdate() { - if (countType != -1) { + switch (countType) { - switch (countType) { + case COUNT_DOWN_TIMER: + countDownTimer = new + LinearTimerCountDownTimer(animationDuration, + updateInterval, timerListener); + countDownTimer.start(); + break; - case COUNT_DOWN_TIMER: - countDownTimer = new - LinearTimerCountDownTimer(animationDuration, - updateInterval, timerListener); - countDownTimer.start(); - break; - - case COUNT_UP_TIMER: - countUpTimer = new LinearTimerCountUpTimer(animationDuration, - updateInterval, timerListener); - countUpTimer.start(); - break; - } + case COUNT_UP_TIMER: + countUpTimer = new LinearTimerCountUpTimer(animationDuration, + updateInterval, timerListener); + countUpTimer.start(); + break; } }