From e9ca81a2fed768af4493c6aba897fa5cfc4523fb Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Thu, 5 Jan 2012 12:00:53 +0800 Subject: Patch. Change-Id: I62fd65461e8989a1d5cf6bc353dfc4b61a2108c8 --- src/com/android/gallery3d/ui/FlingScroller.java | 18 ++++++++++++++---- src/com/android/gallery3d/ui/PositionController.java | 13 +++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src/com') diff --git a/src/com/android/gallery3d/ui/FlingScroller.java b/src/com/android/gallery3d/ui/FlingScroller.java index 9aef07421..fbe27ce00 100644 --- a/src/com/android/gallery3d/ui/FlingScroller.java +++ b/src/com/android/gallery3d/ui/FlingScroller.java @@ -114,13 +114,23 @@ class FlingScroller { } private int getX(float f) { - return (int) Utils.clamp( - Math.round(mStartX + f * mDistance * mCosAngle), mMinX, mMaxX); + int r = (int) Math.round(mStartX + f * mDistance * mCosAngle); + if (mCosAngle > 0 && mStartX <= mMaxX) { + r = Math.min(r, mMaxX); + } else if (mCosAngle < 0 && mStartX >= mMinX) { + r = Math.max(r, mMinX); + } + return r; } private int getY(float f) { - return (int) Utils.clamp( - Math.round(mStartY + f * mDistance * mSinAngle), mMinY, mMaxY); + int r = (int) Math.round(mStartY + f * mDistance * mSinAngle); + if (mSinAngle > 0 && mStartY <= mMaxY) { + r = Math.min(r, mMaxY); + } else if (mSinAngle < 0 && mStartY >= mMinY) { + r = Math.max(r, mMinY); + } + return r; } private double getV(float progress) { diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index abffbc58f..b4dac973f 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -21,6 +21,7 @@ import com.android.gallery3d.app.GalleryActivity; import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.Path; import com.android.gallery3d.ui.PositionRepository.Position; +import com.android.gallery3d.util.GalleryUtils; import android.content.Context; import android.graphics.Bitmap; @@ -61,6 +62,7 @@ class PositionController { // We try to scale up the image to fill the screen. But in order not to // scale too much for small icons, we limit the max up-scaling factor here. private static final float SCALE_LIMIT = 4; + private static final int sHorizontalSlack = GalleryUtils.dpToPixel(12); private PhotoView mViewer; private EdgeView mEdgeView; @@ -543,7 +545,7 @@ class PositionController { scale = Utils.clamp(mCurrentScale, mScaleMin, mScaleMax); } - calculateStableBound(scale); + calculateStableBound(scale, sHorizontalSlack); int x = Utils.clamp(mCurrentX, mBoundLeft, mBoundRight); int y = Utils.clamp(mCurrentY, mBoundTop, mBoundBottom); @@ -570,10 +572,17 @@ class PositionController { // // The results are stored in mBound{Left/Right/Top/Bottom}. // + // An extra parameter "horizontalSlack" (which has the value of 0 usually) + // is used to extend the stable region by some pixels on each side + // horizontally. private void calculateStableBound(float scale) { + calculateStableBound(scale, 0f); + } + + private void calculateStableBound(float scale, float horizontalSlack) { // The number of pixels between the center of the view // and the edge when the edge is aligned. - mBoundLeft = (int) Math.ceil(mViewW / (2 * scale)); + mBoundLeft = (int) Math.ceil((mViewW - horizontalSlack) / (2 * scale)); mBoundRight = mImageW - mBoundLeft; mBoundTop = (int) Math.ceil(mViewH / (2 * scale)); mBoundBottom = mImageH - mBoundTop; -- cgit v1.2.3