1
00:00:00,480 --> 00:00:06,630
So as you can see here this is the line of code that I pasted here and here I referred to the name of

2
00:00:06,630 --> 00:00:08,890
this class preference manager.

3
00:00:09,000 --> 00:00:13,310
OK so this class is going to actually manage the preferences in our Android application.

4
00:00:13,390 --> 00:00:19,200
OK so for example example when a user wants to actually change the settings of the application we need

5
00:00:19,200 --> 00:00:24,180
to actually use this class free France manager in order to manage these sitting.

6
00:00:24,180 --> 00:00:27,570
So this is very important that we actually use this glass.

7
00:00:27,690 --> 00:00:31,110
So prevents manager that set default values.

8
00:00:31,110 --> 00:00:32,940
So what does this method do this.

9
00:00:33,000 --> 00:00:39,990
If it actually is going to actually specify the default values for the first time that our application

10
00:00:39,990 --> 00:00:43,490
is actually installed inside our application.

11
00:00:43,530 --> 00:00:49,740
So unhallowed majorly closed this application and now let's actually uninstall and install this application

12
00:00:49,740 --> 00:00:50,330
here.

13
00:00:53,370 --> 00:00:54,030
OK.

14
00:00:54,270 --> 00:00:58,460
And let's actually run our project again and let's install our project here.

15
00:00:58,470 --> 00:01:01,090
Our application on this emulator here again.

16
00:01:01,170 --> 00:01:07,740
So as you can see here this is our application and this is for the first time that our application is

17
00:01:07,740 --> 00:01:09,810
actually running on this emulator.

18
00:01:10,110 --> 00:01:18,510
So now we need to actually read some of the actually preferences some of the settings that we initially

19
00:01:18,540 --> 00:01:22,180
assigned to this quiz underline preferences that exempt.

20
00:01:22,200 --> 00:01:24,750
So insight is always underlying prefer preferences that is.

21
00:01:24,770 --> 00:01:30,800
And as you can see we have a list preference or multi multi-select preference and other and other less

22
00:01:30,810 --> 00:01:31,350
preference.

23
00:01:31,380 --> 00:01:33,550
And finally another list preference.

24
00:01:33,570 --> 00:01:39,620
So as you can see here for each of these components as you can see I provided a default value right.

25
00:01:39,720 --> 00:01:45,130
A default value for example for the colors are provided the black color for the font.

26
00:01:45,180 --> 00:01:50,880
I provide the default font and for other components I also provided a default value.

27
00:01:51,210 --> 00:01:52,410
So why do they do that.

28
00:01:52,410 --> 00:01:59,820
Because for the first time that our application is actually running on the user's device or application

29
00:01:59,880 --> 00:02:06,740
the Android device is going to actually read the default values for the components for these radio buttons

30
00:02:06,780 --> 00:02:13,230
or for these for these checkboxes and the default values is going to be for example determine the background

31
00:02:13,230 --> 00:02:14,440
color of the quiz.

32
00:02:14,530 --> 00:02:15,030
OK.

33
00:02:15,060 --> 00:02:20,430
So that default value for the first time is really important because the user is actually running the

34
00:02:20,430 --> 00:02:21,900
application for the first time.

35
00:02:22,170 --> 00:02:28,860
And we must actually specify the default value for example for the backend on color or for the front

36
00:02:28,920 --> 00:02:36,270
of the text of the buttons or for example how many options we want to show to the user in order to actually

37
00:02:36,360 --> 00:02:44,430
guess the name of the animal or for example we may we may want to we may want to specify the type of

38
00:02:44,430 --> 00:02:48,140
the animals that we want to actually put inside the squeeze.

39
00:02:48,150 --> 00:02:53,070
So this is very important that we specify a default value and inside this main activity that double

40
00:02:53,070 --> 00:02:58,900
file here as you can see that Savoye we use this class your preference manager in order to set those

41
00:02:58,950 --> 00:03:04,900
default values inside this uncreate method of this main activity that Java class as you can see.

42
00:03:04,920 --> 00:03:10,200
So preference manager that set default values and dismiss that as she accepts free arguments.

43
00:03:10,200 --> 00:03:10,730
Right.

44
00:03:10,800 --> 00:03:13,510
The first argument is is going to be the context.

45
00:03:13,510 --> 00:03:17,080
So the context is this class right main activity that this.

46
00:03:17,130 --> 00:03:22,380
So this is going to be the context that we are going to actually set the default values and for the

47
00:03:22,380 --> 00:03:29,220
second argument we need to specify the actual preferences file that we provided inside our project so

48
00:03:29,220 --> 00:03:36,100
that this class is going to read what those default values from this exemplified so are that examine

49
00:03:36,390 --> 00:03:42,750
that cuius underline preferences so this is the name of this class that we of this vitamine file that

50
00:03:42,750 --> 00:03:45,100
we created inside our project right.

51
00:03:45,120 --> 00:03:50,150
So our That is XML that is underlying preferences at the end is deferred argument.

52
00:03:50,160 --> 00:03:52,940
So what does this argument do.

53
00:03:53,070 --> 00:03:59,160
Now let me show you that for example if you actually call this method again a preference manager that

54
00:03:59,340 --> 00:04:04,440
set default values and then as you can see it is going to show us the arguments so as you can see here

55
00:04:04,740 --> 00:04:11,830
the first argument is actually of type Boolean right and the assigned value falls for the first argument.

56
00:04:11,940 --> 00:04:13,460
Now it says read again.

57
00:04:13,470 --> 00:04:15,690
So the name of this argument is read again.

58
00:04:15,690 --> 00:04:16,910
And what does this mean.

59
00:04:16,920 --> 00:04:24,370
This means that that for the first time our application is running on the user's device and our the

60
00:04:24,960 --> 00:04:29,830
and relativize is going to actually delete those default values from this quiz Underland preferences

61
00:04:29,840 --> 00:04:30,840
that is am I right.

62
00:04:31,110 --> 00:04:38,190
So what happens when the user actually is running the application for actually multiple times for the

63
00:04:38,190 --> 00:04:38,970
next time.

64
00:04:39,000 --> 00:04:39,270
Right.

65
00:04:39,270 --> 00:04:43,460
For example one hour later or for example 10 days later.

66
00:04:43,650 --> 00:04:50,430
In that case as you can see we dont want the application we dont want the device the Android device

67
00:04:50,430 --> 00:04:53,640
to lead to Leto's the default values from there.

68
00:04:53,680 --> 00:04:59,550
This is underlined preferences that are similar because they use it may have actually changed those

69
00:04:59,670 --> 00:05:00,380
values.

70
00:05:00,390 --> 00:05:05,390
OK to use it may have actually to change the background color of the query or use that a man may actually

71
00:05:05,430 --> 00:05:06,160
changed.

72
00:05:06,180 --> 00:05:12,300
I mean have actually changed the front of the text of the buttons or the user may have actually changed

73
00:05:12,420 --> 00:05:20,280
kind of animals that he or she wants to be used in say the quiz or the user may have actually specified

74
00:05:20,640 --> 00:05:21,150
that.

75
00:05:21,150 --> 00:05:25,860
How many options how many guesses are going to be inside the quiz.

76
00:05:25,940 --> 00:05:33,570
So those preferences those settings are going to actually are going to be saved in say the shirt preferences

77
00:05:34,270 --> 00:05:35,700
inside another class.

78
00:05:35,700 --> 00:05:41,820
But here as you can see be assigned a value for us and this means that we dont want to read again after

79
00:05:42,360 --> 00:05:47,310
the user has actually installed the application on the device and they use it for example is running

80
00:05:47,550 --> 00:05:49,640
the application on the device.

81
00:05:49,830 --> 00:05:55,430
And for the next time that the user is actually in the application on the device we dont want to read

82
00:05:55,570 --> 00:05:59,350
preferences to settings from these cuius underling preferences again.

83
00:05:59,380 --> 00:06:05,980
So thats why we assign de-value falls for the first argument which is a Boolean read again right.

84
00:06:06,010 --> 00:06:12,100
We just want to read those default values for the first time that the user is actually running the application

85
00:06:12,360 --> 00:06:12,960
and so forth.

86
00:06:13,090 --> 00:06:18,940
And for the next times of you're going to actually provide some other values and then I'm going to show

87
00:06:18,940 --> 00:06:19,260
you that.

88
00:06:19,270 --> 00:06:23,860
But for now I just know that we assign the value false for the read again argument.

89
00:06:23,860 --> 00:06:27,200
So now let me paste in some lines of code here.

90
00:06:27,250 --> 00:06:28,740
Inside this uncreate my feet.

91
00:06:28,750 --> 00:06:31,820
And then I'm going to explain to you what's going on here.

92
00:06:32,760 --> 00:06:37,040
So as you can see here these are the lines of code that I pasted here.

93
00:06:37,080 --> 00:06:45,420
So as you can see here I refer to the name of this class preference manager that get default shirt preferences.

94
00:06:45,570 --> 00:06:45,780
Right.

95
00:06:45,910 --> 00:06:46,300
Right.

96
00:06:46,300 --> 00:06:51,770
Here we want to get the shirt preferences of our application inside the user's device.

97
00:06:51,780 --> 00:06:57,870
So this is really important because when ever the use that is actually changing the settings of the

98
00:06:57,870 --> 00:07:05,110
quiz animal or get it they're going to actually save those changes to these shared preferences.

99
00:07:05,220 --> 00:07:11,730
So it's very important that we get this shows preferences and as you can see we need to pass this argument

100
00:07:11,790 --> 00:07:12,990
main activity that these.

101
00:07:12,990 --> 00:07:15,150
So this is going to be the context.

102
00:07:15,150 --> 00:07:15,770
Right.

103
00:07:16,110 --> 00:07:21,450
And as you can see I am calling an other method and these are shared preferences.

104
00:07:21,510 --> 00:07:22,200
Right.

105
00:07:22,200 --> 00:07:28,520
So main activity that these dot legis there on shared preferences change the center.

106
00:07:28,710 --> 00:07:30,740
So what that is what does this mean.

107
00:07:30,810 --> 00:07:37,440
This means that we are going to create our listener for the changes of our settings.

108
00:07:37,620 --> 00:07:38,180
Right.

109
00:07:38,190 --> 00:07:44,580
So diskless main activity is going to be notified when ever the user is actually changing the settings

110
00:07:44,580 --> 00:07:45,480
of the application.

111
00:07:45,480 --> 00:07:49,860
So now let me show you Let me show you that in say the emulator.

112
00:07:49,890 --> 00:07:53,520
So now as you can see here our application is running on the simulator.

113
00:07:53,520 --> 00:07:58,860
And if I click on the Settings button here now for example if I want to actually change the background

114
00:07:58,890 --> 00:08:03,110
color of the Queen for example change it to white.

115
00:08:03,120 --> 00:08:09,600
Now as you can see here it says new changes are applied and this means that this class main activity

116
00:08:09,600 --> 00:08:14,070
here is going to be notified when ever the settings is changed.

117
00:08:14,070 --> 00:08:21,090
For example whenever the background color is changed all the fault of the texts of the guest buttons

118
00:08:21,360 --> 00:08:25,800
are actually changed or of for example the types of animal is actually changed.

119
00:08:25,800 --> 00:08:26,420
Right.

120
00:08:26,460 --> 00:08:29,040
Or we can actually change the number of guesses.

121
00:08:29,070 --> 00:08:35,850
So this means that here you are actually creating a listener inside this main activity class to those

122
00:08:35,850 --> 00:08:36,640
changes.

123
00:08:36,640 --> 00:08:42,050
We are going to be notified to those changes so that we can actually respond to those changes.

124
00:08:42,150 --> 00:08:47,610
So now if I click on dispatch button here as you can see now the background color is white and this

125
00:08:47,610 --> 00:08:55,110
means that the main activity class is actually notified to that change and the background color is white

126
00:08:55,260 --> 00:09:03,260
according to that setting according to the change that the user has actually made here in say the settings

127
00:09:03,270 --> 00:09:04,860
activity.

128
00:09:04,860 --> 00:09:11,760
So hopefully that makes sense and its very important that we create our listener for this.

129
00:09:11,880 --> 00:09:14,370
Listen for this shirt preferences.

130
00:09:14,780 --> 00:09:19,840
So preference managers that get default shirt preferences so here we are actually getting the shared

131
00:09:19,860 --> 00:09:24,680
preferences and then we are calling a method on this show preferences.

132
00:09:24,700 --> 00:09:32,100
So that register on shared preferences change listener and then if you are passing this listener to

133
00:09:32,100 --> 00:09:32,870
dismiss it.

134
00:09:33,060 --> 00:09:38,070
So we havent created this listener yet inside this class so we need to create this listener inside this

135
00:09:38,070 --> 00:09:40,660
class settings change listener right.

136
00:09:40,800 --> 00:09:49,020
So now let's actually copy this settings change the center here and now let's scroll down here and then.

137
00:09:49,020 --> 00:09:50,890
Now inside this class.

138
00:09:50,940 --> 00:09:56,190
So before the end in calibrates of these class classes as you can see we have this mean activity the

139
00:09:56,200 --> 00:10:03,220
class and before the end in curly brace of this class now we're going to create a listener for that

140
00:10:03,350 --> 00:10:06,020
for those changes in say the settings activity.

141
00:10:06,050 --> 00:10:06,630
Right.

142
00:10:06,660 --> 00:10:08,990
A shared preferences change listener.

143
00:10:09,000 --> 00:10:10,240
This is really important.

144
00:10:10,260 --> 00:10:20,400
So here just typing private shared preferences dot on shared preferences change listener.

145
00:10:20,880 --> 00:10:24,920
And then here we need to specify a name for this listener right.

146
00:10:24,930 --> 00:10:27,160
So just paste it pistis value here.

147
00:10:27,220 --> 00:10:36,540
Settings change the listener and then put an assignment operator here new again shared preferences that

148
00:10:36,860 --> 00:10:45,420
as you can see should be Finance's dot on shirt preferences change Listen here and now just open and

149
00:10:45,420 --> 00:10:51,400
close the listener by by putting an opening curly brace followed by a closing curly brace.

150
00:10:51,420 --> 00:10:56,780
So now it may actually create a new line here and now we can actually see disvalue here.

151
00:10:56,940 --> 00:11:00,310
Private shared preferences that aren't shared.

152
00:11:00,300 --> 00:11:01,900
Preferences change the listener.

153
00:11:01,980 --> 00:11:05,480
So here we are going to create a listener to those changes.

154
00:11:05,500 --> 00:11:10,190
Inside these shows preferences and in Amy's settings changed the center right.

155
00:11:10,200 --> 00:11:16,270
The same name that be specified here inside is on create Smurfit settings change to listener right.

156
00:11:16,350 --> 00:11:24,180
So now I put an assignment operator here new shared preferences that aren't shared preferences but that

157
00:11:24,220 --> 00:11:26,060
unshipped preference change listener.

158
00:11:26,190 --> 00:11:31,590
Right so now we are inside this inside the curly braces unopen opening curly brace followed by a closing

159
00:11:31,590 --> 00:11:35,710
curly brace and now as you can see here we have an error.

160
00:11:35,730 --> 00:11:39,720
So here we are actually creating an anonymous inner class right.

161
00:11:39,730 --> 00:11:47,040
I told you about anonymous classes in Java in the previous tutorials and now you know what our anonymous

162
00:11:47,180 --> 00:11:47,660
classes.

163
00:11:47,670 --> 00:11:55,130
And here you are creating an anonymous class that actually conforms to this interface.

164
00:11:55,160 --> 00:12:01,820
As you can see here unshared friends change to the center and now you need to actually provide the abstract

165
00:12:01,820 --> 00:12:06,530
method that we have inside this interface and shared to prevent a strange listener.

166
00:12:06,530 --> 00:12:09,520
So what is that an abstract Meffert that abstract.

167
00:12:09,530 --> 00:12:10,600
Is that abstract.

168
00:12:10,610 --> 00:12:13,430
If it is an shared preference change listener.

169
00:12:13,520 --> 00:12:19,720
So if you need to write this move it here and at the end as you can see if we have this incredible piece

170
00:12:19,760 --> 00:12:25,180
of this listener right we need to put up a semicolon here and as you can see here the error is gone

171
00:12:25,520 --> 00:12:26,530
so we override it.

172
00:12:26,530 --> 00:12:29,470
This method here inside these anonymous inner class.

173
00:12:29,470 --> 00:12:32,110
So here we have an anonymous class.

174
00:12:32,180 --> 00:12:40,300
Right and this anonymous class is actually conforming to this on a shared friends change listener interface.

175
00:12:40,640 --> 00:12:46,400
And because that anonymous in a class is actually conforming to this interface we need to actually provide

176
00:12:46,400 --> 00:12:50,080
the abstract method that we have inside this interface right.

177
00:12:50,180 --> 00:12:56,660
So here as you can see we have this method here inside these anonymous class as you can see that it

178
00:12:56,660 --> 00:13:00,720
isn't if it is actually public Woit on shared preference changed.

179
00:13:00,770 --> 00:13:06,500
So this is going to be called whenever it is the use that is actually has changed the preferences of

180
00:13:06,500 --> 00:13:08,030
the application.

181
00:13:08,030 --> 00:13:11,140
So as you can see here we have these preferences.

182
00:13:11,150 --> 00:13:15,040
So for example the user change the format.

183
00:13:15,210 --> 00:13:19,370
And if I click on this back button he had as he can't see the font is changed right.

184
00:13:19,760 --> 00:13:23,960
So this is going to be called when ever the use of changes to preferences.

185
00:13:23,960 --> 00:13:29,900
So on shirtsleeve friends change and the it accepts two arguments the first one is shared preferences

186
00:13:30,230 --> 00:13:32,840
and the second one is the key right.

187
00:13:32,930 --> 00:13:39,680
So now later we will be actually putting more logic's inside this method for now just put these lines

188
00:13:39,680 --> 00:13:40,640
of code here.

189
00:13:40,980 --> 00:13:43,720
And now let's actually scroll to the top here.

190
00:13:43,760 --> 00:13:47,020
As you can see now the error is gone right.

