android - Is there a way to force gif loaded with Glide to be non-animated -
i have set of images, loaded via glide.
the nsfw ones blurred using glide (wasabeef) bitmap transformation, can animated gifs, in case first frame shown blurred, , animation starts looping (unblurred).
the following have tried , not work:
drawabletyperequest<string> builder = glide.with(mimage.getcontext()).load(...); if (entry.isnsfw()) { builder.asbitmap(); } builder.diskcachestrategy(diskcachestrategy.source) //it's none of relevant .skipmemorycache(true) .override(props.getwidth(), props.getheight()); if (entry.isnsfw()) { //successfully blurs nsfw images, still allows unblurred animation builder.dontanimate().bitmaptransform(centrecrop, blur); } else { builder.centercrop(); } builder.crossfade(500) //moving crossfade sfw posts has no effect .into(mimage);
also not working intercepting load:
builder.listener(new requestlistener<string, glidedrawable>() { @override public boolean onexception(exception e, string model, target<glidedrawable> target, boolean isfirstresource) { return false; } @override public boolean onresourceready(glidedrawable resource, string model, target<glidedrawable> target, boolean isfrommemorycache, boolean isfirstresource) { if (entry.isnsfw()) { target.onresourceready(resource, null); //if add , return true image static, unblurred resource.stop(); //if called before target, has no effect return true; } return false; //returning true without calling target stops of images being set on view } });
how can turn off gif playback individual images while still keeping blur transformation?
i have set of images, loaded via glide
from above, assume using recyclerview
show these images , answer based on assumption.
try custom glide target of own stops animation if nsfw this
public class customtarget extends glidedrawableimageviewtarget { private boolean isnsfw; public customtarget(imageview view) { super(view); } public void setnsfw(boolean isnsfw){ this.isnsfw = isnsfw; } @override public void onresourceready(glidedrawable resource, glideanimation<? super glidedrawable> animation) { // super call loads image, sets imageview , starts // animating if gif super.onresourceready(resource, animation); if(isnsfw){ onstop(); // stop playing animation if nsfw } } }
and in view holder class, create , keep reference target other views
public class myviewholder extends recyclerview.viewholder { imageview myimageview; customtarget mycustomtarget; public myviewholder(view itemview) { super(itemview); myimageview = (imageview) itemview.findviewbyid(r.id.myiv); mycustomtarget = new customtarget(myimageview); } }
then in onbindviewholder following
public void onbindviewholder(myviewholder holder, int position) { // current entry in image set final entry entry = entries.get(position); // call before loading resource holder.mycustomtarget.setnsfw(entry.isnsfw()); // no need specify asgif() // refer http://stackoverflow.com/a/34870817/3533289 glide.with(context) .load(entry.geturl()) .into(holder.mycustomtarget); }
i haven't tested solution myself. hope give idea of how tackle issue.
Comments
Post a Comment