Merge "Show stitched panorama in secure album." into gb-ub-photos-arches
diff --git a/res/layout/photopage_bottom_controls.xml b/res/layout/photopage_bottom_controls.xml
index 5b80cf2..434c598 100644
--- a/res/layout/photopage_bottom_controls.xml
+++ b/res/layout/photopage_bottom_controls.xml
@@ -15,21 +15,18 @@
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentLeft="true"
+                android:layout_alignParentBottom="true"
                 android:paddingTop="5dp"
                 android:paddingBottom="5dp"
                 android:paddingLeft="15dp"
                 android:paddingRight="15dp"
                 android:visibility="gone"/>
-        <ImageButton
+        <ImageView
                 android:id="@+id/photopage_bottom_control_panorama"
                 android:src="@drawable/ic_menu_photosphere"
-                android:background="@drawable/photopage_bottom_button_background"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:paddingTop="5dp"
-                android:paddingBottom="5dp"
-                android:paddingLeft="15dp"
-                android:paddingRight="15dp"
+                android:layout_width="70dp"
+                android:layout_height="70dp"
+                android:layout_centerHorizontal="true"
+                android:layout_alignParentBottom="true"
                 android:visibility="gone"/>
 </RelativeLayout>
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index a219f51..cfc9aa0 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -295,19 +295,19 @@
                     }
                     case MSG_ON_CAMERA_CENTER: {
                         mSkipUpdateCurrentPhoto = false;
-                        boolean updateNeeded = false;
+                        boolean stayedOnCamera = false;
                         if (!mPhotoView.getFilmMode()) {
-                            lockOrientation();
-                            updateNeeded = true;
+                            stayedOnCamera = true;
                         } else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff &&
                                 mMediaSet.getMediaItemCount() > 1) {
                             mPhotoView.switchToImage(1);
                         } else {
                             mPhotoView.setFilmMode(false);
-                            updateNeeded = true;
+                            stayedOnCamera = true;
                         }
 
-                        if (updateNeeded) {
+                        if (stayedOnCamera) {
+                            lockOrientation();
                             updateBars();
                             updateCurrentPhoto(mModel.getMediaItem(0));
                         }
@@ -444,7 +444,7 @@
                             mCameraSwitchCutoff = SystemClock.uptimeMillis() +
                                     CAMERA_SWITCH_CUTOFF_THRESHOLD_MS;
                             mPhotoView.stopScrolling();
-                        } else if (oldIndex == 1 && mCurrentIndex == 0) {
+                        } else if (oldIndex >= 1 && mCurrentIndex == 0) {
                             mPhotoView.setWantPictureCenterCallbacks(true);
                             mSkipUpdateCurrentPhoto = true;
                         }
@@ -507,14 +507,18 @@
     }
 
     public boolean canDisplayBottomControls() {
-        return mShowBars && !mPhotoView.getFilmMode();
+        return mIsActive && !mPhotoView.getFilmMode();
     }
 
     public boolean canDisplayBottomControl(int control) {
         if (mCurrentPhoto == null) return false;
         switch(control) {
             case R.id.photopage_bottom_control_edit:
-                return mCurrentPhoto.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE;
+                return mHaveImageEditor && mShowBars
+                        && (mCurrentPhoto.getSupportedOperations()
+                        & MediaItem.SUPPORT_EDIT) != 0
+                        && mCurrentPhoto.getMediaType()
+                        == MediaObject.MEDIA_TYPE_IMAGE;
             case R.id.photopage_bottom_control_panorama:
                 return (mCurrentPhoto.getSupportedOperations()
                         & MediaItem.SUPPORT_PANORAMA) != 0;
@@ -1189,6 +1193,10 @@
         }
         mPhotoView.pause();
         mHandler.removeMessages(MSG_HIDE_BARS);
+        mHandler.removeMessages(MSG_REFRESH_BOTTOM_CONTROLS);
+        if (mBottomControls != null) {
+            mBottomControls.refresh();
+        }
         mActionBar.removeOnMenuVisibilityListener(mMenuVisibilityListener);
         if (mShowSpinner) {
             mActionBar.disableAlbumModeMenu(true);
@@ -1275,6 +1283,9 @@
         mActionBar.setDisplayOptions(
                 ((mSecureAlbum == null) && (mSetPathString != null)), false);
         mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener);
+        if (mBottomControls != null) {
+            mBottomControls.refresh();
+        }
         if (mShowSpinner) {
             mActionBar.enableAlbumModeMenu(
                     GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED, this);
diff --git a/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java b/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java
index f2b576f..5c246e8 100644
--- a/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java
+++ b/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java
@@ -16,6 +16,7 @@
 
 package com.android.gallery3d.ui;
 
+import com.android.gallery3d.R;
 import com.android.gallery3d.app.AbstractGalleryActivity;
 import com.android.gallery3d.app.AlbumSetDataLoader;
 import com.android.gallery3d.data.MediaObject;
@@ -29,6 +30,7 @@
     private final int mPlaceholderColor;
 
     private final ColorTexture mWaitLoadingTexture;
+    private final ResourceTexture mCameraOverlay;
     private final AbstractGalleryActivity mActivity;
     private final SelectionManager mSelectionManager;
     protected final LabelSpec mLabelSpec;
@@ -68,6 +70,8 @@
 
         mWaitLoadingTexture = new ColorTexture(mPlaceholderColor);
         mWaitLoadingTexture.setSize(1, 1);
+        mCameraOverlay = new ResourceTexture(activity,
+                R.drawable.frame_overlay_gallery_camera);
     }
 
     public void setPressedIndex(int index) {
@@ -122,6 +126,12 @@
     protected int renderOverlay(
             GLCanvas canvas, int index, AlbumSetEntry entry, int width, int height) {
         int renderRequestFlags = 0;
+        if (entry.album != null && entry.album.isCameraRoll()) {
+            int minDim = Math.min(width, height);
+            int dim = minDim / 2;
+            int pos = (minDim - dim) / 2;
+            mCameraOverlay.draw(canvas, pos, pos, dim, dim);
+        }
         if (mPressedIndex == index) {
             if (mAnimatePressedUp) {
                 drawPressedUpFrame(canvas, width, height);