@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) { PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f)); float sCenterXEnd = ((getWidth()/2) - vTranslateEnd.x)/scale; float sCenterYEnd = ((getHeight()/2) - vTranslateEnd.y)/scale; new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD).withPanLimited(false).withOrigin(ORIGIN_FLING).start(); return true; } return super.onFling(e1, e2, velocityX, velocityY); }
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(); } } }
.animateScaleAndCenter(result, new PointF(imageWidth / 2, 0)) .withEasing(SubsamplingScaleImageView.EASE_OUT_QUAD) .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; 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; } };
private void scaleDown(final ItemActivity.Callback callback) { final SubsamplingScaleImageView imageView = itemView.findViewById(R.id.subsampling); if (imageView != null) { try { imageView.animateScale(0.0f) .withDuration(300) .withOnAnimationEventListener( new SubsamplingScaleImageView.DefaultOnAnimationEventListener() { @Override public void onComplete() { super.onComplete(); swapView(true); callback.done(); //imageView.recycle(); } }) .start(); } catch (NullPointerException e) { swapView(true); callback.done(); //imageView.recycle(); } } }
/** * 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); } }
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) { PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f)); float sCenterXEnd = ((getWidth()/2) - vTranslateEnd.x)/scale; float sCenterYEnd = ((getHeight()/2) - vTranslateEnd.y)/scale; new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD).withPanLimited(false).withOrigin(ORIGIN_FLING).start(); return true; } return super.onFling(e1, e2, velocityX, velocityY); }
/** * 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(); }