TouchImageView & Volley NetworkImageView working together - android

I'm Using a ViewPager in my project and so far i found Volley to be very good at loading in the images for the individual pages.
Volley needs com.android.volley.toolbox.NetworkImageView and TouchImageView needs com.android.touch.TouchImageView for ImageView in the xml
My question is how i do combine both of these
I cant get the zoom to work when using Volley
Or i can get the zoom to work by loading in standard bitmaps but swapping pages is slow with that and i'm not that experienced with Bitmaps cashing etc hence why i need volley for the easy of use.
Is there a way to get both of these to work together.
My Pager code
Thanks
UPD
I noticed in touch view class public class TouchImageView extends ImageView {
I wonder if changing to public class TouchImageView extends NetworkImageView { would make it work.
but i moved on since i asked the Q and now use uni image loaded instead. Just out of interest Ill give this a go at some stage and report back. It may be that simple

Well if you are sure the issue is with this line:
Bitmap bitmap = BitmapFactory.decodeByteArray(entry.data, 0, entry.data.length);
then you can run this in an AsyncTask and that'll be better I think.
But I suggest you using Picasso library for image loading, because there are many articles out there that say Picasso is faster in image loading and handles all the hard work itself (caching and...).
Then you can use TouchImageView with Picasso.load(urlString).into(touchImageView);

Related

Android library to load multiple image from server, pan, zoom and rotate

In my project, there is a activity where I need to load 2/3 images from server in a image view. Then need to do the below operation with them:
Paging, zooming and rotation by touch gesture.
I have searched a lot but could not manage to find any suitable library for those options.
I tried to achieve it by combining libraries( Picasso +others) but could not manage.
Please guide my to achieve this.
Any sample code, library reference or tutorial will be better.
TouchImageView
which helps to zoom the image
I really like Volley for working with image downloads. It offers a class called "NetworkImageView" which allows you to give it a URL and it loads the image directly, and even scales it down if needed.
As for your zoom & rotation gestures, have a look at uk.co.senab.PhotoView - it's a class which extends ImageView (you can change it to extend NetworkImageView), and allows touch interactions such as zoom. I'm not sure if it supports rotation, but I'm sure that once you get familiar with it, you can add this functionality.
Volley: https://github.com/mcxiaoke/android-volley
PhotoView: https://github.com/chrisbanes/PhotoView

Which approach to use to download many images asynchronously

I've a ListView in which each row item contains many ImageViews apart from some content.
That is, there will be many list items, each containing many images.
In order to not to hold user unnecessarily, I'm showing the content first & then downloading the images asynchronously.
Currently, for each image I'm starting a new AsycTask.
Although, it working alright, but this not a good approach.
In place of this, what should I use?
use this library, best in android for image loading..
https://github.com/nostra13/Android-Universal-Image-Loader
Your scenario seems to fit exactly to use LazyLoading of images. This basically loads images in the background and shows them as soon as they're loaded.
You might want to see this:
Lazy load of images in ListView
An alternative would be using a ThreadPoolExecutor with the images to load, but the above works pretty well and is recommended.
Try using the library
http://square.github.io/picasso/
Many common pitfalls of image loading on Android are handled automatically by Picasso:
Handling ImageView recycling and download cancelation in an adapter.
Complex image transformations with minimal memory use.
Automatic memory and disk caching.

android Bitmap caching for ViewPager issue

I have a ViewPager with ImageView as child views. The ImageView displays Bitmap loaded from network and/or cached to local cache implemented as LruCache based class (from Android support library). The problem is that when the images are removed from LruCache, the GC seems to not release or release too late the bitmap memory. I very often get the exception OutOfMemory while loading new bitmap from network/disk even if the old bitmaps are removed from LruCache and from the holding ImageViews of ViewPager (I removed views from ViewPager). I read that sometimes (?) you must call the Bitmap.recycle (prior to Android 3.0) but this does not work. It also does not work on ICS (I do not call Bitmap.recycle there).
How to solve this problem?
The garbage collector won't recycle your bitmap if something is still referencing it. I would imagine that you have ImageViews hanging onto your bitmaps. ViewPager doesn't recycle Views so you'll need to clear out your ImageView when it's not being shown.
You can check out the BitmapFun sample from android developers site on how to display Bitmaps efficiently. The sample has a GridView and ViewPager of images already that you can refer to in building your app. Though the sample has some caching issue which I did some work around already. You can check it out here.
The problem isn't handling many images, it's that your images aren't getting deallocated when your activity is destroyed.
It's difficult to say why this is without looking at your code. However, this article has some tips that might help:
http://blog.booking.com/android-reuse-bitmaps.html

Android ListView with lots of same drawables performance

I'm developing an Android app with a list view that contains lots of drawables.
Most of them are the same so I'm trying to use a HashMap that returns the same allocated bitmap when it's needed but still there are lots of allocations and GC actions so that the list gets stuck from time to time when scrolling.
What can I do to optimize the performance in such case?
Caching method - loadImage Using google code
mImageWorker.loadImage(pic_url, holder.pic);
holder.*some bitmap*.setImageBitmap(Utility.getBitmap(context, id); //can be one of 5 bitmaps do I use caching with a hashMap
see this example
this will helps you....
don't put so much process under the getView() method . this will lack the listview scroll performance
if you want to do image crapping or drawable to bitmap conversition or anything .. just do all process
before loading adapter.. and just assign values for each row in getView()...
Try to use lazy loading technique using caching, you can find many tutorial on the web:
You have to see this SO thread
Also see this:
Multithreading For Performance, a tutorial by Gilles Debunne.
This is from the Android Developers Blog. The suggested code uses:
AsyncTasks.
A hard, limited size, FIFO cache.
A soft, easily garbage collected cache.
A placeholder Drawable while you download.
If you want to optimize the code, try lazy loading concept for loading images in list. Please refer: Lazy Load images on Listview in android(Beginner Level)?

Asynctask in listactivity

I have a listactivity and each row has a different image that i load from the web and some text.
I'd like to implement asynctask so the images would load on the background.
I've searched many tutorials but haven't found none that use different images per row. The problem is the method doInBackground that is supposed to load the images from the internet. But since they are all different and they depend on its row, how can the thread load them?
Global variables: Bitmap bm; BitmapFactory.Options bmOptions;
In my getView method, I have
ImageView img = (ImageView) v.findViewById(R.id.icon);
if (img!=null){
bm = LoadImage(o.getLink(), bmOptions);
img.setImageBitmap(bm);
}
along with the text load... this img should be load on the doInBackground method, but then I'd have no access to the o (of type User) object that I know because getView gives me the position.
Does anyone have any idea on how to solve this problem?
Thanks,
Rita
There are two ways you can do this: the easy way or the boring way.
If you can add extra dependencies, then I would strongly recommend you take the easy route and use GreedDroid. You can use the item framework they have in there or use the AsyncImageView. Personally I'd use the latter.
The boring way, on the other hand, would be to break out the HttpClient and download the image manually, then use BitmapFactory.decodeStream method to create a Bitmap.
The downloading needs to happen away from the UI thread, so it may feel natural to use an AsyncTask to run it all, and the use a Handler to actually poke the Bitmap into the ImageView (being careful not to set the Bitmap on a view which has already been recycled).
Unfortunately, on many implementations, the ExecutorService that runs the AsyncTasks are limited to using one Thread. This gives an unfortunate feel to the List where the images load one by one, instead of the as-many-as-possible-all-at-once feel to it you may be expecting.
In that case, you'll probably be wanting to (essentially) roll your own AsyncTask.
I'm not a massive fan of AsyncTasks, as you can tell.
The above is such a common task, and such an annoying thing to get right, I'd very much recommend using someone else's library.
I believe you will need to write your own List Adapter so that as more and more list items are displayed (by scrolling down for example), the adapter creates more AsyncTasks and displays the images once they have been fetched.
http://developer.android.com/reference/android/widget/ListAdapter.html
This is where images will be downloaded using async task just have look
http://developer.android.com/resources/articles/painless-threading.html

Categories

Resources