Merge "Round thumbnail corners" into ub-launcher3-qt-dev
diff --git a/go/quickstep/res/drawable/default_thumbnail.xml b/go/quickstep/res/drawable/default_thumbnail.xml
index 0a2dbf0..ab22dcf 100644
--- a/go/quickstep/res/drawable/default_thumbnail.xml
+++ b/go/quickstep/res/drawable/default_thumbnail.xml
@@ -18,5 +18,5 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle">
     <solid android:color="@android:color/darker_gray"/>
-    <corners android:radius="2dp"/>
+    <corners android:radius="@dimen/task_thumbnail_corner_radius"/>
 </shape>
diff --git a/go/quickstep/res/values/dimens.xml b/go/quickstep/res/values/dimens.xml
new file mode 100644
index 0000000..ee154fc
--- /dev/null
+++ b/go/quickstep/res/values/dimens.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+<resources>
+    <dimen name="task_thumbnail_corner_radius">3dp</dimen>
+</resources>
\ No newline at end of file
diff --git a/go/quickstep/src/com/android/quickstep/ThumbnailDrawable.java b/go/quickstep/src/com/android/quickstep/ThumbnailDrawable.java
index 6ef9039..a8cc0a1 100644
--- a/go/quickstep/src/com/android/quickstep/ThumbnailDrawable.java
+++ b/go/quickstep/src/com/android/quickstep/ThumbnailDrawable.java
@@ -16,17 +16,23 @@
 
 package com.android.quickstep;
 
+import static android.graphics.Shader.TileMode.CLAMP;
+
+import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.BitmapShader;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
 import android.graphics.Matrix;
 import android.graphics.Paint;
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
+import android.graphics.RectF;
 import android.graphics.drawable.Drawable;
 
 import androidx.annotation.NonNull;
 
+import com.android.launcher3.R;
 import com.android.systemui.shared.recents.model.ThumbnailData;
 
 /**
@@ -39,11 +45,18 @@
     private final Paint mPaint = new Paint();
     private final Matrix mMatrix = new Matrix();
     private final ThumbnailData mThumbnailData;
+    private final BitmapShader mShader;
+    private final RectF mDestRect = new RectF();
+    private final int mCornerRadius;
     private int mRequestedOrientation;
 
-    public ThumbnailDrawable(@NonNull ThumbnailData thumbnailData, int requestedOrientation) {
+    public ThumbnailDrawable(Resources res, @NonNull ThumbnailData thumbnailData,
+            int requestedOrientation) {
         mThumbnailData = thumbnailData;
         mRequestedOrientation = requestedOrientation;
+        mCornerRadius = (int) res.getDimension(R.dimen.task_thumbnail_corner_radius);
+        mShader = new BitmapShader(mThumbnailData.thumbnail, CLAMP, CLAMP);
+        mPaint.setShader(mShader);
         updateMatrix();
     }
 
@@ -64,12 +77,13 @@
         if (mThumbnailData.thumbnail == null) {
             return;
         }
-        canvas.drawBitmap(mThumbnailData.thumbnail, mMatrix, mPaint);
+        canvas.drawRoundRect(mDestRect, mCornerRadius, mCornerRadius, mPaint);
     }
 
     @Override
     protected void onBoundsChange(Rect bounds) {
         super.onBoundsChange(bounds);
+        mDestRect.set(bounds);
         updateMatrix();
     }
 
@@ -125,5 +139,6 @@
         }
         // Scale to fill.
         mMatrix.postScale(scaleX, scaleY);
+        mShader.setLocalMatrix(mMatrix);
     }
 }
diff --git a/go/quickstep/src/com/android/quickstep/views/TaskItemView.java b/go/quickstep/src/com/android/quickstep/views/TaskItemView.java
index 0b5ed56..9019205 100644
--- a/go/quickstep/src/com/android/quickstep/views/TaskItemView.java
+++ b/go/quickstep/src/com/android/quickstep/views/TaskItemView.java
@@ -177,7 +177,8 @@
             return mDefaultThumbnail;
         }
         int orientation = getResources().getConfiguration().orientation;
-        return new ThumbnailDrawable(thumbnailData,  orientation /* requestedOrientation */);
+        return new ThumbnailDrawable(getResources(), thumbnailData,
+                orientation /* requestedOrientation */);
     }
 
     private @NonNull String getSafeLabel(@Nullable String label) {