├── .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 | [![Build Status](https://travis-ci.org/skydoves/ColorPickerPreference.svg?branch=master)](https://travis-ci.org/skydoves/ColorPickerPreference) 3 | [![API](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16) 4 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 5 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ColorPickerPreference-green.svg?style=flat)](https://android-arsenal.com/details/1/6759) 6 | [![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23297-orange.svg)](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 | ![screenshot](https://user-images.githubusercontent.com/24237865/36096666-9e9fc7ca-103a-11e8-9a1a-e1d685d000f9.png) 12 | ![gif](https://user-images.githubusercontent.com/24237865/36096667-9ec6693e-103a-11e8-8ed8-1d99da83c9ac.gif) 13 | 14 | ## Including in your project 15 | [![Maven Central](https://img.shields.io/maven-central/v/com.github.skydoves/colorpickerpreference.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.skydoves%22%20AND%20a:%22colorpickerpreference%22) 16 | [![Jitpack](https://jitpack.io/v/skydoves/ColorPickerPreference.svg)](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 | ![dialog0](https://user-images.githubusercontent.com/24237865/45362890-0d619b80-b611-11e8-857b-e12f82978b53.jpg) 285 | ![dialog1](https://user-images.githubusercontent.com/24237865/45362892-0d619b80-b611-11e8-9cc5-25518a9d392a.jpg)
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 | ![flag0](https://user-images.githubusercontent.com/24237865/45364191-75fe4780-b614-11e8-81a5-04690a4392db.jpg) 333 | ![flag1](https://user-images.githubusercontent.com/24237865/45364194-75fe4780-b614-11e8-844c-136d14c91560.jpg)
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 | ![alphatileview](https://user-images.githubusercontent.com/24237865/45364416-09377d00-b615-11e8-9707-b83f55053480.jpg)
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 | Buy Me A Coffee 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 |