Skip to content

Commit 86b7efe

Browse files
authored
Merge pull request #25 from KvColorPalette/feature/introduce-new-inverse-colors
Feature/introduce new inverse colors
2 parents 4e799c2 + c4f5296 commit 86b7efe

File tree

7 files changed

+131
-35
lines changed

7 files changed

+131
-35
lines changed

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,23 @@ override fun onCreate() {
9494
This initiation create a color schemas for a theme using the given color at the initiation. This generated color schemas will available for light and dark theme variants.
9595

9696
In this `KvColorPalette.colorSchemeThemePalette` you will have following color attributes.
97-
|Attribute |light-theme |dark-theme |Description |
98-
|-------------|------------|------------|--------------|
99-
|.base |original |original |This is the base color given by the user. |
100-
|.primary |available |available |Suggesting primary color. This color can use for buttons, major component etc. |
101-
|.secondary |available |available |Suggesting secondary color. For any the secondary components which should not use by primary color. |
102-
|.tertiary |available |available |Suggesting tertiary color. |
103-
|.quaternary |available |available |Suggesting quaternary color. |
104-
|.background |available |available |Suggesting background color. |
105-
|.surface |available |available |Suggesting background color. |
106-
|.onPrimary |available |available |This is the color you can use on any component use primary color. |
107-
|.onSecondary |available |available |This is the color you can use on any component use secondary color. |
108-
|.onSurface |available |available |This is the color you can use on any component use secondary color. |
109-
|.shadow |available |available |This is the color for your shadows. |
97+
|Attribute |light-theme |dark-theme |Description |
98+
|-----------------------|------------|------------|--------------|
99+
|.base |original |original |This is the base color given by the user. |
100+
|.default |available |available |This color defines LightMode -> White, DarkMode -> Black. |
101+
|.primary |available |available |Suggesting primary color. This color can use for buttons, major component etc. |
102+
|.secondary |available |available |Suggesting secondary color. For any the secondary components which should not use by primary color. |
103+
|.tertiary |available |available |Suggesting tertiary color. |
104+
|.quaternary |available |available |Suggesting quaternary color. |
105+
|.background |available |available |Suggesting background color. |
106+
|.surface |available |available |Suggesting background color. |
107+
|.onPrimary |available |available |This is the color you can use on any component use primary color. |
108+
|.onSecondary |available |available |This is the color you can use on any component use secondary color. |
109+
|.onSurface |available |available |This is the color you can use on any component use secondary color. |
110+
|.shadow |available |available |This is the color for your shadows. |
111+
|.inverseDefault |available |available |This color defines LightMode -> Black, DarkMode -> White. |
112+
|.inverseOnPrimary |available |available |This is the inverse color of onPrimary color. |
113+
|.inverseOnBackground |available |available |This is the inverse color of onBackground color. |
110114

111115
This `ColorSchemaThemePalette` is another Android Jetpack Compose `ColorSchema`. But that contains additional attributes like `base`, `quaternary`, `shadow` that provide
112116
by the `KvColorPalette-Android` library. All above table mentioned colors are generated according to the given color and created the `ColorScheme`.

gradle/version-catalog/libs.versions.toml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
[versions]
22
minSdkVersion = "26"
3-
compilerSdkVersion = "35"
4-
targetSdkVersion = "35"
3+
compilerSdkVersion = "36"
4+
targetSdkVersion = "36"
55
jvmVersion = "21"
66

7-
agp = "8.7.3"
8-
kotlin = "2.0.0"
7+
agp = "8.13.0"
8+
kotlin = "2.2.0"
99
dokka = "1.8.10"
1010
coreKtx = "1.15.0"
1111
junit = "4.13.2"
1212
junitVersion = "1.2.1"
1313
espressoCore = "3.6.1"
14-
lifecycleRuntimeKtx = "2.8.7"
15-
activityCompose = "1.10.0"
16-
composeBom = "2025.01.00"
17-
appcompat = "1.7.0"
14+
composeBom = "2025.07.00"
1815
material = "1.12.0"
1916
composeMaterial = "1.7.6"
20-
composeNavigation = "2.8.5"
2117

2218
googleTruthVersion = "1.4.4"
2319
mockKVersion = "1.14.5"
@@ -26,19 +22,12 @@ mockKVersion = "1.14.5"
2622
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
2723
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
2824
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
29-
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
30-
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
3125
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
3226
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
3327
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
34-
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
35-
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
36-
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
3728
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
3829
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
3930
androidx-compose-material = { group = "androidx.compose.material", name = "material", version.ref = "composeMaterial"}
40-
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
41-
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "composeNavigation" }
4231

4332
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
4433

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Dec 05 13:15:30 EST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

kv-color-palette/build.gradle.kts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
plugins {
24
alias(libs.plugins.android.library)
35
alias(libs.plugins.kotlin.android)
@@ -34,8 +36,11 @@ android {
3436
sourceCompatibility = javaVersion
3537
targetCompatibility = javaVersion
3638
}
37-
kotlinOptions {
38-
jvmTarget = libs.versions.jvmVersion.get()
39+
40+
kotlin {
41+
compilerOptions {
42+
jvmTarget = JvmTarget.fromTarget(libs.versions.jvmVersion.get())
43+
}
3944
}
4045

4146
publishing {
@@ -48,7 +53,6 @@ android {
4853

4954
dependencies {
5055
implementation(libs.androidx.core.ktx)
51-
implementation(libs.androidx.appcompat)
5256
implementation(libs.material)
5357
implementation(libs.androidx.material3)
5458

kv-color-palette/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
kvColorPaletteGroupId=com.github.KvColorPalette
22
kvColorPaletteArtifactId=KvColorPalette-Android
3-
kvColorPaletteVersion=3.2.0
3+
kvColorPaletteVersion=3.3.0

kv-color-palette/src/main/kotlin/com/kavi/droid/color/palette/extension/ColorSchemeExtension.kt

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.kavi.droid.color.palette.extension
22

33
import androidx.compose.material3.ColorScheme
44
import androidx.compose.ui.graphics.Color
5+
import com.kavi.droid.color.palette.KvColorPalette
56
import com.kavi.droid.color.palette.util.ThemeGenUtil
67
import java.util.WeakHashMap
78

@@ -22,6 +23,20 @@ var ColorScheme.base: Color
2223
colorSchemeMap["base"] = value
2324
}
2425

26+
/**
27+
* This is for use light theme White color and dark theme Black color. This can use most of background or
28+
* shadow mode with alpha value on the color according to the theme.
29+
*/
30+
val ColorScheme.default: Color
31+
get() = getDefaultColor(this)
32+
33+
/**
34+
* This is for use light theme Black color and dark theme White color. This can use most of background or
35+
* shadow mode with alpha value on the color according to the theme.
36+
*/
37+
val ColorScheme.inverseDefault: Color
38+
get() = getDefaultInverseColor(this)
39+
2540
/**
2641
* This is for use light theme primary color dark theme contrast color
2742
*/
@@ -34,6 +49,49 @@ val ColorScheme.quaternary: Color
3449
val ColorScheme.shadow: Color
3550
get() = getShadowColor(this)
3651

52+
/**
53+
* This is for use the inverse color of onPrimary color
54+
*/
55+
val ColorScheme.inverseOnPrimary: Color
56+
get() = getInverseOnPrimaryColor(this)
57+
58+
/**
59+
* This is for use the inverse color of onBackground color
60+
*/
61+
val ColorScheme.inverseOnBackground: Color
62+
get() = getInverseOnBackgroundColor(this)
63+
64+
65+
/**
66+
* This returns default color according to the theme mode. This method finds the mode from the
67+
* theme color scheme's background color. If the background color is a lighter one, it's assume
68+
* this is light mode and generate the default color.
69+
*
70+
* @param colorScheme: [ColorScheme] of the theme
71+
* @return color: [Color] default color for theme
72+
*/
73+
private fun getDefaultColor(colorScheme: ColorScheme): Color {
74+
return if (colorScheme.background.isHighLightColor)
75+
Color.White
76+
else
77+
Color.Black
78+
}
79+
80+
/**
81+
* This returns inverse of default color according to the theme mode. This method finds the mode from the
82+
* theme color scheme's background color. If the background color is a lighter one, it's assume
83+
* this is light mode and generate the inverse of default color.
84+
*
85+
* @param colorScheme: [ColorScheme] of the theme
86+
* @return color: [Color] inverse of default color for theme
87+
*/
88+
private fun getDefaultInverseColor(colorScheme: ColorScheme): Color {
89+
return if (colorScheme.background.isHighLightColor)
90+
Color.Black
91+
else
92+
Color.White
93+
}
94+
3795
/**
3896
* This returns quaternary color according to the theme mode. This method finds the mode from the
3997
* theme color scheme's background color. If the background color is a lighter one, it's assume
@@ -62,4 +120,36 @@ private fun getShadowColor(colorScheme: ColorScheme): Color {
62120
Color.Gray
63121
else
64122
Color.White
65-
}
123+
}
124+
125+
/**
126+
* This returns inverse onPrimary color according to the theme mode. This method finds the mode from the
127+
* theme color scheme's background color. If the background color is a lighter one, it's assume
128+
* this is light mode and returns the inverse of onPrimary color.
129+
*
130+
* @param colorScheme: [ColorScheme] of the theme
131+
* @return color: [Color] inverse of onPrimary color for theme
132+
*/
133+
private fun getInverseOnPrimaryColor(colorScheme: ColorScheme): Color {
134+
return if (colorScheme.background.isHighLightColor) {
135+
KvColorPalette.colorSchemeThemePalette.darkColorScheme.onPrimary
136+
} else {
137+
KvColorPalette.colorSchemeThemePalette.lightColorScheme.onPrimary
138+
}
139+
}
140+
141+
/**
142+
* This returns inverse onBackground color according to the theme mode. This method finds the mode from the
143+
* theme color scheme's background color. If the background color is a lighter one, it's assume
144+
* this is light mode and returns the inverse of onBackground color.
145+
*
146+
* @param colorScheme: [ColorScheme] of the theme
147+
* @return color: [Color] inverse of onBackground color for theme
148+
*/
149+
private fun getInverseOnBackgroundColor(colorScheme: ColorScheme): Color {
150+
return if (colorScheme.background.isHighLightColor) {
151+
KvColorPalette.colorSchemeThemePalette.darkColorScheme.onBackground
152+
} else {
153+
KvColorPalette.colorSchemeThemePalette.lightColorScheme.onBackground
154+
}
155+
}

kv-color-palette/src/main/kotlin/com/kavi/droid/color/palette/util/ThemeGenUtil.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ object ThemeGenUtil {
105105
tertiary = generateLightTertiaryColor(givenColor),
106106
background = backgroundColor,
107107
surface = ColorUtil.blendColors(firstColor = backgroundColor, secondColor = Color.White, .9f),
108+
scrim = Color.Black,
108109
onPrimary = generateOverTheTopLightColor(givenColor),
109110
onSecondary = generateOverTheTopLightColor(secondaryColor),
110111
onSurface = ColorUtil.blendColors(firstColor = Color.Black, Color.White, .25f)
@@ -131,6 +132,7 @@ object ThemeGenUtil {
131132
tertiary = generateLightTertiaryColor(givenColor),
132133
background = backgroundColor,
133134
surface = ColorUtil.blendColors(firstColor = backgroundColor, secondColor = Color.White, .9f),
135+
scrim = Color.Black,
134136
onPrimary = generateOverTheTopLightColor(givenColor),
135137
onSecondary = generateOverTheTopLightColor(secondColor),
136138
onSurface = ColorUtil.blendColors(firstColor = Color.Black, Color.White, .25f)
@@ -148,6 +150,7 @@ object ThemeGenUtil {
148150
tertiary = generateLightTertiaryColor(blend),
149151
background = backgroundColor,
150152
surface = ColorUtil.blendColors(firstColor = backgroundColor, secondColor = Color.White, .9f),
153+
scrim = Color.Black,
151154
onPrimary = generateOverTheTopLightColor(givenColor),
152155
onSecondary = generateOverTheTopLightColor(secondColor),
153156
onSurface = ColorUtil.blendColors(firstColor = Color.Black, Color.White, .25f)
@@ -174,6 +177,7 @@ object ThemeGenUtil {
174177
tertiary = generateDarkTertiaryColor(givenColor),
175178
background = darkBackground,
176179
surface = ColorUtil.blendColors(firstColor = darkBackground, secondColor = Color.Black, .9f),
180+
scrim = Color.White,
177181
onPrimary = ColorUtil.blendColors(firstColor = darkPrimary, secondColor = Color.White, .9f),
178182
onSecondary = ColorUtil.blendColors(firstColor = darkSecondary, secondColor = Color.White, .9f),
179183
onSurface = Color.White
@@ -203,6 +207,7 @@ object ThemeGenUtil {
203207
tertiary = generateDarkTertiaryColor(givenColor),
204208
background = darkBackground,
205209
surface = ColorUtil.blendColors(firstColor = darkBackground, secondColor = Color.Black, .9f),
210+
scrim = Color.White,
206211
onPrimary = ColorUtil.blendColors(firstColor = darkPrimary, secondColor = Color.White, .9f),
207212
onSecondary = ColorUtil.blendColors(firstColor = darkSecondary, secondColor = Color.White, .9f),
208213
onSurface = Color.White
@@ -222,6 +227,7 @@ object ThemeGenUtil {
222227
tertiary = generateDarkTertiaryColor(blend),
223228
background = darkBackground,
224229
surface = ColorUtil.blendColors(firstColor = darkBackground, secondColor = Color.Black, .9f),
230+
scrim = Color.White,
225231
onPrimary = ColorUtil.blendColors(firstColor = darkPrimary, secondColor = Color.White, .9f),
226232
onSecondary = ColorUtil.blendColors(firstColor = darkSecondary, secondColor = Color.White, .9f),
227233
onSurface = Color.White
@@ -255,6 +261,9 @@ object ThemeGenUtil {
255261
return Color.hsl(hue = primaryColor.hsl.hue, saturation = .4f, lightness = .95f)
256262
}
257263

264+
/**
265+
* Generate onPrimary color according to the selected primary color
266+
*/
258267
private fun generateOverTheTopLightColor(givenColor: Color): Color {
259268
return if (givenColor.isHighLightColor) {
260269
ColorUtil.blendColors(firstColor = givenColor, Color.Black, .6f)

0 commit comments

Comments
 (0)