Android Studio Arctic Fox Essentials Java Edition Developing Android Apps Using Android Studio 2020 31 and Java Neil Smyth - Quickly access the ebook and start reading today
Android Studio Arctic Fox Essentials Java Edition Developing Android Apps Using Android Studio 2020 31 and Java Neil Smyth - Quickly access the ebook and start reading today
com
https://ebookmeta.com/product/android-studio-arctic-fox-
essentials-java-edition-developing-android-apps-using-
android-studio-2020-31-and-java-neil-smyth/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/fit-feet-for-life-marco-montanez/
ebookmeta.com
The New Environmental Governance 1st Edition Cameron
Holley Neil Gunningham Clifford Shearing
https://ebookmeta.com/product/the-new-environmental-governance-1st-
edition-cameron-holley-neil-gunningham-clifford-shearing/
ebookmeta.com
https://ebookmeta.com/product/abracastabra-hex-falls-paranormal-cozy-
mystery-4-rachel-rivers/
ebookmeta.com
https://ebookmeta.com/product/microwave-chemistry-1st-edition-
giancarlo-cravotto/
ebookmeta.com
https://ebookmeta.com/product/material-science-and-metallurgy-44th-
edition-v-d-kodgire/
ebookmeta.com
https://ebookmeta.com/product/the-routledge-handbook-of-property-law-
and-society-1st-edition-nicole-graham/
ebookmeta.com
Jewish Women in the Medieval World 500 1500 CE Seminar
Studies 1st Edition Ifft Decker
https://ebookmeta.com/product/jewish-women-in-the-medieval-
world-500-1500-ce-seminar-studies-1st-edition-ifft-decker/
ebookmeta.com
Android Studio Arctic Fox
Essentials
Java Edition
Android Studio Arctic Fox Essentials – Java Edition
ISBN-13: 978-1-951442-36-1
© 2021 Neil Smyth / Payload Media, Inc. All Rights Reserved.
is book is provided for personal use only. Unauthorized use, reproduction
and/or distribution strictly prohibited. All rights reserved.
e content of this book is provided for informational purposes only.
Neither the publisher nor the author o ers any warranties or representation,
express or implied, with regard to the accuracy of information contained in
this book, nor do they accept any liability for any loss or damage arising
from any errors or omissions.
is book contains trademarked terms that are used solely for editorial
purposes and to the bene t of the respective trademark owner. e terms
used within this book are not intended as infringement of any trademarks.
Rev: 1.0
Table of Contents
1. Introduction
1.1 Downloading the Code Samples
1.2 Feedback
1.3 Errata
2. Setting up an Android Studio Development Environment
2.1 System Requirements
2.2 Downloading the Android Studio Package
2.3 Installing Android Studio
2.3.1 Installation on Windows
2.3.2 Installation on macOS
2.3.3 Installation on Linux
2.4 e Android Studio Setup Wizard
2.5 Installing Additional Android SDK Packages
2.6 Making the Android SDK Tools Command-line Accessible
2.6.1 Windows 8.1
2.6.2 Windows 10
2.6.3 Linux
2.6.4 macOS
2.7 Android Studio Memory Management
2.8 Updating Android Studio and the SDK
2.9 Summary
3. Creating an Example Android App in Android Studio
3.1 About the Project
3.2 Creating a New Android Project
3.3 Creating an Activity
3.4 De ning the Project and SDK Settings
3.5 Modifying the Example Application
3.6 Modifying the User Interface
3.7 Reviewing the Layout and Resource Files
3.8 Adding Interaction
3.9 Summary
4. Creating an Android Virtual Device (AVD) in Android Studio
4.1 About Android Virtual Devices
4.2 Creating a New AVD
4.3 Starting the Emulator
4.4 Running the Application in the AVD
4.5 Running on Multiple Devices
4.6 Stopping a Running Application
4.7 Supporting Dark eme
4.8 Running the Emulator in a Tool Window
4.9 AVD Command-line Creation
4.10 Android Virtual Device Con guration Files
4.11 Moving and Renaming an Android Virtual Device
4.12 Summary
5. Using and Con guring the Android Studio AVD Emulator
5.1 e Emulator Environment
5.2 e Emulator Toolbar Options
5.3 Working in Zoom Mode
5.4 Resizing the Emulator Window
5.5 Extended Control Options
5.5.1 Location
5.5.2 Displays
5.5.3 Cellular
5.5.4 Battery
5.5.5 Camera
5.5.6 Phone
5.5.7 Directional Pad
5.5.8 Microphone
5.5.9 Fingerprint
5.5.10 Virtual Sensors
5.5.11 Snapshots
5.5.12 Record and Playback
5.5.13 Google Play
5.5.14 Settings
5.5.15 Help
5.6 Working with Snapshots
5.7 Con guring Fingerprint Emulation
5.8 e Emulator in Tool Window Mode
5.9 Summary
6. A Tour of the Android Studio User Interface
6.1 e Welcome Screen
6.2 e Main Window
6.3 e Tool Windows
6.4 Android Studio Keyboard Shortcuts
6.5 Switcher and Recent Files Navigation
6.6 Changing the Android Studio eme
6.7 Summary
7. Testing Android Studio Apps on a Physical Android Device
7.1 An Overview of the Android Debug Bridge (ADB)
7.2 Enabling ADB on Android-based Devices
7.2.1 macOS ADB Con guration
7.2.2 Windows ADB Con guration
7.2.3 Linux adb Con guration
7.3 Testing the adb Connection
7.4 Summary
8. e Basics of the Android Studio Code Editor
8.1 e Android Studio Editor
8.2 Splitting the Editor Window
8.3 Code Completion
8.4 Statement Completion
8.5 Parameter Information
8.6 Parameter Name Hints
8.7 Code Generation
8.8 Code Folding
8.9 Quick Documentation Lookup
8.10 Code Reformatting
8.11 Finding Sample Code
8.12 Live Templates
8.13 Summary
9. An Overview of the Android Architecture
9.1 e Android So ware Stack
9.2 e Linux Kernel
9.3 Android Runtime – ART
9.4 Android Libraries
9.4.1 C/C++ Libraries
9.5 Application Framework
9.6 Applications
9.7 Summary
10. e Anatomy of an Android Application
10.1 Android Activities
10.2 Android Fragments
10.3 Android Intents
10.4 Broadcast Intents
10.5 Broadcast Receivers
10.6 Android Services
10.7 Content Providers
10.8 e Application Manifest
10.9 Application Resources
10.10 Application Context
10.11 Summary
11. An Overview of Android View Binding
11.1 Find View by Id
11.2 View Binding
11.3 Converting the AndroidSample project
11.4 Enabling View Binding
11.5 Using View Binding
11.6 Choosing an Option
11.7 View Binding in the Book Examples
11.8 Migrating a Project to View Binding
11.9 Summary
12. Understanding Android Application and Activity Lifecycles
12.1 Android Applications and Resource Management
12.2 Android Process States
12.2.1 Foreground Process
12.2.2 Visible Process
12.2.3 Service Process
12.2.4 Background Process
12.2.5 Empty Process
12.3 Inter-Process Dependencies
12.4 e Activity Lifecycle
12.5 e Activity Stack
12.6 Activity States
12.7 Con guration Changes
12.8 Handling State Change
12.9 Summary
13. Handling Android Activity State Changes
13.1 New vs. Old Lifecycle Techniques
13.2 e Activity and Fragment Classes
13.3 Dynamic State vs. Persistent State
13.4 e Android Lifecycle Methods
13.5 Lifetimes
13.6 Foldable Devices and Multi-Resume
13.7 Disabling Con guration Change Restarts
13.8 Lifecycle Method Limitations
13.9 Summary
14. Android Activity State Changes by Example
14.1 Creating the State Change Example Project
14.2 Designing the User Interface
14.3 Overriding the Activity Lifecycle Methods
14.4 Filtering the Logcat Panel
14.5 Running the Application
14.6 Experimenting with the Activity
14.7 Summary
15. Saving and Restoring the State of an Android Activity
15.1 Saving Dynamic State
15.2 Default Saving of User Interface State
15.3 e Bundle Class
15.4 Saving the State
15.5 Restoring the State
15.6 Testing the Application
15.7 Summary
16. Understanding Android Views, View Groups and Layouts
16.1 Designing for Di erent Android Devices
16.2 Views and View Groups
16.3 Android Layout Managers
16.4 e View Hierarchy
16.5 Creating User Interfaces
16.6 Summary
17. A Guide to the Android Studio Layout Editor Tool
17.1 Basic vs. Empty Activity Templates
17.2 e Android Studio Layout Editor
17.3 Design Mode
17.4 e Palette
17.5 Design Mode and Layout Views
17.6 Night Mode
17.7 Code Mode
17.8 Split Mode
17.9 Setting Attributes
17.10 Transforms
17.11 Tools Visibility Toggles
17.12 Converting Views
17.13 Displaying Sample Data
17.14 Creating a Custom Device De nition
17.15 Changing the Current Device
17.16 Layout Validation (Multi Preview)
17.17 Summary
18. A Guide to the Android ConstraintLayout
18.1 How ConstraintLayout Works
18.1.1 Constraints
18.1.2 Margins
18.1.3 Opposing Constraints
18.1.4 Constraint Bias
18.1.5 Chains
18.1.6 Chain Styles
18.2 Baseline Alignment
18.3 Con guring Widget Dimensions
18.4 Guideline Helper
18.5 Group Helper
18.6 Barrier Helper
18.7 Flow Helper
18.8 Ratios
18.9 ConstraintLayout Advantages
18.10 ConstraintLayout Availability
18.11 Summary
19. A Guide to Using ConstraintLayout in Android Studio
19.1 Design and Layout Views
19.2 Autoconnect Mode
19.3 Inference Mode
19.4 Manipulating Constraints Manually
19.5 Adding Constraints in the Inspector
19.6 Viewing Constraints in the Attributes Window
19.7 Deleting Constraints
19.8 Adjusting Constraint Bias
19.9 Understanding ConstraintLayout Margins
19.10 e Importance of Opposing Constraints and Bias
19.11 Con guring Widget Dimensions
19.12 Design Time Tools Positioning
19.13 Adding Guidelines
19.14 Adding Barriers
19.15 Adding a Group
19.16 Working with the Flow Helper
19.17 Widget Group Alignment and Distribution
19.18 Converting other Layouts to ConstraintLayout
19.19 Summary
20. Working with ConstraintLayout Chains and Ratios in Android
Studio
20.1 Creating a Chain
20.2 Changing the Chain Style
20.3 Spread Inside Chain Style
20.4 Packed Chain Style
20.5 Packed Chain Style with Bias
20.6 Weighted Chain
20.7 Working with Ratios
20.8 Summary
21. An Android Studio Layout Editor ConstraintLayout Tutorial
21.1 An Android Studio Layout Editor Tool Example
21.2 Creating a New Activity
21.3 Preparing the Layout Editor Environment
21.4 Adding the Widgets to the User Interface
21.5 Adding the Constraints
21.6 Testing the Layout
21.7 Using the Layout Inspector
21.8 Summary
22. Manual XML Layout Design in Android Studio
22.1 Manually Creating an XML Layout
22.2 Manual XML vs. Visual Layout Design
22.3 Summary
23. Managing Constraints using Constraint Sets
23.1 Java Code vs. XML Layout Files
23.2 Creating Views
23.3 View Attributes
23.4 Constraint Sets
23.4.1 Establishing Connections
23.4.2 Applying Constraints to a Layout
23.4.3 Parent Constraint Connections
23.4.4 Sizing Constraints
23.4.5 Constraint Bias
23.4.6 Alignment Constraints
23.4.7 Copying and Applying Constraint Sets
23.4.8 ConstraintLayout Chains
23.4.9 Guidelines
23.4.10 Removing Constraints
23.4.11 Scaling
23.4.12 Rotation
23.5 Summary
24. An Android ConstraintSet Tutorial
24.1 Creating the Example Project in Android Studio
24.2 Adding Views to an Activity
24.3 Setting View Attributes
24.4 Creating View IDs
24.5 Con guring the Constraint Set
24.6 Adding the EditText View
24.7 Converting Density Independent Pixels (dp) to Pixels (px)
24.8 Summary
25. A Guide to using Apply Changes in Android Studio
25.1 Introducing Apply Changes
25.2 Understanding Apply Changes Options
25.3 Using Apply Changes
25.4 Con guring Apply Changes Fallback Settings
25.5 An Apply Changes Tutorial
25.6 Using Apply Code Changes
25.7 Using Apply Changes and Restart Activity
25.8 Using Run App
25.9 Summary
26. An Overview and Example of Android Event Handling
26.1 Understanding Android Events
26.2 Using the android:onClick Resource
26.3 Event Listeners and Callback Methods
26.4 An Event Handling Example
26.5 Designing the User Interface
26.6 e Event Listener and Callback Method
26.7 Consuming Events
26.8 Summary
27. Android Touch and Multi-touch Event Handling
27.1 Intercepting Touch Events
27.2 e MotionEvent Object
27.3 Understanding Touch Actions
27.4 Handling Multiple Touches
27.5 An Example Multi-Touch Application
27.6 Designing the Activity User Interface
27.7 Implementing the Touch Event Listener
27.8 Running the Example Application
27.9 Summary
28. Detecting Common Gestures Using the Android Gesture Detector
Class
28.1 Implementing Common Gesture Detection
28.2 Creating an Example Gesture Detection Project
28.3 Implementing the Listener Class
28.4 Creating the GestureDetectorCompat Instance
28.5 Implementing the onTouchEvent() Method
28.6 Testing the Application
28.7 Summary
29. Implementing Custom Gesture and Pinch Recognition on Android
29.1 e Android Gesture Builder Application
29.2 e GestureOverlayView Class
29.3 Detecting Gestures
29.4 Identifying Speci c Gestures
29.5 Installing and Running the Gesture Builder Application
29.6 Creating a Gestures File
29.7 Creating the Example Project
29.8 Extracting the Gestures File from the SD Card
29.9 Adding the Gestures File to the Project
29.10 Designing the User Interface
29.11 Loading the Gestures File
29.12 Registering the Event Listener
29.13 Implementing the onGesturePerformed Method
29.14 Testing the Application
29.15 Con guring the GestureOverlayView
29.16 Intercepting Gestures
29.17 Detecting Pinch Gestures
29.18 A Pinch Gesture Example Project
29.19 Summary
30. An Introduction to Android Fragments
30.1 What is a Fragment?
30.2 Creating a Fragment
30.3 Adding a Fragment to an Activity using the Layout XML File
30.4 Adding and Managing Fragments in Code
30.5 Handling Fragment Events
30.6 Implementing Fragment Communication
30.7 Summary
31. Using Fragments in Android Studio - An Example
31.1 About the Example Fragment Application
31.2 Creating the Example Project
31.3 Creating the First Fragment Layout
31.4 Migrating a Fragment to View Binding
31.5 Adding the Second Fragment
31.6 Adding the Fragments to the Activity
31.7 Making the Toolbar Fragment Talk to the Activity
31.8 Making the Activity Talk to the Text Fragment
31.9 Testing the Application
31.10 Summary
32. Modern Android App Architecture with Jetpack
32.1 What is Android Jetpack?
32.2 e “Old” Architecture
32.3 Modern Android Architecture
32.4 e ViewModel Component
32.5 e LiveData Component
32.6 ViewModel Saved State
32.7 LiveData and Data Binding
32.8 Android Lifecycles
32.9 Repository Modules
32.10 Summary
33. An Android Jetpack ViewModel Tutorial
33.1 About the Project
33.2 Creating the ViewModel Example Project
33.3 Reviewing the Project
33.3.1 e Main Activity
33.3.2 e Content Fragment
33.3.3 e ViewModel
33.4 Designing the Fragment Layout
33.5 Implementing the View Model
33.6 Associating the Fragment with the View Model
33.7 Modifying the Fragment
33.8 Accessing the ViewModel Data
33.9 Testing the Project
33.10 Summary
34. An Android Jetpack LiveData Tutorial
34.1 LiveData - A Recap
34.2 Adding LiveData to the ViewModel
34.3 Implementing the Observer
34.4 Summary
35. An Overview of Android Jetpack Data Binding
35.1 An Overview of Data Binding
35.2 e Key Components of Data Binding
35.2.1 e Project Build Con guration
35.2.2 e Data Binding Layout File
35.2.3 e Layout File Data Element
35.2.4 e Binding Classes
35.2.5 Data Binding Variable Con guration
35.2.6 Binding Expressions (One-Way)
35.2.7 Binding Expressions (Two-Way)
35.2.8 Event and Listener Bindings
35.3 Summary
36. An Android Jetpack Data Binding Tutorial
36.1 Removing the Redundant Code
36.2 Enabling Data Binding
36.3 Adding the Layout Element
36.4 Adding the Data Element to Layout File
36.5 Working with the Binding Class
36.6 Assigning the ViewModel Instance to the Data Binding Variable
36.7 Adding Binding Expressions
36.8 Adding the Conversion Method
36.9 Adding a Listener Binding
36.10 Testing the App
36.11 Summary
37. An Android ViewModel Saved State Tutorial
37.1 Understanding ViewModel State Saving
37.2 Implementing ViewModel State Saving
37.3 Saving and Restoring State
37.4 Adding Saved State Support to the ViewModelDemo Project
37.5 Summary
38. Working with Android Lifecycle-Aware Components
38.1 Lifecycle Awareness
38.2 Lifecycle Owners
38.3 Lifecycle Observers
38.4 Lifecycle States and Events
38.5 Summary
39. An Android Jetpack Lifecycle Awareness Tutorial
39.1 Creating the Example Lifecycle Project
39.2 Creating a Lifecycle Observer
39.3 Adding the Observer
39.4 Testing the Observer
39.5 Creating a Lifecycle Owner
39.6 Testing the Custom Lifecycle Owner
39.7 Summary
40. An Overview of the Navigation Architecture Component
40.1 Understanding Navigation
40.2 Declaring a Navigation Host
40.3 e Navigation Graph
40.4 Accessing the Navigation Controller
40.5 Triggering a Navigation Action
40.6 Passing Arguments
40.7 Summary
41. An Android Jetpack Navigation Component Tutorial
41.1 Creating the NavigationDemo Project
41.2 Adding Navigation to the Build Con guration
41.3 Creating the Navigation Graph Resource File
41.4 Declaring a Navigation Host
41.5 Adding Navigation Destinations
41.6 Designing the Destination Fragment Layouts
41.7 Adding an Action to the Navigation Graph
41.8 Implement the OnFragmentInteractionListener
41.9 Adding View Binding Support to the Destination Fragments
41.10 Triggering the Action
41.11 Passing Data Using Safeargs
41.12 Summary
42. An Introduction to MotionLayout
42.1 An Overview of MotionLayout
42.2 MotionLayout
42.3 MotionScene
42.4 Con guring ConstraintSets
42.5 Custom Attributes
42.6 Triggering an Animation
42.7 Arc Motion
42.8 Keyframes
42.8.1 Attribute Keyframes
42.8.2 Position Keyframes
42.9 Time Linearity
42.10 KeyTrigger
42.11 Cycle and Time Cycle Keyframes
42.12 Starting an Animation from Code
42.13 Summary
43. An Android MotionLayout Editor Tutorial
43.1 Creating the MotionLayoutDemo Project
43.2 ConstraintLayout to MotionLayout Conversion
43.3 Con guring Start and End Constraints
43.4 Previewing the MotionLayout Animation
43.5 Adding an OnClick Gesture
43.6 Adding an Attribute Keyframe to the Transition
43.7 Adding a CustomAttribute to a Transition
43.8 Adding Position Keyframes
43.9 Summary
44. A MotionLayout KeyCycle Tutorial
44.1 An Overview of Cycle Keyframes
44.2 Using the Cycle Editor
44.3 Creating the KeyCycleDemo Project
44.4 Con guring the Start and End Constraints
44.5 Creating the Cycles
44.6 Previewing the Animation
44.7 Adding the KeyFrameSet to the MotionScene
44.8 Summary
45. Working with the Floating Action Button and Snackbar
45.1 e Material Design
45.2 e Design Library
45.3 e Floating Action Button (FAB)
45.4 e Snackbar
45.5 Creating the Example Project
45.6 Reviewing the Project
45.7 Removing Navigation Features
45.8 Changing the Floating Action Button
45.9 Adding an Action to the Snackbar
45.10 Summary
46. Creating a Tabbed Interface using the TabLayout Component
46.1 An Introduction to the ViewPager2
46.2 An Overview of the TabLayout Component
46.3 Creating the TabLayoutDemo Project
46.4 Creating the First Fragment
46.5 Duplicating the Fragments
46.6 Adding the TabLayout and ViewPager2
46.7 Creating the Pager Adapter
46.8 Performing the Initialization Tasks
46.9 Testing the Application
46.10 Customizing the TabLayout
46.11 Summary
47. Working with the RecyclerView and CardView Widgets
47.1 An Overview of the RecyclerView
47.2 An Overview of the CardView
47.3 Summary
48. An Android RecyclerView and CardView Tutorial
48.1 Creating the CardDemo Project
48.2 Modifying the Basic Activity Project
48.3 Designing the CardView Layout
48.4 Adding the RecyclerView
48.5 Adding the Image Files
48.6 Creating the RecyclerView Adapter
48.7 Initializing the RecyclerView Component
48.8 Testing the Application
48.9 Responding to Card Selections
48.10 Summary
49. A Layout Editor Sample Data Tutorial
49.1 Adding Sample Data to a Project
49.2 Using Custom Sample Data
49.3 Summary
50. Working with the AppBar and Collapsing Toolbar Layouts
50.1 e Anatomy of an AppBar
50.2 e Example Project
50.3 Coordinating the RecyclerView and Toolbar
50.4 Introducing the Collapsing Toolbar Layout
50.5 Changing the Title and Scrim Color
50.6 Summary
51. An Android Studio Primary/Detail Flow Tutorial
51.1 e Primary/Detail Flow
51.2 Creating a Primary/Detail Flow Activity
51.3 Modifying the Primary/Detail Flow Template
51.4 Changing the Content Model
51.5 Changing the Detail Pane
51.6 Modifying the WebsiteDetailFragment Class
51.7 Modifying the WebsiteListFragment Class
51.8 Adding Manifest Permissions
51.9 Running the Application
51.10 Summary
52. An Overview of Android Intents
52.1 An Overview of Intents
52.2 Explicit Intents
52.3 Returning Data from an Activity
52.4 Implicit Intents
52.5 Using Intent Filters
52.6 Checking Intent Availability
52.7 Summary
53. Android Explicit Intents – A Worked Example
53.1 Creating the Explicit Intent Example Application
53.2 Designing the User Interface Layout for MainActivity
53.3 Creating the Second Activity Class
53.4 Designing the User Interface Layout for SecondActivity
53.5 Reviewing the Application Manifest File
53.6 Creating the Intent
53.7 Extracting Intent Data
53.8 Launching SecondActivity as a Sub-Activity
53.9 Returning Data from a Sub-Activity
53.10 Testing the Application
53.11 Summary
54. Android Implicit Intents – A Worked Example
54.1 Creating the Android Studio Implicit Intent Example Project
54.2 Designing the User Interface
54.3 Creating the Implicit Intent
54.4 Adding a Second Matching Activity
54.5 Adding the Web View to the UI
54.6 Obtaining the Intent URL
54.7 Modifying the MyWebView Project Manifest File
54.8 Installing the MyWebView Package on a Device
54.9 Testing the Application
54.10 Summary
55. Android Broadcast Intents and Broadcast Receivers
55.1 An Overview of Broadcast Intents
55.2 An Overview of Broadcast Receivers
55.3 Obtaining Results from a Broadcast
55.4 Sticky Broadcast Intents
55.5 e Broadcast Intent Example
55.6 Creating the Example Application
55.7 Creating and Sending the Broadcast Intent
55.8 Creating the Broadcast Receiver
55.9 Registering the Broadcast Receiver
55.10 Testing the Broadcast Example
55.11 Listening for System Broadcasts
55.12 Summary
56. A Basic Overview of Java reads, Handlers and Executors
56.1 An Overview of reads
56.2 e Application Main read
56.3 read Handlers
56.4 A reading Example
56.5 Building the App
56.6 Creating a New read
56.7 Implementing a read Handler
56.8 Passing a Message to the Handler
56.9 Java Executor Concurrency
56.10 Working with Runnable Tasks
56.11 Shutting down an Executor Service
56.12 Working with Callable Tasks and Futures
56.13 Handling a Future Result
56.14 Scheduling Tasks
56.15 Summary
57. An Overview of Android Services
57.1 Started Services
57.2 Intent Service
57.3 Bound Service
57.4 e Anatomy of a Service
57.5 Controlling Destroyed Service Restart Options
57.6 Declaring a Service in the Manifest File
57.7 Starting a Service Running on System Startup
57.8 Summary
58. Implementing an Android Started Service – A Worked Example
58.1 Creating the Example Project
58.2 Designing the User Interface
58.3 Creating the Service Class
58.4 Adding the Service to the Manifest File
58.5 Starting the Service
58.6 Testing the IntentService Example
58.7 Using the Service Class
58.8 Creating the New Service
58.9 Launching the Service
58.10 Running the Application
58.11 Adding reading to the Service
58.12 Summary
59. Android Local Bound Services – A Worked Example
59.1 Understanding Bound Services
59.2 Bound Service Interaction Options
59.3 A Local Bound Service Example
59.4 Adding a Bound Service to the Project
59.5 Implementing the Binder
59.6 Binding the Client to the Service
59.7 Completing the Example
59.8 Testing the Application
59.9 Summary
60. Android Remote Bound Services – A Worked Example
60.1 Client to Remote Service Communication
60.2 Creating the Example Application
60.3 Designing the User Interface
60.4 Implementing the Remote Bound Service
60.5 Con guring a Remote Service in the Manifest File
60.6 Launching and Binding to the Remote Service
60.7 Sending a Message to the Remote Service
60.8 Summary
61. An Android Noti cations Tutorial
61.1 An Overview of Noti cations
61.2 Creating the NotifyDemo Project
61.3 Designing the User Interface
61.4 Creating the Second Activity
61.5 Creating a Noti cation Channel
61.6 Creating and Issuing a Noti cation
61.7 Launching an Activity from a Noti cation
61.8 Adding Actions to a Noti cation
61.9 Bundled Noti cations
61.10 Summary
62. An Android Direct Reply Noti cation Tutorial
62.1 Creating the DirectReply Project
62.2 Designing the User Interface
62.3 Creating the Noti cation Channel
62.4 Building the RemoteInput Object
62.5 Creating the PendingIntent
62.6 Creating the Reply Action
62.7 Receiving Direct Reply Input
62.8 Updating the Noti cation
62.9 Summary
63. Foldable Devices and Multi-Window Support
63.1 Foldables and Multi-Window Support
63.2 Using a Foldable Emulator
63.3 Entering Multi-Window Mode
63.4 Enabling and using Freeform Support
63.5 Checking for Freeform Support
63.6 Enabling Multi-Window Support in an App
63.7 Specifying Multi-Window Attributes
63.8 Detecting Multi-Window Mode in an Activity
63.9 Receiving Multi-Window Noti cations
63.10 Launching an Activity in Multi-Window Mode
63.11 Con guring Freeform Activity Size and Position
63.12 Summary
64. An Overview of Android SQLite Databases
64.1 Understanding Database Tables
64.2 Introducing Database Schema
64.3 Columns and Data Types
64.4 Database Rows
64.5 Introducing Primary Keys
64.6 What is SQLite?
64.7 Structured Query Language (SQL)
64.8 Trying SQLite on an Android Virtual Device (AVD)
64.9 e Android Room Persistence Library
64.10 Summary
65. e Android Room Persistence Library
65.1 Revisiting Modern App Architecture
65.2 Key Elements of Room Database Persistence
65.2.1 Repository
65.2.2 Room Database
65.2.3 Data Access Object (DAO)
65.2.4 Entities
65.2.5 SQLite Database
65.3 Understanding Entities
65.4 Data Access Objects
65.5 e Room Database
65.6 e Repository
65.7 In-Memory Databases
65.8 Database Inspector
65.9 Summary
66. An Android TableLayout and TableRow Tutorial
66.1 e TableLayout and TableRow Layout Views
66.2 Creating the Room Database Project
66.3 Converting to a LinearLayout
66.4 Adding the TableLayout to the User Interface
66.5 Con guring the TableRows
66.6 Adding the Button Bar to the Layout
66.7 Adding the RecyclerView
66.8 Adjusting the Layout Margins
66.9 Summary
67. An Android Room Database and Repository Tutorial
67.1 About the RoomDemo Project
67.2 Modifying the Build Con guration
67.3 Building the Entity
67.4 Creating the Data Access Object
67.5 Adding the Room Database
67.6 Adding the Repository
67.7 Modifying the ViewModel
67.8 Creating the Product Item Layout
67.9 Adding the RecyclerView Adapter
67.10 Preparing the Main Fragment
67.11 Adding the Button Listeners
67.12 Adding LiveData Observers
67.13 Initializing the RecyclerView
67.14 Testing the RoomDemo App
67.15 Using the Database Inspector
67.16 Summary
68. Accessing Cloud Storage using the Android Storage Access
Framework
68.1 e Storage Access Framework
68.2 Working with the Storage Access Framework
68.3 Filtering Picker File Listings
68.4 Handling Intent Results
68.5 Reading the Content of a File
68.6 Writing Content to a File
68.7 Deleting a File
68.8 Gaining Persistent Access to a File
68.9 Summary
69. An Android Storage Access Framework Example
69.1 About the Storage Access Framework Example
69.2 Creating the Storage Access Framework Example
69.3 Designing the User Interface
69.4 Adding the Activity Launchers
69.5 Creating a New Storage File
69.6 Saving to a Storage File
69.7 Opening and Reading a Storage File
69.8 Testing the Storage Access Application
69.9 Summary
70. Video Playback on Android using the VideoView and
MediaController Classes
70.1 Introducing the Android VideoView Class
70.2 Introducing the Android MediaController Class
70.3 Creating the Video Playback Example
70.4 Designing the VideoPlayer Layout
70.5 Downloading the Video File
70.6 Con guring the VideoView
70.7 Adding the MediaController to the Video View
70.8 Setting up the onPreparedListener
70.9 Summary
71. Android Picture-in-Picture Mode
71.1 Picture-in-Picture Features
71.2 Enabling Picture-in-Picture Mode
71.3 Con guring Picture-in-Picture Parameters
71.4 Entering Picture-in-Picture Mode
71.5 Detecting Picture-in-Picture Mode Changes
71.6 Adding Picture-in-Picture Actions
71.7 Summary
72. An Android Picture-in-Picture Tutorial
72.1 Adding Picture-in-Picture Support to the Manifest
72.2 Adding a Picture-in-Picture Button
72.3 Entering Picture-in-Picture Mode
72.4 Detecting Picture-in-Picture Mode Changes
72.5 Adding a Broadcast Receiver
72.6 Adding the PiP Action
72.7 Testing the Picture-in-Picture Action
72.8 Summary
73. Making Runtime Permission Requests in Android
73.1 Understanding Normal and Dangerous Permissions
73.2 Creating the Permissions Example Project
73.3 Checking for a Permission
73.4 Requesting Permission at Runtime
73.5 Providing a Rationale for the Permission Request
73.6 Testing the Permissions App
73.7 Summary
74. Android Audio Recording and Playback using MediaPlayer and
MediaRecorder
74.1 Playing Audio
74.2 Recording Audio and Video using the MediaRecorder Class
74.3 About the Example Project
74.4 Creating the AudioApp Project
74.5 Designing the User Interface
74.6 Checking for Microphone Availability
74.7 Initializing the Activity
74.8 Implementing the recordAudio() Method
74.9 Implementing the stopAudio() Method
74.10 Implementing the playAudio() method
74.11 Con guring and Requesting Permissions
74.12 Testing the Application
74.13 Summary
75. Working with the Google Maps Android API in Android Studio
75.1 e Elements of the Google Maps Android API
75.2 Creating the Google Maps Project
75.3 Obtaining Your Developer Signature
75.4 Adding the Apache HTTP Legacy Library Requirement
75.5 Testing the Application
75.6 Understanding Geocoding and Reverse Geocoding
75.7 Adding a Map to an Application
75.8 Requesting Current Location Permission
75.9 Displaying the User’s Current Location
75.10 Changing the Map Type
75.11 Displaying Map Controls to the User
75.12 Handling Map Gesture Interaction
75.12.1 Map Zooming Gestures
75.12.2 Map Scrolling/Panning Gestures
75.12.3 Map Tilt Gestures
75.12.4 Map Rotation Gestures
75.13 Creating Map Markers
75.14 Controlling the Map Camera
75.15 Summary
76. Printing with the Android Printing Framework
76.1 e Android Printing Architecture
76.2 e Print Service Plugins
76.3 Google Cloud Print
76.4 Printing to Google Drive
76.5 Save as PDF
76.6 Printing from Android Devices
76.7 Options for Building Print Support into Android Apps
76.7.1 Image Printing
76.7.2 Creating and Printing HTML Content
76.7.3 Printing a Web Page
76.7.4 Printing a Custom Document
76.8 Summary
77. An Android HTML and Web Content Printing Example
77.1 Creating the HTML Printing Example Application
77.2 Printing Dynamic HTML Content
77.3 Creating the Web Page Printing Example
77.4 Removing the Floating Action Button
77.5 Removing Navigation Features
77.6 Designing the User Interface Layout
77.7 Accessing the WebView from the Main Activity
77.8 Loading the Web Page into the WebView
77.9 Adding the Print Menu Option
77.10 Summary
78. A Guide to Android Custom Document Printing
78.1 An Overview of Android Custom Document Printing
78.1.1 Custom Print Adapters
78.2 Preparing the Custom Document Printing Project
78.3 Creating the Custom Print Adapter
78.4 Implementing the onLayout() Callback Method
78.5 Implementing the onWrite() Callback Method
78.6 Checking a Page is in Range
78.7 Drawing the Content on the Page Canvas
78.8 Starting the Print Job
78.9 Testing the Application
78.10 Summary
79. An Introduction to Android App Links
79.1 An Overview of Android App Links
79.2 App Link Intent Filters
79.3 Handling App Link Intents
79.4 Associating the App with a Website
79.5 Summary
80. An Android Studio App Links Tutorial
80.1 About the Example App
80.2 e Database Schema
80.3 Loading and Running the Project
80.4 Adding the URL Mapping
80.5 Adding the Intent Filter
80.6 Adding Intent Handling Code
80.7 Testing the App Link
80.8 Associating an App Link with a Web Site
80.9 Summary
81. An Android Biometric Authentication Tutorial
81.1 An Overview of Biometric Authentication
81.2 Creating the Biometric Authentication Project
81.3 Con guring Device Fingerprint Authentication
81.4 Adding the Biometric Permission to the Manifest File
81.5 Designing the User Interface
81.6 Adding a Toast Convenience Method
81.7 Checking the Security Settings
81.8 Con guring the Authentication Callbacks
81.9 Adding the CancellationSignal
81.10 Starting the Biometric Prompt
81.11 Testing the Project
81.12 Summary
82. Creating, Testing and Uploading an Android App Bundle
82.1 e Release Preparation Process
82.2 Android App Bundles
82.3 Register for a Google Play Developer Console Account
82.4 Con guring the App in the Console
82.5 Enabling Google Play App Signing
82.6 Creating a Keystore File
82.7 Creating the Android App Bundle
82.8 Generating Test APK Files
82.9 Uploading the App Bundle to the Google Play Developer Console
82.10 Exploring the App Bundle
82.11 Managing Testers
82.12 Rolling the App Out for Testing
82.13 Uploading New App Bundle Revisions
82.14 Analyzing the App Bundle File
82.15 Summary
83. An Overview of Android Dynamic Feature Modules
83.1 An Overview of Dynamic Feature Modules
83.2 Dynamic Feature Module Architecture
83.3 Creating a Dynamic Feature Module
83.4 Converting an Existing Module for Dynamic Delivery
83.5 Working with Dynamic Feature Modules
83.6 Handling Large Dynamic Feature Modules
83.7 Summary
84. An Android Studio Dynamic Feature Tutorial
84.1 Creating the DynamicFeature Project
84.2 Adding Dynamic Feature Support to the Project
84.3 Designing the Base Activity User Interface
84.4 Adding the Dynamic Feature Module
84.5 Reviewing the Dynamic Feature Module
84.6 Adding the Dynamic Feature Activity
84.7 Implementing the launchIntent() Method
84.8 Uploading the App Bundle for Testing
84.9 Implementing the installFeature() Method
84.10 Adding the Update Listener
84.11 Using Deferred Installation
84.12 Removing a Dynamic Module
84.13 Summary
85. An Overview of Gradle in Android Studio
85.1 An Overview of Gradle
85.2 Gradle and Android Studio
85.2.1 Sensible Defaults
85.2.2 Dependencies
85.2.3 Build Variants
85.2.4 Manifest Entries
85.2.5 APK Signing
85.2.6 ProGuard Support
85.3 e Top-level Gradle Build File
85.4 Module Level Gradle Build Files
85.5 Con guring Signing Settings in the Build File
85.6 Running Gradle Tasks from the Command-line
85.7 Summary
Index
1. Introduction
Fully updated for Android Studio Arctic Fox, the goal of this book is to
teach the skills necessary to develop Android based applications using the
Java programming language.
Beginning with the basics, this book provides an outline of the steps
necessary to set up an Android development and testing environment. An
overview of Android Studio is included covering areas such as tool windows,
the code editor and the Layout Editor tool. An introduction to the
architecture of Android is followed by an in-depth look at the design of
Android applications and user interfaces using the Android Studio
environment.
Chapters are also included covering the Android Architecture Components
including view models, lifecycle management, Room database access, the
Database Inspector, app navigation, live data and data binding.
More advanced topics such as intents are also covered, as are touch screen
handling, gesture recognition, and the recording and playback of audio. is
edition of the book also covers printing, transitions, cloud-based le storage
and foldable device support.
e concepts of material design are also covered in detail, including the use
of oating action buttons, Snackbars, tabbed interfaces, card views,
navigation drawers and collapsing toolbars.
Other key features of Android Studio Arctic Fox and Android are also
covered in detail including the Layout Editor, the ConstraintLayout and
ConstraintSet classes, MotionLayout Editor, view binding, constraint chains,
barriers and direct reply noti cations.
Chapters also cover advanced features of Android Studio such as App Links,
Dynamic Delivery, Gradle build con guration, and submitting apps to the
Google Play Developer Console.
Assuming you already have some Java programming experience, are ready
to download Android Studio and the Android SDK, have access to a
Windows, Mac or Linux system and ideas for some apps to develop, you are
ready to get started.
1.1 Downloading the Code Samples
e source code and Android Studio project les for the examples contained
in this book are available for download at:
https://www.ebookfrenzy.com/retail/arcticfoxjava/index.php
e steps to load a project from the code samples into Android Studio are as
follows:
1. From the Welcome to Android Studio dialog, click on the Open button
option.
2. In the project selection dialog, navigate to and select the folder containing
the project to be imported and click on OK.
1.2 Feedback
We want you to be satis ed with your purchase of this book. If you nd any
errors in the book, or have any comments, questions or concerns please
contact us at [email protected].
1.3 Errata
While we make every e ort to ensure the accuracy of the content of this
book, it is inevitable that a book covering a subject area of this size and
complexity may include some errors and oversights. Any known issues with
the book will be outlined, together with solutions, at the following URL:
https://www.ebookfrenzy.com/errata/arcticfoxjava.html
In the event that you nd an error not listed in the errata, please let us know
by emailing our technical support team at [email protected]. ey
are there to help you and will work to resolve any problems you may
encounter.
2. Setting up an Android Studio Development
Environment
Before any work can begin on the development of an Android application,
the rst step is to con gure a computer system to act as the development
platform. is involves a number of steps consisting of installing the
Android Studio Integrated Development Environment (IDE) which also
includes the Android So ware Development Kit (SDK) and OpenJDK Java
development environment.
is chapter will cover the steps necessary to install the requisite
components for Android application development on Windows, macOS and
Linux based systems.
2.1 System Requirements
Android application development may be performed on any of the following
system types:
•Windows 8/10 64-bit
•macOS 10.14 or later, Intel Core, AMD, or Apple silicon
•Chrome OS device with Intel i5 or higher
•Linux systems with version 2.31 or later of GNU C Library (glibc)
•Minimum of 8GB of RAM
•Approximately 8GB of available disk space
•1280 x 800 minimum screen resolution
2.2 Downloading the Android Studio Package
Most of the work involved in developing applications for Android will be
performed using the Android Studio environment. e content and
examples in this book were created based on Android Studio Arctic Fox
2020.3.1 using the Android 11.0 (R) API 30 SDK which, at the time of
writing, are the current versions.
Android Studio is, however, subject to frequent updates so a newer version
may have been released since this book was published.
e latest release of Android Studio may be downloaded from the primary
download page which can be found at the following URL:
https://developer.android.com/studio/index.html
If this page provides instructions for downloading a newer version of
Android Studio it is important to note that there may be some minor
di erences between this book and the so ware. A web search for “Android
Studio Arctic Fox” should provide the option to download the older version
in the event that these di erences become a problem. Alternatively, visit the
following web page to nd Android Studio Arctic Fox in the archives:
https://developer.android.com/studio/archive
2.3 Installing Android Studio
Once downloaded, the exact steps to install Android Studio di er
depending on the operating system on which the installation is being
performed.
2.3.1 Installation on Windows
Locate the downloaded Android Studio installation executable le (named
android-studio-<version>-windows.exe) in a Windows Explorer window and
double-click on it to start the installation process, clicking the Yes button in
the User Account Control dialog if it appears.
Once the Android Studio setup wizard appears, work through the various
screens to con gure the installation to meet your requirements in terms of
the le system location into which Android Studio should be installed and
whether or not it should be made available to other users of the system.
When prompted to select the components to install, make sure that the
Android Studio and Android Virtual Device options are all selected.
Although there are no strict rules on where Android Studio should be
installed on the system, the remainder of this book will assume that the
installation was performed into C:\Program Files\Android\Android Studio
and that the Android SDK packages have been installed into the user’s
AppData\Local\Android\sdk sub-folder. Once the options have been
con gured, click on the Install button to begin the installation process.
On versions of Windows with a Start menu, the newly installed Android
Studio can be launched from the entry added to that menu during the
installation. e executable may be pinned to the task bar for easy access by
navigating to the Android Studio\bin directory, right-clicking on the
executable and selecting the Pin to Taskbar menu option.
2.3.2 Installation on macOS
Android Studio for macOS is downloaded in the form of a disk image
(.dmg) le. Once the android-studio-<version>-mac.dmg le has been
downloaded, locate it in a Finder window and double-click on it to open it
as shown in Figure 2-1:
Figure 2-1
To install the package, simply drag the Android Studio icon and drop it onto
the Applications folder. e Android Studio package will then be installed
into the Applications folder of the system, a process which will typically take
a few seconds to complete.
To launch Android Studio, locate the executable in the Applications folder
using a Finder window and double-click on it.
For future easier access to the tool, drag the Android Studio icon from the
Finder window and drop it onto the dock.
2.3.3 Installation on Linux
Having downloaded the Linux Android Studio package, open a terminal
window, change directory to the location where Android Studio is to be
installed and execute the following command:
unzip /<path to package>/android-studio-ide-<version>-
linux.zip
Note that the Android Studio bundle will be installed into a sub-directory
named android-studio. Assuming, therefore, that the above command was
executed in /home/demo, the so ware packages will be unpacked into
/home/demo/android-studio.
To launch Android Studio, open a terminal window, change directory to the
android-studio/bin sub-directory and execute the following command:
./studio.sh
When running on a 64-bit Linux system, it will be necessary to install some
32-bit support libraries before Android Studio will run. On Ubuntu these
libraries can be installed using the following command:
sudo apt-get install libc6:i386 libncurses5:i386
libstdc++6:i386 lib32z1 libbz2-1.0:i386
On Red Hat and Fedora based 64-bit systems, use the following command:
sudo yum install zlib.i686 ncurses-libs.i686 bzip2-
libs.i686
2.4 e Android Studio Setup Wizard
If you are installing Android Studio for the rst time the initial dialog that
appears once the setup process starts may resemble that shown in Figure 2-2
below:
Figure 2-2
If this dialog appears, click the Next button to display the SDK Components
Setup dialog (Figure 2-3). Within this dialog, make sure that the Android
SDK option is selected along with the latest API package before clicking on
the Next button:
Figure 2-3
A er clicking Next, Android Studio will download and install the Android
SDK and tools.
If you have previously installed an earlier version of Android Studio, the rst
time that this new version is launched, a dialog may appear providing the
option to import settings from a previous Android Studio version. If you
have settings from a previous version and would like to import them into
the latest installation, select the appropriate option and location.
Alternatively, indicate that you do not need to import any previous settings
and click on the OK button to proceed.
A er these initial setup steps have been taken, click the Finish button to
display the Welcome to Android Studio screen:
Figure 2-4
2.5 Installing Additional Android SDK Packages
e steps performed so far have installed the Android Studio IDE and the
current set of default Android SDK packages. Before proceeding, it is worth
taking some time to verify which packages are installed and to install any
missing or updated packages.
is task can be performed by clicking on the More Actions link in the
within the welcome dialog and selecting the SDK Manager option from the
drop down menu. Once invoked, the Android SDK screen of the Preferences
dialog will appear as shown in Figure 2-5:
Figure 2-5
Immediately a er installing Android Studio for the rst time it is likely that
only the latest released version of the Android SDK has been installed. To
install older versions of the Android SDK simply select the checkboxes
corresponding to the versions and click on the Apply button.
Most of the examples in this book will support older versions of Android as
far back as far as Android 8.0 (Oreo). is is to ensure that the apps run on a
wide range of Android devices. Within the list of SDK versions, enable the
checkbox next to Android 8.0 (Oreo) and click on the Apply button. In the
resulting con rmation dialog click on the OK button to install the SDK.
Subsequent dialogs will seek acceptance of licenses and terms before
performing the installation. Click Finish once the installation is complete.
It is also possible that updates will be listed as being available for the latest
SDK. To access detailed information about the packages that are available
for update, enable the Show Package Details option located in the lower
right-hand corner of the screen. is will display information similar to that
shown in Figure 2-6:
Figure 2-6
e above gure highlights the availability of an update. To install the
updates, enable the checkbox to the le of the item name and click on the
Apply button.
In addition to the Android SDK packages, a number of tools are also
installed for building Android applications. To view the currently installed
packages and check for updates, remain within the SDK settings screen and
select the SDK Tools tab as shown in Figure 2-7:
Figure 2-7
Within the Android SDK Tools screen, make sure that the following
packages are listed as Installed in the Status column:
•Android SDK Build-tools
•Android Emulator
•Android SDK Platform-tools
•Google Play Services
•Intel x86 Emulator Accelerator (HAXM installer)
•Google USB Driver (Windows only)
•Layout Inspector image server
Note the Intel x86 Emulator Accelerator (HAXM installer) cannot be
installed on Apple silicon-based Macs.
In the event that any of the above packages are listed as Not Installed or
requiring an update, simply select the checkboxes next to those packages
and click on the Apply button to initiate the installation process. If the
HAXM emulator settings dialog appears, select the recommended memory
allocation:
Figure 2-8
Once the installation is complete, review the package list and make sure that
the selected packages are now listed as Installed in the Status column. If any
are listed as Not installed, make sure they are selected and click on the Apply
button again.
2.6 Making the Android SDK Tools Command-line
Accessible
Most of the time, the underlying tools of the Android SDK will be accessed
from within the Android Studio environment. at being said, however,
there will also be instances where it will be useful to be able to invoke those
tools from a command prompt or terminal window. In order for the
operating system on which you are developing to be able to nd these tools,
it will be necessary to add them to the system’s PATH environment variable.
Regardless of operating system, the PATH variable needs to be con gured to
include the following paths (where <path_to_android_sdk_installation>
represents the le system location into which the Android SDK was
Exploring the Variety of Random
Documents with Different Content
chrysanthemum with long petals. What he wanted was a simple
white chrysanthemum with sixteen petals. The old man told the
village chief to see Lady Yellow, but this flower did not please him,
and, thanking the gardener, he took his departure.
On his way home he happened to enter a field when he saw Lady
White weeping. She told him the sad story of her loneliness, and
when she had finished her tale of woe the village chief informed her
that he had seen Lady Yellow and did not consider her half so
beautiful as her own white self. At these cheery words Lady White
dried her eyes and she nearly jumped off her little feet when this
kind man told her that he wanted her for his lord’s crest!
In another happy moment the happy Lady White was being
carried in a palanquin. When she reached the Daimyo’s palace all
warmly praised her perfection of form. Great artists came from far
and near, set about her and sketched the flower with wonderful skill.
She soon saw her pretty white face on all the Daimyo’s most
precious belongings. She saw it on his armour and lacquer boxes, on
his quilts and cushions and robes. She was painted floating down a
stream and in all manner of quaint and beautiful ways. Every one
acknowledged that the white chrysanthemum with her sixteen petals
made the most wonderful crest in all Japan. While Lady White’s
happy face lived forever designed upon the Daimyo’s possessions,
Lady Yellow met with a sad fate. She had bloomed for herself alone
and had drunk in the visitor’s praise as eagerly as she did the dew
upon her finely curled petals. One day, however, she felt a stiffness
in her limbs and a cessation of the exuberance of life. Her once
proud head fell forward, and when the old man found her he pulled
her up and tossed her upon a rubbish heap.
THE SHET-UP POSY
Ann Trumbull Slosson
Used by permission of Chas. Scribner and Sons.
The sun was shining brightly one day, and a little Sunbeam slid
down his long golden ladder, and crept unperceived under the leaves
of a large tree. All the Sunbeams are in reality tiny Sun-fairies, who
run down to earth on golden ladders, which look to mortals like rays
of the Sun. When they see a cloud coming they climb their ladders
in an instant and draw them up after them into the Sun. The Sun is
ruled by a mighty fairy, who every morning tells his tiny servants,
the beams, where they are to shine, and every evening counts them
on their return, to see he has the right number. It is not known, but
the Sun and Moon are enemies, and that is why they never shine at
the same time. The fairy of the Moon is a woman, and all her beams
are tiny women, who come down on the loveliest little ladders, like
threads of silver. No one knows why the Sun and Moon quarrelled.
Once they were very good friends. But now they are bitter enemies,
and the Sunbeams and Moonbeams may not play together.
One day a little Sunbeam crept into a tree, and sat down near a
Bullfinch’s nest, and watched the Bullfinch and its mate.
“Why should I not have a mate also?” he said to himself. He was
the prettiest little fellow you could imagine. His hair was bright gold,
and he sat still, leaning one arm on his tiny ladder, and listening to
the chatter of the birds.
“But I shall try to keep awake to-night to see her,” said a young
Bullfinch.
“Nonsense!” said its mother. “You shall do no such thing.”
“But the Nightingale says she is so very lovely,” said a Wren,
looking out from her little nest in a hedge close by.
“The Nightingale!” said the old Bullfinch, scornfully. “Every one
knows that the Nightingale was moonstruck long ago. Who can trust
a word he says?”
“Nevertheless, I should like to see her,” said the Wren.
“I have seen her, and the Nightingale is right,” said a Wood-dove
in its soft, cooing tones. “I was awake last night and saw her; she is
more lovely than anything that ever came here before.”
“Of whom were you talking?” asked the Sunbeam; and he shot
across to the Bullfinch’s nest. All the birds were silent when they saw
him. At last the Bullfinch said, “Only of a Moonbeam, your Highness.
No one your Highness would care about,” for the Bullfinch
remembered the quarrel between the Sun and Moon, and did not
like to say much.
“What is she like?” asked the Sunbeam. “I have never seen a
Moonbeam.”
“I have seen her, and she is as beautiful as an angel,” said the
Wood-dove. “But you should ask the Nightingale. He knows more
about her than any one, for he always comes out to sing to her.”
“Where is the Nightingale?” asked the Sunbeam.
“He is resting now,” said the Wren, “and will not say a word. But
later, as the Sun begins to set, he will come out and tell you.”
“At the time when all decent birds are going to roost,” grumbled
the Bullfinch.
“I will wait till the Nightingale comes,” said the Sunbeam.
So all day long he shone about the tree. As the sun moved slowly
down, his ladder dropped with it lower and lower, for it was fastened
to the Sun at one end; and if he had allowed the Sun to disappear
before he had run back and drawn it up, the ladder would have
broken against the earth, and the poor little Sunbeam could never
have gone home again, but would have wandered about, becoming
paler and paler every minute, till at last he died.
But some time before the sun had gone, when it was still shining
in a glorious bed of red and gold, the Nightingale arose, began to
sing loud and clear.
“Oh, is it you at last?” said the Sunbeam. “How I have waited for
you. Tell me quickly about this Moonbeam of whom they are all
talking.”
“What shall I tell you of her?” sang the Nightingale. “She is more
beautiful than the rose. She is the most beautiful thing I have ever
seen. Her hair is silver, and the light of her eyes is far more lovely
than yours. But why should you want to know about her? You
belong to the Sun, and hate Moonbeams.”
“I do not hate them,” said the Sunbeam. “What are they like?
Show this one to me some night, dear Nightingale.”
“I cannot show her to you now,” answered the Nightingale; “for
she will not come out till long after the sun has set; but wait a few
days, and when the Moon is full she will come a little before the Sun
sets, and if you hide beneath a leaf you may look at her. But you
must promise not to shine on her, or you might hurt her, or break
her ladder.”
“I will promise,” said the Sunbeam, and every day he came back
to the same tree at sunset, to talk to the Nightingale about the
Moonbeam, till the Bullfinch was quite angry.
“To-night I shall see her at last,” he said to himself, for the Moon
was almost full, and would rise before the Sun had set. He hid in the
oak-leaves, trembling with expectation.
“She is coming!” said the Nightingale, and the Sunbeam peeped
out from the branches, and watched. In a minute or two a tiny silver
ladder like a thread was placed among the leaves, near the
Nightingale’s nest, and down it came the Moonbeam, and our little
Sunbeam looked out and saw her.
She did not at all look as he had expected she would, but he
agreed with the Nightingale that she was the loveliest thing he had
ever seen. She was all silver, and pale greeny blue. Her hair and
eyes shone like stars. All the Sunbeams looked bright, and hot, but
she looked as cool as the sea; yet she glittered like a diamond. The
Sunbeam gazed at her in surprise, unable to say a word, till all at
once he saw that his little ladder was bending. The sun was sinking,
and he had only just time to scramble back, and draw his ladder
after him.
The Moonbeam only saw his light vanishing, and did not see him.
“To whom were you talking, dear Nightingale?” she asked,
putting her beautiful white arms round his neck, and leaning her
head on his bosom.
“To a Sunbeam,” answered the Nightingale. “Ah, how beautiful he
is! I was telling him about you. He longs to see you.”
“I have never seen a Sunbeam,” said the Moonbeam, wistfully. “I
should like to see one so much;” and all night long she sat close
beside the Nightingale, with her head leaning on his breast whilst he
sang to her of the Sunbeam; and his song was so loud and clear
that it awoke the Bullfinch, who flew into a rage, and declared that if
it went on any longer she would speak to the Owl about it, and have
it stopped. For the Owl was chief judge, and always ate the little
birds when they did not behave themselves.
But the Nightingale never ceased, and the Moonbeam listened till
the tears rose in her eyes and her lips quivered.
“To-night, then, I shall see him,” whispered the Moonbeam, as
she kissed the Nightingale, and bid him adieu.
“And to-night he will see you,” said the Nightingale, as he settled
to rest among the leaves.
All that next day was cloudy, and the Sun did not shine, but
towards evening the clouds passed away and the Sun came forth,
and no sooner had it appeared than the Nightingale saw our
Sunbeam’s ladder placed close to his nest, and in an instant the
Sunbeam was beside him.
“Dear, dear Nightingale,” he said, “you are right. She is more
lovely than the dawn. I have thought of her all night and all day. Tell
me, will she come again to-night? I will wait to see her.”
“Yes, she will come, and you may speak to her, but you must not
touch her,” said the Nightingale; and then they were silent and
waited.
Underneath the oak-tree lay a large white Stone, a common
white Stone, neither beautiful nor useful, for it lay there where it had
fallen, and bitterly lamented that it had no object in life. It never
spoke to the birds, who scarcely knew it could speak; but
sometimes, if the Nightingale lighted upon it, and touched it with his
soft breast, or the Moonbeam shone upon it, it felt as if it would
break with grief that it should be so stupid and useless. It watched
the Sunbeams and Moonbeams come down on their ladders, and
wondered that none of the birds but the Nightingale thought the
Moonbeam beautiful. That evening, as the Sunbeam sat waiting, the
Stone watched it eagerly, and when the Moonbeam placed her tiny
ladder among the leaves, and slid down it, it listened to all that was
said.
At first the Moonbeam did not speak, for she did not see the
Sunbeam, but she came close to the Nightingale, and kissed it as
usual.
“Have you seen him again?” she asked. And, on hearing this, the
Sunbeam shot out from among the green leaves, and stood before
her.
For a few minutes she was silent; then she began to shiver and
sob, and drew nearer to the Nightingale, and if the Sunbeam tried to
approach her, she climbed up her ladder, and went farther still.
“Do not be frightened, dearest Moonbeam,” cried he piteously; “I
would not, indeed, do you any harm, you are so very lovely, and I
love you so much.”
The Moonbeam turned away, sobbing.
“I do not want you to leave me,” she said, “for if you touch me I
shall die. It would have been much better for you not to have seen
me; and now I cannot go back and be happy in the Moon, for I shall
be always thinking of you.”
“I do not care if I die or not, now that I have seen you; and see,”
said the Sunbeam sadly, “my end is sure, for the Sun is fast sinking,
and I shall not return to it, I shall stay with you.”
“Go, while you have time,” cried the Moonbeam. But even as she
spoke the Sun sank beneath the horizon, and the tiny gold ladder of
the Sunbeam broke with a snap, and the two sides fell to earth and
melted away.
“See,” said the Sunbeam, “I cannot return now, neither do I wish
it. I will remain here with you till I die.”
“No, no,” cried the Moonbeam. “Oh, I shall have killed you! What
shall I do? And look, there are clouds drifting near the Moon; if one
of them floats across my ladder it will break it. But I cannot go and
leave you here;” and she leaned across the leaves to where the
Sunbeam sat, and looked into his eyes. But the Nightingale saw that
a tiny white cloud was sailing close by the Moon—a little cloud no
bigger than a spot of white wool, but quite big and strong enough to
break the Moonbeam’s little ladder.
“Go, go at once. See! your ladder will break,” he sang to her; but
she did not notice him, but sat watching the Sunbeam sadly. For a
moment the moon’s light was obscured, as the tiny cloud sailed past
it; then the little silver ladder fell to earth, broken in two and shrunk
away, but the Moonbeam did not heed it.
“It does not matter,” she said, “for I should never have gone back
and left you here, now that I have seen you.”
So all night long they sat together in the oak tree, and the
Nightingale sang to them, and the other birds grumbled that he kept
them awake. But the two were very happy, though the Sunbeam
knew he was growing paler every moment, for he could not live
twenty-four hours away from the Sun.
When the dawn began to appear, the Moonbeam shivered and
trembled.
“The strong Sun,” she said, “would kill me, but I fear something
even worse than the Sun. See how heavy the clouds are! Surely it is
going to rain, and rain would kill us both at once. Oh, where can we
look for shelter before it comes?”
The Sunbeam looked up, and saw that the rain was coming.
“Come,” he said, “let us go;” and they wandered out into the
forest, and sought for a sheltering place, but every moment they
grew weaker.
When they were gone, the Stone looked up at the Nightingale,
and said:
“Oh, why did they go? I like to hear them talk, and they are so
pretty; they can find no shelter out there, and they will die at once.
See! in my side there is a large hole where it is quite dark, and into
which no rain can come. Fly after them and tell them to come, that I
will shelter them.” So the Nightingale spread his wings, and flew,
singing:
“Come back, come back! The Stone will shelter you. Come back
at once before the rain falls.”
They had wandered out into an open field, but when she heard
the Nightingale, the Moonbeam turned her head and said:
“Surely that is the Nightingale singing. See! he is calling us.”
“Follow me,” sang the bird. “Back at once to shelter in the Stone.”
But the Moonbeam tottered and fell.
“I am grown so weak and pale,” she said, “I can no longer
move.”
Then the Nightingale flew to earth. “Climb upon my back,” he
said, “and I will take you both back to the Stone.” So they both sat
upon his back, and he flew with them to the large Stone beneath the
tree.
“Go in,” he said, stopping in front of the hole; and both passed
into the hole, and nestled in the darkness within the Stone.
Then the rain began. All day long it rained, and the Nightingale
sat in his nest half asleep. But when the Moon rose, after the sun
had set, the clouds cleared away, and the air was again full of tiny
silver ladders, down which the Moonbeams came, but the
Nightingale looked in vain for his own particular Moonbeam. He
knew she could not shine on him again, therefore he mourned, and
sang a sorrowful song. Then he flew down to the Stone, and sang a
song at the mouth of the hole, but there came no answer. So he
looked down the hole, into the Stone, but there was no trace of the
Sunbeam or the Moonbeam—only one shining spot of light, where
they had rested. Then the Nightingale knew that they had faded
away and died.
“They could not live away from the Sun and Moon,” he said.
“Still, I wish I had never told the Sunbeam of her beauty; then she
would be here now.”
When the Bullfinch heard of it she was quite pleased. “Now, at
least,” she said, “we shall hear the end of the Moonbeam. I am
heartily glad, for I was sick of her.”
“How much they must have loved each other!” said the Dove. “I
am glad at least that they died together,” and she cooed sadly.
But through the Stone wherein the beams had sheltered, shot up
bright, beautiful rays of light, silver and gold. They coloured it all
over with every colour of the rainbow, and when the Sun or Moon
warmed it with their light it became quite brilliant. So that the Stone,
from being the ugliest thing in the whole forest, became the most
beautiful.
Men found it and called it the Opal. But the Nightingale knew
that it was the Sunbeam and Moonbeam who, in dying, had suffused
the Stone with their mingled colours and light; and the Nightingale
will never forget them, for every night he sings their story, and that
is why his song is so sad.
In sapphire, emerald, amethyst,
Sparkles the sea by the morning kissed;
And the mist from the far-off valleys lie
Gleaming like pearl in the tender sky;
Soft shapes of cloud that melt and drift,
With tints of opal that glow and shift.
Celia Thaxter.
LOST: THE SUMMER
Where has the summer gone?
She was here just a minute ago,
With roses and daisies
To whisper her praises——
And every one loved her so!