Practical usage of ContentLoadingProgressBar - android

I was going through developer site of android and I found a class named ContentLoadingProgressBar. By seeing this class I come up with some questions in my mind. It would be great if someone answers my questions.
What is the difference between Normal ProgressBar and ContentLoadingProgressbar?
What is the practical usage of ContentLoadingProgressBar?
Can we show/hide this progressbar according to our requirement?
How can I custom style this progressBar?
Thanks for your help in Advance. It would be great if someone explain it using codes and examples. Thank you.

Here are my answers!
What is the difference between Normal ProgressBar and
ContentLoadingProgressbar?
ContentLoadingProgressbar waits a minimum time to be dismissed before showing using hide() like with-in 0.5 seconds.So even the show() gets called this can be dismissed before it appear on the screen.
What is the practical usage of ContentLoadingProgressBar
It prevents very fast flickering stuff that you might see with "naive" implementations.
Can we show/hide this progressbar according to our requirement
Yes
How can I custom style this progressBar
<android.support.v4.widget.ContentLoadingProgressBar
android:id="#+id/address_looking_up"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="visible" />
replace style with android:theme https://stackoverflow.com/a/38282149/5188159

Let's say you want to show a ProgressBar for some background operation that may take less than 500ms or more than 5 seconds.
You call progressBar.show() Then you start your background operation.
If your background operation is over within 500ms. Then you call progressBar.hide()
Now the user will see a flicker of the progress bar appearing and disappearing within a fraction of a second.
Introducing ContentLoadingProgressBar:
When you use this progressbar, then it will wait for a minimum time before showing the progress dialog. Which means if the time between show() call and hide() call is less than that minimum time, then there won't be any dialog to be shown to the user.

According to the docs:
ContentLoadingProgressBar implements a ProgressBar that waits a minimum time to be dismissed before showing. Once visible, the progress bar will be visible for a minimum amount of time to avoid "flashes" in the UI when an event could take a largely variable time to complete (from none, to a user perceivable amount)
This clearly mentions it's no different from a regular ProgressBar . Furthermore, this is a UI tweak to be precise, i.e. ContentLoadingProgressBar wouldn't show up if hide() is called in less than 0.5s after executing show(), thus preventing from quick flickering in the UI.

One note of using ContentLoadingProgressBar for recyclerview items. I have a scenario in which an arbitrary RV item can download something on clicked and shows indeterminate progress until completion. It appears to be impossible to use the benefits of CLPB in such case because of maintaining internal delays in CLPB when show()/hide() it: reused views may have inconsisted progress state (progress disappears or become infinite depending on reused holder view state). Thus i was forced to return to old good setVisibility:
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position)
...
if (item.isLoading()) {
//holder.progressBar.show();
holder.progressBar.setVisibility(View.VISIBLE);
} else {
//holder.progressBar.hide();
holder.progressBar.setVisibility(View.INVISIBLE);
}

Related

Show preloader before activity loaded [duplicate]

This question already has an answer here:
How can I display a Progress at start up application in android
(1 answer)
Closed 5 years ago.
I have a heavy user interface that can delay the application load. I want to show an preloader before the UI of activity loaded. note that my ui is in xml file
EDIT:
If you want to load 10 tabs in a view pager, use a FragmentStatePagerAdapter which only loads neighboring tabs(default behavior).
If the heavy UI you specify is only the UI elements, then the app must freeze while loading it. So you'd better show a non-cancelable dialog(without animation) with loading message and after a few moment (like 200ms) load up your UI and explicitly dismiss the dialog.
But if the heavy stuffs is not just UI, maybe some calculations or image processing, just do it in a background thread while showing a dialog with progress and cancel the dialog when the task is done.
#Hassan according to me if on clicking the launcher icon if it takes sometime for your application to render the first screen(perhaps giving a black screen in between). This needs to be corrected in your application.
On the contrary if your applications main screen requires population/retrieval of certain resources for effectively engaging the users, You can possibly do something like a splash screen(outdated) where you do all "population/retrieval" and then simply pass data to your heavy UI.
Now regarding the progress bar if this fetching of data is small, you can give an indeterminate "custom"(some moving animation that would suite your app) progress bar,else if its something like a download you can easily track its progress and show in a horizontal progressbar
You sure can! You are describing a preloader. Here is a nice example of one https://github.com/rtheunissen/md-preloader
You'll have to add more info to your question to get a specific answer, but there are a few basic principles.
You make your life a lot easier if you use a preloader which doesn't show progress of the load, it just goes round and round, because the speed of some load processes can't be measured.
If its a data-load which is taking the time (such as a call to an API), you might want to set a variable for "loading" to true at the top of your script, then when the data has resolved, set it to "false". In your view, have a state or a conditional element which hides / unhides the preloader.
If lots of images are slowing down the page, you might want to look into "lazy-loading" or using "infinite scroll" to only show content when the UI needs to display it on screen.
Thats all the info I can give without more information on the code you have so far. Hope that helps!

Android ProgressBar animation

This seems like it should be a simple question, but for some reason I haven't come up with an obvious answer yet:
I have a horizontal progress bar displayed by my app while it does some work in the background. There are a finite amount of steps in this process, so I display actual progress rather than using an indeterminate progress bar.
However, there are occasionally steps in this process that take a very long time, so the progress bar is stationary for a while.
I could update the progress at a finer resolution, but I'd rather have the progress bar "pulse" or show some other constant animation just so that the user can see it is still working. I assumed Android would have this built in without me having to do much work, since it's such a common UI feature, but I can only seem to get this to work if I use an indeterminate progress bar.
Is there an easy way to do this, or do I have to write some kind of custom animation?

What is the difference between Progressbar and progressDialog?

I have searched everywhere and read the official doc of Google. But I still don't see the difference between them.
When should we use ProgressBar and when should we use ProgressDialog?
ProgressBar:
ProgressDialog:
The ProgressBar is a View, ProgressDialog is a Dialog.
While the answers here are informative, none really address the question.
Use a ProgressDialog when you want to prevent the user from
interacting with the application while waiting. The Dialog aspect
freezes the user from doing anything until it is dismissed. Note how the UI behind the ProgressDialog is grayed-out and inaccessible.
Use a ProgressBar to indicate that something in your app is still
waiting (loading, thinking, etc.) while the user may still interact with
other parts. In this image, the user can still fill out forms while waiting for the gps to respond.
(Thanks to Johnny S for the image of the ProgressDialog.)
ProgressBar is a View (like TextView, ImageView, Button, etc..), which can be used in your layout to show some progress.
ProgressDialog is a Dialog with 'built-in' ProgressBar. Dialogs can be used to make user wait while something is being computed. ProgressDialog makes it easier to show progress of your computation in dialog.
In addition to the differences pointed out in the rest of answers, you should take into account the following recommendation from Dialogs # Android Developer:
Avoid ProgressDialog
Android includes another dialog class called ProgressDialog that shows
a dialog with a progress bar. However, if you need to indicate loading
or indeterminate progress, you should instead follow the design
guidelines for Progress & Activity and use a ProgressBar in your
layout.
It may be also usefull to consider the following answers:
https://stackoverflow.com/a/12559601/2482894
How to avoid ProgressDialog in Android
When your iterations is countable (doing operations in loop, executing code x times etc.) use ProgressBar, if task is not countable status (like invoking web service) use ProgressDialog
From the android documentation
ProgressBar:Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has
progressed; the application can change the amount of progress
(modifying the length of the bar) as it moves forward. There is also a
secondary progress displayable on a progress bar which is useful for
displaying intermediate progress, such as the buffer level during a
streaming playback progress bar.
ProgressDialog:A dialog showing a progress indicator and an optional
text message or view. Only a text message or a view can be used at the
same time.

setVisibility with sleep

I have this code:
result.setVisibility(0);
//a lot of code
//OnClick......
result.setVisibility(8);
SystemClock.sleep(500);
result.setVisibility(0);
So when i click a button the textView disappears and reappears to show that the result is changed.
But instead the textView "result" don't disappear and remains always visible. Why ?
I am not sure if the setVisibility function is at fault here. It appears that you are trying to sleep inside the UI code which happens to be a very commonplace mistake.
I am not sure but this willl help you.
Also I would recommend the usage of the pre defined constants VISIBLE , INVISIBLE and GONE instead of the integers.
Good Luck
Because you tell the thread that need to update the ui to go to sleep...
You should use animations for this stuff.

What does the 'indeterminate' mean in ProgressDialog?

Maybe my English is poor but I really cannot figure out what the "indeterminate" means in this context:
Android Development → ProgressDialog.isIndeterminate()
It means the "loading amount" is not measured.
From wiktionary:
Indeterminate: Not accurately determined or determinable.
It basically just means you're unsure how long the action will take so you cannot say for example something is 50% done.
This normally just means the progress will be displayed as a constantly moving loading bar rather than a percentage or the like.
Basically when setProgressStyle(ProgressDialoge.STYLE_SPINNER) is taken then setIndeterminate() will be true because a circle(Spinner) will rotate, which shows that "do not know how much time it is going to take". When take ProgressStyle(ProgressDialoge.STYLE_HORIZANTAL) we will take setIndeterminate() as false since it take a value/percentage bar like how much percentage it was completed with setProgress(value).
In simple language we can say when the amount is not determined means we don't know how much it gonna be to be completed or loaded fully..!!
Change the indeterminate mode for this ProgressDialog. In
indeterminate mode, the progress is ignored and the dialog shows an
infinite animation instead.
Note: A ProgressDialog with style STYLE_SPINNER is always
indeterminate and will ignore this setting.
Blockquote
For illustration, the progress animation keep loading from left to right and then repeat automatically without user interaction(which setProgress) when indeterminate set to true.
Reference here.

Categories

Resources