pref: 动态取色主题色上文字颜色

This commit is contained in:
HuanCheng65 2023-09-30 15:51:17 +08:00
parent 9356f043ed
commit 1137f0eead
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
2 changed files with 100 additions and 34 deletions

View File

@ -29,6 +29,7 @@ data class ExtendedColors(
val theme: String, val theme: String,
val isNightMode: Boolean, val isNightMode: Boolean,
val primary: Color = Color.Unspecified, val primary: Color = Color.Unspecified,
val onPrimary: Color = Color.Unspecified,
val accent: Color = Color.Unspecified, val accent: Color = Color.Unspecified,
val onAccent: Color = Color.Unspecified, val onAccent: Color = Color.Unspecified,
val topBar: Color = Color.Unspecified, val topBar: Color = Color.Unspecified,
@ -42,7 +43,6 @@ data class ExtendedColors(
val onBottomBarSurface: Color = Color.Unspecified, val onBottomBarSurface: Color = Color.Unspecified,
val text: Color = Color.Unspecified, val text: Color = Color.Unspecified,
val textSecondary: Color = Color.Unspecified, val textSecondary: Color = Color.Unspecified,
val textOnPrimary: Color = Color.Unspecified,
val textDisabled: Color = Color.Unspecified, val textDisabled: Color = Color.Unspecified,
val background: Color = Color.Unspecified, val background: Color = Color.Unspecified,
val chip: Color = Color.Unspecified, val chip: Color = Color.Unspecified,
@ -212,7 +212,7 @@ private fun getLightDynamicColor(tonalPalette: TonalPalette): ExtendedColors {
theme = "dynamic", theme = "dynamic",
isNightMode = false, isNightMode = false,
primary = tonalPalette.primary40, primary = tonalPalette.primary40,
textOnPrimary = tonalPalette.primary90, onPrimary = tonalPalette.primary100,
accent = tonalPalette.secondary40, accent = tonalPalette.secondary40,
onAccent = tonalPalette.secondary100, onAccent = tonalPalette.secondary100,
topBar = getDynamicTopBarColor(tonalPalette), topBar = getDynamicTopBarColor(tonalPalette),
@ -247,7 +247,7 @@ private fun getDarkDynamicColor(tonalPalette: TonalPalette): ExtendedColors {
theme = "dynamic", theme = "dynamic",
isNightMode = true, isNightMode = true,
primary = tonalPalette.primary80, primary = tonalPalette.primary80,
textOnPrimary = tonalPalette.primary10, onPrimary = tonalPalette.primary10,
accent = tonalPalette.secondary80, accent = tonalPalette.secondary80,
onAccent = tonalPalette.secondary20, onAccent = tonalPalette.secondary20,
topBar = tonalPalette.neutralVariant10, topBar = tonalPalette.neutralVariant10,
@ -282,7 +282,7 @@ private fun getBlackDarkDynamicColor(tonalPalette: TonalPalette): ExtendedColors
theme = "dynamic", theme = "dynamic",
isNightMode = true, isNightMode = true,
primary = tonalPalette.primary80, primary = tonalPalette.primary80,
textOnPrimary = tonalPalette.primary10, onPrimary = tonalPalette.primary10,
accent = tonalPalette.secondary80, accent = tonalPalette.secondary80,
onAccent = tonalPalette.secondary20, onAccent = tonalPalette.secondary20,
topBar = tonalPalette.neutralVariant0, topBar = tonalPalette.neutralVariant0,
@ -320,65 +320,131 @@ private fun getThemeColorForTheme(theme: String): ExtendedColors {
val bottomBarColor = val bottomBarColor =
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorNavBar, nowTheme)) Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorNavBar, nowTheme))
return ExtendedColors( return ExtendedColors(
nowTheme, theme = nowTheme,
ThemeUtil.isNightMode(nowTheme), isNightMode = ThemeUtil.isNightMode(nowTheme),
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorNewPrimary, nowTheme)), primary = Color(
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorAccent, nowTheme)), App.ThemeDelegate.getColorByAttr(
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnAccent, nowTheme)), context,
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorToolbar, nowTheme)), R.attr.colorNewPrimary,
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorToolbarItem, nowTheme)), nowTheme
Color( )
),
onPrimary = Color(
App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorOnAccent,
nowTheme
)
),
accent = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorAccent, nowTheme)),
onAccent = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnAccent, nowTheme)),
topBar = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorToolbar, nowTheme)),
onTopBar = Color(
App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorToolbarItem,
nowTheme
)
),
onTopBarSecondary = Color(
App.ThemeDelegate.getColorByAttr( App.ThemeDelegate.getColorByAttr(
context, context,
R.attr.colorToolbarItemSecondary, R.attr.colorToolbarItemSecondary,
nowTheme nowTheme
) )
), ),
Color( onTopBarActive = Color(
App.ThemeDelegate.getColorByAttr( App.ThemeDelegate.getColorByAttr(
context, context,
R.attr.colorToolbarItemActive, R.attr.colorToolbarItemActive,
nowTheme nowTheme
) )
), ),
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorToolbarSurface, nowTheme)), topBarSurface = Color(
Color( App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorToolbarSurface,
nowTheme
)
),
onTopBarSurface = Color(
App.ThemeDelegate.getColorByAttr( App.ThemeDelegate.getColorByAttr(
context, context,
R.attr.colorOnToolbarSurface, R.attr.colorOnToolbarSurface,
nowTheme nowTheme
) )
), ),
bottomBarColor, bottomBar = bottomBarColor,
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorNavBarSurface, nowTheme)), bottomBarSurface = Color(
Color( App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorNavBarSurface,
nowTheme
)
),
onBottomBarSurface = Color(
App.ThemeDelegate.getColorByAttr( App.ThemeDelegate.getColorByAttr(
context, context,
R.attr.colorOnNavBarSurface, R.attr.colorOnNavBarSurface,
nowTheme nowTheme
) )
), ),
textColor.copy(alpha = ContentAlpha.high), text = textColor.copy(alpha = ContentAlpha.high),
textColor.copy(alpha = ContentAlpha.medium), textSecondary = textColor.copy(alpha = ContentAlpha.medium),
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnAccent, nowTheme)), textDisabled = Color(
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.color_text_disabled, nowTheme)), App.ThemeDelegate.getColorByAttr(
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorBackground, nowTheme)), context,
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorChip, nowTheme)), R.attr.color_text_disabled,
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnChip, nowTheme)), nowTheme
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorUnselected, nowTheme)), )
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorCard, nowTheme)), ),
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorFloorCard, nowTheme)), background = Color(
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorDivider, nowTheme)), App.ThemeDelegate.getColorByAttr(
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.shadow_color, nowTheme)), context,
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorIndicator, nowTheme)), R.attr.colorBackground,
Color( nowTheme
)
),
chip = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorChip, nowTheme)),
onChip = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnChip, nowTheme)),
unselected = Color(
App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorUnselected,
nowTheme
)
),
card = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorCard, nowTheme)),
floorCard = Color(
App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorFloorCard,
nowTheme
)
),
divider = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorDivider, nowTheme)),
shadow = Color(App.ThemeDelegate.getColorByAttr(context, R.attr.shadow_color, nowTheme)),
indicator = Color(
App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorIndicator,
nowTheme
)
),
windowBackground = Color(
App.ThemeDelegate.getColorByAttr( App.ThemeDelegate.getColorByAttr(
context, context,
R.attr.colorWindowBackground, R.attr.colorWindowBackground,
nowTheme nowTheme
) )
), ),
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorPlaceholder, nowTheme)), placeholder = Color(
App.ThemeDelegate.getColorByAttr(
context,
R.attr.colorPlaceholder,
nowTheme
)
),
) )
} }

View File

@ -35,4 +35,4 @@ val ExtendedColors.invertChipBackground: Color
get() = if (ThemeUtil.isNightMode(theme)) primary.copy(alpha = 0.3f) else primary get() = if (ThemeUtil.isNightMode(theme)) primary.copy(alpha = 0.3f) else primary
val ExtendedColors.invertChipContent: Color val ExtendedColors.invertChipContent: Color
get() = if (ThemeUtil.isNightMode(theme)) primary else textOnPrimary get() = if (ThemeUtil.isNightMode(theme)) primary else onPrimary