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

Commit adc23265 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

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
parent a750f8cd
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();
+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) {
+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) {