Mobile Programming Lecture 1 - Florida State...

Post on 12-Aug-2020

8 views 0 download

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

Mobile ProgrammingLecture 1

Getting Started

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

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

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.

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

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

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

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

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

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

Activities - Examples

● 3 different apps, 3 different activities

Activities - Examples

● 1 app (Google Maps), 3 different Activities

Activities - Examples

● 1 app (Clock), 3 different Activities

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!

Layouts

Defines the layout structure and holds all elements in an Activity

Layouts

● LinearLayout● RelativeLayout● TableLayout● TabLayout

Layouts - LinearLayout

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

Layouts - LinearLayout

1

Layouts - LinearLayout

1button, textbox, checkbox, etc.

Layouts - LinearLayout

12

Layouts - LinearLayout

123

Layouts - LinearLayout

123

n

.

.

.

Widgets

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

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"

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

References

● Android Developers● The Mobile Lab at Florida State University