1
00:00:00,420 --> 00:00:01,270
Higher want.

2
00:00:01,380 --> 00:00:07,000
So in this tutorial you're going to go ahead and we're going to add another functionality to this application.

3
00:00:07,140 --> 00:00:13,250
So we are going to allow the user to save the image into actually external memory.

4
00:00:13,350 --> 00:00:18,240
So here you can see that we have this button save the picture in order to do that.

5
00:00:18,270 --> 00:00:20,960
So we need a class inside our project.

6
00:00:21,120 --> 00:00:26,190
So let's actually at the top and just get the kind of view to Windows and then we can project.

7
00:00:26,190 --> 00:00:31,730
So here it is our Android you and see it is the project you I need to change it to Android.

8
00:00:31,740 --> 00:00:34,200
So here look at this little triangle here.

9
00:00:34,200 --> 00:00:36,760
If I click on it I can select Android.

10
00:00:36,810 --> 00:00:39,780
Now you can see that it is actually called the Android view.

11
00:00:39,810 --> 00:00:44,930
If I open the app folder you can see that they have the manifest Java address.

12
00:00:44,970 --> 00:00:50,580
So let's open the Java folder and let's open the first package that actually contains these two classes

13
00:00:50,580 --> 00:00:56,010
the colorful class and the main theme with the class select expect package at the top menu just a click

14
00:00:56,010 --> 00:00:59,720
on File New and then click on Dobber class.

15
00:00:59,760 --> 00:01:07,770
So for the name of the class I can actually say save image or a safe flight save flight.

16
00:01:07,860 --> 00:01:11,090
So this is the name of the class and the kind is class.

17
00:01:11,100 --> 00:01:14,420
You don't have to specify the superclass or the interface.

18
00:01:14,430 --> 00:01:18,630
This is the package visibility is public and the modifiers is none.

19
00:01:18,630 --> 00:01:20,600
So just click on OK.

20
00:01:20,740 --> 00:01:22,830
So here it is our class like puppy class.

21
00:01:22,830 --> 00:01:24,120
Safe flight.

22
00:01:24,130 --> 00:01:28,870
So now that the class is created let me double click on this tab here say find that job in order to

23
00:01:28,870 --> 00:01:30,630
make it area there.

24
00:01:30,660 --> 00:01:37,420
Now let's create a method in order to actually save the file to external storage.

25
00:01:37,720 --> 00:01:41,490
So I can say Puplick static look at this method.

26
00:01:41,500 --> 00:01:42,340
It is static.

27
00:01:42,340 --> 00:01:43,290
What does this mean.

28
00:01:43,300 --> 00:01:49,780
This means that other classes if they want to actually use this method method they don't have to create

29
00:01:49,810 --> 00:01:52,310
an object of typesafe by class.

30
00:01:52,390 --> 00:01:54,670
They just need to call this method.

31
00:01:54,680 --> 00:01:56,980
On this say five class itself.

32
00:01:57,070 --> 00:01:59,760
So that's why it is actually called static.

33
00:01:59,770 --> 00:02:01,850
So you're already familiar with that right.

34
00:02:01,880 --> 00:02:02,850
Public static.

35
00:02:02,860 --> 00:02:06,210
And now I need to specify the return type of this method.

36
00:02:06,340 --> 00:02:13,420
So the return type is going to be filed if it is going to return an object of type fight.

37
00:02:13,510 --> 00:02:15,330
So what is going to be the name of that method.

38
00:02:15,430 --> 00:02:19,120
The name of them if it is going to be safe flight.

39
00:02:19,160 --> 00:02:24,040
Right that's the name of this method and this is going to accept some actually the arguments you need

40
00:02:24,110 --> 00:02:26,640
to specify some parameters for this method.

41
00:02:26,840 --> 00:02:29,510
The first priority is going to be off type activity.

42
00:02:29,900 --> 00:02:36,320
So just they've been here activity and the name of this parameter is going to be my activity my activity

43
00:02:37,550 --> 00:02:39,340
and then he'll put a comma.

44
00:02:39,740 --> 00:02:42,660
The second parameter is going to be off the bitmap.

45
00:02:42,710 --> 00:02:47,040
Right because you want to actually save a bitmap to external storage.

46
00:02:47,090 --> 00:02:51,620
So the second parameter is going to be bitmap and the name is going to be bitmap.

47
00:02:51,620 --> 00:02:57,540
So let's here specify that these Smurfette is going to throw an exception.

48
00:02:57,710 --> 00:02:58,750
Right.

49
00:02:58,790 --> 00:03:04,130
This method is error prone and it can actually go wrong and it's going to actually cause some errors.

50
00:03:04,190 --> 00:03:11,420
So we are going to allow two other Nicolet other classes and know that the Smurfit is not actually completely

51
00:03:11,420 --> 00:03:12,170
safe.

52
00:03:12,170 --> 00:03:14,820
This method can actually for an exception.

53
00:03:14,980 --> 00:03:21,260
So other classes if they want to use this method they must actually handle these exception exceptions.

54
00:03:21,260 --> 00:03:23,480
Otherwise it's not going to work.

55
00:03:23,540 --> 00:03:23,960
OK.

56
00:03:24,170 --> 00:03:29,310
So I can say fros no exception.

57
00:03:29,430 --> 00:03:29,890
Right.

58
00:03:30,120 --> 00:03:35,250
So just open and close this method by using these curly braces and opening curly brace followed by a

59
00:03:35,250 --> 00:03:36,380
closing curly brace.

60
00:03:36,540 --> 00:03:40,400
Let's go inside the Smurfette And let's see what we are going to do next.

61
00:03:40,400 --> 00:03:45,700
So create of idea but of types 3 in here so let's specify this data type yestreen.

62
00:03:46,020 --> 00:03:50,190
So notice that this variable is actually going to be a local variable right because it is local to the

63
00:03:50,190 --> 00:03:51,880
curly braces of this method.

64
00:03:52,260 --> 00:03:54,660
So now we're going to specify the name of this value.

65
00:03:54,660 --> 00:04:01,060
Well this is going to be external external storage state.

66
00:04:01,220 --> 00:04:07,790
So if you want to actually know that whether the device has or has an external threat or not.

67
00:04:07,970 --> 00:04:10,370
OK so if you want to be sure about that.

68
00:04:10,370 --> 00:04:12,640
So I create a variable here.

69
00:04:12,710 --> 00:04:18,710
I put an assignment operator and I'm going to refer to this environment class that actually knows about

70
00:04:18,900 --> 00:04:22,100
whether the user has an external storage or not.

71
00:04:22,100 --> 00:04:25,680
So environment that gets external storage.

72
00:04:25,680 --> 00:04:28,900
State semi-hollow.

73
00:04:28,970 --> 00:04:36,030
Now let's create a variable of type fight because we want to actually save this for it to extend or

74
00:04:36,030 --> 00:04:37,100
to store it right.

75
00:04:37,230 --> 00:04:39,430
Our image which is which is actually a file.

76
00:04:39,630 --> 00:04:44,990
So let's create a file and notice that this method must return a value of a file.

77
00:04:45,090 --> 00:04:47,590
So that's why I'm creating this value in here.

78
00:04:47,670 --> 00:04:51,880
And the name of this variable is going to be my file assignment operator.

79
00:04:51,960 --> 00:04:57,110
Initially I'm going to assign the value null to this variable because this is actually a local variable

80
00:04:57,690 --> 00:05:01,760
and the value is not going to be assigned to this variable.

81
00:05:01,770 --> 00:05:07,310
By default if it was an instance variable Yes it was the default value would be null.

82
00:05:07,320 --> 00:05:10,050
But here it is actually a local variable.

83
00:05:10,110 --> 00:05:16,200
And here we must actually specify an initial value for this value but otherwise later when we want to

84
00:05:16,380 --> 00:05:20,130
use this variable it's going to actually show us some error.

85
00:05:20,130 --> 00:05:25,160
The compiler is going to actually complain that this value is not initially initialized yet.

86
00:05:25,200 --> 00:05:29,630
So initially we are going to assign the value and also you know what is the what not mean not means

87
00:05:29,790 --> 00:05:30,360
nothing.

88
00:05:30,420 --> 00:05:32,280
This valuable points to nothing.

89
00:05:32,550 --> 00:05:41,380
So now I can't say if so I'm going to refer to this valuable external storage state but I'm going to

90
00:05:41,740 --> 00:05:48,760
actually compared the value of this valuable to another value so I'm going to say equals right equals

91
00:05:48,910 --> 00:05:54,380
and I'm going to is you can see that this equals my if it needs an argument of type Object.

92
00:05:54,400 --> 00:05:54,990
Right.

93
00:05:55,360 --> 00:06:01,240
So I'm going to say equals environment that media mountains.

94
00:06:01,550 --> 00:06:02,380
What does this mean.

95
00:06:02,390 --> 00:06:07,830
This means device has an external storage and it is ready and we can use it.

96
00:06:08,000 --> 00:06:08,290
Right.

97
00:06:08,290 --> 00:06:13,980
Environment that media mounted we can use the external storage if the external of the storage media

98
00:06:14,020 --> 00:06:21,050
it does have this value then in that case we are a hundred and fifty percent sure that the device has

99
00:06:21,050 --> 00:06:26,080
an external storage and we can save our file to that storage.

100
00:06:26,330 --> 00:06:30,200
So let's go inside the curly braces of this if statement if statement and let's see what you're going

101
00:06:30,200 --> 00:06:30,620
to do next.

102
00:06:30,620 --> 00:06:37,490
But first you can see that what happens if this condition evaluates to false if what happens if the

103
00:06:37,490 --> 00:06:42,310
user actually use this device doesn't have an external storage.

104
00:06:42,320 --> 00:06:45,430
In that case you are going to have an else if an else statement.

105
00:06:45,420 --> 00:06:51,780
So here I can say else and then I can open and close this whole statement by using these curly braces.

106
00:06:51,980 --> 00:06:55,550
And here we can handle this condition.

107
00:06:55,610 --> 00:06:58,090
So here I'm going to actually follow on exception.

108
00:06:58,130 --> 00:07:08,070
I can say fro new exception new exception and inside the prentices I need to specify the message so

109
00:07:08,190 --> 00:07:12,510
I can just put two codes here and I can say this device.

110
00:07:12,510 --> 00:07:24,010
This device does not have does not have to be an external that an external storage.

111
00:07:24,280 --> 00:07:25,610
Right semicolon.

112
00:07:25,690 --> 00:07:28,540
So let's go inside this if statement here.

113
00:07:28,540 --> 00:07:31,740
Let's create another variable of type file here.

114
00:07:31,740 --> 00:07:38,890
So just typing here file the name of this variable is going to be pictures directory pictures directory

115
00:07:39,350 --> 00:07:39,930
right.

116
00:07:40,000 --> 00:07:41,150
Assignment operator.

117
00:07:41,200 --> 00:07:46,990
Now I'm going to refer to this my activity argument that I receive from the Smurfette say fight right.

118
00:07:46,990 --> 00:07:55,900
I can see my activity that my activity actually my activity that gets external storage file directory

119
00:07:56,350 --> 00:07:57,620
get external.

120
00:07:57,730 --> 00:08:01,110
Actually the file still use this method here.

121
00:08:01,510 --> 00:08:07,720
So here we are way to actually pass a value of type string here and that value is going to specify a

122
00:08:07,720 --> 00:08:15,300
directory of the pictures that we want to save into our external storage.

123
00:08:15,340 --> 00:08:20,640
So here the name is going to be the name of this folder so that you're going to see that for that.

124
00:08:20,650 --> 00:08:26,290
But for now just know that you're going to actually create a directory here or a folder in order to

125
00:08:26,290 --> 00:08:33,250
hold all of the color pictures so I can put two quotes here and here instead the quotes I need to specify

126
00:08:33,250 --> 00:08:34,560
the name of that folder.

127
00:08:34,570 --> 00:08:39,150
So it is going to be color up pictures like color.

128
00:08:39,250 --> 00:08:45,630
So here let me tell you that every time they use There's actually a princess on the Save the picture

129
00:08:45,640 --> 00:08:51,280
button let me show you the activity underlayment examined here every time the user's presses on the

130
00:08:51,280 --> 00:08:58,210
spot and save the picture here all you want a new picture to be created and I want that image to be

131
00:08:58,210 --> 00:09:00,280
saved to external storage.

132
00:09:00,370 --> 00:09:00,980
Right.

133
00:09:01,030 --> 00:09:07,080
So every time the user presses on this button a new image is going to be created on your picture is

134
00:09:07,090 --> 00:09:09,400
going to be created with these values.

135
00:09:09,400 --> 00:09:17,610
For example red green blue and that image is going to be saved to our excellent storage.

136
00:09:17,840 --> 00:09:19,620
But here we have a problem.

137
00:09:19,640 --> 00:09:23,790
We must give a unique name for each image.

138
00:09:23,900 --> 00:09:25,030
OK.

139
00:09:25,070 --> 00:09:29,910
Two images with the same name cannot be existed in the same folder.

140
00:09:29,990 --> 00:09:30,390
Right.

141
00:09:30,410 --> 00:09:37,160
So we must give each image that the user actually creates by clicking on the Save the picture button.

142
00:09:37,170 --> 00:09:40,140
We must give each image a unique name.

143
00:09:40,250 --> 00:09:41,600
So let's see how we can do that.

144
00:09:41,600 --> 00:09:45,720
Let's go to the save file class below this line of code.

145
00:09:45,740 --> 00:09:52,280
I'm going to create a variable of type date right date which is in the Java that you can package date

146
00:09:53,120 --> 00:10:02,120
and here the name of this variable is going to be current dates current date assignment operator new

147
00:10:02,570 --> 00:10:04,220
date semicolon.

148
00:10:04,640 --> 00:10:10,270
So when I actually create a new date object it is going to give me the current date.

149
00:10:10,370 --> 00:10:16,140
OK the current date and this object is going to be assigned presumably but right.

150
00:10:16,190 --> 00:10:18,980
Let's create another variable here.

151
00:10:19,060 --> 00:10:21,490
And this is a blank right.

152
00:10:21,530 --> 00:10:28,810
It is like is actually a little bit like integer but it's going to hold more values more larger values.

153
00:10:29,250 --> 00:10:36,040
So learn the name of this variable is going to be elapsed time elapsed time.

154
00:10:37,270 --> 00:10:46,330
Assignment operator and here I'm going to refer to this class system clock that actually elapsed real

155
00:10:46,330 --> 00:10:48,470
time semicolon.

156
00:10:48,610 --> 00:10:55,750
So let me show you the web browser here because I actually opened on you of a page here in stack overflow.

157
00:10:55,780 --> 00:10:59,390
In order to let you know about this elapsed real time effort.

158
00:10:59,530 --> 00:11:01,000
So take a look at this answer.

159
00:11:01,000 --> 00:11:04,740
Here it says here is a little bit about a concept.

160
00:11:04,870 --> 00:11:09,160
It says elapsed your time effort and elapsed through time none was perfect.

161
00:11:09,160 --> 00:11:12,140
So here we are using the elapsed time if it's right.

162
00:11:12,190 --> 00:11:16,850
Return that time since the system was booted.

163
00:11:17,200 --> 00:11:18,340
This is really important.

164
00:11:18,400 --> 00:11:19,910
Let me read it again.

165
00:11:19,960 --> 00:11:28,950
The elapsed real time effort is going to return the time since the system was booted so let me go back

166
00:11:28,950 --> 00:11:30,420
to Andrew studio.

167
00:11:30,870 --> 00:11:31,870
What does this mean.

168
00:11:31,920 --> 00:11:39,360
This means that every time the user wants to actually save the image so as a result the user has to

169
00:11:39,360 --> 00:11:44,000
actually create a new image right because you want to create a new flight every time to use.

170
00:11:44,070 --> 00:11:53,180
It creates a new picture by clicking on the Save the picture button that image is going to have a unique

171
00:11:53,240 --> 00:11:54,640
elapsed time.

172
00:11:55,060 --> 00:11:56,020
OK.

173
00:11:56,030 --> 00:11:57,380
A unique elapsed time.

174
00:11:57,380 --> 00:11:58,250
Let me show you.

175
00:11:58,610 --> 00:12:03,070
That again is going to return the time since the system was booted.

176
00:12:03,150 --> 00:12:06,310
So this elapsed time here is going to be unique.

177
00:12:06,320 --> 00:12:14,300
Every time the user clicks on that button because it's impossible to use that actually create two pictures

178
00:12:14,750 --> 00:12:16,600
with the same elapsed time.

179
00:12:16,640 --> 00:12:17,200
Right.

180
00:12:17,210 --> 00:12:21,580
Because the time has passed by that moment the user presses that button.

181
00:12:21,770 --> 00:12:26,270
So if this doesn't make sense don't worry you can actually put the discussion in the course or you can

182
00:12:26,480 --> 00:12:31,290
message me in the ME and I will do my best to answer your question.

183
00:12:31,430 --> 00:12:37,340
But for now just make sure to actually look at the end of the documentation or watch this tutorial again

184
00:12:37,730 --> 00:12:40,860
in order to understand what does this elapsed time mean.

185
00:12:41,020 --> 00:12:41,500
OK.

186
00:12:41,600 --> 00:12:47,360
Searching the internet just search for this elapsed realtime effect and then you get to get what I mean.

187
00:12:47,390 --> 00:12:51,380
So and we have this elapsed date elapsed time.

188
00:12:51,380 --> 00:12:52,900
Now I can't say.

189
00:12:53,300 --> 00:13:00,700
So let's create a variable of types 3 and in order to specify that unique filename that's unique imagining

190
00:13:00,860 --> 00:13:07,630
like strange and the name of this variable is going to be unique emerge.

191
00:13:07,960 --> 00:13:14,870
The assignment operator so here I can say I can't put two coats.

192
00:13:15,070 --> 00:13:24,160
I can I can put us last year plus I'm concatenating this value of another value plus current state plus

193
00:13:25,610 --> 00:13:35,770
unable to Cote's yet underline plus elapsed time plus two coats or image or image format is going to

194
00:13:35,770 --> 00:13:38,170
be actually of type P and G.

195
00:13:38,200 --> 00:13:38,590
Right.

196
00:13:38,590 --> 00:13:43,430
So I'm going to put that P and G that says semicolon.

197
00:13:43,500 --> 00:13:48,440
This is going to be the unique image name that the user can actually create.

198
00:13:48,690 --> 00:13:55,200
A bunch of times like unlimited times the user can create image a unique image names with unique names

199
00:13:55,260 --> 00:13:57,320
right in the same folder.

200
00:13:57,510 --> 00:13:58,760
That's the trick.

201
00:13:59,010 --> 00:14:00,420
This is really important.

202
00:14:00,450 --> 00:14:01,270
This is the trick.

203
00:14:01,290 --> 00:14:05,070
In order to create unique filenames in the same folder.

204
00:14:05,070 --> 00:14:06,890
Use it in your own projects.

205
00:14:06,900 --> 00:14:09,060
So after this line of code I can say.

