OSDN Git Service

Patch.
authorChih-Chung Chang <chihchung@google.com>
Thu, 5 Jan 2012 04:00:53 +0000 (12:00 +0800)
committerChih-Chung Chang <chihchung@google.com>
Thu, 12 Jan 2012 03:47:14 +0000 (11:47 +0800)
Change-Id: I62fd65461e8989a1d5cf6bc353dfc4b61a2108c8

src/com/android/gallery3d/ui/FlingScroller.java
src/com/android/gallery3d/ui/PositionController.java

index 9aef074..fbe27ce 100644 (file)
@@ -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) {
index abffbc5..b4dac97 100644 (file)
@@ -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;