summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui
diff options
context:
space:
mode:
authorBobby Georgescu <georgescu@google.com>2012-11-30 12:25:01 -0800
committerBobby Georgescu <georgescu@google.com>2012-11-30 12:31:24 -0800
commit85ea4b74e2c18576e2d0191eef804c6e2d2e65a7 (patch)
tree0976139beef3a05c1f4266f0091dc7e08fe48eeb /src/com/android/gallery3d/ui
parent7f072c4c99331a331d2950c11baca5426fad6643 (diff)
downloadandroid_packages_apps_Snap-85ea4b74e2c18576e2d0191eef804c6e2d2e65a7.tar.gz
android_packages_apps_Snap-85ea4b74e2c18576e2d0191eef804c6e2d2e65a7.tar.bz2
android_packages_apps_Snap-85ea4b74e2c18576e2d0191eef804c6e2d2e65a7.zip
Improve fling to delete gesture handling
Bug: 7419862 Bug: 7301456 Allows flings to start anywhere within the width bounds of the image, even if outside the height bounds, making deletion of panoramas more feasible, and gestures are filtered by length to be able to make flinging easier while still avoiding accidental input. Change-Id: Iac933bfee85865a718ed47eadfed76683eb771d2
Diffstat (limited to 'src/com/android/gallery3d/ui')
-rw-r--r--src/com/android/gallery3d/ui/GestureRecognizer.java4
-rw-r--r--src/com/android/gallery3d/ui/PhotoView.java20
2 files changed, 15 insertions, 9 deletions
diff --git a/src/com/android/gallery3d/ui/GestureRecognizer.java b/src/com/android/gallery3d/ui/GestureRecognizer.java
index e4e0c49f5..1e5250b9b 100644
--- a/src/com/android/gallery3d/ui/GestureRecognizer.java
+++ b/src/com/android/gallery3d/ui/GestureRecognizer.java
@@ -32,7 +32,7 @@ public class GestureRecognizer {
boolean onSingleTapUp(float x, float y);
boolean onDoubleTap(float x, float y);
boolean onScroll(float dx, float dy, float totalX, float totalY);
- boolean onFling(float velocityX, float velocityY);
+ boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);
boolean onScaleBegin(float focusX, float focusY);
boolean onScale(float focusX, float focusY, float scale);
void onScaleEnd();
@@ -94,7 +94,7 @@ public class GestureRecognizer {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
- return mListener.onFling(velocityX, velocityY);
+ return mListener.onFling(e1, e2, velocityX, velocityY);
}
}
diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java
index 0758656a1..be6706a14 100644
--- a/src/com/android/gallery3d/ui/PhotoView.java
+++ b/src/com/android/gallery3d/ui/PhotoView.java
@@ -174,8 +174,9 @@ public class PhotoView extends GLView {
public static final int SCREEN_NAIL_MAX = 3;
// These are constants for the delete gesture.
- private static final int SWIPE_ESCAPE_VELOCITY = 2500; // dp/sec
- private static final int MAX_DISMISS_VELOCITY = 4000; // dp/sec
+ private static final int SWIPE_ESCAPE_VELOCITY = 500; // dp/sec
+ private static final int MAX_DISMISS_VELOCITY = 2500; // dp/sec
+ private static final int SWIPE_ESCAPE_DISTANCE = 150; // dp
// The picture entries, the valid index is from -SCREEN_NAIL_MAX to
// SCREEN_NAIL_MAX.
@@ -1069,19 +1070,19 @@ public class PhotoView extends GLView {
}
@Override
- public boolean onFling(float velocityX, float velocityY) {
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (mIgnoreSwipingGesture) return true;
if (mModeChanged) return true;
if (swipeImages(velocityX, velocityY)) {
mIgnoreUpEvent = true;
} else {
- flingImages(velocityX, velocityY);
+ flingImages(velocityX, velocityY, Math.abs(e2.getY() - e1.getY()));
}
mHadFling = true;
return true;
}
- private boolean flingImages(float velocityX, float velocityY) {
+ private boolean flingImages(float velocityX, float velocityY, float dY) {
int vx = (int) (velocityX + 0.5f);
int vy = (int) (velocityY + 0.5f);
if (!mFilmMode) {
@@ -1098,11 +1099,13 @@ public class PhotoView extends GLView {
}
int maxVelocity = GalleryUtils.dpToPixel(MAX_DISMISS_VELOCITY);
int escapeVelocity = GalleryUtils.dpToPixel(SWIPE_ESCAPE_VELOCITY);
+ int escapeDistance = GalleryUtils.dpToPixel(SWIPE_ESCAPE_DISTANCE);
int centerY = mPositionController.getPosition(mTouchBoxIndex)
.centerY();
boolean fastEnough = (Math.abs(vy) > escapeVelocity)
&& (Math.abs(vy) > Math.abs(vx))
- && ((vy > 0) == (centerY > getHeight() / 2));
+ && ((vy > 0) == (centerY > getHeight() / 2))
+ && dY >= escapeDistance;
if (fastEnough) {
vy = Math.min(vy, maxVelocity);
int duration = mPositionController.flingFilmY(mTouchBoxIndex, vy);
@@ -1236,7 +1239,10 @@ public class PhotoView extends GLView {
if (mFilmMode) {
int xi = (int) (x + 0.5f);
int yi = (int) (y + 0.5f);
- mTouchBoxIndex = mPositionController.hitTest(xi, yi);
+ // We only care about being within the x bounds, necessary for
+ // handling very wide images which are otherwise very hard to fling
+ mTouchBoxIndex = mPositionController.hitTest(xi, getHeight() / 2);
+
if (mTouchBoxIndex < mPrevBound || mTouchBoxIndex > mNextBound) {
mTouchBoxIndex = Integer.MAX_VALUE;
} else {