Merge "Update widgets bottom sheet to match redlines" into ub-launcher3-dorval
diff --git a/res/layout/widgets_and_more.xml b/res/layout/widgets_and_more.xml
index 7a6d006..6764aa7 100644
--- a/res/layout/widgets_and_more.xml
+++ b/res/layout/widgets_and_more.xml
@@ -19,7 +19,8 @@
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:padding="8dp"
+    android:paddingStart="16dp"
+    android:paddingTop="28dp"
     android:background="?android:attr/colorPrimary"
     android:elevation="@dimen/deep_shortcuts_elevation"
     android:layout_gravity="bottom">
@@ -27,54 +28,27 @@
     <TextView
         android:id="@+id/title"
         android:layout_width="match_parent"
-        android:layout_height="48dp"
-        android:gravity="center_horizontal|bottom"
-        android:fontFamily="sans-serif"
-        android:textStyle="bold"
-        android:textColor="?android:attr/textColorPrimary"
-        android:textSize="20sp"/>
-
-    <TextView
-        android:layout_width="match_parent"
-        android:layout_height="48dp"
-        android:gravity="center_horizontal|top"
+        android:layout_height="wrap_content"
+        android:gravity="center_horizontal"
         android:fontFamily="sans-serif"
         android:textColor="?android:attr/textColorPrimary"
-        android:textSize="16sp"
-        android:text="@string/long_press_widget_to_add"/>
+        android:textSize="24sp"/>
 
     <TextView
-        android:id="@+id/widgets_header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:gravity="center_horizontal"
+        android:paddingTop="4dp"
         android:fontFamily="sans-serif"
-        android:textColor="?android:attr/textColorPrimary"
-        android:textSize="16sp"
-        android:textStyle="bold"
-        android:text="@string/widget_button_text"/>
+        android:textColor="?android:attr/textColorTertiary"
+        android:textSize="14sp"
+        android:text="@string/long_press_widget_to_add"/>
 
     <include layout="@layout/widgets_scroll_container"
          android:id="@+id/widgets"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
-         android:layout_marginTop="@dimen/widget_row_padding"
-         android:layout_marginBottom="@dimen/widget_row_padding"/>
-
-    <TextView
-        android:id="@+id/shortcuts_header"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:fontFamily="sans-serif"
-        android:textColor="?android:attr/textColorPrimary"
-        android:textSize="16sp"
-        android:textStyle="bold"
-        android:text="@string/widgets_bottom_sheet_custom_shortcuts_section_title"/>
-
-    <include layout="@layout/widgets_scroll_container"
-             android:id="@+id/shortcuts"
-             android:layout_width="wrap_content"
-             android:layout_height="wrap_content"
-             android:layout_marginTop="@dimen/widget_row_padding"
-             android:layout_marginBottom="@dimen/widget_row_padding" />
+         android:layout_marginTop="45dp"
+         android:layout_marginBottom="40dp"/>
 
 </com.android.launcher3.widget.WidgetsAndMore>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index eddae62..4bee87d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -205,8 +205,8 @@
     <string name="app_waiting_download_title"><xliff:g id="name" example="Messenger">%1$s</xliff:g> waiting to install</string>
 
     <!-- Strings for widgets & more in the popup container/bottom sheet -->
-    <string name="widgets_and_more" translatable="false">Widgets &amp; more</string>
-    <string name="widgets_bottom_sheet_custom_shortcuts_section_title" translatable="false">Custom shortcuts</string>
+    <!-- Title for a bottom sheet that shows widgets for a particular app -->
+    <string name="widgets_bottom_sheet_title"><xliff:g id="name" example="Messenger">%1$s</xliff:g> widgets</string>
 
 <!-- Strings for accessibility actions -->
     <!-- Accessibility action to add an app to workspace. [CHAR_LIMIT=30] -->
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index d08f876..fa70de9 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -47,7 +47,7 @@
     public static class Widgets extends SystemShortcut {
 
         public Widgets() {
-            super(R.drawable.ic_widget, R.string.widgets_and_more);
+            super(R.drawable.ic_widget, R.string.widget_button_text);
         }
 
         @Override
diff --git a/src/com/android/launcher3/widget/WidgetsAndMore.java b/src/com/android/launcher3/widget/WidgetsAndMore.java
index a8e7e38..401337b 100644
--- a/src/com/android/launcher3/widget/WidgetsAndMore.java
+++ b/src/com/android/launcher3/widget/WidgetsAndMore.java
@@ -24,6 +24,7 @@
 import android.support.v4.view.animation.FastOutSlowInInterpolator;
 import android.util.AttributeSet;
 import android.view.ContextThemeWrapper;
+import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -49,8 +50,6 @@
 import com.android.launcher3.util.PackageUserKey;
 import com.android.launcher3.util.TouchController;
 
-import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -99,7 +98,8 @@
 
     public void populateAndShow(ItemInfo itemInfo) {
         mOriginalItemInfo = itemInfo;
-        ((TextView) findViewById(R.id.title)).setText(mOriginalItemInfo.title);
+        ((TextView) findViewById(R.id.title)).setText(getContext().getString(
+                R.string.widgets_bottom_sheet_title, mOriginalItemInfo.title));
 
         onWidgetsBound();
 
@@ -116,70 +116,33 @@
     protected void onWidgetsBound() {
         List<WidgetItem> widgets = mLauncher.getWidgetsForPackageUser(new PackageUserKey(
                 mOriginalItemInfo.getTargetComponent().getPackageName(), mOriginalItemInfo.user));
-        List<WidgetItem> shortcuts = new ArrayList<>();
-        // Transfer configurable widgets to shortcuts
-        Iterator<WidgetItem> widgetsIter = widgets.iterator();
-        WidgetItem nextWidget;
-        while (widgetsIter.hasNext()) {
-            nextWidget = widgetsIter.next();
-            if (nextWidget.activityInfo != null) {
-                shortcuts.add(nextWidget);
-                widgetsIter.remove();
-            }
-        }
 
         ViewGroup widgetRow = (ViewGroup) findViewById(R.id.widgets);
         ViewGroup widgetCells = (ViewGroup) widgetRow.findViewById(R.id.widgets_cell_list);
 
-        ViewGroup shortcutRow = (ViewGroup) findViewById(R.id.shortcuts);
-        ViewGroup shortcutCells = (ViewGroup) shortcutRow.findViewById(R.id.widgets_cell_list);
-
         widgetCells.removeAllViews();
-        shortcutCells.removeAllViews();
 
         for (int i = 0; i < widgets.size(); i++) {
-            addItemCell(widgetCells);
+            WidgetCell widget = addItemCell(widgetCells);
+            widget.applyFromCellItem(widgets.get(i), LauncherAppState.getInstance(mLauncher)
+                    .getWidgetCache());
+            widget.ensurePreview();
+            widget.setVisibility(View.VISIBLE);
             if (i < widgets.size() - 1) {
                 addDivider(widgetCells);
             }
         }
-        for (int i = 0; i < shortcuts.size(); i++) {
-            addItemCell(shortcutCells);
-            if (i < shortcuts.size() - 1) {
-                addDivider(shortcutCells);
-            }
-        }
 
-        // Bind the views in the horizontal tray regions.
-        if (widgetCells.getChildCount() > 0) {
-            for (int i = 0; i < widgets.size(); i++) {
-                WidgetCell widget = (WidgetCell) widgetCells.getChildAt(i*2); // skip dividers
-                widget.applyFromCellItem(widgets.get(i), LauncherAppState.getInstance(mLauncher)
-                        .getWidgetCache());
-                widget.ensurePreview();
-                widget.setVisibility(View.VISIBLE);
-            }
-        } else {
-            removeView(findViewById(R.id.widgets_header));
-        }
-        if (shortcutCells.getChildCount() > 0) {
-            for (int i = 0; i < shortcuts.size(); i++) {
-                WidgetCell shortcut = (WidgetCell) shortcutCells.getChildAt(i*2); // skip dividers
-                shortcut.applyFromCellItem(shortcuts.get(i), LauncherAppState.getInstance(mLauncher)
-                        .getWidgetCache());
-                shortcut.ensurePreview();
-                shortcut.setVisibility(View.VISIBLE);
-            }
-        } else {
-            removeView(findViewById(R.id.shortcuts_header));
-        }
+        // If there is only one widget, we want to center it instead of left-align.
+        WidgetsAndMore.LayoutParams params = (WidgetsAndMore.LayoutParams) widgetRow.getLayoutParams();
+        params.gravity = widgets.size() == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.START;
     }
 
     private void addDivider(ViewGroup parent) {
         LayoutInflater.from(getContext()).inflate(R.layout.widget_list_divider, parent, true);
     }
 
-    private void addItemCell(ViewGroup parent) {
+    private WidgetCell addItemCell(ViewGroup parent) {
         WidgetCell widget = (WidgetCell) LayoutInflater.from(getContext()).inflate(
                 R.layout.widget_cell, parent, false);
 
@@ -188,6 +151,7 @@
         widget.setAnimatePreview(false);
 
         parent.addView(widget);
+        return widget;
     }
 
     @Override