Using volley to populate a fragment - android

I am working on a simple app and I am having issues understanding how to use volley for something I feel should be an easy task. Currently I have gotten volley to grab a json array that populates a list of images with titles next to them. The problem is I want to be able to press on an item in the list and spawn a new fragment with a larger version of the image in it. This seems like a really basic task, but I can't seem to find the right way to do it. If I grab the full images to create the list view, I run out of memory. I started grabbing thumbnail images, but then when I create the fragment, the view is inflated before the request for the image finishes. What is the right way to do this?

You can specify a placeholder image while Volley downloads your image, and an error image if the download wasn’t successful. In your situation, you can use your thumbnail image as the placeholder image.
The Making Image Request section in this artcle shows the good way to handle image request with Volley.
Sample code:
// Loading image with placeholder and error image
imageLoader.get(Const.URL_IMAGE, ImageLoader.getImageListener(
imageView, YOUR_THUNMBNAIL_IMAGE, R.drawable.ico_error));

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);

Load image from url to Recyclerview

I have an app that loads content from a database as well as images from the internet. I am using a RecyclerView along with CardView to display my content in a list form.
Each row has an image on the left side and text on the right.
The problem is that the text loads fast but the image takes time to load, so I want the image to continue loading in the background and then load into the ImageView object once loading is complete. I have no idea how to tackle this.
I use Picasso for this situation, but u can also use Glide and many more libraries. The documentation is pretty simple.
Try Picasso:http://square.github.io/picasso/
It's a one liner in onBindViewholder():
Picasso.with(context).load(url).into(viewHolder.imageView);

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.

Asynchronous bitmap buffering with GridView in Android

I am bulding up a grid of images for an app I'm building. It works like so:
Build up a list of Image IDs, which I must query using a different content provider each (these are images from MMS threads)
Create new activity, which hosts an ImageGridFragment. This fragment has a custom adapter that takes the grid of images, and loads each one as a bitmap asynchronously.
After images are loaded, they are cached in an LRU cache so I don't need to run unnecessary computation
So far, everything works quite well. However, I would like to pre-buffer images so that when the user scrolls down, s/he doesn't have to wait for images to load. They should already be loaded. The stock Android Gallery accomplishes. I've had a look at the source, but think there must be a more straightforward way.
To answer members' questions
Images are loaded one by one using the content://mms/part/xxx, where xxx is the ID of an image. These are MMS images, and to my knowledge, cannot be loaded as a batch process (though, maybe I'm wrong). I use a content provider in an AsyncTask to load each image
I've tried the following:
Pre buffer 30 images or so right when the fragment is created. This is not ideal because the massive I/O request, actually prevents the on-screen images from loading quickly (but the buffering does work well!)
Detect when the requested view to load is at the very bottom-right hand corner of the screen, which could work, but then would fail in the case that the GridView takes up only part of the screen. It also seems like there should be a cleaner way to do this
Thought about, but did not try, an OnScrollListener, but this will not pre-buffer images until I start scrolling, which is not ideal
So, my questions are:
Is there a good way to detect when the last GridView item is requested to load? I found that the GridView.getlastvisibleposition() method is not useful here, because it is actually returning the last element for which Adapter.getView() has been called for. If I can do this accurately, I can launch the buffer request at that time
Is there a better way to do this?
you can do right this
if(GridView.getlastvisibleposition() = mAdapter.count()-1)
how you load the images?
is it from URL or from sdcard?
are you using a image loader library?

Categories

Resources