private void play() { Random random = new Random(); if (view.isReady()) { float maxScale = view.getMaxScale(); float minScale = view.getMinScale(); float scale = (random.nextFloat() * (maxScale - minScale)) + minScale; PointF center = new PointF(random.nextInt(view.getSWidth()), random.nextInt(view.getSHeight())); view.setPin(center); AnimationBuilder animationBuilder = view.animateScaleAndCenter(scale, center); if (getPage() == 3) { animationBuilder.withDuration(2000).withEasing(EASE_OUT_QUAD).withInterruptible(false).start(); } else { animationBuilder.withDuration(750).start(); } } }
/** * Double tap zoom handler triggered from gesture detector or on touch, depending on whether * quick scale is enabled. */ private void doubleTapZoom(PointF sCenter, PointF vFocus) { if (!panEnabled) { if (sRequestedCenter != null) { // With a center specified from code, zoom around that point. sCenter.x = sRequestedCenter.x; sCenter.y = sRequestedCenter.y; } else { // With no requested center, scale around the image center. sCenter.x = sWidth()/2; sCenter.y = sHeight()/2; } } float doubleTapZoomScale = Math.min(maxScale, SubsamplingScaleImageView.this.doubleTapZoomScale); boolean zoomIn = (scale <= doubleTapZoomScale * 0.9) || scale == minScale; float targetScale = zoomIn ? doubleTapZoomScale : minScale(); if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) { setScaleAndCenter(targetScale, sCenter); } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn || !panEnabled) { new AnimationBuilder(targetScale, sCenter).withInterruptible(false).withDuration(doubleTapZoomDuration).withOrigin(ORIGIN_DOUBLE_TAP_ZOOM).start(); } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) { new AnimationBuilder(targetScale, sCenter, vFocus).withInterruptible(false).withDuration(doubleTapZoomDuration).withOrigin(ORIGIN_DOUBLE_TAP_ZOOM).start(); } invalidate(); }
@Override public boolean onDoubleTap(MotionEvent event) { if (!isReady()) { return true; } float scale; float screenWidth = DisplayUtils.getScreenWidth(getContext()); if (getSWidth() >= getSHeight()) { if (getSWidth() >= screenWidth) { scale = getMinScale(); } else { scale = screenWidth / (float) getSWidth(); } } else { scale = screenWidth / (float) getSWidth(); } animateScaleAndCenter(!isScaling() ? scale : getMinScale(), new PointF(event.getX(), event.getY())) .withDuration(AnimUtils.DURATION) .withEasing(SubsamplingScaleImageView.EASE_OUT_QUAD) .withInterruptible(false) .start(); return true; } };
/** * Double tap zoom handler triggered from gesture detector or on touch, depending on whether * quick scale is enabled. */ private void doubleTapZoom(PointF sCenter, PointF vFocus) { if (!panEnabled) { if (sRequestedCenter != null) { // With a center specified from code, zoom around that point. sCenter.x = sRequestedCenter.x; sCenter.y = sRequestedCenter.y; } else { // With no requested center, scale around the image center. sCenter.x = sWidth()/2; sCenter.y = sHeight()/2; } } float doubleTapZoomScale = Math.min(maxScale, SubsamplingScaleImageView.this.doubleTapZoomScale); boolean zoomIn = scale <= doubleTapZoomScale * 0.9; float targetScale = zoomIn ? doubleTapZoomScale : minScale(); if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) { setScaleAndCenter(targetScale, sCenter); } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn || !panEnabled) { new AnimationBuilder(targetScale, sCenter).withInterruptible(false).withDuration(doubleTapZoomDuration).withOrigin(ORIGIN_DOUBLE_TAP_ZOOM).start(); } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) { new AnimationBuilder(targetScale, sCenter, vFocus).withInterruptible(false).withDuration(doubleTapZoomDuration).withOrigin(ORIGIN_DOUBLE_TAP_ZOOM).start(); } invalidate(); }
/** * Set if the ImageView should zoom in and out according to the current cropRect **/ private void autoZoom(boolean animate) { //auto-zoom float scale = getNewScale(); PointF center = getCenterOfCropRect(); if (animate) { animateScaleAndCenter(scale, center) .withDuration(300) .withInterruptible(false) .start(); } else { setScaleAndCenter(scale, center); } }