Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (4 votes)
31 views

Instant Download Android Studio Electric Eel Essentials Java Edition Developing Android Apps Using Android Studio 2022 1 1 and Java Neil Smyth PDF All Chapters

Electric

Uploaded by

jouzefssafi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
31 views

Instant Download Android Studio Electric Eel Essentials Java Edition Developing Android Apps Using Android Studio 2022 1 1 and Java Neil Smyth PDF All Chapters

Electric

Uploaded by

jouzefssafi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Experience Seamless Full Ebook Downloads for Every Genre at ebookmeta.

com

Android Studio Electric Eel Essentials Java


Edition Developing Android Apps Using Android
Studio 2022 1 1 and Java Neil Smyth

https://ebookmeta.com/product/android-studio-electric-eel-
essentials-java-edition-developing-android-apps-using-
android-studio-2022-1-1-and-java-neil-smyth/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Android Studio Electric Eel
Essentials
Java Edition
Title
Android Studio Electric Eel Essentials – Java Edition
ISBN-13: 978-1-951442-60-6
© 2023 Neil Smyth / Payload Media, Inc. All Rights Reserved.
This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly
prohibited. All rights reserved.
The content of this book is provided for informational purposes only. Neither the publisher nor the author offers
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.
This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the
respective trademark owner. The terms used within this book are not intended as infringement of any trademarks.
Rev: 1.0
Copyright
Contents

Contents
Table of Contents
1. Introduction................................................................................................................................................ 1
1.1 Downloading the Code Samples........................................................................................................ 1
1.2 Feedback................................................................................................................................................ 1
1.3 Errata..................................................................................................................................................... 2
2. Setting up an Android Studio Development Environment........................................................................ 3
2.1 System requirements............................................................................................................................ 3
2.2 Downloading the Android Studio package...................................................................................... 3
2.3 Installing Android Studio.................................................................................................................... 4
2.3.1 Installation on Windows.............................................................................................................. 4
2.3.2 Installation on macOS.................................................................................................................. 4
2.3.3 Installation on Linux..................................................................................................................... 5
2.4 The Android Studio setup wizard...................................................................................................... 5
2.5 Installing additional Android SDK packages................................................................................... 6
2.6 Installing the Android SDK Command-line Tools.......................................................................... 9
2.6.1 Windows 8.1................................................................................................................................ 10
2.6.2 Windows 10................................................................................................................................. 10
2.6.3 Windows 11................................................................................................................................. 11
2.6.4 Linux............................................................................................................................................. 11
2.6.5 macOS........................................................................................................................................... 11
2.7 Android Studio memory management........................................................................................... 11
2.8 Updating Android Studio and the SDK.......................................................................................... 12
2.9 Summary............................................................................................................................................. 12
3. Creating an Example Android App in Android Studio............................................................................ 13
3.1 About the Project............................................................................................................................... 13
3.2 Creating a New Android Project...................................................................................................... 13
3.3 Creating an Activity........................................................................................................................... 14
3.4 Defining the Project and SDK Settings........................................................................................... 14
3.5 Modifying the Example Application................................................................................................ 15
3.6 Modifying the User Interface ........................................................................................................... 16
3.7 Reviewing the Layout and Resource Files....................................................................................... 21
3.8 Adding Interaction............................................................................................................................. 24
3.9 Summary............................................................................................................................................. 25
4. Creating an Android Virtual Device (AVD) in Android Studio.............................................................. 27
4.1 About Android Virtual Devices....................................................................................................... 27
4.2 Starting the Emulator......................................................................................................................... 29
4.3 Running the Application in the AVD.............................................................................................. 30
4.4 Running on Multiple Devices........................................................................................................... 31
4.5 Stopping a Running Application...................................................................................................... 32
4.6 Supporting Dark Theme.................................................................................................................... 32
4.7 Running the Emulator in a Separate Window................................................................................ 33
4.8 Enabling the Device Frame............................................................................................................... 34

i
Table of Contents
4.9 AVD Command-line Creation......................................................................................................... 36
4.10 Android Virtual Device Configuration Files................................................................................ 37
4.11 Moving and Renaming an Android Virtual Device.................................................................... 38
4.12 Summary........................................................................................................................................... 38
5. Using and Configuring the Android Studio AVD Emulator ................................................................... 39
5.1 The Emulator Environment.............................................................................................................. 39
5.2 Emulator Toolbar Options................................................................................................................ 39
5.3 Working in Zoom Mode................................................................................................................... 41
5.4 Resizing the Emulator Window....................................................................................................... 41
5.5 Extended Control Options................................................................................................................ 41
5.5.1 Location........................................................................................................................................ 42
5.5.2 Displays......................................................................................................................................... 42
5.5.3 Cellular......................................................................................................................................... 42
5.5.4 Battery........................................................................................................................................... 42
5.5.5 Camera.......................................................................................................................................... 42
5.5.6 Phone............................................................................................................................................ 42
5.5.7 Directional Pad............................................................................................................................ 42
5.5.8 Microphone.................................................................................................................................. 42
5.5.9 Fingerprint................................................................................................................................... 42
5.5.10 Virtual Sensors.......................................................................................................................... 43
5.5.11 Snapshots.................................................................................................................................... 43
5.5.12 Record and Playback................................................................................................................ 43
5.5.13 Google Play................................................................................................................................ 43
5.5.14 Settings....................................................................................................................................... 43
5.5.15 Help............................................................................................................................................. 43
5.6 Working with Snapshots.................................................................................................................... 43
5.7 Configuring Fingerprint Emulation................................................................................................ 44
5.8 The Emulator in Tool Window Mode.............................................................................................. 45
5.9 Creating a Resizable Emulator.......................................................................................................... 46
5.10 Summary........................................................................................................................................... 47
6. A Tour of the Android Studio User Interface........................................................................................... 49
6.1 The Welcome Screen.......................................................................................................................... 49
6.2 The Main Window............................................................................................................................. 50
6.3 The Tool Windows............................................................................................................................. 51
6.4 Android Studio Keyboard Shortcuts............................................................................................... 54
6.5 Switcher and Recent Files Navigation............................................................................................. 55
6.6 Changing the Android Studio Theme............................................................................................. 56
6.7 Summary............................................................................................................................................. 57
7. Testing Android Studio Apps on a Physical Android Device................................................................... 59
7.1 An Overview of the Android Debug Bridge (ADB)...................................................................... 59
7.2 Enabling USB Debugging ADB on Android Devices.................................................................... 59
7.2.1 macOS ADB Configuration....................................................................................................... 60
7.2.2 Windows ADB Configuration................................................................................................... 61
7.2.3 Linux adb Configuration............................................................................................................ 62
7.3 Resolving USB Connection Issues................................................................................................... 62
7.4 Enabling Wireless Debugging on Android Devices...................................................................... 63
7.5 Testing the adb Connection.............................................................................................................. 65
7.6 Device Mirroring................................................................................................................................ 65
ii
Table of Contents
7.7 Summary............................................................................................................................................. 65
8. The Basics of the Android Studio Code Editor......................................................................................... 67
8.1 The Android Studio Editor............................................................................................................... 67
8.2 Splitting the Editor Window............................................................................................................. 69
8.3 Code Completion............................................................................................................................... 70
8.4 Statement Completion....................................................................................................................... 71
8.5 Parameter Information...................................................................................................................... 72
8.6 Parameter Name Hints...................................................................................................................... 72
8.7 Code Generation................................................................................................................................ 72
8.8 Code Folding....................................................................................................................................... 73
8.9 Quick Documentation Lookup........................................................................................................ 74
8.10 Code Reformatting.......................................................................................................................... 75
8.11 Finding Sample Code...................................................................................................................... 76
8.12 Live Templates.................................................................................................................................. 76
8.13 Summary........................................................................................................................................... 77
9. An Overview of the Android Architecture............................................................................................... 79
9.1 The Android Software Stack............................................................................................................. 79
9.2 The Linux Kernel................................................................................................................................ 80
9.3 Android Runtime – ART................................................................................................................... 80
9.4 Android Libraries............................................................................................................................... 80
9.4.1 C/C++ Libraries.......................................................................................................................... 81
9.5 Application Framework..................................................................................................................... 81
9.6 Applications........................................................................................................................................ 82
9.7 Summary............................................................................................................................................. 82
10. The Anatomy of an Android Application............................................................................................... 83
10.1 Android Activities............................................................................................................................ 83
10.2 Android Fragments.......................................................................................................................... 83
10.3 Android Intents................................................................................................................................ 84
10.4 Broadcast Intents.............................................................................................................................. 84
10.5 Broadcast Receivers......................................................................................................................... 84
10.6 Android Services.............................................................................................................................. 84
10.7 Content Providers............................................................................................................................ 85
10.8 The Application Manifest................................................................................................................ 85
10.9 Application Resources..................................................................................................................... 85
10.10 Application Context....................................................................................................................... 85
10.11 Summary......................................................................................................................................... 85
11. An Overview of Android View Binding.................................................................................................. 87
11.1 Find View by Id................................................................................................................................ 87
11.2 View Binding ................................................................................................................................... 87
11.3 Converting the AndroidSample project........................................................................................ 88
11.4 Enabling View Binding.................................................................................................................... 88
11.5 Using View Binding......................................................................................................................... 88
11.6 Choosing an Option........................................................................................................................ 89
11.7 View Binding in the Book Examples............................................................................................. 90
11.8 Migrating a Project to View Binding............................................................................................. 90
11.9 Summary........................................................................................................................................... 91
12. Understanding Android Application and Activity Lifecycles................................................................ 93
iii
Table of Contents
12.1 Android Applications and Resource Management...................................................................... 93
12.2 Android Process States.................................................................................................................... 93
12.2.1 Foreground Process.................................................................................................................. 94
12.2.2 Visible Process........................................................................................................................... 94
12.2.3 Service Process.......................................................................................................................... 94
12.2.4 Background Process.................................................................................................................. 94
12.2.5 Empty Process........................................................................................................................... 95
12.3 Inter-Process Dependencies .......................................................................................................... 95
12.4 The Activity Lifecycle....................................................................................................................... 95
12.5 The Activity Stack............................................................................................................................. 95
12.6 Activity States................................................................................................................................... 96
12.7 Configuration Changes................................................................................................................... 96
12.8 Handling State Change.................................................................................................................... 97
12.9 Summary........................................................................................................................................... 97
13. Handling Android Activity State Changes............................................................................................. 99
13.1 New vs. Old Lifecycle Techniques.................................................................................................. 99
13.2 The Activity and Fragment Classes................................................................................................ 99
13.3 Dynamic State vs. Persistent State................................................................................................ 101
13.4 The Android Lifecycle Methods................................................................................................... 102
13.5 Lifetimes.......................................................................................................................................... 103
13.6 Foldable Devices and Multi-Resume........................................................................................... 104
13.7 Disabling Configuration Change Restarts.................................................................................. 104
13.8 Lifecycle Method Limitations....................................................................................................... 104
13.9 Summary......................................................................................................................................... 105
14. Android Activity State Changes by Example........................................................................................ 107
14.1 Creating the State Change Example Project............................................................................... 107
14.2 Designing the User Interface........................................................................................................ 108
14.3 Overriding the Activity Lifecycle Methods................................................................................ 108
14.4 Filtering the Logcat Panel............................................................................................................. 110
14.5 Running the Application............................................................................................................... 112
14.6 Experimenting with the Activity.................................................................................................. 112
14.7 Summary......................................................................................................................................... 113
15. Saving and Restoring the State of an Android Activity........................................................................ 115
15.1 Saving Dynamic State.................................................................................................................... 115
15.2 Default Saving of User Interface State......................................................................................... 115
15.3 The Bundle Class............................................................................................................................ 116
15.4 Saving the State............................................................................................................................... 117
15.5 Restoring the State......................................................................................................................... 118
15.6 Testing the Application.................................................................................................................. 118
15.7 Summary......................................................................................................................................... 118
16. Understanding Android Views, View Groups and Layouts................................................................. 121
16.1 Designing for Different Android Devices................................................................................... 121
16.2 Views and View Groups................................................................................................................ 121
16.3 Android Layout Managers............................................................................................................ 121
16.4 The View Hierarchy....................................................................................................................... 123
16.5 Creating User Interfaces................................................................................................................ 124
16.6 Summary......................................................................................................................................... 124
iv
Table of Contents
17. A Guide to the Android Studio Layout Editor Tool............................................................................. 125
17.1 Basic vs. Empty Activity Templates............................................................................................. 125
17.2 The Android Studio Layout Editor.............................................................................................. 129
17.3 Design Mode................................................................................................................................... 129
17.4 The Palette....................................................................................................................................... 130
17.5 Design Mode and Layout Views.................................................................................................. 131
17.6 Night Mode..................................................................................................................................... 132
17.7 Code Mode...................................................................................................................................... 132
17.8 Split Mode....................................................................................................................................... 133
17.9 Setting Attributes........................................................................................................................... 133
17.10 Transforms.................................................................................................................................... 135
17.11 Tools Visibility Toggles................................................................................................................ 136
17.12 Converting Views......................................................................................................................... 138
17.13 Displaying Sample Data.............................................................................................................. 138
17.14 Creating a Custom Device Definition...................................................................................... 139
17.15 Changing the Current Device.................................................................................................... 140
17.16 Layout Validation......................................................................................................................... 140
17.17 Summary....................................................................................................................................... 141
18. A Guide to the Android ConstraintLayout........................................................................................... 143
18.1 How ConstraintLayout Works...................................................................................................... 143
18.1.1 Constraints............................................................................................................................... 143
18.1.2 Margins..................................................................................................................................... 144
18.1.3 Opposing Constraints............................................................................................................ 144
18.1.4 Constraint Bias........................................................................................................................ 145
18.1.5 Chains....................................................................................................................................... 146
18.1.6 Chain Styles.............................................................................................................................. 146
18.2 Baseline Alignment........................................................................................................................ 147
18.3 Configuring Widget Dimensions................................................................................................. 147
18.4 Guideline Helper............................................................................................................................ 148
18.5 Group Helper.................................................................................................................................. 148
18.6 Barrier Helper................................................................................................................................. 148
18.7 Flow Helper..................................................................................................................................... 150
18.8 Ratios............................................................................................................................................... 151
18.9 ConstraintLayout Advantages...................................................................................................... 151
18.10 ConstraintLayout Availability.................................................................................................... 152
18.11 Summary....................................................................................................................................... 152
19. A Guide to Using ConstraintLayout in Android Studio...................................................................... 153
19.1 Design and Layout Views.............................................................................................................. 153
19.2 Autoconnect Mode........................................................................................................................ 154
19.3 Inference Mode............................................................................................................................... 155
19.4 Manipulating Constraints Manually............................................................................................ 155
19.5 Adding Constraints in the Inspector........................................................................................... 156
19.6 Viewing Constraints in the Attributes Window......................................................................... 157
19.7 Deleting Constraints...................................................................................................................... 158
19.8 Adjusting Constraint Bias............................................................................................................. 158
19.9 Understanding ConstraintLayout Margins................................................................................. 159
19.10 The Importance of Opposing Constraints and Bias................................................................ 160
19.11 Configuring Widget Dimensions............................................................................................... 162
v
Table of Contents
19.12 Design Time Tools Positioning.................................................................................................. 163
19.13 Adding Guidelines....................................................................................................................... 164
19.14 Adding Barriers............................................................................................................................ 166
19.15 Adding a Group............................................................................................................................ 167
19.16 Working with the Flow Helper................................................................................................... 168
19.17 Widget Group Alignment and Distribution............................................................................. 169
19.18 Converting other Layouts to ConstraintLayout....................................................................... 170
19.19 Summary ...................................................................................................................................... 170
20. Working with ConstraintLayout Chains and Ratios in Android Studio............................................. 171
20.1 Creating a Chain............................................................................................................................ 171
20.2 Changing the Chain Style............................................................................................................. 173
20.3 Spread Inside Chain Style............................................................................................................. 173
20.4 Packed Chain Style......................................................................................................................... 174
20.5 Packed Chain Style with Bias........................................................................................................ 174
20.6 Weighted Chain.............................................................................................................................. 174
20.7 Working with Ratios...................................................................................................................... 175
20.8 Summary......................................................................................................................................... 177
21. An Android Studio Layout Editor ConstraintLayout Tutorial............................................................ 179
21.1 An Android Studio Layout Editor Tool Example...................................................................... 179
21.2 Creating a New Activity................................................................................................................ 179
21.3 Preparing the Layout Editor Environment................................................................................. 181
21.4 Adding the Widgets to the User Interface.................................................................................. 182
21.5 Adding the Constraints................................................................................................................. 185
21.6 Testing the Layout.......................................................................................................................... 186
21.7 Using the Layout Inspector........................................................................................................... 187
21.8 Summary......................................................................................................................................... 188
22. Manual XML Layout Design in Android Studio.................................................................................. 189
22.1 Manually Creating an XML Layout............................................................................................. 189
22.2 Manual XML vs. Visual Layout Design....................................................................................... 192
22.3 Summary......................................................................................................................................... 192
23. Managing Constraints using Constraint Sets....................................................................................... 193
23.1 Java Code vs. XML Layout Files................................................................................................... 193
23.2 Creating Views................................................................................................................................ 193
23.3 View Attributes............................................................................................................................... 194
23.4 Constraint Sets................................................................................................................................ 194
23.4.1 Establishing Connections...................................................................................................... 194
23.4.2 Applying Constraints to a Layout......................................................................................... 194
23.4.3 Parent Constraint Connections............................................................................................. 194
23.4.4 Sizing Constraints................................................................................................................... 195
23.4.5 Constraint Bias........................................................................................................................ 195
23.4.6 Alignment Constraints........................................................................................................... 195
23.4.7 Copying and Applying Constraint Sets................................................................................ 195
23.4.8 ConstraintLayout Chains....................................................................................................... 195
23.4.9 Guidelines................................................................................................................................ 196
23.4.10 Removing Constraints.......................................................................................................... 196
23.4.11 Scaling.................................................................................................................................... 196
23.4.12 Rotation.................................................................................................................................. 197
vi
Table of Contents
23.5 Summary......................................................................................................................................... 197
24. An Android ConstraintSet Tutorial...................................................................................................... 199
24.1 Creating the Example Project in Android Studio...................................................................... 199
24.2 Adding Views to an Activity......................................................................................................... 199
24.3 Setting View Attributes.................................................................................................................. 200
24.4 Creating View IDs.......................................................................................................................... 201
24.5 Configuring the Constraint Set.................................................................................................... 202
24.6 Adding the EditText View............................................................................................................. 203
24.7 Converting Density Independent Pixels (dp) to Pixels (px)..................................................... 204
24.8 Summary......................................................................................................................................... 205
25. A Guide to using Apply Changes in Android Studio........................................................................... 207
25.1 Introducing Apply Changes.......................................................................................................... 207
25.2 Understanding Apply Changes Options..................................................................................... 207
25.3 Using Apply Changes..................................................................................................................... 208
25.4 Configuring Apply Changes Fallback Settings........................................................................... 209
25.5 An Apply Changes Tutorial.......................................................................................................... 209
25.6 Using Apply Code Changes.......................................................................................................... 209
25.7 Using Apply Changes and Restart Activity................................................................................. 210
25.8 Using Run App............................................................................................................................... 210
25.9 Summary......................................................................................................................................... 210
26. An Overview and Example of Android Event Handling...................................................................... 211
26.1 Understanding Android Events................................................................................................... 211
26.2 Using the android:onClick Resource........................................................................................... 211
26.3 Event Listeners and Callback Methods....................................................................................... 212
26.4 An Event Handling Example........................................................................................................ 212
26.5 Designing the User Interface........................................................................................................ 213
26.6 The Event Listener and Callback Method................................................................................... 213
26.7 Consuming Events......................................................................................................................... 215
26.8 Summary......................................................................................................................................... 216
27. Android Touch and Multi-touch Event Handling................................................................................ 217
27.1 Intercepting Touch Events............................................................................................................ 217
27.2 The MotionEvent Object............................................................................................................... 217
27.3 Understanding Touch Actions...................................................................................................... 218
27.4 Handling Multiple Touches.......................................................................................................... 218
27.5 An Example Multi-Touch Application........................................................................................ 218
27.6 Designing the Activity User Interface......................................................................................... 219
27.7 Implementing the Touch Event Listener..................................................................................... 219
27.8 Running the Example Application............................................................................................... 222
27.9 Summary......................................................................................................................................... 223
28. Detecting Common Gestures Using the Android Gesture Detector Class.......................................... 225
28.1 Implementing Common Gesture Detection............................................................................... 225
28.2 Creating an Example Gesture Detection Project....................................................................... 226
28.3 Implementing the Listener Class.................................................................................................. 226
28.4 Creating the GestureDetectorCompat Instance......................................................................... 228
28.5 Implementing the onTouchEvent() Method............................................................................... 229
28.6 Testing the Application.................................................................................................................. 229

vii
Table of Contents
28.7 Summary......................................................................................................................................... 230
29. Implementing Custom Gesture and Pinch Recognition on Android.................................................. 231
29.1 The Android Gesture Builder Application.................................................................................. 231
29.2 The GestureOverlayView Class.................................................................................................... 231
29.3 Detecting Gestures......................................................................................................................... 231
29.4 Identifying Specific Gestures........................................................................................................ 231
29.5 Installing and Running the Gesture Builder Application......................................................... 232
29.6 Creating a Gestures File................................................................................................................ 232
29.7 Creating the Example Project....................................................................................................... 232
29.8 Extracting the Gestures File from the SD Card......................................................................... 233
29.9 Adding the Gestures File to the Project...................................................................................... 233
29.10 Designing the User Interface...................................................................................................... 233
29.11 Loading the Gestures File........................................................................................................... 234
29.12 Registering the Event Listener.................................................................................................... 235
29.13 Implementing the onGesturePerformed Method.................................................................... 235
29.14 Testing the Application............................................................................................................... 236
29.15 Configuring the GestureOverlayView....................................................................................... 237
29.16 Intercepting Gestures.................................................................................................................. 237
29.17 Detecting Pinch Gestures............................................................................................................ 237
29.18 A Pinch Gesture Example Project.............................................................................................. 238
29.19 Summary....................................................................................................................................... 240
30. An Introduction to Android Fragments............................................................................................... 241
30.1 What is a Fragment?...................................................................................................................... 241
30.2 Creating a Fragment...................................................................................................................... 241
30.3 Adding a Fragment to an Activity using the Layout XML File................................................ 242
30.4 Adding and Managing Fragments in Code................................................................................ 244
30.5 Handling Fragment Events........................................................................................................... 245
30.6 Implementing Fragment Communication................................................................................. 246
30.7 Summary ........................................................................................................................................ 247
31. Using Fragments in Android Studio - An Example.............................................................................. 249
31.1 About the Example Fragment Application................................................................................. 249
31.2 Creating the Example Project....................................................................................................... 249
31.3 Creating the First Fragment Layout............................................................................................. 249
31.4 Migrating a Fragment to View Binding...................................................................................... 251
31.5 Adding the Second Fragment....................................................................................................... 252
31.6 Adding the Fragments to the Activity......................................................................................... 253
31.7 Making the Toolbar Fragment Talk to the Activity................................................................... 254
31.8 Making the Activity Talk to the Text Fragment......................................................................... 257
31.9 Testing the Application.................................................................................................................. 258
31.10 Summary....................................................................................................................................... 259
32. Modern Android App Architecture with Jetpack................................................................................. 261
32.1 What is Android Jetpack?............................................................................................................. 261
32.2 The “Old” Architecture.................................................................................................................. 261
32.3 Modern Android Architecture..................................................................................................... 261
32.4 The ViewModel Component........................................................................................................ 262
32.5 The LiveData Component............................................................................................................. 262
32.6 ViewModel Saved State................................................................................................................. 263
viii
Table of Contents
32.7 LiveData and Data Binding........................................................................................................... 264
32.8 Android Lifecycles......................................................................................................................... 264
32.9 Repository Modules....................................................................................................................... 264
32.10 Summary....................................................................................................................................... 265
33. An Android Jetpack ViewModel Tutorial............................................................................................. 267
33.1 About the Project........................................................................................................................... 267
33.2 Creating the ViewModel Example Project.................................................................................. 267
33.3 Reviewing the Project.................................................................................................................... 268
33.3.1 The Main Activity.................................................................................................................... 268
33.3.2 The Content Fragment........................................................................................................... 268
33.3.3 The ViewModel....................................................................................................................... 270
33.4 Designing the Fragment Layout................................................................................................... 270
33.5 Implementing the View Model..................................................................................................... 271
33.6 Associating the Fragment with the View Model........................................................................ 271
33.7 Modifying the Fragment............................................................................................................... 272
33.8 Accessing the ViewModel Data.................................................................................................... 273
33.9 Testing the Project.......................................................................................................................... 274
33.10 Summary....................................................................................................................................... 274
34. An Android Jetpack LiveData Tutorial................................................................................................. 275
34.1 LiveData - A Recap........................................................................................................................ 275
34.2 Adding LiveData to the ViewModel............................................................................................ 275
34.3 Implementing the Observer.......................................................................................................... 277
34.4 Summary......................................................................................................................................... 279
35. An Overview of Android Jetpack Data Binding................................................................................... 281
35.1 An Overview of Data Binding...................................................................................................... 281
35.2 The Key Components of Data Binding....................................................................................... 281
35.2.1 The Project Build Configuration........................................................................................... 281
35.2.2 The Data Binding Layout File................................................................................................ 282
35.2.3 The Layout File Data Element............................................................................................... 283
35.2.4 The Binding Classes................................................................................................................ 284
35.2.5 Data Binding Variable Configuration................................................................................... 284
35.2.6 Binding Expressions (One-Way)........................................................................................... 285
35.2.7 Binding Expressions (Two-Way)........................................................................................... 286
35.2.8 Event and Listener Bindings.................................................................................................. 286
35.3 Summary......................................................................................................................................... 287
36. An Android Jetpack Data Binding Tutorial.......................................................................................... 289
36.1 Removing the Redundant Code................................................................................................... 289
36.2 Enabling Data Binding.................................................................................................................. 290
36.3 Adding the Layout Element.......................................................................................................... 291
36.4 Adding the Data Element to Layout File..................................................................................... 292
36.5 Working with the Binding Class.................................................................................................. 292
36.6 Assigning the ViewModel Instance to the Data Binding Variable.......................................... 293
36.7 Adding Binding Expressions........................................................................................................ 294
36.8 Adding the Conversion Method.................................................................................................. 295
36.9 Adding a Listener Binding............................................................................................................ 295
36.10 Testing the App............................................................................................................................. 295
36.11 Summary....................................................................................................................................... 296
ix
Table of Contents
37. An Android ViewModel Saved State Tutorial....................................................................................... 297
37.1 Understanding ViewModel State Saving..................................................................................... 297
37.2 Implementing ViewModel State Saving...................................................................................... 297
37.3 Saving and Restoring State............................................................................................................ 299
37.4 Adding Saved State Support to the ViewModelDemo Project................................................. 299
37.5 Summary......................................................................................................................................... 301
38. Working with Android Lifecycle-Aware Components......................................................................... 303
38.1 Lifecycle Awareness....................................................................................................................... 303
38.2 Lifecycle Owners............................................................................................................................ 303
38.3 Lifecycle Observers........................................................................................................................ 304
38.4 Lifecycle States and Events............................................................................................................ 305
38.5 Summary......................................................................................................................................... 306
39. An Android Jetpack Lifecycle Awareness Tutorial............................................................................... 307
39.1 Creating the Example Lifecycle Project....................................................................................... 307
39.2 Creating a Lifecycle Observer....................................................................................................... 307
39.3 Adding the Observer..................................................................................................................... 309
39.4 Testing the Observer...................................................................................................................... 309
39.5 Creating a Lifecycle Owner........................................................................................................... 309
39.6 Testing the Custom Lifecycle Owner........................................................................................... 311
39.7 Summary......................................................................................................................................... 312
40. An Overview of the Navigation Architecture Component................................................................... 313
40.1 Understanding Navigation............................................................................................................ 313
40.2 Declaring a Navigation Host......................................................................................................... 314
40.3 The Navigation Graph................................................................................................................... 316
40.4 Accessing the Navigation Controller........................................................................................... 317
40.5 Triggering a Navigation Action.................................................................................................... 317
40.6 Passing Arguments......................................................................................................................... 318
40.7 Summary......................................................................................................................................... 318
41. An Android Jetpack Navigation Component Tutorial......................................................................... 319
41.1 Creating the NavigationDemo Project........................................................................................ 319
41.2 Adding Navigation to the Build Configuration......................................................................... 319
41.3 Creating the Navigation Graph Resource File............................................................................ 320
41.4 Declaring a Navigation Host......................................................................................................... 321
41.5 Adding Navigation Destinations.................................................................................................. 322
41.6 Designing the Destination Fragment Layouts............................................................................ 324
41.7 Adding an Action to the Navigation Graph............................................................................... 325
41.8 Implement the OnFragmentInteractionListener....................................................................... 326
41.9 Adding View Binding Support to the Destination Fragments................................................. 327
41.10 Triggering the Action.................................................................................................................. 328
41.11 Passing Data Using Safeargs....................................................................................................... 329
41.12 Summary....................................................................................................................................... 332
42. An Introduction to MotionLayout........................................................................................................ 333
42.1 An Overview of MotionLayout.................................................................................................... 333
42.2 MotionLayout................................................................................................................................. 333
42.3 MotionScene................................................................................................................................... 333
42.4 Configuring ConstraintSets.......................................................................................................... 334
x
Table of Contents
42.5 Custom Attributes.......................................................................................................................... 335
42.6 Triggering an Animation............................................................................................................... 336
42.7 Arc Motion...................................................................................................................................... 338
42.8 Keyframes........................................................................................................................................ 338
42.8.1 Attribute Keyframes................................................................................................................ 338
42.8.2 Position Keyframes................................................................................................................. 339
42.9 Time Linearity................................................................................................................................ 342
42.10 KeyTrigger..................................................................................................................................... 342
42.11 Cycle and Time Cycle Keyframes.............................................................................................. 343
42.12 Starting an Animation from Code............................................................................................. 343
42.13 Summary....................................................................................................................................... 344
43. An Android MotionLayout Editor Tutorial.......................................................................................... 345
43.1 Creating the MotionLayoutDemo Project.................................................................................. 345
43.2 ConstraintLayout to MotionLayout Conversion....................................................................... 345
43.3 Configuring Start and End Constraints...................................................................................... 347
43.4 Previewing the MotionLayout Animation.................................................................................. 349
43.5 Adding an OnClick Gesture......................................................................................................... 350
43.6 Adding an Attribute Keyframe to the Transition....................................................................... 351
43.7 Adding a CustomAttribute to a Transition................................................................................. 354
43.8 Adding Position Keyframes.......................................................................................................... 355
43.9 Summary......................................................................................................................................... 358
44. A MotionLayout KeyCycle Tutorial...................................................................................................... 359
44.1 An Overview of Cycle Keyframes................................................................................................ 359
44.2 Using the Cycle Editor................................................................................................................... 363
44.3 Creating the KeyCycleDemo Project........................................................................................... 364
44.4 Configuring the Start and End Constraints................................................................................ 364
44.5 Creating the Cycles........................................................................................................................ 366
44.6 Previewing the Animation............................................................................................................ 368
44.7 Adding the KeyFrameSet to the MotionScene........................................................................... 368
44.8 Summary......................................................................................................................................... 370
45. Working with the Floating Action Button and Snackbar..................................................................... 371
45.1 The Material Design....................................................................................................................... 371
45.2 The Design Library........................................................................................................................ 371
45.3 The Floating Action Button (FAB) .............................................................................................. 371
45.4 The Snackbar................................................................................................................................... 372
45.5 Creating the Example Project....................................................................................................... 373
45.6 Reviewing the Project.................................................................................................................... 373
45.7 Removing Navigation Features.................................................................................................... 374
45.8 Changing the Floating Action Button......................................................................................... 375
45.9 Adding an Action to the Snackbar............................................................................................... 376
45.10 Summary....................................................................................................................................... 376
46. Creating a Tabbed Interface using the TabLayout Component........................................................... 379
46.1 An Introduction to the ViewPager2............................................................................................ 379
46.2 An Overview of the TabLayout Component.............................................................................. 379
46.3 Creating the TabLayoutDemo Project......................................................................................... 380
46.4 Creating the First Fragment.......................................................................................................... 381
46.5 Duplicating the Fragments........................................................................................................... 382
xi
Table of Contents
46.6 Adding the TabLayout and ViewPager2...................................................................................... 383
46.7 Creating the Pager Adapter........................................................................................................... 384
46.8 Performing the Initialization Tasks.............................................................................................. 385
46.9 Testing the Application.................................................................................................................. 387
46.10 Customizing the TabLayout........................................................................................................ 387
46.11 Summary....................................................................................................................................... 389
47. Working with the RecyclerView and CardView Widgets..................................................................... 391
47.1 An Overview of the RecyclerView............................................................................................... 391
47.2 An Overview of the CardView..................................................................................................... 393
47.3 Summary......................................................................................................................................... 394
48. An Android RecyclerView and CardView Tutorial.............................................................................. 395
48.1 Creating the CardDemo Project.................................................................................................. 395
48.2 Modifying the Basic Activity Project........................................................................................... 395
48.3 Designing the CardView Layout.................................................................................................. 396
48.4 Adding the RecyclerView.............................................................................................................. 397
48.5 Adding the Image Files.................................................................................................................. 397
48.6 Creating the RecyclerView Adapter............................................................................................. 398
48.7 Initializing the RecyclerView Component.................................................................................. 400
48.8 Testing the Application.................................................................................................................. 401
48.9 Responding to Card Selections.................................................................................................... 401
48.10 Summary....................................................................................................................................... 403
49. A Layout Editor Sample Data Tutorial................................................................................................. 405
49.1 Adding Sample Data to a Project................................................................................................. 405
49.2 Using Custom Sample Data.......................................................................................................... 409
49.3 Summary......................................................................................................................................... 412
50. Working with the AppBar and Collapsing Toolbar Layouts................................................................ 413
50.1 The Anatomy of an AppBar.......................................................................................................... 413
50.2 The Example Project...................................................................................................................... 414
50.3 Coordinating the RecyclerView and Toolbar............................................................................. 414
50.4 Introducing the Collapsing Toolbar Layout............................................................................... 416
50.5 Changing the Title and Scrim Color........................................................................................... 419
50.6 Summary......................................................................................................................................... 420
51. An Android Studio Primary/Detail Flow Tutorial............................................................................... 421
51.1 The Primary/Detail Flow............................................................................................................... 421
51.2 Creating a Primary/Detail Flow Activity.................................................................................... 422
51.3 Modifying the Primary/Detail Flow Template........................................................................... 422
51.4 Changing the Content Model....................................................................................................... 423
51.5 Changing the Detail Pane............................................................................................................. 424
51.6 Modifying the ItemDetailFragment Class.................................................................................. 425
51.7 Modifying the ItemListFragment Class....................................................................................... 427
51.8 Adding Manifest Permissions....................................................................................................... 427
51.9 Running the Application............................................................................................................... 427
51.10 Summary....................................................................................................................................... 428
52. An Overview of Android Services......................................................................................................... 429
52.1 Intent Service.................................................................................................................................. 429
52.2 Bound Service................................................................................................................................. 429
xii
Table of Contents
52.3 The Anatomy of a Service............................................................................................................. 430
52.4 Controlling Destroyed Service Restart Options........................................................................ 430
52.5 Declaring a Service in the Manifest File...................................................................................... 430
52.6 Starting a Service Running on System Startup........................................................................... 432
52.7 Summary......................................................................................................................................... 432
53. An Overview of Android Intents.......................................................................................................... 433
53.1 An Overview of Intents................................................................................................................. 433
53.2 Explicit Intents................................................................................................................................ 433
53.3 Returning Data from an Activity................................................................................................. 434
53.4 Implicit Intents............................................................................................................................... 435
53.5 Using Intent Filters......................................................................................................................... 436
53.6 Automatic Link Verification......................................................................................................... 437
53.7 Manually Enabling Links.............................................................................................................. 439
53.8 Checking Intent Availability......................................................................................................... 440
53.9 Summary......................................................................................................................................... 441
54. Android Explicit Intents – A Worked Example.................................................................................... 443
54.1 Creating the Explicit Intent Example Application..................................................................... 443
54.2 Designing the User Interface Layout for MainActivity............................................................. 443
54.3 Creating the Second Activity Class.............................................................................................. 444
54.4 Designing the User Interface Layout for SecondActivity......................................................... 445
54.5 Reviewing the Application Manifest File.................................................................................... 445
54.6 Creating the Intent......................................................................................................................... 446
54.7 Extracting Intent Data................................................................................................................... 447
54.8 Launching SecondActivity as a Sub-Activity.............................................................................. 448
54.9 Returning Data from a Sub-Activity........................................................................................... 449
54.10 Testing the Application............................................................................................................... 449
54.11 Summary....................................................................................................................................... 449
55. Android Implicit Intents – A Worked Example................................................................................... 451
55.1 Creating the Android Studio Implicit Intent Example Project................................................ 451
55.2 Designing the User Interface........................................................................................................ 451
55.3 Creating the Implicit Intent.......................................................................................................... 452
55.4 Adding a Second Matching Activity............................................................................................ 453
55.5 Adding the Web View to the UI................................................................................................... 453
55.6 Obtaining the Intent URL............................................................................................................. 454
55.7 Modifying the MyWebView Project Manifest File.................................................................... 455
55.8 Installing the MyWebView Package on a Device....................................................................... 456
55.9 Testing the Application.................................................................................................................. 457
55.10 Manually Enabling the Link....................................................................................................... 457
55.11 Automatic Link Verification....................................................................................................... 459
55.12 Summary....................................................................................................................................... 461
56. Android Broadcast Intents and Broadcast Receivers........................................................................... 463
56.1 An Overview of Broadcast Intents............................................................................................... 463
56.2 An Overview of Broadcast Receivers.......................................................................................... 464
56.3 Obtaining Results from a Broadcast............................................................................................ 465
56.4 Sticky Broadcast Intents................................................................................................................ 465
56.5 The Broadcast Intent Example...................................................................................................... 466
56.6 Creating the Example Application............................................................................................... 466
xiii
Random documents with unrelated
content Scribd suggests to you:
I have said nothing to Nellie yet. Somehow I can't, till I
have a scrap of success to tell. Is that pride?

Another short tale is going on pretty steadily. Mother


likes me to keep up my practising directly after breakfast
every morning; and then I help her for an hour with the
children. After that, I can generally get one or two hours for
writing; and also there are the evenings. The children go to
bed early, and then Mother works, and Uncle Tom and
Ramsay read. The Romillys always have to work and talk
and play in the evening. It sounds cheerful; but our plan is
better for my stories. We do talk, off and on; only not a
very great deal; and I get on with writing between whiles.

CHAPTER XII.
AND MAGGIE'S EFFORTS.

GLADYS HEPBURN'S JOURNAL—continued.

October 18.

I MET the girls to-day, and they were quite full of the
thought of this Yorkshire estate, which has come to Mr. and
Mrs. Romilly.

The place is named "Beckdale," and it is far-away in a


lonely part of the West Riding. It has belonged to an old
great-uncle of Mrs. Romilly's, who stayed there all the year
round, and never asked anybody to visit him; or scarcely
ever. Once, about ten years ago, the two eldest boys, Keith
and Eustace, spent about a fortnight of their summer
holidays with the old gentleman; and that is all. So of
course his death can't make his relations very unhappy; and
naturally the girls do like the idea of spending their
summers in such a lovely place.

For it must be really very lovely, quite hilly and


mountainous, with beautiful dales, and wild passes, and
queer underground caves, and torrents and waterfalls.
Eustace was walking with the girls; and though he did not
say very much—he never does when they are there—what
he did say sounded more like Switzerland than England. But
I shall miss Nellie dreadfully, if she is to be away so long
every year.

No answer yet about my little book. Every time the


postman knocks I hope and hope, but the letter does not
come. It is a long while to wait.

Something seems to be wrong with Mrs. Romilly—we


don't know what. She has grown terribly thin, and she is
weak and low and hysterical. I think Elfie takes after her
mother in being so hysterical; only it is treated as a crime in
Elfie. Everybody in the house is expected to be always
happy and cheerful, for the sake of Mrs. Romilly, and for
fear of upsetting her. The least thing upsets her now. She
burst into tears in Church on Sunday, and had to be taken
out. It did look so funny to see her little bit of a husband
trying to support her; and I was angry with myself for
feeling it funny, when they all looked so troubled—and yet I
could hardly keep down a smile.

I am quite sure life is not very smooth just now in


Glynde House. Nellie does not say much; but Elfie looks
wretched; and Elfie is a sort of family-barometer, Mother
says. One can tell the state of the home atmosphere from
her face. Maggie and Nona are not easily disturbed; and
Thyrza seems always apart from the rest.

November 22.—A really hopeful answer has come about


my little book. If I am willing to make certain alterations, it
is most likely to be accepted. Of course I should not think of
refusing. They want the story to be more cheerful, and not
to have a sad ending.

I sent off lately another small story-book to a publisher;


but somehow I am not hopeful about that. Now I shall set
to work upon these alterations.

Poor Mrs. Romilly is very ill, with a sharp attack on the


chest. A doctor has been down from London for a
consultation; and he says she has been frightfully delicate
for a long while, and has been under a great strain, trying
to keep up. The lungs are affected, he says, but I believe
not dangerously; and her nerves are much worse. She can
see nobody except Nellie and her maid,—not even Mr.
Romilly; and she won't hear of a trained nurse, and they
don't know what to do with her. I hardly get a glimpse of
Nellie.

December 22.—Poor Mrs. Romilly is a shade better,—not


so fearfully weak and excitable, but still she can't leave her
room, or bear to be spoken to above a whisper. A step on
the landing sends her into a sort of agony. I wonder if she
could not possibly help some of this, if she really tried. She
makes such a fuss always about Elfie controlling herself. But
then Mrs. Romilly is ill, and Elfie is not. That of course
makes some difference. I do think it is terribly trying for
those girls, though—not to speak of Denham. The house
has to be kept as still as if a funeral were going on.

February 20.—Those poor Romillys! Oh, I do feel sorry


for them—and for myself!

There has been another consultation about Mrs.


Romilly; and the doctors say she must go abroad as soon as
possible, and stay away nobody knows how long. Nellie and
Benson are to travel with her.

The cold March winds are talked about as the chief


reason; but of course that is not all, for she is to stay on the
continent six months at least. March winds will be over long
enough before then.

Their chief difficulties have been about the home party.


Mr. Romilly stays at Glynde House, to be sure; but he is of
no use, and Maggie is too young to manage the others. Miss
Jackson not being able to come back makes such a
difference.

They are writing to ask Mrs. Romilly's Bath friend to be


governess. Miss Conway has lost her aunt, and wants now
to support herself by going out. But she is only a girl—and
there are all those girls to look after. And Mr. Romilly being
so fidgety and odd—and Thyrza so set on her own way—and
Elfie so easily upset—why, it ought to be a woman of forty
or fifty, to know what to do. However, Mrs. Romilly is quite
set on having nobody but Miss Conway, and the others
daren't contradict her.
February 24.—It is all settled. Miss Conway comes a
week after Mrs. Romilly goes. I cannot help pitying her.
Uncle Tom says, "No doubt it will all be for the best." But is
everything always for the best,—even unwise arrangements
of our own? If they were, I should think one would not mind
making blunders.

February 25. Wednesday.—This morning at last came


the answer from the Society, which we have waited for so
long. My book is taken. The alterations are found to be all
right. It will be published at once, as a one-and-sixpenny
volume, and I am to have fifteen pounds for the copyright.

Uncle Tom says "selling the copyright" of a book means


getting rid of it altogether. I shall never have any more right
over the tale. He says that is the simplest and best sort of
arrangement for a beginner. I am very glad and very
thankful; and I do feel that this is a real answer to prayer.

About a month ago I told Nellie what I had done; and


she was so interested. But till this morning, the other girls
have only known that I was fond of scribbling tales for my
own amusement. They had arranged to call after breakfast,
and take me for a long walk; and when they came Ramsay
told them about my book.

Elfie's eyes grew very big; and Thyrza as usual said


nothing. She only seemed rather astonished. Nona said
"How nice!" And Maggie began to talk at once about doing
the same. She said she should begin a story to-morrow;
and I think she thought it the easiest thing in the world.
Is it really easy? Or can it be? I have been wondering.
Of course music is easy in one way to a man who has a
musical genius,—and painting to a man who has a gift for
painting. But in another way it is not easy, for it must
always mean hard work, and hard thinking, and
perseverance. Not just tossing off a thing anyhow, and
expecting to succeed without a grain of trouble.

It doesn't seem to me that writing books is a thing


which anybody can do, just in imitation of somebody else.
One must have a sort of natural bent or gift—God's gift,—
and then one has to use that gift, and to make the most of
it by hard work.

I did not say all this to Maggie, however. For she might
have such a bent, and yet not have found it out. And at all
events she may as well try.

February 28. Saturday Evening.—Mother and I have


been to dinner at Glynde House, and had our first view of
Miss Conway. It would have been an earlier view, if we had
not both been away from home for two nights, a thing
which hardly over happens.

I like Miss Conway: and I am sure we shall like her


more still by-and-by, as we know her better.

She is rather uncommon in look, almost as tall and


slight as Mrs. Romilly, and quietly graceful, without any of
those squirming undulations when she walks. I should never
guess her to be so young as they say. She has a pale face,
oval-shaped and rather thin, with regular features and a
firm mouth and dark hair. And her grey eyes look you
straight in the face, with a kind of grave questioning
expression, as if she wanted to make out what you are, and
whether you mean to be friends. She says she is strong,
and fond of long walks. And she is very fond of reading.

Maggie made such a blunder, talking about Miss Conway


out in the hall, never looking to see who might be near. And
Miss Conway was quite close. She spoke out at once, and
Maggie was very much ashamed, for she had been saying
that Miss Conway was stiff and she did not like her.

Mother and I both thought Miss Conway behaved so


well, in such a ladylike manner. She made no fuss, and kept
quite calm, and nobody could have guessed afterwards from
her look what had happened.

There was quite a scene with Elfie at dinner-time. Mr.


Romilly persisted in talking about his wife, and everybody
seemed bent on saying just the wrong thing, till Elfie had a
sort of hysterical attack, like once before, and could not
speak. And Miss Conway seemed to know exactly what to
do. Mother says she will be "quite an acquisition." But I am
afraid that little prim Miss Millington doesn't think so; and
she manages to make the girls so oddly fond of her. I only
hope she will not set them against Miss Conway.

March 10.—My second little book has come back from


the publisher, declined. I do not think I am surprised. It
seemed to me rather poor, when finished. Perhaps I shall
make one more try with it; and if it fails a second time, I
shall feel sure that it is not worth publishing.

I have another tale in hand now, which I really do like.


It is to be larger than the others, perhaps as big as a three-
and-sixpenny book, or even a five-shilling one, but this I
don't whisper to anybody. To write a five-shilling book has
been my dream for years; only of course it may not come to
pass yet.

I shall call the tale "Tom and Mary" for the present. I
am writing each chapter in pencil first, and then in ink
before going on to the next; and a great many parts will
perhaps need copying again, after the whole is done.

Miss Conway has fitted quietly into her work. They all
say she is an interesting teacher,—even Nona, who hates
lessons. Mother thinks it quite wonderful, the way in which
she has taken things into her own hands, and the tact she
shows, for after all she is such a thorough girl, and there
has been nothing in her training to prepare her for this sort
of life.

Things may be going less smoothly than we know; and


it is difficult to tell from Miss Conway's face whether she is
quite happy. She comes in to see Mother and me, but says
little about the girls. And in a grave steady sort of fashion
she is always cheerful; but, as Mother says, one can't tell if
that manner is natural to her. I should like to see her really
excited and pleased. I think she would become almost
beautiful.

Thyrza certainly likes Miss Conway, but Maggie does


not. I fancy Elfie gives her the most affection, and perhaps
she would give more, if Nona did not laugh at her.

March 15.—Maggie has actually finished a story, and is


sending it off to a publisher. The other girls have helped her
to write, and have put in little pieces. I cannot understand
anybody being able to do any real work in such a way; but
of course people are different.

Yesterday Maggie asked me to go in to tea, and she


read aloud the story to all of us in the schoolroom. I
thought her very brave to do such a thing. She asked, too,
if Mother would like to see it, but decided not to have
delays. Curious—that though Maggie is shy about some
things, she is not in the least shy about her writing.

The reading aloud did not take long. I believe Maggie


thought she had written quite a good-sized volume; and
when I calculated for her, and found that it would not be
more than a tiny twopenny or threepenny book, she was
almost vexed, and would not believe me.

Then Maggie wanted to know how we all liked the story;


and the girls praised it immensely. I was puzzled to know
what to say; for it read exactly like a rough copy, and the
verbs were mixed up so oddly, and there were whole pages
without a single full stop. And I could not make out any
particular plot. The people in it come and go and talk and
do things, without any object; and what one person says
would do just as well for all the rest to say.

I could not, of course, be so unkind as to say all this to


Maggie, especially just now, when I have had a little
success! And, after all, how do I know that others won't say
the very same of my story?

When Maggie would have an opinion, I said, "What does


Miss Conway think?"

"I think it wants cohesion," Miss Conway said at once.

Maggie repeated the word, "Cohesion;" and looked


puzzled.
Then she turned to me again; and I said the story was
pretty, I have been wondering since if that was quite
honest; only really one might call almost anything "pretty."
And then I said that perhaps, if I were Maggie, I would try
writing it out once more, so as to improve and polish a
little. But Maggie said, "Oh, that would be a bother! It will
do well enough as it is."

I am afraid I don't understand Maggie. For I should


think one never ought to be content with doing a thing just
"well enough." It ought to be always one's very best and
very utmost. Isn't that meant when we are told in the Bible
to do "with our might" whatever we have to do?

One could hardly look for success, except with one's


best. Of course success is not the chief tag in life; and
sometimes I am afraid that I wish for it too much. The chief
thing is doing all that God gives us to do for Him. One may
think too eagerly about success, but never too much about
doing His will. And that only makes the struggling after our
very best and utmost still more needful. For if it were only
for oneself, it wouldn't matter so much how one worked;
but if it is all for Him, I don't see how one can be content
with any sort of hurried or careless work.

CHAPTER XIII.
LETTERS—VARIOUS.

FROM MAGGIE TO NELLIE.


April 15.

DARLING NELLIE,—We are all so glad to hear


better accounts of sweetest Mother, and that
she likes the idea of going soon to Germany.
The weather has been so lovely this week, that
tennis is beginning, and I am getting several
invitations. So I do hope it will keep fine. Thyrza
is asked too, but she won't go. She says she
can't possibly spare the time from lessons. It is
so tiresome, for I don't half like going alone—at
least to some houses.

I wish Lady Denham and Sir Keith would


come back, for tennis at The Park is nicer than
anywhere else, of course. Did I tell you about
Miss Conway meeting Sir Keith in the train, the
day she came to us, and getting him to see
after her luggage or something of the sort? Poor
Millie says she could never have done such a
thing. I believe Sir Keith caught a bad cold that
day, and that was why Lady Denham hurried off
with him to Torquay, and has stayed there ever
since. If I were a man, I should not like to have
such a fuss made. Lady Denham seems to be
always getting into a fright about him.

I expect I shall hear very soon about my book


now: and when that is settled I mean to write
another. Gladys does, you know. Has Gladys
said anything to you about my story? I thought
it so funny of Gladys not to say more, when I
asked her how she liked it. Millie says Gladys is
jealous of anybody else writing books as well as
herself: and I do really think she must be—just
a little bit. Else, why shouldn't she like my
story, as much as the others do?

I wonder if I shall have fifteen pounds for it,


like Gladys. It would be very nice: and I don't
see why I shouldn't. I think writing books is
great fun.

Tell darling Mother I will write to her next. It


is your turn now, and Father is sending a long
letter to Mother.—Ever your loving sister,
MAGGIE.

Private half-sheet, enclosed in, the above:—

I can't say more for Mother to see, of course,


as she mustn't be worried, but you know we
settled that you should have private scraps now
and then only for yourself, darling, and I must
tell you how disagreeable things are. Miss Con
will have everything just as she chooses in the
schoolroom; and poor dear Millie is so unhappy.
Miss Con seems quite to forget that Millie has
been here so much the longest. I do think it is
too bad. Millie says she feels just like an
intruder now, when she has to go into the
schoolroom.

Only think! Yesterday I found poor Millie


crying so in my room, and she said she had
come there for comfort. It was something Miss
Con had done. I can't imagine what Mother
finds to like so in Miss Con. She is so cold and
stiff. Thyrza defends her through thick and thin;
but of course Thyrza always must go contrary
to everybody else. If I liked Miss Con, Thyrza
would be sure to detest her.

Elfie is the only one besides who pretends to


care for Miss Con: and that is only because she
makes a fuss with Elfie. I'm sure I don't know
what Mother would say. Yesterday, Nona says,
she actually told Elfie to leave off doing her
German translation for Fraulein, because she
"looked tired"—just imagine!—and made her lie
down on the schoolroom sofa, and Elfie went off
sound asleep for more than two hours. And
Popsie wasn't allowed to practise, when Millie
sent her down, for fear of waking Elfie. And it
must have been all a nonsensical fancy, for I
never saw Elfie look better than she did
yesterday evening. We shall have no end of
fusses, if she is coddled like this.

FROM THYRZA TO NELLIE.

April 22.

MY DEAR NELLIE,—YOU told us all to write


quite openly to you, so long as we could
manage not to worry Mother. So I am sending a
sheet enclosed in a letter from Gladys to you,
as she says she has room.

I do wish something could be done about the


way Millie goes on. It is perfectly abominable.
She sets herself against Miss Con on every
possible opportunity, and does her very best to
set the girls against her too.

The fact is, Miss Con doesn't flatter Millie, and


Millie can't get along without flattery. It is meat
and drink to her. And Millie is frightfully jealous
of Miss Con, for being taller and better looking
and cleverer than herself—and also for being
Mother's friend. I do wish sometimes that
Mother had just let things alone, instead of
trying to arrange for Miss Con to be like a
visitor as well as a governess. Millie counts her
dining with us every night a tremendous
grievance.

Then of course Miss Con does insist upon


having schoolroom matters in her own hands. I
don't see how she could manage, if she didn't.
Millie has no reasonable ground for complaint.
Miss Con is always kind and polite to her, and
tries to meet her fancies: but Millie does dearly
love to rule the roost; and of course she can't
be allowed. She is always stirring up mud;
wanting to come into the schoolroom for music,
just when Miss Con is reading aloud or giving a
class lesson; and fidgeting and grumbling over
her "rights," till things are unbearable. Maggie
always takes Millie's part; and I only wonder
Miss Con stays on at all. I do believe it is just
for Mother's sake.

It's no earthly use my saying anything to


Maggie. She is so cockered up with having to
manage the house, that she won't stand a
word. If it wasn't that Rouse and the other
servants know exactly what to do, I am sure I
can't think what we should come to. It's the
merest chance whether Maggie remembers to
give her orders in time. She forgets to order
dinner about twice a week: but happily it comes
up just the same. And Millie just twists Maggie
round her little finger. The two have endless
gossips every night in Millie's room.

I can't tell you how wise Miss Con is with


Elfie. She does not think the Elf at all strong,
and she is careful not to let her do too much,
and to make her have plenty of rest. But all the
time there is no sort of fussing or coddling: and
she never encourages self-indulgence. She
seems to brace up Elfie, without saying much
about it: and I never saw Elfie trying so hard
not to give way to nervous fads. Somehow Miss
Con has a way of making a pleasant duty of a
thing, where other people only give one a
scolding.

I do wish you knew her, Nellie, for I think you


would understand what she is. It isn't often that
Mother's favourites are mine. But Miss Con is so
unlike the common run of people, so earnest
and good and so clever. She seems to have
read and heard and thought over everything.
And she helps me as nobody else ever did, in
other ways—you know what I mean. Her
religion is so real; not mere talk. She makes
one feel that life may be made really worth
living, and that one need not just fritter it away
in girlish nothings—like so many. I think I know
better now what "living to God" really is than I
ever did before. I mean I know what it is,
seeing it in Miss Con. But of course all this is
only for yourself, and for nobody else. You know
how I hate things being passed round and
talked over. If I did not feel perfectly sure of
you, I would not say a word.

You will know whether you can manage to


write anything to Maggie, which might make
her behave more sensibly. I'm not at all sure
that you can, and quoting me would be no good
at all. But anyhow it is a comfort to speak out
for once.

I don't send messages to Mother, as this is


only for you, and the others don't know me to
be writing. I told Gladys I had one or two things
to say which you ought to know, though Mother
must not: and she is safe not to talk.—Your
affectionate sister—

THYRZA.

FROM NELLIE TO MAGGIE.

April 29.

MY DEAREST MAGGIE,—I am going to enclose


a note to you in one to Gladys, as we arranged
to do sometimes. If it goes in the usual way, I
know how difficult it is for you not to show it all
round. Father may see this, by all means: but
please do not read it aloud at the breakfast-
table. However, I am forgetting,—you will not
receive it then.

The dear Mother is much the same,—just so


far better on some days, that I can send
tolerably cheerful accounts. But I do not see
any steady improvement; such as one might
count upon for the future. I suppose we ought
hardly to expect it yet.

I am always thinking about you, darling, and


about all the difficulties that you must have to
contend with. Managing a big household,
without any practice beforehand, is no light
matter. I should find difficulties enough in your
place: and yet I have had some little training
now and then, when Mother has been away
from home.

Your private half-sheet reached me safely,


though I have not been able to answer it till
now. Lately Mother has seemed scarcely able to
bear me out of her sight; and if I am writing,
she wants to know who it is to and what I have
said. And just now, too, she likes me to sleep
with her: so for days I have had scarcely a
moment alone.

But I do feel very sorry for all the little rubs


and worries you speak of. It is so likely that
things should be perplexing sometimes, with no
real head to be appealed to. For you would not
like, any more than I should, to be always
bothering Father. And though I know you are
doing your very best, yet of course you are
young, darling, and only just out of the
schoolroom, and you can't have full authority all
in a moment over the rest.

Mother's idea has been all along that Miss


Conway would act in many ways as a kind of
temporary head. I don't mean in ordering
dinner, and so on: but in everything connected
with you girls. I know it isn't very easy to make
things fit in: but, perhaps, the more you can
appeal to Miss Conway the better. And I think it
ought to be quite clear that Miss Conway has
the entire arrangement and management of
everything in the schoolroom; and that Millie's
plans must yield to hers.

You see, poor Millie has a rather sensitive


temper, and she is a little apt to imagine slights.
Kind Miss Jackson gave in to her too easily,
more than was right. I am afraid Millie has been
spoilt by her: and we cannot expect quite the
same from Miss Conway. I should be very sorry
to think that poor Millie was really unhappy: but
I wouldn't, if I were you, help in the nursing of
all her small grievances.

I shall be delighted to hear that your book is


successful, and that you have fifteen pounds of
your own. Writing books is not at all in my line,
for I am a very humdrum sort of individual; but
it seems quite a nice new amusement for you. I
don't think Gladys would be jealous, darling
Maggie. Why should she? There is room enough
in the world for books by you both. Perhaps she
was a little shy about giving too decided an
opinion.
Mother wants me, and I must stop.—Ever
your loving sister, NELLIE.

FROM MISS CONWAY TO MRS. ROMILLY.

May 1.

MY DEAR MRS. ROMILLY,—I have not hitherto


asked leave to write to you, knowing how you
need complete rest. But Maggie says that you
are expecting and wishing for a few lines.

Some day, when we meet again, I shall have


much to say to you about my first impressions
of all your girls: though I must not trouble you
now with lengthy outpourings. On the whole, I
think I gained a tolerably fair notion of most of
them from your previous descriptions. Only I
expected perhaps that Maggie would be rather
more like yourself.

Thyrza is very hard at work over her various


studies: and I am struck with her force and
energy. She will never turn into a limp pretty
young drawing-room lady, with no ideas in life
beyond the last novel or the latest fashion. But
I do think there are grand possibilities in
Thyrza. There is abundance of steam, ready to
be utilised. A few angularities now do not mean
much.
At present Nona's energies are expended
more upon tennis than upon literature. She
delights, as you know, in any sort of "fun," and
keeps us all with her high spirits; and she takes
life easily. That makes one remark more the
contrast of your little sensitive brave-spirited
Elfie. There is no taking anything easily in Elfie's
case; but I think I never saw a girl of sixteen
make so hard and resolute a fight not to be
mastered. You will, I know, be glad to hear this:
Nona seems to be all bright sunshine without
shadow, while in Elfie sunshine and shade
alternate sharply. She is a dear little creature,
and intensely conscientious.

You may be interested and amused to have


these passing ideas of mine. I could, of course,
say much more, if I did not fear to tire you. We
work very steadily at lessons, and take long
country rambles, sometimes all together,
sometimes in detachments.

How you will enjoy a few days at beautiful


Heidelberg! I hope your time in Germany will be
as pleasant as your time in Italy has been.

You will understand that I do not expect or


wish for any answer. I hear of you constantly.
Only try to get well, my dear Mrs. Romilly, as
soon as possible,—as soon as it is God's will.
Then we may all hope for the joy of welcoming
you home.

Believe me still, your affectionate friend—

You might also like