Merge "Update some UI in PhotoPicker" into sc-mainline-prod
diff --git a/res/layout/fragment_picker_tab.xml b/res/layout/fragment_picker_tab.xml
index a62f21f..17960f9 100644
--- a/res/layout/fragment_picker_tab.xml
+++ b/res/layout/fragment_picker_tab.xml
@@ -70,9 +70,9 @@
         <Button
             android:id="@+id/button_add"
             android:layout_width="wrap_content"
-            android:layout_height="match_parent"
+            android:layout_height="wrap_content"
             android:layout_marginHorizontal="@dimen/picker_bottom_bar_horizontal_gap"
-            android:layout_gravity="end"
+            android:layout_gravity="end|center_vertical"
             android:paddingVertical="@dimen/picker_bottom_bar_vertical_gap"
             android:text="@string/add"
             android:textAllCaps="false"
diff --git a/res/layout/fragment_preview.xml b/res/layout/fragment_preview.xml
index f2cab22..ede43a1 100644
--- a/res/layout/fragment_preview.xml
+++ b/res/layout/fragment_preview.xml
@@ -27,24 +27,28 @@
 
     <!-- Adds scrim for Toolbar -->
     <FrameLayout
+        android:id="@+id/preview_top_scrim"
         android:layout_width="match_parent"
         android:layout_height="@dimen/preview_toolbar_scrim_height"
         android:background="@drawable/preview_gradient_desc"
-        android:layout_gravity="top"/>
+        android:layout_gravity="top"
+        android:visibility="gone"/>
 
     <!-- Adds scrim for deselect and Add button -->
     <FrameLayout
+        android:id="@+id/preview_bottom_scrim"
         android:layout_width="match_parent"
         android:layout_height="@dimen/preview_deselect_scrim_height"
         android:background="@drawable/preview_gradient_asc"
-        android:layout_gravity="bottom"/>
+        android:layout_gravity="bottom"
+        android:visibility="gone"/>
 
     <FrameLayout
-        android:layout_marginHorizontal="@dimen/preview_buttons_margin_horizontal"
+        android:id="@+id/preview_bottom_bar"
         android:layout_gravity="bottom"
-        android:layout_marginBottom="@dimen/preview_buttons_margin_bottom"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content">
+        android:layout_height="@dimen/picker_bottom_bar_size"
+        android:paddingHorizontal="@dimen/preview_buttons_padding_horizontal">
 
         <Button
             android:id="@+id/preview_select_check_button"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 2337f98..1be725e 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -34,6 +34,7 @@
     <color name="picker_item_gradient_color">#42000000</color>
     <color name="preview_gradient_color_light">@android:color/transparent</color>
     <color name="preview_gradient_color_dark">#80202124</color>
+    <color name="preview_scrim_solid_color">#E6000000</color> <!-- 90% opacity black -->
 
     <!-- PhotoPicker Preview -->
     <color name="preview_default_blue">#8AB4F8</color>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 423f6ac..eb9d42c 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -57,8 +57,7 @@
     <dimen name="picker_chip_radius">16dp</dimen>
 
     <!-- PhotoPicker Preview -->
-    <dimen name="preview_buttons_margin_horizontal">16dp</dimen>
-    <dimen name="preview_buttons_margin_bottom">10dp</dimen>
+    <dimen name="preview_buttons_padding_horizontal">16dp</dimen>
     <dimen name="preview_deselect_padding_start">2dp</dimen>
     <dimen name="preview_viewpager_margin">20dp</dimen>
     <!-- PhotoPicker Preview text -->
diff --git a/src/com/android/providers/media/photopicker/PhotoPickerActivity.java b/src/com/android/providers/media/photopicker/PhotoPickerActivity.java
index b1fb7c3..885722e 100644
--- a/src/com/android/providers/media/photopicker/PhotoPickerActivity.java
+++ b/src/com/android/providers/media/photopicker/PhotoPickerActivity.java
@@ -380,8 +380,13 @@
         // 2. Set the toolbar color
         final ColorDrawable toolbarColor;
         if (isPreview && !shouldShowTabChips) {
-            // Preview defaults to black color irrespective of if it should show tab chips or not
-            toolbarColor = new ColorDrawable(getColor(android.R.color.transparent));
+            if (isOrientationLandscape()) {
+                // Toolbar in Preview will have transparent color in Landscape mode.
+                toolbarColor = new ColorDrawable(getColor(android.R.color.transparent));
+            } else {
+                // Toolbar in Preview will have a solid color with 90% opacity in Portrait mode.
+                toolbarColor = new ColorDrawable(getColor(R.color.preview_scrim_solid_color));
+            }
         } else {
             toolbarColor = new ColorDrawable(getColor(R.color.picker_background_color));
         }
diff --git a/src/com/android/providers/media/photopicker/ui/PreviewFragment.java b/src/com/android/providers/media/photopicker/ui/PreviewFragment.java
index d9a16de..d96942b 100644
--- a/src/com/android/providers/media/photopicker/ui/PreviewFragment.java
+++ b/src/com/android/providers/media/photopicker/ui/PreviewFragment.java
@@ -17,6 +17,8 @@
 package com.android.providers.media.photopicker.ui;
 
 import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Color;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.util.Log;
@@ -103,6 +105,31 @@
                 getResources().getDimensionPixelSize(R.dimen.preview_viewpager_margin)));
 
         setUpPreviewLayout(view, getArguments());
+        setupScrimLayerAndBottomBar(view);
+    }
+
+    private void setupScrimLayerAndBottomBar(View fragmentView) {
+        final boolean isLandscape = getResources().getConfiguration().orientation
+                == Configuration.ORIENTATION_LANDSCAPE;
+
+        // Show the scrim layers in Landscape mode. The default visibility is GONE.
+        if (isLandscape) {
+            final View topScrim = fragmentView.findViewById(R.id.preview_top_scrim);
+            topScrim.setVisibility(View.VISIBLE);
+
+            final View bottomScrim = fragmentView.findViewById(R.id.preview_bottom_scrim);
+            bottomScrim.setVisibility(View.VISIBLE);
+        }
+
+        // Set appropriate background color for the bottom bar
+        final int bottomBarColor;
+        if (isLandscape) {
+            bottomBarColor = Color.TRANSPARENT;
+        } else {
+            bottomBarColor = getContext().getColor(R.color.preview_scrim_solid_color);
+        }
+        final View bottomBar = fragmentView.findViewById(R.id.preview_bottom_bar);
+        bottomBar.setBackgroundColor(bottomBarColor);
     }
 
     private void setUpPreviewLayout(@NonNull View view, @Nullable Bundle args) {
@@ -132,7 +159,7 @@
      */
     private void setUpPreviewLayoutForLongPress(@NonNull Button addOrSelectButton,
             @NonNull Button selectCheckButton) {
-        LayoutParams layoutParams
+        final LayoutParams layoutParams
                 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
         addOrSelectButton.setLayoutParams(layoutParams);
 
diff --git a/tests/src/com/android/providers/media/photopicker/espresso/PreviewSingleSelectTest.java b/tests/src/com/android/providers/media/photopicker/espresso/PreviewSingleSelectTest.java
index 8e048f5..bee2414 100644
--- a/tests/src/com/android/providers/media/photopicker/espresso/PreviewSingleSelectTest.java
+++ b/tests/src/com/android/providers/media/photopicker/espresso/PreviewSingleSelectTest.java
@@ -16,6 +16,8 @@
 
 package com.android.providers.media.photopicker.espresso;
 
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+
 import static androidx.test.espresso.Espresso.onView;
 import static androidx.test.espresso.action.ViewActions.click;
 import static androidx.test.espresso.assertion.ViewAssertions.matches;
@@ -28,9 +30,18 @@
 
 import static com.android.providers.media.photopicker.espresso.RecyclerViewTestUtils.longClickItem;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import static org.hamcrest.Matchers.allOf;
 import static org.hamcrest.Matchers.not;
 
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.view.View;
+
+import androidx.appcompat.widget.Toolbar;
 import androidx.test.espresso.Espresso;
 import androidx.test.espresso.IdlingRegistry;
 import androidx.test.ext.junit.rules.ActivityScenarioRule;
@@ -131,12 +142,75 @@
                 .check(matches(isDisplayed()));
     }
 
+    @Test
+    public void testPreview_noScrimLayerAndHasSolidColorInPortrait() {
+        mRule.getScenario().onActivity(activity -> {
+            assertThat(activity.getResources().getConfiguration().orientation).isEqualTo(
+                    Configuration.ORIENTATION_PORTRAIT);
+        });
+
+        onView(withId(PICKER_TAB_RECYCLERVIEW_ID)).check(matches(isDisplayed()));
+        // Navigate to preview
+        longClickItem(PICKER_TAB_RECYCLERVIEW_ID, IMAGE_POSITION, ICON_THUMBNAIL_ID);
+
+        registerIdlingResourceAndWaitForIdle();
+
+        onView(withId(R.id.preview_top_scrim)).check(matches(not(isDisplayed())));
+        onView(withId(R.id.preview_bottom_scrim)).check(matches(not(isDisplayed())));
+
+        mRule.getScenario().onActivity(activity -> {
+            assertBackgroundColorOnToolbarAndBottomBar(activity, R.color.preview_scrim_solid_color);
+        });
+    }
+
+    @Test
+    public void testPreview_showScrimLayerInLandscape() {
+        mRule.getScenario().onActivity(activity -> {
+            activity.setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE);
+        });
+
+        mRule.getScenario().onActivity(activity -> {
+            assertThat(activity.getResources().getConfiguration().orientation).isEqualTo(
+                    Configuration.ORIENTATION_LANDSCAPE);
+        });
+
+        onView(withId(PICKER_TAB_RECYCLERVIEW_ID)).check(matches(isDisplayed()));
+
+        // Navigate to preview
+        longClickItem(PICKER_TAB_RECYCLERVIEW_ID, IMAGE_POSITION, ICON_THUMBNAIL_ID);
+
+        registerIdlingResourceAndWaitForIdle();
+
+        onView(withId(R.id.preview_top_scrim)).check(matches(isDisplayed()));
+        onView(withId(R.id.preview_bottom_scrim)).check(matches(isDisplayed()));
+
+        mRule.getScenario().onActivity(activity -> {
+            assertBackgroundColorOnToolbarAndBottomBar(activity, android.R.color.transparent);
+        });
+    }
+
     private void registerIdlingResourceAndWaitForIdle() {
         mRule.getScenario().onActivity((activity -> IdlingRegistry.getInstance().register(
                 new ViewPager2IdlingResource(activity.findViewById(R.id.preview_viewPager)))));
         Espresso.onIdle();
     }
 
+    private void assertBackgroundColorOnToolbarAndBottomBar(Activity activity, int colorResId) {
+        final Toolbar toolbar = activity.findViewById(R.id.toolbar);
+        final Drawable toolbarDrawable = toolbar.getBackground();
+
+        assertThat(toolbarDrawable).isInstanceOf(ColorDrawable.class);
+
+        final int expectedColor = activity.getColor(colorResId);
+        assertThat(((ColorDrawable) toolbarDrawable).getColor()).isEqualTo(expectedColor);
+
+        final View bottomBar = activity.findViewById(R.id.preview_bottom_bar);
+        final Drawable bottomBarDrawable = bottomBar.getBackground();
+
+        assertThat(bottomBarDrawable).isInstanceOf(ColorDrawable.class);
+        assertThat(((ColorDrawable) bottomBarDrawable).getColor()).isEqualTo(expectedColor);
+    }
+
     private void assertSingleSelectCommonLayoutMatches() {
         onView(withId(R.id.preview_viewPager)).check(matches(isDisplayed()));
         onView(withId(R.id.preview_select_check_button)).check(matches(not(isDisplayed())));