public void loadBitmap(String number, ImageView imageView) { if (cancelPotentialWork(number, imageView)) { final BitmapWorkerRunnable runnable = new BitmapWorkerRunnable(context, imageView, defaultPhoto, number, scaledPhotoSize); final TaggedFutureTask<?> task = new TaggedFutureTask<Void>(runnable, null, number); final AsyncDrawable asyncDrawable = new AsyncDrawable(context.getResources(), defaultCroppedPhoto, task); imageView.setImageDrawable(asyncDrawable); if (!task.isCancelled()) photoResolver.execute(new FutureTask<Void>(task, null)); } }
public boolean cancelPotentialWork(String number, ImageView imageView) { final TaggedFutureTask<?> bitmapWorkerTask = AsyncDrawable.getBitmapWorkerTask(imageView); if (bitmapWorkerTask != null) { final Object tag = bitmapWorkerTask.getTag(); if (tag != null && !tag.equals(number)) { bitmapWorkerTask.cancel(true); } else { return false; } } return true; }