{"id":13643001,"url":"https://github.com/kizitonwose/colorpreference","last_synced_at":"2025-04-10T01:10:36.400Z","repository":{"id":90072790,"uuid":"69104693","full_name":"kizitonwose/colorpreference","owner":"kizitonwose","description":"A custom preference item for easy implementation of a color picker in Android's preference screen.","archived":false,"fork":false,"pushed_at":"2019-02-21T21:41:50.000Z","size":8163,"stargazers_count":312,"open_issues_count":1,"forks_count":29,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T01:10:31.268Z","etag":null,"topics":["android","color-picker","preference-screen","preferences","sharedpreferences"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kizitonwose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/.gitignore","governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-24T13:43:41.000Z","updated_at":"2024-12-26T07:04:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"252ce2b2-5daa-45b3-9120-847baa6c988d","html_url":"https://github.com/kizitonwose/colorpreference","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2Fcolorpreference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2Fcolorpreference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2Fcolorpreference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2Fcolorpreference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kizitonwose","download_url":"https://codeload.github.com/kizitonwose/colorpreference/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137886,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","color-picker","preference-screen","preferences","sharedpreferences"],"created_at":"2024-08-02T01:01:39.363Z","updated_at":"2025-04-10T01:10:36.382Z","avatar_url":"https://github.com/kizitonwose.png","language":"Java","funding_links":[],"categories":["Color"],"sub_categories":[],"readme":"# Color Preference\n\nAn Android library for creating a nice color picker in the preference screen. You can use the inbuilt picker or any other color picker of your choice. The library can be used with the standard preference classes or the AndroidX preference/legacy-preference-v14(support-preference-v7/v14) classes.\n\n[![Build Status](https://travis-ci.org/kizitonwose/colorpreference.svg?branch=master)](https://travis-ci.org/kizitonwose/colorpreference) \n[![JitPack](https://jitpack.io/v/kizitonwose/colorpreference.svg)](https://jitpack.io/#kizitonwose/colorpreference) \n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Color%20Preference-brightgreen.svg)](https://android-arsenal.com/details/1/4401) \n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) \n[![API](https://img.shields.io/badge/API-14%2B-9C27B0.svg)](https://android-arsenal.com/api?level=14)\n\n\n## Preview\n\n\u003cimg src=\"https://raw.githubusercontent.com/kizitonwose/colorpreference/master/art/screenshot_1.png\" alt=\"ExampleMain\" width=\"240\"\u003e \u003cimg src=\"https://raw.githubusercontent.com/kizitonwose/colorpreference/master/art/screenshot_2.png\" alt=\"ExampleCircle\" width=\"240\"\u003e \u003cimg src=\"https://raw.githubusercontent.com/kizitonwose/colorpreference/master/art/screenshot_3.png\" alt=\"ExampleSquare\" width=\"240\"\u003e\n\nGet the sample apk [here](https://github.com/kizitonwose/colorpreference/releases/download/1.0.5/sample-1.0.5.apk)\n\nAlso checkout the sample module [here][sample-url]\n\n\n## Setup\n\n### Gradle\n\nAdd this to your project level `build.gradle`:\n\n```groovy\nallprojects {\n repositories {\n    jcenter()\n    maven { url \"https://jitpack.io\" }\n }\n}\n```\n\nAdd this to your app `build.gradle`:\n\n```groovy\ndependencies {\n\timplementation 'com.github.kizitonwose.colorpreference:core:\u003clatest-version\u003e'\n}\n```\nIf you are using the AndroidX preference/legacy-preference-v14 library, you should use this in your app `build.gradle` instead:\n\n```groovy\ndependencies {\n\timplementation 'com.github.kizitonwose.colorpreference:support:\u003clatest-version\u003e'\n}\n```\n##### Note: `\u003clatest-version\u003e` value can be found on the JitPack badge above the preview images.\n\n## Usage\n\nJust like every other preference object, you add it to the XML file of your Preference screen.\n\n##### Preference usage\n\n```xml\n\u003cPreferenceScreen\u003e\n\n\t\u003ccom.kizitonwose.colorpreference.ColorPreference\n\t\tandroid:defaultValue=\"@color/color_default\"\n\t\tandroid:key=\"@string/pref_key\" /\u003e\n\n\t\u003cCheckBoxPreference\n\t\t... /\u003e\n\n\t\u003cSwitchPreference\n\t\t... /\u003e\n\n\u003c/PreferenceScreen\u003e\n```\n\n##### AndroidX preference/legacy-preference-v14\n\n```xml\n\u003candroidx.preference.PreferenceScreen\u003e \n\n\t\u003ccom.kizitonwose.colorpreferencecompat.ColorPreferenceCompat\n\t\tandroid:defaultValue=\"@color/color_default\"\n\t\tandroid:key=\"@string/pref_key\" /\u003e\n\t\n    \u003candroidx.preference.SwitchPreferenceCompat\n\t\t... /\u003e\n\t\n\t\u003candroidx.preference.SwitchPreferenceCompat\n\t\t... /\u003e\n\t\t\n\u003c/androidx.preference.PreferenceScreen\u003e\n```\n\nThe default implementation is the circle color view. For custom settings, add the app namespace to your XML file:\n\n`xmlns:app=\"http://schemas.android.com/apk/res-auto\"`\n\nNow you can use the custom attributes. All custom attributes are available for the `ColorPreference` and `ColorPreferenceCompat` classes.\n\n```xml\n\u003ccom.kizitonwose.colorpreference.ColorPreference\n\tandroid:defaultValue=\"@color/color_default\"\n\tandroid:key=\"@string/pref_key\"\n\tandroid:summary=\"@string/pref_summary\"\n\tandroid:title=\"@string/pref_title\"\n\tapp:colorShape=\"circle\"\n\tapp:colorChoices=\"@array/color_choices\"\n\tapp:viewSize=\"large\"\n\tapp:numColumns=\"5\"\n\tapp:showDialog=\"true\" /\u003e\n```\n\nTwo important methods in the `ColorPreference` and `ColorPreferenceCompat` classes: \n\n- Get the color value: **`getValue()`**\n \n- Set the color value and update the preference view: **`setValue(int newColor)`**\n\n### Attributes\n\n|Attribute name|Description|Default value|\n|:-:|:-:|:-:|\n|colorShape|The shape of the color view(`circle` or `square`)| `circle`|\n|colorChoices|An array of colors to show on the dialog| An internal array |\n|viewSize|The size of the color view(`normal` or `large`) |`large`|\n|numColumns|The number of columns for the colors on the dialog| 5 |\n|showDialog|If `false`, the user can suppress the in-built dialog and then show a custom color picker. To save the color from the custom picker, just call `setValue(int newColor)`| `true` |\n\n\n### Custom Picker sample\n\nYou can find a working example of how to use a custom color picker in the included [sample][sample-url] module. \nActually, all you have to do is include `app:showDialog=\"false\"` in the preference item to suppress the inbuilt picker, then when you get your color from the custom picker, call `setValue(int newColor)` method of the `ColorPreference`(or `ColorPreferenceCompat`) class and pass in the color. This saves the color and updates the view accordingly.\n\nThe custom picker in the sample uses the [Lobster Color Picker](https://github.com/LarsWerkman/Lobsterpicker) Library. You can use any color picker of your choice.\n\n\n## Extras\n\nIf you want to use the inbuilt color picker in any activity as a simple color picker, you can use the `ColorDialog.Builder` class. A working sample is also included in the [sample][sample-url] module.\n\n```java\n// The context shuould be an Activity which implements ColorDialog.OnColorSelectedListener\nnew ColorDialog.Builder(this)\n\t\t.setColorShape(ColorShape.CIRCLE) //CIRCLE or SQUARE\n\t\t.setColorChoices(R.array.color_choices) //an array of colors\n\t\t.setSelectedColor(Color.GREEN) //the checked color\n\t\t.setTag(\"TAG\") // tags can be useful when multiple components use the picker within an activity\n\t\t.show();\n\n```\n\nActivity usage example\n\n```java\npublic class ExampleActivity extends Activity implements ColorDialog.OnColorSelectedListener {\n\n\t// set these tags when building the color picker dialog\n\t// if you have only one picker in an Activity, you don't need a tag\n\tprivate final String TOOLBAR_PICKER_TAG = \"toolbar\";\n    private final String BACKGROUND_PICKER_TAG = \"background\";\n    \n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        // activity initialization code\n    }\n\n    @Override\n    public void onColorSelected(int newColor, String tag) {\n\t\tswitch (tag){\n\t\t\tcase TOOLBAR_PICKER_TAG:\n\t\t\t\t//change the toolbar color with newColor\n\t\t\t\tbreak;\n\t\t\tcase BACKGROUND_PICKER_TAG:\n\t\t\t\t//change the activity background color with newColor\n\t\t\t\tbreak;\n        }\n    }\n}\n```\n\n\n## Changelog\n\nSee the [changelog](https://github.com/kizitonwose/colorpreference/blob/master/CHANGELOG.md) file.\n\n\n## Thanks\n\nThanks to [Roman Nurik](https://github.com/romannurik) for his initial implementation.\n\n\n## License\n\n```\nCopyright (C) 2016 Kizito Nwose\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n[sample-url]: https://github.com/kizitonwose/colorpreference/tree/master/sample\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkizitonwose%2Fcolorpreference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkizitonwose%2Fcolorpreference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkizitonwose%2Fcolorpreference/lists"}