Merge "RecentsView - reduce work in color tint animator" into sc-dev
diff --git a/Android.bp b/Android.bp
index 45d022f..1b6ffe4 100644
--- a/Android.bp
+++ b/Android.bp
@@ -112,7 +112,6 @@
         "androidx.preference_preference",
         "androidx.slice_slice-view",
         "androidx.cardview_cardview",
-        "com.google.android.material_material",
         "iconloader_base",
     ],
     manifest: "AndroidManifest-common.xml",
diff --git a/AndroidManifest-common.xml b/AndroidManifest-common.xml
index 4eecf29..d725a16 100644
--- a/AndroidManifest-common.xml
+++ b/AndroidManifest-common.xml
@@ -144,7 +144,7 @@
         <activity
             android:name="com.android.launcher3.settings.SettingsActivity"
             android:label="@string/settings_button_text"
-            android:theme="@style/HomeSettings.Theme"
+            android:theme="@style/HomeSettingsTheme"
             android:exported="true"
             android:autoRemoveFromRecents="true">
             <intent-filter>
diff --git a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java
index 754782b..65cdcf0 100644
--- a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java
+++ b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java
@@ -53,14 +53,17 @@
     public static final int ERROR_PERMISSIONS = 1;
     private static final String TAG = "TaskOverlayFactoryGo";
 
-    // Empty constructor required for ResourceBasedOverride
-    public TaskOverlayFactoryGo(Context context) {}
+    private AssistContentRequester mContentRequester;
+
+    public TaskOverlayFactoryGo(Context context) {
+        mContentRequester = new AssistContentRequester(context);
+    }
 
     /**
      * Create a new overlay instance for the given View
      */
     public TaskOverlayGo createOverlay(TaskThumbnailView thumbnailView) {
-        return new TaskOverlayGo(thumbnailView);
+        return new TaskOverlayGo(thumbnailView, mContentRequester);
     }
 
     /**
@@ -72,9 +75,12 @@
         private String mTaskPackageName;
         private String mWebUrl;
         private boolean mAssistPermissionsEnabled;
+        private AssistContentRequester mFactoryContentRequester;
 
-        private TaskOverlayGo(TaskThumbnailView taskThumbnailView) {
+        private TaskOverlayGo(TaskThumbnailView taskThumbnailView,
+                AssistContentRequester assistContentRequester) {
             super(taskThumbnailView);
+            mFactoryContentRequester = assistContentRequester;
         }
 
         /**
@@ -105,9 +111,7 @@
             }
 
             int taskId = task.key.id;
-            AssistContentRequester contentRequester =
-                    new AssistContentRequester(mApplicationContext);
-            contentRequester.requestAssistContent(taskId, this::onAssistContentReceived);
+            mFactoryContentRequester.requestAssistContent(taskId, this::onAssistContentReceived);
         }
 
         /** Provide Assist Content to the overlay. */
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml
index c85d3dc..60eeaff 100644
--- a/quickstep/res/values/dimens.xml
+++ b/quickstep/res/values/dimens.xml
@@ -45,8 +45,9 @@
 
     <!-- These speeds are in dp/s -->
     <dimen name="max_task_dismiss_drag_velocity">2.25dp</dimen>
-    <dimen name="default_task_dismiss_drag_velocity">1.75dp</dimen>
-    <dimen name="default_task_dismiss_drag_velocity_grid">0.75dp</dimen>
+    <dimen name="default_task_dismiss_drag_velocity">1.5dp</dimen>
+    <dimen name="default_task_dismiss_drag_velocity_grid">1dp</dimen>
+    <dimen name="default_task_dismiss_drag_velocity_grid_focus_task">5dp</dimen>
 
     <dimen name="recents_page_spacing">16dp</dimen>
     <dimen name="recents_clear_all_deadzone_vertical_margin">70dp</dimen>
diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
index c6ea953..180af0b 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
@@ -21,6 +21,7 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.os.SystemClock;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.animation.Interpolator;
@@ -72,6 +73,7 @@
     private float mProgressMultiplier;
     private float mEndDisplacement;
     private FlingBlockCheck mFlingBlockCheck = new FlingBlockCheck();
+    private Float mOverrideVelocity = null;
 
     private TaskView mTaskBeingDragged;
 
@@ -268,6 +270,7 @@
             mCurrentAnimation.pause();
         }
         mFlingBlockCheck.unblockFling();
+        mOverrideVelocity = null;
     }
 
     @Override
@@ -283,19 +286,36 @@
             mFlingBlockCheck.onEvent();
         }
 
-        // Once halfway through task dismissal interpolation, switch from reversible dragging-task
-        // animation to playing the remaining task translation animations
-        if (mCurrentAnimation.getProgressFraction() < ANIMATION_PROGRESS_FRACTION_MIDPOINT) {
-            // Halve the value as we are animating the drag across the full length for only the
-            // first half of the progress
-            mCurrentAnimation.setPlayFraction(
-                    Utilities.boundToRange(totalDisplacement * mProgressMultiplier / 2, 0, 1));
+        if (isGoingUp) {
+            if (mCurrentAnimation.getProgressFraction() < ANIMATION_PROGRESS_FRACTION_MIDPOINT) {
+                // Halve the value when dismissing, as we are animating the drag across the full
+                // length for only the first half of the progress
+                mCurrentAnimation.setPlayFraction(
+                        Utilities.boundToRange(totalDisplacement * mProgressMultiplier / 2, 0, 1));
+            } else {
+                // Set mOverrideVelocity to control task dismiss velocity in onDragEnd
+                int velocityDimenId = R.dimen.default_task_dismiss_drag_velocity;
+                if (mRecentsView.showAsGrid()) {
+                    if (mTaskBeingDragged.isFocusedTask()) {
+                        velocityDimenId =
+                                R.dimen.default_task_dismiss_drag_velocity_grid_focus_task;
+                    } else {
+                        velocityDimenId = R.dimen.default_task_dismiss_drag_velocity_grid;
+                    }
+                }
+                mOverrideVelocity = -mTaskBeingDragged.getResources().getDimension(velocityDimenId);
+
+                // Once halfway through task dismissal interpolation, switch from reversible
+                // dragging-task animation to playing the remaining task translation animations
+                final long now = SystemClock.uptimeMillis();
+                MotionEvent upAction = MotionEvent.obtain(now, now,
+                        MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
+                mDetector.onTouchEvent(upAction);
+                upAction.recycle();
+            }
         } else {
-            float dragVelocity = -mTaskBeingDragged.getResources().getDimension(
-                    mRecentsView.showAsGrid() ? R.dimen.default_task_dismiss_drag_velocity_grid
-                            : R.dimen.default_task_dismiss_drag_velocity);
-            onDragEnd(dragVelocity);
-            return true;
+            mCurrentAnimation.setPlayFraction(
+                    Utilities.boundToRange(totalDisplacement * mProgressMultiplier, 0, 1));
         }
 
         return true;
@@ -303,6 +323,10 @@
 
     @Override
     public void onDragEnd(float velocity) {
+        if (mOverrideVelocity != null) {
+            velocity = mOverrideVelocity;
+            mOverrideVelocity = null;
+        }
         // Limit velocity, as very large scalar values make animations play too quickly
         float maxTaskDismissDragVelocity = mTaskBeingDragged.getResources().getDimension(
                 R.dimen.max_task_dismiss_drag_velocity);
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index be927e0..306032c 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -972,6 +972,10 @@
         }
         if (endTarget == HOME) {
             duration = HOME_DURATION;
+            // Early detach the nav bar once the endTarget is determined as HOME
+            if (mRecentsAnimationController != null) {
+                mRecentsAnimationController.detachNavigationBarFromApp(true);
+            }
         } else if (endTarget == RECENTS) {
             if (mRecentsView != null) {
                 int nearestPage = mRecentsView.getDestinationPage();
@@ -1496,7 +1500,7 @@
         if (LIVE_TILE.get()) {
             mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED);
             if (mRecentsAnimationController != null) {
-                mRecentsAnimationController.getController().detachNavigationBarFromApp(true);
+                mRecentsAnimationController.detachNavigationBarFromApp(true);
             }
         } else if (!hasTargets() || mRecentsAnimationController == null) {
             // If there are no targets or the animation not started, then there is nothing to finish
diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationController.java b/quickstep/src/com/android/quickstep/RecentsAnimationController.java
index 462f714..50d0569 100644
--- a/quickstep/src/com/android/quickstep/RecentsAnimationController.java
+++ b/quickstep/src/com/android/quickstep/RecentsAnimationController.java
@@ -155,6 +155,14 @@
     }
 
     /**
+     * @see RecentsAnimationControllerCompat#detachNavigationBarFromApp
+     */
+    @UiThread
+    public void detachNavigationBarFromApp(boolean moveHomeToTop) {
+        UI_HELPER_EXECUTOR.execute(() -> mController.detachNavigationBarFromApp(moveHomeToTop));
+    }
+
+    /**
      * Sets the final surface transaction on a Task. This is used by Launcher to notify the system
      * that animating Activity to PiP has completed and the associated task surface should be
      * updated accordingly. This should be called before `finish`
diff --git a/res/color-night-v31/widgets_picker_scrim.xml b/res/color-night-v31/widgets_picker_scrim.xml
new file mode 100644
index 0000000..be7010b
--- /dev/null
+++ b/res/color-night-v31/widgets_picker_scrim.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2021, 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.
+*/
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+  <item android:color="@android:color/system_neutral1_900" android:alpha="0.8" />
+</selector>
diff --git a/res/color-v31/home_settings_switch_thumb_color.xml b/res/color-v31/home_settings_switch_thumb_color.xml
deleted file mode 100644
index 91d3d9b..0000000
--- a/res/color-v31/home_settings_switch_thumb_color.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2021 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.
--->
-
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <!-- Disabled status of thumb -->
-    <item android:state_enabled="false"
-        android:color="@color/home_settings_thumb_off_color" />
-    <!-- Toggle off status of thumb -->
-    <item android:state_checked="false"
-        android:color="@color/home_settings_thumb_off_color" />
-    <!-- Enabled or toggle on status of thumb -->
-    <item android:color="@color/home_settings_state_on_color" />
-</selector>
diff --git a/res/color-v31/home_settings_switch_track_color.xml b/res/color-v31/home_settings_switch_track_color.xml
deleted file mode 100644
index 50784f5..0000000
--- a/res/color-v31/home_settings_switch_track_color.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2021 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.
--->
-
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <!-- Disabled status of thumb -->
-    <item android:state_enabled="false"
-        android:color="@color/home_settings_track_off_color"
-        android:alpha="?android:attr/disabledAlpha" />
-    <!-- Toggle off status of thumb -->
-    <item android:state_checked="false"
-        android:color="@color/home_settings_track_off_color" />
-    <!-- Enabled or toggle on status of thumb -->
-    <item android:color="@color/home_settings_track_on_color" />
-</selector>
diff --git a/res/color-v31/widgets_picker_scrim.xml b/res/color-v31/widgets_picker_scrim.xml
new file mode 100644
index 0000000..648824a
--- /dev/null
+++ b/res/color-v31/widgets_picker_scrim.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2021, 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.
+*/
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+  <item android:color="@android:color/system_neutral1_200" android:alpha="0.8" />
+</selector>
diff --git a/res/color/widgets_picker_scrim.xml b/res/color/widgets_picker_scrim.xml
new file mode 100644
index 0000000..1cf97f6
--- /dev/null
+++ b/res/color/widgets_picker_scrim.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2021, 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.
+*/
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:color="#000000" android:alpha="0.32" />
+</selector>
diff --git a/res/drawable-v31/home_settings_switch_thumb.xml b/res/drawable-v31/home_settings_switch_thumb.xml
deleted file mode 100644
index 260d5ea..0000000
--- a/res/drawable-v31/home_settings_switch_thumb.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2021 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.
--->
-
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item
-        android:top="4dp"
-        android:left="4dp"
-        android:right="4dp"
-        android:bottom="4dp">
-        <shape android:shape="oval" >
-            <size android:height="20dp" android:width="20dp" />
-            <solid android:color="@color/home_settings_switch_thumb_color" />
-        </shape>
-    </item>
-</layer-list>
\ No newline at end of file
diff --git a/res/drawable-v31/home_settings_switch_track.xml b/res/drawable-v31/home_settings_switch_track.xml
deleted file mode 100644
index 502a300..0000000
--- a/res/drawable-v31/home_settings_switch_track.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2021 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.
--->
-
-<shape
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:shape="rectangle"
-    android:width="52dp"
-    android:height="28dp">
-
-    <solid android:color="@color/home_settings_switch_track_color" />
-    <corners android:radius="35dp" />
-</shape>
\ No newline at end of file
diff --git a/res/layout-v31/settings_activity.xml b/res/layout-v31/settings_activity.xml
deleted file mode 100644
index 59e14f2..0000000
--- a/res/layout-v31/settings_activity.xml
+++ /dev/null
@@ -1,69 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2021 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.
--->
-<androidx.coordinatorlayout.widget.CoordinatorLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/content_parent"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:fitsSystemWindows="true">
-
-    <com.google.android.material.appbar.AppBarLayout
-        android:id="@+id/app_bar"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/colorPrimary"
-        android:fitsSystemWindows="true"
-        android:outlineAmbientShadowColor="@android:color/transparent"
-        android:outlineSpotShadowColor="@android:color/transparent"
-        android:theme="@style/HomeSettings.CollapsingToolbar">
-
-        <com.google.android.material.appbar.CollapsingToolbarLayout
-            android:id="@+id/collapsing_toolbar"
-            android:layout_width="match_parent"
-            android:layout_height="226dp"
-            android:clipToPadding="false"
-            app:collapsedTitleTextAppearance="@style/HomeSettings.CollapsedToolbarTitle"
-            app:contentScrim="@color/home_settings_header_collapsed"
-            app:expandedTitleMarginEnd="24dp"
-            app:expandedTitleMarginStart="24dp"
-            app:expandedTitleTextAppearance="@style/HomeSettings.ExpandedToolbarTitle"
-            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
-            app:maxLines="3"
-            app:scrimAnimationDuration="50"
-            app:scrimVisibleHeightTrigger="174dp"
-            app:statusBarScrim="@null"
-            app:titleCollapseMode="fade"
-            app:toolbarId="@id/action_bar">
-
-            <Toolbar
-                android:id="@+id/action_bar"
-                android:layout_width="match_parent"
-                android:layout_height="?attr/actionBarSize"
-                android:theme="?android:attr/actionBarTheme"
-                android:transitionName="shared_element_view"
-                app:layout_collapseMode="pin" />
-
-        </com.google.android.material.appbar.CollapsingToolbarLayout>
-    </com.google.android.material.appbar.AppBarLayout>
-
-    <FrameLayout
-        android:id="@+id/content_frame"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
-</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
diff --git a/res/layout/add_item_confirmation_activity.xml b/res/layout/add_item_confirmation_activity.xml
index ddc9815..9439baf 100644
--- a/res/layout/add_item_confirmation_activity.xml
+++ b/res/layout/add_item_confirmation_activity.xml
@@ -31,7 +31,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@drawable/add_item_dialog_background"
-        android:padding="24dp"
+        android:paddingTop="24dp"
         android:theme="?attr/widgetsTheme"
         android:layout_gravity="bottom"
         android:orientation="vertical">
@@ -42,6 +42,7 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center_horizontal"
+            android:paddingHorizontal="24dp"
             android:textColor="?android:attr/textColorPrimary"
             android:textSize="24sp"
             android:ellipsize="end"
@@ -53,6 +54,7 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center_horizontal"
+            android:paddingHorizontal="24dp"
             android:paddingTop="8dp"
             android:text="@string/add_item_request_drag_hint"
             android:textSize="14sp"
diff --git a/res/values-night-v31/colors.xml b/res/values-night-v31/colors.xml
deleted file mode 100644
index 2c1bc90..0000000
--- a/res/values-night-v31/colors.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!--
-/*
-* Copyright (C) 2021 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.
-*/
--->
-
-<resources>
-    <color name="home_settings_header_accent">@android:color/system_accent1_100</color>
-    <color name="home_settings_header_collapsed">@android:color/system_neutral1_700</color>
-    <color name="home_settings_header_expanded">@android:color/system_neutral1_900</color>
-
-    <color name="home_settings_thumb_off_color">@android:color/system_neutral2_300</color>
-    <color name="home_settings_track_on_color">@android:color/system_accent2_700</color>
-    <color name="home_settings_track_off_color">@android:color/system_neutral1_700</color>
-</resources>
\ No newline at end of file
diff --git a/res/values-v31/colors.xml b/res/values-v31/colors.xml
index 53c6a35..7b37001 100644
--- a/res/values-v31/colors.xml
+++ b/res/values-v31/colors.xml
@@ -37,13 +37,4 @@
 
     <color name="wallpaper_popup_scrim">@android:color/system_neutral1_900</color>
 
-    <color name="home_settings_header_accent">@android:color/system_accent1_600</color>
-    <color name="home_settings_header_collapsed">@android:color/system_neutral1_100</color>
-    <color name="home_settings_header_expanded">@android:color/system_neutral1_50</color>
-
-    <color name="home_settings_state_on_color">@android:color/system_accent1_100</color>
-    <color name="home_settings_state_off_color">@android:color/system_accent2_100</color>
-    <color name="home_settings_thumb_off_color">@android:color/system_neutral2_100</color>
-    <color name="home_settings_track_on_color">@android:color/system_accent1_600</color>
-    <color name="home_settings_track_off_color">@android:color/system_neutral2_600</color>
 </resources>
diff --git a/res/values-v31/config.xml b/res/values-v31/config.xml
deleted file mode 100644
index afb9e6d..0000000
--- a/res/values-v31/config.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-    Copyright (C) 2021 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.
-  -->
-<resources>
-    <bool name="home_settings_icon_space_reserved">false</bool>
-    <bool name="home_settings_allow_divider">false</bool>
-</resources>
\ No newline at end of file
diff --git a/res/values-v31/styles.xml b/res/values-v31/styles.xml
deleted file mode 100644
index 0d2fce0..0000000
--- a/res/values-v31/styles.xml
+++ /dev/null
@@ -1,95 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-* Copyright (C) 2021 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.
-*/
--->
-
-<resources>
-
-    <style name="HomeSettings.Theme" parent="@android:style/Theme.DeviceDefault.Settings">
-        <item name="android:listPreferredItemPaddingEnd">16dp</item>
-        <item name="android:listPreferredItemPaddingStart">24dp</item>
-        <item name="android:navigationBarColor">@android:color/transparent</item>
-        <item name="android:statusBarColor">@android:color/transparent</item>
-        <item name="android:switchStyle">@style/HomeSettings.SwitchStyle</item>
-        <item name="android:textAppearanceListItem">@style/HomeSettings.PreferenceTitle</item>
-        <item name="android:windowActionBar">false</item>
-        <item name="android:windowNoTitle">true</item>
-        <item name="preferenceTheme">@style/HomeSettings.PreferenceTheme</item>
-    </style>
-
-    <style name="HomeSettings.PreferenceTheme" parent="@style/PreferenceThemeOverlay">
-        <item name="preferenceCategoryStyle">@style/HomeSettings.CategoryStyle</item>
-        <item name="preferenceCategoryTitleTextAppearance">@style/HomeSettings.CategoryTitle</item>
-        <item name="preferenceFragmentCompatStyle">@style/HomeSettings.FragmentCompatStyle</item>
-        <item name="preferenceScreenStyle">@style/HomeSettings.PreferenceScreenStyle</item>
-        <item name="preferenceStyle">@style/HomeSettings.PreferenceStyle</item>
-        <item name="switchPreferenceStyle">@style/HomeSettings.SwitchPreferenceStyle</item>
-    </style>
-
-    <style name="HomeSettings.CategoryStyle" parent="@style/Preference.Category.Material">
-        <item name="allowDividerAbove">@bool/home_settings_allow_divider</item>
-        <item name="allowDividerBelow">@bool/home_settings_allow_divider</item>
-        <item name="iconSpaceReserved">@bool/home_settings_icon_space_reserved</item>
-    </style>
-
-    <style name="HomeSettings.PreferenceStyle" parent="@style/Preference.Material">
-        <item name="iconSpaceReserved">@bool/home_settings_icon_space_reserved</item>
-    </style>
-
-    <style name="HomeSettings.PreferenceScreenStyle"
-            parent="@style/Preference.PreferenceScreen.Material">
-        <item name="iconSpaceReserved">@bool/home_settings_icon_space_reserved</item>
-    </style>
-
-    <style name="HomeSettings.SwitchPreferenceStyle"
-            parent="@style/Preference.SwitchPreference.Material">
-        <item name="iconSpaceReserved">@bool/home_settings_icon_space_reserved</item>
-    </style>
-
-    <style name="HomeSettings.SwitchStyle"
-            parent="@android:style/Widget.Material.CompoundButton.Switch">
-        <item name="android:switchMinWidth">52dp</item>
-        <item name="android:thumb">@drawable/home_settings_switch_thumb</item>
-        <item name="android:track">@drawable/home_settings_switch_track</item>
-    </style>
-
-    <style name="HomeSettings.PreferenceTitle"
-            parent="@android:style/TextAppearance.Material.Subhead">
-        <item name="android:fontFamily">google-sans</item>
-        <item name="android:textSize">20sp</item>
-    </style>
-
-    <style name="HomeSettings.CategoryTitle" parent="@android:style/TextAppearance.Material.Body2">
-        <item name="android:fontFamily">google-sans-text-medium</item>
-    </style>
-
-    <style name="HomeSettings.CollapsingToolbar" parent="@style/Theme.MaterialComponents.DayNight">
-        <item name="colorAccent">@color/home_settings_header_accent</item>
-        <item name="colorPrimary">@color/home_settings_header_expanded</item>
-        <item name="elevationOverlayColor">?attr/colorPrimary</item>
-        <item name="elevationOverlayEnabled">true</item>
-    </style>
-
-    <style name="HomeSettings.CollapsedToolbarTitle"
-            parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title">
-        <item name="android:fontFamily">google-sans</item>
-    </style>
-
-    <style name="HomeSettings.ExpandedToolbarTitle" parent="HomeSettings.CollapsedToolbarTitle">
-        <item name="android:textSize">36sp</item>
-    </style>
-</resources>
\ No newline at end of file
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0f8169e..92824ad 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -154,18 +154,18 @@
     <style name="AppTheme.Dark.DarkMainColor" parent="@style/LauncherTheme.Dark.DarkMainColor" />
     <style name="AppTheme.Dark.DarkText" parent="@style/LauncherTheme.Dark.DarkText" />
 
-    <style name="HomeSettings.Theme" parent="@android:style/Theme.DeviceDefault.Settings">
+    <style name="HomeSettingsTheme" parent="@android:style/Theme.DeviceDefault.Settings">
         <item name="android:navigationBarColor">?android:colorPrimaryDark</item>
         <item name="android:windowActionBar">false</item>
         <item name="android:windowNoTitle">true</item>
-        <item name="preferenceTheme">@style/HomeSettings.PreferenceTheme</item>
+        <item name="preferenceTheme">@style/HomeSettingsPreferenceTheme</item>
     </style>
 
-    <style name="HomeSettings.PreferenceTheme" parent="@style/PreferenceThemeOverlay.v14.Material">
-        <item name="preferenceFragmentCompatStyle">@style/HomeSettings.FragmentCompatStyle</item>
+    <style name="HomeSettingsPreferenceTheme" parent="@style/PreferenceThemeOverlay.v14.Material">
+        <item name="preferenceFragmentCompatStyle">@style/HomeSettingsFragmentCompatStyle</item>
     </style>
 
-    <style name="HomeSettings.FragmentCompatStyle" parent="@style/PreferenceFragment.Material">
+    <style name="HomeSettingsFragmentCompatStyle" parent="@style/PreferenceFragment.Material">
         <item name="android:layout">@layout/home_settings</item>
     </style>
 
diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java
index 5dae5a6..b4288ce 100644
--- a/src/com/android/launcher3/dragndrop/AddItemActivity.java
+++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java
@@ -59,6 +59,7 @@
 import com.android.launcher3.util.SystemUiController;
 import com.android.launcher3.views.AbstractSlideInView;
 import com.android.launcher3.views.BaseDragLayer;
+import com.android.launcher3.widget.AddItemWidgetsBottomSheet;
 import com.android.launcher3.widget.LauncherAppWidgetHost;
 import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
 import com.android.launcher3.widget.NavigableAppWidgetHostView;
@@ -89,6 +90,7 @@
     private LauncherAppState mApp;
     private InvariantDeviceProfile mIdp;
     private BaseDragLayer<AddItemActivity> mDragLayer;
+    private AddItemWidgetsBottomSheet mSlideInView;
 
     private WidgetCell mWidgetCell;
 
@@ -124,8 +126,6 @@
         mDragLayer = findViewById(R.id.add_item_drag_layer);
         mDragLayer.recreateControllers();
         mDragLayer.setInsets(mDeviceProfile.getInsets());
-        AbstractSlideInView<AddItemActivity> slideInView = findViewById(R.id.add_item_bottom_sheet);
-        slideInView.addOnCloseListener(this);
         mWidgetCell = findViewById(R.id.widget_cell);
 
         if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
@@ -151,6 +151,9 @@
         TextView widgetAppName = findViewById(R.id.widget_appName);
         widgetAppName.setText(getApplicationInfo().labelRes);
 
+        mSlideInView = findViewById(R.id.add_item_bottom_sheet);
+        mSlideInView.addOnCloseListener(this);
+        mSlideInView.show();
         setupNavBarColor();
     }
 
@@ -279,7 +282,7 @@
      */
     public void onCancelClick(View v) {
         logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_CANCELLED);
-        finish();
+        mSlideInView.close(/* animate= */ true);
     }
 
     /**
@@ -290,7 +293,7 @@
             ItemInstallQueue.INSTANCE.get(this).queueItem(mRequest.getShortcutInfo());
             logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_PLACED_AUTOMATICALLY);
             mRequest.accept();
-            finish();
+            mSlideInView.close(/* animate= */ true);
             return;
         }
 
@@ -313,7 +316,7 @@
         mWidgetOptions.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
         mRequest.accept(mWidgetOptions);
         logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_PLACED_AUTOMATICALLY);
-        finish();
+        mSlideInView.close(/* animate= */ true);
     }
 
     @Override
diff --git a/src/com/android/launcher3/views/WidgetsEduView.java b/src/com/android/launcher3/views/WidgetsEduView.java
index e69cb5b..c6fa98a 100644
--- a/src/com/android/launcher3/views/WidgetsEduView.java
+++ b/src/com/android/launcher3/views/WidgetsEduView.java
@@ -35,8 +35,6 @@
 
     private static final int DEFAULT_CLOSE_DURATION = 200;
 
-    protected static final int FINAL_SCRIM_BG_COLOR = 0x88000000;
-
     private Rect mInsets = new Rect();
     private View mEduView;
 
@@ -87,7 +85,7 @@
 
     @Override
     protected int getScrimColor(Context context) {
-        return FINAL_SCRIM_BG_COLOR;
+        return context.getResources().getColor(R.color.widgets_picker_scrim);
     }
 
     @Override
diff --git a/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java b/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java
index 9e08303..804973f 100644
--- a/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java
+++ b/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java
@@ -23,8 +23,11 @@
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.util.AttributeSet;
+import android.view.ViewGroup;
+import android.view.ViewParent;
 
 import com.android.launcher3.Insettable;
+import com.android.launcher3.R;
 import com.android.launcher3.dragndrop.AddItemActivity;
 import com.android.launcher3.views.AbstractSlideInView;
 
@@ -48,6 +51,17 @@
         mContent = this;
         mInsets = new Rect();
         mCurrentConfiguration = new Configuration(getResources().getConfiguration());
+    }
+
+    /**
+     * Attaches to activity container and animates open the bottom sheet.
+     */
+    public void show() {
+        ViewParent parent = getParent();
+        if (parent instanceof ViewGroup) {
+            ((ViewGroup) parent).removeView(this);
+        }
+        attachToContainer();
         animateOpen();
     }
 
@@ -95,4 +109,9 @@
         }
         mCurrentConfiguration.updateFrom(newConfig);
     }
+
+    @Override
+    protected int getScrimColor(Context context) {
+        return context.getResources().getColor(R.color.widgets_picker_scrim);
+    }
 }
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index e6791c3..edd42b4 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -15,8 +15,6 @@
  */
 package com.android.launcher3.widget;
 
-import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;
-
 import android.content.Context;
 import android.graphics.Point;
 import android.graphics.Rect;
@@ -62,8 +60,7 @@
     }
 
     protected int getScrimColor(Context context) {
-        int alpha = context.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
-        return setColorAlphaBound(context.getColor(R.color.wallpaper_popup_scrim), alpha);
+        return context.getResources().getColor(R.color.widgets_picker_scrim);
     }
 
     @Override
diff --git a/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java b/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java
index 7963431..3936ec8 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java
@@ -25,6 +25,7 @@
 import android.view.ViewGroup;
 import android.widget.TableRow;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.recyclerview.widget.RecyclerView.Adapter;
@@ -48,8 +49,10 @@
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.OptionalInt;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 /**
  * Recycler view adapter for the widget tray.
@@ -87,6 +90,7 @@
                     || new PackageUserKey(entry.mPkgItem.packageName, entry.mPkgItem.user)
                             .equals(mWidgetsContentVisiblePackageUserKey);
     @Nullable private Predicate<WidgetsListBaseEntry> mFilter = null;
+    @Nullable private RecyclerView mRecyclerView;
 
     public WidgetsListAdapter(Context context, LayoutInflater layoutInflater,
             WidgetPreviewLoader widgetPreviewLoader, IconCache iconCache,
@@ -106,6 +110,16 @@
                         layoutInflater, /*onHeaderClickListener=*/ this, /* listAdapter= */ this));
     }
 
+    @Override
+    public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
+        mRecyclerView = recyclerView;
+    }
+
+    @Override
+    public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
+        mRecyclerView = null;
+    }
+
     public void setFilter(Predicate<WidgetsListBaseEntry> filter) {
         mFilter = filter;
     }
@@ -168,12 +182,10 @@
         mAllEntries.forEach(entry -> {
             if (entry instanceof WidgetsListHeaderEntry) {
                 ((WidgetsListHeaderEntry) entry).setIsWidgetListShown(
-                        new PackageUserKey(entry.mPkgItem.packageName, entry.mPkgItem.user)
-                                .equals(mWidgetsContentVisiblePackageUserKey));
+                        isHeaderForVisibleContent(entry));
             } else if (entry instanceof WidgetsListSearchHeaderEntry) {
                 ((WidgetsListSearchHeaderEntry) entry).setIsWidgetListShown(
-                        new PackageUserKey(entry.mPkgItem.packageName, entry.mPkgItem.user)
-                                .equals(mWidgetsContentVisiblePackageUserKey));
+                        isHeaderForVisibleContent(entry));
             }
         });
         List<WidgetsListBaseEntry> newVisibleEntries = mAllEntries.stream()
@@ -183,6 +195,13 @@
         mDiffReporter.process(mVisibleEntries, newVisibleEntries, mRowComparator);
     }
 
+    private boolean isHeaderForVisibleContent(WidgetsListBaseEntry entry) {
+        return (entry instanceof WidgetsListHeaderEntry
+                || entry instanceof WidgetsListSearchHeaderEntry)
+                && new PackageUserKey(entry.mPkgItem.packageName, entry.mPkgItem.user)
+                .equals(mWidgetsContentVisiblePackageUserKey);
+    }
+
     /**
      * Resets any expanded widget header.
      */
@@ -247,12 +266,40 @@
         if (showWidgets) {
             mWidgetsContentVisiblePackageUserKey = packageUserKey;
             updateVisibleEntries();
+            // Scroll the layout manager to the header position to keep it anchored to the same
+            // position.
+            scrollToSelectedHeaderPosition();
         } else if (packageUserKey.equals(mWidgetsContentVisiblePackageUserKey)) {
             mWidgetsContentVisiblePackageUserKey = null;
             updateVisibleEntries();
         }
     }
 
+    private void scrollToSelectedHeaderPosition() {
+        OptionalInt selectedHeaderPosition =
+                IntStream.range(0, mVisibleEntries.size())
+                        .filter(index -> isHeaderForVisibleContent(mVisibleEntries.get(index)))
+                        .findFirst();
+        RecyclerView.LayoutManager layoutManager =
+                mRecyclerView == null ? null : mRecyclerView.getLayoutManager();
+        if (!selectedHeaderPosition.isPresent() || layoutManager == null) {
+            return;
+        }
+
+        // Scroll to the selected header position. LinearLayoutManager scrolls the minimum distance
+        // necessary, so this will keep the selected header in place during clicks, without
+        // interrupting the animation.
+        int position = selectedHeaderPosition.getAsInt();
+        if (position == mVisibleEntries.size() - 2) {
+            // If the selected header is in the last position (-1 for the content), then scroll to
+            // the final position so the last list of widgets will show.
+            layoutManager.scrollToPosition(mVisibleEntries.size() - 1);
+        } else {
+            // Otherwise, scroll to the position of the selected header.
+            layoutManager.scrollToPosition(position);
+        }
+    }
+
     /**
      * Sets the max horizontal spans that are allowed for grouping more than one widgets in a table
      * row.
diff --git a/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java
index e30e245..090362b 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java
@@ -154,8 +154,25 @@
             return -1;
         }
 
-        View child = getChildAt(0);
-        int rowIndex = getChildPosition(child);
+        int rowIndex = -1;
+        View child = null;
+
+        LayoutManager layoutManager = getLayoutManager();
+        if (layoutManager instanceof LinearLayoutManager) {
+            // Use the LayoutManager as the source of truth for visible positions. During
+            // animations, the view group child may not correspond to the visible views that appear
+            // at the top.
+            rowIndex = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
+            child = layoutManager.findViewByPosition(rowIndex);
+        }
+
+        if (child == null) {
+            // If the layout manager returns null for any reason, which can happen before layout
+            // has occurred for the position, then look at the child of this view as a ViewGroup.
+            child = getChildAt(0);
+            rowIndex = getChildPosition(child);
+        }
+
         for (int i = 0; i < getChildCount(); i++) {
             View view = getChildAt(i);
             if (view instanceof TableLayout) {