diff options
author | Chih-Chung Chang <chihchung@google.com> | 2012-05-22 11:35:46 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-22 19:36:28 -0700 |
commit | b9e6e7f1dffe3d4e4736ed67a323f11a174afbb1 (patch) | |
tree | e0efc6b433d4e440d3dc6212a94a792fc95ae548 | |
parent | 048ca675a9e659fb0d3b150880d71cd42770023d (diff) | |
download | android_packages_apps_Snap-b9e6e7f1dffe3d4e4736ed67a323f11a174afbb1.tar.gz android_packages_apps_Snap-b9e6e7f1dffe3d4e4736ed67a323f11a174afbb1.tar.bz2 android_packages_apps_Snap-b9e6e7f1dffe3d4e4736ed67a323f11a174afbb1.zip |
Unlock orientation only when action bar is needed.
Bug: 6482079
Change-Id: I75d96ca7957f80e9c52f35edf74127f82f194f63
-rw-r--r-- | src/com/android/gallery3d/app/PhotoPage.java | 32 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/PhotoView.java | 63 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/PositionController.java | 17 |
3 files changed, 51 insertions, 61 deletions
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 71a6c8eef..2132d068e 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -75,6 +75,7 @@ public class PhotoPage extends ActivityState implements private static final int MSG_ON_FULL_SCREEN_CHANGED = 4; private static final int MSG_UPDATE_ACTION_BAR = 5; private static final int MSG_UNFREEZE_GLROOT = 6; + private static final int MSG_WANT_BARS = 7; private static final int HIDE_BARS_TIMEOUT = 3500; private static final int UNFREEZE_GLROOT_TIMEOUT = 250; @@ -110,8 +111,6 @@ public class PhotoPage extends ActivityState implements private int mCurrentIndex = 0; private Handler mHandler; private boolean mShowBars = true; - // The value of canShowBars() last time the bar updates state. - private boolean mCanShowBars = false; private volatile boolean mActionBarAllowed = true; private GalleryActionBar mActionBar; private MyMenuVisibilityListener mMenuVisibilityListener; @@ -269,12 +268,10 @@ public class PhotoPage extends ActivityState implements } case MSG_LOCK_ORIENTATION: { mOrientationManager.lockOrientation(); - updateBars(); break; } case MSG_UNLOCK_ORIENTATION: { mOrientationManager.unlockOrientation(); - updateBars(); break; } case MSG_ON_FULL_SCREEN_CHANGED: { @@ -285,6 +282,10 @@ public class PhotoPage extends ActivityState implements updateBars(); break; } + case MSG_WANT_BARS: { + wantBars(); + break; + } case MSG_UNFREEZE_GLROOT: { mActivity.getGLRoot().unfreeze(); break; @@ -378,6 +379,7 @@ public class PhotoPage extends ActivityState implements private void showBars() { if (mShowBars) return; mShowBars = true; + mOrientationManager.unlockOrientation(); mActionBar.show(); mActivity.getGLRoot().setLightsOutMode(false); refreshHidingMessage(); @@ -403,29 +405,24 @@ public class PhotoPage extends ActivityState implements if (mAppBridge != null && mCurrentIndex == 0) return false; // No bars if it's not allowed. if (!mActionBarAllowed) return false; - // No bars if the orientation is locked. - if (mOrientationManager.isOrientationLocked()) return false; return true; } + private void wantBars() { + if (canShowBars()) showBars(); + } + private void toggleBars() { - mCanShowBars = canShowBars(); if (mShowBars) { hideBars(); } else { - if (mCanShowBars) showBars(); + if (canShowBars()) showBars(); } } private void updateBars() { - boolean v = canShowBars(); - if (mCanShowBars == v) return; - mCanShowBars = v; - - if (mCanShowBars) { - showBars(); - } else { + if (!canShowBars()) { hideBars(); } } @@ -687,6 +684,11 @@ public class PhotoPage extends ActivityState implements } @Override + public void onActionBarWanted() { + mHandler.sendEmptyMessage(MSG_WANT_BARS); + } + + @Override public void onFullScreenChanged(boolean full) { Message m = mHandler.obtainMessage( MSG_ON_FULL_SCREEN_CHANGED, full ? 1 : 0, 0); diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index a15dd612c..4490569bb 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -90,33 +90,25 @@ public class PhotoView extends GLView { public void unlockOrientation(); public void onFullScreenChanged(boolean full); public void onActionBarAllowed(boolean allowed); + public void onActionBarWanted(); public void onCurrentImageUpdated(); } - // Here is a graph showing the places we need to lock/unlock device - // orientation: + // The rules about orientation locking: // - // +------------+ A +------------+ - // Page mode | Camera |<---| Photo | - // | [locked] |--->| [unlocked] | - // +------------+ B +------------+ - // ^ ^ - // | C | D - // +------------+ +------------+ - // | Camera | | Photo | - // Film mode | [*] | | [*] | - // +------------+ +------------+ + // (1) We need to lock the orientation if we are in page mode camera + // preview, so there is no (unwanted) rotation animation when the user + // rotates the device. // - // In Page mode, we want to lock in Camera because we don't want the system - // rotation animation. We also want to unlock in Photo because we want to - // show the system action bar in the right place. + // (2) We need to unlock the orientation if we want to show the action bar + // because the action bar follows the system orientation. // - // We don't show action bar in Film mode, so it's fine for it to be locked - // or unlocked in Film mode. + // The rules about action bar: // - // There are four transitions we need to check if we need to - // lock/unlock. Marked as A to D above and in the code. - + // (1) If we are in film mode, we don't show action bar. + // + // (2) If we go from camera to gallery with capture animation, we show + // action bar. private static final int MSG_CANCEL_EXTRA_SCALING = 2; private static final int MSG_SWITCH_FOCUS = 3; private static final int MSG_CAPTURE_ANIMATION_DONE = 4; @@ -457,14 +449,9 @@ public class PhotoView extends GLView { setFilmMode(false); } - if (isCenter && !mFilmMode) { - if (mIsCamera) { - // move into camera, lock - mListener.lockOrientation(); // Transition A - } else { - // move out of camera, unlock - mListener.unlockOrientation(); // Transition B - } + if (isCenter && !mFilmMode && mIsCamera) { + // Move into camera in page mode, lock + mListener.lockOrientation(); } mWasCameraCenter = isCameraCenter; @@ -931,13 +918,9 @@ public class PhotoView extends GLView { mModel.setNeedFullImage(!enabled); mListener.onActionBarAllowed(!enabled); - // If we leave filmstrip mode, we should lock/unlock - if (!enabled) { - if (mPictures.get(0).isCamera()) { - mListener.lockOrientation(); // Transition C - } else { - mListener.unlockOrientation(); // Transition D - } + // Move into camera in page mode, lock + if (!enabled && mPictures.get(0).isCamera()) { + mListener.lockOrientation(); } } @@ -1209,12 +1192,10 @@ public class PhotoView extends GLView { private void captureAnimationDone(int offset) { mHolding &= ~HOLD_CAPTURE_ANIMATION; - if (offset == 1) { - // move out of camera, unlock - if (!mFilmMode) { - // Now the capture animation is done, enable the action bar. - mListener.onActionBarAllowed(true); - } + if (offset == 1 && !mFilmMode) { + // Now the capture animation is done, enable the action bar. + mListener.onActionBarAllowed(true); + mListener.onActionBarWanted(); } snapback(); } diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index bb2b83ecb..d085c4d49 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -209,8 +209,13 @@ class PositionController { } updateScaleAndGapLimit(); - startOpeningAnimationIfNeeded(); - snapAndRedraw(); + + // If we have the opening animation, do it. Otherwise go directly to the + // right position. + if (!startOpeningAnimationIfNeeded()) { + snapAndRedraw(); + skipAnimation(); + } } public void setConstrainedFrame(Rect f) { @@ -280,10 +285,10 @@ class PositionController { return true; } - private void startOpeningAnimationIfNeeded() { - if (mOpenAnimationRect == null) return; + private boolean startOpeningAnimationIfNeeded() { + if (mOpenAnimationRect == null) return false; Box b = mBoxes.get(0); - if (b.mUseViewSize) return; + if (b.mUseViewSize) return false; // Start animation from the saved rectangle if we have one. Rect r = mOpenAnimationRect; @@ -303,6 +308,8 @@ class PositionController { g.mCurrentGap = mViewW; g.doAnimation(g.mDefaultSize, ANIM_KIND_OPENING); } + + return true; } public void setFilmMode(boolean enabled) { |