Anonymous Inner Class That Implements Interface SensorEventListener to Process Accelerometer Events

Figure 7.16 overrides SensorEventListener method onSensorChanged (lines 100–125) to process accelerometer events. If the user moves the device, this method determines whether the movement was enough to be considered a shake. If so, line 123 calls method confirmErase (Fig. 7.17) to display an EraseImageDialogFragment (Section 7.9) and confirm whether the user really wants to erase the image. Interface SensorEventListener also contains method onAccuracyChanged (lines 128–131)—we don’t use this method in this app, so we provide an empty body because the method is required by the interface.

95      // event handler for ...

Get Android™ How to Program, Second Edition 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.