jaredrummler / colorpicker Goto Github PK
View Code? Open in Web Editor NEWA highly customizable color picker for Android
License: Apache License 2.0
A highly customizable color picker for Android
License: Apache License 2.0
Implementing the compat library (v1.0.4) causes this error when attempting to sync the project.
Implementation:
implementation 'com.jaredrummler:colorpicker-compat:1.0.4'
Error:
Failed to resolve: ColorPicker:colorpicker:unspecified
Open File
Show in Project Structure dialog
Dependency tree:
\--- com.jaredrummler:colorpicker-compat:1.0.4
+--- ColorPicker:colorpicker:unspecified FAILED
\--- androidx.preference:preference:1.0.0 (*)
Also happens on:
Normal version syncs fine.
I would really love this repository if you can provide support for fragments also.
Is there a way to set custom font for dialog title and the buttons?
If so, please explain how to do it.
This is probably just a google map api incompatibility issue but I tried using this color picker to pick a color for the markers but the color is not valid and an exception is thrown, app crashes
Would their be a way to create a pallette of colors based on the device's current wallpaper?
Below with the options in the dialog or a button to get wallpaper colors and the pallette of colors be of those with tint options or based on specific dominant colors.
This could be done with either getting the current wallpaper and converting it into a bitmap than using color pallette lib to pull colors or this new Android P wallpaper Colors API?
Hi,
First thanks for this very nice library that perfectly fit my needs :)
Do you think that you can make the dialog buttons configurable like the dialog title?
Reason is that most of the buttons strings are already translated in many languages in my app, that use external translations tools.
Avoiding necessary strings and allowing more complete names to help translators would be really cool.
I'm using ColorPreferenceCompat , and recently I got this crash from the play console:
Fatal Exception: java.lang.IllegalStateException: The activity must implement ColorPickerDialogListener
at com.jaredrummler.android.colorpicker.c.a(ColorPickerDialog.java:19583)
at com.jaredrummler.android.colorpicker.c$3.onClick(ColorPickerDialog.java:190)
at androidx.appcompat.app.AlertController$b.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
I didn't set any special listener. Right on onCreatePreferences, I just call : setOnPreferenceChangeListener
In com.jrummyapps.android.colorpicker.ColorPickerDialog#onAttach
:
This strange code works properly only on some situations:
if (colorPickerDialogListener == null && activity instanceof ColorPickerDialogListener) {
colorPickerDialogListener = (ColorPickerDialogListener) activity;
}
Version:
2.1.5
Code:
ColorPickerDialog dialog = ColorPickerDialog.newBuilder()
.setAllowCustom(true)
.setAllowPresets(false)
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setShowAlphaSlider(false)
.setDialogTitle(R.string.text_select_color)
//HERE! set initial color to 0
.setColor(0)
.create();
Log:
java.lang.StringIndexOutOfBoundsException: length=1; index=2
at java.lang.String.substring(String.java:1897)
at com.jrummyapps.android.colorpicker.ColorPickerDialog.setHex(ColorPickerDialog.java:354)
at com.jrummyapps.android.colorpicker.ColorPickerDialog.createPickerView(ColorPickerDialog.java:274)
at com.jrummyapps.android.colorpicker.ColorPickerDialog.onCreateDialog(ColorPickerDialog.java:163)
at android.app.DialogFragment.getLayoutInflater(DialogFragment.java:406)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
at android.app.BackStackRecord.run(BackStackRecord.java:815)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
I've got a drawing app where the user can select color, alpha and stroke width. It would be useful to have this library also allow the user to select stroke width (and maybe show a dot next to the selection to show how big the stroke would be). This should be a feature, like alpha, that can be turned on or off.
I wish I can change the buttons' text in ColorPickerDialog.
I want to turn transparency and three colors into 16 - ary code, but I don't know how to get transparency, and the callback doesn't return transparency
Looks like onColorSelected is never called, neither when i press "select button" or double-click on colors.
I also implemented ColorPickerDialogListener into fragmente-generator-activity, but nothing happened.
public class Fragment_ColorPicker extends PreferenceFragment implements ColorPickerDialogListener {
public Fragment_ColorPicker() {
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.color_preferences);
}
@Override
public void onColorSelected(int dialogId, @ColorInt int color) {
System.out.println("Hello");
}
@Override
public void onDialogDismissed(int dialogId) {
}
}
Could you help me, please?
listeners are forced to be included inside activity... inside fragment it gives force close on dismiss and select
Add to values-es:
<resources>
<!-- Default title for color picker dialog [CHAR LIMIT=30] -->
<string name="cpv_default_title">Selecciona un color</string>
<string name="cpv_presets">Predeterminados</string>
<string name="cpv_custom">Personalizar</string>
<string name="cpv_select">Seleccionar</string>
<string name="cpv_transparency">Transparencia</string>
</resources>
I got this crash report from the Play Store:
java.lang.IllegalStateException:
at android.app.FragmentManagerImpl.checkStateLoss (FragmentManagerImpl.java:1858)
at android.app.FragmentManagerImpl.enqueueAction (FragmentManagerImpl.java:1881)
at android.app.BackStackRecord.commitInternal (BackStackRecord.java:688)
at android.app.BackStackRecord.commit (BackStackRecord.java:646)
at android.app.DialogFragment.show (DialogFragment.java:230)
at com.jaredrummler.android.colorpicker.ColorPreference.onClick (ColorPreference.java:175)
at android.preference.Preference.performClick (Preference.java:1135)
at android.preference.PreferenceScreen.onItemClick (PreferenceScreen.java:249)
at android.widget.AdapterView.performItemClick (AdapterView.java:318)
at android.widget.AbsListView.performItemClick (AbsListView.java:1158)
at android.widget.AbsListView$PerformClick.run (AbsListView.java:3127)
at android.widget.AbsListView$3.run (AbsListView.java:4042)
at android.os.Handler.handleCallback (Handler.java:790)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6494)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
Don't know any further details.
I just use the preference this way in the preference xml file:
<com.jaredrummler.android.colorpicker.ColorPreference
android:defaultValue="@color/pref__background_color_default" android:key="@string/pref__background_color"
android:summary="@string/pref__background_color_desc" android:title="@string/pref__background_color_title"
app:cpv_allowPresets="true" app:cpv_dialogType="custom"/>
Can we add custom dialog style ? Like .setDialogStyle(R.style.CustomDialogStyle) and set it as you create the alert dialog.
<string name="cpv_default_title">Selecionar uma cor</string>
<string name="cpv_presets">Predefinidos</string>
<string name="cpv_custom">Personalizar</string>
<string name="cpv_select">Selecionar</string>
<string name="cpv_transparency">Transparência</string>
in com.jrummyapps.android.colorpicker.ColorPickerDialog need to add check colorPickerDialogListener not null.
For example, simply throw exception if listener is null on build chain.
Or add checks on every listener methods calls
Any possibility for option to reset color to default/null inside Dialog?
I got this crash report:
java.lang.IllegalStateException:
at android.app.FragmentManagerImpl.checkStateLoss (FragmentManagerImpl.java:1858)
at android.app.FragmentManagerImpl.enqueueAction (FragmentManagerImpl.java:1881)
at android.app.BackStackRecord.commitInternal (BackStackRecord.java:688)
at android.app.BackStackRecord.commit (BackStackRecord.java:646)
at android.app.DialogFragment.show (DialogFragment.java:230)
at com.jaredrummler.android.colorpicker.ColorPreference.onClick (ColorPreference.java:109)
at android.preference.Preference.performClick (Preference.java:1135)
at android.preference.PreferenceScreen.onItemClick (PreferenceScreen.java:249)
at android.widget.AdapterView.performItemClick (AdapterView.java:318)
at android.widget.AbsListView.performItemClick (AbsListView.java:1158)
at android.widget.AbsListView$PerformClick.run (AbsListView.java:3127)
at android.widget.AbsListView$3.run (AbsListView.java:4042)
at android.os.Handler.handleCallback (Handler.java:790)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6494)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
All I do is have normal preferences of this library, such as this one:
<com.jaredrummler.android.colorpicker.ColorPreference
android:defaultValue="@color/pref__os_color_primary_default" app:cpv_showAlphaSlider="true"
android:dependency="@string/pref__use_custom_colors" android:key="@string/pref__os_color_primary"
android:summary="@string/pref__os_primary_color_desc" android:title="@string/pref__os_primary_color_title"
app:cpv_allowPresets="true" app:cpv_dialogTitle="@string/pref__os_primary_color_title"
app:cpv_dialogType="custom"/>
App can be found here:
https://play.google.com/store/apps/details?id=com.lb.lwp_plus
Please add a multi color option in presets.
I would like to be able to set my own listener so that the included Activity does not need to listen for the color result. Something like this:
var dlg = ColorPickerDialog.newBuilder()
dlg.setColorPickerDialogListener(object : ColorPickerDialogListener{
override fun onColorSelected(dialogId: Int, color: Int) {
mood_color_text.setTextColor(color)
}
override fun onDialogDismissed(dialogId: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
I notice that I can use setColorPickerDialogListener
when I don't use the builder, but then I can't figure out how to set all the parameters and load it correctly. What is the best way to set my listener? Thanks.
Can we use other Language for menu ?
I want to change all to Japanese.
I have a ListPreference I am using to allow a user to select a 'theme' that updates the color value for several ColorPreferences. However after setting the value for each key I have to refresh the fragment (go back and come in) for the preview to update. It would be extremely useful if there were a method to update the preference preview or if someone knows of a way to get the preference to refresh.
<PreferenceCategory android:title="Widgets"
android:key="widget_category">
<ListPreference
android:key="widget_presets"
android:defaultValue="1"
android:title="Widget Themes"
android:summary="Select from a few default widget themes or create your own."
android:entries="@array/widget_presets"
android:entryValues="@array/widget_presets_values"/>
<com.jaredrummler.android.colorpicker.ColorPreference
android:defaultValue="0x26000000"
android:key="widget_background_color"
android:summary="Select background color for widgets."
android:title="Widget Background"
app:cpv_allowPresets="true"
app:cpv_showColorShades="false"
app:cpv_previewSize="large"
app:cpv_showAlphaSlider="true"/>
<com.jaredrummler.android.colorpicker.ColorPreference
android:defaultValue="@color/white"
android:key="widget_text_color"
android:summary="Select the primary text color for widgets."
android:title="Primary Text Color"
app:cpv_showColorShades="false"
app:cpv_previewSize="large"/>
<com.jaredrummler.android.colorpicker.ColorPreference
android:defaultValue="@color/white"
android:key="widget_secondary_text_color"
android:summary="Select the secondary text color for widgets."
android:title="Secondary Text Color"
app:cpv_showColorShades="false"
app:cpv_previewSize="large"/>
<SwitchPreference
android:defaultValue="false"
android:key="widget_theme_round_corner"
android:summary="Enable round corners for widgets."
android:title="Round Corners" />
</PreferenceCategory>
Error:
Attempt to invoke interface method 'void com.jaredrummler.android.colorpicker.ColorPickerDialogListener.onColorSelected(int, int)' on a null object reference
This is how I am creating my ColorPickerDialog and I am also setting ColorPickerDialogListener.
ColorPickerDialog.Builder builder = ColorPickerDialog.newBuilder();
builder.setDialogType(ColorPickerDialog.TYPE_PRESETS)
.setAllowPresets(false)
.setDialogId(12)
.setColor(Color.BLACK)
.create().setColorPickerDialogListener(new ColorPickerDialogListener() {
@Override
public void onColorSelected(int dialogId, int color) {
}
@Override
public void onDialogDismissed(int dialogId) {
}
});
builder.show((Activity)mContext);
I look at the code of NestedGridView
- https://github.com/jaredrummler/ColorPicker/blob/master/library/src/main/java/com/jaredrummler/android/colorpicker/NestedGridView.java
I have been puzzled a while, as I'm not understand the idea behind the following code?
@Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
May I know the purpose of having NestedGridView
, instead of a standard GridView
?
How can I use this in Fragment? I have added listener in parent activity of fragment and its working but I want to listen onColorSelected in fragment.
Please help.
Can't the dialog callback interface be separated from the activity such that I can supply my own implementation of the ColorPickerDialogListener
independent of the activity I'm using it in? Maybe something like this:
ColorPickerDialog.newBuilder().setColor(color).show(Activity);
can be changed to ColorPickerDialog.newBuilder().setColor(color).show(Activity, ColorPickerDialogListener);
Is it possible to change the background color of the dialog?
Getting null pointer exception when selecting the color like this--
java.lang.NullPointerException: Attempt to invoke interface method 'void com.jrummyapps.android.colorpicker.ColorPickerDialogListener.onColorSelected(int, int)' on a null object reference
at com.jrummyapps.android.colorpicker.ColorPickerDialog$1.onClick(ColorPickerDialog.java:172)
When trying to use the lib while also using the Preference Support Library the build results in a conflict.
Error:(1000) Attribute "dialogTitle" already defined with incompatible format.
You can easily test this by adding the preference support lib to the dependencies of the demo app:
compile "com.android.support:preference-v14:25.1.0"
To solve this i think it would be good to prefix the custom style attributes defined by this library.
without clicking call it's method
Is there a way to change the 'SELECT' button text in the color picker dialog (ColorPreference)?
A button to restore the default color, if supplied, would be an excellent user/developer enhancement.
I have no idea how to get this working. I've tried so many things but they all fail. I'm pretty new to android app development so bear with me. So just putting implementation 'com.jaredrummler:colorpicker:1.0.5' in my gradle file won't compile. I first have to convert everything to androidx. Alright, i've found that one out. But then I made an preference xml to test it but when i use for instance:
<com.jaredrummler.android.colorpicker.ColorPreference android:defaultValue="0xFFEC407A" android:key="custom_only_color" android:summary="A picker that doesn't show the presets" android:title="Custom color"
It won't give a preview. I also tried the compat version and all other kinds of stuff but i can't figure out how to do it. Is there a step I'm missing?
All classes here extend from android.preference.Preference
instead of from androidx.preference.Preference
, while using this in gradle file:
implementation 'androidx.preference:preference:1.0.0'
This means that if I use this repository within a class that extends PreferenceFragmentCompat, I get a crash of this sort:
android.view.InflateException: Binary XML file line #15: Error inflating class com.jaredrummler.android.colorpicker.ColorPreference
at androidx.preference.PreferenceInflater.createItem(PreferenceInflater.java:266)
at androidx.preference.PreferenceInflater.createItemFromTag(PreferenceInflater.java:295)
at androidx.preference.PreferenceInflater.rInflate(PreferenceInflater.java:362)
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:170)
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:120)
at androidx.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:138)
at androidx.preference.PreferenceFragmentCompat.setPreferencesFromResource(PreferenceFragmentCompat.java:445)
Please fix this. This is the only reason I've forked this repository into mine:
Using ColorPicker version 1.1.0 with an Android app that makes use of AndroidX, I am getting the following ClassCastException:
java.lang.ClassCastException: my.package.SettingsActivity cannot be cast to androidx.fragment.app.FragmentActivity
at com.jaredrummler.android.colorpicker.ColorPreference.onAttachedToActivity(ColorPreference.java:118)
at android.preference.PreferenceGroup.onAttachedToActivity(PreferenceGroup.java:281)
at android.preference.PreferenceGroup.onAttachedToActivity(PreferenceGroup.java:281)
at android.preference.PreferenceScreen.bind(PreferenceScreen.java:169)
at android.preference.PreferenceFragment.bindPreferences(PreferenceFragment.java:391)
at android.preference.PreferenceFragment.onActivityCreated(PreferenceFragment.java:214)
at android.app.Fragment.performActivityCreated(Fragment.java:2531)
The class my.package.SettingsActivity
extends android.preference.PreferenceActivity
.
The same code works perfect with version 1.0.2. Starting with version 1.0.3 the issue appears. Versions 1.0.4 and 1.0.5 are also affected.
how to use this component in xml with databinding onColorChanged event?
I am getting this error while building the project after importing the dependencies
This library is great,
Could you update this lib for working with PreferenceFragmentCompat
Here's the use case
I'd like custom colors to stay in the presets (bumping off the least used color).
Is something like this possible?
Click on ColorPreference -> rotate > rotate back -> click on ColorPreference -> Exceptions thrown...
java.lang.NullPointerException: Attempt to invoke interface method 'void com.jaredrummler.android.colorpicker.ColorPickerDialogListener.onDialogDismissed(int)' on a null object reference
at com.jaredrummler.android.colorpicker.ColorPickerDialog.onDismiss(ColorPickerDialog.java:248)
at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1343)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Hi I started using your color picker in my preferences and it work very well I must say.
I have an listview if items with a button to call the ColorPickerDialog like this
private void showColorPickerDialog(int id, int color) {
ColorPickerDialog dialog = ColorPickerDialog.newBuilder()
.setDialogId(id)
.setColor(color)
.setSelectedButtonText(android.R.string.ok)
.create();
dialog.setColorPickerDialogListener(this);
dialog.show(mContext.getFragmentManager(), "Color_picker");
}
the problem is that all the color circles are blank i.e. they show the white / grey grid wich seems to indicate that every color in 0% alpha. the circle outlines do show color.
The custom screen also shows the two color boxes as blank.
I fiddled around with options and looked at your source code but could not find any thing.
Any Idea what would cause this?
If I cannot resolve this I will have to use another color picker all together since it does not make sense to use two different ones in the same applications
Thanks a lot for your help and very nice work BTW
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.