Merge "Revert "Don't allow Desktop tasks to go outside Overview task bounds"" into main
diff --git a/quickstep/res/layout/task_desktop.xml b/quickstep/res/layout/task_desktop.xml
index 0472007..1564653 100644
--- a/quickstep/res/layout/task_desktop.xml
+++ b/quickstep/res/layout/task_desktop.xml
@@ -19,11 +19,16 @@
     android:id="@+id/task_view_desktop"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:clipChildren="true"
+    android:clipToPadding="true"
     android:contentDescription="@string/recent_task_desktop"
     android:defaultFocusHighlightEnabled="false"
     android:focusable="true"
+    android:padding="0.1dp"
     launcher:focusBorderColor="?attr/materialColorOutline"
     launcher:hoverBorderColor="?attr/materialColorPrimary">
+    <!-- Setting a padding of 0.1 dp since android:clipToPadding needs a non-zero value for
+    padding to work-->
     <View
         android:id="@+id/background"
         android:layout_width="match_parent"
@@ -35,9 +40,4 @@
         android:layout_height="wrap_content"
         android:inflatedId="@id/icon" />
 
-    <com.android.quickstep.views.DesktopTaskContentView
-        android:id="@+id/desktop_content"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent" />
-
 </com.android.quickstep.views.DesktopTaskView>
diff --git a/quickstep/src/com/android/quickstep/views/DesktopTaskContentView.kt b/quickstep/src/com/android/quickstep/views/DesktopTaskContentView.kt
deleted file mode 100644
index 481acac..0000000
--- a/quickstep/src/com/android/quickstep/views/DesktopTaskContentView.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2024 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 android.content.Context
-import android.graphics.Outline
-import android.graphics.Rect
-import android.util.AttributeSet
-import android.view.View
-import android.view.ViewOutlineProvider
-import android.widget.FrameLayout
-import com.android.quickstep.views.TaskView.FullscreenDrawParams
-
-class DesktopTaskContentView
-@JvmOverloads
-constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
-    private val currentFullscreenParams = FullscreenDrawParams(context)
-    private val taskCornerRadius: Float
-        get() = currentFullscreenParams.cornerRadius
-
-    private val bounds = Rect()
-
-    init {
-        clipToOutline = true
-        outlineProvider =
-            object : ViewOutlineProvider() {
-                override fun getOutline(view: View, outline: Outline) {
-                    outline.setRoundRect(bounds, taskCornerRadius)
-                }
-            }
-    }
-
-    override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
-        super.onSizeChanged(w, h, oldw, oldh)
-        bounds.set(0, 0, w, h)
-        invalidateOutline()
-    }
-}
diff --git a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt
index 5e842aa..15b0a6b 100644
--- a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt
+++ b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt
@@ -26,7 +26,6 @@
 import android.util.Log
 import android.view.Gravity
 import android.view.View
-import android.widget.FrameLayout
 import androidx.core.content.res.ResourcesCompat
 import androidx.core.view.updateLayoutParams
 import com.android.launcher3.Flags.enableRefactorTaskThumbnail
@@ -82,12 +81,12 @@
     private val tempRect = Rect()
     private lateinit var backgroundView: View
     private lateinit var iconView: TaskViewIcon
-    private lateinit var contentView: FrameLayout
+    private var childCountAtInflation = 0
 
     override fun onFinishInflate() {
         super.onFinishInflate()
         backgroundView =
-            findViewById<View>(R.id.background).apply {
+            findViewById<View>(R.id.background)!!.apply {
                 updateLayoutParams<LayoutParams> {
                     topMargin = container.deviceProfile.overviewTaskThumbnailTopMarginPx
                 }
@@ -114,12 +113,7 @@
                 )
                 setText(resources.getText(R.string.recent_task_desktop))
             }
-        contentView =
-            findViewById<FrameLayout>(R.id.desktop_content).apply {
-                updateLayoutParams<LayoutParams> {
-                    topMargin = container.deviceProfile.overviewTaskThumbnailTopMarginPx
-                }
-            }
+        childCountAtInflation = childCount
     }
 
     /** Updates this desktop task to the gives task list defined in `tasks` */
@@ -143,8 +137,13 @@
                     } else {
                         taskThumbnailViewDeprecatedPool!!.view
                     }
-                contentView.addView(snapshotView, 0)
 
+                addView(
+                    snapshotView,
+                    // Add snapshotView to the front after initial views e.g. icon and
+                    // background.
+                    childCountAtInflation,
+                )
                 TaskContainer(
                     this,
                     task,
@@ -165,7 +164,7 @@
         super.onRecycle()
         visibility = VISIBLE
         taskContainers.forEach {
-            contentView.removeView(it.snapshotView)
+            removeView(it.snapshotView)
             if (enableRefactorTaskThumbnail()) {
                 taskThumbnailViewPool!!.recycle(it.thumbnailView)
             } else {
@@ -228,7 +227,9 @@
                 width = (taskSize.width() * scaleWidth).toInt()
                 height = (taskSize.height() * scaleHeight).toInt()
                 leftMargin = (positionInParent.x * scaleWidth).toInt()
-                topMargin = (positionInParent.y * scaleHeight).toInt()
+                topMargin =
+                    (positionInParent.y * scaleHeight).toInt() +
+                        container.deviceProfile.overviewTaskThumbnailTopMarginPx
             }
             if (DEBUG) {
                 with(it.snapshotView.layoutParams as LayoutParams) {
diff --git a/quickstep/src/com/android/quickstep/views/TaskContainer.kt b/quickstep/src/com/android/quickstep/views/TaskContainer.kt
index 25aba39..959516f 100644
--- a/quickstep/src/com/android/quickstep/views/TaskContainer.kt
+++ b/quickstep/src/com/android/quickstep/views/TaskContainer.kt
@@ -151,7 +151,7 @@
         if (enableRefactorTaskThumbnail()) {
             bindThumbnailView()
         } else {
-            thumbnailViewDeprecated.bind(task, overlay, taskView)
+            thumbnailViewDeprecated.bind(task, overlay)
         }
         overlay.init()
     }
diff --git a/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java b/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java
index 5dbc2ef..56ca043 100644
--- a/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java
+++ b/quickstep/src/com/android/quickstep/views/TaskThumbnailViewDeprecated.java
@@ -110,7 +110,6 @@
     private TaskView.FullscreenDrawParams mFullscreenParams;
     private ImageView mSplashView;
     private Drawable mSplashViewDrawable;
-    private TaskView mTaskView;
 
     @Nullable
     private Task mTask;
@@ -154,11 +153,10 @@
     /**
      * Updates the thumbnail to draw the provided task
      */
-    public void bind(Task task, TaskOverlay<?> overlay, TaskView taskView) {
+    public void bind(Task task, TaskOverlay<?> overlay) {
         mOverlay = overlay;
         mOverlay.reset();
         mTask = task;
-        mTaskView = taskView;
         int color = task == null ? Color.BLACK : task.colorBackground | 0xFF000000;
         mPaint.setColor(color);
         mBackgroundPaint.setColor(color);
@@ -294,8 +292,8 @@
 
     public void drawOnCanvas(Canvas canvas, float x, float y, float width, float height,
             float cornerRadius) {
-        if (mTask != null && mTaskView.isRunningTask()
-                && !mTaskView.getShouldShowScreenshot()) {
+        if (mTask != null && getTaskView().isRunningTask()
+                && !getTaskView().getShouldShowScreenshot()) {
             canvas.drawRoundRect(x, y, width, height, cornerRadius, cornerRadius, mClearPaint);
             canvas.drawRoundRect(x, y, width, height, cornerRadius, cornerRadius,
                     mDimmingPaintAfterClearing);
@@ -336,6 +334,10 @@
         }
     }
 
+    public TaskView getTaskView() {
+        return (TaskView) getParent();
+    }
+
     public void setOverlayEnabled(boolean overlayEnabled) {
         if (mOverlayEnabled != overlayEnabled) {
             mOverlayEnabled = overlayEnabled;
@@ -388,9 +390,9 @@
         float viewCenterY = viewHeight / 2f;
         float centeredDrawableLeft = (viewWidth - drawableWidth) / 2f;
         float centeredDrawableTop = (viewHeight - drawableHeight) / 2f;
-        float nonGridScale = mTaskView == null ? 1 : 1 / mTaskView.getNonGridScale();
-        float recentsMaxScale = mTaskView == null || mTaskView.getRecentsView() == null
-                ? 1 : 1 / mTaskView.getRecentsView().getMaxScaleForFullScreen();
+        float nonGridScale = getTaskView() == null ? 1 : 1 / getTaskView().getNonGridScale();
+        float recentsMaxScale = getTaskView() == null || getTaskView().getRecentsView() == null
+                ? 1 : 1 / getTaskView().getRecentsView().getMaxScaleForFullScreen();
         float scaleX = nonGridScale * recentsMaxScale * (1 / getScaleX());
         float scaleY = nonGridScale * recentsMaxScale * (1 / getScaleY());
 
@@ -417,7 +419,7 @@
     }
 
     private boolean isThumbnailRotationDifferentFromTask() {
-        RecentsView recents = mTaskView.getRecentsView();
+        RecentsView recents = getTaskView().getRecentsView();
         if (recents == null || mThumbnailData == null) {
             return false;
         }
@@ -465,7 +467,7 @@
         if (mBitmapShader != null && mThumbnailData != null) {
             mPreviewRect.set(0, 0, mThumbnailData.getThumbnail().getWidth(),
                     mThumbnailData.getThumbnail().getHeight());
-            int currentRotation = mTaskView.getOrientedState().getRecentsActivityRotation();
+            int currentRotation = getTaskView().getOrientedState().getRecentsActivityRotation();
             boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
             mPreviewPositionHelper.updateThumbnailMatrix(mPreviewRect, mThumbnailData,
                     getMeasuredWidth(), getMeasuredHeight(), dp.isTablet, currentRotation, isRtl);
@@ -473,7 +475,7 @@
             mBitmapShader.setLocalMatrix(mPreviewPositionHelper.getMatrix());
             mPaint.setShader(mBitmapShader);
         }
-        mTaskView.updateCurrentFullscreenParams();
+        getTaskView().updateCurrentFullscreenParams();
         invalidate();
     }