Skip to content

Instantly share code, notes, and snippets.

@peter-tackage peter-tackage/gist:7168528
Last active Dec 26, 2015

Embed
What would you like to do?
Cancellable Target Callback for Square Picasso
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
You can’t perform that action at this time.