Merge changes Ib7ce422d,I977e7750 into sc-dev
* changes:
Added rounded corner to bitmap Widget Preview
Correct RoundedCorner enforcements.
diff --git a/src/com/android/launcher3/FastBitmapDrawable.java b/src/com/android/launcher3/FastBitmapDrawable.java
index b1fe4a2..0027a50 100644
--- a/src/com/android/launcher3/FastBitmapDrawable.java
+++ b/src/com/android/launcher3/FastBitmapDrawable.java
@@ -28,6 +28,7 @@
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 @@
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<FastBitmapDrawable, Float> SCALE
@@ -102,6 +105,13 @@
@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 @@
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/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
index 2e542ed..687318f 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
@@ -497,12 +497,13 @@
@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/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java
index 247a748..08bb662 100644
--- a/src/com/android/launcher3/widget/PendingItemDragHelper.java
+++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java
@@ -54,10 +54,13 @@
@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 @@
.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/RoundedCornerEnforcement.java b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java
index 99eccd1..1e46ffd 100644
--- a/src/com/android/launcher3/widget/RoundedCornerEnforcement.java
+++ b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java
@@ -72,12 +72,8 @@
}
/** 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();
}
/**
diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java
index 1b0e1ce..2b4b9ea 100644
--- a/src/com/android/launcher3/widget/WidgetCell.java
+++ b/src/com/android/launcher3/widget/WidgetCell.java
@@ -94,6 +94,7 @@
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 @@
setWillNotDraw(false);
setClipToPadding(false);
setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
+ mEnforcedCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(context);
}
private void setContainerWidth() {
@@ -245,7 +247,9 @@
}
public void applyPreview(Bitmap bitmap) {
- applyPreview(new FastBitmapDrawable(bitmap));
+ FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap);
+ drawable.setRoundedCornersRadius(mEnforcedCornerRadius);
+ applyPreview(drawable);
}
private void applyPreview(Drawable drawable) {