OSDN Git Service

Grid/filmstrip switching behavior improvements
authorBobby Georgescu <georgescu@google.com>
Wed, 19 Sep 2012 23:51:05 +0000 (16:51 -0700)
committerBobby Georgescu <georgescu@google.com>
Tue, 25 Sep 2012 18:22:18 +0000 (11:22 -0700)
Bug: 7200453
Bug: 7196483
Bug: 7222179
Bug: 7224619

Changes:
- Launch camera in capture even if paused in grid/filmstrip
- Fixed behavior of filmstrip button after launching grid
  from camera
- Refresh bar timeouts after swiping a photo
- Partially swiping from camera to filmstrip without lifting
  finger and then swiping back no longer results in unwanted
  switch to filmstrip
- Removed hacky solution to switching to filmstrip mode

Change-Id: I5cdde927e6a27a03b99a7f4883c5601bc281f4c8

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

index 9bb2c37..30682a1 100644 (file)
@@ -100,6 +100,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
     private float mUserDistance; // in pixel
     private Future<Integer> mSyncTask = null;
     private boolean mLaunchedFromPhotoPage;
+    private boolean mInCameraApp;
 
     private int mLoadingBits = 0;
     private boolean mInitialSynced = false;
@@ -201,6 +202,11 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
         } else if (mSelectionManager.inSelectionMode()) {
             mSelectionManager.leaveSelectionMode();
         } else {
+            if(mLaunchedFromPhotoPage) {
+                mActivity.getTransitionStore().putIfNotPresent(
+                        PhotoPage.KEY_ALBUMPAGE_TRANSITION,
+                        PhotoPage.MSG_ALBUMPAGE_RESUMED);
+            }
             // TODO: fix this regression
             // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
             onUpPressed();
@@ -359,6 +365,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
 
         mLaunchedFromPhotoPage =
                 mActivity.getStateManager().hasStateClass(PhotoPage.class);
+        mInCameraApp = data.getBoolean(PhotoPage.KEY_APP_BRIDGE, false);
 
         // Don't show animation if it is restored or switched from filmstrip
         if (!mLaunchedFromPhotoPage && restoreState == null && data != null) {
@@ -417,6 +424,14 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
             clearLoadingBit(BIT_LOADING_SYNC);
         }
         mActionModeHandler.pause();
+
+        // The camera app should always launch in capture mode when
+        // resumed, so make the next resume faster by closing the grid
+        // view now
+        if (mInCameraApp) {
+            if (mActivity.getStateManager().getTopState() == this)
+                mActivity.getStateManager().finishState(this);
+        }
     }
 
     @Override
@@ -530,11 +545,11 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
 
     private void prepareAnimationBackToFilmstrip(int slotIndex) {
         if (mAlbumDataAdapter == null || !mAlbumDataAdapter.isActive(slotIndex)) return;
+        MediaItem item = mAlbumDataAdapter.get(slotIndex);
+        if (item == null) return;
         PreparePageFadeoutTexture.prepareFadeOutTexture(mActivity, mRootPane);
         TransitionStore transitions = mActivity.getTransitionStore();
         transitions.put(PhotoPage.KEY_INDEX_HINT, slotIndex);
-        transitions.put(PhotoPage.KEY_MEDIA_ITEM_PATH,
-                mAlbumDataAdapter.get(slotIndex).getPath());
         transitions.put(PhotoPage.KEY_OPEN_ANIMATION_RECT,
                 mSlotView.getSlotRect(slotIndex, mRootPane));
     }
@@ -571,9 +586,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
                 int targetPhoto = mSlotView.getVisibleStart();
                 prepareAnimationBackToFilmstrip(targetPhoto);
                 if(mLaunchedFromPhotoPage) {
-                    mActivity.getTransitionStore().put(
-                            PhotoPage.KEY_ALBUMPAGE_TRANSITION,
-                            PhotoPage.MSG_ALBUMPAGE_RESUMED);
                     onBackPressed();
                 } else {
                     pickPhoto(targetPhoto, true);
index 46a04f0..ea7e839 100644 (file)
@@ -307,7 +307,6 @@ public class PhotoPage extends ActivityState implements
         if (mSetPathString != null) {
             mAppBridge = (AppBridge) data.getParcelable(KEY_APP_BRIDGE);
             if (mAppBridge != null) {
-                mFlags |= FLAG_HIDE_ACTION_BAR | FLAG_HIDE_STATUS_BAR;
                 mShowBars = false;
 
                 mAppBridge.setServer(this);
@@ -375,12 +374,22 @@ public class PhotoPage extends ActivityState implements
 
                 @Override
                 public void onPhotoChanged(int index, Path item) {
+                    int oldIndex = mCurrentIndex;
                     mCurrentIndex = index;
                     if (item != null) {
                         MediaItem photo = mModel.getMediaItem(0);
                         if (photo != null) updateCurrentPhoto(photo);
                     }
+                    if (mAppBridge != null) {
+                        if (oldIndex == 0 && mCurrentIndex > 0
+                                && !mPhotoView.getFilmMode()) {
+                            mPhotoView.setFilmMode(true);
+                        }
+                    }
                     updateBars();
+
+                    // Reset the timeout for the bars after a swipe
+                    refreshHidingMessage();
                 }
 
                 @Override
@@ -766,11 +775,19 @@ public class PhotoPage extends ActivityState implements
                     data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
                             mActivity.getDataManager().getTopSetPath(
                                     DataManager.INCLUDE_ALL));
+
                     // We only show cluster menu in the first AlbumPage in stack
+                    // TODO: Enable this when running from the camera app
                     boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class);
-                    data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum);
-                    mActivity.getTransitionStore().put(
-                            KEY_RETURN_INDEX_HINT, mCurrentIndex);
+                    data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum
+                            && mAppBridge == null);
+
+                    data.putBoolean(PhotoPage.KEY_APP_BRIDGE, mAppBridge != null);
+
+                    // Account for live preview being first item
+                    mActivity.getTransitionStore().put(KEY_RETURN_INDEX_HINT,
+                            mAppBridge != null ? mCurrentIndex - 1 : mCurrentIndex);
+
                     mActivity.getStateManager().startState(AlbumPage.class, data);
                 }
                 return true;
@@ -1108,19 +1125,32 @@ public class PhotoPage extends ActivityState implements
     private void transitionFromAlbumPageIfNeeded() {
         TransitionStore transitions = mActivity.getTransitionStore();
 
-        int resumeIndex = transitions.get(KEY_INDEX_HINT, -1);
-        if (resumeIndex >= 0) {
-            mCurrentIndex = resumeIndex;
-            mModel.setCurrentPhoto((Path)transitions.get(KEY_MEDIA_SET_PATH), mCurrentIndex);
-            mPhotoView.switchToImage(mCurrentIndex);
-        }
-
         int albumPageTransition = transitions.get(
                 KEY_ALBUMPAGE_TRANSITION, MSG_ALBUMPAGE_NONE);
 
-        if(albumPageTransition != MSG_ALBUMPAGE_NONE) {
-            mPhotoView.setFilmMode(mStartInFilmstrip
-                    && albumPageTransition == MSG_ALBUMPAGE_RESUMED);
+        if (albumPageTransition == MSG_ALBUMPAGE_NONE && mAppBridge != null) {
+            // Generally, resuming the PhotoPage when in Camera should
+            // reset to the capture mode to allow quick photo taking
+            mCurrentIndex = 0;
+            mPhotoView.resetToFirstPicture();
+        } else {
+            int resumeIndex = transitions.get(KEY_INDEX_HINT, -1);
+            if (resumeIndex >= 0) {
+                if (mAppBridge != null) {
+                    // Account for live preview being the first item
+                    resumeIndex++;
+                }
+                if (resumeIndex < mMediaSet.getMediaItemCount()) {
+                    mCurrentIndex = resumeIndex;
+                    mModel.moveTo(mCurrentIndex);
+                }
+            }
+        }
+
+        if (albumPageTransition == MSG_ALBUMPAGE_RESUMED) {
+            mPhotoView.setFilmMode(mStartInFilmstrip || mAppBridge != null);
+        } else if (albumPageTransition == MSG_ALBUMPAGE_PICKED) {
+            mPhotoView.setFilmMode(false);
         }
 
         mFadeOutTexture = transitions.get(PreparePageFadeoutTexture.KEY_FADE_TEXTURE);
@@ -1155,10 +1185,11 @@ public class PhotoPage extends ActivityState implements
         mActionBar.setDisplayOptions(
                 ((mSecureAlbum == null) && (mSetPathString != null)), true);
         mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener);
-
-        if (mAppBridge != null && !mHasActivityResult) {
-            mPhotoView.resetToFirstPicture();
+        if (!mShowBars) {
+            mActionBar.hide();
+            mActivity.getGLRoot().setLightsOutMode(true);
         }
+
         mHasActivityResult = false;
         mHandler.sendEmptyMessageDelayed(MSG_UNFREEZE_GLROOT, UNFREEZE_GLROOT_TIMEOUT);
     }
index f1d3f01..aa38ed7 100644 (file)
@@ -25,6 +25,10 @@ public class TransitionStore {
         mStorage.put(key, value);
     }
 
+    public <T> void putIfNotPresent(Object key, T valueIfNull) {
+        mStorage.put(key, get(key, valueIfNull));
+    }
+
     @SuppressWarnings("unchecked")
     public <T> T get(Object key) {
         return (T) mStorage.get(key);
index b30d70a..1cd5e26 100644 (file)
@@ -568,7 +568,6 @@ public class PhotoView extends GLView {
         private boolean mIsDeletable;
         private int mLoadingState = Model.LOADING_INIT;
         private Size mSize = new Size();
-        private boolean mWasCameraCenter;
 
         @Override
         public void reload() {
@@ -612,7 +611,6 @@ public class PhotoView extends GLView {
             mSize.height = getRotated(mRotation, h, w);
         }
 
-        private boolean mNeedToChangeToFilmstripWhenCentered = false;
         @Override
         public void draw(GLCanvas canvas, Rect r) {
             drawTileView(canvas, r);
@@ -629,26 +627,10 @@ public class PhotoView extends GLView {
             boolean isCenter = mPositionController.isCenter();
             boolean isCameraCenter = mIsCamera && isCenter && !canUndoLastPicture();
 
-            if (mWasCameraCenter && mIsCamera && !isCenter && !mFilmMode) {
-                setFilmMode(false);
-                mNeedToChangeToFilmstripWhenCentered = true;
-            } else if (isCenter && mNeedToChangeToFilmstripWhenCentered) {
-                setFilmMode(true);
-                mNeedToChangeToFilmstripWhenCentered = false;
-            }
-            /*
-            TODO: Come out of film mode if it was a short swipe rather than a fling
-            else if (!mWasCameraCenter && isCameraCenter && mFilmMode) {
-                setFilmMode(false);
-            }
-            */
-
             if (isCameraCenter && !mFilmMode) {
                 // Move into camera in page mode, lock
                 mListener.lockOrientation();
             }
-
-            mWasCameraCenter = isCameraCenter;
         }
 
         @Override
@@ -1279,6 +1261,18 @@ public class PhotoView extends GLView {
         mGestureListener.setSwipingEnabled(enabled);
     }
 
+    private void updateActionBar() {
+        boolean isCamera = mPictures.get(0).isCamera();
+        if (isCamera && !mFilmMode) {
+            // Move into camera in page mode, lock
+            mListener.lockOrientation();
+            mListener.onActionBarAllowed(false);
+        } else {
+            mListener.onActionBarAllowed(true);
+            if (mFilmMode) mListener.onActionBarWanted();
+        }
+    }
+
     public void setFilmMode(boolean enabled) {
         if (mFilmMode == enabled) return;
         mFilmMode = enabled;
@@ -1286,16 +1280,8 @@ public class PhotoView extends GLView {
         mModel.setNeedFullImage(!enabled);
         mModel.setFocusHintDirection(
                 mFilmMode ? Model.FOCUS_HINT_PREVIOUS : Model.FOCUS_HINT_NEXT);
+        updateActionBar();
         mListener.onFilmModeChanged(enabled);
-        boolean isCamera = mPictures.get(0).isCamera();
-        if (isCamera && !enabled) {
-            // Move into camera in page mode, lock
-            mListener.lockOrientation();
-            mListener.onActionBarAllowed(false);
-        } else {
-            mListener.onActionBarAllowed(true);
-            if (enabled) mListener.onActionBarWanted();
-        }
     }
 
     public boolean getFilmMode() {
@@ -1322,7 +1308,6 @@ public class PhotoView extends GLView {
     // move to the camera preview and show controls after resume
     public void resetToFirstPicture() {
         mModel.moveTo(0);
-        mListener.onActionBarAllowed(false);
         setFilmMode(false);
     }