android app anatomyandroid application – in parts from studio's “android” view. of the...

40
Android App Anatomy EECS 4443 – Mobile User Interfaces Scott MacKenzie York University © Scott MacKenzie

Upload: others

Post on 02-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android App Anatomy

EECS 4443 – Mobile User Interfaces

Scott MacKenzieYork University

© Scott MacKenzie

Page 2: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android UIStatus Bar

Action Bar

Content Area

Navigation Bar

2© Scott MacKenzie

Page 3: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android Application – In PartsFrom Studio's“Android” viewof the project…

• Project

• Module

• Manifest

• Package

• Source files

• Images (for app)

• XML layout

• String constants

• Build script

3© Scott MacKenzie

Page 4: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Source (.java) Files

4© Scott MacKenzie

Page 5: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android Application – In PartsFrom Studio's“Android” viewof the project…

• Project

• Module

• Manifest

• Package

• Source files

• Images (for app)

• XML layout

• String constants

• Build script

5© Scott MacKenzie

Page 6: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Layout (.xml) Files

6© Scott MacKenzie

Page 7: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Layout (.xml) Files

7© Scott MacKenzie

Page 8: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android Application – In PartsFrom Studio's“Android” viewof the project…

• Project

• Module

• Manifest

• Package

• Source files

• Images (for app)

• XML layout

• String constants

• Build script

8© Scott MacKenzie

Page 9: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

String (.xml) Constants

9© Scott MacKenzie

Page 10: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android Application – In PartsFrom Studio's“Android” viewof the project…

• Project

• Module

• Manifest

• Package

• Source files

• Images (for app)

• XML layout

• String constants

• Build script

10© Scott MacKenzie

Page 11: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

What the heck is "manifest"?

• This is a reasonable question if you are new to Android programming

• Here's a simple way to answer this question (and other questions like this)

• Go to

and type "AndroidManifest.xml" in the search field ( )

© Scott MacKenzie11

developer.android.com

Page 12: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Manifest (.xml) File

12© Scott MacKenzie

No! (next slide)

Page 13: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

minSDK, targetSDK

• Android projects are built to run on devices supporting a range of API levels

• API level determined in the project setup• Varies by IDE• Eclipse:

– Specified in AndroidManifest.xml via <uses-sdk> element (previous slide)

• Studio:– Specified in build.gradle (next slide)

© Scott MacKenzie13

Page 14: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android Application – In PartsFrom Studio's“Android” viewof the project…

• Project

• Module

• Manifest

• Package

• Source files

• Images (for app)

• XML layout

• String constants

• Build script

14© Scott MacKenzie

Page 15: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

build.gradle (Demo_Android)

© Scott MacKenzie15

Page 16: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

API Levels (partial list)

© Scott MacKenzie16

http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

Page 17: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Changing minSDK & targetSDK

• How do you change the min/target API levels for an Android project using Studio?

1. Edit build.gradle2. Sync Project with Gradle Files ( )

• Or (preferred) …1. Right click on your project file ("app")2. Select "Open Module Settings"3. Go to the "Properties" tab and edit settings

1. A better question… How do you figure out stuff like this? (next slide)

© Scott MacKenzie17

Page 18: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

StackOverflow to the Rescue

© Scott MacKenzie18

http://stackoverflow.com/questions/19465049/changing-api-level-android-studio

Page 19: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Android Package (.apk file)

19© Scott MacKenzie

From Studio's“Project” viewof the project…

Page 20: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Activities

20© Scott MacKenzie

Page 21: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Minimum Implementation

21© Scott MacKenzie

Page 22: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Activity Lifecycle

“Running”

22© Scott MacKenzie

Page 23: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

ActivityLifecycle(more detail)

23© Scott MacKenzie

Page 24: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Activity Lifecycle Callbacks (1 of 2)

24© Scott MacKenzie

Page 25: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Activity Lifecycle Callbacks (2 of 2)

25© Scott MacKenzie

Page 26: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

UI – Overview

26© Scott MacKenzie

Page 27: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

UI – Overview

Examples:LinearLayoutRelativeLayoutTableLayout

Examples:TextViewButtonViewGroup

27© Scott MacKenzie

Page 28: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

UI – Layout

28© Scott MacKenzie

Page 29: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

UI – Layout

29© Scott MacKenzie

Page 30: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Layout Example (main.xml)

…30© Scott MacKenzie

Page 31: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Layout Example (main.xml)

Esc Let’s find out.

What’s the difference?

31© Scott MacKenzie

Page 32: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

UI – Input Controls

32© Scott MacKenzie

Page 33: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

UI – Input Events

33© Scott MacKenzie

Page 34: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

UI – Event Listeners

34© Scott MacKenzie

Page 35: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Event Listener Example (onClick)

Note: main.xml has a Button element with android:id="@+id/mybutton" tag

35© Scott MacKenzie

Page 36: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Two Buttons!

36© Scott MacKenzie

Page 37: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Button Callbacks

• Two ways to setup… 1. Code (previous slide)

• Add implements OnClickListener to the signature of the activity

• Invoke setOnClickListener(this) on the Button instance

• Implement onClick(View v)• Example: Demo_Android, Demo_Layout

2. XML• Add android:onClick="buttonClick" as tag to

Button element in XML• Implement buttonClick(View v)• Example: Demo_Buttons

37© Scott MacKenzie

Page 38: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Demo Android

EscLet’s have a look.

38© Scott MacKenzie

Page 39: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

Homework

• Review all notes in these slides– Do this by reading from the Android Developer

API Guide:

• Continue with Lab #1– Task 2, Task 3, …

© Scott MacKenzie39

http://developer.android.com/guide/index.html

Page 40: Android App AnatomyAndroid Application – In Parts From Studio's “Android” view. of the project… • Project • Module • Manifest • Package • Source files • Images

The End(Actually, this is just the beginning!)

40© Scott MacKenzie