About the Authors |
|
xxiii | |
About the Technical Reviewer |
|
xxv | |
Acknowledgments |
|
xxvii | |
Introduction |
|
xxix | |
Chapter 1 Layouts and Views |
|
1 | (84) |
|
1-1 Styling Common Components |
|
|
1 | (9) |
|
|
1 | (1) |
|
|
1 | (1) |
|
|
1 | (9) |
|
1-2 Toggling System UI Elements |
|
|
10 | (4) |
|
|
10 | (1) |
|
|
11 | (1) |
|
|
11 | (3) |
|
1-3 Creating and Displaying Views |
|
|
14 | (6) |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
14 | (6) |
|
|
20 | (6) |
|
|
20 | (1) |
|
|
20 | (1) |
|
|
21 | (5) |
|
1-5 Animating Layout Changes |
|
|
26 | (3) |
|
|
26 | (1) |
|
|
26 | (1) |
|
|
26 | (3) |
|
1-6 Implementing Situation-Specific Layouts |
|
|
29 | (9) |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
30 | (8) |
|
1-7 Placing Text over Images |
|
|
38 | (1) |
|
|
38 | (1) |
|
|
38 | (1) |
|
1-8 Making Extensible Collection Views |
|
|
39 | (12) |
|
|
39 | (1) |
|
|
39 | (1) |
|
|
40 | (11) |
|
1-9 Customizing Empty Lists |
|
|
51 | (2) |
|
|
51 | (1) |
|
|
51 | (1) |
|
|
51 | (2) |
|
1-10 Using CardView in RecyclerView |
|
|
53 | (4) |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
54 | (3) |
|
1-11 Making RecyclerView Section Headers |
|
|
57 | (3) |
|
|
57 | (1) |
|
|
58 | (1) |
|
|
58 | (2) |
|
1-12 Creating Compound Controls |
|
|
60 | (4) |
|
|
60 | (1) |
|
|
61 | (1) |
|
|
61 | (3) |
|
1-13 Customizing Transition Animations |
|
|
64 | (10) |
|
|
64 | (1) |
|
|
64 | (1) |
|
|
64 | (10) |
|
1-14 Creating View Transformations |
|
|
74 | (6) |
|
|
74 | (1) |
|
|
74 | (1) |
|
|
74 | (6) |
|
1-15 Using Android Data Bindings |
|
|
80 | (4) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
80 | (4) |
|
|
84 | (1) |
Chapter 2 User Interaction Recipes |
|
85 | (104) |
|
2-1 Leveraging the Action Bar |
|
|
85 | (8) |
|
|
85 | (1) |
|
|
85 | (1) |
|
|
86 | (7) |
|
2-2 Locking Activity Orientation |
|
|
93 | (1) |
|
|
93 | (1) |
|
|
93 | (1) |
|
|
93 | (1) |
|
2-3 Performing Dynamic Orientation Locking |
|
|
94 | (2) |
|
|
94 | (1) |
|
|
94 | (1) |
|
|
94 | (2) |
|
2-4 Manually Handling Rotation |
|
|
96 | (3) |
|
|
96 | (1) |
|
|
96 | (1) |
|
|
97 | (2) |
|
2-5 Creating Contextual Actions |
|
|
99 | (6) |
|
|
99 | (1) |
|
|
100 | (1) |
|
|
100 | (5) |
|
2-6 Displaying a User Dialog Box |
|
|
105 | (6) |
|
|
105 | (1) |
|
|
105 | (1) |
|
|
105 | (6) |
|
2-7 Customizing Menus and Actions |
|
|
111 | (5) |
|
|
111 | (1) |
|
|
111 | (1) |
|
|
111 | (5) |
|
2-8 Customizing BACK Behavior |
|
|
116 | (4) |
|
|
116 | (1) |
|
|
116 | (1) |
|
|
117 | (3) |
|
2-9 Emulating the HOME Button |
|
|
120 | (1) |
|
|
120 | (1) |
|
|
120 | (1) |
|
|
120 | (1) |
|
2-10 Monitoring TextView Changes |
|
|
120 | (3) |
|
|
120 | (1) |
|
|
121 | (1) |
|
|
121 | (2) |
|
2-11 Customizing Keyboard Actions |
|
|
123 | (3) |
|
|
123 | (1) |
|
|
124 | (1) |
|
|
124 | (2) |
|
2-12 Dismissing the Soft Keyboard |
|
|
126 | (1) |
|
|
126 | (1) |
|
|
127 | (1) |
|
|
127 | (1) |
|
2-13 Handling Complex Touch Events |
|
|
127 | (17) |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
128 | (16) |
|
2-14 Forwarding Touch Events |
|
|
144 | (5) |
|
|
144 | (1) |
|
|
144 | (1) |
|
|
145 | (4) |
|
2-15 Blocking Touch Thieves |
|
|
149 | (4) |
|
|
149 | (1) |
|
|
150 | (1) |
|
|
150 | (3) |
|
2-16 Making Drag-and-Drop Views |
|
|
153 | (8) |
|
|
153 | (1) |
|
|
153 | (1) |
|
|
154 | (7) |
|
2-17 Using the Material Design Navigation Drawer |
|
|
161 | (8) |
|
|
161 | (1) |
|
|
161 | (1) |
|
|
161 | (8) |
|
2-18 Swiping Between Views |
|
|
169 | (11) |
|
|
169 | (1) |
|
|
169 | (1) |
|
|
170 | (10) |
|
2-19 Navigating with Tabs |
|
|
180 | (3) |
|
|
180 | (1) |
|
|
180 | (1) |
|
|
180 | (3) |
|
2-20 Actionable User Feedback Using Snackbar |
|
|
183 | (5) |
|
|
183 | (1) |
|
|
183 | (1) |
|
|
184 | (4) |
|
|
188 | (1) |
Chapter 3 Communications and Networking |
|
189 | (70) |
|
3-1 Displaying Web Information |
|
|
189 | (5) |
|
|
189 | (1) |
|
|
189 | (1) |
|
|
189 | (5) |
|
3-2 Intercepting WebView Events |
|
|
194 | (2) |
|
|
194 | (1) |
|
|
194 | (1) |
|
|
195 | (1) |
|
3-3 Accessing WebView with JavaScript |
|
|
196 | (3) |
|
|
196 | (1) |
|
|
196 | (1) |
|
|
196 | (3) |
|
3-4 Displaying Online Images |
|
|
199 | (2) |
|
|
199 | (1) |
|
|
199 | (1) |
|
|
199 | (2) |
|
3-5 Downloading Completely in the Background |
|
|
201 | (4) |
|
|
201 | (1) |
|
|
201 | (1) |
|
|
201 | (4) |
|
|
205 | (7) |
|
|
205 | (1) |
|
|
205 | (1) |
|
|
205 | (7) |
|
|
212 | (4) |
|
|
212 | (1) |
|
|
212 | (1) |
|
|
212 | (4) |
|
|
216 | (4) |
|
|
216 | (1) |
|
|
216 | (1) |
|
|
216 | (4) |
|
|
220 | (3) |
|
|
220 | (1) |
|
|
220 | (1) |
|
|
220 | (3) |
|
3-10 Sending an SMS Message |
|
|
223 | (3) |
|
|
223 | (1) |
|
|
223 | (1) |
|
|
224 | (2) |
|
3-11 Communicating over Bluetooth |
|
|
226 | (9) |
|
|
226 | (1) |
|
|
226 | (1) |
|
|
226 | (9) |
|
3-12 Querying Network Reachability |
|
|
235 | (2) |
|
|
235 | (1) |
|
|
235 | (1) |
|
|
235 | (2) |
|
3-13 Transferring Data with NFC |
|
|
237 | (8) |
|
|
237 | (1) |
|
|
238 | (1) |
|
|
238 | (7) |
|
|
245 | (10) |
|
|
245 | (1) |
|
|
246 | (1) |
|
|
246 | (9) |
|
3-15 Scanning for Bluetooth Low Energy beacons |
|
|
255 | (3) |
|
|
255 | (1) |
|
|
255 | (1) |
|
|
256 | (2) |
|
|
258 | (1) |
Chapter 4 Interacting with Device Hardware and Media |
|
259 | (108) |
|
4-1 Integrating Device Location |
|
|
259 | (7) |
|
|
259 | (1) |
|
|
259 | (1) |
|
|
260 | (6) |
|
|
266 | (9) |
|
|
266 | (1) |
|
|
266 | (3) |
|
|
269 | (6) |
|
|
275 | (16) |
|
|
275 | (1) |
|
|
275 | (1) |
|
|
275 | (16) |
|
4-4 Monitoring Location Regions |
|
|
291 | (10) |
|
|
291 | (1) |
|
|
292 | (1) |
|
|
292 | (9) |
|
4-5 Capturing Images and Video |
|
|
301 | (6) |
|
|
301 | (1) |
|
|
301 | (1) |
|
|
301 | (6) |
|
4-6 Making a Custom Camera Overlay |
|
|
307 | (6) |
|
|
307 | (1) |
|
|
307 | (1) |
|
|
307 | (6) |
|
|
313 | (3) |
|
|
313 | (1) |
|
|
313 | (1) |
|
|
314 | (2) |
|
4-8 Capturing Custom Video |
|
|
316 | (4) |
|
|
316 | (1) |
|
|
316 | (1) |
|
|
316 | (4) |
|
4-9 Adding Speech Recognition |
|
|
320 | (3) |
|
|
320 | (1) |
|
|
320 | (1) |
|
|
321 | (2) |
|
4-10 Playing Back AudioNideo |
|
|
323 | (8) |
|
|
323 | (1) |
|
|
323 | (1) |
|
|
323 | (8) |
|
4-11 Playing Sound Effects |
|
|
331 | (3) |
|
|
331 | (1) |
|
|
331 | (1) |
|
|
332 | (2) |
|
4-12 Creating a Tilt Monitor |
|
|
334 | (4) |
|
|
334 | (1) |
|
|
334 | (1) |
|
|
334 | (4) |
|
4-13 Monitoring Compass Orientation |
|
|
338 | (4) |
|
|
338 | (1) |
|
|
338 | (1) |
|
|
339 | (3) |
|
4-14 Retrieving Metadata from Media Content |
|
|
342 | (4) |
|
|
342 | (1) |
|
|
342 | (1) |
|
|
342 | (4) |
|
4-15 Detecting User Motion |
|
|
346 | (11) |
|
|
346 | (1) |
|
|
346 | (1) |
|
|
347 | (10) |
|
4-16 Making Applications Context Aware |
|
|
357 | (5) |
|
|
357 | (1) |
|
|
357 | (5) |
|
4-17 Authenticating Users Using Fingerprint Reader |
|
|
362 | (2) |
|
|
362 | (1) |
|
|
362 | (2) |
|
4-18 Scanning QR Codes Using Vision API |
|
|
364 | (2) |
|
|
364 | (1) |
|
|
364 | (2) |
|
|
366 | (1) |
Chapter 5 Persisting Data |
|
367 | (76) |
|
5-1 Making a Preference Screen |
|
|
367 | (6) |
|
|
367 | (1) |
|
|
367 | (1) |
|
|
367 | (6) |
|
5-2 Displaying Custom Preferences |
|
|
373 | (6) |
|
|
373 | (1) |
|
|
373 | (1) |
|
|
374 | (5) |
|
5-3 Persisting Simple Data |
|
|
379 | (4) |
|
|
379 | (1) |
|
|
379 | (1) |
|
|
379 | (4) |
|
5-4 Reading and Writing Files |
|
|
383 | (8) |
|
|
383 | (1) |
|
|
383 | (1) |
|
|
384 | (7) |
|
5-5 Using Files as Resources |
|
|
391 | (2) |
|
|
391 | (1) |
|
|
391 | (1) |
|
|
391 | (2) |
|
|
393 | (5) |
|
|
393 | (1) |
|
|
393 | (1) |
|
|
393 | (5) |
|
|
398 | (2) |
|
|
398 | (1) |
|
|
398 | (1) |
|
|
399 | (1) |
|
|
400 | (4) |
|
|
400 | (1) |
|
|
400 | (1) |
|
|
400 | (4) |
|
5-9 Sharing Your Database |
|
|
404 | (8) |
|
|
404 | (1) |
|
|
405 | (1) |
|
|
405 | (7) |
|
5-10 Sharing Your SharedPreferences |
|
|
412 | (9) |
|
|
412 | (1) |
|
|
412 | (1) |
|
|
413 | (8) |
|
5-11 Sharing Your Other Data |
|
|
421 | (7) |
|
|
421 | (1) |
|
|
421 | (1) |
|
|
422 | (6) |
|
5-12 Integrating With System Documents |
|
|
428 | (14) |
|
|
428 | (1) |
|
|
428 | (1) |
|
|
429 | (13) |
|
|
442 | (1) |
Chapter 6 Interacting with the System |
|
443 | (142) |
|
6-1 Notifying from the Background |
|
|
443 | (23) |
|
|
443 | (1) |
|
|
443 | (1) |
|
|
443 | (23) |
|
6-2 Creating limed and Periodic Tasks |
|
|
466 | (2) |
|
|
466 | (1) |
|
|
466 | (1) |
|
|
466 | (2) |
|
6-3 Scheduling a Periodic Task |
|
|
468 | (8) |
|
|
468 | (1) |
|
|
468 | (1) |
|
|
469 | (7) |
|
6-4 Creating Sticky Operations |
|
|
476 | (5) |
|
|
476 | (1) |
|
|
476 | (1) |
|
|
477 | (4) |
|
6-5 Running Persistent Background Operations |
|
|
481 | (7) |
|
|
481 | (1) |
|
|
481 | (1) |
|
|
481 | (7) |
|
6-6 Launching Other Applications |
|
|
488 | (4) |
|
|
488 | (1) |
|
|
488 | (1) |
|
|
488 | (4) |
|
6-7 Launching System Applications |
|
|
492 | (4) |
|
|
492 | (1) |
|
|
492 | (1) |
|
|
492 | (4) |
|
6-8 Letting Other Applications Launch Your Application |
|
|
496 | (3) |
|
|
496 | (1) |
|
|
496 | (1) |
|
|
497 | (2) |
|
6-9 Interacting with Contacts |
|
|
499 | (8) |
|
|
499 | (1) |
|
|
499 | (1) |
|
|
499 | (8) |
|
6-10 Reading Device Media and Documents |
|
|
507 | (4) |
|
|
507 | (1) |
|
|
507 | (1) |
|
|
508 | (3) |
|
6-11 Saving Device Media and Documents |
|
|
511 | (5) |
|
|
511 | (1) |
|
|
511 | (1) |
|
|
512 | (4) |
|
6-12 Reading Messaging Data |
|
|
516 | (12) |
|
|
516 | (1) |
|
|
516 | (2) |
|
|
518 | (10) |
|
6-13 Interacting with the Calendar |
|
|
528 | (6) |
|
|
528 | (1) |
|
|
528 | (1) |
|
|
528 | (6) |
|
6-14 Logging Code Execution |
|
|
534 | (3) |
|
|
534 | (1) |
|
|
534 | (1) |
|
|
534 | (3) |
|
6-15 Creating a Background Worker |
|
|
537 | (4) |
|
|
537 | (1) |
|
|
537 | (1) |
|
|
537 | (4) |
|
6-16 Customizing the Task Stack |
|
|
541 | (8) |
|
|
541 | (1) |
|
|
541 | (1) |
|
|
542 | (7) |
|
6-17 Implementing AppWidgets |
|
|
549 | (21) |
|
|
549 | (1) |
|
|
549 | (1) |
|
|
550 | (20) |
|
6-18 Supporting Restricted Profiles |
|
|
570 | (14) |
|
|
570 | (1) |
|
|
570 | (1) |
|
|
571 | (13) |
|
|
584 | (1) |
Chapter 7 Graphics and Drawing |
|
585 | (70) |
|
7-1 Creating Drawables as Backgrounds |
|
|
585 | (8) |
|
|
585 | (1) |
|
|
585 | (1) |
|
|
586 | (7) |
|
7-2 Creating Custom State Drawables |
|
|
593 | (5) |
|
|
593 | (1) |
|
|
593 | (1) |
|
|
593 | (5) |
|
7-3 Applying Masks to Images |
|
|
598 | (11) |
|
|
598 | (1) |
|
|
598 | (1) |
|
|
599 | (10) |
|
7-4 Drawing over View Content |
|
|
609 | (16) |
|
|
609 | (1) |
|
|
609 | (1) |
|
|
610 | (15) |
|
7-5 High-Performance Drawing |
|
|
625 | (12) |
|
|
625 | (1) |
|
|
626 | (1) |
|
|
626 | (11) |
|
|
637 | (2) |
|
|
637 | (1) |
|
|
637 | (1) |
|
|
637 | (2) |
|
7-7 Tinting Drawable Elements |
|
|
639 | (5) |
|
|
639 | (1) |
|
|
639 | (1) |
|
|
639 | (5) |
|
7-8 Using Scalable Vector Assets |
|
|
644 | (9) |
|
|
644 | (1) |
|
|
644 | (1) |
|
|
645 | (8) |
|
|
653 | (2) |
Chapter 8 Working with Android NDK and RenderScript |
|
655 | (44) |
|
|
655 | (3) |
|
8-1 Adding Native Bits with JNI |
|
|
658 | (7) |
|
|
658 | (1) |
|
|
658 | (1) |
|
|
659 | (6) |
|
8-2 Building a Purely Native Activity |
|
|
665 | (9) |
|
|
665 | (1) |
|
|
665 | (1) |
|
|
666 | (8) |
|
|
674 | (2) |
|
Using the RenderScript Support Package |
|
|
675 | (1) |
|
8-3 Filtering Images with RenderScript |
|
|
676 | (5) |
|
|
676 | (1) |
|
|
676 | (1) |
|
|
676 | (5) |
|
8-4 Manipulating Images with RenderScript |
|
|
681 | (6) |
|
|
681 | (1) |
|
|
681 | (1) |
|
|
681 | (6) |
|
8-5 Faking Translucent Overlays with Blur |
|
|
687 | (10) |
|
|
687 | (1) |
|
|
687 | (1) |
|
|
688 | (9) |
|
|
697 | (2) |
Index |
|
699 | |