All Projects → kizitonwose → Colorpreference

kizitonwose / Colorpreference

Licence: apache-2.0
A custom preference item for easy implementation of a color picker in Android's preference screen.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Colorpreference

Prefser
Wrapper for Android SharedPreferences with object serialization and RxJava Observables
Stars: ✭ 228 (-23.75%)
Mutual labels:  preferences, sharedpreferences
Hawk
✔️ Secure, simple key-value storage for Android
Stars: ✭ 3,827 (+1179.93%)
Mutual labels:  preferences, sharedpreferences
Preferenceroom
🚚 Android processing library for managing SharedPreferences persistence efficiently and structurally.
Stars: ✭ 341 (+14.05%)
Mutual labels:  preferences, sharedpreferences
Materialpreferences
A highly flexible set of lovely looking views that provides functionality of preferences.
Stars: ✭ 495 (+65.55%)
Mutual labels:  preferences, sharedpreferences
Bulldog
Android library to simplify reading and writing to SharedPreferences, never write code like this anymore prefs.edit().putString("someKey","someString").apply()
Stars: ✭ 133 (-55.52%)
Mutual labels:  preferences, sharedpreferences
Multiplatform Preferences
Kotlin Multi Platform Preferences, for android an ios : SharedPreferences & NSUserDefault
Stars: ✭ 76 (-74.58%)
Mutual labels:  preferences, sharedpreferences
Binaryprefs
Rapidly fast and lightweight re-implementation of SharedPreferences which stores each preference in files separately, performs disk operations via NIO with memory mapped byte buffers and works IPC (between processes). Written from scratch.
Stars: ✭ 484 (+61.87%)
Mutual labels:  preferences, sharedpreferences
Typedpreferences
Preference wrappers for primitive types for Android
Stars: ✭ 191 (-36.12%)
Mutual labels:  preferences, sharedpreferences
PowerPreference
💾 A Powerful library to control and simplify the usage of shared preference in Android.
Stars: ✭ 95 (-68.23%)
Mutual labels:  preferences, sharedpreferences
Yasp
Yet Another Shared Preference
Stars: ✭ 16 (-94.65%)
Mutual labels:  sharedpreferences
Colorpicker
🎨 A color picker for Android. Pick a color using color wheel and slider (HSV & alpha).
Stars: ✭ 254 (-15.05%)
Mutual labels:  color-picker
memo
Android processing and secured library for managing SharedPreferences as key-value elements efficiently and structurally.
Stars: ✭ 18 (-93.98%)
Mutual labels:  sharedpreferences
flutter material color picker
Material color picker, you can customize colors. Selection in two step, first main color and after shades.
Stars: ✭ 68 (-77.26%)
Mutual labels:  color-picker
Colorslider
🎨 Snapchat-style color picker in Swift
Stars: ✭ 258 (-13.71%)
Mutual labels:  color-picker
ToDoApp
📱My android playground app - Simple and Fastest todo app - developing to cover most android concepts, simple logic can make me focus more on framework
Stars: ✭ 28 (-90.64%)
Mutual labels:  sharedpreferences
Electron Store
Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc
Stars: ✭ 3,316 (+1009.03%)
Mutual labels:  preferences
jquery-asColorPicker
ColorInput is a jQuery plugin used to show color picker for a input field.
Stars: ✭ 18 (-93.98%)
Mutual labels:  color-picker
ColorPicker
Customizable Color Picker control for WPF
Stars: ✭ 57 (-80.94%)
Mutual labels:  color-picker
Android Nosql
Lightweight, simple structured NoSQL database for Android
Stars: ✭ 284 (-5.02%)
Mutual labels:  preferences
Mac Setup
🛠️ Front end web development setup for macOS.
Stars: ✭ 265 (-11.37%)
Mutual labels:  preferences

Color Preference

An 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.

Build Status JitPack Android Arsenal License API

Preview

ExampleMain ExampleCircle ExampleSquare

Get the sample apk here

Also checkout the sample module here

Setup

Gradle

Add this to your project level build.gradle:

allprojects {
 repositories {
    jcenter()
    maven { url "https://jitpack.io" }
 }
}

Add this to your app build.gradle:

dependencies {
	implementation 'com.github.kizitonwose.colorpreference:core:<latest-version>'
}

If you are using the AndroidX preference/legacy-preference-v14 library, you should use this in your app build.gradle instead:

dependencies {
	implementation 'com.github.kizitonwose.colorpreference:support:<latest-version>'
}
Note: <latest-version> value can be found on the JitPack badge above the preview images.

Usage

Just like every other preference object, you add it to the XML file of your Preference screen.

Preference usage
<PreferenceScreen>

	<com.kizitonwose.colorpreference.ColorPreference
		android:defaultValue="@color/color_default"
		android:key="@string/pref_key" />

	<CheckBoxPreference
		... />

	<SwitchPreference
		... />

</PreferenceScreen>
AndroidX preference/legacy-preference-v14
<androidx.preference.PreferenceScreen> 

	<com.kizitonwose.colorpreferencecompat.ColorPreferenceCompat
		android:defaultValue="@color/color_default"
		android:key="@string/pref_key" />
	
    <androidx.preference.SwitchPreferenceCompat
		... />
	
	<androidx.preference.SwitchPreferenceCompat
		... />
		
</androidx.preference.PreferenceScreen>

The default implementation is the circle color view. For custom settings, add the app namespace to your XML file:

xmlns:app="http://schemas.android.com/apk/res-auto"

Now you can use the custom attributes. All custom attributes are available for the ColorPreference and ColorPreferenceCompat classes.

<com.kizitonwose.colorpreference.ColorPreference
	android:defaultValue="@color/color_default"
	android:key="@string/pref_key"
	android:summary="@string/pref_summary"
	android:title="@string/pref_title"
	app:colorShape="circle"
	app:colorChoices="@array/color_choices"
	app:viewSize="large"
	app:numColumns="5"
	app:showDialog="true" />

Two important methods in the ColorPreference and ColorPreferenceCompat classes:

  • Get the color value: getValue()

  • Set the color value and update the preference view: setValue(int newColor)

Attributes

Attribute name Description Default value
colorShape The shape of the color view(circle or square) circle
colorChoices An array of colors to show on the dialog An internal array
viewSize The size of the color view(normal or large) large
numColumns The number of columns for the colors on the dialog 5
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

Custom Picker sample

You can find a working example of how to use a custom color picker in the included sample module. Actually, 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.

The custom picker in the sample uses the Lobster Color Picker Library. You can use any color picker of your choice.

Extras

If 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 module.

// The context shuould be an Activity which implements ColorDialog.OnColorSelectedListener
new ColorDialog.Builder(this)
		.setColorShape(ColorShape.CIRCLE) //CIRCLE or SQUARE
		.setColorChoices(R.array.color_choices) //an array of colors
		.setSelectedColor(Color.GREEN) //the checked color
		.setTag("TAG") // tags can be useful when multiple components use the picker within an activity
		.show();

Activity usage example

public class ExampleActivity extends Activity implements ColorDialog.OnColorSelectedListener {

	// set these tags when building the color picker dialog
	// if you have only one picker in an Activity, you don't need a tag
	private final String TOOLBAR_PICKER_TAG = "toolbar";
    private final String BACKGROUND_PICKER_TAG = "background";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // activity initialization code
    }

    @Override
    public void onColorSelected(int newColor, String tag) {
		switch (tag){
			case TOOLBAR_PICKER_TAG:
				//change the toolbar color with newColor
				break;
			case BACKGROUND_PICKER_TAG:
				//change the activity background color with newColor
				break;
        }
    }
}

Changelog

See the changelog file.

Thanks

Thanks to Roman Nurik for his initial implementation.

License

Copyright (C) 2016 Kizito Nwose

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].