From b605450c9b3e4c50c5c932a6a3bd88b8420ddbfe Mon Sep 17 00:00:00 2001 From: Jaydeep Date: Sat, 10 May 2014 01:35:21 +0530 Subject: [PATCH] add provision to add multiple on click listeners to the play button --- .../src/nl/changer/audiowife/AudioWife.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/LibAudioWife/src/nl/changer/audiowife/AudioWife.java b/LibAudioWife/src/nl/changer/audiowife/AudioWife.java index 4532ca5..13a1f96 100644 --- a/LibAudioWife/src/nl/changer/audiowife/AudioWife.java +++ b/LibAudioWife/src/nl/changer/audiowife/AudioWife.java @@ -73,6 +73,8 @@ public class AudioWife { * Array to hold custom completion listeners ****/ private ArrayList mCompletionListeners = new ArrayList(); + + private ArrayList mPlayListeners = new ArrayList(); /*** * Audio URI @@ -224,6 +226,7 @@ public AudioWife init(Context ctx, Uri uri) { ****/ public AudioWife setPlayView(View play) { mPlayButton = play; + initOnPlayClick(); return this; } @@ -232,13 +235,25 @@ private void initOnPlayClick() { if(mPlayButton == null) throw new NullPointerException("Play view cannot be null"); - mPlayButton.setOnClickListener( new View.OnClickListener() { + mPlayListeners.add(new View.OnClickListener() { @Override public void onClick(View v) { play(); } }); + + // Fire all the attached listeners + // when the play button is actually clicked + mPlayButton.setOnClickListener( new View.OnClickListener() { + + @Override + public void onClick(View v) { + for (View.OnClickListener listener : mPlayListeners) { + listener.onClick(v); + } + } + }); } /*** @@ -248,7 +263,6 @@ public void onClick(View v) { ****/ public AudioWife setPauseView(View pause) { mPauseButton = pause; - return this; } @@ -281,6 +295,18 @@ public AudioWife addOnCompletionListener( return this; } + + /**** + * Add custom play button click listener. Adding multiple listeners will + * queue up all the listners and fire them all together when the event occurs. + */ + public AudioWife addOnPlayClickListener( + View.OnClickListener listener) { + + mPlayListeners.add(listener); + + return this; + } /**** * Initialize and prepare the audio player