(final ImageView view,
final String url,
final ImageOptions options,
final int fileLockedExceptionRetryCount,
final Callback.CommonCallback<Drawable> callback)
| 162 | */ |
| 163 | /*package*/ |
| 164 | static Cancelable doBind(final ImageView view, |
| 165 | final String url, |
| 166 | final ImageOptions options, |
| 167 | final int fileLockedExceptionRetryCount, |
| 168 | final Callback.CommonCallback<Drawable> callback) { |
| 169 | |
| 170 | // check params |
| 171 | ImageOptions localOptions = options; |
| 172 | { |
| 173 | if (view == null) { |
| 174 | postArgsException(null, localOptions, "view is null", callback); |
| 175 | return null; |
| 176 | } |
| 177 | |
| 178 | if (TextUtils.isEmpty(url)) { |
| 179 | postArgsException(view, localOptions, "url is null", callback); |
| 180 | return null; |
| 181 | } |
| 182 | |
| 183 | if (localOptions == null) { |
| 184 | localOptions = ImageOptions.DEFAULT; |
| 185 | } |
| 186 | localOptions.optimizeMaxSize(view); |
| 187 | } |
| 188 | |
| 189 | // stop the old loader |
| 190 | MemCacheKey key = new MemCacheKey(url, localOptions); |
| 191 | Drawable oldDrawable = view.getDrawable(); |
| 192 | if (oldDrawable instanceof AsyncDrawable) { |
| 193 | ImageLoader loader = ((AsyncDrawable) oldDrawable).getImageLoader(); |
| 194 | if (loader != null && !loader.stopped) { |
| 195 | if (key.equals(loader.key)) { |
| 196 | // repetitive url and options binding to the same View. |
| 197 | // not need callback to ui. |
| 198 | return null; |
| 199 | } else { |
| 200 | loader.cancel(); |
| 201 | } |
| 202 | } |
| 203 | } else if (oldDrawable instanceof ReusableDrawable) { |
| 204 | MemCacheKey oldKey = ((ReusableDrawable) oldDrawable).getMemCacheKey(); |
| 205 | if (oldKey != null && oldKey.equals(key)) { |
| 206 | MEM_CACHE.put(key, oldDrawable); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // load from Memory Cache |
| 211 | Drawable memDrawable = null; |
| 212 | if (localOptions.isUseMemCache()) { |
| 213 | memDrawable = MEM_CACHE.get(key); |
| 214 | if (memDrawable instanceof BitmapDrawable) { |
| 215 | Bitmap bitmap = ((BitmapDrawable) memDrawable).getBitmap(); |
| 216 | if (bitmap == null || bitmap.isRecycled()) { |
| 217 | memDrawable = null; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | if (memDrawable != null) { // has mem cache |
no test coverage detected