/** * Calculates the zoom transformation based on the current gesture. * * @param outTransform the matrix to store the result to * @param limitTypes whether to limit translation and/or scale. * @return whether or not the transform has been corrected due to limitation */ protected boolean calculateGestureTransform( Matrix outTransform, @LimitFlag int limitTypes) { TransformGestureDetector detector = mGestureDetector; boolean transformCorrected = false; outTransform.set(mPreviousTransform); if (mIsRotationEnabled) { float angle = detector.getRotation() * (float) (180 / Math.PI); outTransform.postRotate(angle, detector.getPivotX(), detector.getPivotY()); } if (mIsScaleEnabled) { float scale = detector.getScale(); outTransform.postScale(scale, scale, detector.getPivotX(), detector.getPivotY()); } transformCorrected |= limitScale(outTransform, detector.getPivotX(), detector.getPivotY(), limitTypes); if (mIsTranslationEnabled) { outTransform.postTranslate(detector.getTranslationX(), detector.getTranslationY()); } transformCorrected |= limitTranslation(outTransform, limitTypes); return transformCorrected; }
@Override public void onGestureUpdate(TransformGestureDetector detector) { mActiveTransform.set(mPreviousTransform); if (mIsRotationEnabled) { float angle = detector.getRotation() * (float) (180 / Math.PI); mActiveTransform.postRotate(angle, detector.getPivotX(), detector.getPivotY()); } if (mIsScaleEnabled) { float scale = detector.getScale(); mActiveTransform.postScale(scale, scale, detector.getPivotX(), detector.getPivotY()); } limitScale(detector.getPivotX(), detector.getPivotY()); if (mIsTranslationEnabled) { mActiveTransform.postTranslate(detector.getTranslationX(), detector.getTranslationY()); } limitTranslation(); if (mListener != null) { mListener.onTransformChanged(mActiveTransform); } }
@Override public void onGestureBegin(TransformGestureDetector detector) { FLog.v(TAG, "onGestureBegin"); mPreviousTransform.set(mActiveTransform); // We only received a touch down event so far, and so we don't know yet in which direction a // future move event will follow. Therefore, if we can't scroll in all directions, we have to // assume the worst case where the user tries to scroll out of edge, which would cause // transformation to be corrected. mWasTransformCorrected = !canScrollInAllDirection(); }
@Override public void onGestureUpdate(TransformGestureDetector detector) { FLog.v(TAG, "onGestureUpdate"); boolean transformCorrected = calculateGestureTransform(mActiveTransform, LIMIT_ALL); onTransformChanged(); if (transformCorrected) { mGestureDetector.restartGesture(); } // A transformation happened, but was it without correction? mWasTransformCorrected = transformCorrected; }
@Override public void onGestureUpdate(TransformGestureDetector detector) { FLog.v(getLogTag(), "onGestureUpdate %s", isAnimating() ? "(ignored)" : ""); if (isAnimating()) { return; } super.onGestureUpdate(detector); }
public static AnimatedZoomableControllerSupport newInstance() { return new AnimatedZoomableControllerSupport(TransformGestureDetector.newInstance()); }
public AnimatedZoomableControllerSupport(TransformGestureDetector transformGestureDetector) { super(transformGestureDetector); mValueAnimator = ValueAnimator.ofFloat(0, 1); mValueAnimator.setInterpolator(new DecelerateInterpolator()); }
public static DefaultZoomableController newInstance() { return new DefaultZoomableController(TransformGestureDetector.newInstance()); }
public DefaultZoomableController(TransformGestureDetector gestureDetector) { mGestureDetector = gestureDetector; mGestureDetector.setListener(this); }
/** Gets the gesture detector. */ protected TransformGestureDetector getDetector() { return mGestureDetector; }
@Override public void onGestureEnd(TransformGestureDetector detector) { FLog.v(TAG, "onGestureEnd"); }
public AbstractAnimatedZoomableController(TransformGestureDetector transformGestureDetector) { super(transformGestureDetector); }
@Override public void onGestureBegin(TransformGestureDetector detector) { FLog.v(getLogTag(), "onGestureBegin"); stopAnimation(); super.onGestureBegin(detector); }
public static AnimatedZoomableController newInstance() { return new AnimatedZoomableController(TransformGestureDetector.newInstance()); }
@SuppressLint("NewApi") public AnimatedZoomableController(TransformGestureDetector transformGestureDetector) { super(transformGestureDetector); mValueAnimator = ValueAnimator.ofFloat(0, 1); mValueAnimator.setInterpolator(new DecelerateInterpolator()); }
@Override public void onGestureBegin(TransformGestureDetector detector) { }
@Override public void onGestureEnd(TransformGestureDetector detector) { mPreviousTransform.set(mActiveTransform); }