Merge "transform Android.mk to Android.bp"
diff --git a/res/drawable/fast_scroll_thumb_drawable.xml b/res/drawable/fast_scroll_thumb_drawable.xml
index 0a7bf61..e2beaec 100644
--- a/res/drawable/fast_scroll_thumb_drawable.xml
+++ b/res/drawable/fast_scroll_thumb_drawable.xml
@@ -17,13 +17,13 @@
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true">
         <shape  android:shape="rectangle">
-            <solid android:color="@color/scroll_thumb_pressed" />
+            <solid android:color="?android:attr/colorControlNormal" />
             <size android:width="8dp" android:height="48dp" />
         </shape>
     </item>
     <item>
         <shape android:shape="rectangle">
-            <solid android:color="@color/scroll_thumb" />
+            <solid android:color="?android:attr/colorControlNormal" />
             <size android:width="8dp" android:height="48dp" />
         </shape>
     </item>
diff --git a/res/drawable/fast_scroll_track_drawable.xml b/res/drawable/fast_scroll_track_drawable.xml
index 63ce70e..d363f1a 100644
--- a/res/drawable/fast_scroll_track_drawable.xml
+++ b/res/drawable/fast_scroll_track_drawable.xml
@@ -16,6 +16,6 @@
   -->
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">
-    <solid android:color="@color/scroll_track" />
+    <solid android:color="@android:color/transparent" />
     <size android:width="8dp" />
 </shape>
diff --git a/res/drawable/gradient_actionbar_background.xml b/res/drawable/gradient_actionbar_background.xml
new file mode 100644
index 0000000..da29c45
--- /dev/null
+++ b/res/drawable/gradient_actionbar_background.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <gradient
+        android:startColor="@color/tool_bar_gradient_max"
+        android:endColor="@android:color/transparent"
+        android:angle="270"
+        android:type="linear" >
+    </gradient>
+</shape>
\ No newline at end of file
diff --git a/res/layout/inspector_activity.xml b/res/layout/inspector_activity.xml
index 05f6b60..284f000 100644
--- a/res/layout/inspector_activity.xml
+++ b/res/layout/inspector_activity.xml
@@ -14,23 +14,100 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
+<androidx.coordinatorlayout.widget.CoordinatorLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    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:layout_height="match_parent"
+    android:fitsSystemWindows="true">
 
-    <Toolbar
-        android:id="@+id/toolbar"
-        android:title="@string/inspector_title"
+    <com.google.android.material.appbar.AppBarLayout
+        android:id="@+id/appBar"
         android:layout_width="match_parent"
-        android:layout_height="?android:attr/actionBarSize"
-        android:elevation="8dp">
-    </Toolbar>
+        android:layout_height="wrap_content"
+        android:fitsSystemWindows="true"
+        android:background="?android:colorPrimary">
 
-    <FrameLayout
-        android:id="@+id/fragment_container"
+        <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:contentScrim="?android:colorPrimary"
+            app:statusBarScrim="@android:color/transparent"
+            app:layout_scrollFlags="scroll|exitUntilCollapsed">
+
+            <com.android.documentsui.inspector.HeaderView
+                android:id="@+id/inspector_header_view"
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/inspector_header_height"
+                app:layout_collapseMode="parallax"/>
+
+            <androidx.appcompat.widget.Toolbar
+                android:id="@+id/toolbar"
+                android:layout_width="match_parent"
+                android:layout_height="?android:attr/actionBarSize"
+                android:background="@drawable/gradient_actionbar_background"
+                android:theme="?actionBarTheme"
+                app:title="@string/inspector_title"
+                app:layout_collapseMode="pin">
+            </androidx.appcompat.widget.Toolbar>
+        </com.google.android.material.appbar.CollapsingToolbarLayout>
+    </com.google.android.material.appbar.AppBarLayout>
+
+    <androidx.core.widget.NestedScrollView
+        android:orientation="vertical"
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
-    </FrameLayout>
+        android:layout_height="match_parent"
+        app:behavior_overlapTop="40dp"
+        app:layout_behavior="@string/appbar_scrolling_view_behavior">
 
-</LinearLayout>
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@drawable/bottom_sheet_dialog_background"
+            android:layout_marginTop="4dp"
+            android:elevation="8dp"
+            android:paddingBottom="5dp">
+
+            <com.android.documentsui.inspector.DetailsView
+                android:id="@+id/inspector_details_view"
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"/>
+
+            <com.android.documentsui.inspector.MediaView
+                android:id="@+id/inspector_media_view"
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"/>
+
+            <com.android.documentsui.inspector.actions.ActionView
+                android:id="@+id/inspector_show_in_provider_view"
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone"/>
+
+            <com.android.documentsui.inspector.actions.ActionView
+                android:id="@+id/inspector_app_defaults_view"
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone"/>
+
+            <com.android.documentsui.inspector.DebugView
+                android:id="@+id/inspector_debug_view"
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:paddingTop="20dp"
+                android:visibility="gone" />
+
+        </LinearLayout>
+    </androidx.core.widget.NestedScrollView>
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/res/layout/inspector_fragment.xml b/res/layout/inspector_fragment.xml
deleted file mode 100644
index 24f0fdb..0000000
--- a/res/layout/inspector_fragment.xml
+++ /dev/null
@@ -1,69 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-    Copyright (C) 2017 The Android Open Source Project
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <LinearLayout
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:paddingBottom="5dp">
-
-        <com.android.documentsui.inspector.HeaderView
-            android:id="@+id/inspector_header_view"
-            android:layout_width="match_parent"
-            android:paddingBottom="5dp"
-            android:layout_height="@dimen/inspector_header_height" />
-
-        <com.android.documentsui.inspector.DetailsView
-            android:id="@+id/inspector_details_view"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
-
-        <com.android.documentsui.inspector.MediaView
-            android:id="@+id/inspector_media_view"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
-
-        <com.android.documentsui.inspector.actions.ActionView
-            android:id="@+id/inspector_show_in_provider_view"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:visibility="gone"/>
-
-        <com.android.documentsui.inspector.actions.ActionView
-            android:id="@+id/inspector_app_defaults_view"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:visibility="gone"/>
-
-        <com.android.documentsui.inspector.DebugView
-            android:id="@+id/inspector_debug_view"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:paddingTop="20dp"
-            android:visibility="gone" />
-
-    </LinearLayout>
-</ScrollView>
diff --git a/res/layout/inspector_header.xml b/res/layout/inspector_header.xml
index 623ae23..937f913 100644
--- a/res/layout/inspector_header.xml
+++ b/res/layout/inspector_header.xml
@@ -22,22 +22,8 @@
         android:id="@+id/inspector_thumbnail"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:scaleType="fitCenter"
         android:alpha="0.0"
-        android:background="@android:color/white" />
-
-    <TextView
-        android:id="@+id/inspector_file_title"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingTop="5dp"
-        android:paddingBottom="5dp"
-        android:paddingStart="16dp"
-        android:paddingEnd="16dp"
-        android:layout_gravity="center_vertical"
-        android:background="@color/inspector_title_background"
-        android:textIsSelectable="true"
-        android:textAlignment="viewStart"
-        android:layout_alignBottom="@+id/inspector_thumbnail"
-        android:textAppearance="@style/InspectorHeaderTitle" />
+        android:background="?attr/gridItemColor" />
 
 </RelativeLayout>
diff --git a/res/layout/inspector_section_title.xml b/res/layout/inspector_section_title.xml
index d3bdaab..ced225c 100644
--- a/res/layout/inspector_section_title.xml
+++ b/res/layout/inspector_section_title.xml
@@ -23,15 +23,22 @@
     android:paddingStart="10dp"
     android:paddingEnd="10dp">
 
+    <!--Empty view for keeping divider when title is gone-->
+    <android.widget.Space
+        android:layout_height="wrap_content"
+        android:layout_width="wrap_content">
+    </android.widget.Space >
+
     <TextView
         android:layout_height="match_parent"
         android:layout_width="match_parent"
         android:id="@+id/inspector_header_title"
-        android:paddingStart="6dp"
-        android:paddingEnd="6dp"
-        android:paddingTop="5dp"
-        android:paddingBottom="5dp"
+        android:paddingStart="16dp"
+        android:paddingEnd="16dp"
+        android:paddingTop="25dp"
+        android:paddingBottom="25dp"
         android:layout_gravity="center_vertical"
         android:textAppearance="?attr/textAppearanceHeadline6"
-        android:textAlignment="viewStart"/>
+        android:textAlignment="viewStart"
+        android:textIsSelectable="true"/>
 </LinearLayout>
\ No newline at end of file
diff --git a/res/layout/table_key_value_row.xml b/res/layout/table_key_value_row.xml
index 6d0d500..f4163ef 100644
--- a/res/layout/table_key_value_row.xml
+++ b/res/layout/table_key_value_row.xml
@@ -21,8 +21,8 @@
     android:layout_height="match_parent"
     android:paddingTop="10dp"
     android:paddingBottom="10dp"
-    android:paddingStart="16dp"
-    android:paddingEnd="16dp">
+    android:paddingStart="30dp"
+    android:paddingEnd="30dp">
 
     <TextView
         android:id="@+id/table_row_key"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 7e8a26e..6c3f217 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -54,6 +54,7 @@
     </item>
     <color name="doc_icon_color">#ff5a5a5a</color>
     <color name="tool_bar_color">@android:color/white</color>
+    <color name="tool_bar_gradient_max">#7f000000</color>
 
     <!-- TODO: Would be nice to move this to a color-set, but not sure how to support animation -->
     <color name="item_doc_title">?android:attr/textColorSecondary</color>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 414faba..f2a9023 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -75,5 +75,5 @@
     <dimen name="bottom_bar_button_horizontal_padding">24dp</dimen>
     <dimen name="bottom_bar_button_corner_radius">4dp</dimen>
 
-    <dimen name="inspector_header_height">250dp</dimen>
+    <dimen name="inspector_header_height">350dp</dimen>
 </resources>
diff --git a/src/com/android/documentsui/inspector/DebugView.java b/src/com/android/documentsui/inspector/DebugView.java
index a781ec5..52ee571 100644
--- a/src/com/android/documentsui/inspector/DebugView.java
+++ b/src/com/android/documentsui/inspector/DebugView.java
@@ -64,14 +64,12 @@
 
     void init(Lookup<String, Executor> executors) {
         assert executors != null;
-        // it's just debug. We do what we want!
-        setBackgroundColor(getResources().getColor(R.color.inspector_debug_mode_color));
         mExecutors = executors;
     }
 
     @Override
     public void accept(DocumentInfo info) {
-        setTitle(R.string.inspector_debug_section, false);
+        setTitle(R.string.inspector_debug_section, true);
 
         put(R.string.debug_content_uri, info.derivedUri.toString());
         put(R.string.debug_document_id, info.documentId);
diff --git a/src/com/android/documentsui/inspector/DetailsView.java b/src/com/android/documentsui/inspector/DetailsView.java
index 5563471..8b30097 100644
--- a/src/com/android/documentsui/inspector/DetailsView.java
+++ b/src/com/android/documentsui/inspector/DetailsView.java
@@ -43,7 +43,9 @@
     }
 
     @Override
-    public void accept(DocumentInfo doc) {
+    public void accept(DocumentInfo doc, String displayName) {
+
+        putTitle(displayName, false);
 
         Lookup<String, String> fileTypeLookup =
                 DocumentsApplication.getFileTypeLookup(getContext());
diff --git a/src/com/android/documentsui/inspector/HeaderView.java b/src/com/android/documentsui/inspector/HeaderView.java
index c411082..bb42b9f 100644
--- a/src/com/android/documentsui/inspector/HeaderView.java
+++ b/src/com/android/documentsui/inspector/HeaderView.java
@@ -49,7 +49,6 @@
     private final Context mContext;
     private final View mHeader;
     private ImageView mThumbnail;
-    private final TextView mTitle;
     private Point mImageDimensions;
 
     public HeaderView(Context context) {
@@ -67,7 +66,6 @@
         mContext = context;
         mHeader = inflater.inflate(R.layout.inspector_header, null);
         mThumbnail = (ImageView) mHeader.findViewById(R.id.inspector_thumbnail);
-        mTitle = (TextView) mHeader.findViewById(R.id.inspector_file_title);
 
         int width = (int) Display.screenWidth((Activity)context);
         int height = mContext.getResources().getDimensionPixelSize(R.dimen.inspector_header_height);
@@ -76,15 +74,8 @@
     }
 
     @Override
-    public void accept(DocumentInfo info, String displayName) {
+    public void accept(DocumentInfo info) {
         loadHeaderImage(info);
-        mTitle.setText(displayName);
-        mTitle.setCustomSelectionActionModeCallback(
-                new HeaderTextSelector(mTitle, this::selectText));
-    }
-
-    private void selectText(Spannable text, int start, int stop) {
-        Selection.setSelection(text, start, stop);
     }
 
     private void loadHeaderImage(DocumentInfo doc) {
@@ -114,8 +105,6 @@
             mThumbnail.setScaleType(ScaleType.CENTER_CROP);
             mThumbnail.setImageBitmap(thumbnail);
         } else {
-            mThumbnail.setPadding(0, 0, 0, mTitle.getHeight());
-
             Drawable mimeIcon =
                     mContext.getContentResolver().getTypeDrawable(info.mimeType);
             mThumbnail.setScaleType(ScaleType.FIT_CENTER);
diff --git a/src/com/android/documentsui/inspector/InspectorActivity.java b/src/com/android/documentsui/inspector/InspectorActivity.java
index aa35c01..ec973de 100644
--- a/src/com/android/documentsui/inspector/InspectorActivity.java
+++ b/src/com/android/documentsui/inspector/InspectorActivity.java
@@ -15,42 +15,95 @@
  */
 package com.android.documentsui.inspector;
 
-import android.app.Activity;
-import android.app.FragmentManager;
+import static androidx.core.util.Preconditions.checkArgument;
+
 import android.content.Intent;
+import android.content.res.TypedArray;
+import android.graphics.Color;
+import android.net.Uri;
 import android.os.Bundle;
 import android.view.MenuItem;
-import android.view.Window;
-import android.widget.Toolbar;
+import android.view.View;
+
+import androidx.annotation.ColorInt;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar;
 
 import com.android.documentsui.R;
+import com.android.documentsui.base.Shared;
+import com.android.documentsui.inspector.InspectorController.DataSupplier;
 
-public class InspectorActivity extends Activity {
+import com.google.android.material.appbar.AppBarLayout;
 
-    private InspectorFragment mFragment;
+public class InspectorActivity extends AppCompatActivity {
+
+    private InspectorController mController;
+    private View mView;
+    private Toolbar mToolbar;
+    private @ColorInt int mTitleColor;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.inspector_activity);
 
-        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
-        setActionBar(toolbar);
-        getActionBar().setDisplayHomeAsUpEnabled(true);
+        mToolbar = findViewById(R.id.toolbar);
+        setSupportActionBar(mToolbar);
+        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+        initRes();
 
-        FragmentManager fragmentManager = getFragmentManager();
-        mFragment = (InspectorFragment) fragmentManager.findFragmentById(
-                R.id.fragment_container);
+        AppBarLayout appBarLayout = findViewById(R.id.appBar);
+        appBarLayout.addOnOffsetChangedListener(this::onOffsetChanged);
 
-        if (mFragment == null) {
-            Intent intent = getIntent();
-            mFragment = InspectorFragment.newInstance(intent);
-            fragmentManager.beginTransaction()
-                    .add(R.id.fragment_container, mFragment)
-                    .commit();
+        final DataSupplier loader = new RuntimeDataSupplier(this, getLoaderManager());
+
+        mView = findViewById(R.id.inspector_root);
+        mController = new InspectorController(this, loader, mView,
+                getIntent().getStringExtra(Intent.EXTRA_TITLE),
+                getIntent().getBooleanExtra(Shared.EXTRA_SHOW_DEBUG, false));
+    }
+
+    private void onOffsetChanged(AppBarLayout layout, int offset) {
+        int diff = layout.getTotalScrollRange() - Math.abs(offset);
+        if (diff <= 0) {
+            //Collapsing tool bar is collapsed, recover to original bar present.
+            mToolbar.getBackground().setAlpha(0);
+            setActionBarItemColor(mTitleColor);
+        } else {
+            float ratio = (float) diff / (float) layout.getTotalScrollRange();
+            int alpha = (int) (ratio * 255);
+            mToolbar.getBackground().setAlpha(alpha);
+            setActionBarItemColor(Color.WHITE);
         }
     }
 
+    private void setActionBarItemColor(int color) {
+        mToolbar.setTitleTextColor(color);
+        mToolbar.getNavigationIcon().setTint(color);
+        mToolbar.getOverflowIcon().setTint(color);
+    }
+
+    private void initRes() {
+        TypedArray ta =
+                this.obtainStyledAttributes(R.style.ActionBarTheme, R.styleable.ActionBarView);
+        mTitleColor = ta.getColor(R.styleable.ActionBarView_android_textColorPrimary, Color.BLACK);
+        ta.recycle();
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+        Uri uri = getIntent().getData();
+        checkArgument(uri.getScheme().equals("content"));
+        mController.loadInfo(uri);
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+        mController.reset();
+    }
+
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
diff --git a/src/com/android/documentsui/inspector/InspectorController.java b/src/com/android/documentsui/inspector/InspectorController.java
index 7d1ec2e..a1d1f85 100644
--- a/src/com/android/documentsui/inspector/InspectorController.java
+++ b/src/com/android/documentsui/inspector/InspectorController.java
@@ -59,7 +59,8 @@
     private final PackageManager mPackageManager;
     private final ProvidersAccess mProviders;
     private final Runnable mErrorSnackbar;
-    private Bundle mArgs;
+    private final String mTitle;
+    private final boolean mShowDebug;
 
     /**
      * InspectorControllerTest relies on this controller.
@@ -76,7 +77,8 @@
             ActionDisplay showProvider,
             ActionDisplay appDefaults,
             DebugDisplay debugView,
-            Bundle args,
+            String title,
+            boolean showDebug,
             Runnable errorRunnable) {
 
         checkArgument(context != null);
@@ -89,7 +91,6 @@
         checkArgument(showProvider != null);
         checkArgument(appDefaults != null);
         checkArgument(debugView != null);
-        checkArgument(args != null);
         checkArgument(errorRunnable != null);
 
         mContext = context;
@@ -101,7 +102,8 @@
         mMedia = media;
         mShowProvider = showProvider;
         mAppDefaults = appDefaults;
-        mArgs = args;
+        mTitle = title;
+        mShowDebug = showDebug;
         mDebugView = debugView;
 
         mErrorSnackbar = errorRunnable;
@@ -111,11 +113,12 @@
      * @param activity
      * @param loader
      * @param layout
-     * @param args Bundle of arguments passed to our host {@link InspectorFragment}. These
+     * @param args Bundle of arguments passed to our host {@link InspectorActivity}. These
      *     can include extras that enable debug mode ({@link Shared#EXTRA_SHOW_DEBUG}
      *     and override the file title (@link {@link Intent#EXTRA_TITLE}).
      */
-    public InspectorController(Activity activity, DataSupplier loader, View layout, Bundle args) {
+    public InspectorController(Activity activity, DataSupplier loader, View layout,
+            String title, boolean showDebug) {
         this(activity,
             loader,
             activity.getPackageManager(),
@@ -126,14 +129,15 @@
             (ActionDisplay) layout.findViewById(R.id.inspector_show_in_provider_view),
             (ActionDisplay) layout.findViewById(R.id.inspector_app_defaults_view),
             (DebugView) layout.findViewById(R.id.inspector_debug_view),
-            args,
+            title,
+            showDebug,
             () -> {
                 // using a runnable to support unit testing this feature.
                 Snackbars.showInspectorError(activity);
             }
         );
 
-        if (args.getBoolean(Shared.EXTRA_SHOW_DEBUG)) {
+        if (showDebug) {
             DebugView view = (DebugView) layout.findViewById(R.id.inspector_debug_view);
             view.init(ProviderExecutor::forAuthority);
         }
@@ -154,8 +158,8 @@
         if (docInfo == null) {
             mErrorSnackbar.run();
         } else {
-            mHeader.accept(docInfo, mArgs.getString(Intent.EXTRA_TITLE, docInfo.displayName));
-            mDetails.accept(docInfo);
+            mHeader.accept(docInfo);
+            mDetails.accept(docInfo, mTitle != null ? mTitle : docInfo.displayName);
 
             if (docInfo.isDirectory()) {
                 mLoader.loadDirCount(docInfo, this::displayChildCount);
@@ -194,11 +198,10 @@
             }
             mMedia.setVisible(!mMedia.isEmpty());
 
-            if (mArgs.getBoolean(Shared.EXTRA_SHOW_DEBUG)) {
+            if (mShowDebug) {
                 mDebugView.accept(docInfo);
             }
-            mDebugView.setVisible(mArgs.getBoolean(Shared.EXTRA_SHOW_DEBUG)
-                    && !mDebugView.isEmpty());
+            mDebugView.setVisible(mShowDebug && !mDebugView.isEmpty());
         }
     }
 
@@ -220,7 +223,7 @@
 
         mMedia.accept(doc, metadata, geoClickListener);
 
-        if (mArgs.getBoolean(Shared.EXTRA_SHOW_DEBUG)) {
+        if (mShowDebug) {
             mDebugView.accept(metadata);
         }
     }
@@ -357,7 +360,7 @@
      * Provides details about a file.
      */
     public interface HeaderDisplay {
-        void accept(DocumentInfo info, String displayName);
+        void accept(DocumentInfo info);
     }
 
     /**
@@ -365,7 +368,7 @@
      */
     public interface DetailsDisplay {
 
-        void accept(DocumentInfo info);
+        void accept(DocumentInfo info, String displayName);
 
         void setChildrenCount(int count);
     }
diff --git a/src/com/android/documentsui/inspector/InspectorFragment.java b/src/com/android/documentsui/inspector/InspectorFragment.java
deleted file mode 100644
index 0345948..0000000
--- a/src/com/android/documentsui/inspector/InspectorFragment.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.documentsui.inspector;
-
-import static androidx.core.util.Preconditions.checkArgument;
-
-import android.app.Fragment;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ScrollView;
-
-import com.android.documentsui.R;
-import com.android.documentsui.inspector.InspectorController.DataSupplier;
-
-/**
- * Displays the Properties view in Files.
- */
-public class InspectorFragment extends Fragment {
-
-    private static final String DOC_URI_ARG = "docUri";
-    private InspectorController mController;
-    private ScrollView mView;
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-    }
-
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-        Bundle savedInstanceState) {
-        final DataSupplier loader = new RuntimeDataSupplier(getActivity(), getLoaderManager());
-
-        mView = (ScrollView) inflater.inflate(R.layout.inspector_fragment,
-                container, false);
-        mController = new InspectorController(getActivity(), loader, mView, getArguments());
-        return mView;
-    }
-
-    @Override
-    public void onStart() {
-        super.onStart();
-        Uri uri = (Uri) getArguments().get(DOC_URI_ARG);
-        mController.loadInfo(uri);
-    }
-
-    @Override
-    public void onStop() {
-        super.onStop();
-        mController.reset();
-    }
-
-    /**
-     * Creates a fragment with the appropriate args.
-     */
-    public static InspectorFragment newInstance(Intent intent) {
-
-        Bundle extras = intent.getExtras();
-        extras = extras != null ? extras : Bundle.EMPTY;
-        Bundle args = extras.deepCopy();
-
-        Uri uri = intent.getData();
-        checkArgument(uri.getScheme().equals("content"));
-        args.putParcelable(DOC_URI_ARG, uri);
-
-        InspectorFragment fragment = new InspectorFragment();
-        fragment.setArguments(args);
-        return fragment;
-    }
-}
diff --git a/src/com/android/documentsui/inspector/MediaView.java b/src/com/android/documentsui/inspector/MediaView.java
index 4e3b185..502df24 100644
--- a/src/com/android/documentsui/inspector/MediaView.java
+++ b/src/com/android/documentsui/inspector/MediaView.java
@@ -65,7 +65,7 @@
 
     @Override
     public void accept(DocumentInfo doc, Bundle metadata, @Nullable Runnable geoClickListener) {
-        setTitle(R.string.inspector_metadata_section, true);
+        putTitle("", true);
 
         Bundle exif = metadata.getBundle(DocumentsContract.METADATA_EXIF);
         if (exif != null) {
diff --git a/src/com/android/documentsui/inspector/TableView.java b/src/com/android/documentsui/inspector/TableView.java
index 194d46a..20c5e14 100644
--- a/src/com/android/documentsui/inspector/TableView.java
+++ b/src/com/android/documentsui/inspector/TableView.java
@@ -18,6 +18,8 @@
 import androidx.annotation.StringRes;
 import android.content.Context;
 import android.content.res.Resources;
+import android.text.Selection;
+import android.text.Spannable;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -77,6 +79,13 @@
             mTitles.put(title, view);
         }
         view.setText(title);
+        view.setCustomSelectionActionModeCallback(
+                new HeaderTextSelector(view, this::selectText));
+        view.setVisibility(title.toString().isEmpty() ? GONE : VISIBLE);
+    }
+
+    private void selectText(Spannable text, int start, int stop) {
+        Selection.setSelection(text, start, stop);
     }
 
     protected KeyValueRow createKeyValueRow(ViewGroup parent) {
diff --git a/src/com/android/documentsui/ui/Snackbars.java b/src/com/android/documentsui/ui/Snackbars.java
index 26b4307..c3f6315 100644
--- a/src/com/android/documentsui/ui/Snackbars.java
+++ b/src/com/android/documentsui/ui/Snackbars.java
@@ -78,7 +78,7 @@
 
     public static final void showInspectorError(Activity activity) {
         //Document Inspector uses a different view from other files app activities.
-        final View view = activity.findViewById(R.id.fragment_container);
+        final View view = activity.findViewById(R.id.inspector_root);
         Snackbar.make(view, R.string.inspector_load_error, Snackbar.LENGTH_INDEFINITE).show();
     }
 
diff --git a/tests/common/com/android/documentsui/bots/InspectorBot.java b/tests/common/com/android/documentsui/bots/InspectorBot.java
index 448a7b7..017991b 100644
--- a/tests/common/com/android/documentsui/bots/InspectorBot.java
+++ b/tests/common/com/android/documentsui/bots/InspectorBot.java
@@ -41,8 +41,10 @@
     }
 
     public void assertTitle(String expected) throws Exception {
+        UiSelector detailView =
+                new UiSelector().resourceId("com.android.documentsui:id/inspector_details_view");
         UiSelector textView
-                = new UiSelector().resourceId("com.android.documentsui:id/inspector_file_title");
+                = detailView.resourceId("com.android.documentsui:id/inspector_header_title");
         String text = mDevice.findObject(textView).getText();
         assertEquals(expected, text);
     }
diff --git a/tests/functional/com/android/documentsui/InternalStorageUiTest.java b/tests/functional/com/android/documentsui/InternalStorageUiTest.java
index 926d07d..deceb8d 100644
--- a/tests/functional/com/android/documentsui/InternalStorageUiTest.java
+++ b/tests/functional/com/android/documentsui/InternalStorageUiTest.java
@@ -16,6 +16,8 @@
 
 package com.android.documentsui;
 
+import android.support.test.filters.LargeTest;
+
 import com.android.documentsui.base.Providers;
 import com.android.documentsui.base.RootInfo;
 import com.android.documentsui.base.State;
@@ -26,10 +28,11 @@
  * is failed and its result will different from the test on the StubProvider. b/115304092 is a
  * example which only happen on root from ExternalStorageProvidrer.
  */
+@LargeTest
 public class InternalStorageUiTest extends ActivityTest<FilesActivity> {
 
-    private static final String fileName = "Test3345678Test.txt";
-    private static final String newFileName = "9527TestTestTest.txt";
+    private static final String fileName = "!Test3345678";
+    private static final String newFileName = "!9527Test";
     private RootInfo rootPrimary;
 
     public InternalStorageUiTest() {
@@ -57,8 +60,8 @@
 
     @Override
     public void tearDown() throws Exception {
-        super.tearDown();
         deleteTestFiles();
+        super.tearDown();
     }
 
     public void testRenameFile() throws Exception {
@@ -81,7 +84,7 @@
     }
 
     private void createTestFiles() {
-        mDocsHelper.createDocument(rootPrimary, "text/plain", fileName);
+        mDocsHelper.createFolder(rootPrimary, fileName);
     }
 
     private void deleteTestFiles() throws Exception {
@@ -100,7 +103,7 @@
         if (selected) {
             bots.main.clickDelete();
             device.waitForIdle();
-            bots.directory.waitForDeleteSnackbarGone();
+            bots.main.clickDialogOkButton();
         }
     }
 }
diff --git a/tests/unit/com/android/documentsui/inspector/InspectorControllerTest.java b/tests/unit/com/android/documentsui/inspector/InspectorControllerTest.java
index 0bcea68..1528c69 100644
--- a/tests/unit/com/android/documentsui/inspector/InspectorControllerTest.java
+++ b/tests/unit/com/android/documentsui/inspector/InspectorControllerTest.java
@@ -80,7 +80,8 @@
     private TestAction mDefaultsTestDouble;
     private TestDebug mDebugTestDouble;
     private TestRunnable mErrCallback;
-    private Bundle mTestArgs;
+    private String mTitle;
+    private boolean mShowDebug;
 
     @Before
     public void setUp() throws Exception {
@@ -96,7 +97,8 @@
         mDefaultsTestDouble = new TestAction();
         mDebugTestDouble = new TestDebug();
         mErrCallback = new TestRunnable();
-        mTestArgs = new Bundle();
+        mTitle = "";
+        mShowDebug = false;
 
         // Add some fake data.
         mDataSupplier.mDoc = TestEnv.FILE_JPG;
@@ -123,7 +125,8 @@
                 mShowInProvider,
                 mDefaultsTestDouble,
                 mDebugTestDouble,
-                mTestArgs,
+                mTitle,
+                mShowDebug,
                 mErrCallback);
     }
 
@@ -142,7 +145,7 @@
      */
     @Test
     public void testShowDebugUpdatesView() throws Exception {
-        mTestArgs.putBoolean(Shared.EXTRA_SHOW_DEBUG, true);
+        mShowDebug = true;
         recreateController();
         mController.loadInfo(TestEnv.FILE_JPG.derivedUri);  // actual URI doesn't matter :)
         mDebugTestDouble.assertVisible(true);
@@ -154,10 +157,10 @@
      */
     @Test
     public void testExtraTitleOverridesDisplayName() throws Exception {
-        mTestArgs.putString(Intent.EXTRA_TITLE, "hammy!");
+        mTitle = "hammy!";
         recreateController();
         mController.loadInfo(TestEnv.FILE_JPG.derivedUri);  // actual URI doesn't matter :)
-        mHeaderTestDouble.assertTitle("hammy!");
+        mDetailsTestDouble.assertTitle("hammy!");
     }
 
     /**
@@ -371,16 +374,10 @@
     private static class TestHeader implements HeaderDisplay {
 
         private boolean mCalled = false;
-        private @Nullable String mTitle;
 
         @Override
-        public void accept(DocumentInfo info, String displayName) {
+        public void accept(DocumentInfo info) {
             mCalled = true;
-            mTitle = displayName;
-        }
-
-        public void assertTitle(String expected) {
-            Assert.assertEquals(expected, mTitle);
         }
 
         public void assertCalled() {
@@ -395,10 +392,16 @@
     private static class TestDetails implements DetailsDisplay {
 
         private boolean mCalled = false;
+        private @Nullable String mTitle;
 
         @Override
-        public void accept(DocumentInfo info) {
+        public void accept(DocumentInfo info, String displayName) {
             mCalled = true;
+            mTitle = displayName;
+        }
+
+        public void assertTitle(String expected) {
+            Assert.assertEquals(expected, mTitle);
         }
 
         @Override