├── .gitignore
├── .idea
├── bytedance_as_plugin.xml
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── compiler.xml
├── dbnavigator.xml
├── encodings.xml
├── gradle.xml
├── jarRepositories.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── LICENSE.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── horizon
│ │ └── colorpickerdemo
│ │ ├── MainActivity.kt
│ │ └── ui
│ │ ├── ColorPickerActivity.kt
│ │ ├── CustomColorFragment.kt
│ │ ├── FancyColorPickerActivity.kt
│ │ └── PickColorFragment.kt
│ └── res
│ ├── anim
│ ├── slide_left_in.xml
│ ├── slide_left_out.xml
│ ├── slide_right_in.xml
│ └── slide_right_out.xml
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ ├── activity_color_picker.xml
│ ├── activity_fancy_color_picker.xml
│ ├── activity_main.xml
│ ├── fragment_color_picker.xml
│ └── fragment_custom_color.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── values-zh
│ └── strings.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── colorpicker
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── horizon
│ │ └── colorpicker
│ │ ├── palette
│ │ ├── ColorPalette.java
│ │ └── ColorSquare.java
│ │ └── seekbar
│ │ ├── AbstractSeekBar.java
│ │ ├── BrightnessBar.java
│ │ ├── ColorBar.java
│ │ ├── HueBar.java
│ │ ├── NormalSeekBar.java
│ │ ├── SaturationBar.java
│ │ ├── Utils.java
│ │ └── listener
│ │ ├── OnStopTrackingListener.java
│ │ └── OnValueChangeListener.java
│ └── res
│ ├── drawable-xhdpi
│ └── icon_check.png
│ ├── drawable-xxhdpi
│ ├── custom_color.png
│ └── seekbar_pointer.png
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ └── dimens.xml
├── fancypicker
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── horizon
│ │ └── fancypicker
│ │ ├── ColorPicker.java
│ │ └── ColorPickerDialog.java
│ └── res
│ ├── layout
│ └── dialog_color_picker.xml
│ ├── values-zh
│ └── strings.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ └── strings.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── image
├── colorpicker.gif
└── fancypicker.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/bytedance_as_plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/dbnavigator.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 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Horizon
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## ColorPicker
3 |
4 | This project has implement two kinds of color pickers.
5 |
6 |
7 | ### Simple case
8 |
9 | 
10 |
11 |
12 | ### Fancy case
13 |
14 | 
15 |
16 |
17 | ## Link
18 | https://juejin.cn/post/6844903908364697613
19 |
20 | ## License
21 | See the [LICENSE](LICENSE.md) file for license rights and limitations.
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdk 32
9 |
10 | defaultConfig {
11 | applicationId "com.horizon.colorpickerdemo"
12 | minSdk 21
13 | targetSdk 32
14 | versionCode 1
15 | versionName "1.0"
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | implementation 'androidx.core:core-ktx:1.8.0'
33 | implementation 'androidx.appcompat:appcompat:1.4.2'
34 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
35 |
36 | implementation project(":colorpicker")
37 | implementation project(":fancypicker")
38 | }
39 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/horizon/colorpickerdemo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpickerdemo
2 |
3 | import android.content.Intent
4 | import androidx.appcompat.app.AppCompatActivity
5 | import android.os.Bundle
6 |
7 | import com.horizon.colorpickerdemo.ui.ColorPickerActivity
8 | import com.horizon.colorpickerdemo.ui.FancyColorPickerActivity
9 | import kotlinx.android.synthetic.main.activity_main.*
10 |
11 | class MainActivity : AppCompatActivity() {
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.activity_main)
16 |
17 | pickColorBtn.setOnClickListener{
18 | startActivity(Intent(this, ColorPickerActivity::class.java))
19 | }
20 |
21 | pickColorBtn2.setOnClickListener {
22 | startActivity(Intent(this, FancyColorPickerActivity::class.java))
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/horizon/colorpickerdemo/ui/ColorPickerActivity.kt:
--------------------------------------------------------------------------------
1 |
2 | package com.horizon.colorpickerdemo.ui
3 |
4 | import android.graphics.Color
5 | import android.os.Bundle
6 | import androidx.appcompat.app.AppCompatActivity
7 | import kotlinx.android.synthetic.main.activity_color_picker.*
8 | import com.horizon.colorpickerdemo.R
9 |
10 | class ColorPickerActivity : AppCompatActivity() {
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | setContentView(R.layout.activity_color_picker)
14 |
15 | val initColor = Color.RED
16 | val square = colorSquare
17 | square.setBackgroundColor(initColor)
18 |
19 | val pickColorFragment = PickColorFragment.newInstance(initColor).apply {
20 | colorDispatcher = { color ->
21 | square.setBackgroundColor(color)
22 | }
23 | popCustomColor = {
24 | switchCustomColorPicker(this)
25 | }
26 | }
27 |
28 | supportFragmentManager.beginTransaction()
29 | .add(R.id.container, pickColorFragment, "PickColorFragment")
30 | .commit()
31 | }
32 |
33 | private fun switchCustomColorPicker(fragment: PickColorFragment) {
34 | supportFragmentManager.beginTransaction()
35 | .setCustomAnimations(
36 | R.anim.slide_right_in,
37 | R.anim.slide_left_out,
38 | R.anim.slide_left_in,
39 | R.anim.slide_right_out
40 | )
41 | .add(R.id.container, fragment.newCustomColorFragment(), "CustomColorFragment")
42 | .addToBackStack(null)
43 | .hide(fragment)
44 | .commit()
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/horizon/colorpickerdemo/ui/CustomColorFragment.kt:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.horizon.colorpickerdemo.ui
4 |
5 | import android.graphics.Color
6 | import android.os.Bundle
7 | import androidx.fragment.app.Fragment
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.view.ViewGroup
11 | import com.horizon.colorpickerdemo.R
12 | import kotlinx.android.synthetic.main.fragment_custom_color.*
13 |
14 |
15 | class CustomColorFragment : Fragment() {
16 | var colorChangeListener :((Int) -> Unit) ?= null
17 |
18 | private var alpha : Int = 0
19 |
20 | private val hsv = FloatArray(3)
21 |
22 | companion object {
23 | @JvmStatic
24 | fun newInstance(color: Int, listener :((Int) -> Unit)) = CustomColorFragment().apply {
25 | val bundle = Bundle()
26 | bundle.putInt ("color", color)
27 | arguments = bundle
28 | colorChangeListener = listener
29 | }
30 | }
31 |
32 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
33 | return inflater.inflate(R.layout.fragment_custom_color, container, false)
34 | }
35 |
36 | override fun onViewStateRestored(savedInstanceState: Bundle?) {
37 | super.onViewStateRestored(savedInstanceState)
38 | var color = Color.RED
39 | arguments?.run { color = getInt("color") }
40 | alpha = color and 0xFF000000.toInt()
41 |
42 | Color.colorToHSV(color, hsv)
43 |
44 | hueBar.setValue(hsv[0] / 360F)
45 | saturationBar.setColor(hsv)
46 | brightnessBar.setColor(hsv)
47 |
48 | hueBar.setOnValueChangeListener {
49 | hsv[0] = it * 360F
50 | updateColor()
51 | }
52 |
53 | saturationBar.setOnValueChangeListener {
54 | hsv[1] = it
55 | updateColor()
56 | }
57 |
58 | brightnessBar.setOnValueChangeListener {
59 | hsv[2] = it
60 | updateColor()
61 | }
62 | }
63 |
64 | private fun updateColor(){
65 | saturationBar.setColor(hsv)
66 | brightnessBar.setColor(hsv)
67 | colorChangeListener?.invoke(alpha or (Color.HSVToColor(hsv) and 0xFFFFFF))
68 | }
69 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/horizon/colorpickerdemo/ui/FancyColorPickerActivity.kt:
--------------------------------------------------------------------------------
1 |
2 | package com.horizon.colorpickerdemo.ui
3 |
4 | import android.graphics.Color
5 | import android.os.Bundle
6 | import androidx.appcompat.app.AppCompatActivity
7 | import com.horizon.colorpickerdemo.R
8 | import com.horizon.fancypicker.ColorPickerDialog
9 | import kotlinx.android.synthetic.main.activity_color_picker.*
10 |
11 | class FancyColorPickerActivity : AppCompatActivity() {
12 |
13 | private var mColor = Color.RED
14 |
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_fancy_color_picker)
18 |
19 | colorSquare.setBackgroundColor(mColor)
20 | colorSquare.setOnClickListener {
21 | ColorPickerDialog.Builder(this@FancyColorPickerActivity, mColor)
22 | .setOnColorPickedListener { color ->
23 | mColor = color
24 | colorSquare.setBackgroundColor(mColor)
25 | }
26 | .build()
27 | .show()
28 | }
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/horizon/colorpickerdemo/ui/PickColorFragment.kt:
--------------------------------------------------------------------------------
1 |
2 | package com.horizon.colorpickerdemo.ui
3 |
4 | import android.os.Bundle
5 | import androidx.fragment.app.Fragment
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import com.horizon.colorpickerdemo.R
10 | import com.horizon.colorpicker.seekbar.Utils
11 | import kotlinx.android.synthetic.main.fragment_color_picker.*
12 |
13 |
14 | class PickColorFragment : Fragment(){
15 | var colorDispatcher: ((Int) -> Unit)? = null
16 | var popCustomColor : (() -> Unit)? = null
17 |
18 | private var resultColor: Int = 0xFF000000.toInt()
19 |
20 | private val colorChangeListener :((Int) -> Unit) = { color ->
21 | resultColor = color
22 | colorDispatcher?.invoke(color)
23 | palette?.selectedColor(color)
24 | }
25 |
26 | companion object {
27 | fun newInstance(color: Int) = PickColorFragment().apply {
28 | val bundle = Bundle()
29 | bundle.putInt ("color", color)
30 | arguments = bundle
31 | }
32 | }
33 |
34 | fun newCustomColorFragment() : CustomColorFragment{
35 | return CustomColorFragment.newInstance(resultColor, colorChangeListener)
36 | }
37 |
38 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
39 | return inflater.inflate(R.layout.fragment_color_picker, container, false)
40 | }
41 |
42 | override fun onViewStateRestored(savedInstanceState: Bundle?) {
43 | super.onViewStateRestored(savedInstanceState)
44 | arguments?.run { resultColor = getInt("color") }
45 |
46 | palette.selectedColor(resultColor)
47 |
48 | palette.setOnColorSelectListener { color->
49 | resultColor = (resultColor and 0xFF000000.toInt()) or (color and 0xFFFFFF)
50 | colorDispatcher?.invoke(resultColor)
51 | }
52 |
53 | palette.setOnCustomColorListener {
54 | popCustomFragment()
55 | }
56 |
57 | alphaBar.setValue(1f - (resultColor ushr 24) / 255F)
58 | alphaBar.setOnValueChangeListener { transparency ->
59 | val alpha = Utils.roundF((1f - transparency) * 255) and 0xFF
60 | resultColor = (alpha shl 24) or (resultColor and 0xFFFFFF)
61 | colorDispatcher?.invoke(resultColor)
62 | }
63 | }
64 |
65 | private fun popCustomFragment() {
66 | popCustomColor?.invoke()
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_left_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_left_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_color_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fancy_color_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
22 |
23 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_color_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
22 |
23 |
33 |
34 |
45 |
46 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_custom_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
32 |
33 |
44 |
45 |
54 |
55 |
65 |
66 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ColorPicker
3 | 色相
4 | 纯度
5 | 明度
6 | 颜色
7 | 透明度
8 | ColorPicker
9 | FancyColorPicker
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 |
9 | #FFFFFF
10 | #333333
11 | #D3D3D3
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 45dp
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ColorPicker
3 | Hue
4 | saturation
5 | brightness
6 | color
7 | alpha
8 | ColorPicker
9 | FancyColorPicker
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | plugins {
4 | id 'com.android.application' version '7.2.1' apply false
5 | id 'com.android.library' version '7.2.1' apply false
6 | id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
7 | }
8 |
9 | task clean(type: Delete) {
10 | delete rootProject.buildDir
11 | }
12 |
--------------------------------------------------------------------------------
/colorpicker/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/colorpicker/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | }
4 |
5 | android {
6 | compileSdk 32
7 | defaultConfig {
8 | minSdk 21
9 | targetSdk 32
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_8
22 | targetCompatibility JavaVersion.VERSION_1_8
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation 'androidx.appcompat:appcompat:1.4.2'
29 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
30 | }
31 |
--------------------------------------------------------------------------------
/colorpicker/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/colorpicker/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/palette/ColorPalette.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.palette;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Color;
8 | import androidx.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 | import android.view.View.OnClickListener;
12 | import android.widget.HorizontalScrollView;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 |
16 | import com.horizon.colorpicker.R;
17 | import com.horizon.colorpicker.seekbar.Utils;
18 |
19 |
20 | public class ColorPalette extends HorizontalScrollView implements OnClickListener {
21 | // TODO collect color
22 | private static final int[] COLORS = {
23 | 0xFFFFFFFF,
24 | 0xFF000000,
25 | 0xFF9C27B0,
26 | 0xFF673AB7,
27 | 0xFF3FB1F5,
28 | 0xFF2196F3,
29 | 0xFF00BCD4,
30 | 0xFFFFA000,
31 | 0xFFB8C500,
32 | 0xFF8BC34A,
33 | 0xFF4CAF50,
34 | 0xFF009688,
35 | 0xFFF57C00,
36 | 0xFFF44336,
37 | 0xFFE91E63,
38 | 0xFFC2185B,
39 | };
40 |
41 | private OnCustomColorListener mOnCustomColorListener;
42 | private OnColorSelectListener mOnColorSelectListener;
43 |
44 | private ColorSquare mLastCheckedView;
45 | private Context mContext;
46 | private int mDimension;
47 | private int mMarginRight;
48 | private Bitmap mPickBitmap;
49 |
50 | public ColorPalette(Context context) {
51 | this(context, null, 0);
52 | }
53 |
54 | public ColorPalette(Context context, @Nullable AttributeSet attrs) {
55 | this(context, attrs, 0);
56 | }
57 |
58 | public ColorPalette(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
59 | super(context, attrs, defStyleAttr);
60 | init(context);
61 | }
62 |
63 | public void setOnCustomColorListener(OnCustomColorListener customColorListener) {
64 | mOnCustomColorListener = customColorListener;
65 | }
66 |
67 | public void setOnColorSelectListener(OnColorSelectListener colorSelectListener) {
68 | mOnColorSelectListener = colorSelectListener;
69 | }
70 |
71 | private void init(Context context) {
72 | mContext = context;
73 | Resources res = context.getResources();
74 |
75 | mPickBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_check);
76 |
77 | setHorizontalScrollBarEnabled(false);
78 | setOverScrollMode(OVER_SCROLL_NEVER);
79 |
80 | mDimension = res.getDimensionPixelSize(R.dimen.square_width);
81 |
82 | mMarginRight = Utils.dip2px(context, 8);
83 | int lastMarginRight = Utils.dip2px(context, 16);
84 |
85 | LinearLayout container = new LinearLayout(context);
86 | container.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
87 | LinearLayout.LayoutParams.MATCH_PARENT));
88 | container.setOrientation(LinearLayout.HORIZONTAL);
89 | addView(container);
90 |
91 | for (int color : COLORS) {
92 | container.addView(makeColorView(color));
93 | }
94 |
95 | int imageDimension = mDimension - res.getDimensionPixelSize(R.dimen.check_padding);
96 | ImageView customColorView = new ImageView(context);
97 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(imageDimension, imageDimension);
98 | lp.setMargins(0, 0, lastMarginRight, 0);
99 | customColorView.setLayoutParams(lp);
100 | customColorView.setImageResource(R.drawable.custom_color);
101 | customColorView.setOnClickListener(this);
102 | container.addView(customColorView);
103 | }
104 |
105 | private View makeColorView(int color) {
106 | ColorSquare colorView = new ColorSquare(mContext, mPickBitmap);
107 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mDimension, mDimension);
108 | lp.setMargins(0, 0, mMarginRight, 0);
109 | colorView.setLayoutParams(lp);
110 | colorView.setColor(color);
111 | if (color == Color.WHITE) {
112 | colorView.setStroke();
113 | }
114 | colorView.setOnClickListener(this);
115 | return colorView;
116 | }
117 |
118 | private void checkSquare(ColorSquare square) {
119 | square.setChecked(true);
120 | if (mLastCheckedView != null && square != mLastCheckedView) {
121 | mLastCheckedView.setChecked(false);
122 | }
123 | mLastCheckedView = square;
124 | }
125 |
126 | public void selectedColor(int color) {
127 | LinearLayout linearLayout = (LinearLayout) getChildAt(0);
128 | for (int i = 0; i < linearLayout.getChildCount() - 1; i++) {
129 | ColorSquare square = (ColorSquare) linearLayout.getChildAt(i);
130 | int item = square.getColor();
131 | if ((color & 0xFFFFFF) == (item & 0xFFFFFF)) {
132 | square.setChecked(true);
133 | } else {
134 | square.setChecked(false);
135 | }
136 | }
137 | }
138 |
139 | @Override
140 | public void onClick(View v) {
141 | if (v instanceof ColorSquare) {
142 | ColorSquare colorSquare = (ColorSquare) v;
143 | checkSquare(colorSquare);
144 | if (mOnColorSelectListener != null) {
145 | mOnColorSelectListener.onColorSelect(colorSquare.getColor());
146 | }
147 | } else {
148 | if (mOnCustomColorListener != null) {
149 | mOnCustomColorListener.onCustomColor();
150 | }
151 | }
152 | }
153 |
154 | public interface OnCustomColorListener {
155 | void onCustomColor();
156 | }
157 |
158 | public interface OnColorSelectListener {
159 | void onColorSelect(int color);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/palette/ColorSquare.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.palette;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.graphics.RectF;
10 | import android.view.View;
11 |
12 | import com.horizon.colorpicker.R;
13 | import com.horizon.colorpicker.seekbar.Utils;
14 |
15 | @SuppressLint("ViewConstructor")
16 | public class ColorSquare extends View {
17 | private static final int STYLE_FILL = 0;
18 | private static final int STYLE_STROKE = 1;
19 | private static final int STYLE_CHECKED = 2;
20 |
21 | private Context mContext;
22 |
23 | private int mStyle = STYLE_FILL;
24 | private int mColor;
25 |
26 | private boolean hasMeasure = false;
27 | private float mRoundRadius;
28 | public int mCheckDimen;
29 |
30 | private Paint mPaint;
31 | private RectF mRect;
32 | private Paint mStrokePaint;
33 |
34 | private Rect mCheckBitmapRect;
35 | private RectF mCheckRect;
36 |
37 | private Bitmap mPickBitmap;
38 |
39 | public ColorSquare(Context context, Bitmap checkBitmap) {
40 | super(context, null);
41 | mPickBitmap = checkBitmap;
42 | init(context);
43 | }
44 |
45 | private void init(Context context) {
46 | mContext = context;
47 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
48 | mRoundRadius = Utils.dip2px(context, 4);
49 | mCheckDimen = Utils.dip2px(context, 18);
50 | }
51 |
52 | public void setStroke() {
53 | mStyle |= STYLE_STROKE;
54 | }
55 |
56 | public void setChecked(boolean checked) {
57 | int oldStyle = mStyle;
58 | if (checked) {
59 | mStyle |= STYLE_CHECKED;
60 | } else {
61 | mStyle &= ~STYLE_CHECKED;
62 | }
63 | if (oldStyle != mStyle) {
64 | invalidate();
65 | }
66 | }
67 |
68 | public void setColor(int color) {
69 | mColor = color;
70 | mPaint.setColor(color);
71 | invalidate();
72 | }
73 |
74 | public int getColor() {
75 | return mColor;
76 | }
77 |
78 | @Override
79 | protected void onDraw(Canvas canvas) {
80 | int w = getWidth();
81 | int h = getHeight();
82 |
83 | if (!hasMeasure) {
84 | hasMeasure = true;
85 | int padding = mContext.getResources().getDimensionPixelSize(R.dimen.check_padding);
86 | mRect = new RectF(0, 0, w - padding, h - padding);
87 | }
88 |
89 | canvas.drawRoundRect(mRect, mRoundRadius, mRoundRadius, mPaint);
90 | if ((mStyle & STYLE_STROKE) != 0) {
91 | if (mStrokePaint == null) {
92 | mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
93 | mStrokePaint.setStyle(Paint.Style.STROKE);
94 | mStrokePaint.setColor(0xFFF1F1F1);
95 | mStrokePaint.setStrokeWidth(Utils.dip2px(mContext, 1));
96 | }
97 | canvas.drawRoundRect(mRect, mRoundRadius, mRoundRadius, mStrokePaint);
98 | }
99 |
100 | if ((mStyle & STYLE_CHECKED) != 0) {
101 | Bitmap bitmap = mPickBitmap;
102 | if (bitmap != null) {
103 | if (mCheckBitmapRect == null) {
104 | mCheckBitmapRect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
105 | mCheckRect = new RectF(w - mCheckDimen, h - mCheckDimen, w, h);
106 | }
107 | canvas.drawBitmap(bitmap, mCheckBitmapRect, mCheckRect, mPaint);
108 | }
109 | }
110 | }
111 |
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/AbstractSeekBar.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.graphics.Canvas;
7 | import android.graphics.Rect;
8 | import android.graphics.drawable.Drawable;
9 | import androidx.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 |
14 | import com.horizon.colorpicker.R;
15 | import com.horizon.colorpicker.seekbar.listener.OnStopTrackingListener;
16 | import com.horizon.colorpicker.seekbar.listener.OnValueChangeListener;
17 |
18 |
19 | public abstract class AbstractSeekBar extends View {
20 | protected OnValueChangeListener mOnValueChangeListener;
21 | protected OnStopTrackingListener mStopTrackingListener;
22 | protected float mValue = 0F;
23 |
24 | protected int HALO_WIDTH;
25 | protected int POINTER_RADIUS;
26 | protected int POINTER_START_X;
27 |
28 | protected int mPointerCenterX;
29 | private int mPointerEndX;
30 |
31 | protected int mWidth;
32 | protected float mBarThickness;
33 | protected float mBarY;
34 |
35 | private Drawable mPointerDrawable;
36 | private Rect mPointerRect;
37 |
38 | private boolean mHasMeasure = false;
39 |
40 | public AbstractSeekBar(Context context) {
41 | this(context, null);
42 | }
43 |
44 | public AbstractSeekBar(Context context, @Nullable AttributeSet attrs) {
45 | this(context, attrs, 0);
46 | }
47 |
48 | public AbstractSeekBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
49 | super(context, attrs, defStyleAttr);
50 | init(attrs, defStyleAttr);
51 | }
52 |
53 | public void setOnValueChangeListener(OnValueChangeListener listener) {
54 | mOnValueChangeListener = listener;
55 | }
56 |
57 | public void setOnStopTrackingListener(OnStopTrackingListener onStopTrackingListener) {
58 | mStopTrackingListener = onStopTrackingListener;
59 | }
60 |
61 | public void setValue(float value) {
62 | mValue = value;
63 | mPointerCenterX = Math.round(mValue * (mPointerEndX - POINTER_START_X)) + POINTER_START_X;
64 | invalidate();
65 | }
66 |
67 | protected void init(AttributeSet attrs, int defStyle) {
68 | Context context = getContext();
69 | Resources res = context.getResources();
70 | float pointerDimension = Utils.dip2px(context, 24f);
71 |
72 | HALO_WIDTH = Math.round(pointerDimension * (9f / 86f));
73 | POINTER_RADIUS = Utils.roundF(pointerDimension / 2f);
74 | POINTER_START_X = POINTER_RADIUS;
75 |
76 | mPointerDrawable = res.getDrawable(R.drawable.seekbar_pointer);
77 | }
78 |
79 | protected void measure() {
80 | mWidth = getMeasuredWidth();
81 | int height = getMeasuredHeight();
82 |
83 | mBarY = height / 2f;
84 |
85 | mPointerEndX = mWidth - POINTER_RADIUS;
86 |
87 | if (mValue != 0) {
88 | mPointerCenterX = Math.round(mValue * (mPointerEndX - POINTER_START_X)) + POINTER_START_X;
89 | } else {
90 | mPointerCenterX = POINTER_START_X;
91 | }
92 | int pointerY = height / 2;
93 | mPointerRect = new Rect(
94 | mPointerCenterX - POINTER_RADIUS,
95 | pointerY - POINTER_RADIUS,
96 | mPointerCenterX + POINTER_RADIUS,
97 | pointerY + POINTER_RADIUS);
98 | }
99 |
100 | protected abstract void drawLine(Canvas canvas);
101 |
102 | @Override
103 | protected void onDraw(Canvas canvas) {
104 | if (!mHasMeasure) {
105 | measure();
106 | mHasMeasure = true;
107 | }
108 |
109 | drawLine(canvas);
110 |
111 | mPointerRect.left = mPointerCenterX - POINTER_RADIUS;
112 | mPointerRect.right = mPointerCenterX + POINTER_RADIUS;
113 | mPointerDrawable.setBounds(mPointerRect);
114 | mPointerDrawable.draw(canvas);
115 | }
116 |
117 | @SuppressLint("ClickableViewAccessibility")
118 | @Override
119 | public boolean onTouchEvent(MotionEvent event) {
120 | switch (event.getAction()) {
121 | case MotionEvent.ACTION_DOWN:
122 | getParent().requestDisallowInterceptTouchEvent(true);
123 | case MotionEvent.ACTION_MOVE:
124 | int ex = (int) event.getX();
125 | int x;
126 | if (ex < POINTER_START_X) {
127 | x = POINTER_START_X;
128 | } else if (ex > mPointerEndX) {
129 | x = mPointerEndX;
130 | } else {
131 | x = ex;
132 | }
133 | if (x != mPointerCenterX) {
134 | mPointerCenterX = x;
135 | mValue = (float) (mPointerCenterX - POINTER_START_X) / (float) (mPointerEndX - POINTER_START_X);
136 | if (mOnValueChangeListener != null) {
137 | mOnValueChangeListener.onValueChanged(mValue);
138 | }
139 |
140 | invalidate();
141 | }
142 | break;
143 | case MotionEvent.ACTION_UP:
144 | case MotionEvent.ACTION_CANCEL:
145 | getParent().requestDisallowInterceptTouchEvent(false);
146 | if (mStopTrackingListener != null) {
147 | mStopTrackingListener.onStopTrackingTouch(mValue);
148 | }
149 | break;
150 | default:
151 | break;
152 | }
153 | return true;
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/BrightnessBar.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import androidx.annotation.Nullable;
6 | import android.util.AttributeSet;
7 |
8 | public class BrightnessBar extends ColorBar {
9 | public BrightnessBar(Context context) {
10 | super(context);
11 | }
12 |
13 | public BrightnessBar(Context context, @Nullable AttributeSet attrs) {
14 | super(context, attrs);
15 | }
16 |
17 | public BrightnessBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
18 | super(context, attrs, defStyleAttr);
19 | }
20 |
21 | public void setColor(float[] hsv) {
22 | float v = hsv[2];
23 | hsv[2] = 0f;
24 | colors[0] = Color.HSVToColor(hsv);
25 | hsv[2] = 1f;
26 | colors[1] = Color.HSVToColor(hsv);
27 | hsv[2] = v;
28 | setShader();
29 | setValue(v);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/ColorBar.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.LinearGradient;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.graphics.Shader;
10 | import androidx.annotation.Nullable;
11 | import android.util.AttributeSet;
12 |
13 | import com.horizon.colorpicker.R;
14 |
15 |
16 | public abstract class ColorBar extends AbstractSeekBar {
17 | private Paint mBarPaint;
18 | private RectF mBarRect = new RectF();
19 | private float mRoundRadius;
20 | protected int[] colors;
21 |
22 | public ColorBar(Context context) {
23 | super(context);
24 | }
25 |
26 | public ColorBar(Context context, @Nullable AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | public ColorBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | }
33 |
34 | @Override
35 | protected void init(AttributeSet attrs, int defStyleAttr) {
36 | super.init(attrs, defStyleAttr);
37 | Context context = getContext();
38 | final TypedArray a = getContext().obtainStyledAttributes(attrs,
39 | R.styleable.ColorBar, defStyleAttr, 0);
40 | mBarThickness = a.getDimensionPixelSize(R.styleable.ColorBar_barThickness,
41 | Utils.dip2px(context, 5f));
42 | a.recycle();
43 |
44 | mRoundRadius = mBarThickness / 2f;
45 | mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
46 | mBarPaint.setStyle(Paint.Style.FILL);
47 |
48 | colors = new int[2];
49 | }
50 |
51 | @Override
52 | protected void measure() {
53 | super.measure();
54 | mBarRect.set(POINTER_RADIUS, mBarY - mRoundRadius, mWidth - POINTER_RADIUS, mBarY + mRoundRadius);
55 | setShader();
56 | }
57 |
58 | protected void setShader() {
59 | if (mBarRect != null) {
60 | mBarPaint.setShader(new LinearGradient(0, 0, mBarRect.right - mBarRect.left, 0,
61 | colors, null, Shader.TileMode.MIRROR));
62 | }
63 | }
64 |
65 | @Override
66 | protected void drawLine(Canvas canvas) {
67 | canvas.drawRoundRect(mBarRect, mRoundRadius, mRoundRadius, mBarPaint);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/HueBar.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.Nullable;
5 | import android.util.AttributeSet;
6 |
7 |
8 |
9 | public class HueBar extends ColorBar {
10 | private static final int[] COLORS = new int[] {
11 | 0xFFFF0000,
12 | 0xFFFFFF00,
13 | 0xFF00FF00,
14 | 0xFF00FFFF,
15 | 0xFF0000FF,
16 | 0xFFFF00FF,
17 | 0xFFFF0000,
18 | };
19 |
20 | public HueBar(Context context) {
21 | super(context);
22 | }
23 |
24 | public HueBar(Context context, @Nullable AttributeSet attrs) {
25 | super(context, attrs);
26 | }
27 |
28 | public HueBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
29 | super(context, attrs, defStyleAttr);
30 | }
31 |
32 | @Override
33 | protected void init(AttributeSet attrs, int defStyleAttr) {
34 | super.init(attrs, defStyleAttr);
35 | colors = COLORS;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/NormalSeekBar.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import androidx.annotation.Nullable;
9 | import android.util.AttributeSet;
10 |
11 | import com.horizon.colorpicker.R;
12 |
13 | public class NormalSeekBar extends AbstractSeekBar {
14 | private Paint mBarUsedPaint;
15 | private Paint mBarBgPaint;
16 |
17 | public NormalSeekBar(Context context) {
18 | super(context);
19 | }
20 |
21 | public NormalSeekBar(Context context, @Nullable AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | public NormalSeekBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | }
28 |
29 | @Override
30 | protected void init(AttributeSet attrs, int defStyle) {
31 | super.init(attrs, defStyle);
32 | Context context = getContext();
33 | final TypedArray a = getContext().obtainStyledAttributes(attrs,
34 | R.styleable.NormalSeekBar, defStyle, 0);
35 | final Resources res = context.getResources();
36 | mBarThickness = a.getDimensionPixelSize(R.styleable.NormalSeekBar_thickness,
37 | Utils.dip2px(context, 1.0F));
38 | int frontColor = a.getColor(R.styleable.NormalSeekBar_frontColor,
39 | res.getColor(R.color.frontColor));
40 | int backgroundColor = a.getColor(R.styleable.NormalSeekBar_backgroundColor,
41 | res.getColor(R.color.backgroundColor));
42 | a.recycle();
43 |
44 | mBarUsedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
45 | mBarUsedPaint.setColor(frontColor);
46 | mBarUsedPaint.setStyle(Paint.Style.STROKE);
47 | mBarUsedPaint.setStrokeWidth(mBarThickness);
48 |
49 | mBarBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
50 | mBarBgPaint.setColor(backgroundColor);
51 | mBarBgPaint.setStyle(Paint.Style.STROKE);
52 | mBarBgPaint.setStrokeWidth(mBarThickness);
53 | }
54 |
55 | @Override
56 | protected void drawLine(Canvas canvas) {
57 | canvas.drawLine(HALO_WIDTH, mBarY, mPointerCenterX, mBarY, mBarUsedPaint);
58 | canvas.drawLine(mPointerCenterX, mBarY, mWidth - HALO_WIDTH, mBarY, mBarBgPaint);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/SaturationBar.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import androidx.annotation.Nullable;
6 | import android.util.AttributeSet;
7 |
8 |
9 | public class SaturationBar extends ColorBar {
10 | public SaturationBar(Context context) {
11 | super(context);
12 | }
13 |
14 | public SaturationBar(Context context, @Nullable AttributeSet attrs) {
15 | super(context, attrs);
16 | }
17 |
18 | public SaturationBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
19 | super(context, attrs, defStyleAttr);
20 | }
21 |
22 | public void setColor(float[] hsv) {
23 | float s = hsv[1];
24 | hsv[1] = 0f;
25 | colors[0] = Color.HSVToColor(hsv);
26 | hsv[1] = 1f;
27 | colors[1] = Color.HSVToColor(hsv);
28 | hsv[1] = s;
29 | setShader();
30 | setValue(s);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/Utils.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar;
2 |
3 | import android.content.Context;
4 |
5 | public class Utils {
6 | public static int roundF(float x) {
7 | return (int) (x + 0.5F);
8 | }
9 |
10 | public static int dip2px(Context context, float dpValue) {
11 | float scale = context.getResources().getDisplayMetrics().density;
12 | return Utils.roundF(dpValue * scale);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/listener/OnStopTrackingListener.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar.listener;
2 |
3 |
4 | public interface OnStopTrackingListener {
5 | void onStopTrackingTouch(float value);
6 | }
7 |
--------------------------------------------------------------------------------
/colorpicker/src/main/java/com/horizon/colorpicker/seekbar/listener/OnValueChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.horizon.colorpicker.seekbar.listener;
2 |
3 |
4 | public interface OnValueChangeListener {
5 | /**
6 | * @param value 取值范围 [0,1.0]
7 | */
8 | void onValueChanged(float value);
9 | }
10 |
--------------------------------------------------------------------------------
/colorpicker/src/main/res/drawable-xhdpi/icon_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/colorpicker/src/main/res/drawable-xhdpi/icon_check.png
--------------------------------------------------------------------------------
/colorpicker/src/main/res/drawable-xxhdpi/custom_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/colorpicker/src/main/res/drawable-xxhdpi/custom_color.png
--------------------------------------------------------------------------------
/colorpicker/src/main/res/drawable-xxhdpi/seekbar_pointer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/colorpicker/src/main/res/drawable-xxhdpi/seekbar_pointer.png
--------------------------------------------------------------------------------
/colorpicker/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/colorpicker/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #1E90FF
4 | #AFAFAF
5 |
6 |
--------------------------------------------------------------------------------
/colorpicker/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 50dp
4 | 5dp
5 |
--------------------------------------------------------------------------------
/fancypicker/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fancypicker/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | }
4 |
5 | android {
6 |
7 | compileSdk 32
8 | defaultConfig {
9 | minSdk 21
10 | targetSdk 32
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'androidx.appcompat:appcompat:1.4.2'
31 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
32 | }
33 |
--------------------------------------------------------------------------------
/fancypicker/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/fancypicker/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/fancypicker/src/main/java/com/horizon/fancypicker/ColorPicker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Lars Werkman
3 | * Copyright 2019 Horizon
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.horizon.fancypicker;
19 |
20 | import android.content.Context;
21 | import android.content.res.Resources;
22 | import android.content.res.TypedArray;
23 | import android.graphics.Canvas;
24 | import android.graphics.Color;
25 | import android.graphics.ComposeShader;
26 | import android.graphics.LinearGradient;
27 | import android.graphics.Paint;
28 | import android.graphics.PorterDuff;
29 | import android.graphics.RectF;
30 | import android.graphics.Shader;
31 | import android.graphics.SweepGradient;
32 | import android.util.AttributeSet;
33 | import android.view.MotionEvent;
34 | import android.view.View;
35 |
36 | /**
37 | * ColorPicker with hue wheel and saturation-value panel
38 | *
39 | * hue wheel reference to
40 | * https://github.com/LarsWerkman/HoloColorPicker
41 | *
42 | * saturation-value panel reference to
43 | * https://github.com/relish-wang/ColorPicker
44 | */
45 | public class ColorPicker extends View {
46 | /**
47 | * Colors to construct the color wheel using {@link SweepGradient}.
48 | */
49 | private static final int[] COLORS = new int[]{
50 | 0xFFFF0000,
51 | 0xFFFFFF00,
52 | 0xFF00FF00,
53 | 0xFF00FFFF,
54 | 0xFF0000FF,
55 | 0xFFFF00FF,
56 | 0xFFFF0000,
57 | };
58 |
59 | /**
60 | * To make RED color in 90 degrees
61 | */
62 | private static final float WHEEL_ROTATE = 90f;
63 |
64 | /**
65 | * {@code Paint} instance used to draw the color wheel.
66 | */
67 | private Paint mColorWheelPaint;
68 |
69 | /**
70 | * {@code Paint} instance used to draw the pointer's "halo".
71 | */
72 | private Paint mPointerHaloPaint;
73 |
74 | /**
75 | * {@code Paint} instance used to draw the pointer (the selected color).
76 | */
77 | private Paint mPointerColorPaint;
78 |
79 | /**
80 | * The width of the color wheel thickness.
81 | */
82 | private int mColorWheelThickness;
83 |
84 | /**
85 | * The radius of the color wheel.
86 | */
87 | private int mColorWheelRadius;
88 | private int mPreferredColorWheelRadius;
89 |
90 | /**
91 | * The radius of the pointer.
92 | */
93 | private int mColorPointerRadius;
94 |
95 | /**
96 | * The radius of the halo of the pointer.
97 | */
98 | private int mColorPointerHaloRadius;
99 |
100 | /**
101 | * The rectangle enclosing the color wheel.
102 | */
103 | private RectF mColorWheelRectangle = new RectF();
104 |
105 | /**
106 | * {@code true} if the user clicked on the pointer to start the move mode.
107 | * {@code false} once the user stops touching the screen.
108 | *
109 | * @see #onTouchEvent(MotionEvent)
110 | */
111 | private boolean mIsMovingWheelPointer = false;
112 |
113 | /**
114 | * color of wheel pointer
115 | */
116 | private int mHueColor;
117 |
118 | /**
119 | * Number of pixels the origin of this view is moved in X- and Y-direction.
120 | *
121 | *
122 | * We use the center of this (quadratic) View as origin of our internal
123 | * coordinate system. Android uses the upper left corner as origin for the
124 | * View-specific coordinate system. So this is the value we use to translate
125 | * from one coordinate system to the other.
126 | *
127 | *
128 | *
129 | * Note: (Re)calculated in {@link #onMeasure(int, int)}.
130 | *
131 | *
132 | * @see #onDraw(Canvas)
133 | */
134 | private float mTranslationOffset;
135 |
136 | /**
137 | * Distance between pointer and user touch in X-direction.
138 | */
139 | private float mSlopX;
140 |
141 | /**
142 | * Distance between pointer and user touch in Y-direction.
143 | */
144 | private float mSlopY;
145 |
146 | /**
147 | * The pointer's position expressed as angle (in rad).
148 | */
149 | private float mAngle;
150 |
151 | private float mSVTrackerRadius;
152 | private float mTracerBorderWidth;
153 | private boolean mMovingSVPointer = false;
154 |
155 | private float[] mHSV = new float[]{0f, 1f, 1f};
156 | private float[] mShaderHSV = new float[]{0f, 1f, 1f};
157 |
158 | private Paint mSVPaint;
159 | private Paint mSVTrackerPaint;
160 | private Paint mSVTrackerBorderPaint;
161 | private Paint mSVSelectorPaint;
162 |
163 | private RectF mSVRect = new RectF();
164 | private Shader mValShader;
165 | private ComposeShader mComposeShader;
166 |
167 | /**
168 | * {@code onColorChangedListener} instance of the onColorChangedListener
169 | */
170 | private OnColorChangedListener onColorChangedListener;
171 |
172 | /**
173 | * {@code onColorSelectedListener} instance of the onColorSelectedListener
174 | */
175 | private OnColorSelectedListener onColorSelectedListener;
176 |
177 | public ColorPicker(Context context) {
178 | super(context);
179 | init(null, 0);
180 | }
181 |
182 | public ColorPicker(Context context, AttributeSet attrs) {
183 | super(context, attrs);
184 | init(attrs, 0);
185 | }
186 |
187 | public ColorPicker(Context context, AttributeSet attrs, int defStyle) {
188 | super(context, attrs, defStyle);
189 | init(attrs, defStyle);
190 | }
191 |
192 | /**
193 | * An interface that is called whenever the color is changed. Currently it
194 | * is always called when the color is changes.
195 | *
196 | * @author lars
197 | */
198 | public interface OnColorChangedListener {
199 | public void onColorChanged(float[] hsv);
200 | }
201 |
202 | /**
203 | * An interface that is called whenever a new color has been selected.
204 | * Currently it is always called when the color wheel has been released.
205 | */
206 | public interface OnColorSelectedListener {
207 | public void onColorSelected(int color);
208 | }
209 |
210 | /**
211 | * Set a onColorChangedListener
212 | *
213 | * @param listener {@code OnColorChangedListener}
214 | */
215 | public void setOnColorChangedListener(OnColorChangedListener listener) {
216 | this.onColorChangedListener = listener;
217 | }
218 |
219 | /**
220 | * Set a onColorSelectedListener
221 | *
222 | * @param listener {@code OnColorSelectedListener}
223 | */
224 | public void setOnColorSelectedListener(OnColorSelectedListener listener) {
225 | this.onColorSelectedListener = listener;
226 | }
227 |
228 | private void init(AttributeSet attrs, int defStyle) {
229 | final TypedArray a = getContext().obtainStyledAttributes(attrs,
230 | R.styleable.ColorPicker, defStyle, 0);
231 | final Resources res = getContext().getResources();
232 |
233 | mColorWheelThickness = a.getDimensionPixelSize(
234 | R.styleable.ColorPicker_color_wheel_thickness,
235 | res.getDimensionPixelSize(R.dimen.color_wheel_thickness));
236 | mColorWheelRadius = a.getDimensionPixelSize(
237 | R.styleable.ColorPicker_color_wheel_radius,
238 | res.getDimensionPixelSize(R.dimen.color_wheel_radius));
239 | mPreferredColorWheelRadius = mColorWheelRadius;
240 |
241 |
242 | mColorPointerRadius = a.getDimensionPixelSize(
243 | R.styleable.ColorPicker_color_pointer_radius,
244 | res.getDimensionPixelSize(R.dimen.color_pointer_radius));
245 | mColorPointerHaloRadius = a.getDimensionPixelSize(
246 | R.styleable.ColorPicker_color_pointer_halo_radius,
247 | res.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
248 |
249 | a.recycle();
250 |
251 | // ComposeShader doesn't work with hardware accelerated on some devices.
252 | setLayerType(View.LAYER_TYPE_SOFTWARE, null);
253 |
254 | initWheel();
255 | initSV();
256 | }
257 |
258 | private void initWheel() {
259 | mAngle = (float) (-Math.PI / 2);
260 |
261 | mColorWheelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
262 | mColorWheelPaint.setShader(new SweepGradient(0, 0, COLORS, null));
263 | mColorWheelPaint.setStyle(Paint.Style.STROKE);
264 | mColorWheelPaint.setStrokeWidth(mColorWheelThickness);
265 |
266 | mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
267 | mPointerHaloPaint.setColor(Color.BLACK);
268 | mPointerHaloPaint.setAlpha(0x50);
269 |
270 | mPointerColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
271 | mHueColor = calculateHueColor(mAngle);
272 | mPointerColorPaint.setColor(mHueColor);
273 | }
274 |
275 | private void initSV() {
276 | Context context = getContext();
277 | mSVPaint = new Paint();
278 |
279 | mSVTrackerRadius = dip2px(context, 7.5f);
280 | mTracerBorderWidth = dip2px(context, 1f);
281 |
282 | mSVTrackerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
283 | mSVTrackerPaint.setColor(0xff000000);
284 | mSVTrackerPaint.setStyle(Paint.Style.STROKE);
285 | mSVTrackerPaint.setStrokeWidth(mTracerBorderWidth);
286 |
287 | mSVTrackerBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
288 | mSVTrackerBorderPaint.setColor(0x7fdddddd);
289 | mSVTrackerBorderPaint.setStyle(Paint.Style.STROKE);
290 | mSVTrackerBorderPaint.setStrokeWidth(mTracerBorderWidth);
291 |
292 | mSVSelectorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
293 | mSVSelectorPaint.setColor(0xffffffff);
294 | mSVSelectorPaint.setStyle(Paint.Style.STROKE);
295 | mSVSelectorPaint.setStrokeWidth(dip2px(context, 0.7f));
296 | }
297 |
298 | private static int dip2px(Context context, float dpValue) {
299 | float scale = context.getResources().getDisplayMetrics().density;
300 | return Math.round(dpValue * scale);
301 | }
302 |
303 | @Override
304 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
305 | final int intrinsicSize = 2 * (mPreferredColorWheelRadius + mColorPointerHaloRadius);
306 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
307 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
308 |
309 | int a;
310 | if (widthMode == MeasureSpec.EXACTLY) {
311 | a = widthSize;
312 | } else if (widthMode == MeasureSpec.AT_MOST) {
313 | a = Math.min(intrinsicSize, widthSize);
314 | } else {
315 | a = intrinsicSize;
316 | }
317 |
318 | // make view height always equals to width
319 | setMeasuredDimension(a, a);
320 |
321 | mTranslationOffset = a * 0.5f;
322 | mColorWheelRadius = a / 2 - mColorWheelThickness - mColorPointerHaloRadius;
323 | mColorWheelRectangle.set(-mColorWheelRadius, -mColorWheelRadius,
324 | mColorWheelRadius, mColorWheelRadius);
325 |
326 | float SVRadius = (float) (mColorWheelRadius * Math.sqrt(2f) / 2f) * 0.86f;
327 | mSVRect.set(-SVRadius, -SVRadius, SVRadius, SVRadius);
328 | }
329 |
330 | private int ave(int s, int e, float t) {
331 | return s + Math.round(t * (e - s));
332 | }
333 |
334 | /**
335 | * Calculate the color using the supplied angle.
336 | *
337 | * @param angle The selected color's position expressed as angle (in rad).
338 | * @return The ARGB value of the color on the color wheel at the specified
339 | * angle.
340 | */
341 | private int calculateHueColor(float angle) {
342 | angle += Math.toRadians(WHEEL_ROTATE);
343 | float unit = (float) (angle / (2 * Math.PI));
344 | if (unit < 0) {
345 | unit += 1;
346 | }
347 |
348 | if (unit <= 0f) {
349 | mHSV[0] = 0f;
350 | return COLORS[0];
351 | }
352 | if (unit >= 1f) {
353 | mHSV[0] = 360f;
354 | return COLORS[COLORS.length - 1];
355 | }
356 |
357 | float p = unit * (COLORS.length - 1);
358 | int i = (int) p;
359 | p -= i;
360 |
361 | int c0 = COLORS[i];
362 | int c1 = COLORS[i + 1];
363 | int a = ave(Color.alpha(c0), Color.alpha(c1), p);
364 | int r = ave(Color.red(c0), Color.red(c1), p);
365 | int g = ave(Color.green(c0), Color.green(c1), p);
366 | int b = ave(Color.blue(c0), Color.blue(c1), p);
367 |
368 | mHSV[0] = unit * 360f;
369 | return Color.argb(a, r, g, b);
370 | }
371 |
372 | /**
373 | * Get the currently selected color.
374 | *
375 | * @return The ARGB value of the currently selected color.
376 | */
377 | public int getColor() {
378 | return mHueColor;
379 | }
380 |
381 | public void setColor(int color) {
382 | color |= 0xFF000000;
383 | mAngle = colorToAngle(color);
384 | mHueColor = calculateHueColor(mAngle);
385 | mPointerColorPaint.setColor(mHueColor);
386 | invalidate();
387 | }
388 |
389 | /**
390 | * Convert a color to an angle.
391 | *
392 | * @param color The RGB value of the color to "find" on the color wheel.
393 | * @return The angle (in rad) the "normalized" color is displayed on the
394 | * color wheel.
395 | */
396 | private float colorToAngle(int color) {
397 | Color.colorToHSV(color, mHSV);
398 | float degrees = mHSV[0] - WHEEL_ROTATE;
399 | if (degrees < -180f) {
400 | degrees += 360f;
401 | }
402 | return (float) Math.toRadians(degrees);
403 | }
404 |
405 | @Override
406 | protected void onDraw(Canvas canvas) {
407 | // All of our positions are using our internal coordinate system.
408 | // Instead of translating them,
409 | // we let Canvas do the work for us.
410 | canvas.translate(mTranslationOffset, mTranslationOffset);
411 |
412 | drawWheel(canvas);
413 | drawSVPanel(canvas);
414 | }
415 |
416 | private void drawWheel(Canvas canvas) {
417 | // Draw the color wheel.
418 | canvas.save();
419 | canvas.rotate(-WHEEL_ROTATE);
420 | canvas.drawOval(mColorWheelRectangle, mColorWheelPaint);
421 | canvas.restore();
422 |
423 | float x = (float) (mColorWheelRadius * Math.cos(mAngle));
424 | float y = (float) (mColorWheelRadius * Math.sin(mAngle));
425 |
426 | // Draw the pointer's "halo"
427 | canvas.drawCircle(x, y, mColorPointerHaloRadius, mPointerHaloPaint);
428 |
429 | // Draw the pointer (the currently selected color) slightly smaller on top.
430 | canvas.drawCircle(x, y, mColorPointerRadius, mPointerColorPaint);
431 | }
432 |
433 | private void drawSVPanel(Canvas canvas) {
434 | mSVPaint.setShader(getSVShader());
435 | canvas.drawRect(mSVRect, mSVPaint);
436 |
437 | int x = (int) (mHSV[1] * mSVRect.height() + mSVRect.left);
438 | int y = (int) ((1f - mHSV[2]) * mSVRect.width() + mSVRect.top);
439 |
440 | // Draw the sv panel's pointer
441 | if(mMovingSVPointer){
442 | canvas.drawCircle(x, y, mSVTrackerRadius + mTracerBorderWidth, mSVTrackerBorderPaint);
443 | canvas.drawCircle(x, y, mSVTrackerRadius - mTracerBorderWidth, mSVTrackerBorderPaint);
444 | canvas.drawCircle(x, y, mSVTrackerRadius , mSVTrackerPaint);
445 | }
446 |
447 | // canvas.clipRect(mSVRect);
448 | canvas.drawCircle(x, y, mSVTrackerRadius - mTracerBorderWidth * 2.5f , mSVSelectorPaint);
449 | }
450 |
451 | private Shader getSVShader() {
452 | if (mValShader == null) {
453 | mValShader = new LinearGradient(
454 | mSVRect.left, mSVRect.top,
455 | mSVRect.left, mSVRect.bottom,
456 | Color.WHITE, Color.BLACK, Shader.TileMode.CLAMP);
457 | }
458 |
459 | if (mShaderHSV[0] != mHSV[0] || mComposeShader == null) {
460 | mShaderHSV[0] = mHSV[0];
461 | Shader satShader = new LinearGradient(
462 | mSVRect.left, mSVRect.top,
463 | mSVRect.right, mSVRect.top,
464 | Color.WHITE, Color.HSVToColor(mShaderHSV), Shader.TileMode.CLAMP);
465 | mComposeShader = new ComposeShader(mValShader, satShader, PorterDuff.Mode.MULTIPLY);
466 | }
467 |
468 | return mComposeShader;
469 | }
470 |
471 | @Override
472 | public boolean onTouchEvent(MotionEvent event) {
473 | getParent().requestDisallowInterceptTouchEvent(true);
474 |
475 | // Convert coordinates to our internal coordinate system
476 | float x = event.getX() - mTranslationOffset;
477 | float y = event.getY() - mTranslationOffset;
478 |
479 | switch (event.getAction()) {
480 | case MotionEvent.ACTION_DOWN:
481 | float px = (float) (mColorWheelRadius * Math.cos(mAngle));
482 | float py = (float) (mColorWheelRadius * Math.sin(mAngle));
483 | if (x >= (px - mColorPointerHaloRadius)
484 | && x <= (px + mColorPointerHaloRadius)
485 | && y >= (py - mColorPointerHaloRadius)
486 | && y <= (py + mColorPointerHaloRadius)) {
487 | mSlopX = x - px;
488 | mSlopY = y - py;
489 | mIsMovingWheelPointer = true;
490 | invalidate();
491 | } else if (mSVRect.contains(x, y)) {
492 | changeSV(x, y);
493 | mMovingSVPointer = true;
494 | } else {
495 | float d = (float) Math.sqrt(x * x + y * y);
496 | if (d <= mColorWheelRadius + mColorPointerHaloRadius
497 | && d >= mColorWheelRadius - mColorPointerHaloRadius) {
498 | mIsMovingWheelPointer = true;
499 | invalidate();
500 | } else {
501 | getParent().requestDisallowInterceptTouchEvent(false);
502 | return false;
503 | }
504 | }
505 | break;
506 | case MotionEvent.ACTION_MOVE:
507 | if (mIsMovingWheelPointer) {
508 | mAngle = (float) Math.atan2(y - mSlopY, x - mSlopX);
509 | mHueColor = calculateHueColor(mAngle);
510 | mPointerColorPaint.setColor(mHueColor);
511 | invokeColorChange();
512 | invalidate();
513 | } else if (mMovingSVPointer) {
514 | changeSV(x, y);
515 | } else {
516 | getParent().requestDisallowInterceptTouchEvent(false);
517 | return false;
518 | }
519 | break;
520 | case MotionEvent.ACTION_UP:
521 | case MotionEvent.ACTION_CANCEL:
522 | mIsMovingWheelPointer = false;
523 | mMovingSVPointer = false;
524 | if (onColorSelectedListener != null) {
525 | onColorSelectedListener.onColorSelected(Color.HSVToColor(mHSV));
526 | }
527 | invalidate();
528 | break;
529 | }
530 | return true;
531 | }
532 |
533 | private void changeSV(float x, float y) {
534 | final RectF rect = mSVRect;
535 | float width = rect.width();
536 | float height = rect.height();
537 |
538 | if (x < rect.left) {
539 | x = 0f;
540 | } else if (x > rect.right) {
541 | x = width;
542 | } else {
543 | x = x - rect.left;
544 | }
545 |
546 | if (y < rect.top) {
547 | y = 0f;
548 | } else if (y > rect.bottom) {
549 | y = height;
550 | } else {
551 | y = y - rect.top;
552 | }
553 | mHSV[1] = x / width;
554 | mHSV[2] = 1f - y / height;
555 | invokeColorChange();
556 | invalidate();
557 | }
558 |
559 | public void invokeColorChange() {
560 | if (onColorChangedListener != null) {
561 | onColorChangedListener.onColorChanged(mHSV);
562 | }
563 | }
564 | }
565 |
--------------------------------------------------------------------------------
/fancypicker/src/main/java/com/horizon/fancypicker/ColorPickerDialog.java:
--------------------------------------------------------------------------------
1 | package com.horizon.fancypicker;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.graphics.Point;
8 | import android.graphics.drawable.ColorDrawable;
9 | import android.os.Bundle;
10 | import androidx.annotation.NonNull;
11 | import android.text.Editable;
12 | import android.text.InputFilter;
13 | import android.text.InputType;
14 | import android.text.LoginFilter;
15 | import android.text.TextUtils;
16 | import android.text.TextWatcher;
17 | import android.util.Log;
18 | import android.view.Gravity;
19 | import android.view.View;
20 | import android.view.Window;
21 | import android.view.WindowManager;
22 | import android.widget.EditText;
23 | import android.widget.TextView;
24 |
25 |
26 | public class ColorPickerDialog extends Dialog
27 | implements ColorPicker.OnColorChangedListener, View.OnClickListener {
28 | private final static String ALLOWED_DIGITS = "1234567890abcdefABCDEF";
29 |
30 | private float[] mHSV = new float[3];
31 |
32 | private ColorPicker mColorPicker;
33 | private View mNewColorView;
34 | private View mCurrentColorView;
35 | private EditText mColorEt;
36 |
37 | private TextView mRedTv;
38 | private TextView mGreenTv;
39 | private TextView mBlueTv;
40 | private TextView mHueTv;
41 | private TextView mSatTv;
42 | private TextView mValTv;
43 |
44 | private OnColorPickedListener mListener;
45 | private TextWatcher mTextWatcher;
46 |
47 | public interface OnColorPickedListener {
48 | void onColorPicked(int color);
49 | }
50 |
51 | private ColorPickerDialog(Context context, int initialColor) {
52 | super(context);
53 | init(initialColor);
54 | }
55 |
56 | private void init(int color) {
57 | setContentView(R.layout.dialog_color_picker);
58 |
59 | findViews();
60 |
61 | mColorEt.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
62 | mColorPicker.setOnColorChangedListener(this);
63 |
64 | mTextWatcher = new TextWatcher() {
65 | @Override
66 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
67 | }
68 |
69 | @Override
70 | public void onTextChanged(CharSequence s, int start, int before, int count) {
71 | }
72 |
73 | @Override
74 | public void afterTextChanged(Editable s) {
75 | int color = strToColor(s.toString());
76 | mColorPicker.setColor(color);
77 | Color.colorToHSV(color, mHSV);
78 | updateColor(color, false);
79 | }
80 | };
81 |
82 |
83 | InputFilter[] filters = new InputFilter[2];
84 | filters[0] = new LoginFilter.UsernameFilterGeneric() {
85 | @Override
86 | public boolean isAllowed(char c) {
87 | return ALLOWED_DIGITS.indexOf(c) != -1;
88 | }
89 |
90 | };
91 | filters[1] = new InputFilter.LengthFilter(6);
92 | mColorEt.setFilters(filters);
93 | mColorEt.addTextChangedListener(mTextWatcher);
94 |
95 |
96 | mCurrentColorView.setBackgroundColor(color);
97 | mColorPicker.setColor(color);
98 | Color.colorToHSV(color, mHSV);
99 | updateColor(color, true);
100 | }
101 |
102 | private int strToColor(String str) {
103 | int color = 0;
104 | if (!TextUtils.isEmpty(str)) {
105 | if (str.length() == 3) {
106 | char[] chars = str.toCharArray();
107 | StringBuilder builder = new StringBuilder(6);
108 | builder.append(chars[0]).append(chars[0]);
109 | builder.append(chars[1]).append(chars[1]);
110 | builder.append(chars[2]).append(chars[2]);
111 | str = builder.toString();
112 | }
113 | try {
114 | color = Integer.parseInt(str, 16);
115 | } catch (NumberFormatException e) {
116 | Log.e("ColorPickerDialog", e.getMessage(), e);
117 | }
118 | }
119 | return color | 0xFF000000;
120 | }
121 |
122 | private void findViews() {
123 | mColorPicker = findViewById(R.id.color_picker);
124 | mNewColorView = findViewById(R.id.new_color_panel);
125 | mCurrentColorView = findViewById(R.id.current_color_panel);
126 | mColorEt = findViewById(R.id.color_et);
127 |
128 | mRedTv = findViewById(R.id.red_tv);
129 | mGreenTv = findViewById(R.id.green_tv);
130 | mBlueTv = findViewById(R.id.blue_tv);
131 | mHueTv = findViewById(R.id.hue_tv);
132 | mSatTv = findViewById(R.id.sat_tv);
133 | mValTv = findViewById(R.id.val_tv);
134 |
135 | View cancelBtn = findViewById(R.id.cancel_btn);
136 | View okBtn = findViewById(R.id.ok_btn);
137 | cancelBtn.setOnClickListener(this);
138 | okBtn.setOnClickListener(this);
139 | }
140 |
141 | @SuppressLint("SetTextI18n")
142 | @Override
143 | public void onColorChanged(float[] hsv) {
144 | mHSV = hsv;
145 | updateColor(Color.HSVToColor(hsv), true);
146 | }
147 |
148 | @SuppressLint("SetTextI18n")
149 | private void updateColor(int color, boolean updateTextView) {
150 | color |= 0xFF000000;
151 |
152 | if (updateTextView) {
153 | mColorEt.removeTextChangedListener(mTextWatcher);
154 | mColorEt.setText(Integer.toHexString(color).substring(2, 8));
155 | mColorEt.addTextChangedListener(mTextWatcher);
156 | }
157 |
158 | mNewColorView.setBackgroundColor(color);
159 |
160 | mRedTv.setText("R: " + Color.red(color));
161 | mGreenTv.setText("G: " + Color.green(color));
162 | mBlueTv.setText("B: " + Color.blue(color));
163 |
164 | mHueTv.setText("H: " + Math.round(mHSV[0]));
165 | mSatTv.setText("S: " + Math.round(mHSV[1] * 100));
166 | mValTv.setText("B: " + Math.round(mHSV[2] * 100));
167 | }
168 |
169 | public int getColor() {
170 | return mColorPicker.getColor();
171 | }
172 |
173 | @Override
174 | public void onClick(View v) {
175 | if (v.getId() == R.id.ok_btn) {
176 | if (mListener != null) {
177 | mListener.onColorPicked(Color.HSVToColor(mHSV));
178 | }
179 | }
180 | dismiss();
181 | }
182 |
183 | @NonNull
184 | @Override
185 | public Bundle onSaveInstanceState() {
186 | Bundle state = super.onSaveInstanceState();
187 | state.putInt("old_color", ((ColorDrawable) mNewColorView.getBackground()).getColor());
188 | state.putInt("new_color", ((ColorDrawable) mCurrentColorView.getBackground()).getColor());
189 | return state;
190 | }
191 |
192 | @Override
193 | public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
194 | super.onRestoreInstanceState(savedInstanceState);
195 | mNewColorView.setBackgroundColor(savedInstanceState.getInt("old_color"));
196 | mColorPicker.setColor(savedInstanceState.getInt("new_color"));
197 | }
198 |
199 | public static class Builder {
200 | private Context context;
201 | private int initColor;
202 | private OnColorPickedListener listener;
203 |
204 | public Builder(Context context, int initColor) {
205 | this.context = context;
206 | this.initColor = initColor;
207 | }
208 |
209 | public Builder setOnColorPickedListener(OnColorPickedListener listener) {
210 | this.listener = listener;
211 | return this;
212 | }
213 |
214 | public ColorPickerDialog build() {
215 | ColorPickerDialog dialog = new ColorPickerDialog(context, initColor);
216 | dialog.mListener = listener;
217 | Window window = dialog.getWindow();
218 | if (window != null) {
219 | window.setGravity(Gravity.CENTER);
220 | window.setDimAmount(0f);
221 | int padding = Math.round(16f * context.getResources().getDisplayMetrics().density);
222 | Point dimens = fetchDimens(context);
223 | WindowManager.LayoutParams lp = window.getAttributes();
224 | lp.width = dimens.x - padding * 2;
225 | lp.height = (int) (lp.width * 1.75f);
226 | window.setAttributes(lp);
227 | }
228 | return dialog;
229 | }
230 | }
231 |
232 | private static Point fetchDimens(Context context) {
233 | try {
234 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
235 | if (windowManager != null) {
236 | Point point = new Point();
237 | windowManager.getDefaultDisplay().getSize(point);
238 | if (point.x > 0 && point.y > 0) {
239 | return point;
240 | }
241 | }
242 | } catch (Exception ignore) {
243 | }
244 | // should not be here, just in case
245 | return new Point(1080, 1920);
246 | }
247 | }
248 |
--------------------------------------------------------------------------------
/fancypicker/src/main/res/layout/dialog_color_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
29 |
30 |
39 |
40 |
51 |
52 |
63 |
64 |
74 |
75 |
85 |
86 |
96 |
97 |
107 |
108 |
118 |
119 |
129 |
130 |
131 |
144 |
145 |
154 |
155 |
162 |
163 |
174 |
175 |
186 |
187 |
188 |
--------------------------------------------------------------------------------
/fancypicker/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 新的
3 | 当前
4 | 取消
5 | 确定
6 |
--------------------------------------------------------------------------------
/fancypicker/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 |
--------------------------------------------------------------------------------
/fancypicker/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #f0f0f0
4 |
5 |
--------------------------------------------------------------------------------
/fancypicker/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 124dp
5 | 11dp
6 | 60dp
7 | 54dp
8 | 15dp
9 | 12dp
10 |
11 |
12 | 4dp
13 | 240dp
14 | 6dp
15 | 14dp
16 |
17 | 16sp
18 | 5dp
19 |
--------------------------------------------------------------------------------
/fancypicker/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | New
3 | Current
4 | Cancel
5 | OK
6 |
7 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat May 04 10:23:41 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/image/colorpicker.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/image/colorpicker.gif
--------------------------------------------------------------------------------
/image/fancypicker.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BillyWei01/ColorPicker/e08aa944927d4c1fefa99bf175beb8e889cbb821/image/fancypicker.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 |
16 | rootProject.name = "ColorPicker"
17 | include ':app', ':colorpicker', ':fancypicker'
18 |
--------------------------------------------------------------------------------