Last active
December 26, 2015 14:49
-
-
Save peter-tackage/7168528 to your computer and use it in GitHub Desktop.
Cancellable Target Callback for Square Picasso
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Bitmap; | |
import android.graphics.drawable.Drawable; | |
import com.squareup.picasso.Picasso; | |
import com.squareup.picasso.Target; | |
public class CancelableTarget implements Target { | |
protected Target mTarget; | |
private boolean mIsCancelled; | |
public CancelableTarget(Target _target) { | |
mTarget = _target; | |
} | |
@Override | |
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { | |
if(!mIsCancelled){ | |
mTarget.onBitmapLoaded(bitmap, from); | |
} | |
} | |
@Override | |
public void onBitmapFailed(Drawable errorDrawable) { | |
if(!mIsCancelled){ | |
mTarget.onBitmapFailed(errorDrawable); | |
} | |
} | |
@Override | |
public void onPrepareLoad(Drawable placeHolderDrawable) { | |
if(!mIsCancelled){ | |
mTarget.onPrepareLoad(placeHolderDrawable); | |
} | |
} | |
public void cancel() { | |
mIsCancelled = true; | |
mTarget = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment