Mobile Programming Lecture 1 - Florida State...

26
Mobile Programming Lecture 1 Getting Started

Transcript of Mobile Programming Lecture 1 - Florida State...

Page 1: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Mobile ProgrammingLecture 1

Getting Started

Page 2: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Today's Agenda

● About the Android Studio IDE● Hello, World! Project● Android Project Structure● Introduction to Activities, Layouts, and Widgets● Editing Files in Android Studio● SDK Tools

Page 3: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

About the Android Studio IDE

● Android Studio is an IDE as Visual Studio is an IDE○ Android Studio is now the official IDE for developing

Android applications and is based on IntelliJ IDEA by JetBrains

● It is a great tool, but there is a chance you will run into problems.○ Lots of online resources including the reference

page from the Android Developer site

Page 4: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Getting the Android Studio IDE

● You can download the latest version of Android Studio for your OS from the following URL○ http://developer.android.com/sdk/index.html

● The installation will also guide you through downloading and/or installing other components○ SDK○ Emulator Images○ etc.

Page 5: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Hello, World! Project - Navigation

From the Android Studio main menu● File > New > New Project● In the Create New Project Window

○ Application Name: The name of your Android application○ Company Domain: Your company’s (or personal domain).

■ e.g. mobile.cs.fsu.edu - reverse is used in combination with application name to create a package name (edu.fsu.cs.mobile.helloworld)

■ The package name can be set manually by clicking the edit link and entering the new package name

○ Project Location: Local path where the application should be created

● Next

Page 6: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Hello, World! Project - Form Factors

● Select the different form factors that your app is intended to run on○ Phone and Tablet

■ This is the form-factor that will be used for most of the course○ Wear

■ If there is adequate time, we will explore developing wearable apps towards the end of the course

○ TV○ Android Auto○ Glass

● Specify the minimum Android SDK that will be supported by your app○ You will be expected to develop apps that target a minimum

SDK of Android 4.0 (ICS) or API 14

Page 7: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Hello, World! Project - Add an Activity

● Presents several default Activity templates● Select Empty Activity● Click Next● Provide a name for the Activity● Ensure the Generate Layout File option is

checked○ This ensures that a layout is generated for your

default Activity when the project is created● Provide a name for the layout file● Click Finish

Page 8: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Hello, World! Project - Setup an Emulator

● In Android Studio, select Tools > Android > AVD Manager

● In the Android Virtual Device Manager, select Create Virtual Device

● Select a Hardware Device and click Next● Choose a System Image and click Next

○ Ensure your device runs at least Ice Cream Sandwich● Provide a name for the AVD

○ You can accept or change the defaults as necessary or modify the advanced settings to suit your needs

● Click Finish

Page 9: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Hello, World! Project - execution

● To run your project○ Shift + F10 or○ Select Run from the Run menu

● If necessary○ Click Yes to launch a new virtual device○ Choose to run as Android Application

Page 10: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Project Structure

● build/ stores the compiled app● src/main/res/ contains drawable files, layouts,

string values, etc.● src/main/java/ contains your source code● AndroidManifest.xml file describes the

application● R.java - do not modify this!

○ generated whenever the project compiles○ more on this later

Page 11: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Activities - Examples

● 3 different apps, 3 different activities

Page 12: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Activities - Examples

● 1 app (Google Maps), 3 different Activities

Page 13: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Activities - Examples

● 1 app (Clock), 3 different Activities

Page 14: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Activities

● An Activity is a UI-based construct focusing on a single user task

● To create an Activity, you must create a class that extends Activity (or one of its subclasses)

● Main point of entry○ int main() is the main point of entry in C++○ public static void main(string args[]) is for Java○ public void onCreate(Bundle savedInstance) for Android!

Page 15: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts

Defines the layout structure and holds all elements in an Activity

Page 16: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts

● LinearLayout● RelativeLayout● TableLayout● TabLayout

Page 17: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts - LinearLayout

Organizes UI components in a straight line as either a row or column

Page 18: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts - LinearLayout

1

Page 19: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts - LinearLayout

1button, textbox, checkbox, etc.

Page 20: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts - LinearLayout

12

Page 21: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts - LinearLayout

123

Page 22: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Layouts - LinearLayout

123

n

.

.

.

Page 23: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Widgets

Widgets are UI elements that appear in an Activity (inside of Layouts!)● Buttons● TextViews (labels)● CheckBoxes● Many more!

Page 24: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

Editing Files in Android Studio

● XML Files○ Plain XML editor

■ edit XML files directly○ Form based editor

■ allows you to modify XML files indirectly using forms● Content Assist

○ Similar to Intellisense, autocomplete○ When in doubt, press Ctrl + Spacebar

● Quick fixes○ e.g. import a package without typing anything

● WYSIWYG editor○ Allows you to drag and drop Widgets into your Layouts○ "What You See Is What You Get"

Page 25: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

SDK Tools

● Development and debugging tools for Android

● SDK Manager○ Allows you to install tools necessary to develop for

specific Android platforms● In Android Studio

○ Tools > Android > SDK Manager

Page 26: Mobile Programming Lecture 1 - Florida State Universityww2.cs.fsu.edu/~yannes/lectures/lect01.Getting.Started.pdf · Mobile Programming Lecture 1 Getting Started. Today's Agenda About

References

● Android Developers● The Mobile Lab at Florida State University