public boolean onTouchEvent(final MotionEvent event) {
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_MOVE:
        {
          // update pointers
          updatePointersOnMove(event);
          // start a new gesture if not already started
          if (!mGestureInProgress && mPointerCount > 0 && shouldStartGesture()) {
            startGesture();
          }
          // notify listener
          if (mGestureInProgress && mListener != null) {
            mListener.onGestureUpdate(this);
          }
          break;
        }

      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_POINTER_DOWN:
      case MotionEvent.ACTION_POINTER_UP:
      case MotionEvent.ACTION_UP:
        {
          // restart gesture whenever the number of pointers changes
          mNewPointerCount = getPressedPointerCount(event);
          stopGesture();
          updatePointersOnTap(event);
          if (mPointerCount > 0 && shouldStartGesture()) {
            startGesture();
          }
          break;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          mNewPointerCount = 0;
          stopGesture();
          reset();
          break;
        }
    }
    return true;
  }
Handles the given motion event.

@param event event to handle
@return whether or not the event was handled
samples/gestures/src/main/java/com/facebook/samples/gestures/MultiPointerGestureDetector.java