From 9f70556fbcb5ece282f28b728a4982cd8e3fcf83 Mon Sep 17 00:00:00 2001 From: Manu Misra Date: Wed, 13 Sep 2017 21:40:40 -0400 Subject: [PATCH 1/2] Added count down progress listener and it's corresonding notification --- .../CountDownAnimation.java | 39 +++++++++++++++++++ .../countdownanimation/TestActivity.java | 6 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/com/ivanrf/countdownanimation/CountDownAnimation.java b/src/com/ivanrf/countdownanimation/CountDownAnimation.java index f9f972a..0a77e33 100644 --- a/src/com/ivanrf/countdownanimation/CountDownAnimation.java +++ b/src/com/ivanrf/countdownanimation/CountDownAnimation.java @@ -35,6 +35,7 @@ public class CountDownAnimation { private int mStartCount; private int mCurrentCount; private CountDownListener mListener; + private CountDownProgressListener mProgressListener; private Handler mHandler = new Handler(); @@ -44,6 +45,9 @@ public void run() { mTextView.setText(mCurrentCount + ""); mTextView.startAnimation(mAnimation); mCurrentCount--; + + if(mProgressListener!=null) + mProgressListener.onCountDownProgress(CountDownAnimation.this); } else { mTextView.setVisibility(View.GONE); if (mListener != null) @@ -136,6 +140,14 @@ public int getStartCount() { return mStartCount; } + /** + * Returns current count left for the count down animation + * @return + */ + public int getCurrentCount() { + return mCurrentCount; + } + /** * Binds a listener to this count down animation. The count down listener is * notified of events such as the end of the animation. @@ -161,4 +173,31 @@ public static interface CountDownListener { */ void onCountDownEnd(CountDownAnimation animation); } + + + /** + * Binds a listener to this count down animation. The count down listener is + * notified of events such as the progress of the animation. + * + * @param progressListener + * The count down listener to be notified + */ + public void setCountDownProgressListener(CountDownProgressListener progressListener) { + mProgressListener = progressListener; + } + + /** + * A count down progress listener receives notifications from a count down animation. + * Notifications indicate count down animation related events, such as the + * progress of the animation. + */ + public static interface CountDownProgressListener { + /** + * Notifies the progress of the count down animation. + * + * @param animation + * The count down animation which reached its next step. + */ + void onCountDownProgress(CountDownAnimation animation); + } } diff --git a/src/com/ivanrf/countdownanimation/TestActivity.java b/src/com/ivanrf/countdownanimation/TestActivity.java index 43a87ba..fff2e1b 100644 --- a/src/com/ivanrf/countdownanimation/TestActivity.java +++ b/src/com/ivanrf/countdownanimation/TestActivity.java @@ -32,8 +32,9 @@ import android.widget.Toast; import com.ivanrf.countdownanimation.CountDownAnimation.CountDownListener; +import com.ivanrf.countdownanimation.CountDownAnimation.CountDownProgressListener; -public class TestActivity extends Activity implements CountDownListener { +public class TestActivity extends Activity implements CountDownListener, CountDownProgressListener { private TextView textView; private EditText startCountEditText; @@ -119,4 +120,7 @@ private int getStartCount() { public void onCountDownEnd(CountDownAnimation animation) { Toast.makeText(this, "Done!", Toast.LENGTH_SHORT).show(); } + + @Override
 public void onCountDownProgress(CountDownAnimation animation) { + // Do whatever you want to do, on progress of every second
 Toast.makeText(this, animation.getCurrentCount()+” seconds left!”, Toast.LENGTH_SHORT).show();
 } } From 8eee8fdbec10e95a675ca8265052648939a55fc7 Mon Sep 17 00:00:00 2001 From: manukmisra <31074474+manukmisra@users.noreply.github.com> Date: Wed, 13 Sep 2017 21:45:34 -0400 Subject: [PATCH 2/2] Formatting changes --- src/com/ivanrf/countdownanimation/TestActivity.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/ivanrf/countdownanimation/TestActivity.java b/src/com/ivanrf/countdownanimation/TestActivity.java index fff2e1b..f7deb89 100644 --- a/src/com/ivanrf/countdownanimation/TestActivity.java +++ b/src/com/ivanrf/countdownanimation/TestActivity.java @@ -121,6 +121,9 @@ public void onCountDownEnd(CountDownAnimation animation) { Toast.makeText(this, "Done!", Toast.LENGTH_SHORT).show(); } - @Override
 public void onCountDownProgress(CountDownAnimation animation) { - // Do whatever you want to do, on progress of every second
 Toast.makeText(this, animation.getCurrentCount()+” seconds left!”, Toast.LENGTH_SHORT).show();
 } + @Override + public void onCountDownProgress(CountDownAnimation animation) { + // Do whatever you want to do, on progress of every second + Toast.makeText(this, animation.getCurrentCount()+” seconds left!”, Toast.LENGTH_SHORT).show(); + } }