/** * check whether the imageView has it's task. * * @param data * @param imageView * @return true no task */ private static boolean checkImageTask(Object data, ImageView imageView) { final BitmapLoadAndDisplayTask bitmapWorkerTask = getBitmapTaskFromImageView(imageView); if (bitmapWorkerTask != null) { final Object bitmapData = bitmapWorkerTask.data; if (bitmapData == null || !bitmapData.equals(data)) { bitmapWorkerTask.cancel(true); } else { return false; } } return true; }
/** * used for ImageView to download images. * * <p>if you use "ViewHolder" and "convertView.getTag()" in listView or gridView, you must use * this method'. * * <p>for image, if you just use bitmap from this method, you don't need to recycle this bitmap. * if you create a temporary bitmap, you must recycle it by yourself. * * @param url * @param defaultBitmap * @param imageView */ public void download(String url, Bitmap defaultBitmap, ImageView imageView) { if (null == url || "".equals(url) || "null".equals(url)) { return; } Bitmap bitmap = null; // bitmap = imageMemoryCache.getBitmapFromSoftCache(url); // bitmap = memoryCache.get(url); bitmap = mLruMemoryCache.get(url); if (bitmap != null) { // Logger.debug(this,"get image from memory cache, " + bitmap + " from url =" + url); imageView.setImageBitmap(bitmap); } else if (checkImageTask(url, imageView)) { final BitmapLoadAndDisplayTask task = new BitmapLoadAndDisplayTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mContext.getResources(), defaultBitmap, task); imageView.setImageDrawable(asyncDrawable); task.executeOnExecutor(executorService, url); } }