From 33f8567dd5003e4bb342683f3768ab7552648b02 Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Tue, 1 May 2012 15:35:02 +0800 Subject: [PATCH] Fix the Camera controls disappearing after zooming problem. Bug: 6392682 Change-Id: I065c52b44c02f9314e58e82846cdf22e2d940eab --- src/com/android/gallery3d/app/PhotoPage.java | 2 +- src/com/android/gallery3d/ui/PhotoView.java | 38 +++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index d7936e24f..1851b976c 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -712,7 +712,7 @@ public class PhotoPage extends ActivityState implements onUserInteraction(); if (mAppBridge != null) { mAppBridge.setServer(this); - mModel.moveTo(0); // move to the camera preview after resume + mPhotoView.resetToFirstPicture(); } } diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index b54a685d4..c6b370d74 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -737,6 +737,8 @@ public class PhotoView extends GLView { private boolean mCanChangeMode; // If we have changed the film mode in this scaling gesture. private boolean mModeChanged; + // If this scaling gesture should be ignored. + private boolean mIgnoreScalingGesture; @Override public boolean onSingleTapUp(float x, float y) { @@ -784,6 +786,11 @@ public class PhotoView extends GLView { @Override public boolean onScaleBegin(float focusX, float focusY) { + // We ignore the scaling gesture if it is a camera preview. + mIgnoreScalingGesture = mPictures.get(0).isCamera(); + if (mIgnoreScalingGesture) { + return true; + } mPositionController.beginScale(focusX, focusY); // We can change mode if we are in film mode, or we are in page // mode and at minimal scale. @@ -795,9 +802,17 @@ public class PhotoView extends GLView { @Override public boolean onScale(float focusX, float focusY, float scale) { + if (mIgnoreScalingGesture) { + return true; + } if (mModeChanged) return true; if (Float.isNaN(scale) || Float.isInfinite(scale)) return false; + + // We wait for the scale change accumulated to a large enough change + // before reacting to it. Otherwise we may mistakenly treat a + // zoom-in gesture as zoom-out or vice versa. if (scale > 0.99f && scale < 1.01f) return false; + int outOfRange = mPositionController.scaleBy(scale, focusX, focusY); // If mode changes, we treat this scaling gesture has ended. @@ -807,7 +822,7 @@ public class PhotoView extends GLView { stopExtraScalingIfNeeded(); // Removing the touch down flag allows snapback to happen - // for file mode change. + // for film mode change. mHolding &= ~HOLD_TOUCH_DOWN; setFilmMode(!mFilmMode); @@ -827,6 +842,15 @@ public class PhotoView extends GLView { return true; } + @Override + public void onScaleEnd() { + if (mIgnoreScalingGesture) { + return; + } + if (mModeChanged) return; + mPositionController.endScale(); + } + private void startExtraScalingIfNeeded() { if (!mCancelExtraScalingPending) { mHandler.sendEmptyMessageDelayed( @@ -845,12 +869,6 @@ public class PhotoView extends GLView { } @Override - public void onScaleEnd() { - if (mModeChanged) return; - mPositionController.endScale(); - } - - @Override public void onDown() { mHolding |= HOLD_TOUCH_DOWN; } @@ -905,6 +923,12 @@ public class PhotoView extends GLView { mTileView.prepareTextures(); } + // move to the camera preview and show controls after resume + public void resetToFirstPicture() { + mModel.moveTo(0); + setFilmMode(false); + } + //////////////////////////////////////////////////////////////////////////// // Rendering //////////////////////////////////////////////////////////////////////////// -- 2.11.0