├── pikolo
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── madrapps
│ │ │ └── pikolo
│ │ │ ├── components
│ │ │ ├── hsl
│ │ │ │ ├── HslMetrics.kt
│ │ │ │ ├── HueComponent.kt
│ │ │ │ ├── LightnessComponent.kt
│ │ │ │ └── SaturationComponent.kt
│ │ │ ├── rgb
│ │ │ │ ├── RgbMetrics.kt
│ │ │ │ ├── RedComponent.kt
│ │ │ │ ├── BlueComponent.kt
│ │ │ │ └── GreenComponent.kt
│ │ │ ├── ColorComponent.kt
│ │ │ └── ArcComponent.kt
│ │ │ ├── listeners
│ │ │ ├── SimpleColorSelectionListener.kt
│ │ │ └── OnColorSelectionListener.kt
│ │ │ ├── Metrics.kt
│ │ │ ├── ColorPicker.kt
│ │ │ ├── RGBColorPicker.kt
│ │ │ └── HSLColorPicker.kt
│ │ └── res
│ │ └── values
│ │ └── attrs.xml
├── proguard-rules.pro
├── build.gradle
└── publish.gradle
├── sample
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── drawable
│ │ │ └── bg_circle.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── madrapps
│ │ └── pickcolor
│ │ └── MainActivity.java
├── proguard-rules.pro
└── build.gradle
├── _config.yml
├── settings.gradle
├── index.html
├── preview
├── rgb-picker.gif
├── screenshot.jpg
├── arc-selectors.gif
├── preview-full.gif
└── preview-small.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── .gitignore
├── .github
└── workflows
│ └── publish.yml
├── .travis.yml
├── README.md
├── gradlew.bat
├── gradlew
└── LICENSE
/pikolo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':pikolo'
2 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
Pikolo
3 |
4 |
--------------------------------------------------------------------------------
/pikolo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/preview/rgb-picker.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/preview/rgb-picker.gif
--------------------------------------------------------------------------------
/preview/screenshot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/preview/screenshot.jpg
--------------------------------------------------------------------------------
/preview/arc-selectors.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/preview/arc-selectors.gif
--------------------------------------------------------------------------------
/preview/preview-full.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/preview/preview-full.gif
--------------------------------------------------------------------------------
/preview/preview-small.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/preview/preview-small.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PickColor
3 |
4 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.enableJetifier=true
2 | android.useAndroidX=true
3 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Madrapps/Pikolo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/bg_circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 22 04:24:07 IST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/hsl/HslMetrics.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.hsl
2 |
3 | import androidx.core.graphics.ColorUtils
4 | import com.madrapps.pikolo.Metrics
5 |
6 | internal class HslMetrics(centerX: Float = 0f, centerY: Float = 0f, color: FloatArray, density: Float) : Metrics(centerX, centerY, color, density) {
7 |
8 | override fun hue() = color[0]
9 |
10 | override fun getColor() = ColorUtils.HSLToColor(color)
11 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/listeners/SimpleColorSelectionListener.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.listeners
2 |
3 | /**
4 | * Empty implementation of [OnColorSelectionListener] so that the clients can override only the methods they care
5 | */
6 | open class SimpleColorSelectionListener : OnColorSelectionListener {
7 |
8 | override fun onColorSelected(color: Int) {}
9 |
10 | override fun onColorSelectionStart(color: Int) {}
11 |
12 | override fun onColorSelectionEnd(color: Int) {}
13 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/rgb/RgbMetrics.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.rgb
2 |
3 | import android.graphics.Color
4 | import androidx.core.graphics.ColorUtils
5 | import com.madrapps.pikolo.Metrics
6 |
7 | internal class RgbMetrics(centerX: Float = 0f, centerY: Float = 0f, color: FloatArray, density: Float) : Metrics(centerX, centerY, color, density) {
8 |
9 | override fun hue(): Float {
10 | val hsl = FloatArray(3)
11 | ColorUtils.RGBToHSL(color[0].toInt(), color[1].toInt(), color[2].toInt(), hsl)
12 | return hsl[0]
13 | }
14 |
15 | override fun getColor() = Color.rgb(color[0].toInt(), color[1].toInt(), color[2].toInt())
16 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/listeners/OnColorSelectionListener.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.listeners
2 |
3 | /**
4 | * Listener to listen to color change events
5 | */
6 | interface OnColorSelectionListener {
7 |
8 | /**
9 | * Invoked every time the color changes
10 | *
11 | * @param color the selected color
12 | */
13 | fun onColorSelected(color: Int)
14 |
15 | /**
16 | * Invoked when the color selection started
17 | *
18 | * @param color the color before the selection started
19 | */
20 | fun onColorSelectionStart(color: Int)
21 |
22 | /**
23 | * Invoked when the color selection is over
24 | *
25 | * @param color the selected color
26 | */
27 | fun onColorSelectionEnd(color: Int)
28 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/rgb/RedComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.rgb
2 |
3 | import android.graphics.Color
4 | import com.madrapps.pikolo.Metrics
5 | import com.madrapps.pikolo.Paints
6 | import com.madrapps.pikolo.components.ArcComponent
7 |
8 | internal class RedComponent(metrics: Metrics, paints: Paints, arcLength: Float, arcStartAngle: Float) : ArcComponent(metrics, paints, arcLength, arcStartAngle) {
9 |
10 | override val componentIndex: Int = 0
11 | override val range: Float = 255f
12 | override val noOfColors = 2
13 | override val colors = IntArray(noOfColors)
14 | override val colorPosition = FloatArray(noOfColors)
15 |
16 | override fun getColorArray(color: FloatArray): IntArray {
17 | colors[0] = Color.BLACK
18 | colors[1] = Color.rgb(255, 0, 0)
19 | return colors
20 | }
21 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/rgb/BlueComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.rgb
2 |
3 | import android.graphics.Color
4 | import com.madrapps.pikolo.Metrics
5 | import com.madrapps.pikolo.Paints
6 | import com.madrapps.pikolo.components.ArcComponent
7 |
8 | internal class BlueComponent(metrics: Metrics, paints: Paints, arcLength: Float, arcStartAngle: Float) : ArcComponent(metrics, paints, arcLength, arcStartAngle) {
9 |
10 | override val componentIndex: Int = 2
11 | override val range: Float = 255f
12 | override val noOfColors = 2
13 | override val colors = IntArray(noOfColors)
14 | override val colorPosition = FloatArray(noOfColors)
15 |
16 | override fun getColorArray(color: FloatArray): IntArray {
17 | colors[0] = Color.BLACK
18 | colors[1] = Color.rgb(0, 0, 255)
19 | return colors
20 | }
21 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/rgb/GreenComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.rgb
2 |
3 | import android.graphics.Color
4 | import com.madrapps.pikolo.Metrics
5 | import com.madrapps.pikolo.Paints
6 | import com.madrapps.pikolo.components.ArcComponent
7 |
8 | internal class GreenComponent(metrics: Metrics, paints: Paints, arcLength: Float, arcStartAngle: Float) : ArcComponent(metrics, paints, arcLength, arcStartAngle) {
9 |
10 | override val componentIndex: Int = 1
11 | override val range: Float = 255f
12 | override val noOfColors = 2
13 | override val colors = IntArray(noOfColors)
14 | override val colorPosition = FloatArray(noOfColors)
15 |
16 | override fun getColorArray(color: FloatArray): IntArray {
17 | colors[0] = Color.BLACK
18 | colors[1] = Color.rgb(0, 255, 0)
19 | return colors
20 | }
21 | }
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 | .idea
57 |
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/hsl/HueComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.hsl
2 |
3 | import androidx.core.graphics.ColorUtils
4 | import com.madrapps.pikolo.Metrics
5 | import com.madrapps.pikolo.Paints
6 | import com.madrapps.pikolo.components.ArcComponent
7 |
8 | internal class HueComponent(metrics: Metrics, paints: Paints, arcLength: Float, arcStartAngle: Float) : ArcComponent(metrics, paints, arcLength, arcStartAngle) {
9 |
10 | override val componentIndex = 0
11 | override val range: Float = 360f
12 | override val noOfColors = 360
13 | override val colors = IntArray(noOfColors)
14 | override val colorPosition = FloatArray(noOfColors)
15 |
16 | override fun getColorArray(color: FloatArray): IntArray {
17 | color[1] = 1f
18 | color[2] = 0.5f
19 | for (i in 0 until noOfColors) {
20 | color[componentIndex] = i.toFloat()
21 | colors[i] = ColorUtils.HSLToColor(color)
22 | }
23 | return colors
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/hsl/LightnessComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.hsl
2 |
3 | import androidx.core.graphics.ColorUtils
4 | import com.madrapps.pikolo.Metrics
5 | import com.madrapps.pikolo.Paints
6 | import com.madrapps.pikolo.components.ArcComponent
7 |
8 | internal class LightnessComponent(metrics: Metrics, paints: Paints, arcLength: Float, arcStartAngle: Float) : ArcComponent(metrics, paints, arcLength, arcStartAngle) {
9 |
10 | override val componentIndex: Int = 2
11 | override val range: Float = 1f
12 | override val noOfColors = 11 // TODO 3 should be sufficient
13 | override val colors = IntArray(noOfColors)
14 | override val colorPosition = FloatArray(noOfColors)
15 |
16 | override fun getColorArray(color: FloatArray): IntArray {
17 | for (i in 0 until noOfColors) {
18 | color[componentIndex] = i.toFloat() / (noOfColors - 1)
19 | colors[i] = ColorUtils.HSLToColor(color)
20 | }
21 | return colors
22 | }
23 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/hsl/SaturationComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components.hsl
2 |
3 | import androidx.core.graphics.ColorUtils
4 | import com.madrapps.pikolo.Metrics
5 | import com.madrapps.pikolo.Paints
6 | import com.madrapps.pikolo.components.ArcComponent
7 |
8 | internal class SaturationComponent(metrics: Metrics, paints: Paints, arcLength: Float, arcStartAngle: Float) : ArcComponent(metrics, paints, arcLength, arcStartAngle) {
9 |
10 | override val componentIndex: Int = 1
11 | override val range: Float = 1f
12 | override val noOfColors = 11 // TODO 2 should be sufficient
13 | override val colors = IntArray(noOfColors)
14 | override val colorPosition = FloatArray(noOfColors)
15 |
16 | override fun getColorArray(color: FloatArray): IntArray {
17 | for (i in 0 until noOfColors) {
18 | color[componentIndex] = i.toFloat() / (noOfColors - 1)
19 | colors[i] = ColorUtils.HSLToColor(color)
20 | }
21 | return colors
22 | }
23 | }
--------------------------------------------------------------------------------
/pikolo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/tsaravana/Me/Programming/SDK/Android/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/tsaravana/Me/Programming/SDK/Android/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | release:
5 | types: [created]
6 |
7 | jobs:
8 | build:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: Checkout
12 | uses: actions/checkout@v2
13 |
14 | - name: Setup JDK 11
15 | uses: actions/setup-java@v1
16 | with:
17 | java-version: 11
18 |
19 | - name: Check
20 | run: ./gradlew check --stacktrace
21 |
22 | - name: Build
23 | run: ./gradlew build --stacktrace
24 |
25 | - name: Publish Artifact
26 | run: ./gradlew pikolo:publishReleasePublicationToSonatypeRepository --max-workers=1 closeAndReleaseSonatypeStagingRepository --stacktrace
27 | env:
28 | OSS_USERNAME: ${{ secrets.OSS_USERNAME }}
29 | OSS_PASSWORD: ${{ secrets.OSS_PASSWORD }}
30 | OSS_STAGING_PROFILE_ID: ${{ secrets.OSS_STAGING_PROFILE_ID }}
31 | OSS_SIGNING_KEY_ID: ${{ secrets.OSS_SIGNING_KEY_ID }}
32 | OSS_SIGNING_PASSWORD: ${{ secrets.OSS_SIGNING_PASSWORD }}
33 | OSS_SIGNING_KEY: ${{ secrets.OSS_SIGNING_KEY }}
34 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | sudo: false
3 | install: true
4 |
5 | jdk: oraclejdk8
6 | android:
7 | components:
8 | - tools
9 | - platform-tools
10 |
11 | # The BuildTools version used by your project
12 | - build-tools-28.0.3
13 |
14 | # The SDK version used to compile your project
15 | - android-28
16 |
17 | env:
18 | global:
19 | # install timeout in minutes (2 minutes by default)
20 | - ADB_INSTALL_TIMEOUT=8
21 |
22 | before_install:
23 | - mkdir "$ANDROID_HOME/licenses" || true
24 | - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
25 | - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
26 |
27 | before_script:
28 | - android list target
29 |
30 | jobs:
31 | include:
32 | - stage: compile
33 | script: ./gradlew assemble
34 | - stage: deploy
35 | if: branch = master AND type != pull_request
36 | script: ./gradlew bintrayUpload
37 |
38 | cache:
39 | directories:
40 | - '$HOME/.m2/repository'
41 | - '$HOME/.gradle'
42 | - '.gradle'
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 30
5 | defaultConfig {
6 | applicationId "com.madrapps.pickcolor"
7 | minSdkVersion 15
8 | targetSdkVersion 30
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled true
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | // implementation project(':pikolo')
23 | implementation 'com.github.madrapps:pikolo:2.0.2'
24 |
25 | implementation fileTree(include: ['*.jar'], dir: 'libs')
26 | implementation 'androidx.appcompat:appcompat:1.3.1'
27 | implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
28 | testImplementation 'junit:junit:4.13.2'
29 |
30 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
31 | exclude group: 'com.android.support', module: 'support-annotations'
32 | })
33 | }
34 |
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/Metrics.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo
2 |
3 | import android.graphics.Paint
4 | import java.util.*
5 |
6 | internal abstract class Metrics(var centerX: Float = 0f, var centerY: Float = 0f, var color: FloatArray, val density: Float) {
7 | override fun equals(other: Any?): Boolean {
8 | if (this === other) return true
9 | if (javaClass != other?.javaClass) return false
10 |
11 | other as Metrics
12 |
13 | if (centerX != other.centerX) return false
14 | if (centerY != other.centerY) return false
15 | if (!Arrays.equals(color, other.color)) return false
16 | if (density != other.density) return false
17 |
18 | return true
19 | }
20 |
21 | override fun hashCode(): Int {
22 | var result = centerX.hashCode()
23 | result = 31 * result + centerY.hashCode()
24 | result = 31 * result + Arrays.hashCode(color)
25 | result = 31 * result + density.hashCode()
26 | return result
27 | }
28 |
29 | abstract fun getColor(): Int
30 |
31 | abstract fun hue(): Float
32 | }
33 |
34 | data class Paints(val shaderPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG), val indicatorPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG))
--------------------------------------------------------------------------------
/pikolo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | def groupId = "com.github.madrapps"
5 | def artifactId = "pikolo"
6 | def libVersion = "2.0.2"
7 |
8 | ext {
9 | GROUP_ID = groupId
10 | ARTIFACT_ID = artifactId
11 | VERSION = libVersion
12 | }
13 |
14 | apply from: 'publish.gradle'
15 |
16 | android {
17 | compileSdkVersion 30
18 |
19 | defaultConfig {
20 | minSdkVersion 15
21 | targetSdkVersion 30
22 | version libVersion
23 |
24 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
25 |
26 | }
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 | }
34 |
35 | dependencies {
36 | implementation fileTree(dir: 'libs', include: ['*.jar'])
37 | implementation 'androidx.appcompat:appcompat:1.3.1'
38 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
39 |
40 | testImplementation 'junit:junit:4.13.2'
41 |
42 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
43 | exclude group: 'com.android.support', module: 'support-annotations'
44 | })
45 | }
46 |
47 | repositories {
48 | google()
49 | mavenCentral()
50 | }
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pikolo
2 |
3 | An android color picker library
4 |
5 | 

6 |
7 | Download
8 | -----
9 |
10 | ```gradle
11 | repositories {
12 | mavenCentral()
13 | }
14 |
15 | dependencies {
16 | implementation 'com.github.madrapps:pikolo:2.0.2'
17 | }
18 | ```
19 |
20 | Features
21 | -----
22 | - Includes `HSLColorPicker` and `RGBColorPicker`
23 | - Full customization of the various parts of the color picker (like arc length, arc position, indicator size, color, etc...) using XML attributes
24 |
25 | Usage
26 | -----
27 | Add the `HSLColorPicker` or `RGBColorPicker` view to your layout and use it in code as below:
28 |
29 | ```java
30 | final ColorPicker colorPicker = findViewById(R.id.colorPicker);
31 | colorPicker.setColorSelectionListener(new SimpleColorSelectionListener() {
32 | @Override
33 | public void onColorSelected(int color) {
34 | // Do whatever you want with the color
35 | imageView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
36 | }
37 | });
38 | ```
39 |
40 | You can take a look at the [sample](https://github.com/Madrapps/Pikolo/tree/master/sample) app to see how
41 | the color picker can be customised. There are 3 components in both pickers. You can change their properties
42 | together or individually. For instance, `arc_length` changes the length of the arc for all 3 components, while
43 | `hue_arc_length` affects only the Hue component. Various other XML attributes are as follows:
44 |
45 | `arc_width` - width (thickness) of the components
46 | `arc_length` - length of the components
47 | `stroke_width` - width of the stroke of the components
48 | `stroke_color` - stroke color of the components
49 | `indicator_radius` - radius of the control indicator used to change color
50 | `indicator_stroke_width` - stroke width of indicator
51 | `indicator_stroke_color` - stroke color of indicator
52 | `radius_offset` - the offset of the components from the center of the picker
53 |
54 |
55 | License
56 | -----
57 |
58 | Pikolo by [Madrapps](http://madrapps.github.io/) is licensed under a [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
59 |
--------------------------------------------------------------------------------
/pikolo/publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 | apply plugin: 'signing'
3 |
4 | task androidSourcesJar(type: Jar) {
5 | archiveClassifier.set('sources')
6 | from android.sourceSets.main.java.srcDirs
7 | from android.sourceSets.main.kotlin.srcDirs
8 | }
9 |
10 | artifacts {
11 | archives androidSourcesJar
12 | }
13 |
14 | def siteUrl = 'https://github.com/Madrapps/Pikolo'
15 | def gitUrl = 'https://github.com/Madrapps/Pikolo.git'
16 |
17 | group = GROUP_ID
18 | version = VERSION
19 |
20 | afterEvaluate {
21 | publishing {
22 | publications {
23 | release(MavenPublication) {
24 |
25 | groupId GROUP_ID
26 | artifactId ARTIFACT_ID
27 | version VERSION
28 |
29 | from components.release
30 | artifact androidSourcesJar
31 |
32 | pom {
33 | name = ARTIFACT_ID
34 | description = 'An android color picker library'
35 | url = siteUrl
36 | licenses {
37 | license {
38 | name = 'The Apache Software License, Version 2.0'
39 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
40 | }
41 | }
42 | developers {
43 | developer {
44 | id = 'instrap'
45 | name = 'Madrapps'
46 | email = 'madrasappfactory@gmail.com'
47 | }
48 | developer {
49 | id = 'thsaravana'
50 | name = 'Saravana Thiyagaraj'
51 | email = 'th.saravana@gmail.com'
52 | }
53 | }
54 |
55 | scm {
56 | connection = gitUrl
57 | developerConnection = gitUrl
58 | url = siteUrl
59 | }
60 | }
61 | }
62 | }
63 | }
64 | }
65 |
66 | signing {
67 | useInMemoryPgpKeys(
68 | System.getenv("OSS_SIGNING_KEY_ID"),
69 | System.getenv("OSS_SIGNING_KEY"),
70 | System.getenv("OSS_SIGNING_PASSWORD"),
71 | )
72 | sign publishing.publications
73 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/madrapps/pickcolor/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.madrapps.pickcolor;
2 |
3 | import android.graphics.PorterDuff;
4 | import android.graphics.drawable.ColorDrawable;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.ImageButton;
9 | import android.widget.ImageView;
10 |
11 | import androidx.appcompat.app.AppCompatActivity;
12 | import androidx.core.graphics.ColorUtils;
13 |
14 | import com.madrapps.pikolo.ColorPicker;
15 | import com.madrapps.pikolo.listeners.SimpleColorSelectionListener;
16 |
17 | import java.util.Random;
18 |
19 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
20 |
21 | private ColorPicker colorPicker;
22 | private ImageView imageView;
23 | private Button randomColorButton;
24 |
25 | private final Random random = new Random();
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | imageView = findViewById(R.id.imageView);
32 |
33 | colorPicker = findViewById(R.id.colorPicker);
34 | colorPicker.setColorSelectionListener(new SimpleColorSelectionListener() {
35 | @Override
36 | public void onColorSelected(int color) {
37 | // Do whatever you want with the color
38 | imageView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
39 | }
40 | });
41 |
42 | initializeColorButtons();
43 |
44 | randomColorButton = findViewById(R.id.randomColorButton);
45 | randomColorButton.setOnClickListener(this);
46 | }
47 |
48 | private void initializeColorButtons() {
49 | findViewById(R.id.imageButton1).setOnClickListener(this);
50 | findViewById(R.id.imageButton2).setOnClickListener(this);
51 | findViewById(R.id.imageButton3).setOnClickListener(this);
52 | findViewById(R.id.imageButton4).setOnClickListener(this);
53 | findViewById(R.id.imageButton5).setOnClickListener(this);
54 | }
55 |
56 | @Override
57 | public void onClick(View v) {
58 | if (v.getId() == R.id.randomColorButton) {
59 | final int color = ColorUtils.HSLToColor(new float[]{random.nextInt(360), random.nextFloat(), random.nextFloat()});
60 | final String hexColor = String.format("#%06X", (0xFFFFFF & color));
61 | randomColorButton.setText(hexColor);
62 | randomColorButton.setBackgroundColor(color);
63 | imageView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
64 | colorPicker.setColor(color);
65 | }
66 | if (v instanceof ImageButton) {
67 | final int color = ((ColorDrawable) ((ImageButton) v).getDrawable()).getColor();
68 | imageView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
69 | colorPicker.setColor(color);
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/ColorComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components
2 |
3 | import android.graphics.Canvas
4 | import android.graphics.PointF
5 | import android.graphics.Shader
6 | import android.view.MotionEvent
7 | import android.view.MotionEvent.*
8 | import com.madrapps.pikolo.Metrics
9 | import com.madrapps.pikolo.Paints
10 | import com.madrapps.pikolo.listeners.OnColorSelectionListener
11 |
12 | internal abstract class ColorComponent(val metrics: Metrics, val paints: Paints) {
13 |
14 | var radius: Float = 0f
15 |
16 | var fillWidth: Float = 0f
17 | var strokeWidth: Float = 0f
18 | var strokeColor: Int = 0
19 |
20 | var indicatorRadius: Float = 0f
21 | var indicatorStrokeWidth: Float = 0f
22 | var indicatorStrokeColor: Int = 0
23 |
24 | var indicatorX: Float = 0f
25 | var indicatorY: Float = 0f
26 |
27 | var angle: Double = 0.0
28 |
29 | private var isTouched = false
30 | private var colorSelectionListener: OnColorSelectionListener? = null
31 |
32 | abstract fun getShader(): Shader
33 | abstract fun drawComponent(canvas: Canvas)
34 |
35 | fun onTouchEvent(event: MotionEvent): Boolean {
36 | val x = event.x
37 | val y = event.y
38 |
39 | when (event.action) {
40 | ACTION_DOWN -> {
41 | if (PointF(x, y) in this) {
42 | colorSelectionListener?.onColorSelectionStart(metrics.getColor())
43 | isTouched = true
44 | calculateAngle(x, y)
45 | updateComponent(angle)
46 | colorSelectionListener?.onColorSelected(metrics.getColor())
47 | }
48 | }
49 |
50 | ACTION_MOVE -> {
51 | if (isTouched) {
52 | calculateAngle(x, y)
53 | updateComponent(angle)
54 | colorSelectionListener?.onColorSelected(metrics.getColor())
55 | }
56 | }
57 |
58 | ACTION_UP -> {
59 | if (isTouched) colorSelectionListener?.onColorSelectionEnd(metrics.getColor())
60 | isTouched = false
61 | }
62 | }
63 |
64 | return isTouched
65 | }
66 |
67 | operator fun contains(point: PointF): Boolean {
68 | val touchRadius = indicatorRadius + indicatorRadius * 0.2
69 | return point.x in (indicatorX - touchRadius)..(indicatorX + touchRadius) && point.y in (indicatorY - touchRadius)..(indicatorY + touchRadius)
70 | }
71 |
72 | open fun calculateAngle(x1: Float, y1: Float) {
73 | val x = x1 - metrics.centerX
74 | val y = y1 - metrics.centerY
75 | val c = Math.sqrt((x * x + y * y).toDouble())
76 |
77 | angle = Math.toDegrees(Math.acos(x / c))
78 | if (y < 0) {
79 | angle = 360 - angle
80 | }
81 | }
82 |
83 | abstract fun updateComponent(angle: Double)
84 |
85 | abstract fun updateAngle(component: Float)
86 |
87 | internal fun setColorSelectionListener(listener: OnColorSelectionListener) {
88 | colorSelectionListener = listener
89 | }
90 |
91 | internal fun setRadius(outerRadius: Float, offset: Float) {
92 | radius = outerRadius - (Math.max(indicatorRadius + indicatorStrokeWidth, fillWidth)) - offset
93 | }
94 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/ColorPicker.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo
2 |
3 | import android.content.Context
4 | import android.graphics.Canvas
5 | import android.os.Parcel
6 | import android.os.Parcelable
7 | import android.util.AttributeSet
8 | import android.util.TypedValue
9 | import android.view.View
10 | import com.madrapps.pikolo.listeners.OnColorSelectionListener
11 |
12 | abstract class ColorPicker @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) {
13 |
14 | protected val paints = Paints()
15 | protected val config: Config
16 |
17 | internal abstract val color: Int
18 |
19 | abstract override fun onDraw(canvas: Canvas)
20 | abstract override fun onSizeChanged(width: Int, height: Int, oldW: Int, oldH: Int)
21 | abstract fun setColorSelectionListener(listener: OnColorSelectionListener)
22 | abstract fun setColor(color: Int)
23 |
24 | init {
25 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyleAttr, 0)
26 |
27 | val arcWidth = typedArray.getDimension(R.styleable.ColorPicker_arc_width, dp(5f))
28 | val strokeWidth = typedArray.getDimension(R.styleable.ColorPicker_stroke_width, 0f)
29 | val indicatorRadius = typedArray.getDimension(R.styleable.ColorPicker_indicator_radius, dp(15f))
30 | val indicatorStrokeWidth = typedArray.getDimension(R.styleable.ColorPicker_indicator_stroke_width, dp(2f))
31 | val strokeColor = typedArray.getColor(R.styleable.ColorPicker_stroke_color, 0)
32 | val indicatorStrokeColor = typedArray.getColor(R.styleable.ColorPicker_indicator_stroke_color, 0)
33 | val arcLength = typedArray.getFloat(R.styleable.ColorPicker_arc_length, 0f)
34 | val radiusOffset = typedArray.getDimension(R.styleable.ColorPicker_radius_offset, 0f)
35 |
36 | typedArray.recycle()
37 |
38 | config = Config(arcWidth, strokeWidth, indicatorRadius, indicatorStrokeWidth,
39 | strokeColor, indicatorStrokeColor, arcLength, radiusOffset)
40 | }
41 |
42 | protected fun dp(value: Float): Float {
43 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, resources.displayMetrics)
44 | }
45 |
46 | override fun onSaveInstanceState(): Parcelable? {
47 | val bundle = super.onSaveInstanceState()
48 | if (bundle != null) {
49 | return SavedState(bundle).apply {
50 | color = this@ColorPicker.color
51 | }
52 | }
53 | return null
54 | }
55 |
56 | override fun onRestoreInstanceState(state: Parcelable?) {
57 | if (state is SavedState) {
58 | super.onRestoreInstanceState(state.superState)
59 | setColor(state.color)
60 | } else {
61 | super.onRestoreInstanceState(state)
62 | }
63 | }
64 |
65 | internal class SavedState : BaseSavedState {
66 | var color: Int = 0
67 |
68 | constructor(bundle: Parcelable) : super(bundle)
69 |
70 | private constructor(parcel: Parcel) : super(parcel) {
71 | color = parcel.readInt()
72 | }
73 |
74 | companion object {
75 | @JvmField
76 | val CREATOR: Parcelable.Creator = object : Parcelable.Creator {
77 | override fun createFromParcel(source: Parcel): SavedState = SavedState(source)
78 | override fun newArray(size: Int): Array = arrayOfNulls(size)
79 | }
80 | }
81 |
82 | override fun describeContents() = 0
83 |
84 | override fun writeToParcel(dest: Parcel, flags: Int) {
85 | super.writeToParcel(dest, flags)
86 | dest.writeInt(color)
87 | }
88 | }
89 |
90 | data class Config(val arcWidth: Float,
91 | val strokeWidth: Float,
92 | val indicatorRadius: Float,
93 | val indicatorStrokeWidth: Float,
94 | val strokeColor: Int,
95 | val indicatorStrokeColor: Int,
96 | val arcLength: Float,
97 | val radiusOffset: Float)
98 | }
--------------------------------------------------------------------------------
/pikolo/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
58 |
59 |
73 |
74 |
85 |
86 |
97 |
98 |
109 |
110 |
121 |
122 |
133 |
134 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/RGBColorPicker.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo
2 |
3 | import android.content.Context
4 | import android.graphics.Canvas
5 | import android.graphics.Color
6 | import android.util.AttributeSet
7 | import android.view.MotionEvent
8 | import com.madrapps.pikolo.components.ColorComponent
9 | import com.madrapps.pikolo.components.rgb.BlueComponent
10 | import com.madrapps.pikolo.components.rgb.GreenComponent
11 | import com.madrapps.pikolo.components.rgb.RedComponent
12 | import com.madrapps.pikolo.components.rgb.RgbMetrics
13 | import com.madrapps.pikolo.listeners.OnColorSelectionListener
14 |
15 | open class RGBColorPicker @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ColorPicker(context, attrs, defStyleAttr) {
16 |
17 | private val metrics = RgbMetrics(color = floatArrayOf(255f, 0f, 0f), density = resources.displayMetrics.density)
18 |
19 | private val redComponent: ColorComponent
20 | private val greenComponent: ColorComponent
21 | private val blueComponent: ColorComponent
22 |
23 | private val redRadiusOffset: Float
24 | private val greenRadiusOffset: Float
25 | private val blueRadiusOffset: Float
26 |
27 | override val color: Int
28 | get() = metrics.getColor()
29 |
30 | init {
31 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.RGBColorPicker, defStyleAttr, 0)
32 |
33 | with(config) {
34 | val redArcLength = typedArray.getFloat(R.styleable.RGBColorPicker_red_arc_length, if (arcLength == 0f) 110f else arcLength)
35 | val redStartAngle = typedArray.getFloat(R.styleable.RGBColorPicker_red_start_angle, 30f)
36 | redComponent = RedComponent(metrics, paints, redArcLength, redStartAngle).also {
37 | it.fillWidth = typedArray.getDimension(R.styleable.RGBColorPicker_red_arc_width, arcWidth)
38 | it.strokeWidth = typedArray.getDimension(R.styleable.RGBColorPicker_red_stroke_width, strokeWidth)
39 | it.indicatorStrokeWidth = typedArray.getDimension(R.styleable.RGBColorPicker_red_indicator_stroke_width, indicatorStrokeWidth)
40 | it.indicatorStrokeColor = typedArray.getColor(R.styleable.RGBColorPicker_red_indicator_stroke_color, indicatorStrokeColor)
41 | it.strokeColor = typedArray.getColor(R.styleable.RGBColorPicker_red_stroke_color, strokeColor)
42 | it.indicatorRadius = typedArray.getDimension(R.styleable.RGBColorPicker_red_indicator_radius, indicatorRadius)
43 | }
44 |
45 | val greenArcLength = typedArray.getFloat(R.styleable.RGBColorPicker_green_arc_length, if (arcLength == 0f) 110f else arcLength)
46 | val greenStartAngle = typedArray.getFloat(R.styleable.RGBColorPicker_green_start_angle, 150f)
47 | greenComponent = GreenComponent(metrics, paints, greenArcLength, greenStartAngle).also {
48 | it.fillWidth = typedArray.getDimension(R.styleable.RGBColorPicker_green_arc_width, arcWidth)
49 | it.strokeWidth = typedArray.getDimension(R.styleable.RGBColorPicker_green_stroke_width, strokeWidth)
50 | it.indicatorStrokeWidth = typedArray.getDimension(R.styleable.RGBColorPicker_green_indicator_stroke_width, indicatorStrokeWidth)
51 | it.indicatorStrokeColor = typedArray.getColor(R.styleable.RGBColorPicker_green_indicator_stroke_color, indicatorStrokeColor)
52 | it.strokeColor = typedArray.getColor(R.styleable.RGBColorPicker_green_stroke_color, strokeColor)
53 | it.indicatorRadius = typedArray.getDimension(R.styleable.RGBColorPicker_green_indicator_radius, indicatorRadius)
54 | }
55 |
56 | val blueArcLength = typedArray.getFloat(R.styleable.RGBColorPicker_blue_arc_length, if (arcLength == 0f) 110f else arcLength)
57 | val blueStartAngle = typedArray.getFloat(R.styleable.RGBColorPicker_blue_start_angle, 270f)
58 |
59 | blueComponent = BlueComponent(metrics, paints, blueArcLength, blueStartAngle).also {
60 | it.fillWidth = typedArray.getDimension(R.styleable.RGBColorPicker_blue_arc_width, arcWidth)
61 | it.strokeWidth = typedArray.getDimension(R.styleable.RGBColorPicker_blue_stroke_width, config.strokeWidth)
62 | it.indicatorStrokeWidth = typedArray.getDimension(R.styleable.RGBColorPicker_blue_indicator_stroke_width, indicatorStrokeWidth)
63 | it.indicatorStrokeColor = typedArray.getColor(R.styleable.RGBColorPicker_blue_indicator_stroke_color, indicatorStrokeColor)
64 | it.strokeColor = typedArray.getColor(R.styleable.RGBColorPicker_blue_stroke_color, strokeColor)
65 | it.indicatorRadius = typedArray.getDimension(R.styleable.RGBColorPicker_blue_indicator_radius, indicatorRadius)
66 | }
67 |
68 | redRadiusOffset = typedArray.getDimension(R.styleable.RGBColorPicker_red_radius_offset, if (radiusOffset == 0f) dp(25f) else radiusOffset)
69 | greenRadiusOffset = typedArray.getDimension(R.styleable.RGBColorPicker_green_radius_offset, if (radiusOffset == 0f) dp(25f) else radiusOffset)
70 | blueRadiusOffset = typedArray.getDimension(R.styleable.RGBColorPicker_blue_radius_offset, if (radiusOffset == 0f) dp(25f) else radiusOffset)
71 | }
72 | typedArray.recycle()
73 | }
74 |
75 | override fun onDraw(canvas: Canvas) {
76 | redComponent.drawComponent(canvas)
77 | greenComponent.drawComponent(canvas)
78 | blueComponent.drawComponent(canvas)
79 | }
80 |
81 | override fun onSizeChanged(width: Int, height: Int, oldW: Int, oldH: Int) {
82 | val minimumSize = if (width > height) height else width
83 | val padding = (paddingLeft + paddingRight + paddingTop + paddingBottom) / 4f
84 | val outerRadius = minimumSize.toFloat() / 2f - padding
85 |
86 | redComponent.setRadius(outerRadius, redRadiusOffset)
87 | greenComponent.setRadius(outerRadius, greenRadiusOffset)
88 | blueComponent.setRadius(outerRadius, blueRadiusOffset)
89 |
90 | metrics.centerX = width / 2f
91 | metrics.centerY = height / 2f
92 |
93 | redComponent.updateComponent(redComponent.angle)
94 | greenComponent.updateComponent(greenComponent.angle)
95 | blueComponent.updateComponent(blueComponent.angle)
96 | }
97 |
98 | override fun onTouchEvent(event: MotionEvent): Boolean {
99 | var isTouched = true
100 | if (!redComponent.onTouchEvent(event)) {
101 | if (!greenComponent.onTouchEvent(event)) {
102 | isTouched = blueComponent.onTouchEvent(event)
103 | }
104 | }
105 | invalidate()
106 | return isTouched
107 | }
108 |
109 | override fun setColorSelectionListener(listener: OnColorSelectionListener) {
110 | redComponent.setColorSelectionListener(listener)
111 | greenComponent.setColorSelectionListener(listener)
112 | blueComponent.setColorSelectionListener(listener)
113 | }
114 |
115 | override fun setColor(color: Int) {
116 | val red = Color.red(color).toFloat()
117 | metrics.color[0] = red
118 | redComponent.updateAngle(red)
119 |
120 | val green = Color.green(color).toFloat()
121 | metrics.color[1] = green
122 | greenComponent.updateAngle(green)
123 |
124 | val blue = Color.blue(color).toFloat()
125 | metrics.color[2] = blue
126 | blueComponent.updateAngle(blue)
127 | invalidate()
128 | }
129 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/HSLColorPicker.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo
2 |
3 | import android.content.Context
4 | import android.graphics.Canvas
5 | import android.util.AttributeSet
6 | import android.view.MotionEvent
7 | import androidx.core.graphics.ColorUtils
8 | import com.madrapps.pikolo.components.ColorComponent
9 | import com.madrapps.pikolo.components.hsl.HslMetrics
10 | import com.madrapps.pikolo.components.hsl.HueComponent
11 | import com.madrapps.pikolo.components.hsl.LightnessComponent
12 | import com.madrapps.pikolo.components.hsl.SaturationComponent
13 | import com.madrapps.pikolo.listeners.OnColorSelectionListener
14 |
15 | open class HSLColorPicker @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ColorPicker(context, attrs, defStyleAttr) {
16 |
17 | private val metrics = HslMetrics(color = floatArrayOf(0f, 1f, 0.5f), density = resources.displayMetrics.density)
18 |
19 | private val hueComponent: ColorComponent
20 | private val saturationComponent: ColorComponent
21 | private val lightnessComponent: ColorComponent
22 |
23 | private val hueRadiusOffset: Float
24 | private val saturationRadiusOffset: Float
25 | private val lightnessRadiusOffset: Float
26 |
27 | override val color: Int
28 | get() = metrics.getColor()
29 |
30 | init {
31 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.HSLColorPicker, defStyleAttr, 0)
32 |
33 | with(config) {
34 | val hueArcLength = typedArray.getFloat(R.styleable.HSLColorPicker_hue_arc_length, if (arcLength == 0f) 360f else arcLength)
35 | val hueStartAngle = typedArray.getFloat(R.styleable.HSLColorPicker_hue_start_angle, 0f)
36 | hueComponent = HueComponent(metrics, paints, hueArcLength, hueStartAngle).also {
37 | it.fillWidth = typedArray.getDimension(R.styleable.HSLColorPicker_hue_arc_width, arcWidth)
38 | it.strokeWidth = typedArray.getDimension(R.styleable.HSLColorPicker_hue_stroke_width, strokeWidth)
39 | it.indicatorStrokeWidth = typedArray.getDimension(R.styleable.HSLColorPicker_hue_indicator_stroke_width, indicatorStrokeWidth)
40 | it.indicatorStrokeColor = typedArray.getColor(R.styleable.HSLColorPicker_hue_indicator_stroke_color, indicatorStrokeColor)
41 | it.strokeColor = typedArray.getColor(R.styleable.HSLColorPicker_hue_stroke_color, strokeColor)
42 | it.indicatorRadius = typedArray.getDimension(R.styleable.HSLColorPicker_hue_indicator_radius, indicatorRadius)
43 | }
44 |
45 | val saturationArcLength = typedArray.getFloat(R.styleable.HSLColorPicker_saturation_arc_length, if (arcLength == 0f) 155f else arcLength)
46 | val saturationStartAngle = typedArray.getFloat(R.styleable.HSLColorPicker_saturation_start_angle, 100f)
47 | saturationComponent = SaturationComponent(metrics, paints, saturationArcLength, saturationStartAngle).also {
48 | it.fillWidth = typedArray.getDimension(R.styleable.HSLColorPicker_saturation_arc_width, arcWidth)
49 | it.strokeWidth = typedArray.getDimension(R.styleable.HSLColorPicker_saturation_stroke_width, strokeWidth)
50 | it.indicatorStrokeWidth = typedArray.getDimension(R.styleable.HSLColorPicker_saturation_indicator_stroke_width, indicatorStrokeWidth)
51 | it.indicatorStrokeColor = typedArray.getColor(R.styleable.HSLColorPicker_saturation_indicator_stroke_color, indicatorStrokeColor)
52 | it.strokeColor = typedArray.getColor(R.styleable.HSLColorPicker_saturation_stroke_color, strokeColor)
53 | it.indicatorRadius = typedArray.getDimension(R.styleable.HSLColorPicker_saturation_indicator_radius, indicatorRadius)
54 | }
55 |
56 | val lightnessArcLength = typedArray.getFloat(R.styleable.HSLColorPicker_lightness_arc_length, if (arcLength == 0f) 155f else arcLength)
57 | val lightnessStartAngle = typedArray.getFloat(R.styleable.HSLColorPicker_lightness_start_angle, 280f)
58 | lightnessComponent = LightnessComponent(metrics, paints, lightnessArcLength, lightnessStartAngle).also {
59 | it.fillWidth = typedArray.getDimension(R.styleable.HSLColorPicker_lightness_arc_width, arcWidth)
60 | it.strokeWidth = typedArray.getDimension(R.styleable.HSLColorPicker_lightness_stroke_width, strokeWidth)
61 | it.indicatorStrokeWidth = typedArray.getDimension(R.styleable.HSLColorPicker_lightness_indicator_stroke_width, indicatorStrokeWidth)
62 | it.indicatorStrokeColor = typedArray.getColor(R.styleable.HSLColorPicker_lightness_indicator_stroke_color, indicatorStrokeColor)
63 | it.strokeColor = typedArray.getColor(R.styleable.HSLColorPicker_lightness_stroke_color, strokeColor)
64 | it.indicatorRadius = typedArray.getDimension(R.styleable.HSLColorPicker_lightness_indicator_radius, indicatorRadius)
65 | }
66 |
67 | hueRadiusOffset = typedArray.getDimension(R.styleable.HSLColorPicker_hue_radius_offset, if (radiusOffset == 0f) dp(1f) else radiusOffset)
68 | saturationRadiusOffset = typedArray.getDimension(R.styleable.HSLColorPicker_saturation_radius_offset, if (radiusOffset == 0f) dp(25f) else radiusOffset)
69 | lightnessRadiusOffset = typedArray.getDimension(R.styleable.HSLColorPicker_lightness_radius_offset, if (radiusOffset == 0f) dp(25f) else radiusOffset)
70 | }
71 | typedArray.recycle()
72 | }
73 |
74 | override fun onDraw(canvas: Canvas) {
75 | hueComponent.drawComponent(canvas)
76 | saturationComponent.drawComponent(canvas)
77 | lightnessComponent.drawComponent(canvas)
78 | }
79 |
80 | override fun onSizeChanged(width: Int, height: Int, oldW: Int, oldH: Int) {
81 | val minimumSize = if (width > height) height else width
82 | val padding = (paddingLeft + paddingRight + paddingTop + paddingBottom) / 4f
83 | val outerRadius = minimumSize.toFloat() / 2f - padding
84 |
85 | hueComponent.setRadius(outerRadius, hueRadiusOffset)
86 | saturationComponent.setRadius(outerRadius, saturationRadiusOffset)
87 | lightnessComponent.setRadius(outerRadius, lightnessRadiusOffset)
88 |
89 | metrics.centerX = width / 2f
90 | metrics.centerY = height / 2f
91 |
92 | hueComponent.updateComponent(hueComponent.angle)
93 | saturationComponent.updateComponent(saturationComponent.angle)
94 | lightnessComponent.updateComponent(lightnessComponent.angle)
95 | }
96 |
97 | override fun onTouchEvent(event: MotionEvent): Boolean {
98 | var isTouched = true
99 | if (!hueComponent.onTouchEvent(event)) {
100 | if (!saturationComponent.onTouchEvent(event)) {
101 | isTouched = lightnessComponent.onTouchEvent(event)
102 | }
103 | }
104 | invalidate()
105 | return isTouched
106 | }
107 |
108 | override fun setColorSelectionListener(listener: OnColorSelectionListener) {
109 | hueComponent.setColorSelectionListener(listener)
110 | saturationComponent.setColorSelectionListener(listener)
111 | lightnessComponent.setColorSelectionListener(listener)
112 | }
113 |
114 | override fun setColor(color: Int) {
115 | with(metrics) {
116 | ColorUtils.colorToHSL(color, this.color)
117 | hueComponent.updateAngle(this.color[0])
118 | saturationComponent.updateAngle(this.color[1])
119 | lightnessComponent.updateAngle(this.color[2])
120 | }
121 | invalidate()
122 | }
123 | }
--------------------------------------------------------------------------------
/pikolo/src/main/java/com/madrapps/pikolo/components/ArcComponent.kt:
--------------------------------------------------------------------------------
1 | package com.madrapps.pikolo.components
2 |
3 | import android.graphics.*
4 | import android.graphics.Color.*
5 | import android.graphics.Paint.Cap.ROUND
6 | import android.graphics.Paint.Style.FILL
7 | import android.graphics.Paint.Style.STROKE
8 | import androidx.core.graphics.ColorUtils
9 | import com.madrapps.pikolo.Metrics
10 | import com.madrapps.pikolo.Paints
11 |
12 | internal abstract class ArcComponent(
13 | metrics: Metrics,
14 | paints: Paints,
15 | private val arcLength: Float,
16 | private val arcStartAngle: Float
17 | ) : ColorComponent(metrics, paints) {
18 |
19 | protected abstract val componentIndex: Int
20 | abstract val noOfColors: Int
21 | internal abstract val colors: IntArray
22 | internal abstract val colorPosition: FloatArray
23 |
24 | private val matrix = Matrix()
25 | private lateinit var shader: Shader
26 | private var innerCircleArcReference: RectF? = null
27 | private val borderColor = floatArrayOf(0f, 0.8f, 1f)
28 |
29 | /**
30 | * This is the max value of the component. For now the min value is taken as 0
31 | */
32 | abstract val range: Float
33 |
34 | private val arcEndAngle: Float
35 | get() {
36 | val end = arcStartAngle + arcLength
37 | return if (end > 360f) end - 360f else end
38 | }
39 |
40 | init {
41 | angle = (arcStartAngle + arcLength / 2f).toDouble()
42 | }
43 |
44 | override fun drawComponent(canvas: Canvas) {
45 | drawArc(canvas)
46 | drawIndicator(canvas)
47 | }
48 |
49 | internal open fun drawArc(canvas: Canvas) {
50 | val shaderPaint = paints.shaderPaint
51 | shaderPaint.style = STROKE
52 | shaderPaint.strokeCap = ROUND
53 |
54 | if (innerCircleArcReference == null) {
55 | innerCircleArcReference = RectF(metrics.centerX - radius, metrics.centerY - radius, metrics.centerX + radius, metrics.centerY + radius)
56 | }
57 | innerCircleArcReference?.let {
58 | if (strokeWidth > 0) {
59 | shaderPaint.shader = null
60 | shaderPaint.color = if (strokeColor == 0) WHITE else strokeColor
61 | shaderPaint.strokeWidth = fillWidth + strokeWidth * 2
62 | canvas.drawArc(it, arcStartAngle, arcLength, false, shaderPaint)
63 | }
64 |
65 | shaderPaint.strokeWidth = fillWidth
66 | shaderPaint.shader = getShader()
67 | canvas.drawArc(it, arcStartAngle, arcLength, false, shaderPaint)
68 | }
69 | }
70 |
71 | internal open fun drawIndicator(canvas: Canvas) {
72 | indicatorX = (metrics.centerX + radius * Math.cos(Math.toRadians(angle))).toFloat()
73 | indicatorY = (metrics.centerY + radius * Math.sin(Math.toRadians(angle))).toFloat()
74 |
75 | val indicatorPaint = paints.indicatorPaint
76 | indicatorPaint.style = FILL
77 |
78 | val color = metrics.getColor()
79 | indicatorPaint.color = color
80 | canvas.drawCircle(indicatorX, indicatorY, indicatorRadius, indicatorPaint)
81 |
82 | if (indicatorStrokeWidth > 0) {
83 | indicatorPaint.color = getBorderColor(color)
84 | indicatorPaint.style = STROKE
85 | indicatorPaint.strokeWidth = indicatorStrokeWidth
86 | canvas.drawCircle(indicatorX, indicatorY, indicatorRadius, indicatorPaint)
87 | }
88 | }
89 |
90 | private fun getBorderColor(color: Int): Int {
91 | if (indicatorStrokeColor != 0) {
92 | return indicatorStrokeColor
93 | }
94 | borderColor[0] = metrics.hue()
95 | val contrastW = ColorUtils.calculateContrast(color, WHITE)
96 | val contrastB = ColorUtils.calculateContrast(color, BLACK)
97 | val contrastDifference = contrastB - contrastW
98 | borderColor[2] = when {
99 | contrastDifference > 16 -> 0f
100 | contrastDifference > 10 -> 0.1f
101 | contrastDifference > 6 -> 0.2f
102 | contrastDifference > 4 -> 0.3f
103 | contrastDifference > 2 -> 0.4f
104 | contrastDifference > 0 -> 0.5f
105 | contrastDifference > -2 -> 0.6f
106 | contrastDifference > -4 -> 0.7f
107 | contrastDifference > -8 -> 0.8f
108 | contrastDifference > -12 -> 0.9f
109 | else -> 1f
110 | }
111 | return ColorUtils.HSLToColor(borderColor)
112 | }
113 |
114 | override fun getShader(): Shader {
115 | with(metrics) {
116 | getColorArray(color.copyOf())
117 | getColorPositionArray()
118 | shader = SweepGradient(centerX, centerY, colors, colorPosition)
119 | // We need a margin of rotation due to the Paint.Cap.Round
120 | matrix.setRotate(arcStartAngle - (fillWidth / 3f / density), centerX, centerY)
121 | shader.setLocalMatrix(matrix)
122 | }
123 |
124 | return shader
125 | }
126 |
127 | internal abstract fun getColorArray(color: FloatArray): IntArray
128 |
129 | private fun getColorPositionArray(): FloatArray {
130 | for (i in 0 until noOfColors) {
131 | colorPosition[i] = i * (arcLength / (noOfColors - 1)) / 360f
132 | }
133 | return colorPosition
134 | }
135 |
136 | override fun calculateAngle(x1: Float, y1: Float) {
137 | super.calculateAngle(x1, y1)
138 | // Don't let the indicator go outside the arc
139 | // limit the indicator between arcStartAngle and arcEndAngle
140 | val associatedArcLength = 360f - arcLength
141 | val middleOfAssociatedArc = arcEndAngle + associatedArcLength / 2f
142 | if (arcEndAngle < arcStartAngle) {
143 | calculateAngleInContinuousRange(middleOfAssociatedArc)
144 | } else if (arcEndAngle > arcStartAngle) {
145 | calculateAngleInNonContinuousRange(middleOfAssociatedArc)
146 | }
147 | }
148 |
149 | /**
150 | * This would be the case when [arcStartAngle]=285 and [arcEndAngle]=75, so that the arc has the 0 degree crossover. This means that the
151 | * associated arc (360 - [arcLength]) is a continuous range. When the angle is in this range, we need to either set it to the [arcStartAngle]
152 | * or the [arcEndAngle]
153 | *
154 | * @param middle the middle point (in angle) of the associated arc
155 | */
156 | private fun calculateAngleInContinuousRange(middle: Float) {
157 | when (angle) {
158 | in arcEndAngle..middle -> angle = arcEndAngle.toDouble()
159 | in middle..arcStartAngle -> angle = arcStartAngle.toDouble()
160 | }
161 | }
162 |
163 | /**
164 | * This is the case where the arc is a continuous range, i.e, the 0 crossover occurs in the associated arc. This can happen in two ways.
165 | *
166 | * 1. The [middle] point can be before the 0 degree. Eg. [arcStartAngle]=10 and [arcEndAngle]=120
167 | * 2. The [middle] point can be after the 0 degree. Eg. [arcStartAngle]=100 and [arcEndAngle]=350
168 | *
169 | * @param middle the middle point (in angle) of the associated arc
170 | */
171 | private fun calculateAngleInNonContinuousRange(middle: Float) {
172 | if (middle > 360f) {
173 | val correctedMiddle = middle - 360f
174 | when (angle) {
175 | in arcEndAngle..360f, in 0f..correctedMiddle -> angle = arcEndAngle.toDouble()
176 | in correctedMiddle..arcStartAngle -> angle = arcStartAngle.toDouble()
177 | }
178 | } else {
179 | when (angle) {
180 | in arcEndAngle..middle -> angle = arcEndAngle.toDouble()
181 | in middle..360f, in 0f..arcStartAngle -> angle = arcStartAngle.toDouble()
182 | }
183 | }
184 | }
185 |
186 | override fun updateComponent(angle: Double) {
187 | var relativeAngle = angle
188 | if (angle < arcStartAngle) {
189 | relativeAngle += 360f
190 | }
191 |
192 | val baseAngle = relativeAngle - arcStartAngle
193 | val component = (baseAngle / arcLength) * range
194 |
195 | metrics.color[componentIndex] = component.toFloat()
196 | }
197 |
198 | override fun updateAngle(component: Float) {
199 | val baseAngle = component / range * arcLength
200 | val relativeAngle = baseAngle + arcStartAngle
201 |
202 | angle = relativeAngle.toDouble()
203 | }
204 |
205 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2017 Madrapps
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------