Skip to content

Commit

Permalink
add provision to add multiple on click listeners to the play button
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeepw committed May 9, 2014
1 parent 03f7d66 commit b605450
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions LibAudioWife/src/nl/changer/audiowife/AudioWife.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class AudioWife {
* Array to hold custom completion listeners
****/
private ArrayList<OnCompletionListener> mCompletionListeners = new ArrayList<MediaPlayer.OnCompletionListener>();

private ArrayList<View.OnClickListener> mPlayListeners = new ArrayList<View.OnClickListener>();

/***
* Audio URI
Expand Down Expand Up @@ -224,6 +226,7 @@ public AudioWife init(Context ctx, Uri uri) {
****/
public AudioWife setPlayView(View play) {
mPlayButton = play;

initOnPlayClick();
return this;
}
Expand All @@ -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);
}
}
});
}

/***
Expand All @@ -248,7 +263,6 @@ public void onClick(View v) {
****/
public AudioWife setPauseView(View pause) {
mPauseButton = pause;

return this;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b605450

Please sign in to comment.