FoxMagiskModuleManager/app/src/main/java/com/fox2code/mmm/utils/BlurUtils.java

71 lines
2.2 KiB
Java
Raw Normal View History

2022-10-07 20:58:34 +00:00
package com.fox2code.mmm.utils;
import android.app.Activity;
2022-10-08 12:43:43 +00:00
import android.graphics.Bitmap;
import android.graphics.Canvas;
2022-10-07 20:58:34 +00:00
import android.os.Build;
import android.view.ViewGroup;
import androidx.annotation.IdRes;
2022-10-08 12:43:43 +00:00
import androidx.annotation.NonNull;
2022-10-07 20:58:34 +00:00
2022-10-08 12:43:43 +00:00
import eightbitlab.com.blurview.BlurAlgorithm;
2022-10-07 20:58:34 +00:00
import eightbitlab.com.blurview.BlurView;
import eightbitlab.com.blurview.RenderEffectBlur;
import eightbitlab.com.blurview.RenderScriptBlur;
public class BlurUtils {
public static void setupBlur(BlurView blurView, Activity activity, @IdRes int viewId) {
setupBlur(blurView, activity, activity.findViewById(viewId));
}
@SuppressWarnings("deprecation")
public static void setupBlur(BlurView blurView, Activity activity, ViewGroup rootView) {
2022-10-08 12:43:43 +00:00
blurView.setupWith(rootView, new BlurAlgorithmWrapper(
Build.VERSION.SDK_INT < Build.VERSION_CODES.S ?
new RenderScriptBlur(blurView.getContext()) : new RenderEffectBlur()))
2022-10-07 20:58:34 +00:00
.setFrameClearDrawable(activity.getWindow().getDecorView().getBackground())
.setBlurRadius(4F).setBlurAutoUpdate(true);
}
2022-10-08 12:43:43 +00:00
// Allow to have fancy blur, use more performance.
private static final class BlurAlgorithmWrapper implements BlurAlgorithm {
private final BlurAlgorithm algorithm;
private BlurAlgorithmWrapper(BlurAlgorithm algorithm) {
this.algorithm = algorithm;
}
@Override
public Bitmap blur(Bitmap bitmap, float blurRadius) {
return this.algorithm.blur(bitmap, blurRadius * 6f);
}
@Override
public void destroy() {
this.algorithm.destroy();
}
@Override
public boolean canModifyBitmap() {
return this.algorithm.canModifyBitmap();
}
@NonNull
@Override
public Bitmap.Config getSupportedBitmapConfig() {
return this.algorithm.getSupportedBitmapConfig();
}
@Override
public float scaleFactor() {
return 1f;
}
@Override
public void render(@NonNull Canvas canvas, @NonNull Bitmap bitmap) {
this.algorithm.render(canvas, bitmap);
}
}
2022-10-07 20:58:34 +00:00
}