download images using URL and then show them using custom PagerAdapter - android

I'd like to download a bunch of images from web and then show them using my custom PagerAdapter. So I can slide to browse all of these images. Please see the following figure:
HttpURLConnection is used to download the image in background and BitmapFactory is used to produce the bitmap.
There is one problem for this app. It's not fluid when sliding to the next image. There is an obvious pause when showing the next image. How to solve this problem. Any suggestions?

If you dont load the image in the background, it will block the Main thread, so your app is not so fluid.
you can try the following open source project:
https://github.com/nostra13/Android-Universal-Image-Loader
https://github.com/lianghanzhen/ImageCacheAndLoader

Related

Android component that displays the thumbnail of its children before loading data

I am making a native android application and I would like to know if there is a particular component which allows to manage the display of the screen before and after loading the data as on the attached images.
Before loading data
After loading data
Your question is not very clear and specific, so I'll try to answer it more generally.
If you want to create a circular loading progress bar as the one shown in your screenshots you can either create/use a custom loader or you can try using something like this.
If you want to create a layout as the one shown and you are reffering to the image loading for what appear to be video thumbnails, then you can use an image loading library such as Picasso or Glide.
If you want to download some resources and you are referring to the networking aspect of this process you can use a networking library such as Retrofit or Volley.

Glide showing ImageView background in between loading images

I've got a simple use case. I have a local image uri (content://path) that I load into an ImageView - that's step 1. After a button is pressed, the image is replaced with an image from our server - that's step 2.
My code is quite simple - or at least, I can reproduce the issue even after I simplified the code to the following:
Glide.with(imageHolder.getContext()).load(url).into(imageHolder);
The first time, this is called with a local uri (content://path), followed by a remote url (http://path.com).
Loading the local uri works just fine. The problem is that, once I initiate the load from the server (which might take a second), Glide rolls back to the ImageView's background image colour. So visually I get old image -> background colour -> new image, which is quite annoying.
Is there some sort of a hidden way in Glide to work around this?
this is because while the server image is being loaded there is a gap between removing local image and showing the new one and that gap is your problem.
one of the workarounds to this issue is to give Glide a placeholder (set your local image as the placeholder) so while Glide is loading image from server it still shows the local image and once the server image is loaded the local one goes away.
Glide.with(imageHolder.getContext())
.placeholder(YOUR_LOCAL_IMAGE_HERE)
.load(url)
.into(imageHolder);

Picasso Square Next Image Cache

I'm using Picasso Square library in my android application. The app is a very simple one and shows a grid of pictures. When you touch one it opens it in full screen and when swiping to the right the next in line should be displayed.
My problem is that for every swipe, the image is loaded by picasso method:
Picasso.with(getApplicationContext()).load(Properties.IMAGE_URL + i).transform(transformation).centerCrop().fit().into(imageView);
I would like to avoid the load wait time and simply cache the next 2 images to be displayed. how would I go about doing this?
I know that picasso caches the images if they were loaded before. Is there a way to load the next image with picasso without attaching it to a specific ui element to be displayed?
There is a way to do it – use fetch(). You can get more information from this question.

Android Loading Indicator for Downloading Images

I am using an Image Loaded which loads images based on requirment and since the images are big. I want to display an intermediate Spinning Image showing which would convey that the image is loading to the User.
I am displaying these images in the Viewpager.
We can not use a Gif image to display the animation and i wonder how it can be done.
P.S i am not looking for a Progress Dialog.
You could try doing a View Animation on the ImageView. Rotate is one of the included animations, and you can define it in XML.
Here's a Youtube Video from Google explaining it a little more.

How display a loading image correctly on Android phone

I have been trying to use a .gif file from my resources, but I get no movement when it loads. I am using it as a loading image while I am doing an asynchronous task. I was previously using a progress dialog but now I would like to display the image myself and not use a dialog. How can I get this image to display correctly?
Try using AnimationDrawable:
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Basically, you should split each of the frames in your gif into separate files - such as .png file (say if it had transparency) and specify these files in the <animation-list> instead. You can also control the duration of each frame.
See the link for code example
If you are deadset on using a gif image you can just use a WebView instead of an ImageView. Then make an html doc that displays your gif image. When you show it in the WebView it will be animated for you.

Categories

Resources