Android Programming The Big Nerd Ranch Guide, 3rd Edition
Lambda expressions 397 Lambda expressions You can write short callbacks directly in your layout file by using lambda expressions ...
Chapter 20 Data Binding and MVVM 398 public class BeatBoxBindingAdapter { @BindingAdapter("app:soundName") public static void b ...
399 21. Unit Testing and Audio Playback One reason MVVM architecture is so appealing is that it makes a critical programming pra ...
Chapter 21 Unit Testing and Audio Playback 400 Lollipop introduced a new way of creating a SoundPool using a SoundPool.Builder. ...
Loading Sounds 401 Now to load your sounds. Add a load(Sound) method to BeatBox to load a Sound into your SoundPool. Listing 21. ...
Chapter 21 Unit Testing and Audio Playback 402 Playing Sounds BeatBox also needs to be able to play sounds. Add the play(Sound) ...
Creating a Test Class 403 Select the Dependencies tab at the top of the screen, click the + button at the bottom of the dialog, ...
Chapter 21 Unit Testing and Audio Playback 404 navigate to a test class associated with the class you are looking at. If there ...
Setting Up Your Test 405 Figure 21.4 Selecting a destination directory Setting Up Your Test Now to build out your SoundViewMode ...
Chapter 21 Unit Testing and Audio Playback 406 If you do that in a unit test, though, you create a problem: If BeatBox is broke ...
Writing Tests 407 Writing Tests Now that your setUp() method is written, you are ready to write your tests. A test is a method i ...
Chapter 21 Unit Testing and Audio Playback 408 on SoundViewModel called onButtonClicked() that calls BeatBox.play(Sound). Write ...
Testing object interactions 409 The verify(Object) uses a fluent interface, much like the AlertDialog.Builder class you used ear ...
Chapter 21 Unit Testing and Audio Playback 410 Rerun your test. This time you should see green, indicating that all your tests ...
Data Binding Callbacks 411 Data Binding Callbacks One last step remains to get your buttons working: You need to hook up onButto ...
Chapter 21 Unit Testing and Audio Playback 412 Unloading Sounds The app works, but to be a good citizen you should clean up you ...
Rotation and Object Continuity 413 Rotation and Object Continuity Now you are a good citizen, which is nice. Unfortunately, your ...
Chapter 21 Unit Testing and Audio Playback 414 Retaining a fragment Fortunately, fragments have a feature that you can use to k ...
Rotation and retained fragments 415 Figure 21.9 Default rotation with a UI fragment On the other hand, if retainInstance is tru ...
Chapter 21 Unit Testing and Audio Playback 416 A retained fragment is not destroyed, but it is detached from the dying activity ...
«
17
18
19
20
21
22
23
24
25
26
»
Free download pdf