Welcome back and this video we are going to create to finish activity, which is the activity that you
can see here, and this activity should come up once we're done with the exercise.
So once we're done with exercise number 12 and then you can see this is what we should get.
So a finish button here at the bottom.
Once we click on it, we get back to the start activity or our main activity.
And then you should also have this little text here and then a text there and a look shape.
So this is something that you can try to build yourself.
You should be able to do that by yourself now.
And yeah, just see it as an exercise that's really good practice to do those things.
And then once you're done, you can go ahead with the next video.
But if you want to follow along with the video, you can do so, of course, as well.
So let's get started.
First of all, we need to create a new activity, so let's go ahead and create an empty activity and
I'm going to call this one finish activity.
And everything else should stay the same.
Click, finish.
And there we are.
So let's go into the layout, out the finish layout, and I don't want to use a constraint layout here.
I want to use a linear layout.
So that's what I'm going to do, a linear layout.
Then I want to have a toolbar here at the top, so let's go ahead and add one and I'm just going to
base it in here.
You can, of course, type it in.
So that's a toolbar.
You can see I gave it the name.
I called it to finish activity.
Then we have the width of each parent and the height of attribute action bar size.
So this is a size that is predefined.
The background should be wide and that's pretty much it underneath it.
I want to have a text which should be called TV.
And so this is going to be with a little margin towards the top that's going to wrap its content in
with and height, it's going to say, and and it's going to have a text size of thirty five and the
color accent, which is our green color as it's color.
And then I want to have another linear layout which contains.
The following elements here, you can see here this little circle, and in order to create that, we
are going to use the color X and border again and an image of you.
So I'm going to step in and explain them real quick so you can see I'm creating a new linear layout
with a with and height of 150 density pixels.
The gravity should be centered.
The margin top is 15 density pixels.
And I'm using the items circular color, X and border, which we've used before, which is just a stroke
of five density pixels, which is green and has a solid background, which is white.
Then I need an image of you and here I'm going to use this, I see action done.
By the way, I have a little content description here with and height.
So this is this little.
I can hear and I will show you how to create that, let's create this little icon.
So let's create this XML file.
And I pasted the code in.
So this is the code that you will need, and that is the width of 24 density, pixels, height as well.
Viewport with is also said to 24.
The tint is said to this green color.
And I have an alpha of point eight.
So it's slightly transparent and then I create a path here.
So this path creates this little icon.
And you could see this is the path data that I have here.
It's a little confusing, but you can just use the path data here.
If you want to know more about path data, you can check out the specification of operation that defined
the path.
So you should also check out the documentation for this, because basically what we are saying is I
want to have a path which takes these coordinates and creates pretty much what we see here.
So this little check, Eichen.
There are, of course, many options how to do that.
You can, of course, Google it, Android double check.
I can and make a check.
I can using XML drawable.
So here, this is the check.
I can.
This one is a little different color, but there's no problem.
And here this is a template that you can use.
So he did it with a layer list here where he said, OK, we have one item, then we rotate that with
a certain amount and then another item, which we were Tait's differently and so forth.
All right.
So there are multiple ways to get to the same solution.
So that's why I think it's fine to use either way.
In the end, what matters is what you get as a result.
And this is just one way that I used with this little.
So this is not something that you have to come up yourself, and that's not something that I would expect.
All right.
Just so you know.
All right, coming back to the activity finished, you can see the problem disappeared and now.
I want to have two textures underneath it, as you can see here.
Congratulations, and then you have finished the work out.
So let's add those two.
And I'm just going to paste him in again because there's no use in you watching me type it all out.
So you can see I just have this text called Congratulations.
I have this dark gray color, 18 USPI, 25 density pixels as a margin top.
So there is a little distance towards the top, as you also can see, of course.
So there's enough distance between them.
And then we have finally this finish button, which also has a little margin towards the top of in our
case here.
Thirty five density pixels.
So I also gave it an ID so that I can access it.
And once you click on it, something will appear.
You can see the height is wrapped content and the width.
I said match parent so it should take the whole with that is available.
The level of gravity is search to bottom.
The margin is set to or margin top at the 35 pixels.
I have this color as the background color.
The Texas finish and text color is a white color here and then of course 18 S.P. for the text size.
All right, so that's the activity finish XML file then we should also check out the manifest.
So let's go over to the manifest.
We can see we have this new activity here.
Actually, there it is, finished activity, and I also would like to add the same settings as I've
done in the other ones, so I said the screen orientation to portrait and I said the action bar.
Or the theme to no action bar.
All right, so pretty much the same thing that I've done with the other exercises or the other activities.
All right.
So that's our interest manifest.
And then we need a moment from which we get to this activity.
So we need to add that at one point.
So how do we get there?
Well, I'd say we get there by going from our exercise activity because that's basically from which
we should move over to the finish activity.
So let's go to our exercise activity.
And here we had this moment where the exercise timer went up.
So here on finish inside of our set exercise progress bar.
And there we have this on finish, and then we constantly went on and created the next exercise.
I don't.
You can see here there was only this little post saying, congratulations, you've completed the seven
minutes work out now, of course, instead of just writing a toast here.
I'm just going to do it with sending you to the next activity.
So what I do is I finish first.
So I finish the old activity, meaning the exercise activity.
So then if we press the button that we don't get to the exercise activity, but we get back to the home
screen or the start screen and the same, if we start an intent that we go to the start screen.
So then we need to create an intent here and it's going to be of type intent.
And here we need to import intent, so let's do that then I want to pass and this but in particular
this exercise activity, because I need to pass in the context and in this case, this exercise activity
is the right choice.
And then I want to go ahead and pass in the class that I want to start.
So finish activity is the one that I want to start.
And I'm going to use the classical approach that we had here class, not Java.
So when we do that, you can see that the arrows disappear and now we can start that intent.
So let's go ahead and start.
Activity with the intent that we created so intent.
All right, so at this point, we can move over from our exercise activity to the finish activity,
but now let's have a look at the finish activity, because in here we have nothing except for setting
the content view.
So nothing too fancy.
But what I would like to have is I would like to add support action bar.
So I'm going to set the support action bar to two bar finish activity, which is this two bar that we
have had in here in our XML code.
Then I want to have an action bar, which is a support action bar.
So I'm going to go ahead and check.
If that's not now, then I'm going to set the display home has enabled so this and empowers our back
button.
And then if we press that button, then I want to go ahead and call this on back prest.
So if we press this toolbar finish activity, which is this toolbar button, so to speak, then I want
to have this set navigation on this now, which means this back button when this was pressed.
And I want to call this function on back press, which is the default functionality for on back pressed
so that we'll try to do is go back to the last activity, which should be the exercise.
But if the exercise is actually finished, that will not be the exercise, but it will directly be our
main activity because here you can see we finish the activity.
So it's multiple layers of activities.
Right.
And we start with our layer of the main activity.
And then we put another layer on top, which is the exercise activity.
And then once we are done with the exercise activity, what I say is get rid of this exercise activity
layer and start this intent to go over to the finish activity.
So pressing on this back button should not bring us back to the exercises because they are closed.
So the stick is empty of it.
So it's not there.
The exercise activity is not on the stack.
So it will just get rid of the current stick element, which is our fitness activity, and directly
go to our.
Starscream, and then what I, of course, want to do is I want to do something once we click on this
finish button.
So remember, we had this finish button here at the very bottom, so and here in our activity.
If you look at it.
And it seems we still have an error somewhere, so let's look at that linear layout.
As it seems, the orientation is still missing.
So let's add on an orientation here, said orientation.
I kept my ID, doesn't want to play with me here.
So orientation.
Which I'm going to set to vertical because I want to put stuff on the left of each other.
All right, so then this line is spread out, so we're not going to need that and now we can see our
activity, you can see now this is how it currently looks.
So I need to send her stuff still, and in order to do so, what we can do is we can add a line here,
which is the gravity.
So I'm going to set the gravity to center horizontal.
Now, let's look at it again.
And we can see now everything moved over to the center.
OK, so that is our UI.
And now once we click on this button finish, which is this big green button.
This one here, then we will call the finish function, which is also built in function, which then
just finishes the current activity and then goes back to the one on the and layer, which in our case
means that it will directly go over to our start activity because that's the last one on the stack.
Right.
So the thing is, if you want to test that, then you will need to go through seven minutes of listening
to the exercise names.
So what I did and what I would also recommend you to do is to go to your exercise activity and then.
Change to exercise time, duration from 30 to one seconds.
And then to do the same thing with our waiting duration as it seems like.
OK, so let's create another private bar rest time or duration, which I'm going to make a long as well,
and I'm going to set that to one as well.
So reset Oreste timer duration.
I'm going to set that here.
Time's.
And then one thousand, all right, so this is the best progress bar countdown timer, so now we can
directly change.
The duration to just one second, for example, because this will make our life a lot easier when testing,
of course, you can also go to your manifest and make your finish activity become your start activity,
but then you can cause some other problems because your main activity will not exist in the stack.
So you cannot really test it properly.
So we need to go through this process.
And I'm just going to post a video while I'm going through all of the exercises because it's going to
create a lot of noise.
So I'll just pause to be right here on the recording because you could see it's moving.
All right.
So here we are at the next exercise and there we are.
So we went over to the screen and as you can see, it doesn't look as intended.
So the background is still great.
So let's take care of that.
And by the way, it has to do with our activity here, so I'm using the no action bar theme, but I
should use to light no action party because that will then get rid of this problem.
And that was pretty much the same error that we or issue that we had when working with our exercise
activity.
Now, let's test it again.
And let's see how it's going to look.
So I started.
All right, and there we are.
So I ran through the exercises and you can see our screen, so we have the light no action bar theme
here and things are looking good.
So now let's press on the finish button and you can see we get back to the home screen now.
Let's test it with the back button.
Let's see what happens there.
And by the way, if you don't want to go through all of the exercises once again, you can, of course,
also change one more parameter here.
And that is the question here, where you have this if statement.
That is this one here where we checked in on finish exercise list size less than so and so.
So what you can, of course, do and this is something that you should only do for testing because otherwise
or at the next moment, you should definitely uncommented this again and replace the coat.
But you can do something like less than two and then it will jump very quickly.
So let's test that as well, because this is going to save you a lot of time when you test that many
times.
OK.
In our case, we just tested very few times because it's rather easy.
Well, sit and then see what is it and that we are.
So you could even make it less than one.
So it jumped directly to the finish screen.
And now let's press the button.
And you can see we also get back to the home screen.
We don't get back to the exercise because that's important.
We don't want to use it to get back to an activity out of which he cannot jump out because potentially
he cannot get out of the exercise activity.
Of course, you can also press the button again, but that's not good behavior.
So that's also something that you always need to consider when building your UI and building your user
experience.
OK, so now I'm going to, of course, get rid of this line and uncommented this line so that things
are as they were intended and then we're done with testing.
So we know that now we can go ahead, of course, and change the rest time of duration to 10 seconds
again and exercise time of duration to 30 seconds again.
All right.
And that's it for now.
And the next video, we're going to create a custom dialog for the back information so that the user
once he presses this button.
He's getting stopped from it because maybe he accidentally presses this button and then he's exercise
and he gets back to the start screens, and that's something that can be super annoying for a user.
And that's also something that we need to really consider when building our application.
OK, so see you in the next video.