项目作者: side-codes

项目描述 :
Color picker library for Android
高级语言: Kotlin
项目地址: git://github.com/side-codes/andColorPicker.git
创建时间: 2020-02-26T00:26:33Z
项目社区:https://github.com/side-codes/andColorPicker

开源协议:Apache License 2.0

下载


andColorPicker — Color Picker library for Android

:avocado: Handy, :snake: flexible, and :zap: lightning-fast Android color picker views and utilities.

andColorPicker logo

:pill: Features

  • Clean, easy-to-use components and API
  • High performance
  • Material styling in mind
  • Standard Android SDK view family
  • Wide color models support
  • Tooling and utilities
  • Alpha channel support
  • Cutting edge tech stack
  • Active development and support

:hammer: Setup

Gradle dependency:

  1. implementation "codes.side:andcolorpicker:0.6.2"

:art: Picker types

HSL (hue, saturation, lightness)

  • Add color model description

Layout XML Snippet

Basic HSL components:

  1. <codes.side.andcolorpicker.hsl.HSLColorPickerSeekBar
  2. android:id="@+id/hueSeekBar"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. app:hslColoringMode="pure"
  6. app:hslMode="hue" ></codes.side.andcolorpicker.hsl.HSLColorPickerSeekBar>

Supported hslMode values:

  • hue (default)
  • saturation
  • lightness

Supported hslColoringMode values:

  • pure (default)
  • output

Alpha component:

  1. <codes.side.andcolorpicker.alpha.HSLAlphaColorPickerSeekBar
  2. android:id="@+id/alphaSeekBar"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content" ></codes.side.andcolorpicker.alpha.HSLAlphaColorPickerSeekBar>

Kotlin Snippet

  1. // Configure color model programmatically
  2. hueSeekBar.mode = Mode.MODE_HUE // Mode.MODE_SATURATION, Mode.MODE_LIGHTNESS
  3. // Configure coloring mode programmatically
  4. hueSeekBar.coloringMode = ColoringMode.PURE_COLOR // ColoringMode.OUTPUT_COLOR
  5. // Group pickers with PickerGroup to automatically synchronize color across them
  6. val group = PickerGroup<IntegerHSLColor>().also {
  7. it.registerPickers(
  8. hueSeekBar,
  9. saturationSeekBar,
  10. lightnessSeekBar,
  11. alphaSeekBar
  12. )
  13. }
  14. // Get current color immediately
  15. Log.d(
  16. TAG,
  17. "Current color is ${hueSeekBar.pickedColor}"
  18. )
  19. // Listen individual pickers or groups for changes
  20. group.addListener(
  21. object : HSLColorPickerSeekBar.DefaultOnColorPickListener() {
  22. override fun onColorChanged(
  23. picker: ColorSeekBar<IntegerHSLColor>,
  24. color: IntegerHSLColor,
  25. value: Int
  26. ) {
  27. Log.d(
  28. TAG,
  29. "$color picked"
  30. )
  31. swatchView.setSwatchColor(
  32. color
  33. )
  34. }
  35. }
  36. )
  37. // Set desired color programmatically
  38. group.setColor(
  39. IntegerHSLColor().also {
  40. it.setFromColorInt(
  41. Color.rgb(
  42. 28,
  43. 84,
  44. 187
  45. )
  46. )
  47. }
  48. )
  49. // Set color components programmatically
  50. hueSeekBar.progress = 50

RGB (red, green, blue)

Properties

  • View name: RGBColorPickerSeekBar
  • app:rgbMode for RGB component selection

LAB

Properties

  • View name: LABColorPickerSeekBar
  • app:labMode for LAB component selection

CMYK (cyan, magenta, yellow, key)

Properties

  • View name: CMYKColorPickerSeekBar
  • app:cmykMode for CMYK component selection
  • app:cmykColoringMode for coloring mode selection

Supported cmykMode values:

  • cyan (default)
  • magenta
  • yellow
  • black

Supported cmykColoringMode values:

  • pure (default)
  • output

Swatches

SwatchView component:

  1. <codes.side.andcolorpicker.view.swatch.SwatchView
  2. android:id="@+id/swatchView"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content" ></codes.side.andcolorpicker.view.swatch.SwatchView>

Kotlin Snippet:

  1. swatchView.setSwatchPatternTint(
  2. Color.LTGRAY
  3. )
  4. swatchView.setSwatchColor(
  5. IntegerHSLColor().also {
  6. it.setFromColorInt(
  7. ColorUtils.setAlphaComponent(
  8. Color.MAGENTA,
  9. 128
  10. )
  11. )
  12. }
  13. )

:memo: License

  1. Copyright 2020 Illia Achour
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.