 Good morning one and all welcome to the second day to Android workshop. Let me just start my session now. So these are some projects we have already imported I mean don't worry what all this you you know during the sessions you will get introduced to each and every project. I will what I will do is I will start creating a new project for you. So this is my Eclipse IDE and where I am going is just file new Android application project. So I clicked on Android application project. So now it asks me application name. So I am saying say a starting point yeah. Then the here is a package name package name is nothing but a namespace for your project. You must have already accessed a lot of classes in Java you know which says like com dot some package name dot the class name. You need to import that in order to you know if you are using some functionalities in your code you need to import corresponding packages it acts like a namespace for you. Then there is a minimum required SDK the target and compile with SDK. So basically this minimum required SDK you should always keep the minimum one which is available which your SDK supports the target SDK better keep it the maximum version which is available in your SDK and the compile with version is nothing but your program will get compile with this version. So here instead of this I am sorry currently I do not have any version other than 4.2 I will show you little later but I am just compiling it in with 4.2 which is available with my Eclipse IDE right now. I will go to next this just says a create a custom launcher icon create activity create project in workspace yes everything should be clicked we do not need any other things. Then next would be a custom launcher icon I guess yes. So if you want some you know custom icon for your application. So basically what is this custom launcher icon this icon I mean when you are you will install your application on the device or even on the emulator the picture representation what you see would be this I mean if you click on this icon then your application will open if you want any other image you can just go ahead and have it then it says a create a blank activity. Now I am just renaming this activity what happens generally is if you keep it as a main activity there will be lot of other people with whom you must be sharing a device. So you know the all applications will be a main activity. So it is difficult to segregate until and unless you do not explicitly change your app name in string.xml. So it is better if you just give your activity some unique name so that you will understand it that this is your activity I am just simply saying finish. So now this will create a complete Android project for me this takes little bit time for you. Now it will have the all those project structure what Nilesh showed you yesterday. So let us just open it and check out what all it has. It is like you know like a project structure which is segregated based on some based on some things right for example under a resources you will have your drawable folder you will have your layout folder which deals with a UI which deals with a lot of resources in your project. You have SRC folder there it would be a complete Java code your multiple Java files if you want to have because there can be a multiple activities in your application. So SRC folder will hold all your Java code. So here we are it opened me a .xml file for me but let us just check out the folder structure first. So this is our folder the starting point right this is our folder starting point forget about the rest all projects there are lot of projects already available they it might confuse you please try to concentrate on this project. So this is the starting point as I told you there is a here is a SRC folder what it does is let me just expand this for you yeah great. So under this SRC you have your package and you have your Java activity which you created starting point activity after that you have some system generated file. You should not play with this file there is there should be a r.and build config Java you these are system generated resources file you should not touch it. Now this is android 4.2 I mean this is what is the magic lies basically the all classes all packages would use you will be able to see here and that is why SDK is so handy to use then there would be a sets folder where you can put your lot of resources then a bin some someone had asked question yesterday where can we get our .apk file. So this is the folder you will get after compiling not just like that. So this is a bin folder and then next what we have is a resources which is a important folder I mean I am not going into detail because later you have a complete session on this resources. So you can basically have your images your audio video if you want to play so you can have it here then there is android manifest file which is kind of controller file which decide we decide lot of things for your application different permissions which activity should be a main activity which means a main class from which your application will start. So these all things are controlled by the .xml file so as a developer what you should be aware about is basically a three files first is .java the second would be under your layout that is your graphical how your once you open your application how your application will look like and third is a manifest file in case your application needs some extra permissions or some extra things to be done. So what I will do is I will just try to show you this .xml first let me expand yeah so by default my activity will look like this a simple hello world it has yeah what I have done is I have simply created one android application project called starting point alright under starting point I am somewhere here under rea's under layout I am at activity starting point .xml this is nothing but a ui of my application if you see at the left palette there are lot of widgets available these are some form widgets then text fields layouts the composite widgets like grid view scroll view images and media there you have image view image button gallery media controller then date picker you have there are lots of widgets available I mean you can see how rich the android ui is so what we will do is I am not doing any coding I will just so I will just show you simply what happens when a default application is getting run on the device so what I am doing is I am going on project run as android application see if you have your SDK configured properly then you should able to follow these steps what I am doing so simply create android application project they just rename your activity run the project that is that is all I am doing nothing any you know great rocket science I am doing here so let us just see how your activities will look like what we will do is we will see first how default activity looks like and then we will do little bit of coding I will just have a button and I will just change this hello world to something else on click of the button simple yeah and someone had question yesterday whether all this demos everything will it work on windows I mean this is the answer I am on windows yeah so finally it is saying that installing starting point apk let me just open console for you so it is now saying installing starting point apk so basically this was the reason why we recorded our videos and we were trying to show you yesterday because running on the device every time it takes time it you know consumes your time and we do not want to waste our so much time in just simply running the application that is why we had recorded our videos and we were trying to show you that okay how the code what the code is required how the output would be okay I am not sure whether you will be able to see this hello world or not but if you see here is a starting point by activity name and this is a hello world if I go to a menu I go back so this is my emulators home screen I am just clicking on menu yeah if you see I am saying okay if you see here is my program here is my application do you remember that custom launcher icon it was showing on the right side it just it just took that icon and it has given me I mean the name is the starting point and the icon is the same I haven't changed that icon and when I open the icon open the application it says hello world simple what we will do is let's go to our XML again this is my XML so it has two ways to do it one is a graphical layout so simply drag and drop whatever you want another is dot XML file so here is my XML file where it is you know I just under a relative layout so this is all a system generated code I haven't written anything I did everything in front of you so I haven't written anything it just a simple system generated code and by default it has given me a text view okay where that hello world is getting displayed so by default it has just only given me a text view what we will do is we will have a button and on click of that button we will simply change the text of text view that's it so I am again going in my I am going in my graphic layout just let me zoom it for you hope it's better then let me just drag and drop a button over here I will just drop it down so if you see I mean the editor is so cool you can just do you just need to drag and drop and obviously if you need a very perfection in the coordinates then definitely go for the XML file so what we will do is let me just say control less I am again going to my dot XML and if I now I have drag and drop one button so if you see now I have in my XML a button alright along with the text view I have a now button so what I will do is I will just change its ID so using this ID you can basically refer this in your code so button click okay and the text which is visible on button is button so let me say click me okay so I just simply change its text so let me just close this now the actual thing starts which is our Java code so I am going in my SRC my package my starting point activity dot Java okay so this is again a system generated code it has given you already an activity to start with as I mentioned as a lot of people mentioned yesterday as a developer what first you will encounter is activity because activity is something where user interacts and we are talking about a touch screen environment here so this is a something a basic block which will be basic programming block which you will use almost in all applications so you know rest all services content provider that depends on whether your application requires it or not but activities something you will always require so it has just two simple methods and this is the starting point so this is the on create method if you remember the activity life cycle yesterday there was a starting point of on create so this is where activity will start what we will do simply here is I will just say text view say txt view equal to I am just typecasting it then this dot sorry this dot there is a method find view by ID so I am not sure whether it will be visible for you but if you just if you see here is a second method find view by ID where what I will pass is I am just trying to get the reference of that text view where hello world is displayed right now I want to change that text so definitely I need the reference of it so how I will get is r dot ID dot okay ID dot it has still not given me let me just go to my XML and check whether I have saved it or not the issue is it does not have an ID attribute that is why I cannot access it so I have to have an ID attribute for text view in order to access it so I am just changing it to txt view fine so I have simply added ID attribute so that I get handle of this and I can change the text using in my code let go back to dot Java file yeah so let me uncomment my code text view this now we we should get it ideally dot okay now you see there are two things coming up BTN click which is my button and txt view which I just now gave alright so now if you see there is something red line coming up it says that yeah so if you just even hover on this word where the error is it shows you what all quick fixes are available it says import text view android widget so what happens in my import is I get this new statement import android dot widget dot text view so whenever you are using a code it will I mean whenever you are using any class which needs to which is not there already imported so it will just definitely direct you that okay you need to import it which is very cool thing you do not need to remember that you know okay I am using a text view which package I have to import I do not need to remember it so I have a text view reference what one more thing we can we have to do is I said that on button click we will change the text so let me go back to XML so what we will do is we will add on click method here so I am saying android colon feed alright it went so we have two methods to do it we will go for on click and I will say change text that's it and obviously if you understand I am just calling this method on on click so I have to define this method in my Java file then only it makes any something some sense right so what we will do is we will go to a Java file will have one method say public void I said change text okay and I need this statement inside this basically it's not required in my main method I am just what I see simple I need to do is on click off the button I need to get reference of my text view I need to change the text that's it simple pretty simple I have already defined a method on on click now in the click method I am just writing a code so so what we have to do is txt view dot there should be method of set text it is yeah I am just changing it to starting point so if you see let's go to the XML back where what we have is I had said change text yeah let me just say a C capital over here and that's it I simply define this method in in my Java code let's see whether the magic works or not so let me just run this application again so there were two emulators basically open to AVDs so with an unnecessarily when you consume time again let's see how our activity will look like now so if you see on a console it will again start showing you the that it's it has installing has started these are I mean important windows for you one is a console which tells you what activity is happening another is a lock cat so if any error occurs there the error would be in a lock cat any exception occurs it would be in a lock cat so this is a important window I mean definitely there are a lot of things which I am trying to show you and it's difficult to grasp the all of these things at a time but just understand the basic procedure for right now so that you know at least throughout the session what you can concentrate on is rather than you know what is the basic better concentrate what is there in android okay because you can go back and try out all these things on your own this is very simple you must be able to understand now this is how simple it is so just try to concentrate what is there in android what is stored in android which makes it so cool so this is how now we have a button and click of this great some exception has occurred so let's check out what is the exception let me just expand lock cat for you could not find method aha alright so it says now exception illegal state could not find the method change text bracket my view right so what mistake I have done in my code is I didn't pass the parameter view in change text I mean this is a syntax for it I just missed it so it gave me exception so again it is telling me to import a view so yeah so this is done right so we have a now correct method I will I want to tell you there are several ways to implement this on click method okay one is this way which I shown you showed you there are various others which you know later on in session would be shown to you one is an anonymous inner class where in a code itself you write that you know that button dot on click listener you implement a listener in a code itself that with that I mean I personally feel the code becomes a little bit difficult so I don't want you to you know we get that difficulty in a first program itself so I just made it simpler for you but definitely there is a one drawback of using this way which I have done is what it does is on click wherever you write the method name it searches in a corresponding activity okay and if it doesn't only in corresponding activity if you want to call any method of some different activity it won't it's not possible but it is possible using that on click listener which you know other presenters will show you soon let's just check whether our application is successful or not so now let me rerun my project let's see yeah so I have my activity again a click me and hello world so yes it worked I hope you can see there is text has been changed to starting point right so this is what it is a simple application what I will take a few minutes to do is I will try to show you the same application on device the are Akash tablet I mean where is APK how to install it I would just like to show you just give me couple of minutes and then we would be done with my session at least so if you let me go to my workspace which is on which is on desktop which is on sorry desktop then Akash workspace starting point so if you see this is what the project structure it was showing in our eclipse ID so all the folders everything is available so I am going inside bin and now I have see starting point dot APK which was not there initially I had shown you in ID also it was not there okay so here is my tablet yeah so now what I have is a this a connector a USB connector okay this is a USB connector I am just inserting a pen drive in this connector and the second the other part I will just insert in this port USB port so let's just see whether our USB has been mounted or not yes it says SD card mounted so I have gone to my file manager application this is a default application okay so if you see there are lot of things available this is the internal memory of a tablet if you have external SD card inside inserted in the tablet so this is the folder where you will get all data and third is the pen drive which is not detected till now so looks to be a connector issue I will ask my next presenter to show you the installation on the device and she she will show you how to install it's pretty simple procedure I had inserted pen drive I showed you where the data would be available just go to that dot APK file click on it it will ask it will give you a dialog box whether you want to install so if you click on install it will start installation that's it that it is as simple as that and after finishing installation it will give you a dialog box open so if you click on open the application will open I mean it's pretty simple straight forward procedure you don't even need actually I don't need to even show you that and this is it for from this session