Merge "polish for the app shortcut popup, fixing padding on several elements." into tm-qpr-dev
diff --git a/res/layout/notification_content.xml b/res/layout/notification_content.xml
index 91897e9..0763d48 100644
--- a/res/layout/notification_content.xml
+++ b/res/layout/notification_content.xml
@@ -17,7 +17,7 @@
 <com.android.launcher3.notification.NotificationMainView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="@dimen/notification_container_height"
     android:orientation="vertical">
 
     <!-- header -->
@@ -25,14 +25,14 @@
         android:id="@+id/header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingEnd="@dimen/notification_padding"
-        android:paddingStart="@dimen/notification_padding">
+        android:paddingEnd="@dimen/notification_padding_end"
+        android:paddingTop="@dimen/notification_padding_header_top"
+        android:paddingStart="@dimen/notification_header_padding_start">
         <TextView
             android:id="@+id/notification_text"
-            android:paddingTop="@dimen/notification_padding"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_gravity="bottom|start"
+            android:layout_gravity="top|start"
             android:text="@string/notifications_header"
             android:textColor="?android:attr/textColorPrimary"
             android:textSize="@dimen/notification_header_text_size"
@@ -42,7 +42,7 @@
             android:layout_width="@dimen/notification_circle_icon_size"
             android:layout_height="@dimen/notification_circle_icon_size"
             android:background="@drawable/notification_circle"
-            android:layout_gravity="bottom|end"
+            android:layout_gravity="top|end"
             android:gravity="center"
             android:textColor="?android:attr/textColorPrimary"
             android:textSize="@dimen/notification_header_count_text_size"
@@ -54,6 +54,8 @@
         android:id="@+id/main_view"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:paddingTop="@dimen/notification_padding_top"
+        android:paddingBottom="@dimen/notification_padding_bottom"
         android:focusable="true" >
 
         <LinearLayout
@@ -62,9 +64,7 @@
             android:layout_height="match_parent"
             android:gravity="center_vertical"
             android:orientation="vertical"
-            android:paddingTop="@dimen/notification_padding"
-            android:paddingBottom="@dimen/notification_padding"
-            android:paddingEnd="@dimen/notification_padding"
+            android:paddingEnd="@dimen/notification_padding_end"
             android:paddingStart="@dimen/notification_main_text_padding_start">
             <TextView
                 android:id="@+id/title"
@@ -91,9 +91,8 @@
             android:id="@+id/popup_item_icon"
             android:layout_width="@dimen/notification_icon_size"
             android:layout_height="@dimen/notification_icon_size"
-            android:layout_gravity="start"
-            android:layout_marginTop="@dimen/notification_padding"
-            android:layout_marginStart="@dimen/notification_icon_padding" />
+            android:layout_gravity="start|center_vertical"
+            android:layout_marginStart="@dimen/notification_icon_padding_start"/>
 
     </FrameLayout>
 </com.android.launcher3.notification.NotificationMainView>
\ No newline at end of file
diff --git a/res/layout/system_shortcut_icon_only.xml b/res/layout/system_shortcut_icon_only.xml
index 5a81f70..92522aa 100644
--- a/res/layout/system_shortcut_icon_only.xml
+++ b/res/layout/system_shortcut_icon_only.xml
@@ -18,8 +18,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="@dimen/system_shortcut_header_icon_touch_size"
     android:layout_height="@dimen/system_shortcut_header_icon_touch_size"
-    android:background="?android:attr/selectableItemBackgroundBorderless"
     android:tint="?attr/iconOnlyShortcutColor"
     android:tintMode="src_in"
     android:padding="@dimen/system_shortcut_header_icon_padding"
-    android:theme="@style/PopupItem" />
+    android:theme="@style/PopupItemIconOnly" />
diff --git a/res/layout/system_shortcut_icon_only_end.xml b/res/layout/system_shortcut_icon_only_end.xml
new file mode 100644
index 0000000..b5b5f02
--- /dev/null
+++ b/res/layout/system_shortcut_icon_only_end.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2023 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.
+-->
+
+<ImageView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="@dimen/system_shortcut_header_icon_touch_size"
+    android:layout_height="@dimen/system_shortcut_header_icon_touch_size"
+    android:tint="?attr/iconOnlyShortcutColor"
+    android:tintMode="src_in"
+    android:padding="@dimen/system_shortcut_header_icon_padding"
+    android:paddingStart="@dimen/system_shortcut_header_icon_padding_inner"
+    android:paddingEnd="@dimen/system_shortcut_header_icon_padding_outer"
+    android:theme="@style/PopupItemIconOnly" />
\ No newline at end of file
diff --git a/res/layout/system_shortcut_icon_only_start.xml b/res/layout/system_shortcut_icon_only_start.xml
new file mode 100644
index 0000000..33a6b17
--- /dev/null
+++ b/res/layout/system_shortcut_icon_only_start.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2023 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.
+-->
+
+<ImageView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="@dimen/system_shortcut_header_icon_touch_size"
+    android:layout_height="@dimen/system_shortcut_header_icon_touch_size"
+    android:tint="?attr/iconOnlyShortcutColor"
+    android:tintMode="src_in"
+    android:padding="@dimen/system_shortcut_header_icon_padding"
+    android:paddingStart="@dimen/system_shortcut_header_icon_padding_outer"
+    android:paddingEnd="@dimen/system_shortcut_header_icon_padding_inner"
+    android:theme="@style/PopupItemIconOnly" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index aa84d2b..21f614f 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -281,7 +281,7 @@
     <dimen name="deep_shortcuts_elevation">2dp</dimen>
     <dimen name="bg_popup_padding">2dp</dimen>
     <dimen name="bg_popup_item_width">216dp</dimen>
-    <dimen name="bg_popup_item_height">56dp</dimen>
+    <dimen name="bg_popup_item_height">52dp</dimen>
     <dimen name="bg_popup_item_vertical_padding">12dp</dimen>
     <dimen name="pre_drag_view_scale">6dp</dimen>
     <!-- an icon with shortcuts must be dragged this far before the container is removed. -->
@@ -290,10 +290,10 @@
     <dimen name="popup_margin">2dp</dimen>
     <dimen name="popup_single_item_radius">100dp</dimen>
     <dimen name="popup_smaller_radius">4dp</dimen>
-    <dimen name="deep_shortcut_drawable_padding">12dp</dimen>
+    <dimen name="deep_shortcut_drawable_padding">16dp</dimen>
     <dimen name="deep_shortcut_drag_handle_size">16dp</dimen>
     <dimen name="popup_padding_start">10dp</dimen>
-    <dimen name="popup_padding_end">16dp</dimen>
+    <dimen name="popup_padding_end">14dp</dimen>
     <dimen name="popup_vertical_padding">4dp</dimen>
     <dimen name="popup_arrow_width">12dp</dimen>
     <dimen name="popup_arrow_height">10dp</dimen>
@@ -301,32 +301,40 @@
     <!-- popup_padding_start + deep_shortcut_icon_size / 2 -->
     <dimen name="popup_arrow_horizontal_center_offset">26dp</dimen>
     <dimen name="popup_arrow_corner_radius">2dp</dimen>
-    <!-- popup_padding_start + deep_shortcut_icon_size + 10dp -->
-    <dimen name="deep_shortcuts_text_padding_start">52dp</dimen>
+    <!-- popup_padding_start + deep_shortcut_icon_size + 12dp -->
+    <dimen name="deep_shortcuts_text_padding_start">54dp</dimen>
     <dimen name="system_shortcut_icon_size">20dp</dimen>
     <!-- popup_arrow_horizontal_center_offset - system_shortcut_icon_size / 2 -->
     <dimen name="system_shortcut_margin_start">16dp</dimen>
-    <dimen name="system_shortcut_header_height">56dp</dimen>
+    <dimen name="system_shortcut_header_height">52dp</dimen>
     <dimen name="system_shortcut_header_icon_touch_size">48dp</dimen>
     <!-- (system_shortcut_header_icon_touch_size - system_shortcut_icon_size) / 2 -->
     <dimen name="system_shortcut_header_icon_padding">14dp</dimen>
+    <!-- side of start/end icon near to container edge -->
+    <dimen name="system_shortcut_header_icon_padding_outer">16dp</dimen>
+    <!-- side of start/end icon far from container edge -->
+    <dimen name="system_shortcut_header_icon_padding_inner">12dp</dimen>
+
 
     <!-- Notifications -->
     <dimen name="bg_round_rect_radius">8dp</dimen>
+    <dimen name="notification_container_height">104dp</dimen>
     <dimen name="notification_max_trans">8dp</dimen>
     <dimen name="notification_space">8dp</dimen>
-    <dimen name="notification_padding">16dp</dimen>
-    <dimen name="notification_padding_top">18dp</dimen>
+    <dimen name="notification_padding_end">16dp</dimen>
+    <dimen name="notification_padding_bottom">12dp</dimen>
+    <dimen name="notification_padding_top">12dp</dimen>
+    <dimen name="notification_padding_header_top">16dp</dimen>
+    <dimen name="notification_header_padding_start">14dp</dimen>
     <dimen name="notification_header_text_size">14sp</dimen>
     <dimen name="notification_header_count_text_size">12sp</dimen>
     <dimen name="notification_main_title_size">14sp</dimen>
     <dimen name="notification_main_text_size">14sp</dimen>
     <dimen name="notification_circle_icon_size">24dp</dimen>
     <dimen name="notification_icon_size">32dp</dimen>
-    <!-- Space between edge and icon and icon and text -->
-    <dimen name="notification_icon_padding">12dp</dimen>
+    <dimen name="notification_icon_padding_start">10dp</dimen>
     <!-- notification_icon_padding + notification_icon_size + notification_icon_padding -->
-    <dimen name="notification_main_text_padding_start">56dp</dimen>
+    <dimen name="notification_main_text_padding_start">54dp</dimen>
     <dimen name="horizontal_ellipsis_size">18dp</dimen>
 
     <!-- Overview -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 65d215f..5dc4f0a 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -249,6 +249,11 @@
         <item name="android:colorControlHighlight">?attr/popupColorTertiary</item>
     </style>
 
+    <style name="PopupItemIconOnly">
+        <item name="android:colorControlHighlight">?attr/popupColorTertiary</item>
+        <item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
+    </style>
+
     <!-- Drop targets -->
     <style name="DropTargetButtonBase" parent="@android:style/TextAppearance.DeviceDefault.Medium">
         <item name="android:drawablePadding">@dimen/drop_target_button_drawable_padding</item>
diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
index 43ca2a6..a7265a7 100644
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -264,14 +264,7 @@
                     shortcuts.get(0), false);
             return;
         }
-        mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons_container, this, 0);
-        for (int i = 0; i < shortcuts.size(); i++) {
-            initializeSystemShortcut(
-                    R.layout.system_shortcut_icon_only,
-                    mSystemShortcutContainer,
-                    shortcuts.get(i),
-                    i < shortcuts.size() - 1);
-        }
+        addSystemShortcutsIconsOnly(shortcuts);
     }
 
     @TargetApi(Build.VERSION_CODES.P)
@@ -404,9 +397,7 @@
         List<SystemShortcut> nonWidgetSystemShortcuts =
                 getNonWidgetSystemShortcuts(systemShortcuts);
         // If total shortcuts over threshold, collapse system shortcuts to single row
-        addSystemShortcutsMaterialU(nonWidgetSystemShortcuts,
-                R.layout.system_shortcut_icons_container_material_u,
-                R.layout.system_shortcut_icon_only);
+        addSystemShortcutsIconsOnly(nonWidgetSystemShortcuts);
         // May need to recalculate row width
         mContainerWidth = Math.max(mContainerWidth,
                 nonWidgetSystemShortcuts.size() * getResources()
@@ -473,6 +464,33 @@
         }
     }
 
+    private void addSystemShortcutsIconsOnly(List<SystemShortcut> systemShortcuts) {
+        if (systemShortcuts.size() == 0) {
+            return;
+        }
+
+        mSystemShortcutContainer = ENABLE_MATERIAL_U_POPUP.get()
+                ? inflateAndAdd(R.layout.system_shortcut_icons_container_material_u, this)
+                : inflateAndAdd(R.layout.system_shortcut_icons_container, this, 0);
+
+        for (int i = 0; i < systemShortcuts.size(); i++) {
+            @LayoutRes int shortcutIconLayout = R.layout.system_shortcut_icon_only;
+            boolean shouldAppendSpacer = true;
+
+            if (i == 0) {
+                shortcutIconLayout = R.layout.system_shortcut_icon_only_start;
+            } else if (i == systemShortcuts.size() - 1) {
+                shortcutIconLayout = R.layout.system_shortcut_icon_only_end;
+                shouldAppendSpacer = false;
+            }
+            initializeSystemShortcut(
+                    shortcutIconLayout,
+                    mSystemShortcutContainer,
+                    systemShortcuts.get(i),
+                    shouldAppendSpacer);
+        }
+    }
+
     /**
      * Inflates and adds [deepShortcutCount] number of DeepShortcutView for the  to a new container
      * @param deepShortcutCount number of DeepShortcutView instances to add
@@ -552,13 +570,13 @@
      * @param resId Resource id to use for SystemShortcut View.
      * @param container ViewGroup to add the shortcut View to as a parent
      * @param info The SystemShortcut instance to create a View for.
-     * @param shouldAddSpacer If True, will add a spacer after the shortcut, when showing the
+     * @param shouldAppendSpacer If True, will add a spacer after the shortcut, when showing the
      *                        SystemShortcut as an icon only. Used to space the shortcut icons
      *                        evenly.
      * @return The view inflated for the SystemShortcut
      */
     protected View initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info,
-            boolean shouldAddSpacer) {
+            boolean shouldAppendSpacer) {
         View view = inflateAndAdd(resId, container);
         if (view instanceof DeepShortcutView) {
             // System shortcut takes entire row with icon and text
@@ -567,7 +585,7 @@
         } else if (view instanceof ImageView) {
             // System shortcut is just an icon
             info.setIconAndContentDescriptionFor((ImageView) view);
-            if (shouldAddSpacer) inflateAndAdd(R.layout.system_shortcut_spacer, container);
+            if (shouldAppendSpacer) inflateAndAdd(R.layout.system_shortcut_spacer, container);
             view.setTooltipText(view.getContentDescription());
         }
         view.setTag(info);