Merge "Update layout for gesture navigation" into qt-dev am: f99876e622
am: 2090cd2d4c

Change-Id: Ibf3c15cf1ecc0b3c87f566472c5f8a6907d4e1e8
diff --git a/res/layout/drawer_layout.xml b/res/layout/drawer_layout.xml
index 0b8aff4..a5331d5 100644
--- a/res/layout/drawer_layout.xml
+++ b/res/layout/drawer_layout.xml
@@ -61,12 +61,12 @@
                     android:layout_height="match_parent"/>
             </FrameLayout>
 
-            <FrameLayout
+            <androidx.coordinatorlayout.widget.CoordinatorLayout
                 android:id="@+id/container_save"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_gravity="bottom|center_horizontal"
-                android:background="?android:attr/colorBackground"
+                android:background="?android:attr/colorBackgroundFloating"
                 android:elevation="8dp" />
 
             <include layout="@layout/directory_app_bar"/>
diff --git a/res/layout/fixed_layout.xml b/res/layout/fixed_layout.xml
index 2a45910..7f7547f 100644
--- a/res/layout/fixed_layout.xml
+++ b/res/layout/fixed_layout.xml
@@ -88,11 +88,11 @@
                     android:layout_height="0dp"
                     android:layout_weight="1" />
 
-                <FrameLayout
+                <androidx.coordinatorlayout.widget.CoordinatorLayout
                     android:id="@+id/container_save"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:background="?android:attr/colorBackground"
+                    android:background="?android:attr/colorBackgroundFloating"
                     android:elevation="8dp" />
 
             </LinearLayout>
diff --git a/res/layout/fragment_pick.xml b/res/layout/fragment_pick.xml
index 7b70de6..c18afa0 100644
--- a/res/layout/fragment_pick.xml
+++ b/res/layout/fragment_pick.xml
@@ -16,7 +16,7 @@
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="@dimen/bottom_bar_height"
+    android:layout_height="wrap_content"
     android:orientation="horizontal"
     android:baselineAligned="false"
     android:gravity="center_vertical|end"
diff --git a/res/layout/fragment_save.xml b/res/layout/fragment_save.xml
index 4c8132b..b3f3c0b 100644
--- a/res/layout/fragment_save.xml
+++ b/res/layout/fragment_save.xml
@@ -16,13 +16,12 @@
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="@dimen/bottom_bar_height"
+    android:layout_height="wrap_content"
     android:paddingStart="@dimen/list_item_padding"
     android:paddingEnd="@dimen/bottom_bar_padding"
     android:orientation="horizontal"
     android:baselineAligned="false"
     android:gravity="center_vertical"
-    android:fitsSystemWindows="true"
     android:minHeight="?android:attr/listPreferredItemHeightSmall">
 
     <FrameLayout
diff --git a/res/layout/inspector_activity.xml b/res/layout/inspector_activity.xml
index 0467fa5..df28d49 100644
--- a/res/layout/inspector_activity.xml
+++ b/res/layout/inspector_activity.xml
@@ -19,21 +19,18 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/inspector_root"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:fitsSystemWindows="true">
+    android:layout_height="match_parent">
 
     <com.google.android.material.appbar.AppBarLayout
         android:id="@+id/app_bar"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:fitsSystemWindows="true"
         android:background="?android:colorBackground">
 
         <com.google.android.material.appbar.CollapsingToolbarLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:minHeight="?android:attr/actionBarSize"
-            android:fitsSystemWindows="true"
             app:titleEnabled="false"
             app:statusBarScrim="@android:color/transparent"
             app:layout_scrollFlags="scroll|exitUntilCollapsed">
@@ -71,10 +68,12 @@
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:overScrollMode="never"
         app:behavior_overlapTop="10dp"
         app:layout_behavior="@string/appbar_scrolling_view_behavior">
 
         <LinearLayout
+            android:id="@+id/inspector_container"
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
diff --git a/res/values-night/colors.xml b/res/values-night/colors.xml
index 36c0922..f358b02 100644
--- a/res/values-night/colors.xml
+++ b/res/values-night/colors.xml
@@ -16,6 +16,7 @@
 <resources>
     <color name="app_background_color">#202124</color>
     <color name="background_floating">#3C4043</color>
+    <color name="nav_bar_translucent">#52000000</color>
 
     <color name="primary">#8AB4F8</color>
     <color name="secondary">#3D8AB4F8</color>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index a5bcf4c..a34f09d 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -21,6 +21,7 @@
 
     <color name="app_background_color">@android:color/white</color>
     <color name="background_floating">@android:color/white</color>
+    <color name="nav_bar_translucent">#99FFFFFF</color>
 
     <color name="primary">#1E88E5</color> <!-- Blue 600 -->
     <color name="secondary">#E3F2FD</color> <!-- Blue 50 -->
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 6667793..971fa1f 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -35,7 +35,6 @@
         <item name="android:listDivider">@drawable/list_divider</item>
         <item name="android:statusBarColor">?android:colorBackground</item>
         <item name="android:navigationBarColor">?android:colorBackground</item>
-        <item name="android:navigationBarDividerColor">@color/hairline</item>
         <item name="android:windowBackground">?android:colorBackground</item>
         <item name="android:windowLightStatusBar">true</item>
         <item name="android:windowLightNavigationBar">true</item>
diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java
index 9b783a8..9954e9d 100644
--- a/src/com/android/documentsui/BaseActivity.java
+++ b/src/com/android/documentsui/BaseActivity.java
@@ -24,7 +24,9 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ProviderInfo;
+import android.graphics.Color;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.MessageQueue.IdleHandler;
 import android.preference.PreferenceManager;
@@ -145,6 +147,8 @@
 
         setContentView(mLayoutId);
 
+        setContainer();
+
         mInjector = getInjector();
         mState = getState(icicle);
         mDrawer = DrawerController.create(this, mInjector.config);
@@ -370,6 +374,32 @@
         return state;
     }
 
+    private void setContainer() {
+        View root = findViewById(R.id.coordinator_layout);
+        root.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
+        root.setOnApplyWindowInsetsListener((v, insets) -> {
+            root.setPadding(insets.getSystemWindowInsetLeft(),
+                    insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), 0);
+
+            View saveContainer = findViewById(R.id.container_save);
+            saveContainer.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom());
+
+            View rootsContainer = findViewById(R.id.container_roots);
+            rootsContainer.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom());
+
+            return insets.consumeSystemWindowInsets();
+        });
+
+        getWindow().setNavigationBarDividerColor(Color.TRANSPARENT);
+        if (Build.VERSION.SDK_INT >= 29) {
+            getWindow().setNavigationBarColor(Color.TRANSPARENT);
+            getWindow().setNavigationBarContrastEnforced(true);
+        } else {
+            getWindow().setNavigationBarColor(getColor(R.color.nav_bar_translucent));
+        }
+    }
+
     @Override
     public void setRootsDrawerOpen(boolean open) {
         mNavigator.revealRootsDrawer(open);
diff --git a/src/com/android/documentsui/files/FilesActivity.java b/src/com/android/documentsui/files/FilesActivity.java
index 297a3f3..d93e5db 100644
--- a/src/com/android/documentsui/files/FilesActivity.java
+++ b/src/com/android/documentsui/files/FilesActivity.java
@@ -20,12 +20,14 @@
 
 import android.app.ActivityManager.TaskDescription;
 import android.content.Intent;
+import android.graphics.Color;
 import android.net.Uri;
 import android.os.Bundle;
 import android.view.KeyEvent;
 import android.view.KeyboardShortcutGroup;
 import android.view.Menu;
 import android.view.MenuItem;
+import android.view.View;
 
 import androidx.annotation.CallSuper;
 import androidx.fragment.app.FragmentManager;
@@ -171,6 +173,10 @@
             updateTaskDescription(intent);
         }
 
+        // Set save container background to transparent for edge to edge nav bar.
+        View saveContainer = findViewById(R.id.container_save);
+        saveContainer.setBackgroundColor(Color.TRANSPARENT);
+
         presentFileErrors(icicle, intent);
     }
 
diff --git a/src/com/android/documentsui/inspector/InspectorActivity.java b/src/com/android/documentsui/inspector/InspectorActivity.java
index e9b872a..f7c2c8d 100644
--- a/src/com/android/documentsui/inspector/InspectorActivity.java
+++ b/src/com/android/documentsui/inspector/InspectorActivity.java
@@ -18,7 +18,9 @@
 import static androidx.core.util.Preconditions.checkArgument;
 
 import android.content.Intent;
+import android.graphics.Color;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.view.MenuItem;
 import android.view.View;
@@ -48,13 +50,14 @@
 
         setContentView(R.layout.inspector_activity);
 
+        setContainer();
+
         mToolbar = findViewById(R.id.toolbar);
         setSupportActionBar(mToolbar);
         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 
         final DataSupplier loader = new RuntimeDataSupplier(this, LoaderManager.getInstance(this));
 
-        mView = findViewById(R.id.inspector_root);
         mController = new InspectorController(this, loader, mView,
                 getIntent().getStringExtra(Intent.EXTRA_TITLE),
                 getIntent().getBooleanExtra(Shared.EXTRA_SHOW_DEBUG, false));
@@ -83,4 +86,27 @@
         }
         return super.onOptionsItemSelected(item);
     }
-}
+
+    private void setContainer() {
+        mView = findViewById(R.id.inspector_root);
+        mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
+        mView.setOnApplyWindowInsetsListener((v, insets) -> {
+            mView.setPadding(insets.getSystemWindowInsetLeft(),
+                    insets.getSystemWindowInsetTop(),
+                    insets.getSystemWindowInsetRight(), 0);
+
+            View container = findViewById(R.id.inspector_container);
+            container.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom());
+            return insets;
+        });
+
+        getWindow().setNavigationBarDividerColor(Color.TRANSPARENT);
+        if (Build.VERSION.SDK_INT >= 29) {
+            getWindow().setNavigationBarColor(Color.TRANSPARENT);
+            getWindow().setNavigationBarContrastEnforced(true);
+        } else {
+            getWindow().setNavigationBarColor(getColor(R.color.nav_bar_translucent));
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/documentsui/picker/PickActivity.java b/src/com/android/documentsui/picker/PickActivity.java
index aece47b..57969e0 100644
--- a/src/com/android/documentsui/picker/PickActivity.java
+++ b/src/com/android/documentsui/picker/PickActivity.java
@@ -23,6 +23,7 @@
 import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION;
 
 import android.content.Intent;
+import android.graphics.Color;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.SystemClock;
@@ -30,6 +31,7 @@
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.MenuItem;
+import android.view.View;
 
 import androidx.annotation.CallSuper;
 import androidx.fragment.app.Fragment;
@@ -187,6 +189,11 @@
         } else if (mState.action == ACTION_OPEN_TREE ||
                    mState.action == ACTION_PICK_COPY_DESTINATION) {
             PickFragment.show(getSupportFragmentManager());
+        } else {
+            // If PickFragment or SaveFragment does not show,
+            // Set save container background to transparent for edge to edge nav bar.
+            View saveContainer = findViewById(R.id.container_save);
+            saveContainer.setBackgroundColor(Color.TRANSPARENT);
         }
 
         if (mState.action == ACTION_GET_CONTENT) {
diff --git a/src/com/android/documentsui/ui/Snackbars.java b/src/com/android/documentsui/ui/Snackbars.java
index c3f6315..5d6e012 100644
--- a/src/com/android/documentsui/ui/Snackbars.java
+++ b/src/com/android/documentsui/ui/Snackbars.java
@@ -16,17 +16,18 @@
 
 package com.android.documentsui.ui;
 
-import androidx.annotation.StringRes;
 import android.app.Activity;
 import android.view.Gravity;
 import android.view.View;
 import android.widget.TextView;
 
-import com.google.android.material.snackbar.Snackbar;
+import androidx.annotation.StringRes;
 
 import com.android.documentsui.R;
 import com.android.documentsui.base.Shared;
 
+import com.google.android.material.snackbar.Snackbar;
+
 import java.util.function.Consumer;
 
 public final class Snackbars {
@@ -109,7 +110,7 @@
 
     public static final Snackbar makeSnackbar(
             Activity activity, CharSequence message, int duration) {
-        final View view = activity.findViewById(R.id.coordinator_layout);
+        final View view = activity.findViewById(R.id.container_save);
         return Snackbar.make(view, message, duration);
     }
 }
diff --git a/tests/functional/com/android/documentsui/BandSelectionUiTest.java b/tests/functional/com/android/documentsui/BandSelectionUiTest.java
index a7eab63..94cdef3 100644
--- a/tests/functional/com/android/documentsui/BandSelectionUiTest.java
+++ b/tests/functional/com/android/documentsui/BandSelectionUiTest.java
@@ -40,8 +40,9 @@
     public void testBandSelection_allFiles() throws Exception {
         bots.main.switchToGridMode();
         Rect dirListBounds = bots.directory.findDocumentsList().getBounds();
-        Point start = new Point(dirListBounds.right - 1, dirListBounds.bottom - 1);
-        Point end = new Point(dirListBounds.left + 1, dirListBounds.top + 1);
+        Rect startDir = bots.directory.findDocument(dirName1).getBounds();
+        Point start = new Point(dirListBounds.right - 1, startDir.centerY());
+        Point end = new Point(dirListBounds.left + 1, dirListBounds.bottom - 1);
         bots.gesture.bandSelection(start, end);
 
         bots.directory.assertSelection(4);
@@ -50,9 +51,10 @@
     public void testBandSelection_someFiles() throws Exception {
         bots.main.switchToGridMode();
         Rect dirListBounds = bots.directory.findDocumentsList().getBounds();
+        Rect startDoc = bots.directory.findDocument(fileNameNoRename).getBounds();
         Rect endDoc = bots.directory.findDocument(fileName1).getBounds();
-        // Start from list right bottom.
-        Point start = new Point(dirListBounds.right - 1, dirListBounds.bottom - 1);
+        // Start from right side of file NoRename.
+        Point start = new Point(dirListBounds.right - 1, startDoc.bottom - 1);
         // End is center of file1
         Point end = new Point(endDoc.centerX(), endDoc.centerY());
         bots.gesture.bandSelection(start, end);
diff --git a/tests/functional/com/android/documentsui/ContextMenuUiTest.java b/tests/functional/com/android/documentsui/ContextMenuUiTest.java
index eb06538..8032240 100644
--- a/tests/functional/com/android/documentsui/ContextMenuUiTest.java
+++ b/tests/functional/com/android/documentsui/ContextMenuUiTest.java
@@ -109,8 +109,11 @@
         menuItems.put("Paste", true);
         menuItems.put("New folder", true);
         Rect dirListBounds = bots.directory.findDocumentsList().getBounds();
-        bots.directory.rightClickDocument(
-                new Point(dirListBounds.right - 1, dirListBounds.bottom - 1)); //bottom right corner
+        Rect dirBounds = bots.directory.findDocument(dirName1).getBounds();
+
+        bots.main.switchToGridMode();
+        // right side of dir1 area
+        bots.directory.rightClickDocument(new Point(dirListBounds.right - 1, dirBounds.centerY()));
         bots.menu.assertPresentMenuItems(menuItems);
     }
 }