Skip to content

Commit 2248765

Browse files
author
Rebecca Franks
committed
Add Spotless configuration and clean up classic color picker ui.
1 parent a3d0d4a commit 2248765

File tree

22 files changed

+196
-134
lines changed

22 files changed

+196
-134
lines changed

CODE_OF_CONDUCT.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119119
version 2.0, available at
120120
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
121121

122-
Community Impact Guidelines were inspired by
122+
Community Impact Guidelines were inspired by
123123
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124124

125125
For answers to common questions about this code of conduct, see the FAQ at
126-
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
126+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
127127
at [https://www.contributor-covenant.org/translations][translations].
128128

129129
[homepage]: https://www.contributor-covenant.org

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ Or add the `HarmonyColorPicker` to your Compose hierarchy for an HSV color wheel
4444
modifier = Modifier.size(400.dp),
4545
onColorChanged = { hsvColor ->
4646
currentColor.value = hsvColor.toColor()
47-
extraColors.value = hsvColor.getColors(colorHarmonyMode = harmonyMode.value)
47+
extraColors.value = hsvColor.getColors(colorHarmonyMode = harmonyMode.value)
4848
})
4949
```
5050

51-
The `HarmonyColorPicker` allows for you to set a certain `ColorHarmonyMode` on the wheel.
52-
This will then display multiple magnifiers on top of the wheel for the different harmony modes: ie complementary, triadic, analogous, shades, monochromatic, tetradic.
51+
The `HarmonyColorPicker` allows for you to set a certain `ColorHarmonyMode` on the wheel.
52+
This will then display multiple magnifiers on top of the wheel for the different harmony modes: ie complementary, triadic, analogous, shades, monochromatic, tetradic.
5353
If you wish to not display other magnifiers - set `ColorHarmonyMode.NONE` as your `harmonyMode` on the wheel.
5454

55-
# ClassicColorPicker:
55+
# ClassicColorPicker:
5656
## Customizing the control
5757

5858
### Size
@@ -119,11 +119,14 @@ HarmonyColorPicker(
119119

120120
# Library Contribution Information
121121

122-
### To make a release
122+
## Code Formatting
123+
124+
This project uses spotless to enforce code formatting. Run `./gradlew spotlessApply` to run formatting before committing.
125+
126+
### Releases
123127

124128
1. Update the version number in color-picker/build.gradle.kts
125129
2. Make a PR into main and get that merged
126130
3. Run "Deploy to Sonatype" GitHub Action.
127-
4. Login to Sonatype and "Close" release. After a few minutes, click "Release".
131+
4. Login to Sonatype and "Close" release. After a few minutes, click "Release".
128132
5. Release should then be available for download on maven (might take like 30 min to propagate).
129-

app/src/main/java/com/godaddy/android/colorpicker/ClassicColorPickerScreen.kt

+10-11
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ import com.godaddy.android.colorpicker.theme.ComposeColorPickerTheme
1919
@Composable
2020
fun ClassicColorPickerScreen(navController: NavController) {
2121
Column {
22-
TopAppBar(title = {
23-
Text(stringResource(R.string.classic_color_picker_sample))
24-
},
22+
TopAppBar(
23+
title = {
24+
Text(stringResource(R.string.classic_color_picker_sample))
25+
},
2526
navigationIcon = {
2627
BackButton { navController.navigateUp() }
27-
})
28+
}
29+
)
2830
val currentColor = remember {
2931
mutableStateOf(Color.Black)
3032
}
@@ -40,20 +42,17 @@ fun ClassicColorPickerScreen(navController: NavController) {
4042
}
4143
)
4244
}
43-
4445
}
4546

46-
4747
@Composable
4848
fun ClassicColorPickerPreview() {
4949
ComposeColorPickerTheme {
5050
ClassicColorPicker(
5151
modifier = Modifier.height(300.dp),
5252
color = Color.Green,
5353
onColorChanged = {
54-
55-
})
56-
54+
}
55+
)
5756
}
5857
}
5958

@@ -65,7 +64,7 @@ fun ClassicColorPickerNoAlphaPreview() {
6564
color = Color.Magenta,
6665
showAlphaBar = false,
6766
onColorChanged = {
68-
69-
})
67+
}
68+
)
7069
}
7170
}

app/src/main/java/com/godaddy/android/colorpicker/ColorPreviewInfo.kt

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ package com.godaddy.android.colorpicker
33
import androidx.compose.foundation.Canvas
44
import androidx.compose.foundation.ExperimentalFoundationApi
55
import androidx.compose.foundation.background
6-
import androidx.compose.foundation.layout.*
6+
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.foundation.layout.PaddingValues
9+
import androidx.compose.foundation.layout.Spacer
10+
import androidx.compose.foundation.layout.fillMaxWidth
11+
import androidx.compose.foundation.layout.height
12+
import androidx.compose.foundation.layout.padding
13+
import androidx.compose.foundation.layout.size
714
import androidx.compose.foundation.lazy.GridCells
815
import androidx.compose.foundation.lazy.LazyVerticalGrid
916
import androidx.compose.foundation.lazy.items
@@ -21,9 +28,9 @@ fun ColorPreviewInfo(currentColor: Color) {
2128
Text(
2229
modifier = Modifier.padding(16.dp),
2330
text = "a: ${currentColor.alpha} \n" +
24-
"r: ${currentColor.red} \n" +
25-
"g: ${currentColor.green} \n" +
26-
"b: ${currentColor.blue}"
31+
"r: ${currentColor.red} \n" +
32+
"g: ${currentColor.green} \n" +
33+
"b: ${currentColor.blue}"
2734
)
2835
Spacer(
2936
modifier = Modifier

app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import androidx.compose.foundation.layout.Column
44
import androidx.compose.foundation.layout.fillMaxWidth
55
import androidx.compose.foundation.layout.height
66
import androidx.compose.foundation.layout.size
7-
import androidx.compose.material.*
7+
import androidx.compose.material.DropdownMenu
8+
import androidx.compose.material.DropdownMenuItem
9+
import androidx.compose.material.Text
10+
import androidx.compose.material.TextButton
11+
import androidx.compose.material.TopAppBar
812
import androidx.compose.runtime.Composable
913
import androidx.compose.runtime.mutableStateOf
1014
import androidx.compose.runtime.remember
@@ -20,12 +24,14 @@ import com.godaddy.android.colorpicker.theme.BackButton
2024
@Composable
2125
fun HarmonyColorPickerScreen(navController: NavController) {
2226
Column {
23-
TopAppBar(title = {
24-
Text(stringResource(R.string.harmony_color_picker_sample))
25-
},
27+
TopAppBar(
28+
title = {
29+
Text(stringResource(R.string.harmony_color_picker_sample))
30+
},
2631
navigationIcon = {
2732
BackButton { navController.navigateUp() }
28-
})
33+
}
34+
)
2935
val currentColor = remember {
3036
mutableStateOf(Color.Black)
3137
}
@@ -62,8 +68,8 @@ fun HarmonyColorPickerScreen(navController: NavController) {
6268
onColorChanged = { hsvColor ->
6369
currentColor.value = hsvColor.toColor()
6470
extraColors.value = hsvColor.getColors(colorHarmonyMode = harmonyMode.value)
65-
})
71+
}
72+
)
6673
ColorPaletteBar(modifier = Modifier.fillMaxWidth().height(70.dp), colors = extraColors.value)
6774
}
68-
6975
}

app/src/main/java/com/godaddy/android/colorpicker/theme/Theme.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ fun ComposeColorPickerTheme(
4242
colors = colors,
4343
content = content
4444
)
45-
}
45+
}

build.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ allprojects {
2222
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
2323
}
2424
}
25+
26+
plugins {
27+
id("com.diffplug.spotless") version "6.2.0"
28+
}
29+
30+
apply("${project.rootDir}/gradle/spotless.gradle")

color-picker/src/androidMain/kotlin/com/godaddy/android/colorpicker/HsvColorExt.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ package com.godaddy.android.colorpicker
55
*
66
* returns @ColorInt
77
*/
8-
fun HsvColor.toColorInt() : Int{
8+
fun HsvColor.toColorInt(): Int {
99
return android.graphics.Color.HSVToColor((alpha * 255).toInt(), floatArrayOf(hue, saturation, value))
10-
}
10+
}

color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/AlphaBar.kt

+18-16
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,32 @@ internal fun AlphaBar(
4141
)
4242
)
4343
}
44-
Canvas(modifier = modifier
45-
.fillMaxSize()
46-
.pointerInput(Unit) {
47-
forEachGesture {
48-
awaitPointerEventScope {
49-
val down = awaitFirstDown()
50-
onAlphaChanged(
51-
getAlphaFromPosition(
52-
down.position.x,
53-
this.size.width.toFloat()
54-
).coerceIn(0f, 1f)
55-
)
56-
drag(down.id) { change ->
57-
change.consumePositionChange()
44+
Canvas(
45+
modifier = modifier
46+
.fillMaxSize()
47+
.pointerInput(Unit) {
48+
forEachGesture {
49+
awaitPointerEventScope {
50+
val down = awaitFirstDown()
5851
onAlphaChanged(
5952
getAlphaFromPosition(
60-
change.position.x,
53+
down.position.x,
6154
this.size.width.toFloat()
6255
).coerceIn(0f, 1f)
6356
)
57+
drag(down.id) { change ->
58+
change.consumePositionChange()
59+
onAlphaChanged(
60+
getAlphaFromPosition(
61+
change.position.x,
62+
this.size.width.toFloat()
63+
).coerceIn(0f, 1f)
64+
)
65+
}
6466
}
6567
}
6668
}
67-
}) {
69+
) {
6870

6971
clipRect {
7072
drawCheckeredBackground()

color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/ClassicColorPicker.kt

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import androidx.compose.foundation.layout.Row
55
import androidx.compose.foundation.layout.Spacer
66
import androidx.compose.foundation.layout.height
77
import androidx.compose.foundation.layout.width
8-
import androidx.compose.material.TextField
98
import androidx.compose.runtime.Composable
10-
import androidx.compose.runtime.MutableState
119
import androidx.compose.runtime.mutableStateOf
1210
import androidx.compose.runtime.saveable.rememberSaveable
1311
import androidx.compose.ui.Modifier
1412
import androidx.compose.ui.graphics.Color
15-
import androidx.compose.ui.graphics.ExperimentalGraphicsApi
1613
import androidx.compose.ui.unit.dp
1714

1815
/**
@@ -39,7 +36,8 @@ fun ClassicColorPicker(
3936
val barThickness = 32.dp
4037
val paddingBetweenBars = 8.dp
4138
Column(modifier = Modifier.weight(0.8f)) {
42-
SaturationValueArea(modifier = Modifier.weight(0.8f),
39+
SaturationValueArea(
40+
modifier = Modifier.weight(0.8f),
4341
currentColor = colorPickerValueState.value,
4442
onSaturationValueChanged = { saturation, value ->
4543
colorPickerValueState.value =
@@ -49,7 +47,8 @@ fun ClassicColorPicker(
4947
)
5048
if (showAlphaBar) {
5149
Spacer(modifier = Modifier.height(paddingBetweenBars))
52-
AlphaBar(modifier = Modifier.height(barThickness),
50+
AlphaBar(
51+
modifier = Modifier.height(barThickness),
5352
currentColor = colorPickerValueState.value,
5453
onAlphaChanged = { alpha ->
5554
colorPickerValueState.value = colorPickerValueState.value.copy(alpha = alpha)
@@ -69,4 +68,3 @@ fun ClassicColorPicker(
6968
)
7069
}
7170
}
72-

color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/HsvColor.kt

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.godaddy.android.colorpicker
22

3-
43
/**
54
* A representation of Color in Hue, Saturation and Value form.
65
*/
@@ -16,16 +15,16 @@ import com.godaddy.android.colorpicker.harmony.ColorHarmonyMode
1615
*/
1716
data class HsvColor(
1817

19-
//from = 0.0, to = 360.0
18+
// from = 0.0, to = 360.0
2019
val hue: Float,
2120

22-
//from = 0.0, to = 1.0
21+
// from = 0.0, to = 1.0
2322
val saturation: Float,
2423

25-
//from = 0.0, to = 1.0
24+
// from = 0.0, to = 1.0
2625
val value: Float,
2726

28-
//from = 0.0, to = 1.0
27+
// from = 0.0, to = 1.0
2928
val alpha: Float
3029
) {
3130

@@ -111,7 +110,6 @@ data class HsvColor(
111110
}
112111
}
113112

114-
115113
companion object {
116114

117115
val DEFAULT = HsvColor(360f, 1.0f, 1.0f, 1.0f)

color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/HueBar.kt

+13-12
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ internal fun HueBar(
3131
val rainbowBrush = remember {
3232
Brush.verticalGradient(getRainbowColors())
3333
}
34-
Canvas(modifier = modifier
35-
.fillMaxSize()
36-
.pointerInput(Unit) {
37-
forEachGesture {
38-
awaitPointerEventScope {
39-
val down = awaitFirstDown()
40-
onHueChanged(getHueFromPoint(down.position.y, size.height.toFloat()))
41-
drag(down.id) { change ->
42-
change.consumePositionChange()
43-
onHueChanged(getHueFromPoint(change.position.y, size.height.toFloat()))
34+
Canvas(
35+
modifier = modifier
36+
.fillMaxSize()
37+
.pointerInput(Unit) {
38+
forEachGesture {
39+
awaitPointerEventScope {
40+
val down = awaitFirstDown()
41+
onHueChanged(getHueFromPoint(down.position.y, size.height.toFloat()))
42+
drag(down.id) { change ->
43+
change.consumePositionChange()
44+
onHueChanged(getHueFromPoint(change.position.y, size.height.toFloat()))
45+
}
4446
}
4547
}
4648
}
47-
}
4849
) {
4950
drawRect(rainbowBrush)
5051
drawRect(Color.Gray, style = Stroke(0.5.dp.toPx()))
@@ -54,7 +55,7 @@ internal fun HueBar(
5455
}
5556
}
5657

57-
private fun getRainbowColors() : List<Color> {
58+
private fun getRainbowColors(): List<Color> {
5859
return listOf(
5960
Color(0xFFFF0040),
6061
Color(0xFFFF00FF),

0 commit comments

Comments
 (0)