From 2cc1f606bc06436c6bf205c5065bb8fa3263374c Mon Sep 17 00:00:00 2001 From: xxjy Date: Mon, 17 Jun 2019 19:10:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9Android9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popmenu/src/main/java/me/kareluo/ui/PopLayout.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/popmenu/src/main/java/me/kareluo/ui/PopLayout.java b/popmenu/src/main/java/me/kareluo/ui/PopLayout.java index 2abad52..504ae64 100644 --- a/popmenu/src/main/java/me/kareluo/ui/PopLayout.java +++ b/popmenu/src/main/java/me/kareluo/ui/PopLayout.java @@ -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; @@ -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); @@ -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(); @@ -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); }