High students in this Tauriel I want to talk about a l Android interface language definition.
So now let's create a new Android studio project and for the application name just hit app 1:53 dash
a.
So you can specify the company domain package name and the project location and then click on next and
here choose a 16 Android 4.1 jelly bean and it connects.
And here too is empty activity next.
And here you don't have to change anything.
And then click on finish.
So now that our project is actually created Let's go to let's first design the user interface of our
application so called Inside this race that lay out and then double double click on this activity underline
that example.
So here let's delete this hello world takes you here and now let's actually tried to a text field inside
this layout.
So at the bottom first click click on this text tab and change this relatively out to linearly out.
And now let's specify the orientation of this layout orientation vertical.
So let's go to design tap.
And now let's drag two text fields.
So it's 36 minutes for the just selected number.
Right.
Select this one and just drag it into this linearly arithmetic.
Let's actually try another text with.
So again select this number and just track it here.
So now we have to edit this here right to takes fields.
So just select this one the first one and let's specify the ID sort for the ID just type in here it
is the first number and the person tells you on your keyboard and for the set this second detects you
are selected and for the idea just type in here.
EDT.
Second number right and that person enter key on your keyboard.
So now let's actually track a button into these lay out.
So inside this we just fall there.
Select the spot.
And just like it here and put it here below.
It takes here and just select this button and for the idea of say in here Betty Betty and multiply Pythian
multiply and then person until you are on your keyboard and for the text to say in here let's select
the text attribute and just type in here or multiply multiply and that person an interview on your keyboard.
So now let's actually just write a text view.
So just select it takes you here and put it here below the Spartan and select takes.
And for the idea to step in here takes the multiply result takes the multiply result and then person
enter on your keyboard and just delete this value for the text attribute of this text.
So now are we actually designed the user interface or application.
So now I want to talk about a idea.
So first let's see how we can actually create a idealy an android.
So just select this app folder there so make sure that you are inside the Android view.
Right.
So if you just click on these two little triangles here make sure that you have selected Android and
select this app folder at the top click on find new and in just here you can see this idea right.
So just click on a IDL file and here you can actually specify the interface name.
So for the interface name we can say for example here the default name is my up are it a the interface.
I think it's good.
This is actually an interface and other classes can implement this interface can't conform to this interface
so that they can actually use the functionalities of this interface.
So let's just name it.
Multiply multiply interface aren't the target source is me.
So just click on finish.
So now as you can see inside this app folder we have another folder called IDL.
And inside this folder we have our package right.
And inside this package we have this wide multiplayer interface that IDL.
So look at this comment here it says demonstrates some basic types that you can use as parameters and
return values in IDL right.
So here you can see these totals as you can see it's essentially a Meffert basic types.
These are the types in integer Lanc boolean float double and string.
So let's actually delete this comment and this method here.
So here as you can see we have an interface right interface multiplayer interface right.
So let me tell you that the end is used for actually creating a relationship between the client and
the remote server.
Right.
So for example the main activity is the client and the server is going to be of the class that is actually
playing the role of a server service.
Let me show you an example here and then it will completely make sense right.
By showing you by creating a real application you cannot actually understand what is ideal used for.
So now inside this interface inside the curly braces of this interface let's write some code.
So now as the name of our interface suggests this is going to be an interface for multiplying values.
Right.
So here I am going to declare a method for that is anybody going to use for multiplying values.
So here I can see it.
So this is going to be the return type of of my method right.
And here I can say multiply multiply two values two values together and then here I can just put a pair
of parenthesis so this method is going to accept some parameters to make parameters actually.
So the first parameter is going to be of type integer.
So int and here I can say first number comma.
And so this is going to be the second parameter second number and because this is actually an interface
and you are already familiar with interfaces in Java you cannot provide a body for this method.
This is going to be a declaration of this method.
So if you just need to put a semicolon at the end at the end of our statement here right we just declared
this method we do not provide implementation here inside this interface.
So now let's actually create a service so at the top just click on file first.
Let's go to view here.
So at the top just click on a view and then open windows and then click on Project.
Right.
And now we want to actually create a service that implements this interface that implements this IDL
here and then we can actually use that service.
So let's actually select this top a failure here just open it and then select this package and at the
top just click on find new and then click on the service to select a service here.
So this is the service right.
And then here we have two options.
Service and the second one is service intent service.
So select this one service here and for the class name.
This is going to be a class.
Right.
So here I can say multiplication multi placation series.
So this is the name on what the name of my service.
Right.
And then click can finish.
So now we have a new class and the name of this class is multiplication service.
Right.
So you can see that this is a public class and this class extends the service class.
So in the inside this class we have this empty constructor that is actually already provided for us
by Android.
And we have this method that is overrated here.
And as you can see some of this if it is actually an bind that returns a value of type A binder.
Right.
So now let's see how we can use the Smiff.
So look at this comment.
It says Return the communication channel to the service.
Right.
So now let's just double click on this tab here.
This multiplication.
So we start over top in order to make this area there.
First let's actually delete these two lines of code here and now I mean I dismiss it right.
First of all Vin Weber that you actually create an ideal file.
So now let me show you that file here view tool windows and then project.
So inside our project we have this idea file right with the extension dot a IDL white men over it that
you create a file that is actually has the extension a IDL.
You must actually build your project.
So at the top click on build and here you have two options.
Clean project and rebuild project.
So when you choose the rebuild project it's going to first clean your project and then it's going to
build your project.
So it's better to choose this option.
Rebuild the project.
So just elected.
And as you can see at the bottom it says great deal be threatening.
So let's wait a little bit here.
So now as you can see it's actually running.
So now everything is OK.
Right.
And now my project is to rebuild.
So now let's go inside this method on buying it.
Look at the return type of the Smurfette I'd buy in there.
So here we must through of value of paper.
Are you buying that right.
So here first let's put this statement here.
So just step in here return return my binder semicolon return my binder.
So this is going to be the return value.
But as you can see we have an error and this means that we haven't created this return value.
So now let's actually tap to just publicly tap here in order to make this area wider.
And let's go inside the curly braces of this clap class multiplication.
Right.
So after the end in calibrates of this Meffert unbind and before the end in Crilley place of this class.
So inside this class just typing here.
So the name of our IDL file is actually multiply multiply interface.
So here we want to create an object of type A binder right.
So in order to do that first we first read the name of your ID or find multiplayer interface dot stop.
This is really important stuff.
With capital S and now we can actually name of name or update we can give a name to our object.
So the name is going to be this name right.
My binder.
So here I can say my binder assignment operator.
So now let's create an object.
So here you're actually just creating a variable of type multiplayer interface that stop.
Right.
So now let's create the actual object.
So in order to do that first you need to put the new vote and then you just you just need to put.
You just need to refer to your interface to your ideal file multiplayer interface.
So when you put the capital in here it's actually the auto companies feature of Android studio is going
to help you to choose this option.
Stop right.
Start with chapiter.
And inside the curly braces you can see these dot dot dot.
So select this one and then press not.
On your keyboard.
So now the autocomplete feature of Android would you put these lines of code here for you automatically.
So here we have an error and after the end curly brace here just put a semicolon.
So now the error is gone.
So now here let's create a new line so that you can assume it can actually the whole method here.
You can see the whole method here.
So now we have actually the over write it up.
We have we have a new order right at Mefford and the access modifier of this method is probably the
return type of this if it is integer and the name of the Smurfit is multiply two values together.
So as you can see we have actually a typo.
Let's go to our multiply interface that IDL So as you can see I did I did a mistake and instead of you
I put y.
So let's just delete this Y and put you multiply two values to get that.
So let's go to our series multiplication service.
And now let's actually change this one to you.
So because we actually changed our ID file again we must just build our project so at the tactical we
can build and then selectively build project.
So let's wait a little bit here and now everything is fine.
Right.
We have no errors here.
So here we have this method.
Multiply two values together and this Smif it accepts two arguments.
The first one is that integer first number and the second one is of type integer second number.
Right.
So now as you can see this MF'er the froze an exception.
So if you want to actually use the Smurfette then our main activity want to use the Smurfette we must
actually handle this exception.
So this Meffert by default returns a value of type integer which is zero.
So we don't want this statement here.
Just delete it.
And now as its name suggests multiply two values together and say return.
So now we have this Meffert accepts two prime hitters right.
So I the first the name of this first number first number multiplied by second number.
So now you can see that this service is actually implemented in this interface.
This multiplayer interface that IDL.
Right.
So we created an ideal file here.
And as you can see this is actually just a simple interface right and you are already familiar with
interfaces in Java.
And we created a service which is this one multiplication service and this service is actually implementing
this interface so that we can actually provide an implementation for them for them if at this interface.
So now we have this Meffert here and this certainly as you can see we have actually an over Meffert
and this service needs to return a value of five and a binder right.
So if we just returned this my binder here.
So now let's go to our main activity here.
So this is going to be our client.
Right.
So now we can actually just interact with the remote service.
Right.
So if you have actually an interface and we have a service and we have a client which is the main activity
and the main activity can interact with the remote service by this idea find this multiply into an interface
that idea.
So that's the whole concept of a deal in Android right Android interface language definition.
Right.
A d l and that's the whole concept.
And now you can actually figure out what's going on here.
So let's go to our main activity and let's see how we can use this service.
So first of all let's actually just declared this the objects the user interface components that we
put here.
So we have to edit takes we have a patent and we have a text view.
So let's go to main activity and say this class here.
First I can't say that it works.
So here I can say it is your first number the first number so I can actually declare my two objects
which are of type.
It takes in just one line.
So comma it is the second number.
Right semicolon.
And then if you have actually a patent spot in between.
Multiply
semi-colon and we have a Takes view so it takes you to 60.
Multiply multiply result takes the multiply result semicolon.
So now let's go inside the Smurfette uncreate right.
And now let's initialize these Optix that we actually declared inside our class.
So the first one is a little first number assignment operator and then we need to cast this object on
any text object find view by ID or that Id dot EDT first number semicolon.
Is the second number assignment operator let's cast this object to an end it takes up to act fine.
View by ID or data ID that EDT.
Second number semicolon.
And we have this button in between and multiply so between multiply assignment operator let's cast this
object to our button object find view by ID or that Id that PTEN multiply semi-colon and we have THC
multiplier is that.
So the multiplier is an assignment operator.
There's that cestus object to our text view object find view Id or ID that he likes the multiply.
Who is that right.
So not everything is fine everything is OK.
So now let's see how we can use this service.
So first of all let's create our listener for the spot in the city and multiply.
So whenever the user clicks on the spot in this button something is going to happen.
So here I'm going to actually implement the view that unclick listener interface.
So class main activity extends app compact activity implements you dot unclick listener.
So now here inside is uncreate Smurfette.
Here I can say PTEN or multiply that set unclick listener.
And then here I need to pass the context so the context is an activity that this and then here inside
the class inside this main activity class we must actually provide an implementation for the uncleaned
method.
That is that is inside of this view that unclick listener interface.
So inside this class I can just see unclick and here and click and now the autocomplete feature of Android
studio is helping me to use this method and then person enter on your keyboard.
So now we have the Smurfette here inside this class.
So let's go to our uncreate Smurfette.
And here we have actually a method called Blind service.
So now we may want to ask ourselves what we want to do here if we want to bind this our main activity
this client of this service.
So we want to use this method bind service.
Right.
So let me show you what are the arguments of this method.
The first argument is going to be of type service right.
And as you can see the first one is actually of that intent and the name is service.
So we need to pass the Internet.
And the second argument is this service connection and the third argument is actually Flack's which
is I-5 integer.
So we need to pass these arguments through the Smurfette so that we can use this method.
So let's see how we can do that first.
Let's actually create.
The intent as you can see here.
So before the declaration before use the people calling this method bind service we need to actually
create the intent.
So let's do that here.
So here I can't say intent intent
right.
And that name is going to be months play intense multi
multiply intent assignment operator.
And then when you say we are just creating of value but of intent and the name is multiply intent.
So now we want to create the actual object of intent.
Right.
So here I just put new.
And then I can just say intent and this method should add that the constructor of intent needs two arguments.
First we need to pass the context.
So here I can say main activity that this comma and the second argument is going to be service right.
So if we actually hover over this bind so we see it it says the first argument is actually off that
intent but the name is service.
So we already created this multiplication so we see it right.
So for the second argument I can pass this multiplication service here so I can say multiplication.
So we start a class semicolon.
Right.
So now you know that YV actually create a disservice because we want to bind this may not be with this
client we deserve service right.
And now if we pass this multiplication said was here.
So now we have the first argument multiplied into.
So here I can say multiply intent karma or I can say multiply servies.
It's better to actually put multiply so.
It's more meaningful multiply series.
So let's change this one two months to play service.
So now we need to specify the second argument.
So the second argument is actually a service connection.
Right.
So let's actually create an object of types that service action inside is main activity class.
So after the end curly brace of the Smurfit uncreate an insight is main activity class.
I'm going to create actually an object of service connection here.
So here I can say service connection service connection and the name is going to be my service connection
my service connection.
And then I put an assignment operator here and I put the new keyboard.
And here I want to use it.
I actually want to create an anonymous in a class.
So let me tell you that this service connection is not a class.
This is just an interface.
So let's let me just hold the combination on a keyboard and then click on the service connection here.
As you can see this is not a class.
This is an interface here with this if it's on service connected and answer was disconnected.
Right.
So you want to actually use this interface.
So now here I am going to create an anonymous class that actually conforms to this interface that implements
this interface.
So here I can see new and then I hold the shift key on my keyboard and then I actually present them
as key on my keyboard.
So now it's you can see that the autocomplete of the autocomplete feature of Android studio is helping
me to choose this option.
So misconnection right as you can see you can see these curly braces such as this one and they press
that intellectual keyboard.
So now you can see that the Android studio provided these quotes here for me automatically.
So now we need to put a semicolon at the end of this or calibers year after the ending calibers and
now everything is fine.
So if you have the anonymous in a class that conforms or implements this service connection and if you
have this tumor if it's you're over rated for us we must actually provide an implementation for these
methods because this is an interface.
So now inside this on we can act.
So we want to use the Smurfit on service connected.
Right.
So we need to put a logic.
So now first of all let's create a valuable of type multiplayer interface inside our class.
So let's actually scroll to the top and inside is main activity class here.
I can just create a variable of multiplayer interface.
So here I can say multiply interface.
Let's actually keep this valuable name right so that the data type is multiplayer interface.
And here I can say my interface right my interface semi-colon.
So now let's actually scroll down here.
So here we just declare this valuable right.
My interface.
Now let's scroll down here and let's go inside this on it connected.
And now let's initialize disparity table.
So here I can see my interface assignment operator.
So look at the Smurfette here on service connected.
This it accepts two parameters.
The first one is component's name and the second one is a binder.
So if you want to use this binder here because we want to actually bind this client main activity with
the interface right with this service.
So now let's actually just type in here.
Monte playlets actually refer to the name of this interface multiply interface that ADL.
So here I can say multiplayer interface multiplayer interface that stop here and that here I can say
that as interface and design if it actually needs an argument of type I bind.
So we actually get this a binder from the Smurfit from this on said Can I get my fit.
So here we can pass this binder to the smith.
So here I can say a binder semi-colon.
So by using the service connection we are actually connecting these Servius this multiplication service
to this interface.
We have the second argument of this point service Smurfit.
So the second argument is my service connection.
So we created this one here.
Right.
And we actually provided the first argument.
So the first argument is of type integer and it is actually a flag.
So here I can say so now as you can see I actually saw it.
I mistakenly deleted the name of this value.
So let me actually undo this action.
So I put a name here so now we have my cell connection right so I can put the comma here.
And now you need to specify the first argument.
Right.
And now that the argument is of type integers so it is actually going to be context.
So this is going to be a flag.
So we must put the flag here.
So here I can say context dot and here we actually choose this one bind auto create write bind all to
create.
This is really important this is the flag that we use.
So its going to bind this service with that interface.
So just put a semicolon at the end of your statement.
Right.
So now we have this spine was here for us.
So its going to do the job for us and we pass these arguments multiply service.
So this is the intent.
And then we have the service connection and then actually the past display context that bind auto create.
So now the binding is actually implemented here.
So let's go to these uncreate method here.
So first of all let's actually just as you can see we have these Eadie takes here.
Right.
So if you want to get the value of this as it takes and this one and then if you want to multiply these
two values together.
And then when the user clicks on this button the result is going to be shown here on this TXI the multiplayer
is out.
So let's go to the street uncreate Mefford.
And here I can create a variable of type integer and the name of this value.
But it's going to be first number first number and then I put an assignment operator here and in here
I can say it is the first number that get fixed that two is three semicolon.
So now as you can see we have an error and because this is actually the end it is invaluable.
Here we are getting a string value so if you want to cast this value you want to just convert actually
this value to an integer value.
So we use the method of the integer class.
So integer parsing.
So you are already familiar with this method and this method accepts an argument of type stream and
it's going to convert this value to an integer value here.
So we actually put this value inside the pantless.
So is the practices of this parsing Smurfit and now the error is gone let's create another rowdier but.
Second number assignment operator.
So integer parsing it has a number that takes that string semicolon.
So now let's create another variable.
The end result.
Assignment operator.
So let me scroll to the top here.
You can see this interface at my interface so we can't actually access the method that we have inside
this IDL file.
This one and we actually provided an implementation for this method inside the service.
So inside this main activity class and inside is Uncle Mefford we actually binded this service with
this client here.
So we created a connection between these services as you can see we provided this my service connection
here right.
So it's going to create a connection between the service and this idea right.
And now these service is my interface it is now initialized.
Right.
So we declared disvalue but my interface and be initialized this rally about here inside this on service
connected.
Right.
So now we have this interface here.
So it's resolved.
Assignment operator and here I can refer to this my interface and now I can see that multiply two values
to get there.
So now I can pass two arguments to dismiss it.
So the first one is going to be for example the first number.
So we get this value from the first actually editrix.
So first number we have a type here.
So the first number and we need to pass the second argument so second number semicolon.
Right.
So now we have actually an error.
So let me show you what is this error.
Let's actually hover over the scanner here and says unhandled exception Android that.
Or is that remote exception.
So now let me show you why we have this exception.
So let's go to this idea file.
As you can see we declared this method here.
Right.
But we provide it at implementation for this method.
Inside this model application said we start Java.
So here look at this piece of code here inside this block of code.
You can see that we actually overwrite it dismiss it.
Multiply two values together.
So we get dismembered from this interface must multiply interface.
And now you can see that it actually froze an exception.
This is really important so because the sniffer froze and it's an exception and it is called the remote
exception.
The Actually must handle this exception.
Otherwise the compiler is not going to allow us to run our application.
So let's go to main activity here.
And inside is actually Smurfette here.
Before this line of code here is actually just typing try I can provide a try block here.
I can't try and then put a catch block and that here inside the parenthesis of this catch here I can
say REMAUT exception.
So you know what is the name of that exception.
Right.
So because inside is so multiplication so we start over.
You can see the name of this exception.
So let's go to the main issue with the Java here.
And inside the sunken ship.
So the type is more the exception and the name is eat right.
And here again just open and close this catch block by using these curly braces.
And here let's just select this line of code here and just cut this line of code and just paste this
line of Cahir inside is try block.
Right.
And now the air is gone.
So now we have this valuable result.
My interface that Multiplex Jubilees together and now we're actually handling this exception because
we put it inside is triplex.
So if we can actually just print.
So here I can say Eat Eat at a print stack trace.
Right.
So we can just print these values to the larg later when I should and Eric Harris.
So we have this right here.
And here I can insert this tripe like I can say TXI the multiply these are the set text.
And here I can refer to the name of this rally about a result but because this is actually an integer
value and if it needs are valuable a value of type string I can convert this value to string value by
just putting a plus operator and then put to double quotes here.
So now let's run our project and see what happens.
Let me show you the emulator.
So now as you can see here my application is running on this emulator.
So now we need to provide the first value.
So the first value is going to be number 10 and the second value is going to be number.
For example again 10.
So let's click on the.
And we have number 100.
So let's change the first value to 5.
And the second value 2 numbers to right let's click on this button again.
And now we have numbered 10 or less change the first value to number three and click on this button.
Now we have number six.
So now you can see that how we used this IDL in Android.
So I think now you can actually figure out how to use a million Android and if you have any questions
about these concepts that I taught you in this lesson please post the discussion in the course and then
I'll do my best to answer all of your questions.
Thank you very much for watching and I'll see you in the next Steve Tauriel.