public static boolean cancelPotentialWork(String path, ImageView imageView) { final LoadThumbnailTask loadPictureTask = getLoadTHumbnailTask(imageView); if (loadPictureTask != null) { final String bitmapPath = loadPictureTask.fotografia; // If bitmapPath is not yet set or it differs from the new path if (bitmapPath == null || !bitmapPath.equals(path)) { // Cancel previous task loadPictureTask.cancel(true); } else { // The same work is already in progress return false; } } // No task associated with the ImageView, or an existing task was cancelled return true; }
public synchronized ExpenseThumbnail getThumbnail( int id, ExpenseThumbnail.OnExpenseThumbnailLoadedListener onLoadedListener, Object onLoadedContext) { ExpenseThumbnail thumb = mThumbs.get(new Integer(id)); if (thumb != null) { if (onLoadedListener != null) thumb.registerOnLoadedListener(onLoadedListener, onLoadedContext); return thumb; } thumb = new ExpenseThumbnail(mContext, id); if (onLoadedListener != null) { thumb.registerOnLoadedListener(onLoadedListener, onLoadedContext); Log.d( "ThumbCache", "thumb id " + Integer.toString(thumb.id) + " has new load listener " + onLoadedListener.toString() + " with context " + (onLoadedContext == null ? "<null>" : onLoadedContext.toString())); } LoadThumbnailTask task = new LoadThumbnailTask(); task.execute(thumb); Log.d("ThumbCache", "added thumb id " + Integer.toString(thumb.id) + " to load list"); // cache the thumbnail mThumbs.put(new Integer(id), thumb); Log.d("ThumbCache", "cached thumb id " + Integer.toString(thumb.id)); return thumb; }