From 2e014c6c7dc8e44a37325ae826dc45600d819571 Mon Sep 17 00:00:00 2001 From: GSWXXN <34705923+GSWXXN@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:58:25 -0600 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E5=9C=86=E8=A7=92=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gswxxn/restoresplashscreen/data/DataConst.kt | 1 + .../hook/systemui/IconHookHandler.kt | 16 ++++++++++++---- .../gswxxn/restoresplashscreen/ui/DevSettings.kt | 11 +++++++++++ .../restoresplashscreen/utils/GraphicUtils.kt | 4 ++-- app/src/main/res/values/strings.xml | 4 ++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/gswxxn/restoresplashscreen/data/DataConst.kt b/app/src/main/java/com/gswxxn/restoresplashscreen/data/DataConst.kt index 9f595c9..b8e4b78 100644 --- a/app/src/main/java/com/gswxxn/restoresplashscreen/data/DataConst.kt +++ b/app/src/main/java/com/gswxxn/restoresplashscreen/data/DataConst.kt @@ -55,4 +55,5 @@ object DataConst { // 开发者设置 val ENABLE_DEV_SETTINGS = PrefsData("enable_dev_settings", false) + val DEV_ICON_ROUND_CORNER_RATE = PrefsData("dev_icon_round_corner", 25) } \ No newline at end of file diff --git a/app/src/main/java/com/gswxxn/restoresplashscreen/hook/systemui/IconHookHandler.kt b/app/src/main/java/com/gswxxn/restoresplashscreen/hook/systemui/IconHookHandler.kt index cd3554d..47208d3 100644 --- a/app/src/main/java/com/gswxxn/restoresplashscreen/hook/systemui/IconHookHandler.kt +++ b/app/src/main/java/com/gswxxn/restoresplashscreen/hook/systemui/IconHookHandler.kt @@ -24,6 +24,7 @@ import com.gswxxn.restoresplashscreen.utils.GraphicUtils import com.gswxxn.restoresplashscreen.utils.IconPackManager import com.gswxxn.restoresplashscreen.utils.MIUIIconsHelper import com.gswxxn.restoresplashscreen.utils.YukiHelper.atLeastMIUI14 +import com.gswxxn.restoresplashscreen.utils.YukiHelper.getDevPrefs import com.gswxxn.restoresplashscreen.utils.YukiHelper.printLog import com.highcapable.yukihookapi.hook.factory.current import com.highcapable.yukihookapi.hook.factory.field @@ -113,9 +114,13 @@ object IconHookHandler: BaseHookHandler() { ) / 1.5).toInt() val bgIconSize = iconSize * 4 - val blurBgDrawable = - GraphicUtils.createShadowedIcon(appContext, currentIconDrawable, iconSize, iconSize * 4) - ?: return@addAfterHook + val blurBgDrawable = GraphicUtils.createShadowedIcon( + appContext, + currentIconDrawable, + iconSize, + iconSize * 4, + iconSize * getDevPrefs(DataConst.DEV_ICON_ROUND_CORNER_RATE) / 100f + ) ?: return@addAfterHook val iconBlurBGView = ImageView(appContext).apply { setImageDrawable(blurBgDrawable) @@ -152,7 +157,10 @@ object IconHookHandler: BaseHookHandler() { iconView.outlineProvider = object : ViewOutlineProvider() { override fun getOutline(view: View, outline: Outline) { val border = dp2px(appContext!!, 1.5f) - outline.setRoundRect(border, border, view.width - border, view.height - border, iconSize.toFloat() / 4.2f) + outline.setRoundRect( + border, border, view.width - border, view.height - border, + iconSize.toFloat() * getDevPrefs(DataConst.DEV_ICON_ROUND_CORNER_RATE) / 100 + ) } } iconView.setClipToOutline(true) // 启用轮廓剪裁 diff --git a/app/src/main/java/com/gswxxn/restoresplashscreen/ui/DevSettings.kt b/app/src/main/java/com/gswxxn/restoresplashscreen/ui/DevSettings.kt index c217170..99510e1 100644 --- a/app/src/main/java/com/gswxxn/restoresplashscreen/ui/DevSettings.kt +++ b/app/src/main/java/com/gswxxn/restoresplashscreen/ui/DevSettings.kt @@ -28,6 +28,17 @@ class DevSettings: BaseActivity() { onBackPressed() } ) + + Line() + TitleText(textId = R.string.icon_settings) + + SeekBarWithStatus( + titleID = R.string.dev_icon_round_corner_rate, + pref = DataConst.DEV_ICON_ROUND_CORNER_RATE, + min = 0, + max = 50, + isPercentage = true + ) } /** onCreate 事件 */ diff --git a/app/src/main/java/com/gswxxn/restoresplashscreen/utils/GraphicUtils.kt b/app/src/main/java/com/gswxxn/restoresplashscreen/utils/GraphicUtils.kt index 004a7af..7861b9d 100644 --- a/app/src/main/java/com/gswxxn/restoresplashscreen/utils/GraphicUtils.kt +++ b/app/src/main/java/com/gswxxn/restoresplashscreen/utils/GraphicUtils.kt @@ -179,9 +179,10 @@ object GraphicUtils { * @param drawable 需要创建阴影的Drawable * @param oriIconSize 原始图标大小 * @param blurIconSize 待模糊图标大小 + * @param cornerRadius 模糊图标圆角大小 * @return 待模糊图标Drawable,如果输入的Drawable或者Context为空则返回null */ - fun createShadowedIcon(context: Context?, drawable: Drawable?, oriIconSize: Int, blurIconSize: Int): Drawable? { + fun createShadowedIcon(context: Context?, drawable: Drawable?, oriIconSize: Int, blurIconSize: Int, cornerRadius: Float): Drawable? { if (drawable == null || context == null) { return null } @@ -196,7 +197,6 @@ object GraphicUtils { val canvas = Canvas(scaledBitmap) // 应用圆角裁剪 - val cornerRadius = scaledSize / 4f val path = Path().apply { addRoundRect(RectF(0f, 0f, scaledSize.toFloat(), scaledSize.toFloat()), cornerRadius, cornerRadius, Path.Direction.CW) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6a2305c..5bc305e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -171,4 +171,8 @@ 开源仓库 使用图标来源 开放源代码许可 + + + + 图标圆角率