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..f7deb89 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,10 @@ 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(); + } }