Skip to content

Commit

Permalink
Merge branch '4.x.x' into support
Browse files Browse the repository at this point in the history
# Conflicts:
#	anylayer/build.gradle
#	maven-upload.gradle
  • Loading branch information
goweii committed Jul 2, 2022
2 parents 899e73a + eec11dd commit 3980e52
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 44 deletions.
7 changes: 4 additions & 3 deletions anylayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ android {
}

dependencies {
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'
compileOnly 'androidx.appcompat:appcompat:1.2.0'
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'
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
52 changes: 12 additions & 40 deletions anylayer/src/main/java/per/goweii/anylayer/dialog/DialogLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ allprojects {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url "https://gitee.com/goweii/maven-repository/raw/master/releases/" }
}
}

Expand Down

0 comments on commit 3980e52

Please sign in to comment.