diff options
author | Chih-Chung Chang <chihchung@google.com> | 2012-04-19 13:34:48 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2012-04-19 13:34:48 +0800 |
commit | 4831a8fbd146ed627b8f6be4f4d1fed4cd4e3fe5 (patch) | |
tree | afa32727cd84c1e04137911db31c1eeea37510be /src/com | |
parent | a0b06477b94978c447eedf1686def0fecc356aeb (diff) | |
download | android_packages_apps_Snap-4831a8fbd146ed627b8f6be4f4d1fed4cd4e3fe5.tar.gz android_packages_apps_Snap-4831a8fbd146ed627b8f6be4f4d1fed4cd4e3fe5.tar.bz2 android_packages_apps_Snap-4831a8fbd146ed627b8f6be4f4d1fed4cd4e3fe5.zip |
Allow filmstrip to scroll before the screennail is loaded.
Change-Id: I9aa7405902c4bfb7e4946cfe4e1263314a958686
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/gallery3d/app/PhotoDataAdapter.java | 3 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/PhotoView.java | 5 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/PositionController.java | 59 |
3 files changed, 28 insertions, 39 deletions
diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java index f9979f88e..ec59997f4 100644 --- a/src/com/android/gallery3d/app/PhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java @@ -210,7 +210,8 @@ public class PhotoDataAdapter implements PhotoPage.Model { for (int i = -SCREEN_NAIL_MAX; i <= SCREEN_NAIL_MAX; ++i) { mChanges[i + SCREEN_NAIL_MAX] = getVersion(mCurrentIndex + i); } - mPhotoView.notifyDataChange(mChanges); + mPhotoView.notifyDataChange(mChanges, mCurrentIndex > 0, + mCurrentIndex < mSize - 1); } public void setDataListener(DataListener listener) { diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index 89475c4b6..306da81c1 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -232,7 +232,8 @@ public class PhotoView extends GLView { // Data/Image change notifications //////////////////////////////////////////////////////////////////////////// - public void notifyDataChange(long[] versions) { + public void notifyDataChange(long[] versions, boolean hasPrev, + boolean hasNext) { // Check if the data version actually changed. boolean changed = false; int N = 2 * SCREEN_NAIL_MAX + 1; @@ -269,7 +270,7 @@ public class PhotoView extends GLView { } // Move the boxes - mPositionController.moveBox(mFromIndex); + mPositionController.moveBox(mFromIndex, hasPrev, hasNext); // Update the ScreenNails. for (int i = -SCREEN_NAIL_MAX; i <= SCREEN_NAIL_MAX; i++) { diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index a5eb22425..f087c6b70 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -83,7 +83,7 @@ class PositionController { // about this many boxes on each side. private static final int BOX_MAX = PhotoView.SCREEN_NAIL_MAX; - public static final int IMAGE_GAP = GalleryUtils.dpToPixel(16); + private static final int IMAGE_GAP = GalleryUtils.dpToPixel(16); private static final int HORIZONTAL_SLACK = GalleryUtils.dpToPixel(12); private Listener mListener; @@ -97,6 +97,9 @@ class PositionController { // picture in bitmap pixels. private float mFocusX, mFocusY; + // whether there is a previous/next picture. + private boolean mHasPrev, mHasNext; + // This is used by the fling animation (page mode). private FlingScroller mPageScroller; @@ -128,7 +131,8 @@ class PositionController { // These are only used during moveBox(). private RangeArray<Box> mTempBoxes = new RangeArray<Box>(-BOX_MAX, BOX_MAX); - private RangeArray<Gap> mTempGaps = new RangeArray<Gap>(-BOX_MAX, BOX_MAX - 1); + private RangeArray<Gap> mTempGaps = + new RangeArray<Gap>(-BOX_MAX, BOX_MAX - 1); // The output of the PositionController. Available throught getPosition(). private RangeArray<Rect> mRects = new RangeArray<Rect>(-BOX_MAX, BOX_MAX); @@ -410,9 +414,6 @@ class PositionController { } public void startScroll(float dx, float dy) { - boolean hasPrev = hasPrevImages(); - boolean hasNext = hasNextImages(); - Box b = mBoxes.get(0); Platform p = mPlatform; @@ -420,13 +421,13 @@ class PositionController { int y = getTargetY(b) + (int) (dy + 0.5f); if (mFilmMode) { - scrollToFilm(x, y, hasPrev, hasNext); + scrollToFilm(x, y); } else { - scrollToPage(x, y, hasPrev, hasNext); + scrollToPage(x, y); } } - private void scrollToPage(int x, int y, boolean hasPrev, boolean hasNext) { + private void scrollToPage(int x, int y) { Box b = mBoxes.get(0); calculateStableBound(b.mCurrentScale); @@ -445,11 +446,11 @@ class PositionController { // Horizontal direction: we show the edge effect when the scrolling // tries to go left of the first image or go right of the last image. - if (!hasPrev && x > mBoundRight) { + if (!mHasPrev && x > mBoundRight) { int pixels = x - mBoundRight; mListener.onPull(pixels, EdgeView.LEFT); x = mBoundRight; - } else if (!hasNext && x < mBoundLeft) { + } else if (!mHasNext && x < mBoundLeft) { int pixels = mBoundLeft - x; mListener.onPull(pixels, EdgeView.RIGHT); x = mBoundLeft; @@ -458,17 +459,17 @@ class PositionController { startAnimation(x, y, b.mCurrentScale, ANIM_KIND_SCROLL); } - private void scrollToFilm(int x, int y, boolean hasPrev, boolean hasNext) { + private void scrollToFilm(int x, int y) { Box b = mBoxes.get(0); // Horizontal direction: we show the edge effect when the scrolling // tries to go left of the first image or go right of the last image. int cx = mViewW / 2; - if (!hasPrev && x > cx) { + if (!mHasPrev && x > cx) { int pixels = x - cx; mListener.onPull(pixels, EdgeView.LEFT); x = cx; - } else if (!hasNext && x < cx) { + } else if (!mHasNext && x < cx) { int pixels = cx - x; mListener.onPull(pixels, EdgeView.RIGHT); x = cx; @@ -517,15 +518,13 @@ class PositionController { } private boolean flingFilm(int velocityX, int velocityY) { - boolean hasPrev = hasPrevImages(); - boolean hasNext = hasNextImages(); - Box b = mBoxes.get(0); Platform p = mPlatform; // If we are already at the edge, don't start the fling. int cx = mViewW / 2; - if ((!hasPrev && p.mCurrentX >= cx) || (!hasNext && p.mCurrentX <= cx)) { + if ((!mHasPrev && p.mCurrentX >= cx) + || (!mHasNext && p.mCurrentX <= cx)) { return false; } @@ -762,8 +761,10 @@ class PositionController { // -2 -1 0 1 2 3 N -- focus goes to the next box // N-3 -2 -1 0 1 2 -- focuse goes to the previous box // -3 -2 -1 1 2 3 N -- the focused box was deleted. - public void moveBox(int fromIndex[]) { + public void moveBox(int fromIndex[], boolean hasPrev, boolean hasNext) { //debugMoveBox(fromIndex); + mHasPrev = hasPrev; + mHasNext = hasNext; RangeIntArray from = new RangeIntArray(fromIndex, -BOX_MAX, BOX_MAX); // 1. Get the absolute X coordiates for the boxes. @@ -999,20 +1000,6 @@ class PositionController { calculateStableBound(scale, 0); } - private boolean hasNextImages() { - for (int i = 1; i <= BOX_MAX; i++) { - if (!mBoxes.get(i).mUseViewSize) return true; - } - return false; - } - - private boolean hasPrevImages() { - for (int i = -1; i >= -BOX_MAX; i--) { - if (!mBoxes.get(i).mUseViewSize) return true; - } - return false; - } - private boolean viewTallerThanScaledImage(float scale) { return mViewH >= heightOf(mBoxes.get(0), scale); } @@ -1136,8 +1123,8 @@ class PositionController { float scale = Utils.clamp(b.mCurrentScale, scaleMin, scaleMax); int x = mCurrentX; if (mFilmMode) { - if (!hasNextImages()) x = Math.max(x, mViewW / 2); - if (!hasPrevImages()) x = Math.min(x, mViewW / 2); + if (mHasNext) x = Math.max(x, mViewW / 2); + if (mHasPrev) x = Math.min(x, mViewW / 2); } else { calculateStableBound(scale, HORIZONTAL_SLACK); x = Utils.clamp(x, mBoundLeft, mBoundRight); @@ -1178,11 +1165,11 @@ class PositionController { int dir = EdgeView.INVALID_DIRECTION; if (mCurrentX < mViewW / 2) { - if (!hasNextImages()) { + if (!mHasNext) { dir = EdgeView.RIGHT; } } else if (mCurrentX > mViewW / 2) { - if (!hasPrevImages()) { + if (!mHasPrev) { dir = EdgeView.LEFT; } } |