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

Add recognition double-tap and single-finger-zoom #551

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
Expand All @@ -20,6 +20,8 @@
import android.graphics.Matrix.ScaleToFit;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.v4.view.MotionEventCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -88,6 +90,7 @@ public class PhotoViewAttacher implements View.OnTouchListener,
private float mBaseRotation;

private boolean mZoomEnabled = true;
private boolean mTouchUpFired = false;
private ScaleType mScaleType = ScaleType.FIT_CENTER;

private OnGestureListener onGestureListener = new OnGestureListener() {
Expand Down Expand Up @@ -231,17 +234,30 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
@Override
public boolean onDoubleTap(MotionEvent ev) {
try {
float scale = getScale();
float x = ev.getX();
float y = ev.getY();

if (scale < getMediumScale()) {
setScale(getMediumScale(), x, y, true);
} else if (scale >= getMediumScale() && scale < getMaximumScale()) {
setScale(getMaximumScale(), x, y, true);
} else {
setScale(getMinimumScale(), x, y, true);
}
final float scale = getScale();
final float x = ev.getX();
final float y = ev.getY();

// If after 50ms touchUp fires, gesture is completed double tap
// Else gesture is single-finger-zoom, do nothing
mTouchUpFired = false;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (mTouchUpFired) {
// Double Tap Finished
if (scale < getMediumScale()) {
setScale(getMediumScale(), x, y, true);
} else if (scale >= getMediumScale() && scale < getMaximumScale()) {
setScale(getMaximumScale(), x, y, true);
} else {
setScale(getMinimumScale(), x, y, true);
}
}
}
}, 50);


} catch (ArrayIndexOutOfBoundsException e) {
// Can sometimes happen when getX() and getY() is called
}
Expand Down Expand Up @@ -362,6 +378,7 @@ public boolean onTouch(View v, MotionEvent ev) {
case MotionEvent.ACTION_UP:
// If the user has zoomed less than min scale, zoom back
// to min scale
mTouchUpFired = true;
if (getScale() < mMinScale) {
RectF rect = getDisplayRect();
if (rect != null) {
Expand Down