Skip to content

Commit

Permalink
feat: 支持配置图标圆角率
Browse files Browse the repository at this point in the history
  • Loading branch information
GSWXXN committed Jan 16, 2024
1 parent 30bb3d7 commit 2e014c6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) // 启用轮廓剪裁
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/gswxxn/restoresplashscreen/ui/DevSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ class DevSettings: BaseActivity<ActivityDevSettingsBinding>() {
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 事件 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,8 @@
<string name="open_source_repo">开源仓库</string>
<string name="icon_resource">使用图标来源</string>
<string name="open_source_license">开放源代码许可</string>


<!--开发者选项-->
<string name="dev_icon_round_corner_rate">图标圆角率</string>
</resources>

0 comments on commit 2e014c6

Please sign in to comment.