From 17ffedda6e3ed57b38afbb775594cf30d83fc652 Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Thu, 3 May 2012 18:22:59 +0800 Subject: [PATCH] Fix 6399813: tapping on a photo that isn't in the middle of the screen doesn't select it. Also make tapping while flinging stop the scroll instead of opening the item. Change-Id: Iefef4738d7d74b29e4594ea3ae2cb1c91e0e17ab --- src/com/android/gallery3d/ui/PhotoView.java | 33 +++++++++++++++++++++- .../android/gallery3d/ui/PositionController.java | 10 +++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index adbf791fb..7b97e78eb 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -748,11 +748,15 @@ public class PhotoView extends GLView { private boolean mModeChanged; // If this scaling gesture should be ignored. private boolean mIgnoreScalingGesture; + // whether the down action happened while the view is scrolling. + private boolean mDownInScrolling; @Override public boolean onSingleTapUp(float x, float y) { - if (mFilmMode) { + if (mFilmMode && !mDownInScrolling) { + switchToHitPicture((int) (x + 0.5f), (int) (y + 0.5f)); setFilmMode(false); + mIgnoreUpEvent = true; return true; } @@ -881,6 +885,13 @@ public class PhotoView extends GLView { @Override public void onDown() { mHolding |= HOLD_TOUCH_DOWN; + + if (mFilmMode && mPositionController.isScrolling()) { + mDownInScrolling = true; + mPositionController.stopScrolling(); + } else { + mDownInScrolling = false; + } } @Override @@ -1020,6 +1031,26 @@ public class PhotoView extends GLView { return 0; } + // Switch to the previous or next picture if the hit position is inside + // one of their boxes. This runs in main thread. + private void switchToHitPicture(int x, int y) { + if (mPrevBound < 0) { + Rect r = mPositionController.getPosition(-1); + if (r.right >= x) { + slideToPrevPicture(); + return; + } + } + + if (mNextBound > 0) { + Rect r = mPositionController.getPosition(1); + if (r.left <= x) { + slideToNextPicture(); + return; + } + } + } + //////////////////////////////////////////////////////////////////////////// // Page mode focus switching // diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index 03fe65b1c..c09ffea0c 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -1003,6 +1003,16 @@ class PositionController { return edges; } + public boolean isScrolling() { + return mPlatform.mAnimationStartTime != NO_ANIMATION + && mPlatform.mCurrentX != mPlatform.mToX; + } + + public void stopScrolling() { + if (mPlatform.mAnimationStartTime == NO_ANIMATION) return; + mPlatform.mFromX = mPlatform.mToX = mPlatform.mCurrentX; + } + //////////////////////////////////////////////////////////////////////////// // Private utilities //////////////////////////////////////////////////////////////////////////// -- 2.11.0