Home > Devices > Fire Phone

MotionGesture Sample App


The MotionGesture sample is a sample app that illustrates obtaining gesture events and using them in your app. The sample app consists of a single Activity, DropDownMenuActivity. This Activity displays a drop-down menu in response to a tilt gesture from the device user. In response to a second tilt gesture, the Activity hides the drop-down menu. The sequence of operations illustrates the program flow for receiving gesture events.

When the Activity is first created, it obtains a GestureManager object.

mGestureManager = GestureManager.createInstance(thisActivity);

Every time the Activity is launched, it obtains a TiltGesture object representing the type of gesture the Activity intends to listen for.

mTiltGesture = Gesture.getGestureFromId(Gesture.TILT);

The Activity uses this TiltGesture object to register as a listener for tilt events, and it specifies that the direction of the tilt should be forward.

public void onGestureEvent(GestureEvent event) {
    Log.d(TAG, "Gesture Received: " + event.toString());

    // Move drawer down if it is not already down
    if (!mDrawerDown) {
        final TranslateAnimation translate = new TranslateAnimation(0, 0,
                                                                    -mDropDownDrawer.getHeight(), 0);
        // Make sure the animated image persists.

        mDrawerDown = true;

    // Move drawer up if it is not already up
    } else {
            final TranslateAnimation translate = new TranslateAnimation(0, 0, 0,

            mDrawerDown = false;

When the Activity is paused or shutdown, it unregisters the listener.

public void onPause() {
    // Release the listener
    if (mGestureManager != null) {