优化 Android 12 风格通知图标深色模式的颜色

This commit is contained in:
2022-03-29 23:47:21 +08:00
parent be4b952f62
commit 256e2ebfce
2 changed files with 24 additions and 3 deletions

View File

@@ -532,7 +532,10 @@ class SystemUIHooker : YukiBaseHooker() {
setColorFilter(if (isUseAndroid12Style || customIconColor == 0) supportColor else customIconColor) setColorFilter(if (isUseAndroid12Style || customIconColor == 0) supportColor else customIconColor)
/** Android 12 设置图标外圈颜色 */ /** Android 12 设置图标外圈颜色 */
if (isUseAndroid12Style && customIconColor != 0) if (isUseAndroid12Style && customIconColor != 0)
background = DrawableBuilder().rounded().solidColor(customIconColor).build() background = DrawableBuilder()
.rounded()
.solidColor(if (context.isSystemInDarkMode) customIconColor.brighter else customIconColor)
.build()
/** 设置原生的背景边距 */ /** 设置原生的背景边距 */
if (isUseAndroid12Style) setPadding(4.dp(context), 4.dp(context), 4.dp(context), 4.dp(context)) if (isUseAndroid12Style) setPadding(4.dp(context), 4.dp(context), 4.dp(context), 4.dp(context))
} else { } else {
@@ -545,8 +548,13 @@ class SystemUIHooker : YukiBaseHooker() {
/** 设置图标着色 */ /** 设置图标着色 */
setColorFilter(supportColor) setColorFilter(supportColor)
/** Android 12 设置图标外圈颜色 */ /** Android 12 设置图标外圈颜色 */
if (isUseAndroid12Style) background = (if (hasIconColor) iconColor else context.systemAccentColor).also {
DrawableBuilder().rounded().solidColor(if (hasIconColor) iconColor else context.systemAccentColor).build() if (isUseAndroid12Style)
background = DrawableBuilder()
.rounded()
.solidColor(if (context.isSystemInDarkMode) it.brighter else it)
.build()
}
/** 设置原生的背景边距 */ /** 设置原生的背景边距 */
if (isUseAndroid12Style) setPadding(4.dp(context), 4.dp(context), 4.dp(context), 4.dp(context)) if (isUseAndroid12Style) setPadding(4.dp(context), 4.dp(context), 4.dp(context), 4.dp(context))
} else iconImageView.apply { } else iconImageView.apply {

View File

@@ -308,6 +308,19 @@ val Context.wallpaperColor
WallpaperManager.getInstance(this).getWallpaperColors(WallpaperManager.FLAG_SYSTEM)?.primaryColor?.toArgb() ?: 0 WallpaperManager.getInstance(this).getWallpaperColors(WallpaperManager.FLAG_SYSTEM)?.primaryColor?.toArgb() ?: 0
} }
/**
* 获取较浅的颜色
* @return [Int]
*/
val Int.brighter: Int
get() {
val hsv = FloatArray(3)
Color.colorToHSV(this, hsv)
hsv[1] = hsv[1] - 0.3f
hsv[2] = hsv[2] + 0.3f
return Color.HSVToColor(hsv)
}
/** /**
* 是否为白色 * 是否为白色
* @return [Boolean] * @return [Boolean]