Implement search history UI

Implement search history base on history db and history manager.

Bug: 111863038
Test: manual
Test: atest DocumentsUITests
Change-Id: I5a839969a3d603deba6fcf3d6945a6a349320385
diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java
index 017f86d..cfd305b 100644
--- a/src/com/android/documentsui/BaseActivity.java
+++ b/src/com/android/documentsui/BaseActivity.java
@@ -66,6 +66,7 @@
 import com.android.documentsui.prefs.ScopedPreferences;
 import com.android.documentsui.queries.CommandInterceptor;
 import com.android.documentsui.queries.SearchChipData;
+import com.android.documentsui.queries.SearchFragment;
 import com.android.documentsui.queries.SearchViewManager;
 import com.android.documentsui.queries.SearchViewManager.SearchManagerListener;
 import com.android.documentsui.roots.ProvidersCache;
@@ -74,7 +75,6 @@
 import com.android.documentsui.sorting.SortModel;
 
 import com.google.android.material.appbar.AppBarLayout;
-import com.google.android.material.chip.Chip;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -204,6 +204,18 @@
                     Metrics.logSearchType(item.getChipType());
                 }
             }
+
+            @Override
+            public void onSearchViewFocusChanged(boolean hasFocus) {
+                final boolean isInitailSearch
+                        = !TextUtils.isEmpty(mSearchManager.getCurrentSearch())
+                        && TextUtils.isEmpty(mSearchManager.getSearchViewText());
+                if (hasFocus && (SearchFragment.get(getSupportFragmentManager()) == null)
+                        && !isInitailSearch) {
+                    SearchFragment.showFragment(getSupportFragmentManager(),
+                            mSearchManager.getSearchViewText());
+                }
+            }
         };
 
         // "Commands" are meta input for controlling system behavior.
@@ -383,11 +395,7 @@
                     doc -> mInjector.actions.openRootDocument(doc));
         }
 
-        final AppBarLayout appBarLayout = findViewById(R.id.app_bar);
-        if (appBarLayout != null) {
-            appBarLayout.setExpanded(true);
-        }
-
+        expandAppBar();
         updateHeaderTitle();
     }
 
@@ -595,6 +603,13 @@
         // TODO: Isolate this behavior to PickActivity.
     }
 
+    public void expandAppBar() {
+        final AppBarLayout appBarLayout = findViewById(R.id.app_bar);
+        if (appBarLayout != null) {
+            appBarLayout.setExpanded(true);
+        }
+    }
+
     public void updateHeaderTitle() {
         if (!mState.stack.isInitialized()) {
             //stack has not initialized, the header will update after the stack finishes loading