-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from godaddy/feature/color-wheel-harmony
Added a Color Wheel for Harmony Color Modes
- Loading branch information
Showing
23 changed files
with
931 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/godaddy/android/colorpicker/ClassicColorPickerScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.godaddy.android.colorpicker | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavController | ||
import com.godaddy.android.colorpicker.theme.BackButton | ||
import com.godaddy.android.colorpicker.theme.ComposeColorPickerTheme | ||
|
||
@Composable | ||
fun ClassicColorPickerScreen(navController: NavController) { | ||
Column { | ||
TopAppBar(title = { | ||
Text(stringResource(R.string.classic_color_picker_sample)) | ||
}, | ||
navigationIcon = { | ||
BackButton { navController.navigateUp() } | ||
}) | ||
val currentColor = remember { | ||
mutableStateOf(Color.Black) | ||
} | ||
ColorPreviewInfo(currentColor = currentColor.value) | ||
ClassicColorPicker( | ||
color = currentColor.value, | ||
modifier = Modifier | ||
.height(300.dp) | ||
.padding(16.dp), | ||
onColorChanged = { hsvColor: HsvColor -> | ||
// Triggered when the color changes, do something with the newly picked color here! | ||
currentColor.value = hsvColor.toColor() | ||
} | ||
) | ||
} | ||
|
||
} | ||
|
||
|
||
@Composable | ||
fun ClassicColorPickerPreview() { | ||
ComposeColorPickerTheme { | ||
ClassicColorPicker( | ||
modifier = Modifier.height(300.dp), | ||
color = Color.Green, | ||
onColorChanged = { | ||
|
||
}) | ||
|
||
} | ||
} | ||
|
||
@Composable | ||
fun ClassicColorPickerNoAlphaPreview() { | ||
ComposeColorPickerTheme { | ||
ClassicColorPicker( | ||
modifier = Modifier.height(300.dp), | ||
color = Color.Magenta, | ||
showAlphaBar = false, | ||
onColorChanged = { | ||
|
||
}) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/godaddy/android/colorpicker/ColorPreviewInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.godaddy.android.colorpicker | ||
|
||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.lazy.GridCells | ||
import androidx.compose.foundation.lazy.LazyVerticalGrid | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun ColorPreviewInfo(currentColor: Color) { | ||
Column(modifier = Modifier.fillMaxWidth()) { | ||
Text( | ||
modifier = Modifier.padding(16.dp), | ||
text = "a: ${currentColor.alpha} \n" + | ||
"r: ${currentColor.red} \n" + | ||
"g: ${currentColor.green} \n" + | ||
"b: ${currentColor.blue}" | ||
) | ||
Spacer( | ||
modifier = Modifier | ||
.background( | ||
currentColor, | ||
shape = CircleShape | ||
) | ||
.size(48.dp) | ||
.align(Alignment.CenterHorizontally) | ||
) | ||
Spacer(Modifier.height(16.dp)) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
fun ColorPaletteBar( | ||
modifier: Modifier = Modifier, | ||
colors: List<HsvColor> | ||
) { | ||
LazyVerticalGrid( | ||
horizontalArrangement = Arrangement.spacedBy(4.dp), | ||
verticalArrangement = Arrangement.spacedBy(4.dp), | ||
cells = GridCells.Adaptive(48.dp), | ||
modifier = modifier | ||
.fillMaxWidth(), | ||
contentPadding = PaddingValues(16.dp), | ||
content = { | ||
items(colors) { color -> | ||
Canvas(modifier = Modifier.size(48.dp)) { | ||
drawCircle(color.toColor()) | ||
} | ||
} | ||
} | ||
) | ||
} |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.godaddy.android.colorpicker | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavController | ||
import com.godaddy.android.colorpicker.harmony.ColorHarmonyMode | ||
import com.godaddy.android.colorpicker.harmony.HarmonyColorPicker | ||
import com.godaddy.android.colorpicker.theme.BackButton | ||
|
||
@Composable | ||
fun HarmonyColorPickerScreen(navController: NavController) { | ||
Column { | ||
TopAppBar(title = { | ||
Text(stringResource(R.string.harmony_color_picker_sample)) | ||
}, | ||
navigationIcon = { | ||
BackButton { navController.navigateUp() } | ||
}) | ||
val currentColor = remember { | ||
mutableStateOf(Color.Black) | ||
} | ||
val extraColors = remember { | ||
mutableStateOf(emptyList<HsvColor>()) | ||
} | ||
ColorPreviewInfo(currentColor = currentColor.value) | ||
val expanded = remember { | ||
mutableStateOf(false) | ||
} | ||
val harmonyMode = remember { | ||
mutableStateOf(ColorHarmonyMode.ANALOGOUS) | ||
} | ||
TextButton(onClick = { | ||
expanded.value = true | ||
}) { | ||
Text(harmonyMode.value.name) | ||
} | ||
DropdownMenu(expanded.value, onDismissRequest = { | ||
expanded.value = false | ||
}) { | ||
ColorHarmonyMode.values().forEach { | ||
DropdownMenuItem(onClick = { | ||
harmonyMode.value = it | ||
expanded.value = false | ||
}) { | ||
Text(it.name) | ||
} | ||
} | ||
} | ||
HarmonyColorPicker( | ||
harmonyMode = harmonyMode.value, | ||
modifier = Modifier.size(400.dp), | ||
onColorChanged = { hsvColor -> | ||
currentColor.value = hsvColor.toColor() | ||
extraColors.value = hsvColor.getColors(colorHarmonyMode = harmonyMode.value) | ||
}) | ||
ColorPaletteBar(modifier = Modifier.fillMaxWidth().height(70.dp), colors = extraColors.value) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.godaddy.android.colorpicker | ||
|
||
sealed class Route(val link: String) { | ||
object Picker : Route("picker") | ||
object ClassicColorPicker : Route("classic") | ||
object HarmonyColorPicker : Route("harmony") | ||
} |
Oops, something went wrong.