summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMindy Pereira <mindyp@google.com>2013-09-09 18:59:53 -0700
committerAndrew Sapperstein <asapperstein@google.com>2013-09-12 18:14:37 +0000
commitf0fac25e570ef98dd9d5df34cf8437888cd118cd (patch)
tree9d7b340f19b8f7bc04eeffd2cd9902c1838e2332
parentc538df19aef3df6c64b0b243eb868b570b9147a1 (diff)
downloadphotoviewer-f0fac25e570ef98dd9d5df34cf8437888cd118cd.tar.gz
Don't scale on double tap if there is movement before an up event
Change-Id: I60fc2025def88ac9b7b55ba52c93569f7cfd8f45
-rw-r--r--src/com/android/ex/photo/views/PhotoView.java80
1 files changed, 65 insertions, 15 deletions
diff --git a/src/com/android/ex/photo/views/PhotoView.java b/src/com/android/ex/photo/views/PhotoView.java
index 0bc704e..a2e7107 100644
--- a/src/com/android/ex/photo/views/PhotoView.java
+++ b/src/com/android/ex/photo/views/PhotoView.java
@@ -34,6 +34,7 @@ import android.view.GestureDetector.OnDoubleTapListener;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
+import android.view.ViewConfiguration;
import com.android.ex.photo.R;
import com.android.ex.photo.fragments.PhotoViewFragment.HorizontallyScrollable;
@@ -59,6 +60,12 @@ public class PhotoView extends View implements OnGestureListener,
/** The width & height of the bitmap returned by {@link #getCroppedPhoto()} */
private final static float CROPPED_SIZE = 256.0f;
+ /**
+ * Touch slop used to determine if this double tap is valid for starting a scale or should be
+ * ignored.
+ */
+ private static int sTouchSlopSquare;
+
/** If {@code true}, the static values have been initialized */
private static boolean sInitialized;
@@ -154,6 +161,19 @@ public class PhotoView extends View implements OnGestureListener,
/** Array to store a copy of the matrix values */
private float[] mValues = new float[9];
+ /**
+ * Track whether a double tap event occurred.
+ */
+ private boolean mDoubleTapOccurred;
+
+ /**
+ * X and Y coordinates for the current down event. Since mDoubleTapOccurred only contains the
+ * information that there was a double tap event, use these to get the secondary tap
+ * information to determine if a user has moved beyond touch slop.
+ */
+ private float mDownFocusX;
+ private float mDownFocusY;
+
public PhotoView(Context context) {
super(context);
initialize();
@@ -194,25 +214,50 @@ public class PhotoView extends View implements OnGestureListener,
@Override
public boolean onDoubleTap(MotionEvent e) {
- if (mDoubleTapToZoomEnabled && mTransformsEnabled) {
- if (!mDoubleTapDebounce) {
- float currentScale = getScale();
- float targetScale = currentScale * DOUBLE_TAP_SCALE_FACTOR;
-
- // Ensure the target scale is within our bounds
- targetScale = Math.max(mMinScale, targetScale);
- targetScale = Math.min(mMaxScale, targetScale);
-
- mScaleRunnable.start(currentScale, targetScale, e.getX(), e.getY());
- }
- mDoubleTapDebounce = false;
- }
- return true;
+ mDoubleTapOccurred = true;
+ return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
- return true;
+ final int action = e.getAction();
+ boolean handled = false;
+
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ mDownFocusX = e.getX();
+ mDownFocusY = e.getY();
+ break;
+ case MotionEvent.ACTION_UP:
+ if (mDoubleTapToZoomEnabled && mTransformsEnabled && mDoubleTapOccurred) {
+ if (!mDoubleTapDebounce) {
+ float currentScale = getScale();
+ float targetScale = currentScale * DOUBLE_TAP_SCALE_FACTOR;
+
+ // Ensure the target scale is within our bounds
+ targetScale = Math.max(mMinScale, targetScale);
+ targetScale = Math.min(mMaxScale, targetScale);
+
+ mScaleRunnable.start(currentScale, targetScale, e.getX(), e.getY());
+ }
+ mDoubleTapDebounce = false;
+ }
+ handled = true;
+ mDoubleTapOccurred = false;
+ break;
+ case MotionEvent.ACTION_MOVE:
+ if (mDoubleTapOccurred) {
+ final int deltaX = (int) (e.getX() - mDownFocusX);
+ final int deltaY = (int) (e.getY() - mDownFocusY);
+ int distance = (deltaX * deltaX) + (deltaY * deltaY);
+ if (distance > sTouchSlopSquare) {
+ mDoubleTapOccurred = false;
+ }
+ }
+ break;
+
+ }
+ return handled;
}
@Override
@@ -379,6 +424,7 @@ public class PhotoView extends View implements OnGestureListener,
mRotateRunnable = null;
setOnClickListener(null);
mExternalClickListener = null;
+ mDoubleTapOccurred = false;
}
/**
@@ -933,6 +979,10 @@ public class PhotoView extends View implements OnGestureListener,
sCropPaint.setColor(resources.getColor(R.color.photo_crop_highlight_color));
sCropPaint.setStyle(Style.STROKE);
sCropPaint.setStrokeWidth(resources.getDimension(R.dimen.photo_crop_stroke_width));
+
+ final ViewConfiguration configuration = ViewConfiguration.get(context);
+ final int touchSlop = configuration.getScaledTouchSlop();
+ sTouchSlopSquare = touchSlop * touchSlop;
}
mGestureDetector = new GestureDetectorCompat(context, this, null);