From ab171f77563f1a29476a83c1e7e18cae0851a0e1 Mon Sep 17 00:00:00 2001 From: goweii Date: Sun, 13 Dec 2020 15:37:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0maven-publish?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maven-upload.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-upload.gradle b/maven-upload.gradle index c2b2f32..f155df2 100644 --- a/maven-upload.gradle +++ b/maven-upload.gradle @@ -1,7 +1,7 @@ apply plugin: 'maven' group "per.goweii.anylayer" -version "4.1.0" +version "4.1.0-androidx" uploadArchives { repositories { From eec11dd45757391445313f18778468ad6e5972f8 Mon Sep 17 00:00:00 2001 From: goweii Date: Sat, 2 Jul 2022 22:16:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=8D=A2visualeffect=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anylayer/build.gradle | 6 +- .../anylayer/dialog/BackdropBlurView.java | 117 ++++++++++++++++++ .../goweii/anylayer/dialog/DialogLayer.java | 52 ++------ build.gradle | 1 - 4 files changed, 132 insertions(+), 44 deletions(-) create mode 100644 anylayer/src/main/java/per/goweii/anylayer/dialog/BackdropBlurView.java diff --git a/anylayer/build.gradle b/anylayer/build.gradle index c3323e1..a31f648 100644 --- a/anylayer/build.gradle +++ b/anylayer/build.gradle @@ -6,7 +6,7 @@ android { dependencies { compileOnly 'androidx.appcompat:appcompat:1.2.0' - implementation 'per.goweii.visualeffect:visualeffect-core:1.0.3' - implementation 'per.goweii.visualeffect:visualeffect-blur:1.0.3' - implementation 'per.goweii.visualeffect:visualeffect-view:1.0.3' + implementation 'com.github.goweii.VisualEffect:visualeffect-core:1.0.0' + implementation 'com.github.goweii.VisualEffect:visualeffect-blur:1.0.0' + implementation 'com.github.goweii.VisualEffect:visualeffect-view:1.0.0' } diff --git a/anylayer/src/main/java/per/goweii/anylayer/dialog/BackdropBlurView.java b/anylayer/src/main/java/per/goweii/anylayer/dialog/BackdropBlurView.java new file mode 100644 index 0000000..a16aa98 --- /dev/null +++ b/anylayer/src/main/java/per/goweii/anylayer/dialog/BackdropBlurView.java @@ -0,0 +1,117 @@ +package per.goweii.anylayer.dialog; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Path; +import android.graphics.RectF; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.NonNull; + +import java.util.Arrays; + +import per.goweii.visualeffect.blur.BlurEffect; +import per.goweii.visualeffect.blur.RSBlurEffect; +import per.goweii.visualeffect.view.BackdropVisualEffectFrameLayout; +import per.goweii.visualeffect.view.OutlineBuilder; + +public class BackdropBlurView extends BackdropVisualEffectFrameLayout { + private final RoundedOutlineBuilder mOutlineBuilder = new RoundedOutlineBuilder(); + + private float mCornerRadius = 0F; + private float mBlurRadius = 8F; + private float mBlurPercent = 0F; + + public BackdropBlurView(Context context) { + this(context, null); + } + + public BackdropBlurView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public BackdropBlurView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + setShowDebugInfo(false); + } + + @Override + public void draw(@NonNull Canvas canvas) { + float simple = getSimpleSize(); + float radius; + if (mBlurPercent > 0) { + radius = Math.min(getWidth(), getHeight()) * mBlurPercent; + mBlurPercent = 0F; + } else { + radius = mBlurRadius; + } + if (radius > 25) { + simple = simple * (radius / 25); + radius = 25; + } else if (radius < 0) { + radius = 0; + } + if (mBlurRadius != radius) { + mBlurRadius = radius; + } + if (getSimpleSize() != simple) { + setSimpleSize(simple); + } + if (radius == 0) { + if (getVisualEffect() != null) { + setVisualEffect(null); + } + } else { + if (!(getVisualEffect() instanceof BlurEffect) || ((BlurEffect) getVisualEffect()).getRadius() != radius) { + setVisualEffect(new RSBlurEffect(getContext(), radius)); + } + } + super.draw(canvas); + } + + public void setCornerRadius(float cornerRadius) { + if (mCornerRadius != cornerRadius) { + mCornerRadius = cornerRadius; + if (mCornerRadius == 0) { + if (getOutlineBuilder() != null) { + setOutlineBuilder(null); + } + } else { + if (getOutlineBuilder() == null) { + setOutlineBuilder(mOutlineBuilder); + } else { + mOutlineBuilder.invalidateOutline(); + } + } + } + } + + public void setBlurPercent(float blurPercent) { + if (mBlurPercent != blurPercent) { + mBlurPercent = blurPercent; + invalidate(); + } + } + + public void setBlurRadius(float blurRadius) { + if (mBlurRadius != blurRadius) { + mBlurRadius = blurRadius; + invalidate(); + } + } + + private class RoundedOutlineBuilder extends OutlineBuilder { + private final RectF rect = new RectF(); + private final float[] radii = new float[8]; + + @Override + public void buildOutline(@NonNull View view, @NonNull Path path) { + float minSide = Math.min(view.getWidth(), view.getHeight()); + float r = Math.min(mCornerRadius, minSide / 2F); + Arrays.fill(radii, r); + rect.set(0, 0, view.getWidth(), view.getHeight()); + path.addRoundRect(rect, radii, Path.Direction.CW); + } + } +} diff --git a/anylayer/src/main/java/per/goweii/anylayer/dialog/DialogLayer.java b/anylayer/src/main/java/per/goweii/anylayer/dialog/DialogLayer.java index 92ea428..aaf930e 100644 --- a/anylayer/src/main/java/per/goweii/anylayer/dialog/DialogLayer.java +++ b/anylayer/src/main/java/per/goweii/anylayer/dialog/DialogLayer.java @@ -35,9 +35,6 @@ import per.goweii.anylayer.utils.SoftInputHelper; import per.goweii.anylayer.utils.Utils; import per.goweii.anylayer.widget.SwipeLayout; -import per.goweii.visualeffect.blur.RSBlurEffect; -import per.goweii.visualeffect.core.VisualEffect; -import per.goweii.visualeffect.view.BackdropVisualEffectView; public class DialogLayer extends DecorLayer { @@ -477,37 +474,12 @@ public void run() { protected void initBackground() { if (getConfig().mBackgroundBlurPercent > 0 || getConfig().mBackgroundBlurRadius > 0) { - getViewHolder().replaceBackgroundToBackdropVisualEffectView(); - getViewHolder().getBackdropVisualEffectView().setShowDebugInfo(false); - getViewHolder().getBackdropVisualEffectView().setOverlayColor(getConfig().mBackgroundColor); - if (getConfig().mBackgroundBlurPercent > 0) { - Utils.onViewLayout(getViewHolder().getBackdropVisualEffectView(), new Runnable() { - @Override - public void run() { - int w = getViewHolder().getBackdropVisualEffectView().getWidth(); - int h = getViewHolder().getBackdropVisualEffectView().getHeight(); - float radius = Math.min(w, h) * getConfig().mBackgroundBlurPercent; - float simple = getConfig().mBackgroundBlurSimple; - if (radius > 25) { - simple = simple * (radius / 25); - radius = 25; - } - getViewHolder().getBackdropVisualEffectView().setSimpleSize(simple); - VisualEffect visualEffect = new RSBlurEffect(getActivity(), radius); - getViewHolder().getBackdropVisualEffectView().setVisualEffect(visualEffect); - } - }); - } else { - float radius = getConfig().mBackgroundBlurRadius; - float simple = getConfig().mBackgroundBlurSimple; - if (radius > 25) { - simple = simple * (radius / 25); - radius = 25; - } - getViewHolder().getBackdropVisualEffectView().setSimpleSize(simple); - VisualEffect visualEffect = new RSBlurEffect(getActivity(), radius); - getViewHolder().getBackdropVisualEffectView().setVisualEffect(visualEffect); - } + getViewHolder().replaceBackgroundToBackdropBlurView(); + getViewHolder().getBackdropBlurView().setShowDebugInfo(false); + getViewHolder().getBackdropBlurView().setOverlayColor(getConfig().mBackgroundColor); + getViewHolder().getBackdropBlurView().setSimpleSize(getConfig().mBackgroundBlurSimple); + getViewHolder().getBackdropBlurView().setBlurRadius(getConfig().mBackgroundBlurRadius); + getViewHolder().getBackdropBlurView().setBlurPercent(getConfig().mBackgroundBlurPercent); } else { if (getConfig().mBackgroundBitmap != null) { getViewHolder().getBackgroundView().setImageBitmap(getConfig().mBackgroundBitmap); @@ -946,19 +918,19 @@ public View getBackground() { return mBackground; } - public void replaceBackgroundToBackdropVisualEffectView() { - if (mBackground instanceof BackdropVisualEffectView) return; + public void replaceBackgroundToBackdropBlurView() { + if (mBackground instanceof BackdropBlurView) return; ViewGroup.LayoutParams layoutParams = mBackground.getLayoutParams(); int index = getChild().indexOfChild(mBackground); getChild().removeViewAt(index); - mBackground = new BackdropVisualEffectView(getChild().getContext()); + mBackground = new BackdropBlurView(getChild().getContext()); getChild().addView(mBackground, index, new ViewGroup.LayoutParams(layoutParams)); } @Nullable - public BackdropVisualEffectView getBackdropVisualEffectView() { - if (mBackground instanceof BackdropVisualEffectView) { - return (BackdropVisualEffectView) mBackground; + public BackdropBlurView getBackdropBlurView() { + if (mBackground instanceof BackdropBlurView) { + return (BackdropBlurView) mBackground; } return null; } diff --git a/build.gradle b/build.gradle index 6969537..9bb2c28 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,6 @@ allprojects { google() jcenter() maven { url 'https://jitpack.io' } - maven { url "https://gitee.com/goweii/maven-repository/raw/master/releases/" } } }