(upbeat music)
(swoop)
(typing)
In this section we're going to create
a basic calculator, as you can see on the screen,
and that's gonna give us a chance to practise
what we've learned about layouts
with a more complex example and we'll also be
connecting code to a lot more buttons
than in our previous button click app.
In this section, we're gonna look at
working with groups of widgets to see how we can do things
like constraining them to be positioned as a group,
as well as setting common properties
for multiple widgets at the same time.
And we'll also show a slightly different approach
to creating on OnClickListener,
so that the same method can be used by multiple buttons.
Now this app as you can see is a basic calculator
and it will let you enter numbers using the app's buttons,
then perform the calculation when any of the
operation keys are pressed.
The plus, minus, multiply and divide.
Now the stock Android calculator builds up the
calculation on the screen, and doesn't actually
evaluate it until you press the equals sign.
But ours is going to evaluate each sum
as soon as you press the next operator,
just like early calculators did.
And we'll have two lines for display
so you can see though,
so you will be able to see both numbers at once
and won't have to remember the previous one,
like you did with those early calculators.
And also, unlike the early calculators, it'll show you
which operation it will perform next,
so you don't lose track.
Pressing equals will update the display with the result.
It can also be used to start a new calculation
by transferring the entered number up into the result,
ready to use in the next calculation.
First let's have a quick demonstration here
of this calculator app to see how it actually works.
So I can enter a number like by clicking on it,
nine
and multiply three equals 27.
Then I can also continue with that
by putting 10
multiplied
and you can see the value's getting updated there,
and we can clear it by just pressing equals,
and I can type in something like 20
plus
to add 20 to it so I've got the value of 290.
And the other thing that we're gonna be doing
in this section of the course is working with
both portrait and landscape versions.
So if I'm going to serve it to landscape now,
and you can see we've got a slightly different result there.
We've got the layout looking a little bit different
to take advantage of landscape mode.
So we'll be learning how to do that as well.
I'll just move that back to portrait.
And then also I've got the value that we've been using
stayed there when we moved from landscape
back to portrait, and then from portrait to landscape.
And we'll also be showing you how to do that
in this section of the course as well.
And later in this section, we're going to have a look
at guidelines, which can be used in a constraint layout
to a link which is either vertically or horizontally
so that you can anchor widgets to them.
Right, so let's move back now to Android Studio
and we can start work on this project.
So let's get started now creating a new project
and then in the next video we're gonna look
at the actual layout of our calculator.
So start Android Studio and we're gonna click on
start a new Android Studio project.
Now I'm gonna call this calculator,
(typing)
I'm going to leave the company domain name the same,
learnprogramming.academy.
Now Android Studio's suggesting a suitable location,
project location, ending with a care calendar directory
and you can store the project somewhere else if you want.
But Android Studio normally remembers where you've told it
to create projects so only the
fallout directory name changes.
So I'm gonna leave it as the default onscreen there,
and there's another important option we have to select
on the screen, and that's this option down here to
include Kotlin support.
Now remember to tick that box if you wanna generate
Kotlin code and make sure it's unticked
if you want Java code.
In my case, I'm going to leave it ticked
and click on next
and we're gonna continue to use the minimum
STK of 17 and you can see this API 17
is already selected here.
So you wanna make sure that that is checked
and leave everything else unchecked
and then click on next again.
Now we're not going to have a menu in this application,
so empty activity which is selected here
for me automatically is our best choice
for the template to use,
so make sure you select that
and click on next again.
And once again we're just going to accept the names
that Android Studio has suggested for both the
activity name and the layout name,
and just make sure that both the generate layout file
and backwards compatibility AppCompact check boxes
are checked and then click on finish.
So that's the project created,
I'm gonna leave it just building
and in the next video we'll actually start producing
the layout for our calculator app.
So I'll see you in the next video.