OSDN Git Service

Slower scrolling for fling in filmstrip mode.
authorChih-Chung Chang <chihchung@google.com>
Tue, 17 Apr 2012 04:56:08 +0000 (12:56 +0800)
committerChih-Chung Chang <chihchung@google.com>
Tue, 17 Apr 2012 04:56:08 +0000 (12:56 +0800)
Also don't animate scale for the first image size.

Change-Id: I6a71c00e813bd203e9f454bc9a776eadec06fd78

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

index 3774cce..6650d24 100644 (file)
@@ -19,7 +19,7 @@ package com.android.gallery3d.ui;
 import android.content.Context;
 import android.graphics.Rect;
 import android.util.Log;
-import android.widget.Scroller;
+import android.widget.OverScroller;
 
 import com.android.gallery3d.common.Utils;
 import com.android.gallery3d.util.GalleryUtils;
@@ -101,7 +101,7 @@ class PositionController {
     private FlingScroller mPageScroller;
 
     // This is used by the fling animation (film mode).
-    private Scroller mFilmScroller;
+    private OverScroller mFilmScroller;
 
     // The bound of the stable region that the focused box can stay, see the
     // comments above calculateStableBound() for details.
@@ -146,7 +146,7 @@ class PositionController {
     public PositionController(Context context, Listener listener) {
         mListener = listener;
         mPageScroller = new FlingScroller();
-        mFilmScroller = new Scroller(context);
+        mFilmScroller = new OverScroller(context);
 
         // Initialize the areas.
         initPlatform();
@@ -194,9 +194,11 @@ class PositionController {
 
     private void setBoxSize(int i, int width, int height, boolean isViewSize) {
         Box b = mBoxes.get(i);
+        boolean wasViewSize = b.mUseViewSize;
+
+        // If we already have an image size, we don't want to use the view size.
+        if (!wasViewSize && isViewSize) return;
 
-        // If we already have image size, we don't want to use the view size.
-        if (isViewSize && !b.mUseViewSize) return;
         b.mUseViewSize = isViewSize;
 
         if (width == b.mImageW && height == b.mImageH) {
@@ -207,9 +209,17 @@ class PositionController {
         float ratio = Math.min(
                 (float) b.mImageW / width, (float) b.mImageH / height);
 
-        b.mCurrentScale *= ratio;
-        b.mFromScale *= ratio;
-        b.mToScale *= ratio;
+        // If this is the first time we receive an image size, we change the
+        // scale directly. Otherwise adjust the scales by a ratio, and snapback
+        // will animate the scale into the min/max bounds if necessary.
+        if (wasViewSize && !isViewSize) {
+            b.mCurrentScale = getMinimalScale(width, height);
+            b.mAnimationStartTime = NO_ANIMATION;
+        } else {
+            b.mCurrentScale *= ratio;
+            b.mFromScale *= ratio;
+            b.mToScale *= ratio;
+        }
 
         b.mImageW = width;
         b.mImageH = height;