/** Factory method that creates a new instance of MultiPointerGestureDetector */ public static MultiPointerGestureDetector newInstance() { return new MultiPointerGestureDetector(); }
/** Gets the scale */ public float getScale() { if (mDetector.getPointerCount() < 2) { return 1; } else { float startDeltaX = mDetector.getStartX()[1] - mDetector.getStartX()[0]; float startDeltaY = mDetector.getStartY()[1] - mDetector.getStartY()[0]; float currentDeltaX = mDetector.getCurrentX()[1] - mDetector.getCurrentX()[0]; float currentDeltaY = mDetector.getCurrentY()[1] - mDetector.getCurrentY()[0]; float startDist = (float) Math.hypot(startDeltaX, startDeltaY); float currentDist = (float) Math.hypot(currentDeltaX, currentDeltaY); return currentDist / startDist; } }
/** Gets the number of pointers after the current gesture */ public int getNewPointerCount() { return mDetector.getNewPointerCount(); }
/** Gets the Y component of the translation */ public float getTranslationY() { return calcAverage(mDetector.getCurrentY(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartY(), mDetector.getPointerCount()); }
/** Gets the X component of the translation */ public float getTranslationX() { return calcAverage(mDetector.getCurrentX(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }
case MotionEvent.ACTION_MOVE: { updatePointersOnMove(event); if (!mGestureInProgress && mPointerCount > 0 && shouldStartGesture()) { startGesture(); case MotionEvent.ACTION_UP: { mNewPointerCount = getPressedPointerCount(event); stopGesture(); updatePointersOnTap(event); if (mPointerCount > 0 && shouldStartGesture()) { startGesture(); stopGesture(); reset(); break;
/** Gets the X coordinate of the pivot point */ public float getPivotX() { return calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }
/** Gets the Y coordinate of the pivot point */ public float getPivotY() { return calcAverage(mDetector.getStartY(), mDetector.getPointerCount()); }
/** Gets the number of pointers in the current gesture */ public int getPointerCount() { return mDetector.getPointerCount(); }
/** Gets whether there is a gesture in progress */ public boolean isGestureInProgress() { return mDetector.isGestureInProgress(); }
private void updatePointersOnTap(MotionEvent event) { mPointerCount = 0; for (int i = 0; i < MAX_POINTERS; i++) { int index = getPressedPointerIndex(event, i); if (index == -1) { mId[i] = MotionEvent.INVALID_POINTER_ID; } else { mId[i] = event.getPointerId(index); mCurrentX[i] = mStartX[i] = event.getX(index); mCurrentY[i] = mStartY[i] = event.getY(index); mPointerCount++; } } }
case MotionEvent.ACTION_MOVE: { updatePointersOnMove(event); if (!mGestureInProgress && mPointerCount > 0 && shouldStartGesture()) { startGesture(); case MotionEvent.ACTION_UP: { mNewPointerCount = getPressedPointerCount(event); stopGesture(); updatePointersOnTap(event); if (mPointerCount > 0 && shouldStartGesture()) { startGesture(); stopGesture(); reset(); break;
/** Gets the X component of the translation */ public float getTranslationX() { return calcAverage(mDetector.getCurrentX(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }
/** Gets the Y component of the translation */ public float getTranslationY() { return calcAverage(mDetector.getCurrentY(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartY(), mDetector.getPointerCount()); }
/** Gets the X coordinate of the pivot point */ public float getPivotX() { return calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }
/** Gets the Y coordinate of the pivot point */ public float getPivotY() { return calcAverage(mDetector.getStartY(), mDetector.getPointerCount()); }
/** Gets the number of pointers in the current gesture */ public int getPointerCount() { return mDetector.getPointerCount(); }
/** Gets whether there is a gesture in progress */ public boolean isGestureInProgress() { return mDetector.isGestureInProgress(); }
private void updatePointersOnTap(MotionEvent event) { mPointerCount = 0; for (int i = 0; i < MAX_POINTERS; i++) { int index = getPressedPointerIndex(event, i); if (index == -1) { mId[i] = MotionEvent.INVALID_POINTER_ID; } else { mId[i] = event.getPointerId(index); mCurrentX[i] = mStartX[i] = event.getX(index); mCurrentY[i] = mStartY[i] = event.getY(index); mPointerCount++; } } }
/** Gets the rotation in radians */ public float getRotation() { if (mDetector.getPointerCount() < 2) { return 0; } else { float startDeltaX = mDetector.getStartX()[1] - mDetector.getStartX()[0]; float startDeltaY = mDetector.getStartY()[1] - mDetector.getStartY()[0]; float currentDeltaX = mDetector.getCurrentX()[1] - mDetector.getCurrentX()[0]; float currentDeltaY = mDetector.getCurrentY()[1] - mDetector.getCurrentY()[0]; float startAngle = (float) Math.atan2(startDeltaY, startDeltaX); float currentAngle = (float) Math.atan2(currentDeltaY, currentDeltaX); return currentAngle - startAngle; } } }