-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to show the loading progress with the image #232
Comments
You know when you start the request ( You can set a If you need more granuality please explain why you want it and how would you use it. |
Because when loading large image more time-consuming, want to let the user know the loading schedule |
I had such a similar demand,to get the progress when loading the image,please help |
There isn't currently any API that would allow you to do this. You may be able to work around this by creating a custom ModelLoader/DataFetcher that would expose progress in some way. However, even if you do so, a not insignificant portion of a load is spent decoding, transforming, and encoding images in the framework, none of which include progress APIs. As a result even if you manage to pipe through progress for the download, you won't get a particularly accurate %. That said, you can use |
Holy high! |
@sjudd: How foes someone pass a ProgressBar to the placeholder() when it requires a Drawable? |
Good point :) I think he meant an (animated) indeterminate progress drawable like this: |
I think just a placeholder is not enough,cloud Glide will provide such API that can get the progress when load a large image? |
If i write a class named SimpleImageLoader which extends AsyncTask and use Java basic api to load large image, of course i can get progress by onProgressUpdate(). |
"of course i can get progress by onProgressUpdate()." No you cannot when you're decoding Bitmap from a Uri. Try doing it. |
@Saketme You can track the stream (if you acquire it first from Uri and wrap it correctly) and there's a good enough correlation of download progress and decode progress. Downloading (I/O) is the slowest, so tracking download tracks decoding. Also you can assume that by the time (or a few ms later) it is at the end of the stream the decode has finished and the bitmap is in the memory. @Folyd an AsyncTask doesn't have much benefits, you just need a way to post progress to the UI thread (e.g. Handler with Main Looper). Glide already has the API just not out of the box, see @sjudd's comment. The closest you can get is tracking the download by tracking/wrapping the stream and then staying at 100% or showing an indeterminate progress bar while Glide is finishing up (transforming/caching). @sjudd please comment on this: in my mind the same way one can write a DataFetcher they can write an encoder which tracks the caching progress wrapping a real encoding stream if it's really that significant that you state. The tranformation is harder because that calls into native Android if I remember correctly which can't report back, but if progress is really that important they can reimplement it with progress. Of course some/all of the above could be hardwired into Glide depending on how much it complicates the internals... that's what this enhancement is about. |
@TWiStErRob Ah I stand corrected then. Thank you :) |
@TWiStErRob You can definitely track download progress from http requests by comparing where you are in the InputStream to the content length. I don't believe you can do so for arbitrary InputStreams because the InputStream API does not expose the total size of the stream. As a result we could allow DataFetchers to return progress but we couldn't enforce that all implementations do so. Decoding, encoding, transforming, and transcoding all do not expose any way to obtain progress beyond setting some fixed % for each process. Encoding may take a substantial amount of time depending on the size of the image. I'll consider a way to pipe progress from DataFetcher's to some interface (maybe RequestListener), but since progress only makes sense for http, isn't entirely accurate, and would be reasonably complex to implement, this isn't hugely high up on my list. If anyone here thinks this is a high priority, I'd certainly welcome a pull request. All that said, you can definitely take our current ModelLoader APIs, implement, subclass, or fork a DataFetcher and expose progress right now without any changes in Glide. It's not trivial to do so, but it's certainly possible. |
If you are using OkHTTP with Glide, you may be able to use their Progress recipe to track your download progress: |
fbis251 could you please give me example how to do this ? I need to track progress while downloading image to file. Or maybe you know better solution ? |
Hey, sorry it took me a while to post this but here is an example on using an okhttp progress interceptor with Glide in Android: |
@TWiStErRob why @fbis251 solution work only if i didn`t use GlideModule? |
@futurobot Can't answer "it doesn't work" without having actual/expected behavior. I don't see any reason why I also answered your gist question, sorry being late, I don't get no notifications for gists :( |
@TWiStErRob i made little sample and it works fine with |
@futurobot |
@hejinxigege nope, i prefer OkHttp, but i think Volley requests is not much different. Volley requests |
+1. Currently just using a progress spinner that spins endlessly, would be nice to have an actual progress bar |
I was playing a little with this, here's a gist. |
@TWiStErRob wow that's fantastic! Thank you ^^ |
@TWiStErRob Thanks for the solution. But too much code. I just need to show a circular loading progress gif file |
@petrovichtim #958, #505 or just add a ProgressBar on top of your ImageView, set it visible right before the Glide load and hide in Glide listener callbacks. If you need further help, please open a new issue! |
@TWiStErRob That's not what I need. I need a real loading progress |
@petrovichtim I don't get it. There's no other known way of displaying progress: either use my approach to sync to progress or just an animated drawable that moves by itself. You said "I just need to show a circular loading progress gif file": by specification GIF animations are internally timed. This means you can't sync their frames with the downloaded byte count (progress). They would just play based on their internal frame delays. If you want to display the byte progress in any way (circular, horizontal, spiral, ...) you'll need to code I wrote in the gist. To only show the red circle, you still need most of the code, just remove the stuff you don't need from the layout and |
@TWiStErRob now I get error
|
@petrovichtim It says what the problem is, it needs |
@TWiStErRob Thanks, but I do not understand where I need to change constructor argumen. Can you write some code please? |
@TWiStErRob Thanks , I change my code to this |
|
@petrovichtim If you continue down this path you'll face hard problems. If it was easy it would probably already be part of Glide. |
@TWiStErRob I think you can first download the thumbnails and then start the main download. But it will be a complex code based on the events of the first download . |
Can I dismiss progress dialog when all the images that I request from the server is finished |
it can't be done on gilde listener? it should be good when it can be done on something like this
|
I wrote the simple tutorial to explain how to integrate YOUR loading progress view with Glide V4. |
@TWiStErRob is Glide v4 have support this feature? I don't want to add |
It's likely not the question of Glide supporting it, it's the question of Java's built-in |
anything else? |
Could tell me which api can get the progress when loading the image?thanks!
The text was updated successfully, but these errors were encountered: