Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When doubleTap is enabled, make an animated zoom-in on double-tapping. #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import android.graphics.PointF;
import android.view.animation.DecelerateInterpolator;

import com.joanzapata.pdfview.PDFView;

/**
* @author Joan Zapata
* <p/>
Expand Down Expand Up @@ -68,13 +66,13 @@ public void startYAnimation(float yFrom, float yTo) {
animation.start();
}

public void startZoomAnimation(float zoomFrom, float zoomTo) {
public void startZoomAnimation(float zoomFrom, float zoomTo, PointF centerPoint) {
if (animation != null) {
animation.cancel();
}
animation = ValueAnimator.ofFloat(zoomFrom, zoomTo);
animation.setInterpolator(new DecelerateInterpolator());
ZoomAnimation zoomAnim = new ZoomAnimation();
ZoomAnimation zoomAnim = new ZoomAnimation(centerPoint);
animation.addUpdateListener(zoomAnim);
animation.addListener(zoomAnim);
animation.setDuration(400);
Expand Down Expand Up @@ -110,10 +108,16 @@ public void onAnimationUpdate(ValueAnimator animation) {

class ZoomAnimation implements AnimatorUpdateListener, AnimatorListener {

private final PointF centerPoint;

public ZoomAnimation(PointF centerPoint) {
this.centerPoint = centerPoint;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
float zoom = (Float) animation.getAnimatedValue();
pdfView.zoomCenteredTo(zoom, new PointF(pdfView.getWidth() / 2, pdfView.getHeight() / 2));
pdfView.zoomCenteredTo(zoom, centerPoint);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
package com.joanzapata.pdfview;

import android.graphics.PointF;
import com.joanzapata.pdfview.PDFView;

import com.joanzapata.pdfview.util.Constants;
import com.joanzapata.pdfview.util.DragPinchListener;
import com.joanzapata.pdfview.util.DragPinchListener.OnDoubleTapListener;
import com.joanzapata.pdfview.util.DragPinchListener.OnDragListener;
import com.joanzapata.pdfview.util.DragPinchListener.OnPinchListener;

import static com.joanzapata.pdfview.util.Constants.Pinch.*;
import static com.joanzapata.pdfview.util.Constants.Pinch.MAXIMUM_ZOOM;
import static com.joanzapata.pdfview.util.Constants.Pinch.MINIMUM_ZOOM;
import static com.joanzapata.pdfview.util.Constants.Pinch.QUICK_MOVE_THRESHOLD_DISTANCE;
import static com.joanzapata.pdfview.util.Constants.Pinch.QUICK_MOVE_THRESHOLD_TIME;

/**
* @author Joan Zapata
Expand Down Expand Up @@ -136,6 +140,8 @@ public void setSwipeEnabled(boolean isSwipeEnabled) {
public void onDoubleTap(float x, float y) {
if (isZooming()) {
pdfView.resetZoomWithAnimation();
} else {
pdfView.zoomWithAnimation(Constants.Pinch.DOUBLECLICK_ZOOM, new PointF(x, y));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,13 @@ public void resetZoom() {
zoomTo(1);
}

public void zoomWithAnimation(float toZoomLevel, PointF centerPoint) {
animationManager.startZoomAnimation(zoom, toZoomLevel, centerPoint);
}

public void resetZoomWithAnimation() {
animationManager.startZoomAnimation(zoom, 1f);
PointF centerPoint = new PointF(getWidth() / 2, getHeight() / 2);
animationManager.startZoomAnimation(zoom, 1f, centerPoint);
}

/** Use an asset file as the pdf source */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public interface Pinch {

static final float MINIMUM_ZOOM = 1;

static final float DOUBLECLICK_ZOOM = 2.5f;

/**
* A move must be quicker than this duration and longer than
* this distance to be considered as a quick move
Expand Down