Welcome back.
Now there's one thing that I would like to add to our application, and that is while we're saving some
thing, this can take a while, even though in our case it's super fast, but this could take a while.
And when things can take a while, we want to let the user know that there is something happening.
And by just using a progress dialogue, we are golden.
OK, so let's go ahead and create the right methods for that.
And you have seen those methods in a demo before where I just created the show progress dialogue method.
So let me just create them in the main activity real quick.
So first of all, I'm going to create this method that is used to display a progress dialogue.
So we need to have a custom progress dialogue variable at the very top.
Let's create that first and then look at the method.
So let me jump to the top, and here I'm going to create a for custom progress dialogue, which will
be of type dialogue, Nullarbor, and I'm going to assign them to it.
OK, so now we can use this custom progress dialogue, and I'm going to create a method that will now
initialized this progress dialogue.
And then it will set its content view to be a layout that we need to set up.
And we saw this layout in a demo before as well.
So let me just paste it in here and show you what I mean.
So let's go ahead and create a new layout file.
I'm going to call this one dialogue underscore custom underscore progress.
OK, so what I wanted to have in here and let me just paste it in, it will be very simple, is basically
going to be.
Well, first of all, when using a linear layout gravitated towards the center.
The items are put next to each other.
We have a little bit of padding and then I'm using a progress bar, which is this thing here.
So this turning circle?
And I'm giving it a certain width and height, as well as a little margin towards the right.
And then we have this text you would just says, please wait.
And the text is in black and text size is 16, and it just is as large as the content requires silver
content and width and height.
OK, so now we can use this dialogue, custom progress, and then we need to show this custom progress
dialog accordingly.
So once we have set the content viewed to be this XML file, we are displaying the progress dialogue.
If you are displaying a progress dialogue, you also need to make sure that you are high while you have
a way to hide it, because otherwise it will just be there and will be in the way so your needs to create
a method that will cancel the progress dialogue.
OK, so let's go ahead and do that.
I'm going to create a private fun cancel progress dialogue here, which will simply check if the custom
progress dialog exists or is not now and if it's not now then used at Custom Progress dialog and dismiss
it.
And also make sure that the custom progress dialog is going to be null the next time, so set it to
null as well.
So what would be good spots to call these methods?
Well, on one hand, once we click on our save button, for example, it would be good to show the progress
dialog.
So that would be in the create method here.
Once we click on the image button.
And I'd say I'm going to show a director here before I launch my call routine.
So show progress dialogue.
That's a good spot.
And what would be a good spot to hide the progress dialogue?
Well, I'd say once the.
Saving is done.
So which means wants to save bitmap, file code is done.
And the best part would be, of course, once we do the run on UI thread code.
So here, let's cancel the progress dialog at this point.
OK, because this is a UI task, you don't want to run it in on the back ground thread.
OK, so let's test this.
Let's see if it's going to appear, even if it's just for a brief moment.
All right.
So there we are.
Let me draw something.
Save it, you see, it showed up really quickly and then.
It was safe to come.
So that's pretty much it for this video and the next one, you're going to learn how to share the image
with your friends by email, for example.
So see you there.