├── .github
├── CODEOWNERS
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── Bug_report.md
│ └── Feature_request.md
└── pull_request_template.md
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── skydoves
│ │ └── colorpickerpreferencedemo
│ │ ├── BaseActivity.kt
│ │ ├── ColorPickerDialogActivity.kt
│ │ ├── ColorPickerViewActivity.kt
│ │ ├── CustomFlag.kt
│ │ ├── MainActivity.kt
│ │ ├── PowerMenuUtils.kt
│ │ ├── PreferenceActivity.kt
│ │ └── PreferenceFragment.kt
│ └── res
│ ├── drawable-hdpi
│ ├── ic_arrow_back_white_24dp.png
│ └── ic_list_white_24dp.png
│ ├── drawable-mdpi
│ ├── ic_arrow_back_white_24dp.png
│ └── ic_list_white_24dp.png
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable-xhdpi
│ ├── ic_arrow_back_white_24dp.png
│ └── ic_list_white_24dp.png
│ ├── drawable-xxhdpi
│ ├── ic_arrow_back_white_24dp.png
│ └── ic_list_white_24dp.png
│ ├── drawable-xxxhdpi
│ ├── ic_arrow_back_white_24dp.png
│ └── ic_list_white_24dp.png
│ ├── drawable
│ ├── flag.png
│ ├── ic_info_black_24dp.xml
│ ├── ic_launcher_background.xml
│ ├── ic_notifications_black_24dp.xml
│ ├── ic_sync_black_24dp.xml
│ ├── palettebar.jpg
│ ├── watercolor.jpg
│ └── wheel_dark.png
│ ├── layout
│ ├── activity_color_picker_dialog.xml
│ ├── activity_color_picker_view.xml
│ ├── activity_main.xml
│ ├── layout_flag.xml
│ ├── layout_header.xml
│ └── layout_toolbar.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
│ └── xml
│ └── pref_settings.xml
├── build.gradle
├── colorpickerpreference
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── skydoves
│ │ └── colorpickerpreference
│ │ └── ColorPickerPreference.kt
│ └── res
│ ├── drawable
│ ├── palette.png
│ └── wheel.png
│ ├── layout
│ └── layout_colorpicker_preference.xml
│ └── values
│ └── attrs_colorpicker.xml
├── dependencies.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── publish.gradle
├── settings.gradle
├── spotless.gradle
└── spotless.license.kt
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Lines starting with '#' are comments.
2 | # Each line is a file pattern followed by one or more owners.
3 |
4 | # More details are here: https://help.github.com/articles/about-codeowners/
5 |
6 | # The '*' pattern is global owners.
7 | # Not adding in this PR, but I'd like to try adding a global owner set with the entire team.
8 | # One interpretation of their docs is that global owners are added only if not removed
9 | # by a more local rule.
10 |
11 | # Order is important. The last matching pattern has the most precedence.
12 | # The folders are ordered as follows:
13 |
14 | # In each subsection folders are ordered first by depth, then alphabetically.
15 | # This should make it easy to add new rules without breaking existing ones.
16 | * @skydoves
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: skydoves
2 | custom: ["https://www.paypal.me/skydoves", "https://www.buymeacoffee.com/skydoves"]
3 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Something is crashing or not working as intended
4 |
5 | ---
6 |
7 | **Please complete the following information:**
8 | - Library Version [e.g. v2.1.0]
9 | - Affected Device(s) [e.g. Samsung Galaxy s10 with Android 9.0]
10 |
11 | **Describe the Bug:**
12 |
13 | Add a clear description about the problem.
14 |
15 | **Expected Behavior:**
16 |
17 | A clear description of what you expected to happen.
18 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem?**
8 |
9 | A clear and concise description of what the problem is.
10 |
11 | **Describe the solution you'd like:**
12 |
13 | A clear and concise description of what you want to happen.
14 |
15 | **Describe alternatives you've considered:**
16 |
17 | A clear description of any alternative solutions you've considered.
18 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Guidelines
2 | Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
3 |
4 | ### Types of changes
5 | What types of changes does your code introduce?
6 |
7 | - [ ] Bugfix (non-breaking change which fixes an issue)
8 | - [ ] New feature (non-breaking change which adds functionality)
9 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
10 |
11 | ### Preparing a pull request for review
12 | Ensure your change is properly formatted by running:
13 |
14 | ```gradle
15 | $ ./gradlew spotlessApply
16 | ```
17 |
18 | Please correct any failures before requesting a review.
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | /.idea
18 | .gradle/
19 | build/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # Intellij
37 | *.iml
38 | .idea/workspace.xml
39 | .idea/tasks.xml
40 | .idea/gradle.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - tools
6 | - platform-tools
7 | - build-tools-28.0.3
8 | - android-28
9 | - extra-android-support
10 | - extra-android-m2repository
11 | - extra-google-m2repository
12 |
13 | jdk:
14 | - oraclejdk8
15 |
16 | branches:
17 | except:
18 | - gh-pages
19 |
20 | notifications:
21 | email: false
22 |
23 | cache:
24 | directories:
25 | - $HOME/.gradle
26 |
27 | script:
28 | - chmod +x ./gradlew
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ColorPickerPreference
2 | [](https://travis-ci.org/skydoves/ColorPickerPreference)
3 | [](https://android-arsenal.com/api?level=16)
4 | [](https://opensource.org/licenses/Apache-2.0)
5 | [](https://android-arsenal.com/details/1/6759)
6 | [](http://androidweekly.net/issues/issue-297)
7 |
8 | A library that lets you implement ColorPickerView, ColorPickerDialog, ColorPickerPreference.
9 | Could get HSV color, RGB values, Html color code from your gallery pictures or custom images just by touching.
10 |
11 | 
12 | 
13 |
14 | ## Including in your project
15 | [](https://search.maven.org/search?q=g:%22com.github.skydoves%22%20AND%20a:%22colorpickerpreference%22)
16 | [](https://jitpack.io/#skydoves/ColorPickerPreference)
17 |
18 | #### Gradle
19 | Add below codes to your **root** `build.gradle` file (not your module build.gradle file).
20 | ```gradle
21 | allprojects {
22 | repositories {
23 | mavenCentral()
24 | }
25 | }
26 | ```
27 | And add a dependency code to your **module**'s `build.gradle` file.
28 | ```gradle
29 | dependencies {
30 | implementation "com.github.skydoves:colorpickerpreference:2.0.6"
31 | }
32 | ```
33 |
34 | ## Usage
35 | Add following XML namespace inside your XML layout file.
36 |
37 | ```gradle
38 | xmlns:app="http://schemas.android.com/apk/res-auto"
39 | ```
40 |
41 |
42 | ### ColorPickerView in XML layout
43 | We can use `ColorPickerView` without any customized attributes.
44 | This `ColorPickerView` will be initialized with the default HSV color palette and default selector.
45 | ```gradle
46 |
50 | ```
51 |
52 | ### Attribute descriptions
53 | We can customize the palette image and selector or various options using the below attributes.
54 | ```gradle
55 | app:palette="@drawable/palette" // sets a custom palette image.
56 | app:selector="@drawable/wheel" // sets a custom selector image.
57 | app:selector_size="32dp" // sets a width & height size of the selector.
58 | app:alpha_selector="0.8" // sets an alpha of thr selector.
59 | app:alpha_flag="0.8" // sets an alpha of the flag.
60 | app:actionMode="last" // sets action mode 'always' or 'last'.
61 | app:preferenceName="MyColorPicker" // sets a preference name.
62 | app:debounceDuration="200" // sets a debounce duration of the invoking color listener.
63 | ```
64 |
65 | ### ColorListener
66 | `ColorListener` is invoked when tapped by a user or selected a position by a function.
67 | ```java
68 | colorPickerView.setColorListener(new ColorListener() {
69 | @Override
70 | public void onColorSelected(int color, boolean fromUser) {
71 | LinearLayout linearLayout = findViewById(R.id.linearLayout);
72 | linearLayout.setBackgroundColor(color);
73 | }
74 | });
75 | ```
76 |
77 | ### ColorEnvelope
78 | `ColorEnvelope` is a wrapper class of color models for providing more variety of color models.
79 | We can get HSV color value, Hex string code, ARGB value from the `ColorEnvelope`.
80 | ```java
81 | colorEnvelope.getColor() // returns a integer color.
82 | colorEnvelope.getHexCode() // returns a hex code string.
83 | colorEnvelope.getArgb() // returns a argb integer array.
84 | ```
85 |
86 | ### ColorEnvelope Listener
87 | `ColorEnvelopeListener` extends `ColorListener` and it provides `ColorEnvelope` as a parameter.
88 | ```java
89 | colorPickerView.setColorListener(new ColorEnvelopeListener() {
90 | @Override
91 | public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {
92 | linearLayout.setBackgroundColor(envelope.getColor());
93 | textView.setText("#" + envelope.getHexCode());
94 | }
95 | });
96 | ```
97 |
98 | ### Palette
99 | If we do not set any customized palette, the default palette drawable is the `ColorHsvPalette`.
100 | We can move and select a point on the palette using a specific color using the below methods.
101 | ```java
102 | colorPickerView.selectByHsvColor(color);
103 | colorPickerView.selectByHsvColorRes(R.color.colorPrimary);
104 | ```
105 | We can change the default palette as a desired image drawable using the below method.
106 | But if we change the palette using another drawable, we can not use the `selectByHsvColor` method.
107 | ```java
108 | colorPickerView.setPaletteDrawable(drawable);
109 | ```
110 | If we want to change back to the default palette, we can change it using the below method.
111 | ```java
112 | colorPickerView.setHsvPaletteDrawable();
113 | ```
114 |
115 | ### ActionMode
116 | `ActionMode` is an option restrict to invoke the `ColorListener` by user actions.
117 | ```java
118 | colorPickerView.setActionMode(ActionMode.LAST); // ColorListener will be invoked when the finger is released.
119 | ```
120 |
121 | ### Debounce
122 | Only emits color values to the listener if a particular timespan has passed without it emitting using `debounceDuration` attribute.
123 | We can set the `debounceDuration` on our xml layout file.
124 | ```xml
125 | app:debounceDuration="150"
126 | ```
127 | Or we can set it programmatically.
128 | ```java
129 | colorPickerView.setDebounceDuration(150);
130 | ```
131 |
132 | ### Create using builder
133 | This is how to create `ColorPickerView`'s instance using `ColorPickerView.Builder` class.
134 | ```java
135 | ColorPickerView colorPickerView = new ColorPickerView.Builder(context)
136 | .setColorListener(colorListener)
137 | .setPreferenceName("MyColorPicker");
138 | .setActionMode(ActionMode.LAST)
139 | .setAlphaSlideBar(alphaSlideBar)
140 | .setBrightnessSlideBar(brightnessSlideBar)
141 | .setFlagView(new CustomFlag(context, R.layout.layout_flag))
142 | .setPaletteDrawable(ContextCompat.getDrawable(context, R.drawable.palette))
143 | .setSelectorDrawable(ContextCompat.getDrawable(context, R.drawable.selector))
144 | .build();
145 | ```
146 |
147 | ### Restore and save
148 | This is how to restore the state of `ColorPickerView`.
149 | `setPreferenceName()` method restores all of the saved states (selector, color) automatically.
150 |
151 | ```java
152 | colorPickerView.setPreferenceName("MyColorPicker");
153 | ```
154 |
155 | This is how to save the states of `ColorPickerView`.
156 | `setLifecycleOwner()` method saves all of the states automatically when the lifecycleOwner is destroy.
157 | ```java
158 | colorPickerView.setLifecycleOwner(this);
159 | ```
160 | Or we can save the states manually using the below method.
161 | ```java
162 | ColorPickerPreferenceManager.getInstance(this).saveColorPickerData(colorPickerView);
163 | ```
164 |
165 | ### Manipulate and clear
166 | We can manipulate and clear the saved states using `ColorPickerPreferenceManager`.
167 | ```java
168 | ColorPickerPreferenceManager manager = ColorPickerPreferenceManager.getInstance(this);
169 | manager.setColor("MyColorPicker", Color.RED); // manipulates the saved color data.
170 | manager.setSelectorPosition("MyColorPicker", new Point(120, 120)); // manipulates the saved selector's position data.
171 | manager.clearSavedAllData(); // clears all of the states.
172 | manager.clearSavedColor("MyColorPicker"); // clears only saved color data.
173 | manager.restoreColorPickerData(colorPickerView); // restores the saved states manually.
174 | ```
175 |
176 | ### Palette from Gallery
177 | Here is how to get a bitmap drawable from the gallery image and set it to the palette.
178 |
179 |
180 | Declare below permission on your `AndroidManifest.xml` file.
181 | ```gradle
182 |
183 | ```
184 | The below codes will start the Gallery and we can choose the desired image.
185 | ```java
186 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
187 | photoPickerIntent.setType("image/*");
188 | startActivityForResult(photoPickerIntent, REQUEST_CODE_GALLERY);
189 | ```
190 | In the `onActivityResult`, we can get a bitmap drawable from the gallery and set it as the palette. And We can change the palette image of the `ColorPickerView` using the `setPaletteDrawable` method.
191 | ```java
192 | try {
193 | final Uri imageUri = data.getData();
194 | final InputStream imageStream = getContentResolver().openInputStream(imageUri);
195 | final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
196 | Drawable drawable = new BitmapDrawable(getResources(), selectedImage);
197 | colorPickerView.setPaletteDrawable(drawable);
198 | } catch (FileNotFoundException e) {
199 | e.printStackTrace();
200 | }
201 | ```
202 |
203 | ### ColorPickerPreference
204 | ColorPickerPreference is used in PreferenceScreen and shows ColorPickerDialog if be clicked.
205 | ```xml
206 |
231 |
232 |
233 | `AlphaSlideBar` in XML layout
234 | ```gradle
235 | // sets a size of the border.
242 | ```
243 | We can attach and connect the `AlphaSlideBar` to our `ColorPickerView` using `attachAlphaSlider` method.
244 |
245 | ```java
246 | AlphaSlideBar alphaSlideBar = findViewById(R.id.alphaSlideBar);
247 | colorPickerView.attachAlphaSlider(alphaSlideBar);
248 | ```
249 | We can make it vertically using the below attributes.
250 | ```gradle
251 | android:layout_width="280dp" // width must set a specific width size.
252 | android:layout_height="wrap_content"
253 | android:rotation="90"
254 | ```
255 |
256 | ## BrightnessSlideBar
257 | BrightnessSlideBar changes the brightness of the selected color.
258 |
259 |
260 | `BrightnessSlideBar` in XML layout
261 | ```gradle
262 | // sets a size of the border.
269 | ```
270 | We can attach and connect the `BrightnessSlideBar` to our `ColorPickerView` using `attachBrightnessSlider` method.
271 |
272 | ```java
273 | BrightnessSlideBar brightnessSlideBar = findViewById(R.id.brightnessSlide);
274 | colorPickerView.attachBrightnessSlider(brightnessSlideBar);
275 | ```
276 | We can make it vertically using the below attributes.
277 | ```gradle
278 | android:layout_width="280dp" // width must set a specific width size.
279 | android:layout_height="wrap_content"
280 | android:rotation="90"
281 | ```
282 |
283 | ## ColorPickerDialog
284 | 
285 | 
286 |
287 | `ColorPickerDialog` can be used just like an AlertDialog and it provides colors by tapping from any drawable.
288 |
289 | ```java
290 | new ColorPickerDialog.Builder(this)
291 | .setTitle("ColorPicker Dialog")
292 | .setPreferenceName("MyColorPickerDialog")
293 | .setPositiveButton(getString(R.string.confirm),
294 | new ColorEnvelopeListener() {
295 | @Override
296 | public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {
297 | setLayoutColor(envelope);
298 | }
299 | })
300 | .setNegativeButton(getString(R.string.cancel),
301 | new DialogInterface.OnClickListener() {
302 | @Override
303 | public void onClick(DialogInterface dialogInterface, int i) {
304 | dialogInterface.dismiss();
305 | }
306 | })
307 | .attachAlphaSlideBar(true) // the default value is true.
308 | .attachBrightnessSlideBar(true) // the default value is true.
309 | .setBottomSpace(12) // set a bottom space between the last slidebar and buttons.
310 | .show();
311 | ```
312 |
313 | we can get an instance of `ColorPickerView` from the `ColorPickerView.Builder` and we can customize it.
314 | ```java
315 | ColorPickerView colorPickerView = builder.getColorPickerView();
316 | colorPickerView.setFlagView(new CustomFlag(this, R.layout.layout_flag)); // sets a custom flagView
317 | builder.show(); // shows the dialog
318 | ```
319 |
320 | ## FlagView
321 | We can implement showing a `FlagView` above and below on the selector.
322 | This library provides `BubbleFlagView` by default as we can see the [previews](https://github.com/skydoves/ColorPickerView#colorpickerview).
323 | Here is the example code for implementing it.
324 |
325 | ```java
326 | BubbleFlag bubbleFlag = new BubbleFlag(this);
327 | bubbleFlag.setFlagMode(FlagMode.FADE);
328 | colorPickerView.setFlagView(bubbleFlag);
329 | ```
330 |
331 | We can also fully customize the `FlagView` like below.
332 | 
333 | 
334 |
335 | First, We need a customized layout like below.
336 | ```gradle
337 |
338 |
344 |
345 |
352 |
353 |
366 |
367 | ```
368 |
369 | Second, we need to create a class that extends `FlagView`. Here is an example code.
370 | ```java
371 | public class CustomFlag extends FlagView {
372 |
373 | private TextView textView;
374 | private AlphaTileView alphaTileView;
375 |
376 | public CustomFlag(Context context, int layout) {
377 | super(context, layout);
378 | textView = findViewById(R.id.flag_color_code);
379 | alphaTileView = findViewById(R.id.flag_color_layout);
380 | }
381 |
382 | @Override
383 | public void onRefresh(ColorEnvelope colorEnvelope) {
384 | textView.setText("#" + colorEnvelope.getHexCode());
385 | alphaTileView.setPaintColor(colorEnvelope.getColor());
386 | }
387 | }
388 | ```
389 |
390 | And last, set the `FlagView` to the `ColorPickerView` using the `setFlagView` method.
391 |
392 | ```java
393 | colorPickerView.setFlagView(new CustomFlag(this, R.layout.layout_flag));
394 | ```
395 |
396 | ### FlagMode
397 | `FlagMode` is an option to decides the visibility action of the `FlagView`.
398 | ```java
399 | colorPickerView.setFlagMode(FlagMode.ALWAYS); // showing always by tapping and dragging.
400 | colorPickerView.setFlagMode(FlagMode.LAST); // showing only when finger released.
401 | ```
402 |
403 | ## AlphaTileView
404 | 
405 | `AlphaTileView` visualizes ARGB colors over the view.
406 | If we need to represent ARGB colors on the general view, it will not be showing accurately. Because a color will be mixed with the parent view's background color. so if we need to represent ARGB colors accurately, we can use the `AlphaTileView`.
407 |
408 | ```gradle
409 | // the color of odd tiles
416 | ```
417 |
418 | ### ColorPickerView Methods
419 | Methods | Return | Description
420 | --- | --- | ---
421 | getColor() | int | gets the last selected color.
422 | getColorEnvelope() | ColorEnvelope | gets the `ColorEnvelope` of the last selected color.
423 | setPaletteDrawable(Drawable drawable) | void | changes palette drawable manually.
424 | setSelectorDrawable(Drawable drawable) | void | changes selector drawable manually.
425 | setSelectorPoint(int x, int y) | void | selects the specific coordinate of the palette manually.
426 | selectByHsvColor(@ColorInt int color) | void | changes selector's selected point by a specific color.
427 | selectByHsvColorRes(@ColorRes int resource) | void | changes selector's selected point by a specific color using a color resource.
428 | setHsvPaletteDrawable() | void | changes the palette drawable as the default drawable (ColorHsvPalette).
429 | selectCenter() | void | selects the center of the palette manually.
430 | setActionMode(ActionMode) | void | sets the color listener's trigger action mode.
431 | setFlagView(FlagView flagView) | void | sets `FlagView` on `ColorPickerView`.
432 | attachAlphaSlider | void | linking an `AlphaSlideBar` on the `ColorPickerView`.
433 | attachBrightnessSlider | void | linking an `BrightnessSlideBar` on the `ColorPickerView`.
434 |
435 | #### ColorPickerPreference
436 | Methods | Return | Description
437 | --- | --- | ---
438 | setColorPickerDialogBuilder(ColorPickerDialog.Builder builder) | void | sets ColorPickerDialog.Builder as your own build
439 | getColorPickerDialogBuilder() | ColorPickerDialog.Builder | returns ColorPickerDialog.Builder
440 |
441 | ## Posting & Blog
442 | - [Android Weekly #297](http://androidweekly.net/issues/issue-297)
443 | - [25 new Android libraries, projects and tools worthy to check in Spring 2018](https://medium.com/@mmbialas/25-new-android-libraries-projects-and-tools-worthy-to-check-in-spring-2018-68e3c5e93568)
444 | - [Colour Wheel – Part 1](https://blog.stylingandroid.com/colour-wheel-part-1)
445 | - [Using ColorPickerPreference library in Android Studio - Youtube](https://www.youtube.com/watch?v=_q7a0EPbGvU)
446 |
447 | ## Find this library useful? :heart:
448 | Support it by joining [stargazers](https://github.com/skydoves/ColorPickerPreference/stargazers) for this repository. :star:
449 |
450 | ## Supports :coffee:
451 | If you feel like support me a coffee for my efforts, I would greatly appreciate it.
452 |
453 |
454 | # License
455 | ```xml
456 | Copyright 2018 skydoves
457 |
458 | Licensed under the Apache License, Version 2.0 (the "License");
459 | you may not use this file except in compliance with the License.
460 | You may obtain a copy of the License at
461 |
462 | http://www.apache.org/licenses/LICENSE-2.0
463 |
464 | Unless required by applicable law or agreed to in writing, software
465 | distributed under the License is distributed on an "AS IS" BASIS,
466 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
467 | See the License for the specific language governing permissions and
468 | limitations under the License.
469 | ```
470 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply from: '../dependencies.gradle'
4 |
5 | android {
6 | compileSdkVersion versions.compileSdk
7 | defaultConfig {
8 | applicationId "com.skydoves.colorpickerpreferencedemo"
9 | minSdkVersion versions.minSdk
10 | targetSdkVersion versions.compileSdk
11 | versionCode versions.versionCode
12 | versionName versions.versionName
13 | }
14 | lintOptions {
15 | abortOnError false
16 | }
17 | compileOptions {
18 | sourceCompatibility JavaVersion.VERSION_1_8
19 | targetCompatibility JavaVersion.VERSION_1_8
20 | }
21 | buildFeatures {
22 | viewBinding true
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation "com.google.android.material:material:$versions.googleMaterial"
28 | implementation "com.github.skydoves:elasticviews:$versions.elasticViews"
29 | implementation "androidx.preference:preference-ktx:$versions.preference"
30 | implementation "com.github.skydoves:powermenu:$versions.powerMenu"
31 | implementation project(":colorpickerpreference")
32 | }
33 |
34 | apply from: '../spotless.gradle'
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/BaseActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.content.SharedPreferences
20 | import android.os.Bundle
21 | import android.view.View
22 | import android.widget.ImageView
23 | import android.widget.TextView
24 | import androidx.appcompat.app.AppCompatActivity
25 | import androidx.appcompat.widget.Toolbar
26 | import androidx.core.content.ContextCompat
27 | import androidx.preference.PreferenceManager
28 |
29 | open class BaseActivity : AppCompatActivity() {
30 |
31 | private lateinit var sharedPreferences: SharedPreferences
32 |
33 | override fun onCreate(savedInstanceState: Bundle?) {
34 | super.onCreate(savedInstanceState)
35 | sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
36 | }
37 |
38 | fun setToolbarTitle(title: String) {
39 | val toolbar = findViewById(R.id.toolbar)
40 | val textView = toolbar.findViewById(R.id.toolbar_title)
41 | textView.text = title
42 |
43 | val back = toolbar.findViewById(R.id.toolbar_home)
44 | back.setOnClickListener { finish() }
45 | }
46 |
47 | override fun onResume() {
48 | super.onResume()
49 | setToolbarColor()
50 | setBackgroundColor()
51 | }
52 |
53 | /** set toolbar color from DefaultSharedPreferences(PreferenceScreen) */
54 | private fun setToolbarColor() {
55 | val toolbar = findViewById(R.id.toolbar)
56 | toolbar.setBackgroundColor(
57 | sharedPreferences.getInt(
58 | getString(R.string.ToolbarColorPickerPreference),
59 | ContextCompat.getColor(baseContext, R.color.colorPrimary)
60 | )
61 | )
62 | }
63 |
64 | /** set background color from DefaultSharedPreferences(PreferenceScreen) */
65 | private fun setBackgroundColor() {
66 | val view = findViewById(R.id.layout_background)
67 | view?.setBackgroundColor(
68 | sharedPreferences.getInt(
69 | getString(R.string.BackgroundColorPickerPreference),
70 | ContextCompat.getColor(baseContext, R.color.background)
71 | )
72 | )
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/ColorPickerDialogActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.annotation.SuppressLint
20 | import android.os.Bundle
21 | import android.view.View
22 | import android.widget.LinearLayout
23 | import android.widget.TextView
24 | import com.skydoves.colorpickerview.ColorEnvelope
25 | import com.skydoves.colorpickerview.ColorPickerDialog
26 | import com.skydoves.colorpickerview.flag.BubbleFlag
27 | import com.skydoves.colorpickerview.flag.FlagMode
28 | import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
29 |
30 | class ColorPickerDialogActivity : BaseActivity() {
31 |
32 | override fun onCreate(savedInstanceState: Bundle?) {
33 | super.onCreate(savedInstanceState)
34 | setContentView(R.layout.activity_color_picker_dialog)
35 | setToolbarTitle("ColorPickerDialogActivity")
36 | }
37 |
38 | fun showDialog(view: View) {
39 | val builder = ColorPickerDialog.Builder(this)
40 | .setTitle("ColorPicker Dialog")
41 | .setPreferenceName("Test")
42 | .setPositiveButton(
43 | getString(R.string.confirm),
44 | ColorEnvelopeListener { envelope, _ -> setLayoutColor(envelope) }
45 | )
46 | .setNegativeButton(
47 | getString(R.string.cancel)
48 | ) { dialogInterface, i -> dialogInterface.dismiss() }
49 | builder.colorPickerView.flagView = BubbleFlag(this).apply { flagMode = FlagMode.FADE }
50 | builder.show()
51 | }
52 |
53 | @SuppressLint("SetTextI18n")
54 | private fun setLayoutColor(envelope: ColorEnvelope) {
55 | val textView = findViewById(R.id.textView)
56 | textView.text = "#${envelope.hexCode}"
57 |
58 | val linearLayout = findViewById(R.id.linearLayout)
59 | linearLayout.setBackgroundColor(envelope.color)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/ColorPickerViewActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.annotation.SuppressLint
20 | import android.app.Activity
21 | import android.content.Intent
22 | import android.graphics.BitmapFactory
23 | import android.graphics.drawable.BitmapDrawable
24 | import android.os.Bundle
25 | import android.view.View
26 | import android.widget.TextView
27 | import androidx.appcompat.app.AppCompatActivity
28 | import androidx.core.content.ContextCompat
29 | import com.skydoves.colorpickerpreferencedemo.databinding.ActivityColorPickerViewBinding
30 | import com.skydoves.colorpickerview.AlphaTileView
31 | import com.skydoves.colorpickerview.ColorEnvelope
32 | import com.skydoves.colorpickerview.ColorPickerDialog
33 | import com.skydoves.colorpickerview.flag.BubbleFlag
34 | import com.skydoves.colorpickerview.flag.FlagMode
35 | import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
36 | import com.skydoves.colorpickerview.sliders.AlphaSlideBar
37 | import com.skydoves.colorpickerview.sliders.BrightnessSlideBar
38 | import com.skydoves.powermenu.OnMenuItemClickListener
39 | import com.skydoves.powermenu.PowerMenu
40 | import com.skydoves.powermenu.PowerMenuItem
41 | import java.io.FileNotFoundException
42 |
43 | class ColorPickerViewActivity : AppCompatActivity() {
44 |
45 | private var flagPalette = false
46 | private var flagSelector = false
47 |
48 | private val powerMenu: PowerMenu by lazy {
49 | PowerMenuUtils.getPowerMenu(this, this, powerMenuItemClickListener)
50 | }
51 | private val powerMenuItemClickListener = OnMenuItemClickListener { position, _ ->
52 | when (position) {
53 | 1 -> palette()
54 | 2 -> paletteFromGallery()
55 | 3 -> selector()
56 | 4 -> dialog()
57 | }
58 | powerMenu.dismiss()
59 | }
60 |
61 | private lateinit var binding: ActivityColorPickerViewBinding
62 |
63 | override fun onCreate(savedInstanceState: Bundle?) {
64 | super.onCreate(savedInstanceState)
65 |
66 | binding = ActivityColorPickerViewBinding.inflate(layoutInflater)
67 | setContentView(binding.root)
68 |
69 | with(binding) {
70 | colorPickerView.setColorListener(
71 | ColorEnvelopeListener { envelope, _ -> setLayoutColor(envelope) }
72 | )
73 |
74 | // set a bubble flagView
75 | colorPickerView.flagView = BubbleFlag(this@ColorPickerViewActivity).apply { flagMode = FlagMode.FADE }
76 |
77 | // attach alphaSlideBar
78 | val alphaSlideBar = findViewById(R.id.alphaSlideBar)
79 | colorPickerView.attachAlphaSlider(alphaSlideBar)
80 |
81 | // attach brightnessSlideBar
82 | val brightnessSlideBar = findViewById(R.id.brightnessSlide)
83 | colorPickerView.attachBrightnessSlider(brightnessSlideBar)
84 | colorPickerView.setLifecycleOwner(this@ColorPickerViewActivity)
85 | }
86 | }
87 |
88 | /**
89 | * set layout color & textView html code
90 | *
91 | * @param envelope ColorEnvelope by ColorEnvelopeListener
92 | */
93 | @SuppressLint("SetTextI18n")
94 | private fun setLayoutColor(envelope: ColorEnvelope) {
95 | val textView = findViewById(R.id.textView)
96 | textView.text = "#${envelope.hexCode}"
97 |
98 | val alphaTileView = findViewById(R.id.alphaTileView)
99 | alphaTileView.setPaintColor(envelope.color)
100 | }
101 |
102 | /** shows the popup menu for changing options.. */
103 | fun overflowMenu(view: View) {
104 | powerMenu.showAsAnchorLeftTop(view)
105 | }
106 |
107 | /** changes palette image using drawable resource. */
108 | private fun palette() {
109 | if (flagPalette) {
110 | binding.colorPickerView.setPaletteDrawable(ContextCompat.getDrawable(this, R.drawable.palette)!!)
111 | } else {
112 | binding.colorPickerView.setPaletteDrawable(ContextCompat.getDrawable(this, R.drawable.palettebar)!!)
113 | }
114 | flagPalette = !flagPalette
115 | }
116 |
117 | /** changes palette image from a gallery image. */
118 | private fun paletteFromGallery() {
119 | val photoPickerIntent = Intent(Intent.ACTION_PICK)
120 | photoPickerIntent.type = "image/*"
121 | startActivityForResult(photoPickerIntent, 1000)
122 | }
123 |
124 | /** changes selector image using drawable resource. */
125 | private fun selector() {
126 | if (flagSelector) {
127 | binding.colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, R.drawable.wheel)!!)
128 | } else {
129 | binding.colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, R.drawable.wheel_dark)!!)
130 | }
131 | flagSelector = !flagSelector
132 | }
133 |
134 | /** shows ColorPickerDialog */
135 | private fun dialog() {
136 | val builder = ColorPickerDialog.Builder(this)
137 | .setTitle("ColorPicker Dialog")
138 | .setPreferenceName("Test")
139 | .setPositiveButton(
140 | getString(R.string.confirm),
141 | ColorEnvelopeListener { envelope, _ -> setLayoutColor(envelope) }
142 | )
143 | .setNegativeButton(
144 | getString(R.string.cancel)
145 | ) { dialogInterface, _ -> dialogInterface.dismiss() }
146 | val colorPickerView = builder.colorPickerView
147 | colorPickerView.flagView = CustomFlag(this, R.layout.layout_flag)
148 | builder.show()
149 | }
150 |
151 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
152 | super.onActivityResult(requestCode, resultCode, data)
153 |
154 | // user choose a picture from gallery
155 | if (requestCode == 1000 && resultCode == Activity.RESULT_OK) {
156 | try {
157 | val imageUri = data!!.data
158 | val imageStream = contentResolver.openInputStream(imageUri!!)
159 | val selectedImage = BitmapFactory.decodeStream(imageStream)
160 | val drawable = BitmapDrawable(resources, selectedImage)
161 | binding.colorPickerView.setPaletteDrawable(drawable)
162 | } catch (e: FileNotFoundException) {
163 | e.printStackTrace()
164 | }
165 | }
166 | }
167 |
168 | override fun onBackPressed() {
169 | if (powerMenu.isShowing)
170 | powerMenu.dismiss()
171 | else
172 | super.onBackPressed()
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/CustomFlag.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.annotation.SuppressLint
20 | import android.content.Context
21 | import android.view.View
22 | import android.widget.TextView
23 | import com.skydoves.colorpickerview.ColorEnvelope
24 | import com.skydoves.colorpickerview.flag.FlagView
25 |
26 | /**
27 | * onBind Views
28 | *
29 | * @param context context
30 | * @param layout custom flagView's layout
31 | */
32 | @SuppressLint("ViewConstructor")
33 | class CustomFlag(context: Context, layout: Int) : FlagView(context, layout) {
34 |
35 | private val textView: TextView = findViewById(R.id.flag_color_code)
36 | private val view: View = findViewById(R.id.flag_color_layout)
37 |
38 | /**
39 | * invoked when selector moved
40 | *
41 | * @param colorEnvelope provide color, htmlCode, rgb
42 | */
43 | @SuppressLint("SetTextI18n")
44 | override fun onRefresh(colorEnvelope: ColorEnvelope) {
45 | textView.text = "#${colorEnvelope.hexCode}"
46 | view.setBackgroundColor(colorEnvelope.color)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.content.Intent
20 | import android.os.Bundle
21 | import android.view.View
22 |
23 | class MainActivity : BaseActivity() {
24 |
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | setContentView(R.layout.activity_main)
28 | setToolbarTitle("ColorPreference Demo")
29 | }
30 |
31 | fun example0(view: View) {
32 | startActivity(Intent(this, ColorPickerViewActivity::class.java))
33 | }
34 |
35 | fun example1(view: View) {
36 | startActivity(Intent(this, ColorPickerDialogActivity::class.java))
37 | }
38 |
39 | fun example2(view: View) {
40 | startActivity(Intent(this, PreferenceActivity::class.java))
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/PowerMenuUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.content.Context
20 | import android.graphics.Color
21 | import androidx.core.content.ContextCompat
22 | import androidx.lifecycle.LifecycleOwner
23 | import com.skydoves.powermenu.CircularEffect
24 | import com.skydoves.powermenu.MenuAnimation
25 | import com.skydoves.powermenu.OnMenuItemClickListener
26 | import com.skydoves.powermenu.PowerMenu
27 | import com.skydoves.powermenu.PowerMenuItem
28 |
29 | object PowerMenuUtils {
30 | fun getPowerMenu(
31 | context: Context,
32 | lifecycleOwner: LifecycleOwner,
33 | onMenuItemClickListener: OnMenuItemClickListener
34 | ): PowerMenu {
35 | return PowerMenu.Builder(context)
36 | .setHeaderView(R.layout.layout_header)
37 | .addItem(PowerMenuItem("Palette", false))
38 | .addItem(PowerMenuItem("Palette(Gallery)", false))
39 | .addItem(PowerMenuItem("Selector", false))
40 | .addItem(PowerMenuItem("Dialog", false))
41 | .setLifecycleOwner(lifecycleOwner)
42 | .setAnimation(MenuAnimation.SHOWUP_TOP_LEFT)
43 | .setCircularEffect(CircularEffect.BODY)
44 | .setMenuRadius(10f)
45 | .setMenuShadow(10f)
46 | .setTextColor(ContextCompat.getColor(context, R.color.md_grey_800))
47 | .setSelectedEffect(false)
48 | .setShowBackground(false)
49 | .setMenuColor(Color.WHITE)
50 | .setOnMenuItemClickListener(onMenuItemClickListener)
51 | .build()
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/PreferenceActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.os.Bundle
20 | import androidx.appcompat.app.AppCompatActivity
21 |
22 | class PreferenceActivity : AppCompatActivity() {
23 |
24 | override fun onCreate(savedInstanceState: Bundle?) {
25 | super.onCreate(savedInstanceState)
26 |
27 | supportFragmentManager
28 | .beginTransaction()
29 | .replace(android.R.id.content, PreferenceFragment())
30 | .commit()
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/skydoves/colorpickerpreferencedemo/PreferenceFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | package com.skydoves.colorpickerpreferencedemo
18 |
19 | import android.os.Bundle
20 | import android.widget.Toast
21 | import androidx.preference.PreferenceFragmentCompat
22 | import com.skydoves.colorpickerpreference.ColorPickerPreference
23 | import com.skydoves.colorpickerview.ColorPickerDialog
24 | import com.skydoves.colorpickerview.flag.BubbleFlag
25 | import com.skydoves.colorpickerview.flag.FlagMode
26 | import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
27 |
28 | class PreferenceFragment : PreferenceFragmentCompat() {
29 |
30 | override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
31 | addPreferencesFromResource(R.xml.pref_settings)
32 | initColorPickerPreference()
33 | }
34 |
35 | /** customizes [ColorPickerPreference]'s [ColorPickerDialog]. */
36 | private fun initColorPickerPreference() {
37 | /** sets custom flag to the color picker. */
38 | val colorPickerPreferenceToolbar = findPreference(
39 | requireContext().getString(R.string.ToolbarColorPickerPreference)
40 | )
41 | val colorPickerView = colorPickerPreferenceToolbar?.getColorPickerView()
42 | colorPickerView?.flagView = BubbleFlag(requireContext()).apply { flagMode = FlagMode.FADE }
43 |
44 | val colorPickerPreferenceBackground = findPreference(
45 | requireContext().getString(R.string.BackgroundColorPickerPreference)
46 | )
47 | colorPickerPreferenceBackground?.getColorPickerView()?.flagView = CustomFlag(requireContext(), R.layout.layout_flag)
48 | colorPickerPreferenceBackground?.preferenceColorListener = ColorEnvelopeListener { envelope, _ ->
49 | Toast.makeText(requireContext(), "background color: #${envelope.hexCode} is selected", Toast.LENGTH_SHORT).show()
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-hdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_list_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-hdpi/ic_list_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-mdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_list_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-mdpi/ic_list_white_24dp.png
--------------------------------------------------------------------------------
/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-xhdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-xhdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_list_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-xhdpi/ic_list_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-xxhdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_list_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-xxhdpi/ic_list_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-xxxhdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_list_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable-xxxhdpi/ic_list_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/flag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable/flag.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_info_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/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/drawable/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sync_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/palettebar.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable/palettebar.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/watercolor.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable/watercolor.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/wheel_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/drawable/wheel_dark.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_color_picker_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
16 |
17 |
25 |
26 |
34 |
35 |
36 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_color_picker_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
18 |
19 |
29 |
30 |
38 |
39 |
40 |
41 |
46 |
47 |
56 |
57 |
63 |
64 |
72 |
73 |
74 |
80 |
81 |
88 |
89 |
90 |
96 |
97 |
105 |
106 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
18 |
19 |
28 |
29 |
39 |
40 |
41 |
45 |
46 |
55 |
56 |
65 |
66 |
67 |
71 |
72 |
81 |
82 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_flag.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/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-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #D50000
4 | #B71C1C
5 | #D50000
6 |
7 |
8 | #FFEBEE
9 | #FFCDD2
10 | #EF9A9A
11 | #E57373
12 | #EF5350
13 | #F44336
14 | #E53935
15 | #D32F2F
16 | #C62828
17 | #B71C1C
18 | #FF8A80
19 | #FF5252
20 | #FF1744
21 | #D50000
22 |
23 |
24 | #FCE4EC
25 | #F8BBD0
26 | #F48FB1
27 | #F06292
28 | #EC407A
29 | #E91E63
30 | #D81B60
31 | #C2185B
32 | #AD1457
33 | #880E4F
34 | #FF80AB
35 | #FF4081
36 | #F50057
37 | #C51162
38 |
39 |
40 | #F3E5F5
41 | #E1BEE7
42 | #CE93D8
43 | #BA68C8
44 | #AB47BC
45 | #9C27B0
46 | #8E24AA
47 | #7B1FA2
48 | #6A1B9A
49 | #4A148C
50 | #EA80FC
51 | #E040FB
52 | #D500F9
53 | #AA00FF
54 |
55 |
56 | #EDE7F6
57 | #D1C4E9
58 | #B39DDB
59 | #9575CD
60 | #7E57C2
61 | #673AB7
62 | #5E35B1
63 | #512DA8
64 | #4527A0
65 | #311B92
66 | #B388FF
67 | #7C4DFF
68 | #651FFF
69 | #6200EA
70 |
71 |
72 | #E8EAF6
73 | #C5CAE9
74 | #9FA8DA
75 | #7986CB
76 | #5C6BC0
77 | #3F51B5
78 | #3949AB
79 | #303F9F
80 | #283593
81 | #1A237E
82 | #8C9EFF
83 | #536DFE
84 | #3D5AFE
85 | #304FFE
86 |
87 |
88 | #E3F2FD
89 | #BBDEFB
90 | #90CAF9
91 | #64B5F6
92 | #42A5F5
93 | #2196F3
94 | #1E88E5
95 | #1976D2
96 | #1565C0
97 | #0D47A1
98 | #82B1FF
99 | #448AFF
100 | #2979FF
101 | #2962FF
102 |
103 |
104 | #E1F5FE
105 | #B3E5FC
106 | #81D4fA
107 | #4fC3F7
108 | #29B6FC
109 | #03A9F4
110 | #039BE5
111 | #0288D1
112 | #0277BD
113 | #01579B
114 | #80D8FF
115 | #40C4FF
116 | #00B0FF
117 | #0091EA
118 |
119 |
120 | #E0F7FA
121 | #B2EBF2
122 | #80DEEA
123 | #4DD0E1
124 | #26C6DA
125 | #00BCD4
126 | #00ACC1
127 | #0097A7
128 | #00838F
129 | #006064
130 | #84FFFF
131 | #18FFFF
132 | #00E5FF
133 | #00B8D4
134 |
135 |
136 | #E0F2F1
137 | #B2DFDB
138 | #80CBC4
139 | #4DB6AC
140 | #26A69A
141 | #009688
142 | #00897B
143 | #00796B
144 | #00695C
145 | #004D40
146 | #A7FFEB
147 | #64FFDA
148 | #1DE9B6
149 | #00BFA5
150 |
151 |
152 | #E8F5E9
153 | #C8E6C9
154 | #A5D6A7
155 | #81C784
156 | #66BB6A
157 | #4CAF50
158 | #43A047
159 | #388E3C
160 | #2E7D32
161 | #1B5E20
162 | #B9F6CA
163 | #69F0AE
164 | #00E676
165 | #00C853
166 |
167 |
168 | #F1F8E9
169 | #DCEDC8
170 | #C5E1A5
171 | #AED581
172 | #9CCC65
173 | #8BC34A
174 | #7CB342
175 | #689F38
176 | #558B2F
177 | #33691E
178 | #CCFF90
179 | #B2FF59
180 | #76FF03
181 | #64DD17
182 |
183 |
184 | #F9FBE7
185 | #F0F4C3
186 | #E6EE9C
187 | #DCE775
188 | #D4E157
189 | #CDDC39
190 | #C0CA33
191 | #A4B42B
192 | #9E9D24
193 | #827717
194 | #F4FF81
195 | #EEFF41
196 | #C6FF00
197 | #AEEA00
198 |
199 |
200 | #FFFDE7
201 | #FFF9C4
202 | #FFF590
203 | #FFF176
204 | #FFEE58
205 | #FFEB3B
206 | #FDD835
207 | #FBC02D
208 | #F9A825
209 | #F57F17
210 | #FFFF82
211 | #FFFF00
212 | #FFEA00
213 | #FFD600
214 |
215 |
216 | #FFF8E1
217 | #FFECB3
218 | #FFE082
219 | #FFD54F
220 | #FFCA28
221 | #FFC107
222 | #FFB300
223 | #FFA000
224 | #FF8F00
225 | #FF6F00
226 | #FFE57F
227 | #FFD740
228 | #FFC400
229 | #FFAB00
230 |
231 |
232 | #FFF3E0
233 | #FFE0B2
234 | #FFCC80
235 | #FFB74D
236 | #FFA726
237 | #FF9800
238 | #FB8C00
239 | #F57C00
240 | #EF6C00
241 | #E65100
242 | #FFD180
243 | #FFAB40
244 | #FF9100
245 | #FF6D00
246 |
247 |
248 | #FBE9A7
249 | #FFCCBC
250 | #FFAB91
251 | #FF8A65
252 | #FF7043
253 | #FF5722
254 | #F4511E
255 | #E64A19
256 | #D84315
257 | #BF360C
258 | #FF9E80
259 | #FF6E40
260 | #FF3D00
261 | #DD2600
262 |
263 |
264 | #EFEBE9
265 | #D7CCC8
266 | #BCAAA4
267 | #A1887F
268 | #8D6E63
269 | #795548
270 | #6D4C41
271 | #5D4037
272 | #4E342E
273 | #3E2723
274 |
275 |
276 | #FAFAFA
277 | #F5F5F5
278 | #EEEEEE
279 | #E0E0E0
280 | #BDBDBD
281 | #9E9E9E
282 | #757575
283 | #616161
284 | #424242
285 | #212121
286 | #000000
287 | #ffffff
288 |
289 |
290 | #ECEFF1
291 | #CFD8DC
292 | #B0BBC5
293 | #90A4AE
294 | #78909C
295 | #607D8B
296 | #546E7A
297 | #455A64
298 | #37474F
299 | #263238
300 | #303030
301 | #424242
302 | #212121
303 |
304 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ColorPickerPreferenceDemo
3 | Ok
4 | Cancel
5 | Options
6 | ToolbarColorPickerPreference
7 | BackgroundColorPickerPreference
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/pref_settings.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
9 |
10 |
15 |
16 |
30 |
31 |
41 |
42 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | apply from: './dependencies.gradle'
3 |
4 | repositories {
5 | google()
6 | mavenCentral()
7 | jcenter()
8 | }
9 |
10 | dependencies {
11 | classpath "com.android.tools.build:gradle:$versions.gradleBuildTool"
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
13 | classpath "com.diffplug.spotless:spotless-plugin-gradle:$versions.spotlessGradle"
14 | classpath "com.vanniktech:gradle-maven-publish-plugin:$versions.mavenPublish"
15 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$versions.dokkaGradle"
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | mavenCentral()
23 | jcenter()
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/colorpickerpreference/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/colorpickerpreference/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply from: '../dependencies.gradle'
4 |
5 | android {
6 | compileSdkVersion versions.compileSdk
7 | defaultConfig {
8 | minSdkVersion versions.minSdk
9 | targetSdkVersion versions.compileSdk
10 | versionCode versions.versionCode
11 | versionName versions.versionName
12 | }
13 | buildFeatures {
14 | buildConfig false
15 | }
16 | }
17 |
18 | dependencies {
19 | implementation "androidx.annotation:annotation:$versions.annotation"
20 | implementation "androidx.preference:preference-ktx:$versions.preference"
21 | api "com.github.skydoves:colorpickerview:$versions.colorpickerView"
22 | }
23 |
24 | apply plugin: "com.vanniktech.maven.publish"
25 | apply from: '../spotless.gradle'
26 |
--------------------------------------------------------------------------------
/colorpickerpreference/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
17 | @file:Suppress("unused", "MemberVisibilityCanBePrivate")
18 |
19 | package com.skydoves.colorpickerpreference
20 |
21 | import android.content.Context
22 | import android.content.res.TypedArray
23 | import android.graphics.Color
24 | import android.graphics.drawable.Drawable
25 | import android.graphics.drawable.GradientDrawable
26 | import android.util.AttributeSet
27 | import android.view.View
28 | import androidx.appcompat.app.AlertDialog
29 | import androidx.core.content.edit
30 | import androidx.preference.Preference
31 | import androidx.preference.PreferenceViewHolder
32 | import com.skydoves.colorpickerview.ColorEnvelope
33 | import com.skydoves.colorpickerview.ColorPickerDialog
34 | import com.skydoves.colorpickerview.ColorPickerView
35 | import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
36 | import com.skydoves.colorpickerview.listeners.ColorListener
37 | import com.skydoves.colorpickerview.listeners.ColorPickerViewListener
38 |
39 | /**
40 | * ColorPickerPreference is a preference for persisting a chosen color by users.
41 | * We can show a [ColorPickerDialog] and customize the dialog and [ColorPickerView].
42 | */
43 | class ColorPickerPreference : Preference {
44 |
45 | private lateinit var colorBox: View
46 | private lateinit var preferenceDialog: AlertDialog
47 | private lateinit var preferenceColorPickerView: ColorPickerView
48 |
49 | var preferenceColorListener: ColorPickerViewListener? = null
50 | var defaultColor: Int = Color.BLACK
51 | var cornerRadius: Int = 0
52 | var paletteDrawable: Drawable? = null
53 | var selectorDrawable: Drawable? = null
54 | var dialogTitle: String? = null
55 | var positive: String? = null
56 | var negative: String? = null
57 | var attachAlphaSlideBar = true
58 | var attachBrightnessSlideBar = true
59 |
60 | constructor(context: Context) : super(context)
61 |
62 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
63 | getAttrs(attrs)
64 | onInit()
65 | }
66 |
67 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
68 | context,
69 | attrs,
70 | defStyleAttr
71 | ) {
72 | getAttrs(attrs, defStyleAttr)
73 | onInit()
74 | }
75 |
76 | private fun getAttrs(attrs: AttributeSet) {
77 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference)
78 | try {
79 | setTypeArray(typedArray)
80 | } finally {
81 | typedArray.recycle()
82 | }
83 | }
84 |
85 | private fun getAttrs(attrs: AttributeSet, defStyle: Int) {
86 | val typedArray =
87 | context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference, defStyle, 0)
88 | try {
89 | setTypeArray(typedArray)
90 | } finally {
91 | typedArray.recycle()
92 | }
93 | }
94 |
95 | private fun setTypeArray(typedArray: TypedArray) {
96 | defaultColor =
97 | typedArray.getColor(R.styleable.ColorPickerPreference_default_color, defaultColor)
98 | cornerRadius =
99 | typedArray.getDimensionPixelSize(R.styleable.ColorPickerPreference_preference_colorBox_radius, cornerRadius)
100 | paletteDrawable = typedArray.getDrawable(R.styleable.ColorPickerPreference_preference_palette)
101 | selectorDrawable = typedArray.getDrawable(R.styleable.ColorPickerPreference_preference_selector)
102 | dialogTitle = typedArray.getString(R.styleable.ColorPickerPreference_preference_dialog_title)
103 | positive = typedArray.getString(R.styleable.ColorPickerPreference_preference_dialog_positive)
104 | negative = typedArray.getString(R.styleable.ColorPickerPreference_preference_dialog_negative)
105 | attachAlphaSlideBar =
106 | typedArray.getBoolean(
107 | R.styleable.ColorPickerPreference_preference_attachAlphaSlideBar,
108 | attachAlphaSlideBar
109 | )
110 | attachBrightnessSlideBar =
111 | typedArray.getBoolean(
112 | R.styleable.ColorPickerPreference_preference_attachBrightnessSlideBar,
113 | attachBrightnessSlideBar
114 | )
115 | }
116 |
117 | fun onInit() {
118 | widgetLayoutResource = R.layout.layout_colorpicker_preference
119 | preferenceDialog = ColorPickerDialog.Builder(context).apply {
120 | setTitle(dialogTitle)
121 | setPositiveButton(
122 | positive,
123 | ColorEnvelopeListener { envelope, _ ->
124 | if (colorBox.background is GradientDrawable) {
125 | (colorBox.background as GradientDrawable).setColor(envelope.color)
126 | notifyColorChanged(envelope)
127 | preferenceManager
128 | .sharedPreferences.edit {
129 | putInt(key, envelope.color)
130 | }
131 | }
132 | }
133 | )
134 | setNegativeButton(negative) { dialogInterface, _ -> dialogInterface.dismiss() }
135 | attachAlphaSlideBar(attachAlphaSlideBar)
136 | attachBrightnessSlideBar(attachBrightnessSlideBar)
137 | this@ColorPickerPreference.preferenceColorPickerView = this.colorPickerView.apply {
138 | paletteDrawable?.let { setPaletteDrawable(it) }
139 | selectorDrawable?.let { setSelectorDrawable(it) }
140 | preferenceName = key
141 | setInitialColor(defaultColor)
142 | }
143 | }.create()
144 | }
145 |
146 | private fun notifyColorChanged(envelope: ColorEnvelope) {
147 | preferenceColorListener?.let {
148 | if (it is ColorListener) {
149 | it.onColorSelected(envelope.color, true)
150 | } else if (it is ColorEnvelopeListener) {
151 | it.onColorSelected(envelope, true)
152 | }
153 | }
154 | }
155 |
156 | override fun onBindViewHolder(holder: PreferenceViewHolder) {
157 | super.onBindViewHolder(holder)
158 | colorBox = holder.findViewById(R.id.preference_colorBox)
159 | colorBox.background = GradientDrawable().apply {
160 | cornerRadius = this@ColorPickerPreference.cornerRadius.toFloat()
161 | setColor(
162 | if (key == null) {
163 | this@ColorPickerPreference.defaultColor
164 | } else {
165 | preferenceManager.sharedPreferences.getInt(key, this@ColorPickerPreference.defaultColor)
166 | }
167 | )
168 | }
169 | }
170 |
171 | override fun onClick() {
172 | super.onClick()
173 | preferenceDialog.show()
174 | }
175 |
176 | /** gets an [AlertDialog] that created by preferences. */
177 | fun getPreferenceDialog(): AlertDialog = preferenceDialog
178 |
179 | /** gets a [ColorPickerView] that created by preferences. */
180 | fun getColorPickerView(): ColorPickerView = preferenceColorPickerView
181 | }
182 |
--------------------------------------------------------------------------------
/colorpickerpreference/src/main/res/drawable/palette.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/colorpickerpreference/src/main/res/drawable/palette.png
--------------------------------------------------------------------------------
/colorpickerpreference/src/main/res/drawable/wheel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/colorpickerpreference/src/main/res/drawable/wheel.png
--------------------------------------------------------------------------------
/colorpickerpreference/src/main/res/layout/layout_colorpicker_preference.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/colorpickerpreference/src/main/res/values/attrs_colorpicker.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/dependencies.gradle:
--------------------------------------------------------------------------------
1 | ext.versions = [
2 | minSdk : 16,
3 | compileSdk : 31,
4 | versionCode : 17,
5 | versionName : '2.0.6',
6 |
7 | gradleBuildTool : '7.0.2',
8 | spotlessGradle : '5.14.0',
9 | ktlintGradle : '0.41.0',
10 | dokkaGradle : '1.4.32',
11 | mavenPublish : '0.15.1',
12 |
13 | kotlin : '1.4.31',
14 | preference : '1.1.1',
15 | annotation : '1.3.0',
16 | colorpickerView: '2.2.3',
17 |
18 | // used for demo
19 | googleMaterial : '1.3.0-alpha03',
20 | elasticViews : '2.0.7',
21 | powerMenu : '2.1.7',
22 | ]
23 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2018 skydoves (Jaewoong Eum)
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 | #
16 |
17 | # Jvm environments
18 | org.gradle.jvmargs=-Xmx4g
19 |
20 | # AndroidX
21 | android.useAndroidX=true
22 |
23 | # Required to publish to Nexus
24 | systemProp.org.gradle.internal.publish.checksums.insecure=true
25 |
26 | # Increase timeout when pushing to Sonatype
27 | systemProp.org.gradle.internal.http.connectionTimeout=120000
28 | systemProp.org.gradle.internal.http.socketTimeout=120000
29 |
30 | # Maven
31 | GROUP=com.github.skydoves
32 | POM_PACKAGING=aar
33 |
34 | VERSION_NAME=2.0.7-SNAPSHOT
35 |
36 | POM_ARTIFACT_ID=colorpickerpreference
37 | POM_NAME=colorpickerpreference
38 | POM_DESCRIPTION=A library that lets you implement ColorPicker, ColorPickerDialog, ColorPickerPreference.
39 |
40 | POM_URL=https://github.com/skydoves/ColorPickerPreference/
41 | POM_SCM_URL=https://github.com/skydoves/ColorPickerPreference/
42 | POM_SCM_CONNECTION=scm:git:git://github.com/skydoves/ColorPickerPreference.git
43 | POM_SCM_DEV_CONNECTION=scm:git:git://github.com/skydoves/ColorPickerPreference.git
44 |
45 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
46 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
47 | POM_LICENCE_DIST=repo
48 |
49 | POM_DEVELOPER_ID=skydoves
50 | POM_DEVELOPER_NAME=Jaewoong Eum
51 | POM_DEVELOPER_URL=https://github.com/skydoves/
52 |
53 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skydoves/ColorPickerPreference/46243ef7b6c0bfc753cbef913c19c0945243ce2f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Oct 25 13:49:21 KST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto init
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto init
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :init
68 | @rem Get command-line arguments, handling Windows variants
69 |
70 | if not "%OS%" == "Windows_NT" goto win9xME_args
71 |
72 | :win9xME_args
73 | @rem Slurp the command line arguments.
74 | set CMD_LINE_ARGS=
75 | set _SKIP=2
76 |
77 | :win9xME_args_slurp
78 | if "x%~1" == "x" goto execute
79 |
80 | set CMD_LINE_ARGS=%*
81 |
82 | :execute
83 | @rem Setup the command line
84 |
85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
86 |
87 |
88 | @rem Execute Gradle
89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
90 |
91 | :end
92 | @rem End local scope for the variables with windows NT shell
93 | if "%ERRORLEVEL%"=="0" goto mainEnd
94 |
95 | :fail
96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
97 | rem the _cmd.exe /c_ return code!
98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
99 | exit /b 1
100 |
101 | :mainEnd
102 | if "%OS%"=="Windows_NT" endlocal
103 |
104 | :omega
105 |
--------------------------------------------------------------------------------
/publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 | apply plugin: 'maven-publish'
3 | apply from: '../dependencies.gradle'
4 |
5 | ext.repository = [
6 | name : "colorpickerpreference",
7 | description: "A library that lets you implement ColorPicker, ColorPickerDialog, ColorPickerPreference.",
8 | websiteUrl : "https://github.com/skydoves/ColorPickerPreference",
9 | scm : 'scm:git@github.com/skydoves/ColorPickerPreference.git'
10 | ]
11 |
12 | def (property_user, property_key) = getBintrayProperties()
13 | bintray {
14 | user = property_user
15 | key = property_key
16 |
17 | publications = ["release"]
18 | publish = true
19 | override = true
20 | dryRun = false
21 |
22 | pkg {
23 | repo = "maven"
24 | name = repository.name
25 | userOrg = "devmagician"
26 | desc = repository.description
27 | websiteUrl = repository.websiteUrl
28 | vcsUrl = "${websiteUrl}.git"
29 | issueTrackerUrl = "${websiteUrl}/issues"
30 | licenses = ["Apache-2.0"]
31 | labels = ["android"]
32 | publicDownloadNumbers = false
33 |
34 | githubRepo = websiteUrl
35 | githubReleaseNotesFile = "${websiteUrl}/releases"
36 |
37 | version {
38 | desc = repository.description
39 | name = versions.versionName
40 | vcsTag = versions.versionName
41 | released = new Date()
42 | gpg { sign = true }
43 | }
44 | }
45 | }
46 |
47 | afterEvaluate {
48 | publishing {
49 | publications {
50 | release(MavenPublication) {
51 | from components.release
52 |
53 | group = "com.github.skydoves"
54 | artifactId = repository.name
55 | version = versions.versionName
56 |
57 | artifact androidJavadocsJar
58 | artifact(sourceJar)
59 |
60 | pom {
61 | name = repository.name
62 | description = repository.description
63 | url = repository.websiteUrl
64 | licenses {
65 | license {
66 | name = "The Apache License, Version 2.0"
67 | url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
68 | }
69 | }
70 | developers {
71 | developer {
72 | id = "skydoves"
73 | name = "Jaewoong Eum"
74 | }
75 | }
76 | scm {
77 | connection = repository.scm
78 | developerConnection = repository.scm
79 | url = repository.websiteUrl
80 | }
81 | }
82 | }
83 | }
84 | }
85 | }
86 |
87 | def getBintrayProperties() {
88 | def filename = "local.properties"
89 | def propsFile = rootProject.file(filename)
90 | if (propsFile.exists()) {
91 | Properties properties = new Properties()
92 | properties.load(project.rootProject.file(filename).newDataInputStream())
93 | return [
94 | properties.getProperty("bintray.user"),
95 | properties.getProperty("bintray.key")
96 | ]
97 | } else {
98 | print(filename + " does not exist!")
99 | return ["", ""]
100 | }
101 | }
102 |
103 | task checkBintrayConfig {
104 | doLast {
105 | def (user, key) = getBintrayProperties()
106 | if (user == null || user.isEmpty() || key == null || key.isEmpty()) {
107 | throw new IllegalArgumentException("Must specify Bintray information! Check your local.properties file.")
108 | }
109 | }
110 | }
111 |
112 | task androidJavadocs(type: Javadoc) {
113 | source = android.sourceSets.main.java.srcDirs
114 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
115 | android.libraryVariants.all { variant ->
116 | if (variant.name == 'release') {
117 | owner.classpath += variant.javaCompileProvider.get().classpath
118 | }
119 | }
120 | exclude '**/R.html', '**/R.*.html', '**/index.html'
121 | }
122 |
123 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
124 | archiveClassifier.set('javadoc')
125 | from androidJavadocs.destinationDir
126 | }
127 |
128 | task sourceJar(type: Jar) {
129 | from android.sourceSets.main.java.srcDirs
130 | classifier "sources"
131 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':colorpickerpreference'
2 |
--------------------------------------------------------------------------------
/spotless.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.diffplug.spotless"
2 | apply from: '../dependencies.gradle'
3 | spotless {
4 | java {
5 | target "**/*.java"
6 | trimTrailingWhitespace()
7 | licenseHeaderFile '../spotless.license.kt'
8 | removeUnusedImports()
9 | googleJavaFormat()
10 | endWithNewline()
11 | }
12 | kotlin {
13 | target "**/*.kt"
14 | ktlint("$versions.ktlintGradle").userData(['indent_size': '2', 'continuation_indent_size': '2'])
15 | licenseHeaderFile '../spotless.license.kt'
16 | trimTrailingWhitespace()
17 | endWithNewline()
18 | }
19 | }
--------------------------------------------------------------------------------
/spotless.license.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 skydoves
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 | */
16 |
--------------------------------------------------------------------------------