Ejemplo n.º 1
0
  @Override
  protected void handleInProgressEvent(int actionCode, MotionEvent event) {
    switch (actionCode) {
      case MotionEvent.ACTION_POINTER_UP:
        // Gesture ended but
        updateStateByEvent(event);

        if (!mSloppyGesture) {
          mListener.onRotateEnd(this);
        }

        resetState();
        break;

      case MotionEvent.ACTION_CANCEL:
        if (!mSloppyGesture) {
          mListener.onRotateEnd(this);
        }

        resetState();
        break;

      case MotionEvent.ACTION_MOVE:
        updateStateByEvent(event);

        // Only accept the event if our relative pressure is within
        // a certain limit. This can help filter shaky data as a
        // finger is lifted.
        if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) {
          final boolean updatePrevious = mListener.onRotate(this);
          if (updatePrevious) {
            mPrevEvent.recycle();
            mPrevEvent = MotionEvent.obtain(event);
          }
        }
        break;
    }
  }
Ejemplo n.º 2
0
  @Override
  protected void handleStartProgressEvent(int actionCode, MotionEvent event) {
    switch (actionCode) {
      case MotionEvent.ACTION_POINTER_DOWN:
        // At least the second finger is on screen now

        resetState(); // In case we missed an UP/CANCEL event
        mPrevEvent = MotionEvent.obtain(event);
        mTimeDelta = 0;

        updateStateByEvent(event);

        // See if we have a sloppy gesture
        mSloppyGesture = isSloppyGesture(event);
        if (!mSloppyGesture) {
          // No, start gesture now
          mGestureInProgress = mListener.onRotateBegin(this);
        }
        break;

      case MotionEvent.ACTION_MOVE:
        if (!mSloppyGesture) {
          break;
        }

        // See if we still have a sloppy gesture
        mSloppyGesture = isSloppyGesture(event);
        if (!mSloppyGesture) {
          // No, start normal gesture now
          mGestureInProgress = mListener.onRotateBegin(this);
        }

        break;

      case MotionEvent.ACTION_POINTER_UP:
        if (!mSloppyGesture) {
          break;
        }

        break;
    }
  }