From 8d84cc6d45b956b3ed52ba2a1c5ea49105f047cc Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Mon, 18 Jun 2012 17:24:58 +0800 Subject: Fix scaling gesture responsiveness. Bug: 6632011 Change-Id: I9cfeafa4365354a631565f8ee4a9b53df76d06e9 --- src/com/android/gallery3d/ui/PhotoView.java | 21 +++++++++++++++------ .../android/gallery3d/ui/PositionController.java | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index 6aace393f..3fba261fb 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -885,6 +885,8 @@ public class PhotoView extends GLView { private boolean mModeChanged; // If this scaling gesture should be ignored. private boolean mIgnoreScalingGesture; + // If we have seen a scaling gesture. + private boolean mSeenScaling; // whether the down action happened while the view is scrolling. private boolean mDownInScrolling; // If we should ignore all gestures other than onSingleTapUp. @@ -897,6 +899,8 @@ public class PhotoView extends GLView { private boolean mFirstScrollX; // The accumulated Y delta that has been sent to mPositionController. private int mDeltaY; + // The accumulated scaling change from a scaling gesture. + private float mAccScale; @Override public boolean onSingleTapUp(float x, float y) { @@ -987,6 +991,7 @@ public class PhotoView extends GLView { @Override public boolean onFling(float velocityX, float velocityY) { if (mIgnoreSwipingGesture) return true; + if (mSeenScaling) return true; if (swipeImages(velocityX, velocityY)) { mIgnoreUpEvent = true; } else { @@ -1057,6 +1062,8 @@ public class PhotoView extends GLView { mCanChangeMode = mFilmMode || mPositionController.isAtMinimalScale(); mModeChanged = false; + mSeenScaling = true; + mAccScale = 1f; return true; } @@ -1067,15 +1074,16 @@ public class PhotoView extends GLView { if (mModeChanged) return true; if (Float.isNaN(scale) || Float.isInfinite(scale)) return false; - // We wait for the scale change accumulated to a large enough change - // before reacting to it. Otherwise we may mistakenly treat a - // zoom-in gesture as zoom-out or vice versa. - if (scale > 0.99f && scale < 1.01f) return false; - int outOfRange = mPositionController.scaleBy(scale, focusX, focusY); + // We wait for a large enough scale change before changing mode. + // Otherwise we may mistakenly treat a zoom-in gesture as zoom-out + // or vice versa. + mAccScale *= scale; + boolean largeEnough = (mAccScale < 0.97f || mAccScale > 1.03f); + // If mode changes, we treat this scaling gesture has ended. - if (mCanChangeMode) { + if (mCanChangeMode && largeEnough) { if ((outOfRange < 0 && !mFilmMode) || (outOfRange > 0 && mFilmMode)) { stopExtraScalingIfNeeded(); @@ -1129,6 +1137,7 @@ public class PhotoView extends GLView { @Override public void onDown(float x, float y) { mDeltaY = 0; + mSeenScaling = false; mListener.onCommitDeleteImage(); if (mIgnoreSwipingGesture) return; diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index 2b91fcbfe..d556cafdc 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -62,7 +62,7 @@ class PositionController { // (always 1). private static final int ANIM_TIME[] = { 0, // ANIM_KIND_SCROLL - 50, // ANIM_KIND_SCALE + 0, // ANIM_KIND_SCALE SNAPBACK_ANIMATION_TIME, // ANIM_KIND_SNAPBACK 400, // ANIM_KIND_SLIDE 300, // ANIM_KIND_ZOOM -- cgit v1.2.3