Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presenter Sudhanshu Gupta

Similar presentations


Presentation on theme: "Presenter Sudhanshu Gupta"— Presentation transcript:

1 Presenter Sudhanshu Gupta
Android Unleashed Android App Development Course Class 2 – Introduction to Android Studio, ADB , AVD & First “Hello Android” App Presenter Sudhanshu Gupta

2 Table Of Contents Creating a New Project & Getting familiar with Android Studio Introduction & Installation of ADB. Understanding & Setting-up AVD. Deploying your first “Hello Android” App to Android Device via ADB. Exercise Hands-on session on:: Installation of ADB. Configuring AVD. Pushing first Android App to Device.

3 Creating a New Project In our last class, We are done with Installation of Android Studio and are now ready to Develop our First- Hello Android App. Double click the Android Studio shortcut to open the Welcome Screen , and click “Start A New Android Studio Project”. (Refer to Images)

4 Creating a New Project In the second dialog that appears, configure your project. Application Name : HelloAndroid (No Spaces) Company Domain : android.unleashed.com Project Location : c:\AndroidCourseProjects\HelloAndroid (Or as per your choice)

5 Creating a New Project Select the SDK version running on our device or for which we wish to develop the application. Select API 19: Android 4.4 (Kitkat) for our project. Minimum SDK dropdown provides options to develop for other SDK versions (which were installed during Android Studio configuration). Refer to image.

6 Creating a New Project Select the type of “Launcher Activity”. Let it be Blank Activity for now. Activity acts as a canvas where you draw your controls (Views / Buttons / Layouts). Click Next.

7 Creating a New Project Enter the Title of this Activity. “My First Hello Android App”. Click Finish.

8 Creating a New Project Once Finish is clicked, Android Studio performs few background tasks for you, to configure the new project. Wait till these background operations finish.

9 Creating a New Project

10 Getting Familiar with Android Studio
Congratulations!!! We just created our first Android Studio project & now we want to start programming. But, Lets first get familiar with the navigation of the project. We now discuss the Structure of a Project in Android Studio. We will start by understanding the Project Navigation Panel.

11 Getting Familiar with Android Studio

12 Getting Familiar with Android Studio
Project Navigation Panel Android view (Default) Shows the most important source directories Groups the build files for all modules in a common folder. Groups all the manifest files for each module in a common folder. Groups resource files for different locales, orientations, and screen types in a single group per resource type. Project view Shows the directory structure of the project. Package view Shows only the package structure. (Packages & Classes)

13 Getting Familiar with Android Studio
Project Structure (Important files / elements) build/ -- contains compiled resources after compiling application. Also contains files generated by compiler such as R.java (\HelloAndroid\app\build\generated\source\r\debug\com\unleashed\android\helloandroid \R.java) , which contains references to application resources. libs/ contains the libraries referenced from our code. src/main/ -- contains the source code of the application. src/main/java/ -- contains Java classes organized in packages. Each class is part of project package namespace. (ie. com.unleashed.android.helloandroid) src/main/res/ -- contains project resources. E.g. XML files that specify Layouts, Menu, or Image files. src/main/res/drawable/ contains images used in our application. Images for different screen densities, are stored in different folders. (e.g. HDPI, MDPI, XHDPI, XXHDPI). src/main/res/layout/ -- contains XML definition of the views and their elements. These layout files are used to draw views (Buttons, TextView, etc) on the Activity. src/main/res/menu/ -- contains XML definition of the Menus used in the application. src/main/res/values/ -- contains XML files that define name-value pairs. E.g. colors, strings, styles. (dimens.xml, strings.xml, styles.xml) AndroidManifest.xml – Declares basic information required by Android System to run the application. E.g. Pakage Name, Version , Activities, Permissions , Intents, Required HW. build.gradle – script file used to build our project.

14 Getting Familiar with Android Studio
Changing Project Properties There are two dialog boxes that contain project settings (Available in toolbar too). File  Settings & File  Project Structure Important Options (File Settings) : Editor -> Code Style : configure code styles as per your taste. (Tab indents, Font etc) Encoding : IDE’s Encoding. Default is UTF-8 Gradle : Gradle configurations. Gradle is a tool to build and manage Java Projects. Important Options (File Project Structure) : Project : We can change Project Name & Project SDK. We can change SDK for only this project. Modules : Lists the existing modules available in the project. E.g. “app”. We can modify their respective properties. File Settings File Project Structure

15 Getting Familiar with Android Studio
Code Editor Settings – Remember to check these options if not already selected. Open the editor settings navigate to File | Settings, section Editor  General | Mouse (Allows to change the font size of the editor using the mouse wheel) Open the editor settings navigate to File | Settings, section Editor  General | Other (When we move the mouse over a piece of code and wait 500 ms, a quick doc about that code will be displayed in a small dialog.)

16 Getting Familiar with Android Studio
More Code Editor Settings – Remember to check these options if not already selected. Smart Keys : Open the editor settings navigate to File | Settings, section Editor  General | Smart Keys (Configures Closing braces, quotes, XML tags, indenting lines when “Enter” key is pressed.) Appearance : Open the editor settings navigate to File | Settings, section Editor  General | Appearance (Select the options highlighted , to enable Line Numbers in editor and Method / Function separator.)

17 Getting Familiar with Android Studio
More Code Editor Settings – Remember to check these options if not already selected. Colors & Fonts : Open the editor settings navigate to File | Settings, section Editor  Colors & Fonts (Changes the fonts and colors. There are a lot of options and elements to configure (keywords, numbers, warnings, errors, comments, strings, and so on). Editor Tabs: Open the editor settings navigate to File | Settings, section Editor  General | Editor Tabs (Select - select the Mark modified tabs with asterisk option to easily detect the modified and not-saved files)

18 Getting Familiar with Android Studio
More Code Editor Settings – Remember to check these options if not already selected. Code Folding : Open the editor settings navigate to File | Settings, section Editor  General | Code Folding (It is very useful to hide code blocks that we are not editing, simplifying the code view. We can collapse or expand the blocks using the icons from the editor). Auto Import : Open the editor settings navigate to File | Settings, Editor  General | Auto Import (Configures how the editor behaves when we paste code that uses classes that are not imported in the current class. By default when we do this, a pop up appears to add the import command.)

19 Getting Familiar with Android Studio
Code Completion (Ctrl + Spacebar) Android Studio displays a list of suggestions while typing the code. If “Code Completion” suggestions are not displayed, it can be opened by pressing Ctrl + Spacebar key combo. Keep typing, Select command from the list, press ENTER key, or Double-click to add it in your code. If you are typing an expression (say if(bool_value)) , select bool_value , and press “!” key to insert a negated expression. Ie. If( ! bool_value).

20 Getting Familiar with Android Studio
Smart Type Code Completion (Ctrl + Shift + Spacebar) Normal Code Completion – All variables starting with “o” are displayed. Smart Type Code Completion – Only expected datatype of method Log.i(String) are displayed.

21 Getting Familiar with Android Studio
Completion of Statements (Ctrl + Shift + Enter) Android Studio allows for auto-complete of a statement segment. Type any statement  if , while , for , do Press Ctrl + Shift + Enter to complete the statement block , ie parenthesis & open-close braces. This technique can also be used to complete Methods (Function) declarations. Start typing a method and after typing the opening parenthesis, or after typing the method parameters, press Ctrl + Shift + Enter. The closing parenthesis and the brackets are added to complete the method specification. Ctrl + Shift + Enter Ctrl + Shift + Enter

22 Getting Familiar with Android Studio
Automatic Code Generation (Alt + Insert) Android Studio can be used to generate constructors, getters, and setters methods, equals and toString methods, override or delegate methods. After Pressing Alt + Insert

23 Getting Familiar with Android Studio
Inserting Code Templates ( Ctrl + J ) Goto menu Code  Insert Live Templates (Different Menu pops-up depending upon the placement of cursor) Android Studio provides means to insert ‘Templates’ : To iterate between : Collections, Arrays, Linked Lists. Code to print formatted strings. Code to Throw Exceptions. Code to add Static / Final variables. The left edge of the dialog, each template has a prefix, so if you type the prefix in the editor and press the Tab key, the code template is added automatically. Inside Function In Class Scope (Outside Function)

24 Getting Familiar with Android Studio
Navigating Code – Method 1 – Ctrl + Click on Symbol Most direct way to navigate to declarations or type declarations is to press Ctrl and click on the symbol when it is displayed as a link. Navigate | Declaration

25 Getting Familiar with Android Studio
Navigating Code – Method 2 -- Icons From the left edge of the editor we can navigate through the hierarchy of methods. Next to the method declarations that belong to a hierarchy of methods, there is an icon that indicates if a method is: Implementing an Interface method, Implementing an Abstract class method, Overriding a Superclass method, Or if a method is Implemented / Overridden by other descendants. Click on these icons to navigate to the methods in the hierarchy. Navigate | Super Method or Navigate | Implementation(s) Test it by opening the main activity of our first project (MainActivity.java).

26 Getting Familiar with Android Studio
Navigating Code – Method 3 – Using Custom Regions Custom Region is just a piece of code that you want to group and give a name to. E.g., if there is a class with a lot of methods, we can create some custom regions to distribute the methods among them. Select the fragment of code, navigate to Code | Surround With, and select one of these two options: <editor-fold…> Comments Region…endregion Comments Both of them create a region but using a different style. We can navigate them using the Navigate | Custom Folding menu.

27 Getting Familiar with Android Studio
Navigate menu Lets spend some time discussing various options under this category Class/File/Symbol: Finds a Class (Ctrl+N), a File, Symbol (Ctrl+Shift+N) by its name. Line: Goes to a line code by its number.

28 Getting Familiar with Android Studio
Navigate menu File Structure (Ctrl + F12) Opens a dialog box, displaying the list of methods, the icons that indicate the type of element, or the icons that indicate the visibility of the element. Type Hierarchy (Ctrl + H) : Opens a dialog that shows the type hierarchy of the selected object. Method Hierarchy (Ctrl + Shift + H) : Opens a dialog that shows the method hierarchy of the selected method. Call Hierarchy (Ctrl + Alt + H) : Opens a dialog that shows the call hierarchy of the selected method. Next Method (Ctrl + Down) : Navigates to the next method. Previous Method (Ctrl + Up) : Navigates to the previous method.

29 Android Studio – Tips & Tricks
When in Doubt, place the cursor in the area of interest (basically the code section), and press Alt+Enter, to see the various options. Depending on the context (ie. Placement of the cursor) , appropriate options are displayed for user to use. Ctrl + / : Comments each line of the selected code. Ctrl + Shift + / : To use block comments Ctrl + Alt + I : Indents the selected code. Useful when you finish writing a block of code or method to clean it up. Ctrl + Alt + O : Optimizes the imports, removing the unused ones and reordering the rest of them. And Of course the Regular(s) – Ctrl + F : Finds a string in the active tab of the editor. Ctrl + R : Replaces a string in the active tab of the editor. Ctrl + A : Selects all the code of the opened file.

30 Getting Familiar with Android Studio
Graphical Editor

31 Introduction & Installation of ADB
ADB – Android Debug Bridge

32 Understanding & Setting-up AVD
AVD – Android Virtual Device

33 Deploying your first “Hello Android” App to Android Device via ADB
Time has come to get our hands dirty…

34

35

36

37

38 Workout (Exercise) Time
Students are expected to finish the following task-items, before the next class: Hands-on session on:: Check Installation of ADB on their machines. Creating a New AVD (Android Virtual Device / Simulator). Develop and compile first “Hello Android” app. Pushing first Android App to their Android Device (Phone / Tablet). Play around a bit with Android Studio IDE to get a better feel of the tool. Surf through code files (Hello Android) and try to tweak code and see the effect on final APK.

39 References for further reading
[Book] Android Studio Application Development – Belen Cruz Zapata Action Bars --


Download ppt "Presenter Sudhanshu Gupta"

Similar presentations


Ads by Google