Skip to content

Commit

Permalink
Added gif loop ended listener
Browse files Browse the repository at this point in the history
  • Loading branch information
AnwarShahriar committed Dec 2, 2018
1 parent f7d8604 commit 7fa56dc
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class GifDrawable extends Drawable implements GifFrameLoader.FrameCallbac
private Paint paint;
private Rect destRect;

private OnGifLoopEndedListener gifLoopEndedListener;

/**
* Constructor for GifDrawable.
*
Expand Down Expand Up @@ -165,6 +167,10 @@ public Bitmap getFirstFrame() {
return state.frameLoader.getFirstFrame();
}

public void setGifLoopEndedListener(OnGifLoopEndedListener gifLoopEndedListener) {
this.gifLoopEndedListener = gifLoopEndedListener;
}

// Public API.
@SuppressWarnings("WeakerAccess")
public void setFrameTransformation(Transformation<Bitmap> frameTransformation,
Expand Down Expand Up @@ -351,6 +357,9 @@ public void onFrameReady() {
}

if (maxLoopCount != LOOP_FOREVER && loopCount >= maxLoopCount) {
if (gifLoopEndedListener != null) {
gifLoopEndedListener.onGifLoopEnded();
}
stop();
}
}
Expand Down Expand Up @@ -415,4 +424,11 @@ public int getChangingConfigurations() {
return 0;
}
}

/**
* A callback to notify loop completion of a gif, where the loop count is explicitly specified.
*/
public interface OnGifLoopEndedListener {
void onGifLoopEnded();
}
}

0 comments on commit 7fa56dc

Please sign in to comment.