Merge changes Id401f273,I0b21c8ea,Ieb7936bd into ub-launcher3-qt-dev

* changes:
  Layout aligned to dp grid for portrait (3/3)
  Layout aligned to dp grid for portrait (2/3)
  Layout aligned to dp grid for portrait (1/3)
diff --git a/go/quickstep/res/layout/clear_all_button.xml b/go/quickstep/res/layout/clear_all_button.xml
index be76d53..2f7c8ae 100644
--- a/go/quickstep/res/layout/clear_all_button.xml
+++ b/go/quickstep/res/layout/clear_all_button.xml
@@ -14,22 +14,20 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<com.android.quickstep.views.ClearAllItemView
+<FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/clear_all_item_view"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="@dimen/clear_all_item_view_height">
     <Button
         android:id="@+id/clear_all_button"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginVertical="16dp"
+        android:layout_width="@dimen/clear_all_button_width"
+        android:layout_height="match_parent"
         android:layout_gravity="center_horizontal"
-        android:paddingHorizontal="32dp"
         android:background="@drawable/clear_all_button"
         android:gravity="center"
         android:text="@string/recents_clear_all"
         android:textAllCaps="false"
         android:textColor="@color/clear_all_button_text"
         android:textSize="14sp"/>
-</com.android.quickstep.views.ClearAllItemView>
+</FrameLayout>
diff --git a/go/quickstep/res/layout/task_item_view.xml b/go/quickstep/res/layout/task_item_view.xml
index 1483d4c..699178d 100644
--- a/go/quickstep/res/layout/task_item_view.xml
+++ b/go/quickstep/res/layout/task_item_view.xml
@@ -17,14 +17,13 @@
 <com.android.quickstep.views.TaskItemView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
+    android:layout_height="@dimen/task_item_height"
     android:orientation="horizontal">
     <com.android.quickstep.views.TaskThumbnailIconView
         android:id="@+id/task_icon_and_thumbnail"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginHorizontal="8dp"
-        android:layout_marginTop="16dp">
+        android:layout_marginHorizontal="@dimen/task_thumbnail_icon_horiz_margin">
         <ImageView
             android:id="@+id/task_thumbnail"
             android:layout_width="match_parent"
@@ -39,7 +38,6 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
-        android:layout_marginHorizontal="8dp"
         android:singleLine="true"
         android:textColor="@android:color/white"
         android:textSize="24sp"/>
diff --git a/go/quickstep/res/values/dimens.xml b/go/quickstep/res/values/dimens.xml
index ee154fc..0be5ee6 100644
--- a/go/quickstep/res/values/dimens.xml
+++ b/go/quickstep/res/values/dimens.xml
@@ -15,5 +15,13 @@
      limitations under the License.
 -->
 <resources>
+    <dimen name="task_item_height">60dp</dimen>
+    <dimen name="task_item_top_margin">16dp</dimen>
+    <dimen name="task_thumbnail_icon_horiz_margin">16dp</dimen>
+
     <dimen name="task_thumbnail_corner_radius">3dp</dimen>
+
+    <dimen name="clear_all_item_view_height">36dp</dimen>
+    <dimen name="clear_all_item_view_top_margin">20dp</dimen>
+    <dimen name="clear_all_button_width">106dp</dimen>
 </resources>
\ No newline at end of file
diff --git a/go/quickstep/src/com/android/quickstep/views/ClearAllItemView.java b/go/quickstep/src/com/android/quickstep/views/ClearAllItemView.java
deleted file mode 100644
index 378dbf4..0000000
--- a/go/quickstep/src/com/android/quickstep/views/ClearAllItemView.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2019 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.
- */
-
-package com.android.quickstep.views;
-
-import static com.android.quickstep.views.TaskLayoutUtils.getClearAllItemHeight;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.widget.FrameLayout;
-
-/**
- * Recycler view item that lays out the clear all button and measures the space it takes based on
- * the device height.
- */
-public final class ClearAllItemView extends FrameLayout {
-
-    public ClearAllItemView(Context context, AttributeSet attrs) {
-        super(context, attrs);
-    }
-
-    @Override
-    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        int buttonHeight = getClearAllItemHeight(getContext());
-        int newHeightSpec = MeasureSpec.makeMeasureSpec(buttonHeight, MeasureSpec.EXACTLY);
-        super.onMeasure(widthMeasureSpec, newHeightSpec);
-    }
-}
diff --git a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
index cf6eb6d..1454953 100644
--- a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
+++ b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
@@ -20,6 +20,8 @@
 import static androidx.recyclerview.widget.LinearLayoutManager.VERTICAL;
 
 import static com.android.quickstep.TaskAdapter.CHANGE_EVENT_TYPE_EMPTY_TO_CONTENT;
+import static com.android.quickstep.TaskAdapter.ITEM_TYPE_CLEAR_ALL;
+import static com.android.quickstep.TaskAdapter.ITEM_TYPE_TASK;
 import static com.android.quickstep.TaskAdapter.TASKS_START_POSITION;
 
 import android.animation.Animator;
@@ -29,6 +31,7 @@
 import android.animation.PropertyValuesHolder;
 import android.animation.ValueAnimator;
 import android.content.Context;
+import android.graphics.Rect;
 import android.util.ArraySet;
 import android.util.AttributeSet;
 import android.util.FloatProperty;
@@ -44,6 +47,7 @@
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
+import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
 import androidx.recyclerview.widget.RecyclerView.OnChildAttachStateChangeListener;
 
 import com.android.launcher3.BaseActivity;
@@ -174,6 +178,29 @@
             mTaskRecyclerView.setItemAnimator(mDefaultItemAnimator);
             mLoadingContentItemAnimator.setOnAnimationFinishedRunnable(
                     () -> mTaskRecyclerView.setItemAnimator(new DefaultItemAnimator()));
+            ItemDecoration marginDecorator = new ItemDecoration() {
+                @Override
+                public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
+                        @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
+                    // TODO: Determine if current margins cause off screen item to be fully off
+                    // screen and if so, modify them so that it is partially off screen.
+                    int itemType = parent.getChildViewHolder(view).getItemViewType();
+                    switch (itemType) {
+                        case ITEM_TYPE_CLEAR_ALL:
+                            outRect.top = (int) getResources().getDimension(
+                                    R.dimen.clear_all_item_view_top_margin);
+                            // TODO: In landscape, add bottom margin as well since we won't have
+                            // nav bar to buffer things nicely.
+                            break;
+                        case ITEM_TYPE_TASK:
+                            outRect.top = (int) getResources().getDimension(
+                                    R.dimen.task_item_top_margin);
+                            break;
+                        default:
+                    }
+                }
+            };
+            mTaskRecyclerView.addItemDecoration(marginDecorator);
 
             mEmptyView = findViewById(R.id.recent_task_empty_view);
             mContentView = mTaskRecyclerView;
@@ -188,7 +215,6 @@
                     updateContentViewVisibility();
                 }
             });
-            // TODO: Move layout param logic into onMeasure
         }
     }
 
diff --git a/go/quickstep/src/com/android/quickstep/views/TaskItemView.java b/go/quickstep/src/com/android/quickstep/views/TaskItemView.java
index 9019205..1b61a10 100644
--- a/go/quickstep/src/com/android/quickstep/views/TaskItemView.java
+++ b/go/quickstep/src/com/android/quickstep/views/TaskItemView.java
@@ -15,8 +15,6 @@
  */
 package com.android.quickstep.views;
 
-import static com.android.quickstep.views.TaskLayoutUtils.getTaskHeight;
-
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
@@ -91,13 +89,6 @@
         CONTENT_TRANSITION_PROGRESS.setValue(this, 1.0f);
     }
 
-    @Override
-    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        int taskHeight = getTaskHeight(getContext());
-        int newHeightSpec = MeasureSpec.makeMeasureSpec(taskHeight,MeasureSpec.EXACTLY);
-        super.onMeasure(widthMeasureSpec, newHeightSpec);
-    }
-
     /**
      * Resets task item view to empty, loading UI.
      */
diff --git a/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java b/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java
deleted file mode 100644
index e28a9e0..0000000
--- a/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2019 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.
- */
-package com.android.quickstep.views;
-
-import static com.android.quickstep.TaskAdapter.MAX_TASKS_TO_DISPLAY;
-
-import android.content.Context;
-
-import com.android.launcher3.InvariantDeviceProfile;
-
-/**
- * Utils to determine dynamically task and view sizes based off the device height and width.
- */
-public final class TaskLayoutUtils {
-
-    private static final float CLEAR_ALL_ITEM_TO_HEIGHT_RATIO = 7.0f / 64;
-
-    private TaskLayoutUtils() {}
-
-    /**
-     * Calculate task height based off the available height in portrait mode such that when the
-     * recents list is full, the total height fills in the available device height perfectly. In
-     * landscape mode, we keep the same task height so that tasks scroll off the top.
-     *
-     * @param context current context
-     * @return task height
-     */
-    public static int getTaskHeight(Context context) {
-        final int availableHeight =
-                InvariantDeviceProfile.INSTANCE.get(context).portraitProfile.availableHeightPx;
-        final int availableTaskSpace = availableHeight - getClearAllItemHeight(context);
-        return (int) (availableTaskSpace * 1.0f / MAX_TASKS_TO_DISPLAY);
-    }
-
-    /**
-     * Calculate clear all item height scaled to available height in portrait mode.
-     *
-     * @param context current context
-     * @return clear all item height
-     */
-    public static int getClearAllItemHeight(Context context) {
-        final int availableHeight =
-                InvariantDeviceProfile.INSTANCE.get(context).portraitProfile.availableHeightPx;
-        return (int) (CLEAR_ALL_ITEM_TO_HEIGHT_RATIO * availableHeight);
-    }
-}