private void updateImageCache() { HashSet<Long> toBeRemoved = new HashSet<Long>(mImageCache.keySet()); for (int i = mActiveStart; i < mActiveEnd; ++i) { MediaItem item = mData[i % DATA_CACHE_SIZE]; long version = item == null ? MediaObject.INVALID_DATA_VERSION : item.getDataVersion(); if (version == MediaObject.INVALID_DATA_VERSION) continue; ImageEntry entry = mImageCache.get(version); toBeRemoved.remove(version); if (entry != null) { if (Math.abs(i - mCurrentIndex) > 1) { if (entry.fullImageTask != null) { entry.fullImageTask.cancel(); entry.fullImageTask = null; } entry.fullImage = null; entry.requestedBits &= ~BIT_FULL_IMAGE; } } else { entry = new ImageEntry(); entry.rotation = item.getFullImageRotation(); mImageCache.put(version, entry); } } // Clear the data and requests for ImageEntries outside the new window. for (Long version : toBeRemoved) { ImageEntry entry = mImageCache.remove(version); if (entry.fullImageTask != null) entry.fullImageTask.cancel(); if (entry.screenNailTask != null) entry.screenNailTask.cancel(); } }
@Override public Bitmap run(JobContext jc) { Bitmap bitmap = mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc); if (jc.isCancelled()) return null; if (bitmap != null) { bitmap = BitmapUtils.rotateBitmap( bitmap, mItem.getRotation() - mItem.getFullImageRotation(), true); } return bitmap; }