1
00:00:00,850 --> 00:00:01,510
Welcome back.

2
00:00:01,720 --> 00:00:07,150
And this video, we're going to prepare our brush size selector and we're going to see how to use display

3
00:00:07,150 --> 00:00:11,560
metrics because what we want to do is we want to be able to set the size of our brush.

4
00:00:11,740 --> 00:00:16,120
And in order to achieve that, well, we need to use dimensions because this will look different on

5
00:00:16,120 --> 00:00:20,200
different devices and we want to make sure that it's going to look more or less the same.

6
00:00:20,560 --> 00:00:27,280
So inside of our drawing view, let's go ahead and create a new function, and I'm going to put it right

7
00:00:27,280 --> 00:00:29,350
here just before the inner class.

8
00:00:29,740 --> 00:00:34,780
So at the very bottom, I'm going to now go ahead and create a new function, and I'm going to make

9
00:00:34,780 --> 00:00:35,350
it public.

10
00:00:35,350 --> 00:00:39,580
Or I don't add the private key word because I want to be able to use it in the main activity.

11
00:00:39,580 --> 00:00:43,930
So that's why I'm not going to add anything before it, no access modifier.

12
00:00:44,200 --> 00:00:47,500
So I'm going to call this method set size for brush.

13
00:00:47,860 --> 00:00:52,450
And what it's going to require is going to be the new size that I want to use, which will be of type

14
00:00:52,450 --> 00:00:56,020
float because values on the screen are using floats.

15
00:00:56,590 --> 00:01:03,520
So now I'm going to set the brush size, which is this value that we created here, which is a variable

16
00:01:03,520 --> 00:01:06,010
for stroke brush size to draw on the canvas.

17
00:01:06,700 --> 00:01:10,030
And we set that to zero and made a float out of it.

18
00:01:10,630 --> 00:01:10,940
OK.

19
00:01:11,320 --> 00:01:16,300
And now we're going to use that and overwrite it with this new size.

20
00:01:16,750 --> 00:01:23,890
But unfortunately, I kind of just say new size because I want to take the screen dimension into consideration.

21
00:01:24,160 --> 00:01:31,000
In order to achieve that, I can use the typed value class, which contains the applied dimension method.

22
00:01:31,510 --> 00:01:34,240
And this requires a couple of values.

23
00:01:34,250 --> 00:01:37,260
So an integer, a float and the metrics.

24
00:01:37,270 --> 00:01:42,790
So the unit that we want to use, then the value as well as the metrics.

25
00:01:42,820 --> 00:01:49,690
So if you want to know more about it, apply dimensions you can see here unit float display metrics.

26
00:01:50,200 --> 00:01:51,400
So let's go over.

27
00:01:52,360 --> 00:02:00,970
So let's go ahead and use the typed value dot complex unit, the IP as the.

28
00:02:02,350 --> 00:02:07,270
First of all, you hear, and that will be our unit.

29
00:02:07,400 --> 00:02:15,670
OK, so the unit that I want to use is in fact this aesthetic value complex, you know, Dippy and this

30
00:02:15,670 --> 00:02:21,760
will then allow me to make sure that it's going to take their density pixels into consideration, then

31
00:02:21,760 --> 00:02:23,360
it needs to have the value.

32
00:02:23,380 --> 00:02:28,960
So the new value that we are going to pass to it, which will be our new size.

33
00:02:29,230 --> 00:02:31,740
And then finally, it needs to know the metrics.

34
00:02:31,750 --> 00:02:33,760
So here you see display metrics.

35
00:02:34,180 --> 00:02:36,520
OK, so where do I get them from?

36
00:02:36,550 --> 00:02:39,730
Well, I can get them from resources that display metrics.

37
00:02:40,670 --> 00:02:47,980
Okay, so this will basically do the trick and will set the new brush size to be a value based on our

38
00:02:47,980 --> 00:02:55,720
new size that we're passing, but adjusted to the metrics of our display, so adjusted to the size of

39
00:02:55,720 --> 00:02:56,380
our display.

40
00:02:56,380 --> 00:03:03,760
So it's going to be proportionate to the size of the screen because this line here has this certain

41
00:03:03,760 --> 00:03:07,120
thickness, but on a bigger screen it will look different, right?

42
00:03:07,270 --> 00:03:14,950
We want to adjust this thickness to the screen that is, the game is running up and then I need to set

43
00:03:14,950 --> 00:03:16,480
that for my draw paint.

44
00:03:16,870 --> 00:03:26,860
So my am draw paint stroke with now needs to be used while using our hand brush size that we just set

45
00:03:26,860 --> 00:03:27,010
up.

46
00:03:29,210 --> 00:03:34,910
So now inside of our drawing view, we are setting up the brush size and that is here.

47
00:03:35,300 --> 00:03:37,340
OK, so we can get rid of this.

48
00:03:37,670 --> 00:03:44,030
So inside of the set up drawing method, we are setting up the brush size and we don't need that anymore

49
00:03:44,300 --> 00:03:48,770
because we are going to set that in our main activity.

50
00:03:49,100 --> 00:03:55,250
So let's go over to the main activity and actually called this method that will allow us to set the

51
00:03:55,250 --> 00:03:58,010
brush size based on the dimensions that we're using.

52
00:03:58,370 --> 00:04:02,810
And therefore, I'm going to require the drawing view that I want to use.

53
00:04:03,140 --> 00:04:07,100
So here I will need to get the drawing view.

54
00:04:07,910 --> 00:04:12,700
Using private VAR drawing view is how I'm going to call it.

55
00:04:12,710 --> 00:04:19,540
It will be of type drawing view, which is our class that we just created, and I'm going to make it

56
00:04:19,550 --> 00:04:21,800
another bowl and set it to null at this point.

57
00:04:21,800 --> 00:04:30,920
And then we can go ahead and set the drawing view to be found by its I.D., our Dart ID Dot drawing

58
00:04:30,920 --> 00:04:38,240
view, which is this simple drawing view that we created because you see we are using our own view,

59
00:04:38,540 --> 00:04:42,320
so we're not using a text view or button view or whatever.

60
00:04:42,320 --> 00:04:48,830
We're creating our very own view, which is destroying view that we're created right and we're inheriting

61
00:04:48,830 --> 00:04:51,560
from view or this glasses and everything from you.

62
00:04:51,560 --> 00:04:53,480
So that's why we can use it in XML.

63
00:04:53,720 --> 00:04:59,600
But in order to now access it in our main activity, we still need to use find view by ID or data binding.

64
00:04:59,610 --> 00:05:01,400
What if worked alternatively as well.

65
00:05:01,670 --> 00:05:07,520
And now we can set the size for the brush, let's say 20 to float.

66
00:05:08,990 --> 00:05:10,670
And this will.

67
00:05:11,880 --> 00:05:15,630
Give us the brush size of 20, which will look slightly differently.

68
00:05:15,930 --> 00:05:20,610
So let's check it out, and you see it's a lot thicker because now it's taking the size of the screen

69
00:05:20,610 --> 00:05:21,780
into consideration.

70
00:05:22,260 --> 00:05:24,930
And also because they have the size here.

71
00:05:24,930 --> 00:05:29,310
Now, for my drawing view, I don't need to set that in here.

72
00:05:29,310 --> 00:05:34,800
So I commented this line out because otherwise I would override it, and that's not necessary.

73
00:05:35,430 --> 00:05:35,790
All right.

74
00:05:35,970 --> 00:05:42,360
So that's pretty much the preparation for the next video because what we want to do is you want to be

75
00:05:42,360 --> 00:05:44,640
able to set the size for the brush.

76
00:05:44,970 --> 00:05:50,880
And in the next video, we're going to be able to select the brush size from a custom dialogue that

77
00:05:50,880 --> 00:05:51,750
we're going to create.

78
00:05:52,290 --> 00:05:54,270
So let's check that out in the next video.

