Skip to content

Instantly share code, notes, and snippets.

@samuel22gj
Last active May 27, 2020 06:47
Show Gist options
  • Save samuel22gj/1934d8ef796a20f242eb82ab58f920bb to your computer and use it in GitHub Desktop.
Save samuel22gj/1934d8ef796a20f242eb82ab58f920bb to your computer and use it in GitHub Desktop.
Glide v4 target for GifDrawable or Drawable
/**
* A target for display {@link GifDrawable} or {@link Drawable} objects in {@link ImageView}s.
*/
public class GifDrawableImageViewTarget extends ImageViewTarget<Drawable> {
private int mLoopCount = GifDrawable.LOOP_FOREVER;
public GifDrawableImageViewTarget(ImageView view, int loopCount) {
super(view);
mLoopCount = loopCount;
}
public GifDrawableImageViewTarget(ImageView view, int loopCount, boolean waitForLayout) {
super(view, waitForLayout);
mLoopCount = loopCount;
}
@Override
protected void setResource(@Nullable Drawable resource) {
if (resource instanceof GifDrawable) {
((GifDrawable) resource).setLoopCount(mLoopCount);
}
view.setImageDrawable(resource);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment