diff options
-rw-r--r-- | src/com/android/gallery3d/ui/GestureRecognizer.java | 9 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/PhotoView.java | 25 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/PositionController.java | 27 |
3 files changed, 56 insertions, 5 deletions
diff --git a/src/com/android/gallery3d/ui/GestureRecognizer.java b/src/com/android/gallery3d/ui/GestureRecognizer.java index 492f993d7..4a17d4364 100644 --- a/src/com/android/gallery3d/ui/GestureRecognizer.java +++ b/src/com/android/gallery3d/ui/GestureRecognizer.java @@ -17,6 +17,7 @@ package com.android.gallery3d.ui; import android.content.Context; +import android.os.SystemClock; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.ScaleGestureDetector; @@ -62,6 +63,14 @@ public class GestureRecognizer { return mDownUpDetector.isDown(); } + public void cancelScale() { + long now = SystemClock.uptimeMillis(); + MotionEvent cancelEvent = MotionEvent.obtain( + now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0); + mScaleDetector.onTouchEvent(cancelEvent); + cancelEvent.recycle(); + } + private class MyGestureListener extends GestureDetector.SimpleOnGestureListener { @Override diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index c2c750ba4..252f3484d 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -38,6 +38,7 @@ public class PhotoView extends GLView { private static final int MSG_TRANSITION_COMPLETE = 1; private static final int MSG_SHOW_LOADING = 2; + private static final int MSG_CANCEL_EXTRA_SCALING = 3; private static final long DELAY_SHOW_LOADING = 250; // 250ms; @@ -103,6 +104,7 @@ public class PhotoView extends GLView { private Rect mOpenAnimationRect; private Point mImageCenter = new Point(); + private boolean mCancelExtraScalingPending; public PhotoView(GalleryActivity activity) { mTileView = new TileImageView(activity); @@ -137,6 +139,12 @@ public class PhotoView extends GLView { } break; } + case MSG_CANCEL_EXTRA_SCALING: { + mGestureRecognizer.cancelScale(); + mPositionController.setExtraScalingRange(false); + mCancelExtraScalingPending = false; + break; + } default: throw new AssertionError(message.what); } } @@ -570,7 +578,22 @@ public class PhotoView extends GLView { public boolean onScale(float focusX, float focusY, float scale) { if (Float.isNaN(scale) || Float.isInfinite(scale) || mTransitionMode != TRANS_NONE) return true; - mPositionController.scaleBy(scale, focusX, focusY); + boolean outOfRange = mPositionController.scaleBy( + scale, focusX, focusY); + if (outOfRange) { + if (!mCancelExtraScalingPending) { + mHandler.sendEmptyMessageDelayed( + MSG_CANCEL_EXTRA_SCALING, 700); + mPositionController.setExtraScalingRange(true); + mCancelExtraScalingPending = true; + } + } else { + if (mCancelExtraScalingPending) { + mHandler.removeMessages(MSG_CANCEL_EXTRA_SCALING); + mPositionController.setExtraScalingRange(false); + mCancelExtraScalingPending = false; + } + } return true; } diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index 09fbc1706..625505f49 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -59,6 +59,9 @@ class PositionController { private static final float SCALE_LIMIT = 4; private static final int sHorizontalSlack = GalleryUtils.dpToPixel(12); + private static final float SCALE_MIN_EXTRA = 0.6f; + private static final float SCALE_MAX_EXTRA = 1.4f; + private PhotoView mViewer; private EdgeView mEdgeView; private int mImageW, mImageH; @@ -78,6 +81,7 @@ class PositionController { // The minimum and maximum scale we allow. private float mScaleMin, mScaleMax = SCALE_LIMIT; + private boolean mExtraScalingRange = false; // This is used by the fling animation private FlingScroller mScroller; @@ -269,7 +273,8 @@ class PositionController { (focusY - mViewH / 2f) / mCurrentScale); } - public void scaleBy(float s, float focusX, float focusY) { + // Returns true if the result scale is outside the stable range. + public boolean scaleBy(float s, float focusX, float focusY) { // We want to keep the focus point (on the bitmap) the same as when // we begin the scale guesture, that is, @@ -281,6 +286,7 @@ class PositionController { int y = Math.round(mFocusBitmapY - (focusY - mViewH / 2f) / s); startAnimation(x, y, s, ANIM_KIND_SCALE); + return (s < mScaleMin || s > mScaleMax); } public void endScale() { @@ -288,6 +294,13 @@ class PositionController { startSnapbackIfNeeded(); } + public void setExtraScalingRange(boolean enabled) { + mExtraScalingRange = enabled; + if (!enabled) { + startSnapbackIfNeeded(); + } + } + public float getCurrentScale() { return mCurrentScale; } @@ -419,7 +432,8 @@ class PositionController { mToX = targetX; mToY = targetY; - mToScale = Utils.clamp(scale, 0.6f * mScaleMin, 1.4f * mScaleMax); + mToScale = Utils.clamp(scale, SCALE_MIN_EXTRA * mScaleMin, + SCALE_MAX_EXTRA * mScaleMax); // If the scaled height is smaller than the view height, // force it to be in the center. @@ -561,9 +575,14 @@ class PositionController { boolean needAnimation = false; float scale = mCurrentScale; - if (mCurrentScale < mScaleMin || mCurrentScale > mScaleMax) { + float scaleMin = mExtraScalingRange ? + mScaleMin * SCALE_MIN_EXTRA : mScaleMin; + float scaleMax = mExtraScalingRange ? + mScaleMax * SCALE_MAX_EXTRA : mScaleMax; + + if (mCurrentScale < scaleMin || mCurrentScale > scaleMax) { needAnimation = true; - scale = Utils.clamp(mCurrentScale, mScaleMin, mScaleMax); + scale = Utils.clamp(mCurrentScale, scaleMin, scaleMax); } calculateStableBound(scale, sHorizontalSlack); |