5cosc005w mobile application development lecture 1: introduction...
TRANSCRIPT
![Page 1: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/1.jpg)
5COSC005W MOBILE APPLICATIONDEVELOPMENT
Lecture 1: Introduction to Android
Dr Dimitris C. Dracopoulos
Module Web page:
http://users.wmin.ac.uk/∼dracopd/DOCUM/courses/5cosc005w/5cosc005w.html
This material is based on Android Developer Fundamentals 2 by Google used under
a Creative Commons Attribution 4.0 International license.
![Page 2: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/2.jpg)
Introduction to the Module
Syllabus
Lectures (slides + theory concepts)
Tutorials
Software
Assessment
Schedule
What is expected from you?
Lecture AttendanceTutorial Attendance (actual not just swiping of card!)Completion of ALL Tutorial Exercises within the week (if not possiblewithin the tutorial session then on your own time).Code of Conduct
![Page 3: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/3.jpg)
Code of Conduct
Do not cheat on assignments (this is INDIVIDUAL work and NOTthe product of collaboration!):
Discuss only general approaches not specific details of implementationDo not take written notes on other’s work and do not exchange code
Respect the lab environment. Do not:Interfere with the operation of computers/printersInterfere with other’s filesChange another’s passwordCopy another’s program, etc.Bring any food or drinks (except water)
Cheating is reported to university and then it is out of the modulelecturers hands (independent committee decision without theparticipation of the module tutors)Possible consequences:
A mark of 0 for assignmentA mark of 0 for the courseA permanent note on student recordSuspension/Expulsion from university
![Page 4: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/4.jpg)
Code of Conduct (cont’ed)
Any code found in the web or textbook and used in your work shouldbe properly referenced in comments within your code.
Academic year 2017–2018:
49 students were reported for collusion in coursework 1.55 students were reported for collusion in coursework 2.
Assignment Viva: No understanding == Fail mark
![Page 5: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/5.jpg)
Academic Integrity
The University of Westminster is committed to the highest standardsof academic integrity and honesty. Students are expected to befamiliar with these standards regarding academic honesty and touphold the policies of the University in this respect. Students areparticularly urged to familiarize themselves with the provisions of theAcademic Regulations and in this case with Academic MisconductRegulations (https://www.westminster.ac.uk/sites/default/public-files/general-documents/Section-10-Academic-Misconduct-v2.pdf)and avoid any behavior which could potentially result in suspicions ofcheating, plagiarism, misrepresentation of facts and/or participationin an offence. Academic dishonesty is a serious offence and can resultin suspension or expulsion from the University.
![Page 6: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/6.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to AndroidAndroid Developer Fundamentals V2
Introduction to Android
This work is licensed under a Creative Commons Attribution 4.0 International License.
11
Build your first app
1
Android Developer Fundamentals V2
Lesson 1
![Page 7: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/7.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android 2
1.0 Introduction to Android
![Page 8: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/8.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
What is Android?
● Mobile operating system based on Linux kernel● User Interface for touch screens● Used on over 80% of all smartphones● Powers devices such as watches, TVs, and cars● Over 2 Million Android apps in Google Play store● Highly customizable for devices / by vendors● Open source
3
![Page 9: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/9.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Android app examples
4
Pandora Pokemon GO FacebookMessenger
![Page 10: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/10.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Android Software Developer Kit (SDK)
● Development tools (debugger, monitors, editors)
● Libraries (maps, wearables)
● Virtual devices (emulators)
● Documentation (developer.android.com)
● Sample code
5
![Page 11: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/11.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Android Studio
6
● Official Android IDE● Develop, run, debug,
test, and package apps● Monitors and
performance tools● Virtual devices● Project views● Visual layout editor
![Page 12: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/12.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Android Platform Architecture
7
![Page 13: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/13.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Android stack
8
1. System and user apps2. Android OS API in
Java framework3. Expose native APIs;
run apps4. Expose device
hardware capabilities5. Linux Kernel
![Page 14: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/14.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
System and user apps
● System apps have no special status● System apps provide key capabilities to app developers
Example:
Your app can use a system app to deliver a SMS message.
9
![Page 15: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/15.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Java API Framework
The entire feature-set of the Android OS is available to you through APIs written in the Java language.
● View class hierarchy to create UI screens● Notification manager● Activity manager for life cycles and navigation
10
![Page 16: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/16.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Android runtime
Each app runs in its own process with its own instance of the Android Runtime.
11
![Page 17: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/17.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
C/C++ libraries
● Core C/C++ Libraries give access to core native Android system components and services.
12
![Page 18: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/18.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Hardware Abstraction Layer (HAL)
● Standard interfaces that expose device hardware capabilities as libraries
Examples: Camera, bluetooth module
13
![Page 19: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/19.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Linux Kernel
● Threading and low-level memory management● Security features● Drivers
14
![Page 20: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/20.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Older Android versions
15
Codename Version Released API Level
Honeycomb 3.0 - 3.2.6 Feb 2011 11 - 13
Ice Cream Sandwich 4.0 - 4.0.4 Oct 2011 14 - 15
Jelly Bean 4.1 - 4.3.1 July 2012 16 - 18
KitKat 4.4 - 4.4.4 Oct 2013 19 - 20
Lollipop 5.0 - 5.1.1 Nov 2014 21 - 22
Android History and Platform Versionsfor more and earlier versions before 2011
![Page 21: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/21.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Newer Android versions
16
Codename Version Released API Level
Marshmallow 6.0 - 6.0.1 Oct 2015 23
Nougat 7.0 - 7.1 Sept 2016 24 - 25
Oreo 8.0 - 8.1 Sept 2017 26 - 27
Pie 9.0 Aug 2018 28
![Page 22: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/22.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
App Development
17
![Page 23: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/23.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
What is an Android app?
● One or more interactive screens● Written using Java Programming Language and XML● Uses the Android Software Development Kit (SDK)● Uses Android libraries and Android Application
Framework● Executed by Android Runtime Virtual machine (ART)
18
![Page 24: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/24.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
Challenges of Android development
● Multiple screen sizes and resolutions● Performance: make your apps responsive and smooth● Security: keep source code and user data safe● Compatibility: run well on older platform versions● Marketing: understand the market and your users
(Hint: It doesn't have to be expensive, but it can be.)
19
![Page 25: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/25.jpg)
Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License.
Introduction to Android
App building blocks
● Resources: layouts, images, strings, colors as XML and media files
● Components: activities, services, and helper classes as Java code
● Manifest: information about app for the runtime● Build configuration: APK versions in Gradle config files
20
![Page 26: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/26.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
1.1 Your first Android app
21
![Page 27: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/27.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Android Studio
22
![Page 28: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/28.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
What is Android Studio?
23
● Android integrated development environment (IDE) ● Project and Activity templates● Layout editor● Testing tools● Gradle-based build● Log console and debugger● Emulators
![Page 29: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/29.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Android Studio interface
24
1. Toolbar2. Navigation bar3. Project pane4. Editor5. Tabs for other
panes
![Page 30: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/30.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Creating your first Android app
25
![Page 31: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/31.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Start Android Studio
26
![Page 32: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/32.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Create a project inside Android Studio
27
![Page 33: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/33.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Name your app
28
![Page 34: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/34.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Pick activity template
29
Choose templates for common activities, such as maps or navigation drawers.
Pick Empty Activity or Basic Activity for simple and custom activities.
![Page 35: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/35.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Name your activity
30
● Good practice:○ Name main activity
MainActivity
○ Name layout activity_main
● Use AppCompat● Generating layout
file is convenient
![Page 36: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/36.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Project folders
31
1. manifests—Android Manifest file - description of app read by the Android runtime
2. java—Java source code packages3. res—Resources (XML) - layout,
strings, images, dimensions, colors...
4. build.gradle—Gradle build files
![Page 37: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/37.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Gradle build system
● Modern build subsystem in Android Studio
● Three build.gradle:○ project○ module○ settings
● Typically not necessary to know low-level Gradle details
● Learn more about gradle at https://gradle.org/
32
![Page 38: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/38.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Run your app
3333
1. Run
2. Select virtual or physical
device
3. OK
![Page 39: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/39.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Create a virtual device
34
Use emulators to test app on different versions of Android and form factors.
Tools > Android > AVD Manager or:
![Page 40: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/40.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Configure virtual device
35
1. Choose hardware2. Select Android version3. Finalize
![Page 41: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/41.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Run on a virtual device
36
![Page 42: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/42.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Run on a physical device
37
1. Turn on Developer Options: a. Settings > About phoneb. Tap Build number seven times
2. Turn on USB Debugginga. Settings > Developer Options > USB Debugging
3. Connect phone to computer with cable
Windows/Linux additional setup: ● Using Hardware Devices
Windows drivers:● OEM USB Drivers
![Page 43: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/43.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Get feedback as your app runs
1. Emulator running the app
2. Run pane3. Run tab to
open or close the Run pane
38
![Page 44: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/44.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Adding logging to your app
● As the app runs, the Logcat pane shows information
● Add logging statements to your app that will show up in the
Logcat pane
● Set filters in Logcat pane to see what's important to you
● Search using tags
39
![Page 45: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/45.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
The Logcat pane
1. Logcat tab to show Logcat pane
2. Log level menu
40
![Page 46: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/46.jpg)
Android Developer Fundamentals V2 Your first
Android appThis work is licensed under a Creative Commons Attribution 4.0 International License.
Logging statementimport android.util.Log;
// Use class name as tag
private static final String TAG =
MainActivity.class.getSimpleName();
// Show message in Android Monitor, logcat pane
// Log.<log-level>(TAG, "Message");
Log.d(TAG, “Creating the URI…”);
41
![Page 47: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/47.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
1.2 Layouts and resources for the UI
42
![Page 48: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/48.jpg)
Android Developer Fundamentals V2
Views
43
![Page 49: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/49.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Everything you see is a view
If you look at your mobile device, every user interface element that you see is a View.
44
Views
![Page 50: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/50.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
What is a view?
View subclasses are basic user interface building blocks
● Display text (TextView class), edit text (EditText class)
● Buttons (Button class), menus, other controls
● Scrollable (ScrollView, RecyclerView)
● Show images (ImageView)
● Group views (ConstraintLayout and LinearLayout)
45
![Page 51: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/51.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Examples of view subclasses
46
Button
EditText
Slider
CheckBox
RadioButton
Switch
![Page 52: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/52.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
View attributes
● Color, dimensions, positioning
● May have focus (e.g., selected to receive user input)
● May be interactive (respond to user clicks)
● May be visible or not
● Relationships to other views
47
![Page 53: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/53.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Create views and layouts
● Android Studio layout editor: visual representation of XML ● XML editor● Java code
48
![Page 54: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/54.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Android Studio layout editor
49
1. XML layout file 2. Design and Text
tabs3. Palette pane4. Component Tree 5. Design and
blueprint panes6. Attributes tab
![Page 55: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/55.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
View defined in XML<TextView
android:id="@+id/show_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/myBackgroundColor"
android:text="@string/count_initial_value"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/count_text_size"
android:textStyle="bold"
/>
50
![Page 56: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/56.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
View attributes in XML
51
android:<property_name>="<property_value>"
Example: android:layout_width="match_parent"
android:<property_name>="@<resource_type>/resource_id"
Example: android:text="@string/button_label_next"
android:<property_name>="@+id/view_id"
Example: android:id="@+id/show_count"
![Page 57: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/57.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Create View in Java code
In an Activity:
TextView myText = new TextView(this);
myText.setText("Display this text!");
52
context
![Page 58: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/58.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
What is the context?
● Context is an interface to global information about an application environment
● Get the context:Context context = getApplicationContext();
● An Activity is its own context:TextView myText = new TextView(this);
53
![Page 59: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/59.jpg)
Android Developer Fundamentals V2
ViewGroup and View hierarchy
54
![Page 60: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/60.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
ViewGroup contains "child" views
● ConstraintLayout: Positions UI elements using constraint connections to other elements and to the layout edges
● ScrollView: Contains one element and enables scrolling
● RecyclerView: Contains a list of elements and enables scrolling by adding and removing elements dynamically
55
![Page 61: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/61.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
ViewGroups for layouts
Layouts
● are specific types of ViewGroups (subclasses of ViewGroup)
● contain child views
● can be in a row, column, grid, table, absolute
56
![Page 62: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/62.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Common Layout Classes
57
LinearLayout ConstraintLayout GridLayout TableLayout
![Page 63: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/63.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Common Layout Classes
● ConstraintLayout: Connect views with constraints ● LinearLayout: Horizontal or vertical row● RelativeLayout: Child views relative to each other● TableLayout: Rows and columns● FrameLayout: Shows one child of a stack of children
58
![Page 64: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/64.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Hierarchy of viewgroups and views
59
ViewGroup
ViewGroup View View
View View View
Root view is always a ViewGroup
![Page 65: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/65.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
View hierarchy and screen layout
60
![Page 66: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/66.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
View hierarchy in the layout editor
61
![Page 67: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/67.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Layout created in XML<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button ... /> <TextView ... /> <Button ... /></LinearLayout
62
![Page 68: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/68.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Layout created in Java Activity code
LinearLayout linearL = new LinearLayout(this);
linearL.setOrientation(LinearLayout.VERTICAL);
TextView myText = new TextView(this);
myText.setText("Display this text!");
linearL.addView(myText);
setContentView(linearL);
63
![Page 69: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/69.jpg)
This work is licensed under a Creative Commons Attribution 4.0 International License.
Android Developer Fundamentals V2 Layouts and
resources for the UI
Set width and height in Java code
Set the width and height of a view:
LinearLayout.LayoutParams layoutParams =
new Linear.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_CONTENT);
myView.setLayoutParams(layoutParams);
64
![Page 70: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/70.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Best practices for view hierarchies
65
● Arrangement of view hierarchy affects app performance
● Use smallest number of simplest views possible
● Keep the hierarchy flat—limit nesting of views and view groups
![Page 71: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/71.jpg)
Android Developer Fundamentals V2
The layout editor and Constraint
Layout
66
![Page 72: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/72.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
The layout editor with ConstraintLayout
67
● Connect UI elements to parent layout
● Resize and position elements
● Align elements to others
● Adjust margins and dimensions
● Change attributes
![Page 73: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/73.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
What is ConstraintLayout?
68
● Default layout for new Android Studio project
● ViewGroup that offers flexibility for layout design
● Provides constraints to determine positions and alignment of UI elements
● Constraint is a connection to another view, parent layout, or invisible guideline
![Page 74: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/74.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Layout editor main toolbar
69
1. Select Design Surface: Design and Blueprint panes2. Orientation in Editor: Portrait and Landscape3. Device in Editor: Choose device for preview4. API Version in Editor: Choose API for preview5. Theme in Editor: Choose theme for preview 6. Locale in Editor: Choose language/locale for preview
![Page 75: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/75.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
ConstraintLayout toolbar in layout editor
70
1. Show: Show Constraints and Show Margins2. Autoconnect: Enable or disable3. Clear All Constraints: Clear all constraints in layout4. Infer Constraints: Create constraints by inference5. Default Margins: Set default margins6. Pack: Pack or expand selected elements7. Align: Align selected elements8. Guidelines: Add vertical or horizontal guidelines9. Zoom controls: Zoom in or out
![Page 76: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/76.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Autoconnect
71
● Enable Autoconnect in toolbar if disabled
● Drag element to any part of a layout
● Autoconnect generates constraints against parent layout
![Page 77: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/77.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
ConstraintLayout handles
72
1. Resizing handle2. Constraint line and handle3. Constraint handle4. Baseline handle
![Page 78: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/78.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Attributes pane
73
● Click the Attributes tab● Attributes pane includes:
○ Margin controls for positioning
○ Attributes such as layout_width
![Page 79: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/79.jpg)
Android Developer Fundamentals V2
Event Handling
74
![Page 80: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/80.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Events
75
Something that happens
● In UI: Click, tap, drag
● Device: DetectedActivity such as walking, driving, tilting
● Events are "noticed" by the Android system
![Page 81: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/81.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Event Handlers
76
Methods that do something in response to a click
● A method, called an event handler, is triggered by a specific event and does something in response to the event
![Page 82: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/82.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Attach in XML and implement in Java
77
Attach handler to view in XML layout:android:onClick="showToast"
Implement handler in Java activity:public void showToast(View view) {
String msg = "Hello Toast!";
Toast toast = Toast.makeText(
this, msg, duration);
toast.show();
}
}
![Page 83: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/83.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Alternative: Set click handler in Java
78
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String msg = "Hello Toast!";
Toast toast = Toast.makeText(this, msg, duration);
toast.show();
}
});
![Page 84: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/84.jpg)
Android Developer Fundamentals V2
Resources and measurements
79
![Page 85: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/85.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Resources
● Separate static data from code in your layouts.
● Strings, dimensions, images, menu text, colors, styles
● Useful for localization
80
![Page 86: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/86.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Where are the resources in your project?
81
resources and resource filesstored in res folder
![Page 87: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/87.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Refer to resources in code
82
● Layout:R.layout.activity_main
setContentView(R.layout.activity_main);
● View:R.id.recyclerview
rv = (RecyclerView) findViewById(R.id.recyclerview);
● String:In Java: R.string.titleIn XML: android:text="@string/title"
![Page 88: 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction …users.wmin.ac.uk/~dracopd/DOCUM/courses/5cosc005w... · 2019-01-21 · Introduction to Android App building blocks](https://reader034.vdocuments.us/reader034/viewer/2022042320/5f0a40957e708231d42abff1/html5/thumbnails/88.jpg)
Android Developer Fundamentals V2This work is licensed under a Creative Commons Attribution 4.0 International License.
Layouts and resources for the
UI
Measurements
● Density-independent Pixels (dp): for Views
● Scale-independent Pixels (sp): for text
Don't use device-dependent or density-dependent units:
● Actual Pixels (px)
● Actual Measurement (in, mm)
● Points - typography 1/72 inch (pt)
83