Erase a Palette with a Shake
Shaking a device can be used as a deliberate gesture for controlling UI elements. On smart phones, it is typically assigned to the Undo command so that a shake can reverse or clear a prior action. Let’s take a look at how this gesture can be detected and used by our color mixer.
What is a shake? When we move the device abruptly side to side, forward or backward, up or down, the idea is that our sketch triggers a “shake” event. For the color mixer, we want to use the shake for clearing out all color swatches. The shake needs to be detected no matter how we hold the device and independent of what’s up or down. You might already anticipate the issue: we know well that the accelerometer is the ideal sensor for us to ...
Get Rapid Android Development 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.