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
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
com
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
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?
CHAPTER XII.
AND MAGGIE'S EFFORTS.
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.
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.
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.
CHAPTER XIII.
LETTERS—VARIOUS.
April 22.
THYRZA.
April 29.
May 1.