Skip to content

Instantly share code, notes, and snippets.

@peter-tackage
Last active December 26, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter-tackage/7168528 to your computer and use it in GitHub Desktop.
Save peter-tackage/7168528 to your computer and use it in GitHub Desktop.
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