Gallery2: Fix various issues and glitches

* Remove unnecessary navbar toggles, and add missing ones
* Modify picker dialog style
* Update main gallery layout so new bottom navigation works
  properly, and fix various other issues related to it
* Don't hide action bar in editor when adjusting effects, so
  we can see the values we adjust
* Update toolbar layout

Change-Id: I2a8f0b57ec874434c0fd0bb55de784b5d8379091
diff --git a/res/layout/action_mode.xml b/res/layout/action_mode.xml
index efa920d..186ce5b 100644
--- a/res/layout/action_mode.xml
+++ b/res/layout/action_mode.xml
@@ -24,6 +24,7 @@
     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="wrap_content"
             android:layout_height="match_parent">
+
         <ImageView android:layout_gravity="right|center_vertical"
                 android:layout_width="8dp"
                 android:layout_height="8dp"
@@ -33,7 +34,7 @@
                 android:divider="?android:attr/listDividerAlertDialog"
                 android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
                 android:textColor="@color/black_transparent_4"
-                android:textSize="20sp"
+                android:textSize="18sp"
                 android:singleLine="true"
                 android:gravity="start|center_vertical"
                 android:paddingEnd="15dip"
diff --git a/res/layout/gallery_main.xml b/res/layout/gallery_main.xml
index cd47ee3..749d5be 100755
--- a/res/layout/gallery_main.xml
+++ b/res/layout/gallery_main.xml
@@ -41,29 +41,32 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
-        <!-- MAIN CONTENT -->
         <RelativeLayout
             android:id="@+id/gallery_root"
             android:layout_width="match_parent"
-            android:layout_height="match_parent">
+            android:layout_height="match_parent"
+            android:layout_above="@+id/bottom_navigation">
 
-            <android.support.design.widget.BottomNavigationView
-                android:id="@+id/bottom_navigation"
-                android:elevation="8dp"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_alignParentBottom="true"
-                app:menu="@menu/navigation_items"
-                app:itemBackground="@color/primary"
-                app:itemIconTint="@drawable/item_bg"
-                app:itemTextColor="@drawable/item_bg" />
+            <!-- Toolbar -->
+            <include layout="@layout/toolbar" />
 
-            <include layout="@layout/gl_root_group"/>
+            <!-- Main content -->
+            <include layout="@layout/gl_root_group" />
+
         </RelativeLayout>
 
-        <!-- This layout will overlap all the others -->
-        <include
-            android:id="@+id/toolbar"
-            layout="@layout/toolbar"  />
+        <!-- Bottom bar -->
+        <android.support.design.widget.BottomNavigationView
+            android:id="@+id/bottom_navigation"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:background="@color/primary"
+            android:layout_alignParentBottom="true"
+            app:menu="@menu/navigation_items"
+            app:itemBackground="@color/primary"
+            app:itemIconTint="@drawable/item_bg"
+            app:itemTextColor="@drawable/item_bg" />
+
     </RelativeLayout>
+
 </LinearLayout>
diff --git a/res/layout/gl_root_group.xml b/res/layout/gl_root_group.xml
index eee2b49..6302171 100644
--- a/res/layout/gl_root_group.xml
+++ b/res/layout/gl_root_group.xml
@@ -19,8 +19,7 @@
     <RelativeLayout
         android:id="@+id/gl_parent_layout"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:layout_marginBottom="56dp">
+        android:layout_height="match_parent">
         <com.android.gallery3d.ui.GLRootView
             android:id="@+id/gl_root_view"
             android:layout_width="match_parent"
diff --git a/res/layout/popup_list_item.xml b/res/layout/popup_list_item.xml
index 0fad174..a2f7c31 100644
--- a/res/layout/popup_list_item.xml
+++ b/res/layout/popup_list_item.xml
@@ -19,12 +19,12 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
-    android:textSize="20sp"
+    android:textSize="18sp"
     android:textColor="@color/black_transparent_4"
     android:singleLine="true"
     android:gravity="center_vertical"
     android:paddingStart="16dp"
     android:paddingEnd="16dp"
-    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:minHeight="?android:attr/listPreferredItemHeightSmall"
     android:minWidth="196dp"
 />
diff --git a/res/layout/toolbar.xml b/res/layout/toolbar.xml
index 1617286..892f736 100755
--- a/res/layout/toolbar.xml
+++ b/res/layout/toolbar.xml
@@ -28,13 +28,18 @@
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 -->
 
-<Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="?android:attr/actionBarSize"
-    android:background="@color/primary"
-    android:elevation="8dp"
-    android:theme="@style/ToolbarTheme"
-    android:titleTextAppearance="@style/ToolbarTitleStyle"
-    android:popupTheme="@style/ToolbarPopUpTheme" >
+    android:layout_height="wrap_content"
+    android:theme="@style/ToolbarTheme">
 
-</Toolbar>
+    <Toolbar
+        android:id="@+id/toolbar"
+        android:layout_width="match_parent"
+        android:layout_height="?android:attr/actionBarSize"
+        android:background="@color/primary"
+        android:elevation="8dp"
+        android:titleTextAppearance="@style/ToolbarTitleStyle"
+        android:popupTheme="@style/ToolbarPopUpTheme" />
+
+</android.support.design.widget.AppBarLayout>
diff --git a/res/menu/albumset.xml b/res/menu/albumset.xml
index 603fb9b..b21bf3d 100644
--- a/res/menu/albumset.xml
+++ b/res/menu/albumset.xml
@@ -24,7 +24,7 @@
     <item android:id="@+id/action_select"
         android:icon="@drawable/ic_selection"
         android:title="@string/select_album"
-        android:showAsAction="never" />
+        android:showAsAction="ifRoom" />
     <item android:id="@+id/action_manage_offline"
             android:title="@string/make_available_offline"
             android:visible="false"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 429348e..9388e98 100755
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -32,7 +32,7 @@
     <color name="album_placeholder">@color/white</color>
 
     <!-- configuration for photo page -->
-    <color name="photo_background">@color/primary</color>
+    <color name="photo_background">@color/black</color>
     <color name="photo_placeholder">@color/light_black</color>
     <color name="photo_page_action_bar">#8A000000</color>
     <color name="photo_page_bottom_panel">#8A000000</color>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index dafe0d9..788339c 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -23,7 +23,7 @@
         <item name="switchStyle">@android:style/Widget.CompoundButton</item>
     </style>
 
-    <style name="Theme.Gallery.Dialog" parent="android:Theme.Holo.Dialog" />
+    <style name="Theme.Gallery.Dialog" parent="android:Theme.Material.Dialog" />
 
     <style name="Theme.Gallery" parent="android:Theme.Material.Light">
         <item name="android:colorPrimary">@color/primary</item>
@@ -66,7 +66,9 @@
         <item name="android:background">@null</item>
         <item name="android:src">@drawable/icn_media_play</item>
     </style>
-    <style name="DialogPickerTheme" parent="Theme.Gallery">
+    <style name="DialogPickerTheme" parent="android:Theme.Material">
+        <item name="android:colorPrimary">@color/primary</item>
+        <item name="android:colorPrimaryDark">@color/primaryDark</item>
     </style>
     <style name="Theme.ProxyLauncher" parent="@android:Theme.Translucent.NoTitleBar">
     </style>
@@ -319,8 +321,7 @@
         <item name="android:windowDisablePreview">true</item>
         <item name="android:windowDrawsSystemBarBackgrounds">true</item>
         <item name="android:windowBackground">@android:color/black</item>
-        <item name="android:statusBarColor">@android:color/transparent</item>
-        <item name="android:windowTranslucentStatus">true</item>
+        <item name="android:statusBarColor">#212121</item>
         <item name="android:windowTranslucentNavigation">false</item>
         <item name="android:windowActionBar">false</item>
         <item name="android:windowActionModeOverlay">true</item>
@@ -338,6 +339,8 @@
 
     <style name="ToolbarTheme" parent="android:Theme.Material" >
         <item name="android:actionOverflowButtonStyle">@style/WhiteOverflow</item>
+        <item name="colorPrimary">@color/primary</item>
+        <item name="colorPrimaryDark">@color/primaryDark</item>
     </style>
 
     <style name="ToolbarTitleStyle" parent="android:TextAppearance.Material.Widget.Toolbar.Title">
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java
index c3ef4c3..4f3f348 100644
--- a/src/com/android/gallery3d/app/AlbumPage.java
+++ b/src/com/android/gallery3d/app/AlbumPage.java
@@ -285,7 +285,10 @@
         if (mInCameraApp) {
             GalleryUtils.startGalleryActivity(mActivity);
         } else if (mActivity.getStateManager().getStateCount() > 1) {
-            ((GalleryActivity) mActivity).toggleNavBar(true);
+            Toolbar toolbar = mActivity.getToolbar();
+            if (toolbar != null) {
+                ((GalleryActivity) mActivity).toggleNavBar(true);
+            }
             super.onBackPressed();
         } else if (mParentMediaSetString != null) {
             Bundle data = new Bundle(getData());
@@ -797,10 +800,14 @@
             case SelectionManager.ENTER_SELECTION_MODE: {
                 mActionModeHandler.startActionMode();
                 performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
+                ((GalleryActivity) mActivity).toggleNavBar(false);
                 break;
             }
             case SelectionManager.LEAVE_SELECTION_MODE: {
                 mActionModeHandler.finishActionMode();
+                if (mActivity.getStateManager().getStateCount() <= 1) {
+                    ((GalleryActivity) mActivity).toggleNavBar(true);
+                }
                 mRootPane.invalidate();
                 updateMenuItem();
                 break;
diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java
index 2b87f97..7eaa2bc 100755
--- a/src/com/android/gallery3d/app/AlbumSetPage.java
+++ b/src/com/android/gallery3d/app/AlbumSetPage.java
@@ -278,6 +278,13 @@
     }
 
     private void pickAlbum(int slotIndex) {
+        if (mActivity.getStateManager().getStateCount() >= 1) {
+            android.widget.Toolbar toolbar = mActivity.getToolbar();
+            if (toolbar != null) {
+                ((GalleryActivity) mActivity).toggleNavBar(false);
+            }
+        }
+
         if (!mIsActive) return;
 
         MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex);
@@ -701,12 +708,12 @@
                 //mActionBar.disableClusterMenu(true);
                 mActionModeHandler.startActionMode();
                 performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
-                ((GalleryActivity)mActivity).toggleNavBar(false);
+                ((GalleryActivity) mActivity).toggleNavBar(false);
                 break;
             }
             case SelectionManager.LEAVE_SELECTION_MODE: {
                 mActionModeHandler.finishActionMode();
-                ((GalleryActivity)mActivity).toggleNavBar(true);
+                ((GalleryActivity) mActivity).toggleNavBar(true);
                 /*if (mShowClusterMenu) {
                     mActionBar.enableClusterMenu(mSelectedAction, this);
                 }*/
@@ -732,13 +739,11 @@
         mDetailsHelper.hide();
         mAlbumSetView.setHighlightItemPath(null);
         mSlotView.invalidate();
-        ((GalleryActivity)mActivity).toggleNavBar(true);
     }
 
     private void showDetails() {
         mShowDetails = true;
         if (mDetailsHelper == null) {
-            ((GalleryActivity)mActivity).toggleNavBar(false);
             mDetailsHelper = new DetailsHelper(mActivity, mRootPane, mDetailsSource);
             mDetailsHelper.setCloseListener(new CloseListener() {
                 @Override
diff --git a/src/com/android/gallery3d/app/GalleryActivity.java b/src/com/android/gallery3d/app/GalleryActivity.java
index d4b5087..0489237 100755
--- a/src/com/android/gallery3d/app/GalleryActivity.java
+++ b/src/com/android/gallery3d/app/GalleryActivity.java
@@ -206,13 +206,8 @@
         if (show) {
             mBottomNavigation.setVisibility(View.VISIBLE);
         } else {
-            mBottomNavigation.setVisibility(View.INVISIBLE);
+            mBottomNavigation.setVisibility(View.GONE);
         }
-
-        // Convert dp to pixels
-        float dp = getApplicationContext().getResources().getDisplayMetrics().density;
-
-        params.setMargins(0, 0, 0, show ? Math.round(56 * dp) : 0);
     }
 
     public void showScreen(int position) {
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index 76bd5db..6108c8e 100755
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -1025,7 +1025,6 @@
     @Override
     protected void onBackPressed() {
         showBars();
-        ((GalleryActivity)mActivity).toggleNavBar(true);
         if (mShowDetails) {
             hideDetails();
         } else if (mAppBridge == null || !switchWithCaptureAnimation(-1)) {
@@ -1044,7 +1043,7 @@
                 mActionBar.setBackGroundDefault();
                 int count = mActivity.getStateManager().getStateCount();
                 if (mIsFromVideoScreen || count == 1 || mIsFromTimelineScreen) {
-                    ((GalleryActivity)mActivity).toggleNavBar(true);
+                    ((GalleryActivity) mActivity).toggleNavBar(true);
                     if (mModel instanceof PhotoDataAdapter) {
                         ((PhotoDataAdapter) mModel).setDataListener(null);
                     }
@@ -1669,7 +1668,7 @@
         mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener);
         refreshBottomControlsWhenReady();
         if (((mSecureAlbum == null) && (mSetPathString != null))) {
-            ((GalleryActivity)mActivity).toggleNavBar(false);
+            ((GalleryActivity) mActivity).toggleNavBar(false);
         }
         // if (mShowSpinner && mPhotoView.getFilmMode()) {
         // mActionBar.enableAlbumModeMenu(
diff --git a/src/com/android/gallery3d/app/SlideshowPage.java b/src/com/android/gallery3d/app/SlideshowPage.java
index 2923ee9..29df606 100644
--- a/src/com/android/gallery3d/app/SlideshowPage.java
+++ b/src/com/android/gallery3d/app/SlideshowPage.java
@@ -176,7 +176,9 @@
     @Override
     public void onPause() {
         super.onPause();
-        ((GalleryActivity) mActivity).toggleNavBar(true);
+        if (mActivity.getStateManager().getStateCount() <= 1) {
+            ((GalleryActivity) mActivity).toggleNavBar(true);
+        }
         mIsActive = false;
         mModel.pause();
         mSlideshowView.release();
diff --git a/src/com/android/gallery3d/app/TimeLinePage.java b/src/com/android/gallery3d/app/TimeLinePage.java
index 7810a15..a9abc81 100755
--- a/src/com/android/gallery3d/app/TimeLinePage.java
+++ b/src/com/android/gallery3d/app/TimeLinePage.java
@@ -697,12 +697,12 @@
             case SelectionManager.ENTER_SELECTION_MODE: {
                 mActionModeHandler.startActionMode();
                 performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
-                ((GalleryActivity)mActivity).toggleNavBar(false);
+                ((GalleryActivity) mActivity).toggleNavBar(false);
                 break;
             }
             case SelectionManager.LEAVE_SELECTION_MODE: {
                 mActionModeHandler.finishActionMode();
-                ((GalleryActivity)mActivity).toggleNavBar(true);
+                ((GalleryActivity) mActivity).toggleNavBar(true);
                 mRootPane.invalidate();
                 break;
             }
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index bc8f7d8..5b1aa84 100755
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -436,8 +436,6 @@
         if (mCurrentEditor.showsActionBar()) {
             setActionBar();
             showActionBar(true);
-        } else {
-            showActionBar(false);
         }
 
         if (representation.getFilterType() == FilterRepresentation.TYPE_WATERMARK_CATEGORY) {