From a750f8cdcab8c244e1b206f5ea004e78f8babcb4 Mon Sep 17 00:00:00 2001 From: Pierre Barbier de Reuille Date: Thu, 25 Mar 2021 11:01:06 +0000 Subject: [PATCH 1/2] Correct RoundedCorner enforcements. The feature status will not, in the end, depend on the widget, so removed the argument. Bug: 183097166 Test: Manual test Change-Id: I977e775072cf1724f3e31b848d3ac4c862d23e00 --- .../launcher3/widget/LauncherAppWidgetHostView.java | 5 +++-- .../launcher3/widget/RoundedCornerEnforcement.java | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java index 2e542edf76..687318f775 100644 --- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java @@ -497,12 +497,13 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView @UiThread private void enforceRoundedCorners() { - if (mEnforcedCornerRadius <= 0 || !RoundedCornerEnforcement.isRoundedCornerEnabled(this)) { + if (mEnforcedCornerRadius <= 0 || !RoundedCornerEnforcement.isRoundedCornerEnabled()) { resetRoundedCorners(); return; } View background = RoundedCornerEnforcement.findBackground(this); - if (RoundedCornerEnforcement.hasAppWidgetOptedOut(this, background)) { + if (background == null + || RoundedCornerEnforcement.hasAppWidgetOptedOut(this, background)) { resetRoundedCorners(); return; } diff --git a/src/com/android/launcher3/widget/RoundedCornerEnforcement.java b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java index 99eccd1303..1e46ffd30c 100644 --- a/src/com/android/launcher3/widget/RoundedCornerEnforcement.java +++ b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java @@ -72,12 +72,8 @@ public class RoundedCornerEnforcement { } /** Check if the app widget is in the deny list. */ - public static boolean isRoundedCornerEnabled(@NonNull View view) { - if (!Utilities.ATLEAST_S || !FeatureFlags.ENABLE_ENFORCED_ROUNDED_CORNERS.get()) { - return false; - } - // Here we need to test if the view's component is in the (to be created) deny list. - return true; + public static boolean isRoundedCornerEnabled() { + return Utilities.ATLEAST_S && FeatureFlags.ENABLE_ENFORCED_ROUNDED_CORNERS.get(); } /** From adc23265dc00c881b303aabe4d7d5609f710f029 Mon Sep 17 00:00:00 2001 From: Pierre Barbier de Reuille Date: Thu, 25 Mar 2021 11:01:34 +0000 Subject: [PATCH 2/2] Added rounded corner to bitmap Widget Preview This applies to the widget picker and the initial Widget drop. Bug: 183615331 Test: Manually using top preinstalled widgets Change-Id: Ib7ce422dc485396c2aceec6f43e83529d642ecc7 --- .../android/launcher3/FastBitmapDrawable.java | 18 ++++++++++++++++++ .../widget/PendingItemDragHelper.java | 9 ++++++++- .../android/launcher3/widget/WidgetCell.java | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/FastBitmapDrawable.java b/src/com/android/launcher3/FastBitmapDrawable.java index b1fe4a235c..0027a50d95 100644 --- a/src/com/android/launcher3/FastBitmapDrawable.java +++ b/src/com/android/launcher3/FastBitmapDrawable.java @@ -28,6 +28,7 @@ import android.graphics.ColorFilter; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; +import android.graphics.Path; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -61,6 +62,8 @@ public class FastBitmapDrawable extends Drawable { private boolean mIsPressed; private boolean mIsDisabled; private float mDisabledAlpha = 1f; + private float mRoundedCornersRadius = 0f; + private final Path mClipPath = new Path(); // Animator and properties for the fast bitmap drawable's scale private static final Property SCALE @@ -102,6 +105,13 @@ public class FastBitmapDrawable extends Drawable { @Override public final void draw(Canvas canvas) { + if (mRoundedCornersRadius > 0) { + float radius = mRoundedCornersRadius * mScale; + mClipPath.reset(); + mClipPath.addRoundRect(0, 0, getIntrinsicWidth(), getIntrinsicHeight(), + radius, radius, Path.Direction.CCW); + canvas.clipPath(mClipPath); + } if (mScale != 1f) { int count = canvas.save(); Rect bounds = getBounds(); @@ -164,6 +174,14 @@ public class FastBitmapDrawable extends Drawable { return mScale; } + public void setRoundedCornersRadius(float radius) { + mRoundedCornersRadius = radius; + } + + public float getRoundedCornersRadius() { + return mRoundedCornersRadius; + } + @Override public int getIntrinsicWidth() { return mBitmap.getWidth(); diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java index 247a748ba6..08bb66211c 100644 --- a/src/com/android/launcher3/widget/PendingItemDragHelper.java +++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java @@ -54,10 +54,13 @@ public class PendingItemDragHelper extends DragPreviewProvider { @Nullable private RemoteViews mRemoteViewsPreview; @Nullable private LauncherAppWidgetHostView mAppWidgetHostViewPreview; + private final float mEnforcedRoundedCornersForWidget; public PendingItemDragHelper(View view) { super(view); mAddInfo = (PendingAddItemInfo) view.getTag(); + mEnforcedRoundedCornersForWidget = RoundedCornerEnforcement.computeEnforcedRadius( + view.getContext()); } /** @@ -115,10 +118,14 @@ public class PendingItemDragHelper extends DragPreviewProvider { .addDragListener(new AppWidgetHostViewDragListener(launcher)); } if (preview == null) { - preview = new FastBitmapDrawable( + FastBitmapDrawable p = new FastBitmapDrawable( app.getWidgetCache().generateWidgetPreview(launcher, createWidgetInfo.info, maxWidth, null, previewSizeBeforeScale).first); + if (RoundedCornerEnforcement.isRoundedCornerEnabled()) { + p.setRoundedCornersRadius(mEnforcedRoundedCornersForWidget); + } + preview = p; } if (previewSizeBeforeScale[0] < previewBitmapWidth) { diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index 1b0e1ce0b2..2b4b9ea55e 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -94,6 +94,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { protected final BaseActivity mActivity; protected final DeviceProfile mDeviceProfile; private final CheckLongPressHelper mLongPressHelper; + private final float mEnforcedCornerRadius; private RemoteViews mPreview; private LauncherAppWidgetHostView mAppWidgetHostViewPreview; @@ -118,6 +119,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { setWillNotDraw(false); setClipToPadding(false); setAccessibilityDelegate(mActivity.getAccessibilityDelegate()); + mEnforcedCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(context); } private void setContainerWidth() { @@ -245,7 +247,9 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { } public void applyPreview(Bitmap bitmap) { - applyPreview(new FastBitmapDrawable(bitmap)); + FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap); + drawable.setRoundedCornersRadius(mEnforcedCornerRadius); + applyPreview(drawable); } private void applyPreview(Drawable drawable) {