From 7faef9ba9baa78037ea41d82532298655c86b7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E7=A9=BA?= <70465933+YuKongA@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:46:48 +0800 Subject: [PATCH] Update MiBlurUtils.kt --- .../utils/blur/MiBlurUtils.kt | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/top/yukonga/mediaControlBlur/utils/blur/MiBlurUtils.kt b/app/src/main/kotlin/top/yukonga/mediaControlBlur/utils/blur/MiBlurUtils.kt index 016742f..8a9eb8b 100644 --- a/app/src/main/kotlin/top/yukonga/mediaControlBlur/utils/blur/MiBlurUtils.kt +++ b/app/src/main/kotlin/top/yukonga/mediaControlBlur/utils/blur/MiBlurUtils.kt @@ -1,7 +1,6 @@ package top.yukonga.mediaControlBlur.utils.blur import android.graphics.Outline -import android.util.Log import android.view.View import android.view.ViewOutlineProvider @@ -9,6 +8,10 @@ object MiBlurUtils { const val BACKGROUND = 1 const val FOREGROUND = 2 + private val setBackgroundBlur by lazy { + View::class.java.getDeclaredMethod("setBackgroundBlur", Integer.TYPE, FloatArray::class.java, Array::class.java) + } + private val setMiViewBlurMode by lazy { View::class.java.getDeclaredMethod("setMiViewBlurMode", Integer.TYPE) } @@ -41,6 +44,10 @@ object MiBlurUtils { View::class.java.getDeclaredMethod("disableMiBackgroundContainBelow", java.lang.Boolean.TYPE) } + fun View.setBackgroundBlur(blurRadius: Int, cornerRadius: FloatArray, blendModes: Array) { + setBackgroundBlur.invoke(this, blurRadius, cornerRadius, blendModes) + } + fun View.setMiBackgroundBlurMode(mode: Int) { setMiBackgroundBlurMode.invoke(this, mode) } @@ -49,16 +56,17 @@ object MiBlurUtils { setMiViewBlurMode.invoke(this, mode) } - fun View.setMiBackgroundBlurRadius(radius: Int) { - if (radius < 0 || radius > 500) { - Log.e("MiBlurUtils", "setMiBackgroundBlurRadius error radius is " + radius + " " + this.javaClass.getName() + " hashcode " + this.hashCode()) - return + fun View.setMiBackgroundBlurRadius(blurRadios: Int) { + val radius = when { + blurRadios < 0 -> 0 + blurRadios > 500 -> 500 + else -> blurRadios } setMiBackgroundBlurRadius.invoke(this, radius) } - fun View.setPassWindowBlurEnabled(z: Boolean) { - setPassWindowBlurEnabled.invoke(this, z) + fun View.setPassWindowBlurEnabled(enabled: Boolean) { + setPassWindowBlurEnabled.invoke(this, enabled) } fun View.disableMiBackgroundContainBelow(z: Boolean) { @@ -73,8 +81,8 @@ object MiBlurUtils { clearMiBackgroundBlendColor.invoke(this) } - fun View.setBackgroundBlurScaleRatio(ratio: Float) { - setMiBackgroundBlurScaleRatio.invoke(this, ratio) + fun View.setBackgroundBlurScaleRatio(blurScaleRadio: Float) { + setMiBackgroundBlurScaleRatio.invoke(this, blurScaleRadio) } fun View.setMiBackgroundBlendColors(iArr: IntArray, f: Float) {