Android using Nostra 13 Universal Image Loader to replicate behavior as
that of Google Play Store app's loading image
I just started using this awesome Nostra 13 Universal Image Loader and I
have implemented it on my ListView. While scrolling up and down the
ListView,I notice very very small time to load already cached images.(FIY
this time is very very very small,but still visible)
When I use Google Play App,it also has loading views while loading images
and when image load is complete and as I scroll up and down, I don't see
any more loading images(not even for a small time). Further I am not
implying that Google Play App is using Nostra 13 Universal Image Loader.I
am interested on how to achieve this behavior using Universal Image Loader
Library
So my question is how to achieve that using UIL. Meaning once the image
has been downloaded and cached,what should I do properly to configure UIL
to show cached images without any loading screen. Once I scroll down and
up( after image has been dowloaded), the image be properly loaded without
any loading screen. So far following are my configuration
//On Application File
public static DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true).cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.showImageOnLoading(null)
.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
.resetViewBeforeLoading(true)
.build();
public static void initImageLoader(Context context) {
ImageLoaderConfiguration config = new
ImageLoaderConfiguration.Builder(
context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.threadPoolSize(5)
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.memoryCacheSize(2 * 1024 * 1024)
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.taskExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
.discCache(
new UnlimitedDiscCache(StorageUtils
.getCacheDirectory(context)))
.discCacheSize(50 * 1024 * 1024).discCacheSize(200)
.tasksProcessingOrder(QueueProcessingType.LIFO)
.build();
ImageLoader.getInstance().init(config);
}
And on Adapter class
ImageLoader imageLoader =imageLoader.getInstance();
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
if (convertView == null) {
holder = new Holder();
//normal inflating and stuff
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
imageLoader.displayImage(imageUrl,
holder.productImageView, MainApplication.options,
animateFirstListener);
imageLoader.displayImage(imageUrl1, holder.userImageView,
MainApplication.options, animateFirstListener);
return convertView;
}
private static class AnimateFirstDisplayListener extends
SimpleImageLoadingListener {
static final List<String> displayedImages = Collections
.synchronizedList(new LinkedList<String>());
@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
I have also tried this way on Adapter class
//On Adapter Class
Bitmap bitmap = imageLoader.getMemoryCache().get("imageUrl");
if (bitmap != null
|| imageLoader.getDiscCache().get("imageUrl").exists()) {
if (bitmap == null)
bitmap = BitmapFactory.decodeFile(imageLoader.getDiscCache()
.get("imageUrl").getPath());
if (bitmap != null)
holder.productImageView.setImageBitmap(bitmap);
} else {
imageLoader.displayImage("imageUrl", holder.productImageView,
MainApplication.options, animateFirstListener);
}
Bitmap bitmap1 = imageLoader.getMemoryCache().get("imageUrl1");
if (bitmap1 != null
|| imageLoader.getDiscCache().get("imageUrl1").exists()) {
if (bitmap1 == null)
bitmap = BitmapFactory.decodeFile(imageLoader.getDiscCache()
.get("imageUrl1").getPath());
if (bitmap != null)
holder.userImageView.setImageBitmap(bitmap);
} else {
imageLoader.displayImage("imageUrl1", holder.userImageView,
MainApplication.options, animateFirstListener);
}
This will eventually get OutOfMemory Exception.So is there any way I can
achieve the image loading mechanism as found on Google Play App. Any
direction would be great.Thanks
No comments:
Post a Comment