Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions popmenu/src/main/java/me/kareluo/ui/PopLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class PopLayout extends FrameLayout implements View.OnLayoutChangeListene

private Path mDestBulgePath;

private Path mPopMaskReversePath;

private Matrix mCornuteMatrix;

private int mSiteMode = SITE_BOTTOM;
Expand All @@ -54,7 +56,7 @@ public class PopLayout extends FrameLayout implements View.OnLayoutChangeListene

private static final int DEFAULT_BULGE_SIZE = 16;

private static final Xfermode MODE = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
private static final Xfermode MODE = new PorterDuffXfermode(Build.VERSION.SDK_INT >= 28 ? PorterDuff.Mode.DST_OUT : PorterDuff.Mode.DST_IN);

public PopLayout(Context context) {
this(context, null, 0);
Expand Down Expand Up @@ -95,6 +97,7 @@ private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {

mBulgePath = new Path();
mPopMaskPath = new Path();
mPopMaskReversePath = new Path();
mDestBulgePath = new Path();
mCornuteMatrix = new Matrix();

Expand Down Expand Up @@ -238,7 +241,14 @@ public void draw(Canvas canvas) {
int layer = canvas.saveLayer(0, 0, canvas.getWidth(),
canvas.getHeight(), null, Canvas.ALL_SAVE_FLAG);
super.draw(canvas);
canvas.drawPath(mPopMaskPath, mPaint);
if (Build.VERSION.SDK_INT >= 28) {
mPopMaskReversePath.reset();
mPopMaskReversePath.addRect(0, 0, getWidth(), getHeight(), Path.Direction.CW);
mPopMaskReversePath.op(mPopMaskPath, Path.Op.DIFFERENCE);
canvas.drawPath(mPopMaskReversePath, mPaint);
} else {
canvas.drawPath(mPopMaskPath, mPaint);
}
canvas.restoreToCount(layer);
}

Expand Down