Show an empty view when there is no widget available

Test: Remove all widgets from work profile using TestDpc. Observe
      empty view is shown in the full widget tray. Add back some
      widgets to work profile and observe widgets showing up in the
      full widgets tray

Bug: 179797520
Change-Id: I2e1fcb5a0014568a4674e2bcc0a3ed3c6ec5a44a
diff --git a/res/layout/widgets_full_sheet.xml b/res/layout/widgets_full_sheet.xml
index 28a8c6f..6c18d7a 100644
--- a/res/layout/widgets_full_sheet.xml
+++ b/res/layout/widgets_full_sheet.xml
@@ -15,6 +15,7 @@
 -->
 <com.android.launcher3.widget.picker.WidgetsFullSheet
     xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
@@ -27,6 +28,14 @@
         android:background="?android:attr/colorPrimary"
         android:elevation="4dp">
 
+        <TextView
+            android:id="@+id/no_widgets_text"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:gravity="center"
+            android:visibility="gone"
+            tools:text="No widgets available" />
+
         <!-- Fast scroller popup -->
         <TextView
             android:id="@+id/fast_scroller_popup"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 44b5ee7..6fb72b1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -74,6 +74,9 @@
     <!-- Search bar text shown in the popup view showing all available widgets installed on the
          device. [CHAR_LIMIT=50] -->
     <string name="widgets_full_sheet_search_bar_hint">Search</string>
+    <!-- Text shown when there is no widgets shown in the popup view showing all available widgets
+         installed on the device. [CHAR_LIMIT=none] -->
+    <string name="no_widgets_available">No widgets available</string>
 
     <!-- All Apps -->
     <!-- Search bar text in the apps view. [CHAR_LIMIT=50] -->
diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
index bf9b849..330175f 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
@@ -82,6 +82,7 @@
     @Nullable private PersonalWorkPagedView mViewPager;
     private int mInitialTabsHeight = 0;
     private View mTabsView;
+    private TextView mNoWidgetsView;
     private SearchAndRecommendationViewHolder mSearchAndRecommendationViewHolder;
     private SearchAndRecommendationsScrollController mSearchAndRecommendationsScrollController;
 
@@ -141,19 +142,32 @@
                 mViewPager);
         fastScroller.setOnFastScrollChangeListener(mSearchAndRecommendationsScrollController);
 
+        mNoWidgetsView = findViewById(R.id.no_widgets_text);
+
         onWidgetsBound();
     }
 
     @Override
     public void onActivePageChanged(int currentActivePage) {
-        WidgetsRecyclerView currentRecyclerView =
-                mAdapters.get(currentActivePage).mWidgetsRecyclerView;
+        AdapterHolder currentAdapterHolder = mAdapters.get(currentActivePage);
+        WidgetsRecyclerView currentRecyclerView = currentAdapterHolder.mWidgetsRecyclerView;
         currentRecyclerView.bindFastScrollbar();
         mSearchAndRecommendationsScrollController.setCurrentRecyclerView(currentRecyclerView);
 
+        updateNoWidgetsView(currentAdapterHolder);
+
         reset();
     }
 
+    private void updateNoWidgetsView(AdapterHolder adapterHolder) {
+        boolean isWidgetAvailable = adapterHolder.mWidgetsListAdapter.getItemCount() > 0;
+        adapterHolder.mWidgetsRecyclerView.setVisibility(isWidgetAvailable ? VISIBLE : GONE);
+
+        // Always resets the text in case this is updated by search.
+        mNoWidgetsView.setText(R.string.no_widgets_available);
+        mNoWidgetsView.setVisibility(isWidgetAvailable ? GONE : VISIBLE);
+    }
+
     private void reset() {
         mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView.scrollToTop();
         if (mHasWorkProfile) {
@@ -276,6 +290,8 @@
         AdapterHolder primaryUserAdapterHolder = mAdapters.get(AdapterHolder.PRIMARY);
         primaryUserAdapterHolder.setup(findViewById(R.id.primary_widgets_list_view));
         primaryUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets);
+        updateNoWidgetsView(primaryUserAdapterHolder);
+
         if (mHasWorkProfile) {
             AdapterHolder workUserAdapterHolder = mAdapters.get(AdapterHolder.WORK);
             workUserAdapterHolder.setup(findViewById(R.id.work_widgets_list_view));