1
00:00:01,070 --> 00:00:01,730
Welcome back.

2
00:00:02,420 --> 00:00:07,460
Now there's one thing that I would like to add to our application, and that is while we're saving some

3
00:00:07,460 --> 00:00:13,190
thing, this can take a while, even though in our case it's super fast, but this could take a while.

4
00:00:13,190 --> 00:00:18,500
And when things can take a while, we want to let the user know that there is something happening.

5
00:00:18,770 --> 00:00:23,930
And by just using a progress dialogue, we are golden.

6
00:00:24,440 --> 00:00:28,370
OK, so let's go ahead and create the right methods for that.

7
00:00:28,610 --> 00:00:36,320
And you have seen those methods in a demo before where I just created the show progress dialogue method.

8
00:00:36,680 --> 00:00:41,060
So let me just create them in the main activity real quick.

9
00:00:41,150 --> 00:00:46,910
So first of all, I'm going to create this method that is used to display a progress dialogue.

10
00:00:47,420 --> 00:00:51,320
So we need to have a custom progress dialogue variable at the very top.

11
00:00:51,320 --> 00:00:53,240
Let's create that first and then look at the method.

12
00:00:53,870 --> 00:01:03,290
So let me jump to the top, and here I'm going to create a for custom progress dialogue, which will

13
00:01:03,290 --> 00:01:07,790
be of type dialogue, Nullarbor, and I'm going to assign them to it.

14
00:01:08,510 --> 00:01:16,100
OK, so now we can use this custom progress dialogue, and I'm going to create a method that will now

15
00:01:16,430 --> 00:01:18,350
initialized this progress dialogue.

16
00:01:18,680 --> 00:01:24,550
And then it will set its content view to be a layout that we need to set up.

17
00:01:24,950 --> 00:01:27,920
And we saw this layout in a demo before as well.

18
00:01:28,130 --> 00:01:31,820
So let me just paste it in here and show you what I mean.

19
00:01:34,410 --> 00:01:38,250
So let's go ahead and create a new layout file.

20
00:01:38,520 --> 00:01:44,730
I'm going to call this one dialogue underscore custom underscore progress.

21
00:01:46,840 --> 00:01:52,690
OK, so what I wanted to have in here and let me just paste it in, it will be very simple, is basically

22
00:01:52,690 --> 00:01:53,500
going to be.

23
00:01:54,130 --> 00:01:58,180
Well, first of all, when using a linear layout gravitated towards the center.

24
00:01:58,600 --> 00:02:00,940
The items are put next to each other.

25
00:02:00,950 --> 00:02:06,190
We have a little bit of padding and then I'm using a progress bar, which is this thing here.

26
00:02:06,430 --> 00:02:09,729
So this turning circle?

27
00:02:10,690 --> 00:02:14,950
And I'm giving it a certain width and height, as well as a little margin towards the right.

28
00:02:15,490 --> 00:02:18,160
And then we have this text you would just says, please wait.

29
00:02:18,280 --> 00:02:24,850
And the text is in black and text size is 16, and it just is as large as the content requires silver

30
00:02:24,970 --> 00:02:26,050
content and width and height.

31
00:02:26,740 --> 00:02:32,920
OK, so now we can use this dialogue, custom progress, and then we need to show this custom progress

32
00:02:32,920 --> 00:02:34,170
dialog accordingly.

33
00:02:34,180 --> 00:02:40,360
So once we have set the content viewed to be this XML file, we are displaying the progress dialogue.

34
00:02:40,720 --> 00:02:47,470
If you are displaying a progress dialogue, you also need to make sure that you are high while you have

35
00:02:47,470 --> 00:02:53,740
a way to hide it, because otherwise it will just be there and will be in the way so your needs to create

36
00:02:53,740 --> 00:02:56,890
a method that will cancel the progress dialogue.

37
00:02:57,460 --> 00:02:59,050
OK, so let's go ahead and do that.

38
00:02:59,290 --> 00:03:09,220
I'm going to create a private fun cancel progress dialogue here, which will simply check if the custom

39
00:03:09,220 --> 00:03:16,990
progress dialog exists or is not now and if it's not now then used at Custom Progress dialog and dismiss

40
00:03:16,990 --> 00:03:17,170
it.

41
00:03:17,740 --> 00:03:23,050
And also make sure that the custom progress dialog is going to be null the next time, so set it to

42
00:03:23,050 --> 00:03:23,830
null as well.

43
00:03:24,550 --> 00:03:27,370
So what would be good spots to call these methods?

44
00:03:27,970 --> 00:03:35,920
Well, on one hand, once we click on our save button, for example, it would be good to show the progress

45
00:03:35,920 --> 00:03:36,520
dialog.

46
00:03:36,850 --> 00:03:39,550
So that would be in the create method here.

47
00:03:39,970 --> 00:03:41,830
Once we click on the image button.

48
00:03:44,460 --> 00:03:48,990
And I'd say I'm going to show a director here before I launch my call routine.

49
00:03:49,890 --> 00:03:53,040
So show progress dialogue.

50
00:03:53,430 --> 00:03:54,240
That's a good spot.

51
00:03:54,570 --> 00:03:57,600
And what would be a good spot to hide the progress dialogue?

52
00:04:00,090 --> 00:04:02,400
Well, I'd say once the.

53
00:04:04,160 --> 00:04:05,370
Saving is done.

54
00:04:05,390 --> 00:04:09,620
So which means wants to save bitmap, file code is done.

55
00:04:12,000 --> 00:04:18,300
And the best part would be, of course, once we do the run on UI thread code.

56
00:04:18,540 --> 00:04:21,870
So here, let's cancel the progress dialog at this point.

57
00:04:23,070 --> 00:04:29,460
OK, because this is a UI task, you don't want to run it in on the back ground thread.

58
00:04:30,330 --> 00:04:32,790
OK, so let's test this.

59
00:04:33,330 --> 00:04:36,660
Let's see if it's going to appear, even if it's just for a brief moment.

60
00:04:39,130 --> 00:04:39,610
All right.

61
00:04:39,820 --> 00:04:40,660
So there we are.

62
00:04:40,690 --> 00:04:41,810
Let me draw something.

63
00:04:41,830 --> 00:04:45,520
Save it, you see, it showed up really quickly and then.

64
00:04:46,860 --> 00:04:48,510
It was safe to come.

65
00:04:48,810 --> 00:04:53,430
So that's pretty much it for this video and the next one, you're going to learn how to share the image

66
00:04:53,670 --> 00:04:55,440
with your friends by email, for example.

67
00:04:55,660 --> 00:04:56,610
So see you there.

