Skip to content

Commit

Permalink
Merge pull request #62 from coderforlife/main
Browse files Browse the repository at this point in the history
Initial transition to multiplatform
  • Loading branch information
skydoves authored Jun 29, 2024
2 parents ae2bad3 + 66cb5a0 commit 9c9f534
Show file tree
Hide file tree
Showing 74 changed files with 2,087 additions and 1,823 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Kotlin class files
./.kotlin
/.kotlin

# Generated files
bin/
Expand Down
74 changes: 53 additions & 21 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,50 @@ import com.github.skydoves.colorpicker.compose.Configuration
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id(libs.plugins.android.application.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.kotlin.multiplatform.get().pluginId)
id(libs.plugins.jetbrains.compose.get().pluginId)
id(libs.plugins.compose.compiler.get().pluginId)
id(libs.plugins.baseline.profile.get().pluginId)
// TODO: id(libs.plugins.baseline.profile.get().pluginId)
}

kotlin {
applyDefaultHierarchyTemplate()
androidTarget()
iosX64()
iosArm64()
iosSimulatorArm64()

task("testClasses")

sourceSets {
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.ui)
implementation(compose.components.uiToolingPreview)
implementation(compose.material)
implementation(compose.components.resources)

implementation(libs.androidx.compose.navigation)

implementation(project(":colorpicker-compose"))

// TODO: implementation(libs.photo.picker)
}

androidMain.dependencies {
implementation(libs.androidx.activity.compose)
}
}
}

android {
namespace = "com.github.skydoves.colorpickercomposedemo"
compileSdk = Configuration.compileSdk
namespace = "com.github.skydoves.colorpickercomposedemo"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")

defaultConfig {
applicationId = "com.github.skydoves.colorpickercomposedemo"
minSdk = Configuration.minSdk
Expand All @@ -24,8 +60,10 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = libs.versions.jvmTarget.get()
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}

buildFeatures {
Expand All @@ -45,21 +83,15 @@ android {
isDebuggable = false
}
}
}

dependencies {
implementation(project(":colorpicker-compose"))

implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.material)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.navigation)

implementation(libs.photo.picker)
// TODO:
// dependencies {
// baselineProfile(project(":benchmark"))
// }
}

baselineProfile(project(":benchmark"))
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ package com.github.skydoves.colorpickercomposedemo
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent { MainScreen() }
setContent {
MaterialTheme(colors = darkColors()) {
MainScreen()
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M15.96,10.29l-2.75,3.54 -1.96,-2.36L8.5,15h11l-3.54,-4.71zM3,5L1,5v16c0,1.1 0.9,2 2,2h16v-2L3,21L3,5zM21,1L7,1c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L23,3c0,-1.1 -0.9,-2 -2,-2zM21,17L7,17L7,3h14v14z"/>
<path android:fillColor="#FFFFFFFF" android:pathData="M15.96,10.29l-2.75,3.54 -1.96,-2.36L8.5,15h11l-3.54,-4.71zM3,5L1,5v16c0,1.1 0.9,2 2,2h16v-2L3,21L3,5zM21,1L7,1c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L23,3c0,-1.1 -0.9,-2 -2,-2zM21,17L7,17L7,3h14v14z"/>

</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:fillColor="#FFFFFFFF"
android:pathData="M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM200,760L760,760Q760,760 760,760Q760,760 760,760L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760ZM240,680L720,680L570,480L450,640L360,520L240,680ZM200,760Q200,760 200,760Q200,760 200,760L200,200Q200,200 200,200Q200,200 200,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760L200,760Z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:fillColor="#FFFFFFFF"
android:pathData="M480,880Q398,880 325,848.5Q252,817 197.5,762.5Q143,708 111.5,635Q80,562 80,480Q80,397 112.5,324Q145,251 200.5,197Q256,143 330,111.5Q404,80 488,80Q568,80 639,107.5Q710,135 763.5,183.5Q817,232 848.5,298.5Q880,365 880,442Q880,557 810,618.5Q740,680 640,680L566,680Q557,680 553.5,685Q550,690 550,696Q550,708 565,730.5Q580,753 580,782Q580,832 552.5,856Q525,880 480,880ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480ZM260,520Q286,520 303,503Q320,486 320,460Q320,434 303,417Q286,400 260,400Q234,400 217,417Q200,434 200,460Q200,486 217,503Q234,520 260,520ZM380,360Q406,360 423,343Q440,326 440,300Q440,274 423,257Q406,240 380,240Q354,240 337,257Q320,274 320,300Q320,326 337,343Q354,360 380,360ZM580,360Q606,360 623,343Q640,326 640,300Q640,274 623,257Q606,240 580,240Q554,240 537,257Q520,274 520,300Q520,326 537,343Q554,360 580,360ZM700,520Q726,520 743,503Q760,486 760,460Q760,434 743,417Q726,400 700,400Q674,400 657,417Q640,434 640,460Q640,486 657,503Q674,520 700,520ZM480,800Q489,800 494.5,795Q500,790 500,782Q500,768 485,749Q470,730 470,692Q470,650 499,625Q528,600 570,600L640,600Q706,600 753,561.5Q800,523 800,442Q800,321 707.5,240.5Q615,160 488,160Q352,160 256,253Q160,346 160,480Q160,613 253.5,706.5Q347,800 480,800Z"/>
</vector>
File renamed without changes
19 changes: 19 additions & 0 deletions app/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Designed and developed by 2022 skydoves (Jaewoong Eum)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<string name="app_name">ColorPickerCompose</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package com.github.skydoves.colorpickercomposedemo

import androidx.annotation.DrawableRes
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
Expand All @@ -33,10 +33,6 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -47,12 +43,16 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import colorpickercomposedemo.app.generated.resources.*
import com.github.skydoves.colorpickercomposedemo.screens.HsvColorPickerColoredSelectorScreen
import com.github.skydoves.colorpickercomposedemo.screens.ImageColorPickerScreen
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource

sealed class Screen(val route: String, val name: String, @DrawableRes val drawable: Int) {
data object ImageColorPicker : Screen("image_picker", "Image", R.drawable.image_24px)
data object HsvPicker : Screen("hsv_picker", "HSV", R.drawable.palette_24px)
sealed class Screen(val route: String, val name: String, val drawable: DrawableResource) {
data object ImageColorPicker : Screen("image_picker", "Image", Res.drawable.image_24px)
data object HsvPicker : Screen("hsv_picker", "HSV", Res.drawable.palette_24px)
}

val navigationItems = listOf(
Expand All @@ -64,7 +64,6 @@ val navigationItems = listOf(
fun MainScreen() {
val navController = rememberNavController()
Scaffold(
modifier = Modifier.semantics { testTagsAsResourceId = true },
bottomBar = { BottomBar(navController) },
topBar = { MainToolBar() },
) { innerPadding ->
Expand Down Expand Up @@ -94,7 +93,7 @@ fun MainToolBar() {
modifier = Modifier
.padding(8.dp)
.align(Alignment.CenterVertically),
text = stringResource(R.string.app_name),
text = stringResource(Res.string.app_name),
color = Color.White,
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
Expand All @@ -110,16 +109,18 @@ fun BottomBar(navController: NavController) {
navigationItems.forEach { screen ->
BottomNavigationItem(
modifier = Modifier.testTag(screen.name),
icon = { Icon(painterResource(id = screen.drawable), contentDescription = null) },
icon = { Icon(painterResource(screen.drawable), contentDescription = null) },
label = { Text(screen.name) },
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
onClick = {
navController.navigate(screen.route) {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
navController.graph.findStartDestination().route?.let {
popUpTo(it) {
saveState = true
}
}
// Avoid multiple copies of the same destination when
// reselecting the same item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:OptIn(BuildCompat.PrereleaseSdkCheck::class)

package com.github.skydoves.colorpickercomposedemo

import android.annotation.SuppressLint
import android.graphics.ImageDecoder
import android.os.Build
import android.provider.MediaStore
import androidx.activity.compose.rememberLauncherForActivityResult
//import android.graphics.ImageDecoder
//import android.os.Build
//import android.provider.MediaStore
//import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand All @@ -31,33 +28,31 @@ import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.vectorResource
//import androidx.compose.ui.graphics.asImageBitmap
//import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.core.os.BuildCompat
import colorpickercomposedemo.app.generated.resources.*
import com.github.skydoves.colorpicker.compose.ColorPickerController
import com.google.modernstorage.photopicker.PhotoPicker
import org.jetbrains.compose.resources.vectorResource
//import com.google.modernstorage.photopicker.PhotoPicker

@Composable
@SuppressLint("UnsafeOptInUsageError")
fun ColumnScope.PhotoPickerIcon(
controller: ColorPickerController,
) {
val context = LocalContext.current
val photoPicker =
rememberLauncherForActivityResult(PhotoPicker()) { uris ->
val uri = uris.firstOrNull() ?: return@rememberLauncherForActivityResult

val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uri))
} else {
MediaStore.Images.Media.getBitmap(context.contentResolver, uri)
}

controller.setPaletteImageBitmap(bitmap.asImageBitmap())
}
// val context = LocalContext.current
// val photoPicker =
// rememberLauncherForActivityResult(PhotoPicker()) { uris ->
// val uri = uris.firstOrNull() ?: return@rememberLauncherForActivityResult
//
// val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uri))
// } else {
// MediaStore.Images.Media.getBitmap(context.contentResolver, uri)
// }
//
// controller.setPaletteImageBitmap(bitmap.asImageBitmap())
// }

Box(
modifier = Modifier
Expand All @@ -69,9 +64,9 @@ fun ColumnScope.PhotoPickerIcon(
.size(42.dp)
.clickable {
// Launch the picker with only one image selectable
photoPicker.launch(PhotoPicker.Args(PhotoPicker.Type.IMAGES_ONLY, 1))
//photoPicker.launch(PhotoPicker.Args(PhotoPicker.Type.IMAGES_ONLY, 1))
},
imageVector = ImageVector.vectorResource(R.drawable.ic_gallery),
imageVector = vectorResource(Res.drawable.ic_gallery),
contentDescription = null,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.github.skydoves.colorpicker.compose.AlphaSlider
Expand All @@ -50,6 +47,7 @@ import com.github.skydoves.colorpicker.compose.BrightnessSlider
import com.github.skydoves.colorpicker.compose.HsvColorPicker
import com.github.skydoves.colorpicker.compose.drawColorIndicator
import com.github.skydoves.colorpicker.compose.rememberColorPickerController
import org.jetbrains.compose.ui.tooling.preview.Preview

@OptIn(ExperimentalMaterialApi::class)
@Preview
Expand All @@ -60,7 +58,7 @@ fun HsvColorPickerColoredSelectorScreen() {
var hexCode by remember { mutableStateOf("") }
var textColor by remember { mutableStateOf(Color.Transparent) }

Column(modifier = Modifier.semantics { testTagsAsResourceId = true }) {
Column {
Spacer(modifier = Modifier.weight(1f))

Row(modifier = Modifier.weight(3f)) {
Expand Down
Loading

0 comments on commit 9c9f534

Please sign in to comment.