OSDN Git Service

Show/hide action bar at the right time.
authorChih-Chung Chang <chihchung@google.com>
Wed, 2 May 2012 12:05:16 +0000 (20:05 +0800)
committerChih-Chung Chang <chihchung@google.com>
Thu, 3 May 2012 05:12:15 +0000 (13:12 +0800)
Bug: 6399476

Change-Id: I5046b2e73822ebadd94680f61d87db183b40b5c2

src/com/android/gallery3d/app/PhotoPage.java
src/com/android/gallery3d/ui/PhotoView.java

index a43034c..76d4f91 100644 (file)
@@ -56,18 +56,17 @@ import com.android.gallery3d.ui.PhotoView;
 import com.android.gallery3d.ui.ScreenNail;
 import com.android.gallery3d.ui.SelectionManager;
 import com.android.gallery3d.ui.SynchronizedHandler;
-import com.android.gallery3d.ui.UserInteractionListener;
 import com.android.gallery3d.util.GalleryUtils;
 
 public class PhotoPage extends ActivityState implements
-        PhotoView.Listener, UserInteractionListener,
-        OrientationManager.Listener, AppBridge.Server {
+        PhotoView.Listener, OrientationManager.Listener, AppBridge.Server {
     private static final String TAG = "PhotoPage";
 
     private static final int MSG_HIDE_BARS = 1;
     private static final int MSG_LOCK_ORIENTATION = 2;
     private static final int MSG_UNLOCK_ORIENTATION = 3;
     private static final int MSG_ON_FULL_SCREEN_CHANGED = 4;
+    private static final int MSG_UPDATE_ACTION_BAR = 5;
 
     private static final int HIDE_BARS_TIMEOUT = 3500;
 
@@ -101,10 +100,10 @@ public class PhotoPage extends ActivityState implements
     private int mCurrentIndex = 0;
     private Handler mHandler;
     private boolean mShowBars = true;
+    private volatile boolean mActionBarAllowed = true;
     private GalleryActionBar mActionBar;
     private MyMenuVisibilityListener mMenuVisibilityListener;
     private boolean mIsMenuVisible;
-    private boolean mIsInteracting;
     private MediaItem mCurrentPhoto = null;
     private MenuExecutor mMenuExecutor;
     private boolean mIsActive;
@@ -200,6 +199,7 @@ public class PhotoPage extends ActivityState implements
 
                 // Action bar should not be displayed when camera starts.
                 mFlags |= FLAG_HIDE_ACTION_BAR;
+                mShowBars = false;
             }
 
             mMediaSet = mActivity.getDataManager().getMediaSet(mSetPathString);
@@ -222,6 +222,7 @@ public class PhotoPage extends ActivityState implements
                         MediaItem photo = mModel.getCurrentMediaItem();
                         if (photo != null) updateCurrentPhoto(photo);
                     }
+                    updateBars();
                 }
 
                 @Override
@@ -269,6 +270,10 @@ public class PhotoPage extends ActivityState implements
                         mAppBridge.onFullScreenChanged(message.arg1 == 1);
                         break;
                     }
+                    case MSG_UPDATE_ACTION_BAR: {
+                        updateBars();
+                        break;
+                    }
                     default: throw new AssertionError(message.what);
                 }
             }
@@ -304,8 +309,6 @@ public class PhotoPage extends ActivityState implements
         mCurrentPhoto = photo;
         if (mCurrentPhoto == null) return;
         updateMenuOperations();
-        // Hide the action bar when going back to camera preview.
-        if (photo == mScreenNailItem) hideBars();
         updateTitle();
         if (mShowDetails) {
             mDetailsHelper.reloadDetails(mModel.getCurrentIndex());
@@ -356,62 +359,58 @@ public class PhotoPage extends ActivityState implements
         return true;
     }
 
+    //////////////////////////////////////////////////////////////////////////
+    //  Action Bar show/hide management
+    //////////////////////////////////////////////////////////////////////////
+
     private void showBars() {
         if (mShowBars) return;
         mShowBars = true;
         mActionBar.show();
-        WindowManager.LayoutParams params = ((Activity) mActivity).getWindow().getAttributes();
+        WindowManager.LayoutParams params =
+                ((Activity) mActivity).getWindow().getAttributes();
         params.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
         ((Activity) mActivity).getWindow().setAttributes(params);
+        refreshHidingMessage();
     }
 
     private void hideBars() {
         if (!mShowBars) return;
         mShowBars = false;
         mActionBar.hide();
-        WindowManager.LayoutParams params = ((Activity) mActivity).getWindow().getAttributes();
+        WindowManager.LayoutParams params =
+                ((Activity) mActivity).getWindow().getAttributes();
         params.systemUiVisibility = View. SYSTEM_UI_FLAG_LOW_PROFILE;
         ((Activity) mActivity).getWindow().setAttributes(params);
+        mHandler.removeMessages(MSG_HIDE_BARS);
     }
 
     private void refreshHidingMessage() {
         mHandler.removeMessages(MSG_HIDE_BARS);
-        if (!mIsMenuVisible && !mIsInteracting) {
+        if (!mIsMenuVisible) {
             mHandler.sendEmptyMessageDelayed(MSG_HIDE_BARS, HIDE_BARS_TIMEOUT);
         }
     }
 
-    @Override
-    public void onUserInteraction() {
-        showBars();
-        refreshHidingMessage();
-    }
-
-    public void onUserInteractionTap() {
+    private void toggleBars() {
         if (mShowBars) {
             hideBars();
-            mHandler.removeMessages(MSG_HIDE_BARS);
-        } else {
+        } else if (canShowBars()) {
             showBars();
-            refreshHidingMessage();
         }
     }
 
-    @Override
-    public void onUserInteractionBegin() {
-        showBars();
-        mIsInteracting = true;
-        refreshHidingMessage();
+    private void updateBars() {
+        if (canShowBars()) {
+            showBars();
+        } else {
+            hideBars();
+        }
     }
 
-    @Override
-    public void onUserInteractionEnd() {
-        mIsInteracting = false;
-
-        // This function could be called from GL thread (in SlotView.render)
-        // and post to the main thread. So, it could be executed while the
-        // activity is paused.
-        if (mIsActive) refreshHidingMessage();
+    private boolean canShowBars() {
+        boolean atCamera = mAppBridge != null && mCurrentIndex == 0;
+        return mActionBarAllowed && !atCamera;
     }
 
     @Override
@@ -475,7 +474,6 @@ public class PhotoPage extends ActivityState implements
         mShareActionProvider = GalleryActionBar.initializeShareActionProvider(menu);
         if (mPendingSharePath != null) updateShareURI(mPendingSharePath);
         mMenu = menu;
-        mShowBars = true;
         updateMenuOperations();
         updateTitle();
         return true;
@@ -608,7 +606,7 @@ public class PhotoPage extends ActivityState implements
         if (playVideo) {
             playVideo((Activity) mActivity, item.getPlayUri(), item.getName());
         } else {
-            onUserInteractionTap();
+            toggleBars();
         }
     }
 
@@ -623,6 +621,12 @@ public class PhotoPage extends ActivityState implements
     }
 
     @Override
+    public void onActionBarAllowed(boolean allowed) {
+        mActionBarAllowed = allowed;
+        mHandler.sendEmptyMessage(MSG_UPDATE_ACTION_BAR);
+    }
+
+    @Override
     public void onFullScreenChanged(boolean full) {
         Message m = mHandler.obtainMessage(
                 MSG_ON_FULL_SCREEN_CHANGED, full ? 1 : 0, 0);
@@ -710,7 +714,6 @@ public class PhotoPage extends ActivityState implements
         mActionBar.setDisplayOptions(mSetPathString != null, true);
         mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener);
 
-        onUserInteraction();
         if (mAppBridge != null) {
             mAppBridge.setServer(this);
             mPhotoView.resetToFirstPicture();
index c6b370d..be3d81f 100644 (file)
@@ -74,6 +74,7 @@ public class PhotoView extends GLView {
         public void lockOrientation();
         public void unlockOrientation();
         public void onFullScreenChanged(boolean full);
+        public void onActionBarAllowed(boolean allowed);
     }
 
     // Here is a graph showing the places we need to lock/unlock device
@@ -755,6 +756,7 @@ public class PhotoView extends GLView {
 
         @Override
         public boolean onDoubleTap(float x, float y) {
+            if (mPictures.get(0).isCamera()) return false;
             PositionController controller = mPositionController;
             float scale = controller.getImageScale();
             // onDoubleTap happened on the second ACTION_DOWN.
@@ -892,6 +894,7 @@ public class PhotoView extends GLView {
         mFilmMode = enabled;
         mPositionController.setFilmMode(mFilmMode);
         mModel.setNeedFullImage(!enabled);
+        mListener.onActionBarAllowed(!enabled);
 
         // If we leave filmstrip mode, we should lock/unlock
         if (!enabled) {
@@ -1127,6 +1130,8 @@ public class PhotoView extends GLView {
         if (mHolding != 0) return true;
         if (offset == 1) {
             if (mNextBound <= 0) return false;
+            // Temporary disable action bar until the capture animation is done.
+            if (!mFilmMode) mListener.onActionBarAllowed(false);
             switchToNextImage();
             mPositionController.startCaptureAnimationSlide(-1);
         } else if (offset == -1) {
@@ -1146,7 +1151,11 @@ public class PhotoView extends GLView {
         mHolding &= ~HOLD_CAPTURE_ANIMATION;
         if (offset == 1) {
             // move out of camera, unlock
-            if (!mFilmMode) mListener.unlockOrientation();  // Transition B
+            if (!mFilmMode) {
+                mListener.unlockOrientation();  // Transition B
+                // Now the capture animation is done, enable the action bar.
+                mListener.onActionBarAllowed(true);
+            }
         }
         snapback();
     }