SlideShare a Scribd company logo
1 of 544
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 1
1
Android Bootcamp
for Developers
Using Java, 4e
Chapter 1: Voilà! Meet the
Android
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 2
Icebreaker
• The class will be broken up into pairs of students.
• Each student will create three questions to ask their partner:
− One true/false question
− One question that can be answered with a number
− One question that requires a short answer
• Partners will take turns asking the questions they’ve prepared.
• Each student will then introduce their partner to the class using the information
they’ve learned.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 3
Chapter Objectives (1 of 2)
When you complete this chapter, you will be able to:
• 01.01 Describe the market for Android applications
• 01.02 Identify the role of the Android platform in the mobile market
• 01.03 Describe the features of the Android phone
• 01.04 Identify the languages used in Android development
• 01.05 Describe the role of Google Play in the marketplace
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 4
Chapter Objectives (2 of 2)
When you complete this chapter, you will be able to:
• 01.06 Understand the connection between Windows and Android
• 01.07 Create an Android project using Android Studio
• 01.08 Design the user interface layout within the virtual device
• 01.09 Execute an Android application on an emulator
• 01.10 Open a saved Android project in Android Studio
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 5
1.1 Understanding the Market for Android
Applications
• Two primary mobile operating systems
− iOS for iPhone
− Google Android
• Recently, the Google Android phone has become the sales leader
• Apps: mobile applications created for smartphones
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 6
1.2 The Role of the Android in the Mobile
Market
• Open-Source Platform
− Android is an open-source operating system—no company or individual defines
the features or direction of the development
− Open Handset Alliance: an open-source business alliance of 80 firms that develop
standards for mobile devices
• Android Open-Source Devices
− Android smartphones, tablets, and smartwatches are sold by many companies
− As you develop an app, you test it using an emulator, which duplicates how the
app looks and feels on a particular device
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 7
1.3 Features of the Android Phone (1 of 3)
Feature Description
3D graphics The interface can support 3D graphics for a 3D interactive game experience or 3D
image rendering.
Split screen A split-screen, multiwindow feature displays more than one Android application at
the same time. Watch a movie on the left side and hold a video call with your
friends who are also watching the movie.
Dark mode The Dark mode feature helps to save the phone’s battery life. Blank white space
consumes more power and drains the battery.
Facial recognition Android provides this high-level feature for automatically identifying or verifying a
person’s face from a digital image or a video frame.
Front- and rear-facing
camera
Android phones can use either a front- or rear-facing camera, allowing developers
to create applications involving video calling.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 8
1.3 Features of the Android Phone (2 of 3)
Feature Description
Multiple language
voice-to-text support
Android supports multiple human languages. Android provides a feature of
converting text to speech in different languages. Text messages can be read aloud
to help people who are visually impaired.
On-screen keyboard The on-screen keyboard offers suggestions for spelling corrections as well as
options for completing words you start typing. The on-screen keyboard also
supports voice input.
Power management Android identifies programs running in the background that are using memory and
processor resources. You can close those apps to free up the phone’s processor
memory, extending the battery power.
Gaming For optimized gaming, Android supports the use of a gyroscope, gravity and
barometric sensors, linear acceleration, and rotation vectors, which provide game
developers with highly sensitive and responsive controls.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 9
1.3 Features of the Android Phone (3 of 3)
Feature Description
Voice-based
recognition
Android recognizes voice actions for calling, texting, and navigating with the phone.
Wi-Fi Internet tethering Android supports tethering, which allows a phone to be used as a wireless or wired
hotspot that other devices can use to connect to the Internet.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 10
1.4 Languages Used in Android Development
(1 of 4)
• Java is an object-oriented programming language patterned after the C++
language
• Java and Kotlin can be used to code Android apps
• Android Studio
− An integrated development environment (IDE) for building and integrating
application development tools and open-source projects
− Includes the Android Software Development Kit (SDK)
− XML is used to assist in the layout of the Android emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 11
1.4 Languages Used in Android Development
(2 of 4)
Figure 1-4 Android Studio
running Java code
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 12
1.4 Languages Used in Android Development
(3 of 4)
• Android Emulator
− Design, develop, prototype, and test Android apps without using a physical
device
− Mimics almost every feature of a real Android handset, except placing phone
calls
• Versions of Android
− First release was 1.0 (September 2008)
− Each subsequent release adds features and fixes known bugs
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 13
1.4 Languages Used in Android Development
(4 of 4)
• Versions of Android (continued)
− Android has adopted a naming system based on treats/desserts
− When the revision level reached 10.0, Android started emphasizing revision
number over names
− Most recent versions were Android 12.0 (Snow Cone, October 2021) and
Android 13.0 (Tiramisu, October 2022)
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 14
Activity 1.1: Knowledge Check
(1 of 2)
1. What is the name of the organization that sets the standards for Android
mobile devices?
2. Name at least four types of devices that run the Android OS.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 15
Activity 1.1: Knowledge Check
(2 of 2)
3. Should a developer target only the most recent version of the Android OS
when creating an app?
4. What is the name of the current version of the Android OS?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 16
Activity 1.1: Knowledge Check Answers
(1 of 2)
1. What is the name of the organization that sets the standards for Android
mobile devices?
Answer: Open Handset Alliance
2. Name at least four types of devices that run the Android OS.
Answer: Smartphones, foldable phones, tablets, watches, MP4 players,
automobiles, and Internet TVs
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 17
Activity 1.1: Knowledge Check Answers
(2 of 2)
3. Should a developer target only the most recent version of the Android OS
when creating an app?
Answer: No. To support as many Android devices as possible, you should set
the minimum development version to the lowest available that allows your app
to provide its core feature set.
4. What is the name of the current version of the Android OS?
Answer: Android 13.0 (internal name: Tiramisu)
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 18
1.5 Google Play in the Marketplace (1 of 2)
• The Android platform consists of the Android OS, application development tools,
and a marketplace
• Apps are compiled into package files with an .apk extension
• Google Play (http://play.google.com) sells and deploys all apps
• Programs must meet minimum standards, including:
− Reliability
− Efficiency
− Performance
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 19
1.5 Google Play in the Marketplace (2 of 2)
• Developers must sign an agreement and pay a one-time registration fee
(currently $25) to publish apps on Google Play
• Apps offered for free are free to publish
• For paid apps, standard split is 85% of sales for the developer and 15% for
wireless carriers for the first $1 million of annual earnings selling digital goods or
services
• Also sold through the Amazon Appstore
− Pays developers 80% of the sale price for sold apps and grants 10% of their
Appstore revenue as an Amazon Web Services credit
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 20
1.6 The Connection between Windows and
Android
• Beginning with Windows 11, you can download Android apps to your PC from
the Microsoft Store
• Android apps are also available for Windows-based tablets and other touch
devices
• Phone Link App
− The Microsoft Phone Link app allows you to connect an Android phone to a
Windows 11 PC
− Enables text messaging, notifications, and transfer of photos from the phone
on the PC
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 21
1.7 Creating an Android Project Using
Android Studio (1 of 8)
• Install Android Studio from developer.android.com/studio
• Opening Android Studio to Create a New Project
− Name: the human-readable title for your app
− Package name: the Java package namespace for the source code
− Save location on your hard drive or USB drive
− Minimum SDK: the minimum API level required by your app
− Language (Java or Kotlin)
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 22
1.7 Creating an Android Project Using
Android Studio (2 of 8)
• Creating the Hello Android World Project
− Android Studio facilitations app creation for various form factors
− Two most common projects: Empty Activity and Basic Project
− To create a new Android project, you open Studio, click the New Project
button, and make selections and entries for the project specs
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 23
1.7 Creating an Android Project Using
Android Studio (3 of 8)
Figure 1-8 Welcome to
Android Studio window
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 24
1.7 Creating an Android Project Using
Android Studio (4 of 8)
Figure 1-9 New Project
window with Empty Activity
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 25
1.7 Creating an Android Project Using
Android Studio (5 of 8)
Figure 1-10 Creating Empty
Activity
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 26
1.7 Creating an Android Project Using
Android Studio (6 of 8)
Figure 1-11 Android Studio
project view
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 27
1.7 Creating an Android Project Using
Android Studio (7 of 8)
• Building the User Interface
− The user interface must be intuitive
− The user interface must not distract from functionality
− Java code or XML layout files are needed
− The XML method is preferred because it allows you to design a user
interface without writing large amounts of code
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 28
1.7 Creating an Android Project Using
Android Studio (8 of 8)
• The Android Project View
− The Android project view contains the key source application folders for a
project: manifests, java, and res
− The manifests folder includes the AndroidManifest.xml file, which
contains all the information about the application that Android needs to run
− The java folder contains the Java code source files
− The res folder contains resources the app may need: images, music, video,
and the user interface named activity_main.xml
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 29
1.8 The User Interface Layout within the
Virtual Device (1 of 12)
• The Android SDK includes layout files called activity_main.xml in the res/layout
folder of the app
• The Layout Editor contains the Palette, Component Tree, toolbar, Design
editor, and Attributes pane
• Layout: a container that holds as many widgets as needed
• Widget: a single element (a.k.a. object), such as a Button from the Palette
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 30
1.8 The User Interface Layout within the
Virtual Device (2 of 12)
Figure 1-12 Coding window in
Android Studio
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 31
1.8 The User Interface Layout within the
Virtual Device (3 of 12)
• The Attributes pane contains the attributes and settings of the currently active
app project or object
• Attribute: a characteristic of an object that describes what that object can do
• Android Studio displays an emulator configuration called the Android Virtual
Device (AVD) for design and layout purposes
• To change the virtual device, you open the activity_main.xml file to open the
Layout Editor, then click the Device for Preview (D) button and select the
desired device
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 32
1.8 The User Interface Layout within the
Virtual Device (4 of 12)
Figure 1-13 Layout Editor for
emulator layout design
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 33
1.8 The User Interface Layout within the
Virtual Device (5 of 12)
Figure 1-14 Device for
Preview button
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 34
1.8 The User Interface Layout within the
Virtual Device (6 of 12)
Figure 1-15 Generic phone
selected for Device for
Preview
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 35
1.8 The User Interface Layout within the
Virtual Device (7 of 12)
• When you select the default TextView component, its text is displayed in the
Component Tree
− The Component Tree displays widgets in the order they were placed on the
emulator
• Within the Common Attributes section of the Attributes pane, you can see the
text attribute of the component, which is the text it contains
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 36
1.8 The User Interface Layout within the
Virtual Device (8 of 12)
Figure 1-16 Design editor
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 37
1.8 The User Interface Layout within the
Virtual Device (9 of 12)
Figure 1-17 Attributes pane
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 38
1.8 The User Interface Layout within the
Virtual Device (10 of 12)
• The TextView Component
− Text can be updated by:
 Changing the hard-coded value for the text attribute in the Attributes
pane
 Modifying resource files
 Changing the application XML source code
− It is good programming practice to add an id attribute to each component
(object) for use in Java code
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 39
1.8 The User Interface Layout within the
Virtual Device (11 of 12)
Figure 1-18 Emulator with
TextView control and text
attribute
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 40
1.8 The User Interface Layout within the
Virtual Device (12 of 12)
Figure 1-19 The id attribute
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 41
1.9 Executing an Android Application on an
Emulator (1 of 2)
• The Android emulator (virtual device) runs slowly
− Even when idling, it consumes significant CPU time
• To run and automatically save your app, click the Run button
• Click the Terminate button to stop the emulator from running
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 42
1.9 Executing an Android Application on an
Emulator (2 of 2)
Figure 1-20 Hello Android
World app displayed in
emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 43
Activity 1.2: Knowledge Check
1. In Android Studio, objects such as buttons and text boxes are called _____.
2. Java code source files are stored in the _____ folder.
3. Testing the app is done in a(n) _____.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 44
Activity 1.2: Knowledge Check Answers
1. In Android Studio, objects such as buttons and text boxes are called _____.
Answer: widgets
2. Java code source files are stored in the _____ folder.
Answer: java
3. Testing the app is done in a(n) _____.
Answer: emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 45
1.10 Opening a Saved Android Project in
Android Studio
• To load a saved project, open Studio and then choose the project to open
− Click on it in the Recent Projects column or
− Click Open an existing Android Project in the Quick Start column, navigate to
it, and click the OK button
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 46
Self-Assessment
1. After reading about the market and requirements for software development for
Android devices, what skills would you like to gain or improve before you
begin developing Android apps for publication? What aspects of the market for
these apps would you like to learn more about?
2. What is your initial impression of the Android Studio and Android SDK tools
available to you as an Android developer?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 47
Summary
• Click the link to review the objectives for this presentation.
Chapter objectives
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 48
48
Android Bootcamp
for Developers
Using Java, 4e
Chapter 2: Simplify! The Android
User Interface
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 49
Chapter Objectives (1 of 2)
When you complete this chapter, you will be able to:
• 02.01 Develop a user interface using the TextView, ImageView, and Button
components
• 02.02 Add text using the String table in the Translations Editor
• 02.03 Construct the user interface using a ConstraintLayout
• 02.04 Plan out program design
• 02.05 Create multiple Android activities
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 50
Chapter Objectives (2 of 2)
When you complete this chapter, you will be able to:
• 02.06 View activities in the Android Manifest file
• 02.07 Write code using the onCreate( ) method
• 02.08 Create a Button event handler
• 02.09 Code a Button event handler
• 02.10 Correct errors in code
• 02.11 Run the completed app in the emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 51
2.1 Designing an Android App (1 of 5)
Figure 2-1 Easy Recipes
Android app (left)
Figure 2-2 Second screen with
recipe (right)
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 52
2.1 Designing an Android App (2 of 5)
• Designing apps is like constructing a building
• The Big Picture: To create the Easy Recipes app, you follow a set of steps that
you repeat every time you create an Android application
− Create the user interface (XML layout) for every screen
− Create a Java class (Activity) for every screen
− Code each Java class with appropriate objects and actions
− Test the application in the Android phone emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 53
2.1 Designing an Android App (3 of 5)
• Using the Android User Interface
− Interface: the space where interactions occur between people and the app
− Android apps run on various form factors
− The layout is stored as XML code
 Special Android-formatted XML code is extremely compact
 XML is a set of instructions for placing components on the screen
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 54
2.1 Designing an Android App (4 of 5)
Figure 2-4 Creating an empty
activity for the Easy Recipes
app
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 55
2.1 Designing an Android App (5 of 5)
Figure 2-5 Android
Studio open and
ready for you to
design the Easy
Recipes app
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 56
2.2 Using the String Table in the Translations
Editor (1 of 5)
• The Translations Editor in Android Studio can display the original text in the
language in which it was programmed, or the language of the current locale plus
culturally specific settings
• The String Table
− Android provides the strings.xml file or String table inside the Resources
folder
− strings.xml: a default file that is part of every Android application and
contains commonly used strings for an application
− string: a series of alphanumeric characters that can include spaces
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 57
2.2 Using the String Table in the Translations
Editor (2 of 5)
• The String Table (continued)
− Localization: the use of the String table to change text based on the user’s
preferred language
− Every string is composed of a key (a.k.a. id attribute), which is the name of
a component, and a default value, which is the text associated with the
component
− To create an application that is accessible to those with visual disabilities,
add descriptions to the user interface components that can be read out
loud to your user by a speech-based accessibility service such as a screen
reader
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 58
2.2 Using the String Table in the Translations
Editor (3 of 5)
Figure 2-7 The strings.xml tab
displaying XML code
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 59
2.2 Using the String Table in the Translations
Editor (4 of 5)
Figure 2-10 Adding another
string to the String table
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 60
2.2 Using the String Table in the Translations
Editor (5 of 5)
Figure 2-11 Completed String
table on the Translations
Editor tab
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 61
2.3 Constructing the User Interface with the
ConstraintLayout (1 of 18)
• The Android user interface includes a layout resource designer called the
ConstraintLayout in the Component Tree
− Organizes how components appear on the app’s screens
− Provides more flexibility in positioning components than other layouts
− Constraints: the building blocks in an Android layout that attach or align a
component to the screen, either by attaching it vertically and horizontally to
the edges of the screen or aligning it with another component (or parent) on
the screen
− Constraints are used to create a Responsive Design UI
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 62
2.3 Constructing the User Interface with the
ConstraintLayout (2 of 18)
• Constraint Handles
− Four circular dots on the edges of a selected component
− A Constraint component must have at least two constraints—a vertical and a
horizontal one
− If you drag all four Constraint handles to the four edges of the emulator
screen, you can then drag the component anywhere on the screen and it will
stay in that location when you run the app
− In the ConstraintLayout, a nonconstrained component will float to the top of
the screen when the app is run
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 63
2.3 Constructing the User Interface with the
ConstraintLayout (3 of 18)
• Constraint Handles (continued)
− A white Constraint handle means
that the component is not aligned
− A blue Constraint handle means
that the component is aligned with
the screen or another component
− Corner boxes resize the
component
Figure 2-12 The four circles
are Constraint handles
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 64
2.3 Constructing the User Interface with the
ConstraintLayout (4 of 18)
• XML Code
− After you move the Constraint handles in the Design view, Android Studio
updates your layout resources as XML code in the res/layout resource
directory
− Other common layouts used in Android Studio include:
 LinearLayout
 RelativeLayout
 TableLayout
 GridView
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 65
2.3 Constructing the User Interface with the
ConstraintLayout (5 of 18)
Figure 2-13 ConstraintLayout
XML code
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 66
2.3 Constructing the User Interface with the
ConstraintLayout (6 of 18)
• The Easy Recipes Opening User Interface: To change a component's attributes,
select it and use the Attributes pane
• Android Text Attributes
− The text attribute uses text from a string resource to display within the
component
− The textSize attribute can use various units of measurement
 The preferred unit is often sp (scaled-independent pixels)
 Other units: inches (in), millimeters (mm), pixels (px), density-
independent pixels (dp or dip)
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 67
2.3 Constructing the User Interface with the
ConstraintLayout (7 of 18)
Figure 2-16 The text attribute
with @string used to display
the String table
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 68
2.3 Constructing the User Interface with the
ConstraintLayout (8 of 18)
Figure 2-17 TextView text
displayed in emulator after
@string selected
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 69
2.3 Constructing the User Interface with the
ConstraintLayout (9 of 18)
Figure 2-18 Updating the
textSize of the TextView
component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 70
2.3 Constructing the User Interface with the
ConstraintLayout (10 of 18)
• Adding a File to the Resources Folder
− Graphics used in ImageView components must first be placed in the
res/drawable folder
− Android supports .png (preferred), .jpg (acceptable), and .gif (discouraged)
graphic formats
− Android categorizes device screens based on size and density
− Android creates a Drawable resource for images when you save them in the
res/drawable folder
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 71
2.3 Constructing the User Interface with the
ConstraintLayout (11 of 18)
Figure 2-19 The sorbet.png
file copied into the drawable
folder within the res folder
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 72
2.3 Constructing the User Interface with the
ConstraintLayout (12 of 18)
• The ImageView Component
− An ImageView component can display an icon, a company logo, or a
graphic on the Android screen
− Reminder: The image to be used should be placed in a drawable resources
folder before the ImageView component is placed in the emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 73
2.3 Constructing the User Interface with the
ConstraintLayout (13 of 18)
Figure 2-23 ImageView
component with image
displayed in the emulator and
the id entered
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 74
2.3 Constructing the User Interface with the
ConstraintLayout (14 of 18)
Figure 2-24 The
contentDescription set for
accessibility
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 75
2.3 Constructing the User Interface with the
ConstraintLayout (15 of 18)
• Adding a Button Component
− Button components are commonly used in GUIs
− The Android SDK includes four types of button components: Button,
FloatingActionButton, ToggleButton, and ImageButton
− backgrountTint: an attribute that can be added to a component to set a
background color
− textColor: an attribute that sets the color of the text in a component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 76
2.3 Constructing the User Interface with the
ConstraintLayout (16 of 18)
Figure 2-26 Button
component placed on
emulator and the id named
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 77
2.3 Constructing the User Interface with the
ConstraintLayout (17 of 18)
Figure 2-27 Button displaying
larger text
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 78
2.3 Constructing the User Interface with the
ConstraintLayout (18 of 18)
Figure 2-28 Button with
colors displayed for
background tint color
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 79
Activity 2.1: Knowledge Check (1 of 2)
1. List the major steps you follow to create an Android application.
2. Android loads text resources from the project's _____.
3. Which Android layout provides flexibility in positioning components and
facilitates making your layout a Responsive Design UI?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 80
Activity 2.1: Knowledge Check (2 of 2)
4. Which unit of measurement is often preferred for the textSize attribute? Why?
5. To display an illustration or photo in an Android app you use a(n) _____.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 81
Activity 2.1: Knowledge Check Answers
(1 of 2)
1. List the major steps you follow to create an Android application.
Answer: (1) Create the user interface (XML layout) for each screen.
(2) Create a Java class (Activity) for every screen.
(3) Code each Java class with the appropriate objects and actions.
(4) Test the application in the emulator.
2. Android loads text resources from the project's _____.
Answer: string table or strings.xml file
3. Which Android layout provides flexibility in positioning components and
facilitates making your layout a Responsive Design UI?
Answer: ConstraintLayout
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 82
Activity 2.1: Knowledge Check Answers
(2 of 2)
4. Which unit of measurement is often preferred for the textSize attribute? Why?
Answer: sp (scaled-independent pixels), because it will scale the font to meet
the user's size preference
5. To display an illustration or photo in an Android app you use a(n) _____.
Answer: ImageView component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 83
2.4 Planning Out Program Design
• Phases in the program development life cycle:
− Gather and analyze the program requirements
− Design the user interface
− Design the program processing objects
− Code the program
− Test the program
• Creating Activities
− Activity: a screen, constructed from XML files and a Java class
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 84
2.5 Creating Multiple Android Activities
(1 of 2)
• A class describes a group of objects and serves as a blueprint, or template, for
creating those objects
• An object is a specific, concrete instance of a class
• When you create an object, you instantiate it, meaning you define one
particular variation of the object within a class
• Each screen represents one Activity, and each Activity must have a matching
Java class file within the java folder
• The convention is to use Pascal case for Java class names
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 85
2.5 Creating Multiple Android Activities
(2 of 2)
Figure 2-34 New Recipe class
in the Easy Recipes project
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 86
2.6 Viewing Activities in the Android Manifest
File (1 of 3)
• The Android Manifest file (AndroidManifest.xml) contains:
− The name of the Java application
− A listing of each activity
− Permissions needed to access other Android functions (such as the Internet,
services, and broadcast receivers)
− The minimum level of the Android API
• Android Studio automatically adds each activity you create to the Android
Manifest file
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 87
2.6 Viewing Activities in the Android Manifest
File (2 of 3)
Figure 2-35
AndroidManifest.xml
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 88
2.6 Viewing Activities in the Android Manifest
File (3 of 3)
• Coding the Android Activity
− The entry point of the Activity class is the onCreate() event handler method
 Where you initialize the Activity by placing it on the top of Android's stack
of Activities
− Method: a set of Java statements that can be included inside a Java class; a
piece of code that performs some type of action
− Method body: a collection of statements that defines what the method does
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 89
2.7 Writing Code Using the onCreate()
Method (1 of 2)
• Syntax for the onCreate() method:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
• This method has a void return type, which means it does not return anything
• The Java code necessary to display the content of a specific screen is called
SetContentView, which has the following syntax:
setContentView(R.layout.activity_main);
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 90
2.7 Writing Code Using the onCreate()
Method (2 of 2)
Figure 2-36 MainActivity.java
code for onCreate( ) method
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 91
2.8 Creating a Button Event Handler
(1 of 3)
• Event handler: a part of a program coded to respond to a specific event
• Tapping a button is called a click event in Java code
• Java code for an event handler must contain the following sections:
− A class attribute to hold a reference to the Button object:
Button = (Button)findViewById(R.id.btRecipe);
 Includes the findViewById() method to find a layout XML file
− An OnClickListener() method to await the button click action's onClick()
method to respond to the click event
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 92
2.8 Creating a Button Event Handler
(2 of 3)
• When you import the Button type as an Android widget, the button package
becomes available throughout the app
− An import statement makes more Java functions available to your app
• After the Button attribute is referenced in MainActivity.java, an OnClickListener()
method is necessary to detect when the user taps an on-screen button
• When an OnClickListener is placed in the code window, Java creates an onClick
auto-generated stub—a piece of code that serves as a placeholder to declare
itself
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 93
2.8 Creating a Button Event Handler
(3 of 3)
• Syntax for an OnClickListener() method that listens for a Button:
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
• The startActivity() method creates an intent to start another Activity
− Two parameters: context and name of Activity to open
− Syntax: startActivity(new Intent(MainActivity.this,
Recipe.class));
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 94
2.9 Coding a Button Event Handler
(1 of 3)
Figure 2-38 Button
instantiated with Button
library added
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 95
2.9 Coding a Button Event Handler
(2 of 3)
Figure 2-40 The
setOnClickListener added
with auto-complete feature
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 96
2.9 Coding a Button Event Handler
(3 of 3)
Figure 2-41 Complete code
for MainActivity.java—
startActivity will launch the
second screen’s Recipe.class
when the user clicks the
button
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 97
Activity 2.2: Knowledge Check (1 of 2)
1. Name the phases of the development life cycle in order.
2. The file included in each Android application that provides essential
information such as the minimum API level to the Android device is called
_____.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 98
Activity 2.2: Knowledge Check (2 of 2)
3. Which Java method initializes an Android Activity?
4. A part of a program that responds to a user interaction such as tapping an on-
screen button is called a(n) _____.
5. Which Java method is necessary to detect a user interaction with the app?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 99
Activity 2.2: Knowledge Check Answers
(1 of 2)
1. Name the phases of the development life cycle in order.
Answer:
(1) Gather and analyze the program requirements.
(2) Design the user interface.
(3) Design the program processing objects.
(4) Code the program.
(5) Test the program.
2. The file included in each Android application that provides essential
information such as the minimum API level to the Android device is called
_____.
Answer: the Android Manifest or AndroidManifest.xml
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 100
Activity 2.2: Knowledge Check Answers
(2 of 2)
3. Which Java method initializes an Android Activity?
Answer: onCreate()
4. A part of a program that responds to a user interaction such as tapping an on-
screen button is called a(n) _____.
Answer: event handler
5. Which Java method is necessary to detect a user interaction with the app?
Answer: OnClickListener()
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 101
2.10 Correcting Errors in Code
Figure 2-42 Syntax error
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 102
2.11 Saving and Running the Application
• Each time an Android application is tested in the emulator, the programming
design and code are automatically saved
• Click the toolbar's Save All button to save the project
• Click the toolbar’s Run app button to test the application in the emulator
− The first time an app is executed, you will be prompted to choose an
emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 103
Self-Assessment
1. What is your opinion of the Android Studio user interface design tools? Are
there any improvements you'd like to see? Which tools do you anticipate using
most often when creating or updating Android apps?
2. When creating the app project for Chapter 2, which did you enjoy more:
working with the XML layout tools in Studio or writing Java code? How do you
expect to use these UI creation skills in your future career?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 104
Summary
• Click the link to review the objectives for this presentation.
Chapter objectives
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 105
105
Android Bootcamp
for Developers
Using Java, 4e
Chapter 3: Engage! Android
User Input, Variables, and
Operations
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 106
Chapter Objectives (1 of 3)
When you complete this chapter, you will be able to:
• 03.01 Collect user input
• 03.02 Add a Text Number component
• 03.03 Add a string array
• 03.04 Change the background attribute
• 03.05 Set the hint attribute for a Text component
• 03.06 Develop a user interface using a Spinner component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 107
Chapter Objectives (2 of 3)
When you complete this chapter, you will be able to:
• 3.07 Add a prompt and entries to a Spinner component
• 3.08 Code the EditText class for the Text Number component
• 3.09 Code the Spinner component
• 3.10 Instantiate the Button component and variables
• 3.11 Code the getText() method
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 108
Chapter Objectives (3 of 3)
When you complete this chapter, you will be able to:
• 3.12 Understand arithmetic operations
• 3.13 Code the setText( ) method
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 109
3.1 Collecting User Input (1 of 4)
Figure 3-1 Opening screen for
Concert Tickets app
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 110
3.1 Collecting User Input (2 of 4)
• Processes required to create this application:
− Define display text using the Translations Editor and strings.xml file
− Set the background color
− Define a Text Number component
− Define a Spinner component
− Convert string data to numeric data
− Perform arithmetic operations with user-entered data
− Display the results, properly formatted, to the user
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 111
3.1 Collecting User Input (3 of 4)
• Simplifying User Input
− The onscreen keyboard is called a soft keyboard
− Input can come in the form of tapping or gestures (using two fingers to pan,
rotate, or zoom)
− The primary design challenge is to simplify the user experience
 Use legible fonts, simplify input, and optimize each device’s capabilities
to maximize user experience
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 112
3.1 Collecting User Input (4 of 4)
• Using Android Text Components
− Text entered via a soft or physical keyboard is the most common type of
mobile input
− Text components can request different input types (e.g., plain text, phone
number, various types of numeric values)
− The component type can constrain the characters available
• User Experience
− User experience refers to all aspects of interaction with a device
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 113
3.2 Adding a Text Number Component
(1 of 3)
• You can use the id attribute in the Attributes pane to enter a name that begins
with the prefix tv (for TextView)
− Use descriptive names like tvTickets
• Using the String Table
− String items displayed in the components of an app can be stored in the
string table (strings.xml)
− A string array can be used to store a group of related strings
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 114
3.2 Adding a Text Number Component
(2 of 3)
Figure 3-5 Adding strings in
the Translations Editor
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 115
3.2 Adding a Text Number Component
(3 of 3)
Figure 3-6 String table
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 116
3.3 Adding a String Array (1 of 2)
• A string array defines a string resource of related items in a central location
within strings.xml
• An item defines an individual entry within a string array
• As you type the string array XML code, the Android Studio editor offers
suggestions in a panel that can complete a statement
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 117
3.3 Adding a String Array (2 of 2)
Figure 3-9 The string array
named tvGroup with three
items added in XML code
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 118
3.4 Changing Background Attributes
(1 of 4)
• The Android background feature can help provide an app's individual flair
• The background is white by default
• To change it, set the background attribute in the Attributes pane
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 119
3.4 Changing Background Attributes
(2 of 4)
Figure 3-10 Changing the
background color
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 120
3.4 Changing Background Attributes
(3 of 4)
Figure 3-11 Title added to
emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 121
3.4 Changing Background Attributes
(4 of 4)
Figure 3-12 Adding a Text
Number component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 122
3.5 Setting the Hint Attribute for a Text
Component (1 of 2)
• A hint is a short description of a component that is visible as gray text (also
called a watermark) inside a Text Number component or any Text input
− Often used to provide guidelines about the input expected in a component
for the user
• You can change the color of the hint by changing the textColorHint attribute
− May be necessary to ensure adequate contrast between the text and
background
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 123
3.5 Setting the Hint Attribute for a Text
Component (2 of 2)
Figure 3-15 Warning symbol
removed from Text Number
component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 124
Activity 3.1: Knowledge Check
1. If a component holds multiple text strings, it is best to store them in a(n)
_____.
2. To change the screen color for an activity in your app, you set the _____.
3. When you see gray text describing what sort of data to enter within a text entry
box in an app, you are looking at a(n) _____.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 125
Activity 3.1: Knowledge Check Answers
1. If a component holds multiple text strings, it is best to store them in a(n)
_____.
Answer: string array
2. To change the screen color for an activity in your app, you set the _____.
Answer: background attribute
3. When you see gray text describing what sort of data to enter within a text entry
box in an app, you are looking at a(n) _____.
Answer: hint
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 126
3.6 Developing a User Interface Using a
Spinner Component
• A Spinner component is similar to a
drop-down list for selecting a single
item from a fixed list
• The Spinner component displays a
prompt with a list of strings called
items
• Figure 3-16 Spinner dialog box
displaying the three concert groups
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 127
3.7 Adding a Prompt and Entries to a Spinner
Component (1 of 6)
• A prompt, which can be used to display instructions at the top of the Spinner
control, is stored in strings.xml and is named prompt
• Using Entries
− The Spinner attribute called entries connects the string array in strings.xml
to the Spinner component so the entries can be displayed in the application
− The spinnerMode attribute sets the component to dialog mode or drop-
down mode
− The layout_width and layout_height attributes set the dimensions
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 128
3.7 Adding a Prompt and Entries to a Spinner
Component (2 of 6)
Figure 3-18 Pick a Resource
dialog box with tvGroup
string array selected
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 129
3.7 Adding a Prompt and Entries to a Spinner
Component (3 of 6)
• Adding the Button, TextView, and ImageView Controls
− ImageView components should have a content description for visually
impaired users
− This description is provided by setting the contentDescription attribute
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 130
3.7 Adding a Prompt and Entries to a Spinner
Component (4 of 6)
Figure 3-20 Adding a Button
component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 131
3.7 Adding a Prompt and Entries to a Spinner
Component (5 of 6)
Figure 3-21 Adding a
TextView component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 132
3.7 Adding a Prompt and Entries to a Spinner
Component (6 of 6)
Figure 3-22 Adding an
ImageView component with a
contentDescription attribute
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 133
3.8 Coding the EditText Class for the Text
Number Component (1 of 2)
• A Java variable is used to contain data that changes during the execution of a
program
• A final variable can be initialized only once
− Attempting to reassign the value results in a compile error when the
application runs
• For the concert tickets app, you insert code to create the tickets variable
containing the extracted EditText class text:
final EditText tickets =
(EditText)findViewById(R.id.tvTickets);
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 134
3.8 Coding the EditText Class for the Text
Number Component (2 of 2)
Figure 3-23 EditText code for
Text Number component
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 135
3.9 Coding the Spinner Control
Figure 3-24 Spinner
component code
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 136
3.10 Instantiating the Button Component and
Variables (1 of 6)
• An OnClickListener waits in the background and listens for the user to click a
button
• Clicking the button activates a Button event, triggering the Button event OnClick
handler to execute the associated code
• Code to instantiate the TextView component to a variable named result is used
to display the result of the ticket price calculation in the concert tickets app:
final TextView result =
((TextView)findViewById(R.id.tvResult));
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 137
3.10 Instantiating the Button Component and
Variables (2 of 6)
Figure 3-27 TextView
component code for the
result
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 138
3.10 Instantiating the Button Component and
Variables (3 of 6)
• Declaring Variables
− Two steps are necessary in order to use a variable: (1) declare the variable
and (2) assign a value to the variable
− The declared type of a variable determines which operations are allowed
− Java has eight built-in primitive (simple) types of data
• Primitive Data Types
− Java requires all variables to have a data type
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 139
3.10 Instantiating the Button Component and
Variables (4 of 6)
Type Meaning Range Default Value
byte Often used with arrays –128 to 127 0
short Often used with arrays –32,768 to 32,767 0
int Most commonly used number value –2,147,483,648 to 2,147,483,647 0
long Used for numbers that exceed int –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
0
float A 32-bit floating-point number +/–3.40282347 ^38 0
double Most common for decimal values +/–1.79769313486231570 ^308 0
char Used for single characters Characters 0
boolean Used for conditional statements True or false False
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 140
3.10 Instantiating the Button Component and
Variables (5 of 6)
• Primitive Data Types (continued)
− Sample variable initialization and declarations:
double costPerTicket = 89.99;
int numberOfTickets;
double totalCost;
String groupChoice;
• The String Data Type
− The String type is a class and not a primitive data type
− A string can be a character, word, or phrase
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 141
3.10 Instantiating the Button Component and
Variables (6 of 6)
• The String Data Type (continued)
− Most strings used in Java are objects of type String (e.g.,
String groupChoice;)
• Declaring the Variables in the Project
− Typically declared at the beginning of an activity
− Variables must be declared before you can use them
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 142
3.11 Coding the getText() Method
(1 of 2)
• Data stored in the EditText component can be read with the getText() method
• Data is read in as a string, by default
• A Parse class is used to convert strings into numbers
− Parse types include Integer.parseInt(), Float.parseFloat(),
Double.parseDouble(), and Long.parseLong()
• Sample code to extract a string and convert it into an integer:
numberOfTickets =
Integer.parseInt(tickets.getText().toString());
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 143
3.11 Coding the getText() Method
(2 of 2)
• Working with Mathematical Operations
− The ability to perform arithmetic operations is fundamental to many
applications
− Most programs require arithmetic operations to add, subtract, multiply, and
divide numeric data
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 144
Activity 3.2: Knowledge Check
1. A drop-down list for an Android app is created using a(n) _____.
2. The attribute that connects the choices for a drop-down list to their component
is called _____.
3. Which Java keyword prevents a variable from being reassigned?
4. Which Java method reads text stored in an EditText component?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 145
Activity 3.2: Knowledge Check Answers
1. A drop-down list for an Android app is created using a(n) _____.
Answer: Spinner component
2. The attribute that connects the choices for a drop-down list to their component
is called _____.
Answer: entries
3. Which Java keyword prevents a variable from being reassigned?
Answer: final
4. Which Java method reads text stored in an EditText component?
Answer: getText()
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 146
3.12 Understanding Arithmetic Operators
(1 of 3)
• Java's arithmetic operators are + (addition), – (subtraction), * (multiplication), /
(division), % (remainder), ++ (increment 1), and -- (decrement 1)
• The order of operations determines the sequence for performing calculations
when multiple operators are included in an expression
− Parentheses; ++ & --; *, /, & %; + & – (left to right)
• Formatting Numbers
− Java includes a class called DecimalFormat that provides patterns for
formatting numbers for output on the Android device
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 147
3.12 Understanding Arithmetic Operators
(2 of 3)
Figure 3-30 Calculating and
formatting the ticket cost
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 148
3.12 Understanding Arithmetic Operators
(3 of 3)
• Displaying Android Output: Computed results must be displayed
• Using the getSelectedItem() Method
− The getSelectedItem() method returns the text label of the currently
selected Spinner item
− Sample code that assigns a selected item to a String variable named
groupChoice:
groupChoice = group.getSelectedItem( ).toString( );
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 149
3.13 Coding the setText() Method
• The setText() method displays text in a TextView component
• You can concatenate text and string variable values using +, e.g.,
String mobile = "Android";
String completeSentence = mobile + " is a platform.";
• Sample statement using the setText() method to display text in a TextView
component named result:
result.setText("Cost for " + groupChoice + " is " +
currency.format(totalCost));
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 150
Self-Assessment
1. At this point, how comfortable are you using Java classes such as String and
Parse to accomplish the goals of a program? What else would you like to learn
about these Java classes?
2. Consider the Java methods used to code the sample concert ticket
application. How do you anticipate using these methods for your own app
development? What would their most common use cases be for you?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 151
Summary
• Click the link to review the objectives for this presentation.
Chapter objectives
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 152
152
Android Bootcamp
for Developers
Using Java, 4e
Chapter 4: Explore! Icons and
Decision-Making Components
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 153
Chapter Objectives (1 of 3)
When you complete this chapter, you will be able to:
• 04.01 Create an Android project with a custom icon
• 04.02 Display the Action bar icon using code
• 04.03 Place a RadioGroup and RadioButtons in Android applications
• 04.04 Determine layouts with the layout:margin attributes
• 04.05 Align components using the foregroundGravity attributes
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 154
Chapter Objectives (2 of 3)
When you complete this chapter, you will be able to:
• 04.06 Add a RadioButton Group
• 04.07 Write code for a RadioButton component
• 04.08 Make decisions with conditional statements
• 04.09 Make decisions using an If statement
• 04.10 Make decisions using an If Else statement
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 155
Chapter Objectives (3 of 3)
When you complete this chapter, you will be able to:
• 04.11 Make decisions using logical operators
• 04.12 Display an Android toast notification
• 04.13 Use the isChecked() method with RadioButtons
• 04.14 Make decisions using nested If statements
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part.
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 156
4.1 Creating an Android Project with a
Custom Icon (1 of 12)
• We will be creating an app to convert pounds to kilograms and kilograms to
pounds
• App is designed to be used in a hospital setting to administer medication to
patients based on patient weight
• Hospital scales register pounds, whereas medication dosages are based on
patient weight in kilograms
• Formulas needed:
− Kilograms = pounds * 2.2
− Pounds = kilograms / 2.2
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 157
4.1 Creating an Android Project with a
Custom Icon (2 of 12)
Figure 4-1 Opening screen of
the Medical Calculator
Figure 4-2 Results screen of
the Medical Calculator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 158
4.1 Creating an Android Project with a
Custom Icon (3 of 12)
• Steps to complete the app:
− Create a customized launcher icon
− Use code to add the icon for display in the Action bar
− Define a TextField for the data entry of the weight of the patient
− Define a RadioGroup to select a conversion of pounds to kilograms or
kilograms to pounds
− Display a toast message for data validation
− Convert data so it can be used for arithmetic operations
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 159
4.1 Creating an Android Project with a
Custom Icon (4 of 12)
• Steps to complete the app (continued):
− Perform arithmetic operations on data the user enters
− Display formatted results
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 160
4.1 Creating an Android Project with a
Custom Icon (5 of 12)
• Using the Launcher Icon
− The launcher icon opens the app from the home screen and represents the
app when it is published to Google Play
− A high-quality launcher icon can influence users to purchase your app
− Icons can establish brand identity
− Simple images with clear visual cues have a memorable impact
− Vector-based graphics are best for icon design because these images can
be easily scaled without loss of detail
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 161
4.1 Creating an Android Project with a
Custom Icon (6 of 12)
• Using the Launcher Icon (continued)
− Google Play specifies the size and format of all launcher icons
− Should be saved with the .png file format/extension
− When you publish an app to Google Play, you must provide a 512 × 512-
pixel, high-resolution application icon in the developer console as you upload
your program
 This icon is displayed on the Google Play site to provide a description of
the app and does not replace your launcher icon
− Google Play's naming convention for launcher icons: ic_launcher
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 162
4.1 Creating an Android Project with a
Custom Icon (7 of 12)
Resolution Dots Per Inch (dpi) Size (px)
ldpi (low-density screen) 120 36 × 36
mdpi (medium-density screen) 160 48 × 48
hdpi (high-density screen) 240 72 × 72
xhdpi (extra high-density screen) 320 96 × 96
xxhdpi (extra extra high-density screen) 480 144 × 144
xxxhdpi (extra extra extra high-density screen) 640 192 × 192
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 163
4.1 Creating an Android Project with a
Custom Icon (8 of 12)
• Customizing a Launcher Icon
− Image Asset Studio: Android Studio tool that helps you generate your own
app icons from images
 Generates a set of icons at the appropriate resolution for each pixel
density your app supports
− Use the built-in Image Asset Studio wizard to create these multiple icons and
store them in the correct folders
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 164
4.1 Creating an Android Project with a
Custom Icon (9 of 12)
Figure 4-6 Default launcher
icons in the Asset Studio
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 165
4.1 Creating an Android Project with a
Custom Icon (10 of 12)
Figure 4-7 Custom launcher
icons
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 166
4.1 Creating an Android Project with a
Custom Icon (11 of 12)
Figure 4-8 Confirmed icon
path in Asset Studio displayed
in res/mipmap folders
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 167
4.1 Creating an Android Project with a
Custom Icon (12 of 12)
Figure 4-9 Resized custom
icons and their pathways in
the mipmap folder
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 168
4.2 Displaying the Action Bar Icon Using
Code (1 of 4)
• An Action bar icon is considered a logo that represents what the program’s
function is in a single glance
− For example, the medical symbol conveys the purpose and identity of the
app
• Supporting code needed in MainActivity.java to display the image in the Action
bar:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 169
4.2 Displaying the Action Bar Icon Using
Code (2 of 4)
Figure 4-11 Icon displayed in
running app in the emulator
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 170
4.2 Displaying the Action Bar Icon Using
Code (3 of 4)
• String Table
− String resources are stored within the /res/values/strings.xml file
− Any strings you add to the strings.xml file are accessible within your
application
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 171
4.2 Displaying the Action Bar Icon Using
Code (4 of 4)
Figure 4-12 Translations
Editor with new strings in the
String table
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 172
4.3 Placing a RadioGroup and RadioButtons
in Android Applications (1 of 2)
• RadioButton components are used to select or deselect an option
− Can be arranged horizontally or vertically
− Have a label defined by the Text attribute
− Checked attribute can be set to true or false
− Typically used together in a RadioGroup container
 Only one RadioButton in the group can be selected at a time
− It saves time to offer a default selection (checked = true) for the option that is
used most often
172
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 173
4.3 Placing a RadioGroup and RadioButtons
in Android Applications (2 of 2)
• Changing the Text Color of RadioButton and CheckBox Components
− Hexadecimal color code: a triplet of three colors
 Example: #FF0000 is a true red
 Color system used by the Android platform
− Codes range from 00 to FF (00 = none, FF = full)
− Codes are identified by a pound sign, followed by the red, green, and blue
values contained in the color
173
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 174
4.4 Determining Layouts with the
layout:margin Attributes
• You can change a component's alignment after placing it on the UI by adjusting
its Gravity settings
• The layout:margin attribute allows for more flexibility in controlling your layout
− You can change all margins equally or change the left, top, right, and bottom
margins individually
• Set density-independent pixel (dp) values instead of “eyeballing” to create equal
spaces around components
• Using the same specified margins creates a symmetrical layout
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 175
Activity 4.1: Knowledge Check
(1 of 2)
1. What is an app's opening icon called?
2. What tool can you use to generate a launcher icon from an image?
3. RadioButton components are typically used together in a(n) _____.
4. What is #FF0000?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 176
Activity 4.1: Knowledge Check
(2 of 2)
5. What settings are used to change the alignment of an object?
6. Which attribute can you use to set the spacing around each side of an object
individually?
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 177
Activity 4.1: Knowledge Check Answers
(1 of 2)
1. What is an app's opening icon called?
Answer: The launcher icon
2. What tool can you use to generate a launcher icon from an image?
Answer: Image Asset Studio
3. RadioButton components are typically used together in a(n) _____.
Answer: RadioGroup
4. What is #FF0000?
Answer: The hexadecimal color code for a true red color
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 178
Activity 4.1: Knowledge Check Answers
(2 of 2)
5. What settings are used to change the alignment of an object?
Answer: Gravity settings
6. Which attribute can you use to set the spacing around each side of an object
individually?
Answer: layout:margin attribute
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 179
4.5 Aligning Components Using the
foregroundGravity Attributes
• A component's gravity can be changed using the Attributes pane or with a
toolbar shortcut
• The foregroundGravity tool changes the linear alignment of a component
• Layout gravity is similar to the alignment feature in Microsoft Office that allows a
component to snap to the left, center, right, top, or bottom
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 180
4.6 Adding the RadioButton Group and Other
Components (1 of 5)
• When naming a RadioButton with the id attribute, use a name that begins with
the prefix rb, which represents a radio button in the code
• Completing the User Interface
− Remember to create a clean layout and use the entire screen effectively
Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole or in part. 181
4.6 Adding the RadioButton Group and Other
Components (2 of 5)
Figure 4-15 Text Number
component and
foregroundGravity attribute
to center hint text
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide
Android App Development Guide

More Related Content

Similar to Android App Development Guide

Is Java Required for Android App Development.pdf
Is Java Required for Android App Development.pdfIs Java Required for Android App Development.pdf
Is Java Required for Android App Development.pdfIndian Website Company
 
Top Cross Platform Mobile App Development Frameworks
Top Cross Platform Mobile App Development FrameworksTop Cross Platform Mobile App Development Frameworks
Top Cross Platform Mobile App Development FrameworksWDP Technologies
 
android-developer-jobs
android-developer-jobs android-developer-jobs
android-developer-jobs FredReynolds2
 
Mastering the Android Developer Jobs: Essential Questions and Best Practices
Mastering the Android Developer Jobs: Essential Questions and Best PracticesMastering the Android Developer Jobs: Essential Questions and Best Practices
Mastering the Android Developer Jobs: Essential Questions and Best PracticesFredReynolds2
 
Which android app development tools deserve your attention this year
Which android app development tools deserve your attention this year  Which android app development tools deserve your attention this year
Which android app development tools deserve your attention this year Moon Technolabs Pvt. Ltd.
 
Android Web app
Android Web app Android Web app
Android Web app Sumit Kumar
 
Introduction to android - SpringPeople
Introduction to android - SpringPeopleIntroduction to android - SpringPeople
Introduction to android - SpringPeopleSpringPeople
 
Blending Creativity and Technology With Android App Development
Blending Creativity and Technology With Android App DevelopmentBlending Creativity and Technology With Android App Development
Blending Creativity and Technology With Android App Developmentamanraza23
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app developmentAbhishekKumar4779
 
androidPramming.ppt
androidPramming.pptandroidPramming.ppt
androidPramming.pptBijayKc16
 
Comparisons react native vs. flutter vs. ionic vs. xamarin vs. native script
Comparisons  react native vs. flutter vs. ionic vs. xamarin vs. native scriptComparisons  react native vs. flutter vs. ionic vs. xamarin vs. native script
Comparisons react native vs. flutter vs. ionic vs. xamarin vs. native scriptMoonTechnolabsPvtLtd
 
How to become an android application developer
How to become an android application developerHow to become an android application developer
How to become an android application developerventurehire
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedAhsanul Karim
 
Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement Shubham Pahune
 
Native mobile app development pros, cons, alternatives, and cost optimization
Native mobile app development pros, cons, alternatives, and cost optimizationNative mobile app development pros, cons, alternatives, and cost optimization
Native mobile app development pros, cons, alternatives, and cost optimizationCynoteck Technology Solutions
 
Software training report
Software training reportSoftware training report
Software training reportNatasha Bains
 

Similar to Android App Development Guide (20)

Is Java Required for Android App Development.pdf
Is Java Required for Android App Development.pdfIs Java Required for Android App Development.pdf
Is Java Required for Android App Development.pdf
 
Top Cross Platform Mobile App Development Frameworks
Top Cross Platform Mobile App Development FrameworksTop Cross Platform Mobile App Development Frameworks
Top Cross Platform Mobile App Development Frameworks
 
Android
AndroidAndroid
Android
 
android-developer-jobs
android-developer-jobs android-developer-jobs
android-developer-jobs
 
Mastering the Android Developer Jobs: Essential Questions and Best Practices
Mastering the Android Developer Jobs: Essential Questions and Best PracticesMastering the Android Developer Jobs: Essential Questions and Best Practices
Mastering the Android Developer Jobs: Essential Questions and Best Practices
 
Which android app development tools deserve your attention this year
Which android app development tools deserve your attention this year  Which android app development tools deserve your attention this year
Which android app development tools deserve your attention this year
 
Android Web app
Android Web app Android Web app
Android Web app
 
Introduction to android - SpringPeople
Introduction to android - SpringPeopleIntroduction to android - SpringPeople
Introduction to android - SpringPeople
 
Blending Creativity and Technology With Android App Development
Blending Creativity and Technology With Android App DevelopmentBlending Creativity and Technology With Android App Development
Blending Creativity and Technology With Android App Development
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app development
 
androidPramming.ppt
androidPramming.pptandroidPramming.ppt
androidPramming.ppt
 
Comparisons react native vs. flutter vs. ionic vs. xamarin vs. native script
Comparisons  react native vs. flutter vs. ionic vs. xamarin vs. native scriptComparisons  react native vs. flutter vs. ionic vs. xamarin vs. native script
Comparisons react native vs. flutter vs. ionic vs. xamarin vs. native script
 
Android 1
Android  1Android  1
Android 1
 
Complete Guide to Mobile App Development
Complete Guide to Mobile App DevelopmentComplete Guide to Mobile App Development
Complete Guide to Mobile App Development
 
Android overview
Android overviewAndroid overview
Android overview
 
How to become an android application developer
How to become an android application developerHow to become an android application developer
How to become an android application developer
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
 
Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement
 
Native mobile app development pros, cons, alternatives, and cost optimization
Native mobile app development pros, cons, alternatives, and cost optimizationNative mobile app development pros, cons, alternatives, and cost optimization
Native mobile app development pros, cons, alternatives, and cost optimization
 
Software training report
Software training reportSoftware training report
Software training report
 

More from MattMarino13

1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptx1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptxMattMarino13
 
1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptx1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptxMattMarino13
 
BITM3730 11-14.pptx
BITM3730 11-14.pptxBITM3730 11-14.pptx
BITM3730 11-14.pptxMattMarino13
 
01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptxMattMarino13
 
02slide_accessible.pptx
02slide_accessible.pptx02slide_accessible.pptx
02slide_accessible.pptxMattMarino13
 
AndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptxAndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptxMattMarino13
 
9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptx9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptxMattMarino13
 
krajewski_om12 _01.pptx
krajewski_om12 _01.pptxkrajewski_om12 _01.pptx
krajewski_om12 _01.pptxMattMarino13
 
CapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptxCapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptxMattMarino13
 
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptxProject Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptxMattMarino13
 
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptxProject Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptxMattMarino13
 
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...MattMarino13
 
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...MattMarino13
 
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...MattMarino13
 
1-23-19 Agenda.pptx
1-23-19 Agenda.pptx1-23-19 Agenda.pptx
1-23-19 Agenda.pptxMattMarino13
 
EDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptxEDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptxMattMarino13
 
Agenda January 20th 2016.pptx
Agenda January 20th 2016.pptxAgenda January 20th 2016.pptx
Agenda January 20th 2016.pptxMattMarino13
 
BITM3730 8-29.pptx
BITM3730 8-29.pptxBITM3730 8-29.pptx
BITM3730 8-29.pptxMattMarino13
 
BITM3730 8-30.pptx
BITM3730 8-30.pptxBITM3730 8-30.pptx
BITM3730 8-30.pptxMattMarino13
 
BITM3730Week1.pptx
BITM3730Week1.pptxBITM3730Week1.pptx
BITM3730Week1.pptxMattMarino13
 

More from MattMarino13 (20)

1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptx1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptx
 
1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptx1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptx
 
BITM3730 11-14.pptx
BITM3730 11-14.pptxBITM3730 11-14.pptx
BITM3730 11-14.pptx
 
01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx
 
02slide_accessible.pptx
02slide_accessible.pptx02slide_accessible.pptx
02slide_accessible.pptx
 
AndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptxAndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptx
 
9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptx9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptx
 
krajewski_om12 _01.pptx
krajewski_om12 _01.pptxkrajewski_om12 _01.pptx
krajewski_om12 _01.pptx
 
CapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptxCapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptx
 
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptxProject Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
 
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptxProject Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
 
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
 
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
 
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
 
1-23-19 Agenda.pptx
1-23-19 Agenda.pptx1-23-19 Agenda.pptx
1-23-19 Agenda.pptx
 
EDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptxEDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptx
 
Agenda January 20th 2016.pptx
Agenda January 20th 2016.pptxAgenda January 20th 2016.pptx
Agenda January 20th 2016.pptx
 
BITM3730 8-29.pptx
BITM3730 8-29.pptxBITM3730 8-29.pptx
BITM3730 8-29.pptx
 
BITM3730 8-30.pptx
BITM3730 8-30.pptxBITM3730 8-30.pptx
BITM3730 8-30.pptx
 
BITM3730Week1.pptx
BITM3730Week1.pptxBITM3730Week1.pptx
BITM3730Week1.pptx
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

Android App Development Guide

  • 1. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 1 1 Android Bootcamp for Developers Using Java, 4e Chapter 1: Voilà! Meet the Android Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 2. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 2 Icebreaker • The class will be broken up into pairs of students. • Each student will create three questions to ask their partner: − One true/false question − One question that can be answered with a number − One question that requires a short answer • Partners will take turns asking the questions they’ve prepared. • Each student will then introduce their partner to the class using the information they’ve learned.
  • 3. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 3 Chapter Objectives (1 of 2) When you complete this chapter, you will be able to: • 01.01 Describe the market for Android applications • 01.02 Identify the role of the Android platform in the mobile market • 01.03 Describe the features of the Android phone • 01.04 Identify the languages used in Android development • 01.05 Describe the role of Google Play in the marketplace Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 4. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 4 Chapter Objectives (2 of 2) When you complete this chapter, you will be able to: • 01.06 Understand the connection between Windows and Android • 01.07 Create an Android project using Android Studio • 01.08 Design the user interface layout within the virtual device • 01.09 Execute an Android application on an emulator • 01.10 Open a saved Android project in Android Studio Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 5. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 5 1.1 Understanding the Market for Android Applications • Two primary mobile operating systems − iOS for iPhone − Google Android • Recently, the Google Android phone has become the sales leader • Apps: mobile applications created for smartphones
  • 6. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 6 1.2 The Role of the Android in the Mobile Market • Open-Source Platform − Android is an open-source operating system—no company or individual defines the features or direction of the development − Open Handset Alliance: an open-source business alliance of 80 firms that develop standards for mobile devices • Android Open-Source Devices − Android smartphones, tablets, and smartwatches are sold by many companies − As you develop an app, you test it using an emulator, which duplicates how the app looks and feels on a particular device
  • 7. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 7 1.3 Features of the Android Phone (1 of 3) Feature Description 3D graphics The interface can support 3D graphics for a 3D interactive game experience or 3D image rendering. Split screen A split-screen, multiwindow feature displays more than one Android application at the same time. Watch a movie on the left side and hold a video call with your friends who are also watching the movie. Dark mode The Dark mode feature helps to save the phone’s battery life. Blank white space consumes more power and drains the battery. Facial recognition Android provides this high-level feature for automatically identifying or verifying a person’s face from a digital image or a video frame. Front- and rear-facing camera Android phones can use either a front- or rear-facing camera, allowing developers to create applications involving video calling.
  • 8. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 8 1.3 Features of the Android Phone (2 of 3) Feature Description Multiple language voice-to-text support Android supports multiple human languages. Android provides a feature of converting text to speech in different languages. Text messages can be read aloud to help people who are visually impaired. On-screen keyboard The on-screen keyboard offers suggestions for spelling corrections as well as options for completing words you start typing. The on-screen keyboard also supports voice input. Power management Android identifies programs running in the background that are using memory and processor resources. You can close those apps to free up the phone’s processor memory, extending the battery power. Gaming For optimized gaming, Android supports the use of a gyroscope, gravity and barometric sensors, linear acceleration, and rotation vectors, which provide game developers with highly sensitive and responsive controls.
  • 9. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 9 1.3 Features of the Android Phone (3 of 3) Feature Description Voice-based recognition Android recognizes voice actions for calling, texting, and navigating with the phone. Wi-Fi Internet tethering Android supports tethering, which allows a phone to be used as a wireless or wired hotspot that other devices can use to connect to the Internet.
  • 10. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 10 1.4 Languages Used in Android Development (1 of 4) • Java is an object-oriented programming language patterned after the C++ language • Java and Kotlin can be used to code Android apps • Android Studio − An integrated development environment (IDE) for building and integrating application development tools and open-source projects − Includes the Android Software Development Kit (SDK) − XML is used to assist in the layout of the Android emulator
  • 11. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 11 1.4 Languages Used in Android Development (2 of 4) Figure 1-4 Android Studio running Java code
  • 12. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 12 1.4 Languages Used in Android Development (3 of 4) • Android Emulator − Design, develop, prototype, and test Android apps without using a physical device − Mimics almost every feature of a real Android handset, except placing phone calls • Versions of Android − First release was 1.0 (September 2008) − Each subsequent release adds features and fixes known bugs
  • 13. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 13 1.4 Languages Used in Android Development (4 of 4) • Versions of Android (continued) − Android has adopted a naming system based on treats/desserts − When the revision level reached 10.0, Android started emphasizing revision number over names − Most recent versions were Android 12.0 (Snow Cone, October 2021) and Android 13.0 (Tiramisu, October 2022)
  • 14. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 14 Activity 1.1: Knowledge Check (1 of 2) 1. What is the name of the organization that sets the standards for Android mobile devices? 2. Name at least four types of devices that run the Android OS.
  • 15. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 15 Activity 1.1: Knowledge Check (2 of 2) 3. Should a developer target only the most recent version of the Android OS when creating an app? 4. What is the name of the current version of the Android OS?
  • 16. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 16 Activity 1.1: Knowledge Check Answers (1 of 2) 1. What is the name of the organization that sets the standards for Android mobile devices? Answer: Open Handset Alliance 2. Name at least four types of devices that run the Android OS. Answer: Smartphones, foldable phones, tablets, watches, MP4 players, automobiles, and Internet TVs
  • 17. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 17 Activity 1.1: Knowledge Check Answers (2 of 2) 3. Should a developer target only the most recent version of the Android OS when creating an app? Answer: No. To support as many Android devices as possible, you should set the minimum development version to the lowest available that allows your app to provide its core feature set. 4. What is the name of the current version of the Android OS? Answer: Android 13.0 (internal name: Tiramisu)
  • 18. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 18 1.5 Google Play in the Marketplace (1 of 2) • The Android platform consists of the Android OS, application development tools, and a marketplace • Apps are compiled into package files with an .apk extension • Google Play (http://play.google.com) sells and deploys all apps • Programs must meet minimum standards, including: − Reliability − Efficiency − Performance
  • 19. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 19 1.5 Google Play in the Marketplace (2 of 2) • Developers must sign an agreement and pay a one-time registration fee (currently $25) to publish apps on Google Play • Apps offered for free are free to publish • For paid apps, standard split is 85% of sales for the developer and 15% for wireless carriers for the first $1 million of annual earnings selling digital goods or services • Also sold through the Amazon Appstore − Pays developers 80% of the sale price for sold apps and grants 10% of their Appstore revenue as an Amazon Web Services credit
  • 20. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 20 1.6 The Connection between Windows and Android • Beginning with Windows 11, you can download Android apps to your PC from the Microsoft Store • Android apps are also available for Windows-based tablets and other touch devices • Phone Link App − The Microsoft Phone Link app allows you to connect an Android phone to a Windows 11 PC − Enables text messaging, notifications, and transfer of photos from the phone on the PC
  • 21. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 21 1.7 Creating an Android Project Using Android Studio (1 of 8) • Install Android Studio from developer.android.com/studio • Opening Android Studio to Create a New Project − Name: the human-readable title for your app − Package name: the Java package namespace for the source code − Save location on your hard drive or USB drive − Minimum SDK: the minimum API level required by your app − Language (Java or Kotlin)
  • 22. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 22 1.7 Creating an Android Project Using Android Studio (2 of 8) • Creating the Hello Android World Project − Android Studio facilitations app creation for various form factors − Two most common projects: Empty Activity and Basic Project − To create a new Android project, you open Studio, click the New Project button, and make selections and entries for the project specs
  • 23. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 23 1.7 Creating an Android Project Using Android Studio (3 of 8) Figure 1-8 Welcome to Android Studio window
  • 24. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 24 1.7 Creating an Android Project Using Android Studio (4 of 8) Figure 1-9 New Project window with Empty Activity
  • 25. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 25 1.7 Creating an Android Project Using Android Studio (5 of 8) Figure 1-10 Creating Empty Activity
  • 26. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 26 1.7 Creating an Android Project Using Android Studio (6 of 8) Figure 1-11 Android Studio project view
  • 27. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 27 1.7 Creating an Android Project Using Android Studio (7 of 8) • Building the User Interface − The user interface must be intuitive − The user interface must not distract from functionality − Java code or XML layout files are needed − The XML method is preferred because it allows you to design a user interface without writing large amounts of code
  • 28. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 28 1.7 Creating an Android Project Using Android Studio (8 of 8) • The Android Project View − The Android project view contains the key source application folders for a project: manifests, java, and res − The manifests folder includes the AndroidManifest.xml file, which contains all the information about the application that Android needs to run − The java folder contains the Java code source files − The res folder contains resources the app may need: images, music, video, and the user interface named activity_main.xml
  • 29. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 29 1.8 The User Interface Layout within the Virtual Device (1 of 12) • The Android SDK includes layout files called activity_main.xml in the res/layout folder of the app • The Layout Editor contains the Palette, Component Tree, toolbar, Design editor, and Attributes pane • Layout: a container that holds as many widgets as needed • Widget: a single element (a.k.a. object), such as a Button from the Palette
  • 30. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 30 1.8 The User Interface Layout within the Virtual Device (2 of 12) Figure 1-12 Coding window in Android Studio
  • 31. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 31 1.8 The User Interface Layout within the Virtual Device (3 of 12) • The Attributes pane contains the attributes and settings of the currently active app project or object • Attribute: a characteristic of an object that describes what that object can do • Android Studio displays an emulator configuration called the Android Virtual Device (AVD) for design and layout purposes • To change the virtual device, you open the activity_main.xml file to open the Layout Editor, then click the Device for Preview (D) button and select the desired device
  • 32. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 32 1.8 The User Interface Layout within the Virtual Device (4 of 12) Figure 1-13 Layout Editor for emulator layout design
  • 33. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 33 1.8 The User Interface Layout within the Virtual Device (5 of 12) Figure 1-14 Device for Preview button
  • 34. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 34 1.8 The User Interface Layout within the Virtual Device (6 of 12) Figure 1-15 Generic phone selected for Device for Preview
  • 35. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 35 1.8 The User Interface Layout within the Virtual Device (7 of 12) • When you select the default TextView component, its text is displayed in the Component Tree − The Component Tree displays widgets in the order they were placed on the emulator • Within the Common Attributes section of the Attributes pane, you can see the text attribute of the component, which is the text it contains
  • 36. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 36 1.8 The User Interface Layout within the Virtual Device (8 of 12) Figure 1-16 Design editor
  • 37. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 37 1.8 The User Interface Layout within the Virtual Device (9 of 12) Figure 1-17 Attributes pane
  • 38. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 38 1.8 The User Interface Layout within the Virtual Device (10 of 12) • The TextView Component − Text can be updated by:  Changing the hard-coded value for the text attribute in the Attributes pane  Modifying resource files  Changing the application XML source code − It is good programming practice to add an id attribute to each component (object) for use in Java code
  • 39. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 39 1.8 The User Interface Layout within the Virtual Device (11 of 12) Figure 1-18 Emulator with TextView control and text attribute
  • 40. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 40 1.8 The User Interface Layout within the Virtual Device (12 of 12) Figure 1-19 The id attribute
  • 41. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 41 1.9 Executing an Android Application on an Emulator (1 of 2) • The Android emulator (virtual device) runs slowly − Even when idling, it consumes significant CPU time • To run and automatically save your app, click the Run button • Click the Terminate button to stop the emulator from running
  • 42. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 42 1.9 Executing an Android Application on an Emulator (2 of 2) Figure 1-20 Hello Android World app displayed in emulator
  • 43. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 43 Activity 1.2: Knowledge Check 1. In Android Studio, objects such as buttons and text boxes are called _____. 2. Java code source files are stored in the _____ folder. 3. Testing the app is done in a(n) _____.
  • 44. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 44 Activity 1.2: Knowledge Check Answers 1. In Android Studio, objects such as buttons and text boxes are called _____. Answer: widgets 2. Java code source files are stored in the _____ folder. Answer: java 3. Testing the app is done in a(n) _____. Answer: emulator
  • 45. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 45 1.10 Opening a Saved Android Project in Android Studio • To load a saved project, open Studio and then choose the project to open − Click on it in the Recent Projects column or − Click Open an existing Android Project in the Quick Start column, navigate to it, and click the OK button
  • 46. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 46 Self-Assessment 1. After reading about the market and requirements for software development for Android devices, what skills would you like to gain or improve before you begin developing Android apps for publication? What aspects of the market for these apps would you like to learn more about? 2. What is your initial impression of the Android Studio and Android SDK tools available to you as an Android developer?
  • 47. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 47 Summary • Click the link to review the objectives for this presentation. Chapter objectives
  • 48. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 48 48 Android Bootcamp for Developers Using Java, 4e Chapter 2: Simplify! The Android User Interface Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 49. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 49 Chapter Objectives (1 of 2) When you complete this chapter, you will be able to: • 02.01 Develop a user interface using the TextView, ImageView, and Button components • 02.02 Add text using the String table in the Translations Editor • 02.03 Construct the user interface using a ConstraintLayout • 02.04 Plan out program design • 02.05 Create multiple Android activities Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 50. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 50 Chapter Objectives (2 of 2) When you complete this chapter, you will be able to: • 02.06 View activities in the Android Manifest file • 02.07 Write code using the onCreate( ) method • 02.08 Create a Button event handler • 02.09 Code a Button event handler • 02.10 Correct errors in code • 02.11 Run the completed app in the emulator Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 51. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 51 2.1 Designing an Android App (1 of 5) Figure 2-1 Easy Recipes Android app (left) Figure 2-2 Second screen with recipe (right)
  • 52. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 52 2.1 Designing an Android App (2 of 5) • Designing apps is like constructing a building • The Big Picture: To create the Easy Recipes app, you follow a set of steps that you repeat every time you create an Android application − Create the user interface (XML layout) for every screen − Create a Java class (Activity) for every screen − Code each Java class with appropriate objects and actions − Test the application in the Android phone emulator
  • 53. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 53 2.1 Designing an Android App (3 of 5) • Using the Android User Interface − Interface: the space where interactions occur between people and the app − Android apps run on various form factors − The layout is stored as XML code  Special Android-formatted XML code is extremely compact  XML is a set of instructions for placing components on the screen
  • 54. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 54 2.1 Designing an Android App (4 of 5) Figure 2-4 Creating an empty activity for the Easy Recipes app
  • 55. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 55 2.1 Designing an Android App (5 of 5) Figure 2-5 Android Studio open and ready for you to design the Easy Recipes app
  • 56. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 56 2.2 Using the String Table in the Translations Editor (1 of 5) • The Translations Editor in Android Studio can display the original text in the language in which it was programmed, or the language of the current locale plus culturally specific settings • The String Table − Android provides the strings.xml file or String table inside the Resources folder − strings.xml: a default file that is part of every Android application and contains commonly used strings for an application − string: a series of alphanumeric characters that can include spaces
  • 57. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 57 2.2 Using the String Table in the Translations Editor (2 of 5) • The String Table (continued) − Localization: the use of the String table to change text based on the user’s preferred language − Every string is composed of a key (a.k.a. id attribute), which is the name of a component, and a default value, which is the text associated with the component − To create an application that is accessible to those with visual disabilities, add descriptions to the user interface components that can be read out loud to your user by a speech-based accessibility service such as a screen reader
  • 58. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 58 2.2 Using the String Table in the Translations Editor (3 of 5) Figure 2-7 The strings.xml tab displaying XML code
  • 59. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 59 2.2 Using the String Table in the Translations Editor (4 of 5) Figure 2-10 Adding another string to the String table
  • 60. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 60 2.2 Using the String Table in the Translations Editor (5 of 5) Figure 2-11 Completed String table on the Translations Editor tab
  • 61. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 61 2.3 Constructing the User Interface with the ConstraintLayout (1 of 18) • The Android user interface includes a layout resource designer called the ConstraintLayout in the Component Tree − Organizes how components appear on the app’s screens − Provides more flexibility in positioning components than other layouts − Constraints: the building blocks in an Android layout that attach or align a component to the screen, either by attaching it vertically and horizontally to the edges of the screen or aligning it with another component (or parent) on the screen − Constraints are used to create a Responsive Design UI
  • 62. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 62 2.3 Constructing the User Interface with the ConstraintLayout (2 of 18) • Constraint Handles − Four circular dots on the edges of a selected component − A Constraint component must have at least two constraints—a vertical and a horizontal one − If you drag all four Constraint handles to the four edges of the emulator screen, you can then drag the component anywhere on the screen and it will stay in that location when you run the app − In the ConstraintLayout, a nonconstrained component will float to the top of the screen when the app is run
  • 63. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 63 2.3 Constructing the User Interface with the ConstraintLayout (3 of 18) • Constraint Handles (continued) − A white Constraint handle means that the component is not aligned − A blue Constraint handle means that the component is aligned with the screen or another component − Corner boxes resize the component Figure 2-12 The four circles are Constraint handles
  • 64. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 64 2.3 Constructing the User Interface with the ConstraintLayout (4 of 18) • XML Code − After you move the Constraint handles in the Design view, Android Studio updates your layout resources as XML code in the res/layout resource directory − Other common layouts used in Android Studio include:  LinearLayout  RelativeLayout  TableLayout  GridView
  • 65. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 65 2.3 Constructing the User Interface with the ConstraintLayout (5 of 18) Figure 2-13 ConstraintLayout XML code
  • 66. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 66 2.3 Constructing the User Interface with the ConstraintLayout (6 of 18) • The Easy Recipes Opening User Interface: To change a component's attributes, select it and use the Attributes pane • Android Text Attributes − The text attribute uses text from a string resource to display within the component − The textSize attribute can use various units of measurement  The preferred unit is often sp (scaled-independent pixels)  Other units: inches (in), millimeters (mm), pixels (px), density- independent pixels (dp or dip)
  • 67. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 67 2.3 Constructing the User Interface with the ConstraintLayout (7 of 18) Figure 2-16 The text attribute with @string used to display the String table
  • 68. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 68 2.3 Constructing the User Interface with the ConstraintLayout (8 of 18) Figure 2-17 TextView text displayed in emulator after @string selected
  • 69. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 69 2.3 Constructing the User Interface with the ConstraintLayout (9 of 18) Figure 2-18 Updating the textSize of the TextView component
  • 70. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 70 2.3 Constructing the User Interface with the ConstraintLayout (10 of 18) • Adding a File to the Resources Folder − Graphics used in ImageView components must first be placed in the res/drawable folder − Android supports .png (preferred), .jpg (acceptable), and .gif (discouraged) graphic formats − Android categorizes device screens based on size and density − Android creates a Drawable resource for images when you save them in the res/drawable folder
  • 71. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 71 2.3 Constructing the User Interface with the ConstraintLayout (11 of 18) Figure 2-19 The sorbet.png file copied into the drawable folder within the res folder
  • 72. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 72 2.3 Constructing the User Interface with the ConstraintLayout (12 of 18) • The ImageView Component − An ImageView component can display an icon, a company logo, or a graphic on the Android screen − Reminder: The image to be used should be placed in a drawable resources folder before the ImageView component is placed in the emulator
  • 73. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 73 2.3 Constructing the User Interface with the ConstraintLayout (13 of 18) Figure 2-23 ImageView component with image displayed in the emulator and the id entered
  • 74. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 74 2.3 Constructing the User Interface with the ConstraintLayout (14 of 18) Figure 2-24 The contentDescription set for accessibility
  • 75. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 75 2.3 Constructing the User Interface with the ConstraintLayout (15 of 18) • Adding a Button Component − Button components are commonly used in GUIs − The Android SDK includes four types of button components: Button, FloatingActionButton, ToggleButton, and ImageButton − backgrountTint: an attribute that can be added to a component to set a background color − textColor: an attribute that sets the color of the text in a component
  • 76. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 76 2.3 Constructing the User Interface with the ConstraintLayout (16 of 18) Figure 2-26 Button component placed on emulator and the id named
  • 77. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 77 2.3 Constructing the User Interface with the ConstraintLayout (17 of 18) Figure 2-27 Button displaying larger text
  • 78. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 78 2.3 Constructing the User Interface with the ConstraintLayout (18 of 18) Figure 2-28 Button with colors displayed for background tint color
  • 79. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 79 Activity 2.1: Knowledge Check (1 of 2) 1. List the major steps you follow to create an Android application. 2. Android loads text resources from the project's _____. 3. Which Android layout provides flexibility in positioning components and facilitates making your layout a Responsive Design UI?
  • 80. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 80 Activity 2.1: Knowledge Check (2 of 2) 4. Which unit of measurement is often preferred for the textSize attribute? Why? 5. To display an illustration or photo in an Android app you use a(n) _____.
  • 81. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 81 Activity 2.1: Knowledge Check Answers (1 of 2) 1. List the major steps you follow to create an Android application. Answer: (1) Create the user interface (XML layout) for each screen. (2) Create a Java class (Activity) for every screen. (3) Code each Java class with the appropriate objects and actions. (4) Test the application in the emulator. 2. Android loads text resources from the project's _____. Answer: string table or strings.xml file 3. Which Android layout provides flexibility in positioning components and facilitates making your layout a Responsive Design UI? Answer: ConstraintLayout
  • 82. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 82 Activity 2.1: Knowledge Check Answers (2 of 2) 4. Which unit of measurement is often preferred for the textSize attribute? Why? Answer: sp (scaled-independent pixels), because it will scale the font to meet the user's size preference 5. To display an illustration or photo in an Android app you use a(n) _____. Answer: ImageView component
  • 83. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 83 2.4 Planning Out Program Design • Phases in the program development life cycle: − Gather and analyze the program requirements − Design the user interface − Design the program processing objects − Code the program − Test the program • Creating Activities − Activity: a screen, constructed from XML files and a Java class
  • 84. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 84 2.5 Creating Multiple Android Activities (1 of 2) • A class describes a group of objects and serves as a blueprint, or template, for creating those objects • An object is a specific, concrete instance of a class • When you create an object, you instantiate it, meaning you define one particular variation of the object within a class • Each screen represents one Activity, and each Activity must have a matching Java class file within the java folder • The convention is to use Pascal case for Java class names
  • 85. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 85 2.5 Creating Multiple Android Activities (2 of 2) Figure 2-34 New Recipe class in the Easy Recipes project
  • 86. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 86 2.6 Viewing Activities in the Android Manifest File (1 of 3) • The Android Manifest file (AndroidManifest.xml) contains: − The name of the Java application − A listing of each activity − Permissions needed to access other Android functions (such as the Internet, services, and broadcast receivers) − The minimum level of the Android API • Android Studio automatically adds each activity you create to the Android Manifest file
  • 87. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 87 2.6 Viewing Activities in the Android Manifest File (2 of 3) Figure 2-35 AndroidManifest.xml
  • 88. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 88 2.6 Viewing Activities in the Android Manifest File (3 of 3) • Coding the Android Activity − The entry point of the Activity class is the onCreate() event handler method  Where you initialize the Activity by placing it on the top of Android's stack of Activities − Method: a set of Java statements that can be included inside a Java class; a piece of code that performs some type of action − Method body: a collection of statements that defines what the method does
  • 89. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 89 2.7 Writing Code Using the onCreate() Method (1 of 2) • Syntax for the onCreate() method: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } • This method has a void return type, which means it does not return anything • The Java code necessary to display the content of a specific screen is called SetContentView, which has the following syntax: setContentView(R.layout.activity_main);
  • 90. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 90 2.7 Writing Code Using the onCreate() Method (2 of 2) Figure 2-36 MainActivity.java code for onCreate( ) method
  • 91. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 91 2.8 Creating a Button Event Handler (1 of 3) • Event handler: a part of a program coded to respond to a specific event • Tapping a button is called a click event in Java code • Java code for an event handler must contain the following sections: − A class attribute to hold a reference to the Button object: Button = (Button)findViewById(R.id.btRecipe);  Includes the findViewById() method to find a layout XML file − An OnClickListener() method to await the button click action's onClick() method to respond to the click event
  • 92. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 92 2.8 Creating a Button Event Handler (2 of 3) • When you import the Button type as an Android widget, the button package becomes available throughout the app − An import statement makes more Java functions available to your app • After the Button attribute is referenced in MainActivity.java, an OnClickListener() method is necessary to detect when the user taps an on-screen button • When an OnClickListener is placed in the code window, Java creates an onClick auto-generated stub—a piece of code that serves as a placeholder to declare itself
  • 93. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 93 2.8 Creating a Button Event Handler (3 of 3) • Syntax for an OnClickListener() method that listens for a Button: button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub } }); • The startActivity() method creates an intent to start another Activity − Two parameters: context and name of Activity to open − Syntax: startActivity(new Intent(MainActivity.this, Recipe.class));
  • 94. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 94 2.9 Coding a Button Event Handler (1 of 3) Figure 2-38 Button instantiated with Button library added
  • 95. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 95 2.9 Coding a Button Event Handler (2 of 3) Figure 2-40 The setOnClickListener added with auto-complete feature
  • 96. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 96 2.9 Coding a Button Event Handler (3 of 3) Figure 2-41 Complete code for MainActivity.java— startActivity will launch the second screen’s Recipe.class when the user clicks the button
  • 97. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 97 Activity 2.2: Knowledge Check (1 of 2) 1. Name the phases of the development life cycle in order. 2. The file included in each Android application that provides essential information such as the minimum API level to the Android device is called _____.
  • 98. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 98 Activity 2.2: Knowledge Check (2 of 2) 3. Which Java method initializes an Android Activity? 4. A part of a program that responds to a user interaction such as tapping an on- screen button is called a(n) _____. 5. Which Java method is necessary to detect a user interaction with the app?
  • 99. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 99 Activity 2.2: Knowledge Check Answers (1 of 2) 1. Name the phases of the development life cycle in order. Answer: (1) Gather and analyze the program requirements. (2) Design the user interface. (3) Design the program processing objects. (4) Code the program. (5) Test the program. 2. The file included in each Android application that provides essential information such as the minimum API level to the Android device is called _____. Answer: the Android Manifest or AndroidManifest.xml
  • 100. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 100 Activity 2.2: Knowledge Check Answers (2 of 2) 3. Which Java method initializes an Android Activity? Answer: onCreate() 4. A part of a program that responds to a user interaction such as tapping an on- screen button is called a(n) _____. Answer: event handler 5. Which Java method is necessary to detect a user interaction with the app? Answer: OnClickListener()
  • 101. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 101 2.10 Correcting Errors in Code Figure 2-42 Syntax error
  • 102. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 102 2.11 Saving and Running the Application • Each time an Android application is tested in the emulator, the programming design and code are automatically saved • Click the toolbar's Save All button to save the project • Click the toolbar’s Run app button to test the application in the emulator − The first time an app is executed, you will be prompted to choose an emulator
  • 103. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 103 Self-Assessment 1. What is your opinion of the Android Studio user interface design tools? Are there any improvements you'd like to see? Which tools do you anticipate using most often when creating or updating Android apps? 2. When creating the app project for Chapter 2, which did you enjoy more: working with the XML layout tools in Studio or writing Java code? How do you expect to use these UI creation skills in your future career?
  • 104. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 104 Summary • Click the link to review the objectives for this presentation. Chapter objectives
  • 105. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 105 105 Android Bootcamp for Developers Using Java, 4e Chapter 3: Engage! Android User Input, Variables, and Operations Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 106. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 106 Chapter Objectives (1 of 3) When you complete this chapter, you will be able to: • 03.01 Collect user input • 03.02 Add a Text Number component • 03.03 Add a string array • 03.04 Change the background attribute • 03.05 Set the hint attribute for a Text component • 03.06 Develop a user interface using a Spinner component Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 107. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 107 Chapter Objectives (2 of 3) When you complete this chapter, you will be able to: • 3.07 Add a prompt and entries to a Spinner component • 3.08 Code the EditText class for the Text Number component • 3.09 Code the Spinner component • 3.10 Instantiate the Button component and variables • 3.11 Code the getText() method Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 108. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 108 Chapter Objectives (3 of 3) When you complete this chapter, you will be able to: • 3.12 Understand arithmetic operations • 3.13 Code the setText( ) method Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 109. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 109 3.1 Collecting User Input (1 of 4) Figure 3-1 Opening screen for Concert Tickets app
  • 110. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 110 3.1 Collecting User Input (2 of 4) • Processes required to create this application: − Define display text using the Translations Editor and strings.xml file − Set the background color − Define a Text Number component − Define a Spinner component − Convert string data to numeric data − Perform arithmetic operations with user-entered data − Display the results, properly formatted, to the user
  • 111. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 111 3.1 Collecting User Input (3 of 4) • Simplifying User Input − The onscreen keyboard is called a soft keyboard − Input can come in the form of tapping or gestures (using two fingers to pan, rotate, or zoom) − The primary design challenge is to simplify the user experience  Use legible fonts, simplify input, and optimize each device’s capabilities to maximize user experience
  • 112. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 112 3.1 Collecting User Input (4 of 4) • Using Android Text Components − Text entered via a soft or physical keyboard is the most common type of mobile input − Text components can request different input types (e.g., plain text, phone number, various types of numeric values) − The component type can constrain the characters available • User Experience − User experience refers to all aspects of interaction with a device
  • 113. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 113 3.2 Adding a Text Number Component (1 of 3) • You can use the id attribute in the Attributes pane to enter a name that begins with the prefix tv (for TextView) − Use descriptive names like tvTickets • Using the String Table − String items displayed in the components of an app can be stored in the string table (strings.xml) − A string array can be used to store a group of related strings
  • 114. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 114 3.2 Adding a Text Number Component (2 of 3) Figure 3-5 Adding strings in the Translations Editor
  • 115. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 115 3.2 Adding a Text Number Component (3 of 3) Figure 3-6 String table
  • 116. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 116 3.3 Adding a String Array (1 of 2) • A string array defines a string resource of related items in a central location within strings.xml • An item defines an individual entry within a string array • As you type the string array XML code, the Android Studio editor offers suggestions in a panel that can complete a statement
  • 117. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 117 3.3 Adding a String Array (2 of 2) Figure 3-9 The string array named tvGroup with three items added in XML code
  • 118. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 118 3.4 Changing Background Attributes (1 of 4) • The Android background feature can help provide an app's individual flair • The background is white by default • To change it, set the background attribute in the Attributes pane
  • 119. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 119 3.4 Changing Background Attributes (2 of 4) Figure 3-10 Changing the background color
  • 120. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 120 3.4 Changing Background Attributes (3 of 4) Figure 3-11 Title added to emulator
  • 121. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 121 3.4 Changing Background Attributes (4 of 4) Figure 3-12 Adding a Text Number component
  • 122. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 122 3.5 Setting the Hint Attribute for a Text Component (1 of 2) • A hint is a short description of a component that is visible as gray text (also called a watermark) inside a Text Number component or any Text input − Often used to provide guidelines about the input expected in a component for the user • You can change the color of the hint by changing the textColorHint attribute − May be necessary to ensure adequate contrast between the text and background
  • 123. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 123 3.5 Setting the Hint Attribute for a Text Component (2 of 2) Figure 3-15 Warning symbol removed from Text Number component
  • 124. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 124 Activity 3.1: Knowledge Check 1. If a component holds multiple text strings, it is best to store them in a(n) _____. 2. To change the screen color for an activity in your app, you set the _____. 3. When you see gray text describing what sort of data to enter within a text entry box in an app, you are looking at a(n) _____.
  • 125. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 125 Activity 3.1: Knowledge Check Answers 1. If a component holds multiple text strings, it is best to store them in a(n) _____. Answer: string array 2. To change the screen color for an activity in your app, you set the _____. Answer: background attribute 3. When you see gray text describing what sort of data to enter within a text entry box in an app, you are looking at a(n) _____. Answer: hint
  • 126. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 126 3.6 Developing a User Interface Using a Spinner Component • A Spinner component is similar to a drop-down list for selecting a single item from a fixed list • The Spinner component displays a prompt with a list of strings called items • Figure 3-16 Spinner dialog box displaying the three concert groups
  • 127. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 127 3.7 Adding a Prompt and Entries to a Spinner Component (1 of 6) • A prompt, which can be used to display instructions at the top of the Spinner control, is stored in strings.xml and is named prompt • Using Entries − The Spinner attribute called entries connects the string array in strings.xml to the Spinner component so the entries can be displayed in the application − The spinnerMode attribute sets the component to dialog mode or drop- down mode − The layout_width and layout_height attributes set the dimensions
  • 128. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 128 3.7 Adding a Prompt and Entries to a Spinner Component (2 of 6) Figure 3-18 Pick a Resource dialog box with tvGroup string array selected
  • 129. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 129 3.7 Adding a Prompt and Entries to a Spinner Component (3 of 6) • Adding the Button, TextView, and ImageView Controls − ImageView components should have a content description for visually impaired users − This description is provided by setting the contentDescription attribute
  • 130. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 130 3.7 Adding a Prompt and Entries to a Spinner Component (4 of 6) Figure 3-20 Adding a Button component
  • 131. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 131 3.7 Adding a Prompt and Entries to a Spinner Component (5 of 6) Figure 3-21 Adding a TextView component
  • 132. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 132 3.7 Adding a Prompt and Entries to a Spinner Component (6 of 6) Figure 3-22 Adding an ImageView component with a contentDescription attribute
  • 133. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 133 3.8 Coding the EditText Class for the Text Number Component (1 of 2) • A Java variable is used to contain data that changes during the execution of a program • A final variable can be initialized only once − Attempting to reassign the value results in a compile error when the application runs • For the concert tickets app, you insert code to create the tickets variable containing the extracted EditText class text: final EditText tickets = (EditText)findViewById(R.id.tvTickets);
  • 134. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 134 3.8 Coding the EditText Class for the Text Number Component (2 of 2) Figure 3-23 EditText code for Text Number component
  • 135. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 135 3.9 Coding the Spinner Control Figure 3-24 Spinner component code
  • 136. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 136 3.10 Instantiating the Button Component and Variables (1 of 6) • An OnClickListener waits in the background and listens for the user to click a button • Clicking the button activates a Button event, triggering the Button event OnClick handler to execute the associated code • Code to instantiate the TextView component to a variable named result is used to display the result of the ticket price calculation in the concert tickets app: final TextView result = ((TextView)findViewById(R.id.tvResult));
  • 137. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 137 3.10 Instantiating the Button Component and Variables (2 of 6) Figure 3-27 TextView component code for the result
  • 138. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 138 3.10 Instantiating the Button Component and Variables (3 of 6) • Declaring Variables − Two steps are necessary in order to use a variable: (1) declare the variable and (2) assign a value to the variable − The declared type of a variable determines which operations are allowed − Java has eight built-in primitive (simple) types of data • Primitive Data Types − Java requires all variables to have a data type
  • 139. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 139 3.10 Instantiating the Button Component and Variables (4 of 6) Type Meaning Range Default Value byte Often used with arrays –128 to 127 0 short Often used with arrays –32,768 to 32,767 0 int Most commonly used number value –2,147,483,648 to 2,147,483,647 0 long Used for numbers that exceed int –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 0 float A 32-bit floating-point number +/–3.40282347 ^38 0 double Most common for decimal values +/–1.79769313486231570 ^308 0 char Used for single characters Characters 0 boolean Used for conditional statements True or false False
  • 140. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 140 3.10 Instantiating the Button Component and Variables (5 of 6) • Primitive Data Types (continued) − Sample variable initialization and declarations: double costPerTicket = 89.99; int numberOfTickets; double totalCost; String groupChoice; • The String Data Type − The String type is a class and not a primitive data type − A string can be a character, word, or phrase
  • 141. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 141 3.10 Instantiating the Button Component and Variables (6 of 6) • The String Data Type (continued) − Most strings used in Java are objects of type String (e.g., String groupChoice;) • Declaring the Variables in the Project − Typically declared at the beginning of an activity − Variables must be declared before you can use them
  • 142. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 142 3.11 Coding the getText() Method (1 of 2) • Data stored in the EditText component can be read with the getText() method • Data is read in as a string, by default • A Parse class is used to convert strings into numbers − Parse types include Integer.parseInt(), Float.parseFloat(), Double.parseDouble(), and Long.parseLong() • Sample code to extract a string and convert it into an integer: numberOfTickets = Integer.parseInt(tickets.getText().toString());
  • 143. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 143 3.11 Coding the getText() Method (2 of 2) • Working with Mathematical Operations − The ability to perform arithmetic operations is fundamental to many applications − Most programs require arithmetic operations to add, subtract, multiply, and divide numeric data
  • 144. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 144 Activity 3.2: Knowledge Check 1. A drop-down list for an Android app is created using a(n) _____. 2. The attribute that connects the choices for a drop-down list to their component is called _____. 3. Which Java keyword prevents a variable from being reassigned? 4. Which Java method reads text stored in an EditText component?
  • 145. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 145 Activity 3.2: Knowledge Check Answers 1. A drop-down list for an Android app is created using a(n) _____. Answer: Spinner component 2. The attribute that connects the choices for a drop-down list to their component is called _____. Answer: entries 3. Which Java keyword prevents a variable from being reassigned? Answer: final 4. Which Java method reads text stored in an EditText component? Answer: getText()
  • 146. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 146 3.12 Understanding Arithmetic Operators (1 of 3) • Java's arithmetic operators are + (addition), – (subtraction), * (multiplication), / (division), % (remainder), ++ (increment 1), and -- (decrement 1) • The order of operations determines the sequence for performing calculations when multiple operators are included in an expression − Parentheses; ++ & --; *, /, & %; + & – (left to right) • Formatting Numbers − Java includes a class called DecimalFormat that provides patterns for formatting numbers for output on the Android device
  • 147. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 147 3.12 Understanding Arithmetic Operators (2 of 3) Figure 3-30 Calculating and formatting the ticket cost
  • 148. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 148 3.12 Understanding Arithmetic Operators (3 of 3) • Displaying Android Output: Computed results must be displayed • Using the getSelectedItem() Method − The getSelectedItem() method returns the text label of the currently selected Spinner item − Sample code that assigns a selected item to a String variable named groupChoice: groupChoice = group.getSelectedItem( ).toString( );
  • 149. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 149 3.13 Coding the setText() Method • The setText() method displays text in a TextView component • You can concatenate text and string variable values using +, e.g., String mobile = "Android"; String completeSentence = mobile + " is a platform."; • Sample statement using the setText() method to display text in a TextView component named result: result.setText("Cost for " + groupChoice + " is " + currency.format(totalCost));
  • 150. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 150 Self-Assessment 1. At this point, how comfortable are you using Java classes such as String and Parse to accomplish the goals of a program? What else would you like to learn about these Java classes? 2. Consider the Java methods used to code the sample concert ticket application. How do you anticipate using these methods for your own app development? What would their most common use cases be for you?
  • 151. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 151 Summary • Click the link to review the objectives for this presentation. Chapter objectives
  • 152. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 152 152 Android Bootcamp for Developers Using Java, 4e Chapter 4: Explore! Icons and Decision-Making Components Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 153. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 153 Chapter Objectives (1 of 3) When you complete this chapter, you will be able to: • 04.01 Create an Android project with a custom icon • 04.02 Display the Action bar icon using code • 04.03 Place a RadioGroup and RadioButtons in Android applications • 04.04 Determine layouts with the layout:margin attributes • 04.05 Align components using the foregroundGravity attributes Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 154. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 154 Chapter Objectives (2 of 3) When you complete this chapter, you will be able to: • 04.06 Add a RadioButton Group • 04.07 Write code for a RadioButton component • 04.08 Make decisions with conditional statements • 04.09 Make decisions using an If statement • 04.10 Make decisions using an If Else statement Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 155. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 155 Chapter Objectives (3 of 3) When you complete this chapter, you will be able to: • 04.11 Make decisions using logical operators • 04.12 Display an Android toast notification • 04.13 Use the isChecked() method with RadioButtons • 04.14 Make decisions using nested If statements Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
  • 156. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 156 4.1 Creating an Android Project with a Custom Icon (1 of 12) • We will be creating an app to convert pounds to kilograms and kilograms to pounds • App is designed to be used in a hospital setting to administer medication to patients based on patient weight • Hospital scales register pounds, whereas medication dosages are based on patient weight in kilograms • Formulas needed: − Kilograms = pounds * 2.2 − Pounds = kilograms / 2.2
  • 157. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 157 4.1 Creating an Android Project with a Custom Icon (2 of 12) Figure 4-1 Opening screen of the Medical Calculator Figure 4-2 Results screen of the Medical Calculator
  • 158. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 158 4.1 Creating an Android Project with a Custom Icon (3 of 12) • Steps to complete the app: − Create a customized launcher icon − Use code to add the icon for display in the Action bar − Define a TextField for the data entry of the weight of the patient − Define a RadioGroup to select a conversion of pounds to kilograms or kilograms to pounds − Display a toast message for data validation − Convert data so it can be used for arithmetic operations
  • 159. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 159 4.1 Creating an Android Project with a Custom Icon (4 of 12) • Steps to complete the app (continued): − Perform arithmetic operations on data the user enters − Display formatted results
  • 160. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 160 4.1 Creating an Android Project with a Custom Icon (5 of 12) • Using the Launcher Icon − The launcher icon opens the app from the home screen and represents the app when it is published to Google Play − A high-quality launcher icon can influence users to purchase your app − Icons can establish brand identity − Simple images with clear visual cues have a memorable impact − Vector-based graphics are best for icon design because these images can be easily scaled without loss of detail
  • 161. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 161 4.1 Creating an Android Project with a Custom Icon (6 of 12) • Using the Launcher Icon (continued) − Google Play specifies the size and format of all launcher icons − Should be saved with the .png file format/extension − When you publish an app to Google Play, you must provide a 512 × 512- pixel, high-resolution application icon in the developer console as you upload your program  This icon is displayed on the Google Play site to provide a description of the app and does not replace your launcher icon − Google Play's naming convention for launcher icons: ic_launcher
  • 162. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 162 4.1 Creating an Android Project with a Custom Icon (7 of 12) Resolution Dots Per Inch (dpi) Size (px) ldpi (low-density screen) 120 36 × 36 mdpi (medium-density screen) 160 48 × 48 hdpi (high-density screen) 240 72 × 72 xhdpi (extra high-density screen) 320 96 × 96 xxhdpi (extra extra high-density screen) 480 144 × 144 xxxhdpi (extra extra extra high-density screen) 640 192 × 192
  • 163. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 163 4.1 Creating an Android Project with a Custom Icon (8 of 12) • Customizing a Launcher Icon − Image Asset Studio: Android Studio tool that helps you generate your own app icons from images  Generates a set of icons at the appropriate resolution for each pixel density your app supports − Use the built-in Image Asset Studio wizard to create these multiple icons and store them in the correct folders
  • 164. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 164 4.1 Creating an Android Project with a Custom Icon (9 of 12) Figure 4-6 Default launcher icons in the Asset Studio
  • 165. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 165 4.1 Creating an Android Project with a Custom Icon (10 of 12) Figure 4-7 Custom launcher icons
  • 166. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 166 4.1 Creating an Android Project with a Custom Icon (11 of 12) Figure 4-8 Confirmed icon path in Asset Studio displayed in res/mipmap folders
  • 167. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 167 4.1 Creating an Android Project with a Custom Icon (12 of 12) Figure 4-9 Resized custom icons and their pathways in the mipmap folder
  • 168. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 168 4.2 Displaying the Action Bar Icon Using Code (1 of 4) • An Action bar icon is considered a logo that represents what the program’s function is in a single glance − For example, the medical symbol conveys the purpose and identity of the app • Supporting code needed in MainActivity.java to display the image in the Action bar: getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setLogo(R.mipmap.ic_launcher); getSupportActionBar().setDisplayUseLogoEnabled(true);
  • 169. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 169 4.2 Displaying the Action Bar Icon Using Code (2 of 4) Figure 4-11 Icon displayed in running app in the emulator
  • 170. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 170 4.2 Displaying the Action Bar Icon Using Code (3 of 4) • String Table − String resources are stored within the /res/values/strings.xml file − Any strings you add to the strings.xml file are accessible within your application
  • 171. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 171 4.2 Displaying the Action Bar Icon Using Code (4 of 4) Figure 4-12 Translations Editor with new strings in the String table
  • 172. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 172 4.3 Placing a RadioGroup and RadioButtons in Android Applications (1 of 2) • RadioButton components are used to select or deselect an option − Can be arranged horizontally or vertically − Have a label defined by the Text attribute − Checked attribute can be set to true or false − Typically used together in a RadioGroup container  Only one RadioButton in the group can be selected at a time − It saves time to offer a default selection (checked = true) for the option that is used most often 172
  • 173. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 173 4.3 Placing a RadioGroup and RadioButtons in Android Applications (2 of 2) • Changing the Text Color of RadioButton and CheckBox Components − Hexadecimal color code: a triplet of three colors  Example: #FF0000 is a true red  Color system used by the Android platform − Codes range from 00 to FF (00 = none, FF = full) − Codes are identified by a pound sign, followed by the red, green, and blue values contained in the color 173
  • 174. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 174 4.4 Determining Layouts with the layout:margin Attributes • You can change a component's alignment after placing it on the UI by adjusting its Gravity settings • The layout:margin attribute allows for more flexibility in controlling your layout − You can change all margins equally or change the left, top, right, and bottom margins individually • Set density-independent pixel (dp) values instead of “eyeballing” to create equal spaces around components • Using the same specified margins creates a symmetrical layout
  • 175. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 175 Activity 4.1: Knowledge Check (1 of 2) 1. What is an app's opening icon called? 2. What tool can you use to generate a launcher icon from an image? 3. RadioButton components are typically used together in a(n) _____. 4. What is #FF0000?
  • 176. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 176 Activity 4.1: Knowledge Check (2 of 2) 5. What settings are used to change the alignment of an object? 6. Which attribute can you use to set the spacing around each side of an object individually?
  • 177. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 177 Activity 4.1: Knowledge Check Answers (1 of 2) 1. What is an app's opening icon called? Answer: The launcher icon 2. What tool can you use to generate a launcher icon from an image? Answer: Image Asset Studio 3. RadioButton components are typically used together in a(n) _____. Answer: RadioGroup 4. What is #FF0000? Answer: The hexadecimal color code for a true red color
  • 178. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 178 Activity 4.1: Knowledge Check Answers (2 of 2) 5. What settings are used to change the alignment of an object? Answer: Gravity settings 6. Which attribute can you use to set the spacing around each side of an object individually? Answer: layout:margin attribute
  • 179. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 179 4.5 Aligning Components Using the foregroundGravity Attributes • A component's gravity can be changed using the Attributes pane or with a toolbar shortcut • The foregroundGravity tool changes the linear alignment of a component • Layout gravity is similar to the alignment feature in Microsoft Office that allows a component to snap to the left, center, right, top, or bottom
  • 180. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 180 4.6 Adding the RadioButton Group and Other Components (1 of 5) • When naming a RadioButton with the id attribute, use a name that begins with the prefix rb, which represents a radio button in the code • Completing the User Interface − Remember to create a clean layout and use the entire screen effectively
  • 181. Hoisington, Android Bootcamp for Developers Using Java, 4th Edition. © 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 181 4.6 Adding the RadioButton Group and Other Components (2 of 5) Figure 4-15 Text Number component and foregroundGravity attribute to center hint text

Editor's Notes

  1. Instructions: Task: This is an introductory exercise for the beginning of a course. Objectives: To provide an informal way for participants to learn about each other and begin working together. This exercise also gives students practice speaking in front of a group, introduces them to interviewing, and gives the instructor insight into who the students are and what is important to them.  Steps: Break the class into pairs of students. Have them interview each other to discover interesting facts and then introduce each other to the class.  Average Time in Class: 30–45 min Note: To adapt this activity for an online learning environment, conduct the interviews using a web conferencing tool (e.g., Zoom or Microsoft Teams). When you break the class into pairs, send the pairs into breakout rooms for 10 minutes to interview each other. When the class comes back together, give each pair 2–4 minutes to introduce each other to the rest of the class.
  2. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  3. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  4. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  5. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  6. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  7. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  8. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  9. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  10. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  11. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  12. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  13. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  14. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  15. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  16. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  17. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  18. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  19. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  20. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  21. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  22. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  23. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  24. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  25. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  26. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  27. Table 3-2 Primitive data types in Java
  28. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  29. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  30. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  31. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  32. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  33. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  34. Table 4-1 Launcher icon sizes
  35. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  36. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  37. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  38. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  39. Table 4-3 Relational operators
  40. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  41. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  42. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  43. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  44. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  45. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  46. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  47. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  48. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  49. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  50. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  51. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  52. Table 6-2 Methods used in the life cycle of an Activity
  53. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  54. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  55. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  56. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  57. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  58. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  59. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  60. Table 7-1 GridView component attributes
  61. Table 7-2 Animals array
  62. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  63. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  64. Table 7-3 Arguments in the onItemClick() method
  65. Table 7-4 Popular ScaleType options
  66. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  67. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  68. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  69. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  70. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  71. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  72. Table 8-1 Table for Linear layout
  73. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  74. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  75. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  76. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  77. Table 8-2 XML code for common themes
  78. Instructions: Use the Self-Assessment question to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  79. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  80. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  81. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  82. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  83. Code Syntax box from page 316
  84. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  85. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  86. Instructions: Use the Self-Assessment question to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  87. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  88. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  89. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  90. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  91. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  92. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  93. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  94. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  95. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  96. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  97. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  98. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  99. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  100. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  101. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.
  102. Instructions: Briefly review with students the major concepts you will be covering during this class. There is one objective for every major A-Head section of the chapter.
  103. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  104. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  105. Table 12-1 App category types on Google Play
  106. Table 12-1 App category types on Google Play (continued)
  107. Table 12-1 App category types on Google Play (continued)
  108. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  109. Instructions: Use the Knowledge Check questions to periodically pose a question to students during class to gauge how well they can recall the material that was presented.
  110. Instructions: Use the Self-Assessment questions to encourage students to evaluate their progress or goals in the course, as well as determine how they might apply their learning or grow as an individual.