Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 119b7a6a authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille Committed by Android (Google) Code Review
Browse files

Merge changes Ib7ce422d,I977e7750 into sc-dev

* changes:
  Added rounded corner to bitmap Widget Preview
  Correct RoundedCorner enforcements.
parents c699c018 adc23265
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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<FastBitmapDrawable, Float> 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();
+3 −2
Original line number Diff line number Diff line
@@ -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;
        }
+8 −1
Original line number Diff line number Diff line
@@ -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) {
+2 −6
Original line number Diff line number Diff line
@@ -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();
    }

    /**
+5 −1
Original line number Diff line number Diff line
@@ -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) {