Merge "Fix foldable single page bug" into tm-qpr-dev
diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java
index 2200b35..139e923 100644
--- a/quickstep/src/com/android/quickstep/SystemUiProxy.java
+++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java
@@ -628,14 +628,20 @@
         }
     }
 
-    public void startIntentsWithLegacyTransition(PendingIntent pendingIntent1, Bundle options1,
-            PendingIntent pendingIntent2, Bundle options2,
-            @SplitConfigurationOptions.StagePosition int sidePosition, float splitRatio,
-            RemoteAnimationAdapter adapter, InstanceId instanceId) {
+    /**
+     * Starts a pair of intents or shortcuts in split-screen using legacy transition. Passing a
+     * non-null shortcut info means to start the app as a shortcut.
+     */
+    public void startIntentsWithLegacyTransition(PendingIntent pendingIntent1,
+            @Nullable ShortcutInfo shortcutInfo1, @Nullable Bundle options1,
+            PendingIntent pendingIntent2, @Nullable ShortcutInfo shortcutInfo2,
+            @Nullable Bundle options2, @SplitConfigurationOptions.StagePosition int sidePosition,
+            float splitRatio, RemoteAnimationAdapter adapter, InstanceId instanceId) {
         if (mSystemUiProxy != null) {
             try {
-                mSplitScreen.startIntentsWithLegacyTransition(pendingIntent1, options1,
-                        pendingIntent2, options2, sidePosition, splitRatio, adapter, instanceId);
+                mSplitScreen.startIntentsWithLegacyTransition(pendingIntent1, shortcutInfo1,
+                        options1, pendingIntent2, shortcutInfo2, options2, sidePosition, splitRatio,
+                        adapter, instanceId);
             } catch (RemoteException e) {
                 Log.w(TAG, "Failed call startIntentsWithLegacyTransition");
             }
diff --git a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
index e5d54d7..1b2bfc9 100644
--- a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
+++ b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
@@ -261,8 +261,9 @@
                         getOppositeStagePosition(stagePosition), splitRatio, adapter,
                         shellInstanceId);
             } else {
-                mSystemUiProxy.startIntentsWithLegacyTransition(getPendingIntent(intent1),
-                        options1.toBundle(), getPendingIntent(intent2), null /* options2 */,
+                mSystemUiProxy.startIntentsWithLegacyTransition(
+                        getPendingIntent(intent1), getShortcutInfo(intent1), options1.toBundle(),
+                        getPendingIntent(intent2), getShortcutInfo(intent2), null /* options2 */,
                         stagePosition, splitRatio, adapter, shellInstanceId);
             }
         }
@@ -271,15 +272,13 @@
     private void launchIntentOrShortcut(Intent intent, ActivityOptions options1, int taskId,
             @StagePosition int stagePosition, float splitRatio, RemoteTransition remoteTransition,
             @Nullable InstanceId shellInstanceId) {
-        PendingIntent pendingIntent = getPendingIntent(intent);
-        final ShortcutInfo shortcutInfo = getShortcutInfo(intent,
-                pendingIntent.getCreatorUserHandle());
+        final ShortcutInfo shortcutInfo = getShortcutInfo(intent);
         if (shortcutInfo != null) {
             mSystemUiProxy.startShortcutAndTask(shortcutInfo,
                     options1.toBundle(), taskId, null /* options2 */, stagePosition,
                     splitRatio, remoteTransition, shellInstanceId);
         } else {
-            mSystemUiProxy.startIntentAndTask(pendingIntent, options1.toBundle(), taskId,
+            mSystemUiProxy.startIntentAndTask(getPendingIntent(intent), options1.toBundle(), taskId,
                     null /* options2 */, stagePosition, splitRatio, remoteTransition,
                     shellInstanceId);
         }
@@ -288,15 +287,13 @@
     private void launchIntentOrShortcutLegacy(Intent intent, ActivityOptions options1, int taskId,
             @StagePosition int stagePosition, float splitRatio, RemoteAnimationAdapter adapter,
             @Nullable InstanceId shellInstanceId) {
-        PendingIntent pendingIntent = getPendingIntent(intent);
-        final ShortcutInfo shortcutInfo = getShortcutInfo(intent,
-                pendingIntent.getCreatorUserHandle());
+        final ShortcutInfo shortcutInfo = getShortcutInfo(intent);
         if (shortcutInfo != null) {
             mSystemUiProxy.startShortcutAndTaskWithLegacyTransition(shortcutInfo,
                     options1.toBundle(), taskId, null /* options2 */, stagePosition,
                     splitRatio, adapter, shellInstanceId);
         } else {
-            mSystemUiProxy.startIntentAndTaskWithLegacyTransition(pendingIntent,
+            mSystemUiProxy.startIntentAndTaskWithLegacyTransition(getPendingIntent(intent),
                     options1.toBundle(), taskId, null /* options2 */, stagePosition, splitRatio,
                     adapter, shellInstanceId);
         }
@@ -322,7 +319,7 @@
     }
 
     @Nullable
-    private ShortcutInfo getShortcutInfo(Intent intent, UserHandle userHandle) {
+    private ShortcutInfo getShortcutInfo(Intent intent) {
         if (intent == null || intent.getPackage() == null) {
             return null;
         }
@@ -334,7 +331,7 @@
 
         try {
             final Context context = mContext.createPackageContextAsUser(
-                    intent.getPackage(), 0 /* flags */, userHandle);
+                    intent.getPackage(), 0 /* flags */, mUser);
             return new ShortcutInfo.Builder(context, shortcutId).build();
         } catch (PackageManager.NameNotFoundException e) {
             Log.w(TAG, "Failed to create a ShortcutInfo for " + intent.getPackage());
diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml
index 63970cd..92f6881 100644
--- a/res/values-sw600dp-land/dimens.xml
+++ b/res/values-sw600dp-land/dimens.xml
@@ -30,6 +30,4 @@
     <dimen name="dynamic_grid_edge_margin">11.33dp</dimen>
     <dimen name="cell_layout_padding">11.33dp</dimen>
 
-<!-- AllApps -->
-    <dimen name="all_apps_bottom_sheet_horizontal_padding">52dp</dimen>
 </resources>
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index d69e777..0af0603 100644
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -26,7 +26,6 @@
 
 <!-- AllApps -->
     <dimen name="all_apps_search_bar_content_overlap">0dp</dimen>
-    <dimen name="all_apps_bottom_sheet_horizontal_padding">48dp</dimen>
 
 <!-- Fast scroll -->
     <dimen name="fastscroll_popup_width">75dp</dimen>
diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml
index 235631d..6362960 100644
--- a/res/values-sw720dp-land/dimens.xml
+++ b/res/values-sw720dp-land/dimens.xml
@@ -22,9 +22,6 @@
     <dimen name="dynamic_grid_edge_margin">21.93dp</dimen>
     <dimen name="cell_layout_padding">29.33dp</dimen>
 
-<!-- AllApps -->
-    <dimen name="all_apps_bottom_sheet_horizontal_padding">32dp</dimen>
-
 <!-- Dragging-->
     <dimen name="drop_target_top_margin">0dp</dimen>
     <dimen name="drop_target_bottom_margin">32dp</dimen>
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index 09b2d6f..d7a5881 100644
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -18,9 +18,6 @@
 <!-- PagedView  -->
     <dimen name="min_page_snap_velocity">3400dp</dimen>
 
-<!-- AllApps -->
-    <dimen name="all_apps_bottom_sheet_horizontal_padding">28dp</dimen>
-
 <!-- Dynamic grid -->
     <dimen name="dynamic_grid_edge_margin">27.59dp</dimen>
     <dimen name="cell_layout_padding">36dp</dimen>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index e6f285c..26180f3 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -151,6 +151,9 @@
         <!-- Support attributes in FolderStyle -->
         <attr name="folderStyle" format="reference" />
 
+        <!-- Support attributes in AllAppsStyle. Defaults to AllAppsStyleDefault -->
+        <attr name="allAppsStyle" format="reference" />
+
         <!-- numAllAppsColumns defaults to numColumns, if not specified -->
         <attr name="numAllAppsColumns" format="integer" />
         <!-- Number of columns to use when extending the all-apps size,
@@ -418,6 +421,10 @@
         <attr name="iconDrawablePadding" format="dimension" />
     </declare-styleable>
 
+    <declare-styleable name="AllAppsStyle">
+        <attr name="horizontalPadding" format="dimension" />
+    </declare-styleable>
+
     <declare-styleable name="ShadowDrawable">
         <attr name="android:src" />
         <attr name="android:shadowColor" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 321aef5..a9638f9 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -131,7 +131,6 @@
     <dimen name="all_apps_content_fade_in_offset">150dp</dimen>
     <dimen name="all_apps_tip_bottom_margin">8dp</dimen>
     <dimen name="all_apps_height_extra">6dp</dimen>
-    <dimen name="all_apps_bottom_sheet_horizontal_padding">0dp</dimen>
     <dimen name="all_apps_paged_view_top_padding">40dp</dimen>
 
     <dimen name="all_apps_icon_drawable_padding">8dp</dimen>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 6b57532..a0b5570 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -304,4 +304,8 @@
         <item name="iconDrawablePadding">7dp</item>
     </style>
 
+    <style name="AllAppsStyleDefault">
+        <item name="horizontalPadding">16dp</item>
+    </style>
+
 </resources>
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 0070f95..086cf05 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -404,6 +404,7 @@
         allAppsBorderSpacePx = new Point(
                 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
                 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
+        setupAllAppsStyle(context);
 
         workspacePageIndicatorHeight = res.getDimensionPixelSize(
                 R.dimen.workspace_page_indicator_height);
@@ -810,9 +811,6 @@
         int cellLayoutHorizontalPadding =
                 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
         if (isTablet) {
-            allAppsLeftRightPadding =
-                    res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
-
             int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
                     + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
                     + allAppsLeftRightPadding * 2;
@@ -823,6 +821,20 @@
         }
     }
 
+    private void setupAllAppsStyle(Context context) {
+        TypedArray allAppsStyle;
+        if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
+            allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
+                    R.styleable.AllAppsStyle);
+        } else {
+            allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
+                    R.styleable.AllAppsStyle);
+        }
+        allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
+                R.styleable.AllAppsStyle_horizontalPadding, 0);
+        allAppsStyle.recycle();
+    }
+
     /**
      * Returns the amount of extra (or unused) vertical space.
      */
@@ -1806,7 +1818,7 @@
          * Set the viewScaleProvider for the builder
          *
          * @param viewScaleProvider The viewScaleProvider to be set for the
-         *                                DeviceProfile
+         *                          DeviceProfile
          * @return This builder
          */
         @NonNull
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index d97eac9..604c1b8 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -175,6 +175,7 @@
      */
     public int numAllAppsColumns;
     public int numDatabaseAllAppsColumns;
+    public @StyleRes int allAppsStyle;
 
     /**
      * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
@@ -384,6 +385,8 @@
         hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
         hotseatQsbSpace = displayOption.hotseatQsbSpace;
 
+        allAppsStyle = closestProfile.allAppsStyle;
+
         numAllAppsColumns = closestProfile.numAllAppsColumns;
         numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
                 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
@@ -789,6 +792,7 @@
         private final @StyleRes int folderStyle;
         private final @StyleRes int cellStyle;
 
+        private final @StyleRes int allAppsStyle;
         private final int numAllAppsColumns;
         private final int numDatabaseAllAppsColumns;
         private final int numHotseatIcons;
@@ -824,6 +828,8 @@
             demoModeLayoutId = a.getResourceId(
                     R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
 
+            allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
+                    R.style.AllAppsStyleDefault);
             numAllAppsColumns = a.getInt(
                     R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
             numDatabaseAllAppsColumns = a.getInt(
diff --git a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt
index 0aecfb2..daf4608 100644
--- a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt
+++ b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt
@@ -120,6 +120,7 @@
 
                 horizontalMargin = FloatArray(4) { 22f }
 
+                allAppsStyle = R.style.AllAppsStyleDefault
                 allAppsCellSize =
                     listOf(
                             PointF(80f, 104f),
@@ -198,6 +199,7 @@
 
                 horizontalMargin = floatArrayOf(54f, 120f, 54f, 54f)
 
+                allAppsStyle = R.style.AllAppsStyleDefault
                 allAppsCellSize =
                     listOf(
                             PointF(96f, 142f),
@@ -277,6 +279,7 @@
 
                 horizontalMargin = floatArrayOf(21.5f, 21.5f, 22.5f, 30.5f)
 
+                allAppsStyle = R.style.AllAppsStyleDefault
                 allAppsCellSize =
                     listOf(PointF(0f, 0f), PointF(0f, 0f), PointF(68f, 104f), PointF(80f, 104f))
                         .toTypedArray()