Bye-Bye Progress Dialog, Hello Alert Dialog

We all see those beautiful looping circles or straight lines showing us the progress of a particular task while it is getting done in the background. Some of these are customized and contain beautiful texts.
Previously we had Progress Dialog class in android to create these progress indicators, but now when it is deprecated we have the beautiful alert dialogs. These are the popup windows in our apps used for accomplishing some other smaller task which does not require a separate activity or fragment. These tasks involve asking for permissions, confirming an action like logout or making transactions, etc.
The main focus of this article is to show how to create progress dialog using alert dialog, that’s why I will not cover the features of alert dialogs in detail. I will extend this blog to contain that afterward or will write a separate article for that.
Let’s create one😀
Step 1. Create a custom layout:
You can use any progress indicator or create on your own and design it accordingly. Here I am using the Progress bar provided by material design. So a sample custom progress layout looks like below:
I am using a text view to display a progress message like “please wait for its loading”, etc. If you want you can hide it using visibility property in step 3.
Also, note that the progress dialog used here is determinant which means it will not give real-time updates on progress like what we get when download something in terms of percentage. It will just keep rotating until it is dismissed.
Step 2. Create a generic alert dialog creator:
Here I am creating this generic creator so that you can use this to create different types of progress dialog for different locations or even other kinds of dialogs.
Here setCancellationOnTouchOutside is used for stopping users to interact with the screen while the alert dialog is there. We can enable and disable it. This method returns a dialog to which properties can be added like action buttons(will discuss in another blog). We will set the text for the loading text view and then will show the progress dialog.
Step 3. Create the Progress dialog:
Passing correct arguments to the above method, we can create the progress bar function and then can set the text.
This method returns the displayed progress dialog. You can use that to dismiss it on whatever condition you want by calling .dismiss() method on the returned dialog.
So this is all you can go and create your beautiful eye-catching progress dialog and make waiting for processes fun for your users.
I will try to add more features of alert dialogs to this blog or create a separate blog for alert dialogs specifically (will post the link here).
Feel free to comment if there are doubts or if you feel anything needs to be corrected😀.