/** * Adds an {@link ImageCache} to this image loader. * * @param fragmentManager A FragmentManager to use to retain the cache over configuration * changes such as an orientation change. * @param memCacheSizePercent The cache size as a percent of available app memory. */ public void addImageCache(FragmentManager fragmentManager, float memCacheSizePercent) { mImageCache = ImageCache.getInstance(fragmentManager, memCacheSizePercent); }
/** * Find and return an existing ImageCache stored in a {@link ImageCache.RetainFragment}, if not found a new * one is created using the supplied params and saved to a {@link ImageCache.RetainFragment}. * * @param fragmentManager The fragment manager to use when dealing with the retained fragment. * @param memCacheSizePercent The cache size as a percent of available app memory. * @return An existing retained ImageCache object or a new one if one did not exist */ public static ImageCache getInstance( FragmentManager fragmentManager, float memCacheSizePercent) { // Search for, or create an instance of the non-UI RetainFragment final RetainFragment mRetainFragment = findOrCreateRetainFragment(fragmentManager); // See if we already have an ImageCache stored in RetainFragment ImageCache imageCache = (ImageCache) mRetainFragment.getObject(); // No existing ImageCache, create one and store it in RetainFragment if (imageCache == null) { imageCache = new ImageCache(memCacheSizePercent); mRetainFragment.setObject(imageCache); } return imageCache; }
/** * Initialize the cache. * * @param memCacheSizePercent The cache size as a percent of available app memory. */ private void init(float memCacheSizePercent) { int memCacheSize = calculateMemCacheSize(memCacheSizePercent); // Set up memory cache if (BuildConfig.DEBUG) { Log.d(TAG, "Memory cache created (size = " + memCacheSize + ")"); } mMemoryCache = new LruCache<String, Bitmap>(memCacheSize) { /** * Measure item size in kilobytes rather than units which is more practical * for a bitmap cache */ @Override protected int sizeOf(String key, Bitmap bitmap) { final int bitmapSize = getBitmapSize(bitmap) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; }
if (imageCache.getBitmapFromMemCache(message.getKeyString()) == null) { imageCache.addBitmapToCache(message.getKeyString(), data.getProfilePic()); myViewHolder.shareContactImage.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString()));
public void loadImage(Object data, ImageView imageView, ProgressBar progressBar, TextView textView) { if (data == null) { imageView.setImageBitmap(mLoadingBitmap); return; } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); if (progressBar != null) { progressBar.setVisibility(View.GONE); } } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView, progressBar, textView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); try { task.execute(data); } catch (Exception ex) { Log.e(TAG, "Exception while processing images: " + ex.getMessage()); } } }
mImageCache.addBitmapToCache(dataString, bitmap);
/** * Creating a new ImageCache object using the specified parameters. * * @param memCacheSizePercent The cache size as a percent of available app memory. */ private ImageCache(float memCacheSizePercent) { init(memCacheSizePercent); }
/** * Measure item size in kilobytes rather than units which is more practical * for a bitmap cache */ @Override protected int sizeOf(String key, Bitmap bitmap) { final int bitmapSize = getBitmapSize(bitmap) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } };
if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) { galleryImageView.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString())); } else { imageCache.addBitmapToCache(message.getKeyString(), fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0))); galleryImageView.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) { galleryImageView.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString())); } else { imageCache.addBitmapToCache(message.getKeyString(), fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0))); galleryImageView.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
this.conversationService = new MobiComConversationService(context); this.contactService = new AppContactService(context); this.imageCache = ImageCache.getInstance(((FragmentActivity) context).getSupportFragmentManager(), 0.1f); this.messageList = messageList; geoApiKey = Utils.getMetaDataValue(context.getApplicationContext(), ConversationActivity.GOOGLE_API_KEY_META_DATA);
myHolder.imageViewRLayout.setVisibility(View.VISIBLE); if (msg.getFilePaths() != null && msg.getFilePaths().size() > 0) { if (imageCache.getBitmapFromMemCache(msg.getKeyString()) != null) { myHolder.imageViewPhoto.setImageBitmap(imageCache.getBitmapFromMemCache(msg.getKeyString())); } else { imageCache.addBitmapToCache(message.getKeyString(), fileClientService.createAndSaveVideoThumbnail(msg.getFilePaths().get(0))); myHolder.imageViewPhoto.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(msg.getFilePaths().get(0))); myHolder.attachmentDownloadProgressLayout.setVisibility(View.GONE); myHolder.attachedFile.setVisibility(View.GONE); if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) { myHolder.preview.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString())); } else { imageCache.addBitmapToCache(message.getKeyString(), fileClientService.createAndSaveVideoThumbnail(filePath)); myHolder.preview.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(filePath));
imageCache = ImageCache.getInstance((getActivity()).getSupportFragmentManager(), 0.1f); imageThumbnailLoader.setImageFadeIn(false); imageThumbnailLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);