5.7 MainActivityFragment Class

MainActivityFragment (Sections 5.7.15.7.10) displays the DoodleView (Section 5.8), manages the menu options displayed on the app bar and in the options menu, and manages the sensor event handling for the app’s shake-to-erase feature.

5.7.1 package Statement, import Statements and Fields

Section 5.3 discussed the key new classes and interfaces used by MainActivityFragment. We’ve highlighted these classes and interfaces in Fig. 5.20. DoodleView variable doodleView (line 24) represents the drawing area. Accelerometer information is delivered to the app as float values. The float variables in lines 25–27 are used to calculate changes in the device’s acceleration to determine when a shake event occurs (so we can ask ...

Get Android How to Program, 3/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.