From aeb3062e84ed28f0e25a73f511f287ae0a3e4294 Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Thu, 3 May 2012 11:41:05 +0800 Subject: [PATCH] Fix NPE in onFullScreenChanged message handler. Bug: 6430929 Also tweak the timing of showing action bar and the timing of unlock orientation. Change-Id: I1af4703ccf99f5257e9724a20d0aa216d20e13c2 --- .../android/gallery3d/app/OrientationManager.java | 4 +++ src/com/android/gallery3d/app/PhotoPage.java | 36 ++++++++++++++++------ src/com/android/gallery3d/ui/PhotoView.java | 31 +++++++++++-------- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/com/android/gallery3d/app/OrientationManager.java b/src/com/android/gallery3d/app/OrientationManager.java index 93a1fc506..a54f66840 100644 --- a/src/com/android/gallery3d/app/OrientationManager.java +++ b/src/com/android/gallery3d/app/OrientationManager.java @@ -109,6 +109,10 @@ public class OrientationManager { disableCompensation(); } + public boolean isOrientationLocked() { + return mOrientationLocked; + } + // Calculate the compensation value and send it to listeners. private void updateCompensation() { if (mOrientation == OrientationEventListener.ORIENTATION_UNKNOWN) { diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 76d4f91eb..51a57f2f9 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -100,6 +100,8 @@ 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; @@ -260,10 +262,12 @@ 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: { @@ -380,7 +384,7 @@ public class PhotoPage extends ActivityState implements mActionBar.hide(); WindowManager.LayoutParams params = ((Activity) mActivity).getWindow().getAttributes(); - params.systemUiVisibility = View. SYSTEM_UI_FLAG_LOW_PROFILE; + params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE; ((Activity) mActivity).getWindow().setAttributes(params); mHandler.removeMessages(MSG_HIDE_BARS); } @@ -392,27 +396,38 @@ public class PhotoPage extends ActivityState implements } } + private boolean canShowBars() { + // No bars if we are showing camera preview. + 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 toggleBars() { + mCanShowBars = canShowBars(); if (mShowBars) { hideBars(); - } else if (canShowBars()) { - showBars(); + } else { + if (mCanShowBars) showBars(); } } private void updateBars() { - if (canShowBars()) { + boolean v = canShowBars(); + if (mCanShowBars == v) return; + mCanShowBars = v; + + if (mCanShowBars) { showBars(); } else { hideBars(); } } - private boolean canShowBars() { - boolean atCamera = mAppBridge != null && mCurrentIndex == 0; - return mActionBarAllowed && !atCamera; - } - @Override public void onOrientationCompensationChanged(int degrees) { mActivity.getGLRoot().setOrientationCompensation(degrees); @@ -730,6 +745,9 @@ public class PhotoPage extends ActivityState implements mScreenNail = null; } mOrientationManager.removeListener(this); + + // Remove all pending messages. + mHandler.removeCallbacksAndMessages(null); super.onDestroy(); } diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index be3d81ff5..adbf791fb 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -473,19 +473,20 @@ public class PhotoView extends GLView { boolean isCenter = mPositionController.isCenter(); if (mLoadingState == LOADING_COMPLETE) { - if (mIsCamera) { - boolean full = !mFilmMode && isCenter - && mPositionController.isAtMinimalScale(); - if (full != mFullScreen) { - mFullScreen = full; - mListener.onFullScreenChanged(full); - } - } setTileViewPosition(r); PhotoView.super.render(canvas); } renderMessage(canvas, r.centerX(), r.centerY()); + if (mIsCamera) { + boolean full = !mFilmMode && isCenter + && mPositionController.isAtMinimalScale(); + if (full != mFullScreen) { + mFullScreen = full; + mListener.onFullScreenChanged(full); + } + } + // We want to have the following transitions: // (1) Move camera preview out of its place: switch to film mode // (2) Move camera preview into its place: switch to page mode @@ -502,9 +503,16 @@ public class PhotoView extends GLView { // setFilmMode(true); } else if (!mWasCameraCenter && isCameraCenter && mFilmMode) { setFilmMode(false); - } else if (isCameraCenter && !mFilmMode) { - // move into camera, lock - mListener.lockOrientation(); // Transition A + } + + if (isCenter && !mFilmMode) { + if (mIsCamera) { + // move into camera, lock + mListener.lockOrientation(); // Transition A + } else { + // move out of camera, unlock + mListener.unlockOrientation(); // Transition B + } } mWasCameraCenter = isCameraCenter; @@ -1152,7 +1160,6 @@ public class PhotoView extends GLView { if (offset == 1) { // move out of camera, unlock if (!mFilmMode) { - mListener.unlockOrientation(); // Transition B // Now the capture animation is done, enable the action bar. mListener.onActionBarAllowed(true); } -- 2.11.0