/** 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 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; } } }
@Before public void setup() { mListener = mock(TransformGestureDetector.Listener.class); mMultiPointerGestureDetector = mock(MultiPointerGestureDetector.class); when(mMultiPointerGestureDetector.getPointerCount()).thenReturn(0); when(mMultiPointerGestureDetector.getStartX()).thenReturn(new float[] {100f, 200f}); when(mMultiPointerGestureDetector.getStartY()).thenReturn(new float[] {500f, 600f}); when(mMultiPointerGestureDetector.getCurrentX()).thenReturn(new float[] {10f, 20f}); when(mMultiPointerGestureDetector.getCurrentY()).thenReturn(new float[] {50f, 40f}); mGestureDetector = new TransformGestureDetector(mMultiPointerGestureDetector); mGestureDetector.setListener(mListener); }
/** Gets the X component of the translation */ public float getTranslationX() { return calcAverage(mDetector.getCurrentX(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }
/** 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 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; } } }
/** Gets the X component of the translation */ public float getTranslationX() { return calcAverage(mDetector.getCurrentX(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }