Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/com/ivanrf/countdownanimation/CountDownAnimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class CountDownAnimation {
private int mStartCount;
private int mCurrentCount;
private CountDownListener mListener;
private CountDownProgressListener mProgressListener;

private Handler mHandler = new Handler();

Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}
9 changes: 8 additions & 1 deletion src/com/ivanrf/countdownanimation/TestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}