Skip to content

Instantly share code, notes, and snippets.

@duanhong169
Last active December 15, 2015 09:09
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 duanhong169/5235814 to your computer and use it in GitHub Desktop.
Save duanhong169/5235814 to your computer and use it in GitHub Desktop.
/**
* 该Drawable能够为与之绑定的ImageView保持一个BitmapWorkerTask(AsyncTask)的引用,使得
* BitmapWorkerTask能够在需要的时候被取消,并且保证只有最后与ImageView绑定的BitmapWorkerTask
* 才能够更新ImageView
*/
private static class AsyncDrawable extends BitmapDrawable {
private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
/**
* bitmap参数是占位图片(placeholder),代表图片正在加载中
*/
public AsyncDrawable(Resources res, Bitmap bitmap, BitmapWorkerTask bitmapWorkerTask) {
super(res, bitmap);
bitmapWorkerTaskReference =
new WeakReference<BitmapWorkerTask>(bitmapWorkerTask);
}
public BitmapWorkerTask getBitmapWorkerTask() {
return bitmapWorkerTaskReference.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment