♪ (robotic music) ♪
Hi, now that you know exactly what Android is,
let's just create our first application in Android.
To create that, you will be opening up your Android Studio
and you will be presented with this window.
And once you have downloaded all the SDKs,
then you can go ahead and design your first application.
Click on the start a new Android Studio Project.
Here you need to give the application a name.
Let me just call it MyHelloFirstApp.
And this is your company domain name,
it can be anything you'd like it to be.
In my case, it's com.example.demouser.
Combining this Company name and Application name,
your package name will be formed.
Make sure this package name is unique
because when you're going to upload your APK at the end,
that APK package will be checked out
by your Google Play Store.
If it is not unique, at that point in time,
you might want to change that package name.
If you try to put this com.example.demouser,
is has already been taken by Google, for example,
you can't upload an application like this.
Let's say you put com.planet.MyHelloFirstApp
and that domain is also taken by somebody else,
then you cannot upload it.
It has to be unique.
Next, this is your project location, for our example purpose
we are going to use this package name only.
This is the project location, where our project is going to be saved.
You can change it if you like. Click on Next.
Then you have to select minimum and maximum SDK here.
Maximum by default will be that latest one
that is 25 API or if you're using 24, 24 API.
And then there will be a minimum you will have to select.
I could have gone all the way down to nine
and you can see I will be targeting
approximately 100% of the devices, right now, in the market.
The problem here is the more I go down
the more I'm sacrificing the features.
Because the Gingerbread will not contain
all the features which my Android API 25 contains.
Of course, even if I am selecting 15,
15 will not contain all the features
which my API 25 contains, right?
But till 15, I can get the Android Support Library,
that is the external leverage provided by the Android Framework
and you can get those libraries
to support those features up until a version.
I cannot get support libraries below--
all the way down to the 2.3.
So that's why you need to make a balance also,
and you can see while I'm selecting API 15,
I can still target 97.4% of the devices.
That's a good thing.
Go to Next, then you will see all of these templates,
you can select any of these templates to start
your Android application development as we are starting our very first app
and we are going to start from scratch.
I will click on Empty Activity and press Next.
Give the name of that activity, I'm going to call it MainActivity only.
That's it.
You can give any name, whatever you like,
this will ensure that you're creating an activity name
that is the Java file, plus the layout that is the XML file.
It will create a layout file, if you don't want that, uncheck this.
But you definitely want the UI bar of your activity also,
how, exactly activity will look like on the screen.
You want that,.
And then there is a backward compatibility checked.
Turning this on that means your activity
will be extending AppCompat activity.
If you uncheck this then your activity
will be extending extended activity class.
So backward compatibility is to make sure
that even the previous versions
are able to access the new features
which are there in new versions
with the help of support libraries.
Press on Finish.
Let the Gradle build. Gradle is a building tool here
which is used by your Android system to build your application.
Please, wait for Gradle to build your project first.
If you try to keep on clicking here and there,
your Gradle might crash.
You need a pretty fast machine for Gradle not to crash.
So let the Gradle build, once the Gradle--
you'll see down below "indexing is done" and Gradle is built,
after that, you can see this is the Java file
that is MainActivity, the Activity in Java file,
and this is the Activity's layout file.
That is the XML file.
This is how your first application will look like.
Now before doing anything else, let me just run this application.
To run this application, first of all,
you need to create a virtual device.
How can you create a virtual device?
There's this icon, AVD manager, known as "Android Virtual Device".
Click on that.
Either there will be a by default virtual device
created for you by Android or you will be seeing this screen.
You can even delete that Virtual Device and come to this screen.
Click on this button,
and select one of the resolution device
which you want to work on.
That's a Nexus 5, screen resolution 1080x1920.
If you want to work with this kind of resolution, go ahead.
Or if you want to work with any other resolution
you can select that too.
Press Next.
Then it asks you what should be your system image,
which system image you want to run on your virtual device.
Now, here it will only show you the system images
that you downloaded,
at the time of downloading from your SDK manager.
In mine, you can see there is a 23 and a 25, so I will go with 25.
I'm using x86_64 that too with Google API.
If you don't want to use this Google API,
then you can go with normal x86
but then you must have downloaded that system image here.
Other images.
Any ARM or image if you want to work with that too.
but I wouldn't recommend the ARM as they are very slow.
I'd recommend-- I'm using the latest one,
To Google API, press Next.
You can give the name of your device or virtual device
anything you want, let's say Black_Knight_01
and press Finish.
Here you see my device is ready,
all I have to do is press the Play button.
Launch button and it will launch the emulator.
Wait some seconds and you can see
the emulator will be up and running in a bit.
x86 emulators are way faster as compared to your ARM.
If this would have been an ARM machine,
it would've taken a long time to run.
This won't take hardly a minute to turn on
and I would recommend once your emulator is on,
whenever you're developing, do not close your emulator.
Unless you are done for the day or done with the development
for the day, why ?
Because every time you close your emulator and run it again
it will take the same time to launch the emulator again and again.
So what you can do here is just run it once
and then after that, keep on running your application
from your Android Studio
and they will directly go on your emulator.
So your emulator doesn't have to restart or get the resources again.
How will you do that? As you can see, my emulator is running,
What I would do to run my application
is here, you can see a Play button launch button, or run button.
Just click on that.
My Android Studio automatically detected that there is a device
connected to me, that's called Black_Knight.
Press on OK.
And this application will run on my Android device.
Just wait for it, Gradle will start building.
If there is any error or something,
that also will be detected at this point in time.
There we go.
So this is my very first app, which I have created
from the Android App Studio.
Even if you close your app now, you go to your apps,
you can see your app here.
You click on this, so it's just behaving like any other app.
Now before moving any further in Android,
let's just learn a little bit about your Android Studio ID, etc.
The left bar is known as project panel, we will come to that.
This middle area is known as code area,
or you can create your layout also here by dragging and dropping.
The middle part is known as your console.
This is where you will be seeing what is going on with your Android.
I just ran an application here, in my Android Virtual Device.
So it gave me what was going on, this was the run mode,
what was going on with my application in run mode.
But you can go to your Android monitor, also you will see a logcat.
Logcat will be your friend
throughout your Android application development
because it tells you what is going on in your Android Virtual Device.
Okay, so now you can see here,
this part here is known as project panel,
in this, what you are seeing is the Android Project Data Key.
We'll talk about other project data key
but when we talk about Android Project Data Key,
you will see your project is divided in two parts,
one is your app folder,
and the other one is your Gradle script folder.
Let's just talk about Gradle's script folder first.
When we open up our Gradle script, you will see that in Gradle
there are mainly three types of Gradle file,
one is called ProjectMyHello.Gradle
which will contain nothing but the information
about my Gradle version itself as you can see
which Gradle I'm using right now is Gradle 2.2.2
and include all the repositories in this project.
Second Gradle file which we will be seeing
is module level Gradle file.
As I only have the mobile module here so there is only one.
If there would have been an Android wear
then there would be a wear also.
If there would be TV, then there would be a TV module file also.
So there is only one, what exactly it contains
it contains the information of all the module itself.
What is the minimum version of SDK I'm going to use,
what is the target version for this SDK,
what is the application ID,
the compilation SDK version, so all that information
will be included in this module-level Gradle,
Even the dependencies you want to add that is libraries and all--
that will also be added in this.
As you can see there are this many libraries as of right now.
I'm using the Espresso libraries com,
and the com support,
there is app compact support libraries also,
I'm using JUnit library also.
If you want to add any external leverage
that also will be adding inside dependencies on it .
So that's what the use of the module build Gradle file
it [inaudible]
and gives you the information about that particular modules.
Next settings.gradle file,
it's again one file per application.
It tells the compiler which module
has to part into the compilation
at any particular time.
For example, if you have a better application
designed also for your mobile, TV, and wear,
and your TV, and wear are still not complete
for the production level.
Then, when your mobile app for wear is complete
then you can include the module of mobile here only.
Like this, mobile.
Then the name of the Gradle file,
like, right now, it's app here, it will be mobile.
And if there is a wear also, then we will be putting wear too.
Like this: wear.
If there would be a wear that's the condition,
that there is a wear module too.
Okay, so as of right now, there is no wear,
so it's only just one, that's why this setting-gradle file
contains only app
because that's the only Gradle file
you're going to compile whenever you're going to run it.
Okay great, so that was Gradle scripts.
Now let's talk about app bar,
in the app bar you will see mainly three folders.
First is your manifest project.
Inside this you will find a file android manifest.xml,
this is the file which comes in contact
with your Android device for the very first time
when you install your application.
So when this application is getting installed
in any emulator or device,
this is the file that will come in contact
with your Android device for the very first time.
What exactly it contains, it contains the information
about the application itself, like the package name,
what's is going to be my package name,
the application's information like how many screens
or how many activities it'll contain.
If there are more screens, then you have to register them here,
only, again if there is another activity,
there will be another activity tag.
Or if there is more services then there will be more services tags.
And it will also include the permission, let's say your application
is going to contain any permission like internet permission,
or access netbook permission or GPS permission.
You need to declare those permissions here inside this manifest file only.
Let's say, I want to include the internet permission
I will use this permission, internet, and there you go.
So this is how your permission gets added also.
So that was Android manifest.
In the manifest file you can see there are many attributes,
like AllowBackup will make sure
that your application is compatible for backing up.
And icon attribute here is getting the icon
from @mipmap/ic_launcher.
I will talk about this @mipmap in a bit,
but know that this here is getting the icon...
Or this label attribute also is getting the text
from your resource folder.
We'll talk about how it's getting there.
SupportRTL is again right to left,
there are language which go from right to left
so this application will support RTL language too.
And theme, I'm getting this style from resource folder
we'll talk about that also, but know these attributes are setting...
This one is setting the icon to my application
this one is setting the name or label to my application
and this one is setting the style to my application.
Now let's just go to our Java folder.
When you open up your Java folder you will find three package,
First package is know as development package.
Second package is known as Android test package
or instrumented test package.
Third package is known as unit testing package.
The first development package
you will put all the code for your application development.
This is the package which you'll be dealing a lot
when you're doing the Android application development.
All your activities, services, broadcasts,
content providers, database classes,
all those classes will be kept inside this development package only.
As you can see there is only one activity right now,
that's MainActivity, if you open up,
this is how your MainActivity looks like.
Inside your MainActivity, you can see that--
activity is nothing but a class which is extending AppCompatActivity
and this AppCompatActivity is being inherited from
or is taken from your Android support library.
As you can see, AppCompatLibrary is important
for your android.support.v7. app.
Now if I would have done activity also,
then, also syntactically, there would be no problem
because ultimately, this is activity only, right ?
I'm designing for the latest version
then the features like material design
all the new features, will not be supported
by the previous version if they are not included there.
So that's the reason I want to do the AppCompatActivity.
Inside your activity, you can see there's a method I'm using,
an overrided method called OnCreate,
so that OnCreate method is already defined
inside AppCompatActivity and I'm just overriding it.
And inside this, there's the very first statement I'm doing
which is super.OnCreate.
Super.OnCreate will make sure that before I do anything,
before I do any customization in this particular method
I want to use all the functionalities
which was there in my parent activity.
I don't want to temper with the functionality
which was provided to me
by my Activity class, the OnCreate functionality
which was provided to me by Activity class.
I want that.
Plus if I want any of my own functionality
that I would be including after including this statement.
Once I include this, then I'm including my own statement
that is SetContentView.
I'm providing a particular view to my activity
and that I'm also doing with R.layout.activity_main.
Just for now, understand that I'm attaching my layout file here.
I'm attaching this layout file as you can see, Activity_Main,
Activity_Main.
I will discuss into more detail in a bit
on how exactly it's getting attached
but you can see activity_main is the file
which is getting attached to this particular Main Activity here now.
So that was the development package
and that was the MainActivity file.
In other packages like Android test,
you will see the files which are used for UI testing
here all the UI testing class will be put inside this--
All the JUnit classes testing,
all the classes for JUnit will be put.
So that was the Java folder.
So the Java folder will specifically contain all your coding bar.
Now let's just come to res folder.
Now, res folder is a very important folder
in your Android application development
because Android application development is not just about Java,
it includes your resources and they can be images.
Resources can be layout files, XML files, any values resources
that you are providing [hard-coded].
So let's talk about them in more detail.
There will be a res folder and inside that res folder
there will be some dedicated folders like drawable.
Drawable is a folder which will be used to include the images.
Generally the drawable--
Each and every folder you're gonna design inside your res folder
will have a specific purpose.
So the drawable here is used for your images
or if you have any animations, selectors.
For those kind of things you will be using the drawable.
You will be seeing more of it in your folder's sessions
what exactly this drawable folder can be used more for.
For now, understand that all the images
and animation parts you'll put here.
Next is your layout folder.
Layout folder is a folder where you will provide all the layout
for your activity.
All the UI part, any layout you want to show to your screen
this is the folder where you want to design.
So that file which you just saw, this is where it resides.
Activity_Main.xml,
any XML file you're seeing, any layout file you're seeing,
they are in your layout folder.
You can see that this layout here is the drag and drop screen.
That is called layout, there you can drag any button right now,
and place it where you want.
This is the Drag & Drop bar, when you click on the text tab here
you will be able to see the coding part, and the XML part also.
We will discuss about the coding part
and how exactly you can deal with these XML parts
for the session.
But for now know that :
in layout folder, all the layout file exists
and you can edit the layout of these XML file
with the app Layout Editor.
Next is your mipmap.
Mipmap is a folder which is, again, used for your images only
but here you can put
the different screen resolution images together.
As you can see, the image here is known as ic_launcher.png.
Each and every image is named the same here,
like ic_launcher.png...
but you can see the difference is the resolution.
There will be images which will be--
This image here is high pixel image,
then there is extra high pixel image,
then there is extra, extra high pixel image, so the resolution changes.
If you have an image of a different resolution,
you will put it in the mipmap
by putting the same name.
If my image name is logo
and I have five different resolutions of logo
I will put logo only but the resolution will be different.
Like one maybe 42x42, other maybe 72x72
and other one, maybe, extra high 128x128.
So automatically, it will create a folder
which will define my high density pixel image differently,
and medium density pixel differently,
and extra high density pixel image differently.
So what are the use of it?
If you run your application on any device
which uses extra high density pixel,
you don't have to specify or put in the code
that use this image.
It will automatically adjust that,
"okay this is my extra high density pixel device".
It will automatically pick this image only.
That was mipmap.
Now let's talk about values, now values is a folder
where you generally put all your other resource
which you want to put
or show to the users, like colors.
Values is the folder where you want
to define your different resources,
to make the localization.
So you don't have to define those resources again, and again.
It may be any string value, or any title, or any color also.
As you can see, I defined a color file.xml separately
and then defined the color tag.
Remember that any resource you want to define,
you have to use the resource tag first.
So now this will be a resource, this color will be a resource
and the name of the color by which I'm going to access it anywhere,
is now ColorPrimary.
The use of this will define the resources,
let's say, this is the color right now.
As you can see, the color is 3F51B5.
I don't have to remember this color code
or hashcode again and again.
And I can directly use this ColorPrimary wherever I want to use it.
In a bit we are going to see how exactly we can use it.
In the second uses, let's say tomorrow your boss says
"I want to change this color".
Instead of ColorPrimary,
you define one more color here,
and that color is Title_Color, let's call it color.
You define a color called 99ccc--
So, 99cc00.
Okay so this is my title color.
Let's say tomorrow your boss say, "we're going to change our title color".
So you don't have to go to each and every place
where you had used this hashcode.
If you would have done hard-coded here,
you'd have to change the hashcode in each and every place.
Here you are just going to change the color here
and wherever you've used this name there,
all those places will be receiving the changes.
So that's the beauty of defining the resources here.
So in this way I have to find resource colors
only here you can see ColorPrimary
ColorDark, ColorAccent and ColorTitle, right ?
One more thing I want to point out here, anything you put in your resource
even a image, even a layout file, even all these color
which I'm putting here right now, anything you put in your res folder,
they get a registry inside a file named as Android Java file.
Android Java file is a system generated file
which is being provided to you by your Android system itself,
or the Android application itself, so you don't have to create it
but whatever you do inside the res folder
that will get entry inside the hard-coded Java file.
As of right now, the color which I have just defined,
the whole entry plus the ActivityMain.xml should also have entry
and all these mipmap should also have a entry.
Let's just check that out.
You won't be seeing R.java file inside your Android data key.
To see that, you'll need to change the data key to package.
and inside the package, this is your development package.
You can see R, just click on this R.java file
and you can go back to Android now.
So this is your Android R.java you can see that file
under the build folder are generated and should not be edited.
So you are not to tamper with this file.
I'm just showing you this to prove my point
that everything you put inside your res folder is registered here.
So I'm gonna find my ActivityMain first.
Anything you put inside your res folder
will get registered inside your R.java file
but in the same way that you're defining it.
Like your layout file that is Activity_Main.xml,
you have to find inside a layout folder,
so it will be inside your R.java folder
but inside a class layout.
So... Class Layout.
You can see class layout and then inside that,
the name ActivityMain.
[inaudible]
Yeah, there we go. So you can see the entry here now.
In the same way, let's talk about mipmap.
So mipmap will be registered inside the R.java file
but with class mipmap.
You can see here under ic_launcher.
Mainly this is just one image, right?
So with just one name, so that's why there is only one entry.
I just saved a bunch of colors there so to check out colors
which class will it be saved in? Color.
Resources color.
As you can see, the tag is color here.
So, color.
And inside color you can now find out
what is the name by which you saved.
ColorPrimary, ColorDark, ColorAccent and Title_Color.
So you just have to find out the ColorPrimary, ColorDark...
Yeah, see, ColorPrimary, ColorDark, ColorPrimary Dark
and the Title.
I included my own, TitleColor.
So it will be somewhere around here
If anything is not there, you can even rebuild your project
and sync it now.
Okay, now find color, class, color.
So we have already seen that ColorPrimary, ColorDark.
Sorry, color.
ColorPrimary, ColorDark, ColorAccent,ColorPrimary Dark
And there's TitleColor. Yeah, there we go.
TitleColor, which we saved here, right?
So any resource you create, there will be an entry.
Now you can see...
In the same way there is a dimension folder or dimens folder.
Inside which we are defining some spaces.
Dimens are used to define blank spaces
and putting some horizontal margin.
That is 16dp for the default screen size.
But if the same screen size is a tablet,
or a screen size with a 7 inch screen, or 10 inch screen
the same horizontal margin will become 64.
Can you see that? The name of Activity_Horizontal_Margin
is the same as Activity_Horizontal_Margin.
So Android will automatically detect which device it's running
whether it's a tablet or a device.
Accordingly, it will pick one of these resources
whenever they are being used.
I still need to tell you how to use these resources but...
Know that this will get an entry inside of your R.java file
Dimens... Yeah, you can see that.
There will be an activity_...
Yeah. Activity_Horizontal_Margin
and _Vertical.
Next...String.
So you can see here there is a string also.
I have created under resources string with the app name
My-Hello-First-App.
The reason here is... See here.
Every time you open up your app,
you'll see this My Hello first App
that is because you have to find it here.
Now, let us see how exactly I use this,
how exactly I use my resources.
You must have seen in your manifest file,
when you go to your manifest file I told you that icon--
this icon is used to set my icon.
But, how exactly, it's setting my icon
because there is @mipmap/ic_launcher
so @mipmap means I'm going or I'm referring to my mipmap class.
@ first of all, let's just talk about what is @.
If you are defining or if you are accessing your resources
If you want to access a resource, mipmap is what? A resource.
If you want to access a resource inside a XML file
you'll be using @ to denote your R.java file.
This @ right now is denoting or is referring to my R.java.
So first statement will do what?
@ that means it goes to R.java file
and inside R.java file which class I want to go ahead with?
That is mipmap.
So it will start searching for class mipmap.
So inside mipmap also which file it want? Ic_launcher
So is there an ic_launcher? Yes.
So that's the reason you were able to see the icon here.
You were able to see this icon.
If you want to change the icon just give some other icon.
If you have any other image here
you can give any other image and the icon will change.
Let me just check if I have any other image--
Let me just copy this and paste it here
inside the drawable.
I'm putting it in drawable but you can put it in mipmap also,
if you have more then one icon
or different resolution size of the same image.
So, if I'm a referring it from drawable, this time ,
how, exactly, will I be referring it?
Again, go to the R.java file by using @,
but this time I won't be using mipmap, I'll be using drawable.
You can see in the drawable there is an dog icon.
So if I run this...
Just make sure if you are using icons,
those icons should be actually compatible to the icon size.
You can't expect a big icon size
or big image to become an icon.
So I don't know if my image is actually an icon... yeah.
It was compatible to that.
So you can see here, My Hello App--
now the icon has changed.
So in this way you can use the resources.
Every time you want to use resource inside a res folder
you'll be using @ and the class name.
So in the same way you can see label.
Label is one of the titles you see here.
As you can see, I have MyHelloFirstApp
how exactly it's picking up @string in the resource folder,
there is a string. an @ string.
And inside the string there is a name App_Name.
Did I define this resource? Yeah.
You can see in this string, I defined string
and the string is app_name.
If I change this here...
First App.
So now I don't have to worry about changing it there.
It'll automatically get changed
and every time you open your application now,
there will be the title First App, instead of MyHelloFirstApp.
So you see First App. There you go.
So I hope this makes things clear
in the same way you can check all these styles.
Style gives you--
Style is, again, one of the resource
which tells how exactly your application will look like,
so, in this particular style you can see that I am using a theme.
That theme is also Theme.AppCompat.Light.DarkActionBar.
Now this appcompat is very crucial
because in your Java or in your Activity
you are using AppCompat Activity.
If you would be using a normal Activity file here,
now, at that point of time, the syntax is right,
but when you run this application,
the theme will not be compatible with the [source].
The UI you want is not the--
You may not get the same UI that you want.
If you are using Activity then according to that Activity,
there will be a different theme.
So I'm using AppCompat,
so for AppCompat, I'm using the AppCompat theme.
Light and Dark action bar.
And you can see I'm customizing it by using one of the items.
I'm going to customize one of the items known as ColorPrimary.
And here you can see Asset is a XML file, right?
So I won't be using colors,
it will be @color/colorprimary.
I have already defined a @color.
Isn't it in the color file? @color, color file--
Great!
In the same way I'm customizing other also...
Let's say I don't want to put color primary,
I want to use my color which I have just defined.
So it is title_color.
So now, if you run this you will be able
to see the color has changed.
So this is how your resource of file works
around in your Android.
So this how you access your resource file inside the XML.
That is by using @.
If you want to access your resource file in your Java--
As you can see I have attached this layout,
attached this file which is defined in Layout
inside my Java file, inside my Activity
with the help of resource file only.
So if you are accessing a R.java file
inside your Java folder,
then you will be using .operator
You can see, again, I'm using R, this time no @
R, then dot and then, the class name that is layout.
And then, the file name which you want to process.
That's how you'll be accessing it.
Ok so, that was an overview
on Android Studio and the Project Data Key.
And what are the different components you see in your Android studio.
I hope this will help you in understanding
your Android Studio better.
In further session we will learn more about designing UIs
and how exactly we can work around with our screens and all.
So that's it from my side an introduction
to Android Studio and Android.
Thank you
♪ (robotic music) ♪