Last active
December 15, 2015 09:09
-
-
Save duanhong169/5235814 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 该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