1
00:00:01,020 --> 00:00:01,650
Welcome back.

2
00:00:01,800 --> 00:00:07,560
And this video, we're going to implement the under your button, so basically undo button here, you

3
00:00:07,560 --> 00:00:13,890
can see once you click on that, it will delete the last entry on our drawing board.

4
00:00:14,220 --> 00:00:16,020
And yeah, let's just implement it.

5
00:00:16,650 --> 00:00:18,720
Therefore, let's go over to our project.

6
00:00:18,720 --> 00:00:23,880
And the first thing that I'm going to do is I'm going to duplicate this image button here, and I'm

7
00:00:23,880 --> 00:00:27,570
going to call this one image button undo.

8
00:00:28,470 --> 00:00:35,420
And then according to I need to use another image or another trouble, and I have this trouble.

9
00:00:35,430 --> 00:00:37,170
You can just use any trouble you want.

10
00:00:37,530 --> 00:00:39,240
I will just use this icy undo.

11
00:00:39,270 --> 00:00:41,420
You can download the project and get it from there.

12
00:00:41,430 --> 00:00:46,530
So this will be the page that I'm going to use and I'm going to assign it to my image.

13
00:00:46,530 --> 00:00:51,150
But and so the idea is that it's going to look like this where we have the gallery here, the image

14
00:00:51,150 --> 00:00:55,170
button and then the brush size selector, so to speak.

15
00:00:55,680 --> 00:00:58,190
OK, now let's go ahead and use it.

16
00:00:58,200 --> 00:01:01,560
In order to use the button, we need to do the same thing the image button.

17
00:01:01,830 --> 00:01:04,370
We need to do the same thing as we did here with the image button.

18
00:01:04,379 --> 00:01:08,130
So let me just copy the I b brush.

19
00:01:08,130 --> 00:01:11,670
And accordingly, this will be I undo.

20
00:01:13,340 --> 00:01:23,750
Here on do like so fine view by ID and accordingly, we want to assign the on click event for it as

21
00:01:23,750 --> 00:01:24,050
well.

22
00:01:24,440 --> 00:01:31,400
So but I'm not going to call the show brush size chooser dialogue, but instead what I want to do is

23
00:01:31,400 --> 00:01:34,610
I want to call a method that will undo the drawing.

24
00:01:34,610 --> 00:01:38,460
And here, by the way, this is not ibey brush, but I be undue.

25
00:01:39,050 --> 00:01:42,380
So that was the idea of our image button, which is this button here?

26
00:01:43,160 --> 00:01:43,580
OK.

27
00:01:43,940 --> 00:01:49,320
So where could we do something that has to do with drawing well and our drawing view?

28
00:01:49,340 --> 00:01:52,040
That's where we created all of our paths, right?

29
00:01:52,340 --> 00:01:59,000
So there is this empaths variable that is an array list of custom paths and custom paths we saw.

30
00:01:59,000 --> 00:02:01,910
It's just our own class that we created here as well.

31
00:02:02,240 --> 00:02:08,960
And now we are going to require is basically going to be the same thing, but one for undue puffs.

32
00:02:09,199 --> 00:02:17,660
So an ArrayList, that will be a list of custom paths, but we'll just collect or store to undo paths.

33
00:02:18,320 --> 00:02:23,720
Now accordingly, we just need to create a method that will take care of the undoing.

34
00:02:24,170 --> 00:02:25,230
And how do we do that?

35
00:02:25,250 --> 00:02:30,470
Well, basically what we want to do is we want to delete an entry from empaths and we want to store

36
00:02:30,470 --> 00:02:31,670
it in undo, perhaps.

37
00:02:32,240 --> 00:02:34,220
OK, so let's create a method for that.

38
00:02:34,550 --> 00:02:37,130
So fun on click undo.

39
00:02:37,490 --> 00:02:43,310
So I'm going to call it, and I want to check first if there are any paths even to delete from.

40
00:02:43,400 --> 00:02:50,030
So only if there are paths, which means if the imperfect size is greater than zero, only then do I

41
00:02:50,030 --> 00:02:52,910
want to add something to my undo.

42
00:02:52,910 --> 00:02:53,330
Perhaps.

43
00:02:53,780 --> 00:02:55,670
And what is it that I want to add to it?

44
00:02:56,000 --> 00:03:01,910
Well, the path that I'm removing from my empaths, we can do it in one line where we say and perhaps

45
00:03:02,060 --> 00:03:06,140
remove that and then the index and what is the index that I want to use?

46
00:03:06,380 --> 00:03:09,020
Well, I basically want to delete the last entry.

47
00:03:09,320 --> 00:03:12,680
And how do we get the last entry of an array list?

48
00:03:13,370 --> 00:03:16,370
Well, by using the size of the array list minus one.

49
00:03:16,730 --> 00:03:19,490
So empaths that size minus one.

50
00:03:20,300 --> 00:03:26,600
Because what that remove add method does is it returns the item that it removes.

51
00:03:27,230 --> 00:03:33,950
OK, so we are basically receiving the item that it removes and we are adding it to our undo paths.

52
00:03:34,400 --> 00:03:38,300
So this by itself would not call the on draw method.

53
00:03:38,870 --> 00:03:43,970
This one here, which takes care of all of the drawing right, which takes care of drawing all of the

54
00:03:43,970 --> 00:03:44,360
paths.

55
00:03:44,630 --> 00:03:51,260
So here and perhaps that's basically all of the custom paths that we created, and that's where it actually

56
00:03:51,260 --> 00:03:51,920
draws them.

57
00:03:52,550 --> 00:03:57,800
So what we need to do is we need to call this method once again.

58
00:03:57,800 --> 00:04:03,380
So this on draw method once again, and we don't call it manually by saying on draw like so.

59
00:04:03,620 --> 00:04:10,430
But what we can do instead is we call the invalidate method, which will then internally call on draw.

60
00:04:11,150 --> 00:04:16,250
OK, because this is an override method and this is done for views, right?

61
00:04:16,250 --> 00:04:23,840
This is a method that exists inside of views because our drawing view is of class type view.

62
00:04:24,410 --> 00:04:28,680
So it's just going to redraw the entire page.

63
00:04:29,030 --> 00:04:31,560
So that's what our Click Undo method will do.

64
00:04:31,800 --> 00:04:32,840
I know we just need to call it.

65
00:04:32,960 --> 00:04:35,570
And the best spot would be once we click on the button.

66
00:04:35,580 --> 00:04:39,110
So here in the set on Click Listener, we can just use this method.

67
00:04:39,350 --> 00:04:45,260
But because this method is in this drawing view class, we need to make sure that we use the drawing

68
00:04:45,260 --> 00:04:47,930
view here in order to get access to it.

69
00:04:48,020 --> 00:04:53,750
So here I'm just going to say drawing view dots on click undo.

70
00:04:53,870 --> 00:04:55,670
So I'm just going to call this method.

71
00:04:56,090 --> 00:04:59,570
But because drawing viewers and Nullarbor, we need to add the question mark here.

72
00:05:00,170 --> 00:05:02,090
OK, so now let's go ahead.

73
00:05:03,210 --> 00:05:11,370
And test this and see if it's going to work, so draw and draw and you see the undo works perfectly.

74
00:05:12,340 --> 00:05:13,900
And withdraw some more.

75
00:05:14,980 --> 00:05:21,490
And also with different colors and stuff, and I'll click the back button and you see it works as intended.

76
00:05:22,240 --> 00:05:27,880
So now you could implement a redo button very easily, you know how to create the undo button.

77
00:05:28,180 --> 00:05:31,990
Basically, you just need to add back the.

78
00:05:33,970 --> 00:05:39,640
Here, the last, Andrew, from undue payoffs to impasse, basically with the same approach that you

79
00:05:39,640 --> 00:05:44,740
have here and then call Invalidate, so I would say try it by yourself.

80
00:05:45,220 --> 00:05:47,280
Implement this as a little challenge for yourself.

81
00:05:47,290 --> 00:05:49,600
This will really help you to understand this a little better.

82
00:05:49,930 --> 00:05:51,160
And good luck with it.

83
00:05:51,610 --> 00:05:56,260
So in the next video, we're going to look at cold routines, which is a little demo that you will need

84
00:05:56,260 --> 00:05:58,750
to understand how to run cold in the background.

85
00:05:58,760 --> 00:06:04,930
And then we're going to look at how we can make a sandwich out of our images because we actually have

86
00:06:04,930 --> 00:06:05,950
two images here, right?

87
00:06:05,960 --> 00:06:09,100
The image in the background and what we are drawing.

88
00:06:09,820 --> 00:06:11,620
All right, so see you in the next video.

