Colorpicker Compose

Overview

colorpicker-compose

License API API Profile


🎨 Jetpack Compose color picker library that allows you to get colors from any images like gallery pictures by tapping on the desired color. Also, it supports brightness and alpha slider, which can adjust your ARGB factors.

Preview

Download

Maven Central

Gradle

Add the dependency below to your module's build.gradle file:

dependencies {
    implementation "com.github.skydoves:colorpicker-compose:1.0.0"
}

SNAPSHOT

See how to import the snapshot

Including the SNAPSHOT

Snapshots of the current development version of ColorPicker-Compose are available, which track the latest versions.

To import snapshot versions on your project, add the code snippet below on your gradle file:

repositories {
   maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

Next, add the dependency below to your module's build.gradle file:

dependencies {
    implementation "com.github.skydoves:colorpicker-compose:1.0.1-SNAPSHOT"
}

Usage

First, you should initialize ColorPickerController, which allows you to control color pickers and all subcomponents.

val controller = rememberColorPickerController()

Next, you can implement a color picker with the ImageColorPicker composable function.

ImageColorPicker(
    modifier = Modifier.fillMaxSize(),
    paletteImageBitmap = ImageBitmap.imageResource(R.drawable.palettebar),
    controller = controller
)

ImageColorPicker

ImageColorPicker allows you to get colors from any images such as gallery pictures or drawable resources by tapping on the desired color. It interacts with the ColorPickerController to control the color picker and other components. You can use the ImageColorPicker as the following example:

ImageColorPicker(
    modifier = Modifier
        .fillMaxWidth()
        .height(450.dp)
        .padding(10.dp),
    controller = controller,
    paletteImageBitmap = ImageBitmap.imageResource(R.drawable.palettebar),
    paletteContentScale = PaletteContentScale.FIT,
    onColorChanged = { colorEnvelope: ColorEnvelope ->
        // do something
    }
)

With the modernstorage's Photo Picker, you can set an desired image as the palette like the below:

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())
    }

As you can see the above, you can set the palette with the setPaletteImageBitmap function of the controller.

PaletteContentScale

You can adjust your palette's image scale with the setPaletteContentScale function of the controller as the below:

controller.setPaletteContentScale(PaletteContentScale.FIT) // scale the image to fit width and height.
controller.setPaletteContentScale(PaletteContentScale.CROP) // center crop the image.

HsvColorPicker

HsvColorPicker allows you to get colors from HSV color palette by tapping on the desired color. It interacts with the ColorPickerController to control the color picker and other components. You can use the HsvColorPicker as the following example:

HsvColorPicker(
    modifier = Modifier
        .fillMaxWidth()
        .height(450.dp)
        .padding(10.dp),
    controller = controller,
    onColorChanged = { colorEnvelope: ColorEnvelope ->
        // do something
    }
)

Note: If you use HsvColorPicker, you can not set the palette and content scale with the setPaletteImageBitmap and setPaletteContentScale functions.

ColorEnvelope

ColorEnvelope is a data transfer object that includes updated color factors. If you pass the onColorChanged lambda function to the ImageColorPicker or HsvColorPicker, the lambda receives ColorEnvelope. ColorEnvelope includes the following properties:

onColorChanged = { colorEnvelope: ColorEnvelope ->
    val color: Color = colorEnvelope.color // ARGB color value.
    val hexCode: String = colorEnvelope.hexCode // Color hex code, which represents color value.
    val fromUser: Boolean = colorEnvelope.fromUser // Represents this event is triggered by user or not.
}

ColorPickerController

ColorPickerController interacts with color pickers and it allows you to control the all subcomponents.

Custom Wheel

You can customize the wheel with the following functions:

.setWheelRadius(40.dp) // set the radius size of the wheel.
.setWheelColor(Color.Blue) // set the color of the wheel.
.setWheelAlpha(0.5f) // set the transparency of the wheel.
.setWheelImageBitmap(imageBitmap) // set the wheel image with your custom ImageBitmap.

Select Points

You can select specific points with the functions below:

.selectByCoordinate(x = 100f, y = 100f, fromUser = false) // select x = 100, y = 100.
.selectCenter(fromUser = false) // select center of the palette.

Debounce

You can set the debounce duration, which decides to invoke the color listener from the last tapping. Debounce can be useful to reduce overhead. For example, communicating with IoT devices or relevant works that require heavy operations.

.setDebounceDuration(300L)

Enable and Disable

You can enable or disable your color picker with the below function:

.setEnabled(false)

AlphaSlider

AlphaSlider allows you to adjust the alpha value of the selected color from color pickers. AlphaSlider needs to be tied to the ColorPickerController, and the value changes will be assembled with the selected color factors. You can implement AlphaSlider as the following example:

AlphaSlider(
    modifier = Modifier
        .fillMaxWidth()
        .padding(10.dp)
        .height(35.dp)
    controller = controller,
)

You can customize the border of the sider with the following parameters:

AlphaSlider(
    borderRadius = 6.dp,
    borderSize = 5.dp,
    borderColor = Color.LightGray,
    ..
)

You can customize the wheel of the sider with the following parameters:

AlphaSlider(
    wheelRadius = 30.dp,
    wheelColor = Color.White,
    wheelPaint = Paint().apply { color = wheelColor },
    wheelImageBitmap = ImageBitmap.imageResource(R.drawable.wheel),
    ..
)

Also, you can customize tiles of the background with the following parameters:

AlphaSlider(
    tileOddColor = Color.White,
    tileEvenColor = Color.LightGray,
    tileSize = 30.dp,
    ..
)

BrightnessSlider

BrightnessSlider allows you to adjust the brightness value of the selected color from color pickers. BrightnessSlider needs to be tied to the ColorPickerController, and the value changes will be assembled with the selected color factors. You can implement BrightnessSlider as the following example:

BrightnessSlider(
    modifier = Modifier
        .fillMaxWidth()
        .padding(10.dp)
        .height(35.dp)
    controller = controller,
)

You can customize the wheel of the sider with the following parameters:

BrightnessSlider(
    wheelRadius = 30.dp,
    wheelColor = Color.White,
    wheelPaint = Paint().apply { color = wheelColor },
    wheelImageBitmap = ImageBitmap.imageResource(R.drawable.wheel),
    ..
)

AlphaTile

AlphaTile allows you to display ARGB colors including transparency with tiles.

AlphaTile(
    modifier = Modifier
        .size(80.dp)
        .clip(RoundedCornerShape(6.dp))
    controller = controller
)

Also, you can customize tiles of the background with the following parameters:

AlphaTile(
    tileOddColor = Color.White,
    tileEvenColor = Color.LightGray,
    tileSize = 30.dp,
    ..
)

Find this repository useful? ❤️

Support it by joining stargazers for this repository.
Also, follow me on GitHub for my next creations! 🤩

License

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.
Comments
  • Selection indicators are huge

    Selection indicators are huge

    Please complete the following information:

    • Library Version: 1.0.0
    • Affected Device: emulator WXGA tablet

    Describe the Bug: The white selector circle is about 5x bigger than in the screenshots in the documentation

    Expected Behavior: Selector to look like the screenshots

    opened by sproctor 2
  • Not able to set value of alpha and brightness sliders to 0

    Not able to set value of alpha and brightness sliders to 0

    • Library Version v1.0.0

    The values of alpha and brightness sliders cannot be set to 0.

    As you can see in this screenshot, If I slide the alpha slider to the leftmost side, it's value only gets to #09 instead of #00

    This also applies to the brightness slider.

    opened by daannnnn 2
  • need

    need "," for next attribute

    Thanks for this library is really good

    ✍️ Explain examples

    In readme need "," in:

    BrightnessSlider( modifier = Modifier .fillMaxWidth() .padding(10.dp) .height(35.dp) controller = controller, )

    AlphaTile( modifier = Modifier .size(80.dp) .clip(RoundedCornerShape(6.dp)) controller = controller )

    opened by LucasGinard 0
  • Fix a typo (missing commas) in README.md

    Fix a typo (missing commas) in README.md

    🎯 Goal

    Add missing commas in the readme

    🛠 Implementation details

    Describe the implementation details for this Pull Request.

    ✍️ Explain examples

    Explain examples with code for this updates.

    Preparing a pull request for review

    Ensure your change is properly formatted by running:

    $ ./gradlew spotlessApply
    

    Please correct any failures before requesting a review.

    opened by lhoyong 0
  • Set behavior not like in preview

    Set behavior not like in preview

    Please complete the following information:

    • Library Version [e.g. v1.0.0]
    • Affected Device(s) [e.g. Samsung Galaxy s10 with Android 9.0]

    Describe the Bug:

    Color sets only after new click

    Expected Behavior:

    Color sets also while drag


    I found out that drag just doesn't work.

    ----Update 1---- I found out that drag not working if scroll enabled.

    ----Update 2---- this repo does not have this problem https://github.com/SmartToolFactory/Jetpack-Compose-Tutorials#gesture

    opened by Monabr 1
  • Allow to set HsvColorPicker color and BrightnessSlider value manually

    Allow to set HsvColorPicker color and BrightnessSlider value manually

    I use this code to set the color, but I'm not able to set the brightness

    `val hsv = FloatArray(3) val color = Color(initialColor) RGBToHSV( (color.red * 255).toInt(), (color.green * 255).toInt(), (color.blue * 255).toInt(), hsv) val pickerWidth = 500f val radius = pickerWidth / 2f val colorRadius: Float = hsv[1] * radius val angle: Double = ((1 - (hsv[0] / 360f)) * (2 * Math.PI)) val midX: Float = pickerWidth / 2f //midpoint of the circle val midY: Float = pickerWidth / 2f val xOffset: Float = (kotlin.math.cos(angle) * colorRadius).toFloat() //offset from the midpoint of the circle val yOffset: Double = sin(angle) * colorRadius val x = midX + xOffset val y = midY + yOffset

                            controller.selectByCoordinate(x, y.toFloat(), fromUser = false)`
    

    Regarding the brightness the setBrightness function should be public

    opened by joe1327 1
Releases(1.0.1)
  • 1.0.1(Dec 11, 2022)

    What's Changed

    • Bump AGP to 7.1.2 and Gradle Wrapper to 7.4.2 by @skydoves in https://github.com/skydoves/colorpicker-compose/pull/1
    • Fix a typo (missing commas) in README.md by @lhoyong in https://github.com/skydoves/colorpicker-compose/pull/4
    • need "," for next attribute by @LucasGinard in https://github.com/skydoves/colorpicker-compose/pull/6
    • Update AGP to 7.2.0, Compose to 1.2.0-rc01, and target SDK to 32 by @skydoves in https://github.com/skydoves/colorpicker-compose/pull/7
    • Update Compose to 1.2.0-rc02 by @skydoves in https://github.com/skydoves/colorpicker-compose/pull/8
    • Update Compose compiler to 1.3.2 and Kotlin to 1.7.20 by @skydoves in https://github.com/skydoves/colorpicker-compose/pull/11
    • Fix not being able to set value of alpha and brightness sliders to 0 by @daannnnn in https://github.com/skydoves/colorpicker-compose/pull/3
    • Migrate to Compose BOM by @skydoves in https://github.com/skydoves/colorpicker-compose/pull/12
    • Change default side of thumbs and tiles following the density by @skydoves in https://github.com/skydoves/colorpicker-compose/pull/13

    New Contributors

    • @skydoves made their first contribution in https://github.com/skydoves/colorpicker-compose/pull/1
    • @lhoyong made their first contribution in https://github.com/skydoves/colorpicker-compose/pull/4
    • @LucasGinard made their first contribution in https://github.com/skydoves/colorpicker-compose/pull/6
    • @daannnnn made their first contribution in https://github.com/skydoves/colorpicker-compose/pull/3

    Full Changelog: https://github.com/skydoves/colorpicker-compose/compare/1.0.0...1.0.1

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Mar 9, 2022)

    🎉 ColorPicker Compose library has been announced!

    🎨 Jetpack Compose color picker library for getting colors from any images by tapping on the desired color.

    Source code(tar.gz)
    Source code(zip)
Owner
Jaewoong Eum
Android Developer Advocate @GetStream 🥑 • GDE for Android • Open Source Software Engineer ❤️ • Love coffee, music, magic tricks, and writing poems.
Jaewoong Eum
Jetpack Compose Color Picker

Bundle of Stylish customizable Color pickers, selectors, colorful sliders written with Jetpack Compose enables users to choose from HSL, HSV or RGB color modes to pick Solid colors or gradients.

Smart Tool Factory 34 Nov 29, 2022
Utility library that extends Jetpack Compose Colors with Material Design2 colors, Color swatches like in Flutter

????♾ Utility library that expands Compose Colors with Material Design2 colors, color swatches, Material Design 3 Tonal Palettes, color names, and utility functions to convert between HSL, HSV, RGB, HCT models and to HEX or from HEX

Smart Tool Factory 18 Dec 13, 2022
🎨 Android colorpicker for getting colors from any images by tapping on the desired color.

ColorPickerView ?? ColorPickerView implements getting HSV colors, ARGB values, Hex color codes from any image drawables or your gallery pictures by ta

Jaewoong Eum 1.3k Dec 26, 2022
🎨 Android colorpicker for getting colors from any images by tapping on the desired color.

ColorPickerView ?? ColorPickerView implements getting HSV colors, ARGB values, Hex color codes from any image drawables or your gallery pictures by ta

Jaewoong Eum 1.3k Jan 8, 2023
An Android Holo themed colorpicker designed by Marie Schweiz

Android Holo ColorPicker Marie Schweiz http://marie-schweiz.de/ made a beautifull new design for the Holo ColorPicker which added a lot of new functio

Lars Werkman 1.4k Dec 21, 2022
A great material designed colorpicker by Marie Schweiz

Lobsterpicker Designed by Marie Schweiz, Developed by Lars Werkman Lobsterpicker is a library for android material design made to support apps and dev

Lars Werkman 534 Sep 15, 2022
MVVM + Kotlin + Jetpack Compose +Navigation Compose + Hilt + Retrofit + Unit Testing + Compose Testing + Coroutines + Kotlin Flow + Io mockK

MvvmKotlinJetpackCompose Why do we need an architecture even when you can make an app without it? let's say you created a project without any architec

Sayyed Rizwan 46 Nov 29, 2022
Funstuff - Minimal Kotlin Multiplatform project with SwiftUI, Jetpack Compose, Compose for Wear OS, Compose for Desktop

PeopleInSpace Minimal Kotlin Multiplatform project with SwiftUI, Jetpack Compose

Shivam Dhuria 2 Feb 15, 2022
Jetpack Compose Boids | Flocking Insect 🐜. bird or Fish simulation using Jetpack Compose Desktop 🚀, using Canvas API 🎨

?? ?? ?? Compose flocking Ants(boids) ?? ?? ?? Jetpack compose Boids | Flocking Insect. bird or Fish simulation using Jetpack Compose Desktop ?? , usi

Chetan Gupta 38 Sep 25, 2022
🔥🔥🔥Android Compose Banner!!! 安卓 Compose 版本的 Banner

Banner 打造 Compose 版本的 Banner 没有 ViewPager ? 之前写安卓的时候这都不是事,不管是自己使用 ViewPager 实现又或者是直接使用三方库,都不是什么难事;特别是使用三方库,添加一行依赖基本就没啥事了,但。。。现在使用 Compose 该怎么搞? 本来想着 C

朱江 39 Dec 7, 2022
Compose icons is a pack of libraries that provide well known Icon Packs to use in Jetpack Compose Multiplatform.

Compose icons is a pack of libraries that provide well known Icon Packs to use in Jetpack Compose Multiplatform. The library usage is inspired by Compose Material Icons.

Gabriel Souza 280 Dec 29, 2022
A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Why Not Compose! A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Md. Mahmudul Hasan Shohag 186 Jan 1, 2023
Android interval timer app using compose + compose navigation, dagger hilt, room, kotlin coroutines + flow and mvvm design pattern.

What's InTime? ⏳ InTime is an interval timer application using android jetpack components and a long running service. The purpose of this project is t

P. 46 Oct 10, 2022
Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

MindOrks 382 Jan 5, 2023
A Kotlin library to use Jetpack Compose in Android and iOS. Allow to write UI for both in Kotin. Still experimental as many compose features are not yet available.

Multiplatform Compose A Kotlin library to use Jetpack Compose in Android and iOS. Allow to write UI for both in Kotin. Still experimental as many comp

Clément Beffa 548 Jan 7, 2023
K5-compose is a sketchy port of p5.js for Jetpack Compose

k5-compose k5-compose is a sketchy port of P5.js for Jetpack Compose Desktop. This library provides you a playground to play with your sketches so you

Nikhil Chaudhari 176 Nov 22, 2022
Jetpack Compose based project, used to stress-testing compose features / integrations and explore non-trivial functionality

Project containing Jetpack Compose samples For pagination & network images it uses CATAAS. Known issues Navigation-Compose Issue with fast tapping on

Denis Rudenko 59 Dec 14, 2022
Pokedex Compose is an independent re-write of a demo application by the name of Pokedex, but written in jetpack compose.

Pokedex Compose Pokedex Compose is an independent re-write of a similar project by the name of Pokedex. I am recreating the UI but I am doing it using

Jose Patino 4 May 1, 2022
A minimal notes application in Jetpack Compose with MVVM architecture. Built with components like DataStore, Coroutines, ViewModel, LiveData, Room, Navigation-Compose, Coil, koin etc.

Paper - A Minimal Notes App A minimal notes application in Jetpack Compose with MVVM architecture. Built with components like DataStore, Coroutines, V

Akshay Sharma 139 Jan 2, 2023
Appleader707 1 Aug 9, 2022