Skip to content

Commit 182bcdf

Browse files
authored
Merge pull request #1 from KvColorPallet/feature/introduce-new-colors-to-theme-pallet
Feature/introduce new colors to theme pallet
2 parents d78bd8a + 69609cc commit 182bcdf

File tree

12 files changed

+93
-52
lines changed

12 files changed

+93
-52
lines changed

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# KV Android Color Pallet
1+
# KV Color Pallet - Android
22

33
This is a lightweight Android library that generates a color palette from a given color and creates a theme color set for Android applications.
44
This library simplifies the process of building consistent and visually appealing color themes.
@@ -24,29 +24,55 @@ Add the following dependency to your `build.gradle` / `build.gradle.kts` file:
2424
For Groovy - `build.gradle`:
2525
````
2626
dependencies {
27-
implementation 'com.github.kavi707:kv-android-color-pallet:0.0.2'
27+
implementation 'com.github.kavi707:kv-android-color-pallet:0.0.3'
2828
}
2929
````
3030
For Kotlin DSL - `build.gradle.kts`:
3131
````
3232
dependencies {
33-
implementation("com.github.kavi707:kv-android-color-pallet:0.0.2")
33+
implementation("com.github.kavi707:kv-android-color-pallet:0.0.3")
3434
}
3535
````
3636

3737
# Usage
38-
### Initiate
39-
On usage of the kv-android-color-pallet, from your application class, Initiate it using following code.
40-
While initiating, you have to parse a color (androidx.compose.ui.graphics.Color) that you prefer to use as your primary color in your application.
38+
After you integrated the `KvColorPallet-Android` library, you can consume it as follows.
39+
40+
### Basic Usage
41+
If you wants to consume basic features in `KvColorPallet` then use singleton instance as follows. This singleton instance allows consumers to access following basic functionalities.
42+
```
43+
// Generate alpha color schem of given color
44+
KvColorPallet.instance.generateAlphaColorPallet(givenColor: MatPackage().matGold.color)
45+
46+
// Generate mat color schem of given color
47+
KvColorPallet.instance.generateColorPallet(givenColor: MatPackage().matGold)
48+
49+
// Generate theme color pallet of given color
50+
KvColorPallet.instance.generateThemeColorPallet(givenColor: MatPackage().matGold.color)
51+
```
52+
53+
### Advance Usage
54+
If you wants to use `KvColorPallet-Android` to generate your theme color pallet when your application start-up, then you have to initiate the library in Application level.
55+
To initiate you have to pass one base color that you think your application will use. Use following code to initiate the library package.
4156
````
4257
override fun onCreate() {
4358
super.onCreate()
4459
// Initialize the kv-android-color-pallet
45-
KvColorPallet.init(MatPackage.MatDGreen.color)
60+
KvColorPallet.initialize(MatPackage.MatDGreen)
4661
}
4762
````
48-
This initiation create a color set for a theme using the given color at the initiation.
49-
This generated color set available for light and dark theme variants.
63+
This initiation create a color set for a theme using the given color at the initiation. This generated color set available for light and dark theme variants.
64+
65+
In this `KvColorPallet.appThemePallet` you will have following color attributes.
66+
|Attribute |light-theme |dark-theme |Description |
67+
|-------------|------------|------------|--------------|
68+
|.base |original |original |This is the base color given by the user. |
69+
|.primary |available |available |Suggesting primary color. This color can use for buttons, major component etc. |
70+
|.secondary |available |available |Suggesting secondary color. For any the secondary components which should not use by primary color. |
71+
|.tertiary |available |available |Suggesting tertiary color. |
72+
|.background |available |available |Suggesting background color. |
73+
|.onPrimary |available |available |This is the color you can use on any component use primary color. |
74+
|.onSecondary |available |available |This is the color you can use on any component use secondary color. |
75+
|.shadow |available |available |This is the color for your shadows. |
5076

5177
### Use generated theme
5278
As mentioned above, according to the initiation color, that generate the color set for light and dark them.

kv-color-pallet/src/main/kotlin/com/kavi/droid/color/pallet/KvColorPallet.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,34 @@ import com.kavi.droid.color.pallet.util.ThemeGenUtil
1717
/**
1818
* This is the kv-color-pallet android library.
1919
*/
20-
class KvColorPallet(private val givenColor: Color = Color.White) {
20+
class KvColorPallet {
2121

2222
companion object {
23-
var instance: KvColorPallet? = null
23+
/**
24+
* This is a basic initialization without a basic color. When consumer use this initialization, in default KvColorPallet with not
25+
* provide a theme color pallet. Consumer can use this as a singleton.
26+
*/
27+
var instance: KvColorPallet = KvColorPallet()
2428
lateinit var appThemePallet: AppThemePallet
2529

26-
fun init(givenColor: Color) {
27-
instance ?: run {
28-
instance = KvColorPallet(givenColor = givenColor)
29-
}
30+
/**
31+
* KvColorPallet initialization. Consumer can use this to initialize the KvColorPallet from their application delegate if they need a
32+
* Theme color pallet at the application start-up.
33+
*
34+
* On this initiation of kv-color-pallet, we generate a theme color pallet using the given color.
35+
* `basicColor` is mandatory parameter while initiate the library.
36+
*/
37+
fun initialize(basicColor: KvColor) {
38+
val closestColor = ColorUtil.findClosestColor(basicColor.color)
39+
appThemePallet = instance.generateThemeColorPallet(closestColor.color)
3040
}
3141
}
3242

3343
init {
3444
/**
35-
* On initiation of kv-color-pallet, we generate a theme color pallet using the given color.
36-
* `givenColor` is mandatory parameter while initiate the library.
37-
*
38-
* Consumer who is using kv-color-pallet, will get a color pallet for the theme of the application
45+
* This generate theme-pallet with color transparent. This is un-usable.
3946
*/
40-
val closestColor = ColorUtil.findClosestColor(givenColor)
41-
appThemePallet = generateThemeColorPallet(closestColor)
47+
appThemePallet = generateThemeColorPallet(Color.Transparent)
4248
}
4349

4450
/**
@@ -90,7 +96,7 @@ class KvColorPallet(private val givenColor: Color = Color.White) {
9096
* @param givenColor The color to generate the theme color pallet for.
9197
* @return A theme color pallet.
9298
*/
93-
fun generateThemeColorPallet(givenColor: KvColor): AppThemePallet {
99+
fun generateThemeColorPallet(givenColor: Color): AppThemePallet {
94100
return ThemeGenUtil.generateThemeColorSet(givenColor = givenColor)
95101
}
96102
}

kv-color-pallet/src/main/kotlin/com/kavi/droid/color/pallet/model/ThemeColorPallet.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ data class AppThemePallet(
1414
* Color pallet for theme.
1515
*/
1616
data class ThemeColorPallet(
17+
val base: Color,
1718
val primary: Color,
1819
val secondary: Color,
1920
val tertiary: Color,
2021
val background: Color = Color.White,
2122
val onPrimary: Color = Color.White,
2223
val onSecondary: Color = Color.White,
24+
val shadow: Color = Color.Gray
2325
)

kv-color-pallet/src/main/kotlin/com/kavi/droid/color/pallet/util/ColorUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ object ColorUtil {
7676
shortestDistance = colorMatch300.colorDistance
7777
closestColor = colorMatch300.matchedColor
7878

79-
// Do comparison with 300 color list
79+
// Do comparison with 200 color list
8080
val colorMatch200 = Mat200Package.compareColor(givenColor)
8181

8282
if (colorMatch200.isExactMatch) {

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ object ThemeGenUtil {
1414
* @param givenColor The color to generate theme color set.
1515
* @return A theme color set. [AppThemePallet]
1616
*/
17-
internal fun generateThemeColorSet(givenColor: KvColor): AppThemePallet {
18-
val closestColor = findClosestColor(givenColor.color)
17+
internal fun generateThemeColorSet(givenColor: Color): AppThemePallet {
18+
val closestColor = findClosestColor(givenColor)
1919

20-
val lightColorPallet = generateLightThemeColorSet(closestColor)
21-
val darkColorPallet = generateDarkThemeColorSet(closestColor)
20+
val lightColorPallet = generateLightThemeColorSet(givenColor, closestColor)
21+
val darkColorPallet = generateDarkThemeColorSet(givenColor, closestColor)
2222

2323
return AppThemePallet(light = lightColorPallet, dark = darkColorPallet)
2424
}
@@ -28,14 +28,16 @@ object ThemeGenUtil {
2828
* @param closestColor The closest color to original consumer given color.
2929
* @return A light theme color set. [ThemeColorPallet]
3030
*/
31-
private fun generateLightThemeColorSet(closestColor: KvColor): ThemeColorPallet {
31+
private fun generateLightThemeColorSet(givenColor: Color, closestColor: KvColor): ThemeColorPallet {
3232
return ThemeColorPallet(
33+
base = givenColor,
3334
primary = closestColor.color,
3435
secondary = generateLightSecondaryColor(closestColor.color),
3536
tertiary = generateLightTeriaryColor(closestColor),
3637
background = generateLightBackgroundColor(closestColor),
3738
onPrimary = Color.White,
38-
onSecondary = Color.White
39+
onSecondary = Color.White,
40+
shadow = Color.Gray
3941
)
4042
}
4143

@@ -44,16 +46,18 @@ object ThemeGenUtil {
4446
* @param closestColor The closest color to original consumer given color.
4547
* @return A dark theme color set. [ThemeColorPallet]
4648
*/
47-
private fun generateDarkThemeColorSet(primaryColor: KvColor): ThemeColorPallet {
49+
private fun generateDarkThemeColorSet(givenColor: Color, primaryColor: KvColor): ThemeColorPallet {
4850
val closestColor = findClosestColor(primaryColor.color)
4951

5052
return ThemeColorPallet(
53+
base = givenColor,
5154
primary = generateDarkPrimaryColor(closestColor.color),
5255
secondary = generateDarkSecondaryColor(closestColor.color),
5356
tertiary = generateDarkTeriaryColor(closestColor),
5457
background = generateDarkBackgroundColor(closestColor.color),
5558
onPrimary = Color.White,
56-
onSecondary = Color.Black
59+
onSecondary = Color.Black,
60+
shadow = Color.White
5761
)
5862
}
5963

ui-app/src/main/kotlin/com/kavi/droid/color/pallet/app/KvColorPalletApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ class KvColorPalletApp: Application() {
99
override fun onCreate() {
1010
super.onCreate()
1111
// Initialize the kv color pallet
12-
KvColorPallet.init(MatPackage.MatDGreen.color)
12+
KvColorPallet.initialize(MatPackage.MatDGreen)
1313
}
1414
}

ui-app/src/main/kotlin/com/kavi/droid/color/pallet/app/theme/Theme.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.ui.graphics.Color
1010
import com.kavi.droid.color.pallet.KvColorPallet
1111

12-
/*private val LightColorScheme = lightColorScheme(
13-
primary = Purple40,
14-
secondary = PurpleGrey40,
15-
tertiary = Pink40,
16-
background = Color.Gray
17-
/* Other default colors to override */
18-
background = Color(0xFFFFFBFE),
19-
surface = Color(0xFFFFFBFE),
20-
onPrimary = Color.White,
21-
onSecondary = Color.White,
22-
onTertiary = Color.White,
23-
onBackground = Color(0xFF1C1B1F),
24-
onSurface = Color(0xFF1C1B1F),
25-
)*/
26-
2712
@Composable
2813
fun KvColorPalletTheme(
2914
darkTheme: Boolean = isSystemInDarkTheme(),

ui-app/src/main/kotlin/com/kavi/droid/color/pallet/app/ui/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fun TabViewExample() {
4949
name = "Color Pallet",
5050
icon = R.drawable.icon_color_grid
5151
),
52-
TabItem(name = "Theme Gen", icon = R.drawable.icon_theme_set)
52+
TabItem(name = "Theme Gen", icon = R.drawable.icon_theme_masks)
5353
)
5454
var selectedTabIndex by remember { mutableStateOf(0) }
5555

ui-app/src/main/kotlin/com/kavi/droid/color/pallet/app/ui/tab/pallet/pager/AlphaPalletPager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fun AlphaPalletPager() {
6767

6868
@Composable
6969
fun AlphaPalletColorRow(givenColor: KvColor, selectedColor: Color, onSelect: (color: Color) -> Unit) {
70-
val colors = KvColorPallet.instance!!.generateAlphaColorPallet(givenColor.color)
70+
val colors = KvColorPallet.instance.generateAlphaColorPallet(givenColor.color)
7171
Row {
7272
colors.forEach {
7373
ColorBox(givenColor = it, selectedColor = selectedColor, onSelect = onSelect)

ui-app/src/main/kotlin/com/kavi/droid/color/pallet/app/ui/tab/pallet/pager/PalletPager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fun PalletPager() {
6666

6767
@Composable
6868
fun PalletColorRow(givenColor: KvColor, selectedColor: Color, onSelect: (color: Color) -> Unit) {
69-
val colors = KvColorPallet(givenColor.color).generateColorPallet(givenColor)
69+
val colors = KvColorPallet.instance.generateColorPallet(givenColor)
7070
Row {
7171
colors.forEach {
7272
ColorBox(givenColor = it, selectedColor = selectedColor, onSelect = onSelect)

0 commit comments

Comments
 (0)