larswerkman / holocolorpicker Goto Github PK
View Code? Open in Web Editor NEWAn Android Holo themed colorpicker designed by Marie Schweiz
License: Apache License 2.0
An Android Holo themed colorpicker designed by Marie Schweiz
License: Apache License 2.0
Hi. I think you should update the maven repo to reflect latest fixes
While flipping through my viewpager which contains a fragments, one of which contains the HoloColorPicker. When onRestoreInstanceState is called it calls the callback onColorChanged().
This is not intended behaviour as the user has not interacted with the color picker. I would expect that this callback not be called onRestoreInstanceState.
...
onColorChanged():83, LEDFragment {com.my.package}
setNewCenterColor():742, ColorPicker {com.larswerkman.holocolorpicker}
onRestoreInstanceState():876, ColorPicker {com.larswerkman.holocolorpicker}
dispatchRestoreInstanceState():12767, View {android.view}
dispatchRestoreInstanceState():2643, ViewGroup {android.view}
restoreHierarchyState():12745, View {android.view}
restoreViewState():613, Fragment {android.app}
moveToState():910, FragmentManagerImpl {android.app}
attachFragment():1260, FragmentManagerImpl {android.app}
...
as title :enhancement
Can this libarary add activity call and color result when user select color?
because most developer want user to input their color, but not in their own activity to achieve.
instead i prefer to call a color select dialog when user want to change color.
It'd be really helpful if you could create a sample application demoing a few things here and there.
Also, it'd be a great idea to add a custom preferencescreen with a preview of the color chosen. Just a thought.
This is pretty complex for me. Can someone please list step by step guide to use this color picker in your own app! Thank You!
The getColor() method returns 0 when you call it before you have touched the picker, but it should instead be a green color value like shown in the circle.
It would help to add this line in the init method to preset the color:
mCenterNewColor = calculateColor(mAngle);
Creating an App using 2 Holopickers, i accidentally stumbled upon some resizers for the picker (in another issue about the SVBar) Being :
app:color_center_halo_radius="40dp"
app:color_center_radius="30dp"
app:color_pointer_halo_radius="22dp"
app:color_pointer_radius="16dp"
app:color_wheel_radius="70dp"
app:color_wheel_thickness="24dp"
for instance then i started looking at for info on how to do something similar for the 'bars' but google didn't find an answer. but somehow i managed to find :
app:bar_length="140dp"
app:bar_pointer_halo_radius="14dp"
app:bar_pointer_radius="10dp"
app:bar_thickness="8dp"
i mus have been looking through the source-code, but that is a tad tricky for me, Java is not my first language and AS is taking up so much memory that many times webpages get put in the pagefile on the harddrive, which makes it all rather slow.
Anyway the question i did not find any answer to is how can i remove the margins from the picker (or make them smaller) so that i can put them a little closer together while using "Constraint-layout".
Basically anyway are there any other parameters i can modify.
If you set bar_orientation_horizontal for portrait and unset it for landscape, after you rotate the device, you get the same value as in previously used layout.
This is how it was coded as part of #29, so I'm bringing here @tonyr59h to discuss it.
I fixed it by removing orientation related code from saturation and value bars from onSaveInstanceState
and onRestoreInstanceState
.
it seems conversation RGB-HSV and back causes loss of precision and position in SVBar goes to zero after several iterations
Found a unnecessary .DS_Store file in the folders "res" and "res/values". Maybe it's not useful for this repo....
I'm using your lib in dilog like that:
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()).setTitle(title);
LayoutInflater dialogInflater = getActivity().getLayoutInflater();
View colorPickerLayout = dialogInflater.inflate(R.layout.dialog_colorpicker, null); //here I got only ColorPicker and svbar
adb.setView(colorPickerLayout);
final ColorPicker picker = (ColorPicker) colorPickerLayout.findViewById(R.id.picker);
SVBar svBar = (SVBar) colorPickerLayout.findViewById(R.id.svbar);
picker.addSVBar(svBar);
//trying different ways to set new as old color exactly, but SVbar change position every time
picker.setOldCenterColor(color);
picker.setColor(color);
svBar.setColor(color);
adb.setPositiveButton("Set", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
listener.onBlurredAlertDialogPositiveClick(BlurredColorPickerDialog.this, picker.getColor());
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
listener.onBlurredAlertDialogNegativeClick(BlurredColorPickerDialog.this);
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
listener.onBlurredAlertDialogCancel(BlurredColorPickerDialog.this);
}
});
and xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<com.larswerkman.holocolorpicker.ColorPicker
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:color_wheel_radius="128dp"
app:color_wheel_thickness="24dp"
app:color_center_radius="54dp"
app:color_center_halo_radius="60dp"
app:color_pointer_radius="16dp"
app:color_pointer_halo_radius="22dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<com.larswerkman.holocolorpicker.SVBar
android:id="@+id/svbar"
android:layout_width="200dp"
android:layout_height="112dp"
android:layout_gravity="center"
android:layout_margin="5dip"
android:layout_below="@+id/picker"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
What i'm doing wrong? Is it bug in lib?
picker.setOnColorChangedListener(new ColorPicker.OnColorChangedListener() {
@OverRide
public void onColorChanged(int i) {
i <==sometimes will give -1;
}
});
Please, add sample for changing orientation for bars.
Thanks.
When you tap on a bar the pointer for the bar moves to the tapped position, yet no events are triggered, and the linked color picker doesn't change. The pointer does move, which hints that the color should have changed.
Hi. I really like your color picker and want to use it in my app. However I found two problems with the color.
When you pick a color with a high saturate or value and then do a picker.setColor(picker.getColor())
, the color changes a bit. I thought, this should not happen, so I looked around in the code and found, that the normalizeColor(int)
method is a too complicated. I think to get an accurate value for the normColor
variable, one could use the following lines, which solve the problem for me:
Color.colorToHSV(color, mHSV);
mHSV[1] = 1f;
mHSV[2] = 1f;
int normColor = Color.HSVToColor(Color.alpha(color), mHSV);
When you do a picker.setColor(Color.BLACK)
, the SVBar slider is set to white (saturate=0). I solved this by changing the if-block in the setColor(int)
method of the ColorPicker:
if (mHSV[1] < mHSV[2]) {
mSVbar.setSaturation(mHSV[1]);
} else {
SVbar.setValue(mHSV[2]);
}
I know, I could do a pull request with these changed, but I certainly don't know how to do this, so here is an issue for it. I hope it helps. Keep up the very good work.
Not really an issue. I need to be able to send the selected color as a string to a database. Is it possible to convert the selection to a string? If it is, how would I go about doing that? I'm very new to this library so any help in the right direction would be great. Thank you.
Hey Lars Werkman,
thank you for your great work with this colorPicker!
I use your colorPicker (with SV- and Opacitybars) to send an ip frame with the selected color to another device. I noticed, you trigger the onColorChangedListener on every ColorPicker.setNewCenterColor(.) call. This is wrong, if there are some bars (which update the actual color value with setNewCenterColor).
with this function update in ColorPicker it is solved:
/**
* Puts an ColorChanged Event on the listener.
*
*/
public void ColorChangedEvent(){
if (onColorChangedListener != null && mCenterNewColor != oldChangedListenerColor) {
onColorChangedListener.onColorChanged(mCenterNewColor);
oldChangedListenerColor = mCenterNewColor;
}
}
/**
* Change the color of the center which indicates the new color.
*
* @param color int of the color.
*/
public void setNewCenterColor(int color) {
mCenterNewColor = color;
mCenterNewPaint.setColor(color);
if (mCenterOldColor == 0) {
mCenterOldColor = color;
mCenterOldPaint.setColor(color);
}
invalidate();
}
and put
ColorPicker.ColorChangedEvent();
after every call of setNewCenterColor(.) in functions of the bars instead of .setColor(color).
in ColorPicker Functions, ColorChangedEvent() needs to be called after correct value is set to setNewCenterColor(.) function calls. (if a bar changes the value later on, a wrong value will be put on listener.
By the way... you dont see, how many listener Function calls you get, whith the old version by just using the colorpicker on an android device.
Best Regards!
Buttairfly
the method "setEnabled" does not work, is there any way to disable it?
While playing around with a setup that includes Picker, SaturationBar and ValueBar I noticed that the SaturationBar and ValueBar don't interact properly. There is always a little jump in the color when going from adjusting one bar to adjusting the other bar.
After a little digging I think I've found the problem: in the SaturationBar on line 478 it should be "mHSVColor[2]" instead of "1f"? Could someone correct this or instruct me as to how to do it myself? I am new to GitHub..
Thank you!
[EDIT] I realized that it is quite a bit more complicated and am currently working on a solution that I will gladly contribute if someone is interested.
Hi all,
when I try to set the color of the picker through a call to setColor, it works. But immediatily after, if I call getColor it returns another color which is always the full green one. Any update to fix this problem?
Hi, I have issue with this holo color picker, I set the old color with int -6697984 but when I get the color from the picker, it returns -6632448. I have added saturation, value, opacity and even sv bar, but it still does not give exact color int as I set before.
Do you know what is the problem and what probably could be the solution?
It is 16 bit color picker?
i want the default of the SaturationBar to be "255" and opacityBar "0" or SaturationBar to be "0" and opacityBar "255" this is possible?
The Issue is that the defalut is no color and that Annoying!
As far as I can see, there is no way to choose gray colors with this Color Picker, such as #B5B5B5 or #222222. If there is a was to do this, and a obvious one at that, I apologies for the submitting of this issue.
I Really love this spinner's design, but I hardly consider using an other one instead, due to this issue.
Add a appropriate license, such as the Apache 2 License.
Hello,
looks like the following atributes can't be accessed from XML even with namespace change.
<attr name="bar_length" format="dimension" />
<attr name="bar_pointer_radius" format="dimension" />
<attr name="bar_pointer_halo_radius" format="dimension" />
<attr name="bar_orientation_horizontal" format="boolean" />
The Wheel attributes are accessible.
I'm using the maven repository.
Thanks!
How to return(or convert) real value of color of RGB
like red=255 green=255 blue=255 from ARGB which returning from .getColor();
Thank's
I'd like to mirror the saturation bar so the black part is on the left side. Is there an easy way to do this?
Hi,
First of all, thanks for the lib.
I need to be able to change the COLORS shown by the color picker.
Could you please add a method to set the colors please ?
I am currently trying to build a little mobile app to control some rgb light fixtures. This library works great for me and I wanted to implement a function to turn on/off the lights without setting the intensity value to zero (to save the color for the next run) or adding another button/switch.
So, I am currently trying to make the ColorPicker.OnClickListener(...)
which seems to be a View.OnClickListener(...)
work in order to toggle between on and off state.
This doesn't seem to work (at least for me) because the OnClick(View v){...}
override method in the Listener is never called although I'm touching my virtual emulator's display and I set the ColorPicker clickable beforehand.
Is there any way to make it work? Thank you!
[EDIT] OnClick(View v){...}
could be called by ColorPicker object .performClick();
Dear users of HoloColorPicker,
I am aware of the issue, but due to school and work
I havent had much time to resolve it.
It will try to work it out as soon as possible!!
Thanks
Lars
Since updating the COLORS[] array breaks setColor() I am unable to customize the colors.
Please add a way to select black and white
Hi all,
selecting the (final) color over the SVBar triggers no OnColorSelected-Event. (onColorChanged-Events will be triggered fine)
I think this case should be fixed, it should trigger the onColorSelected Event?
case MotionEvent.ACTION_UP:
mIsMovingPointer = false;
break;
}
[https://github.com/LarsWerkman/HoloColorPicker/blob/master/libary/src/main/java/com/larswerkman/holocolorpicker/SVBar.java#L378]
I am getting below exception (Please see attached screenshot )
Stack trace
android.content.res.Resources$NotFoundException: Could not find attr resource matching value 0x7FFF0004 (resolved name: bar_thickness) in current configuration.
at android.content.res.BridgeResources.throwException(BridgeResources.java:699)
at android.content.res.BridgeResources.getDimensionPixelSize(BridgeResources.java:412)
at com.larswerkman.holocolorpicker.OpacityBar.init(OpacityBar.java:188)
at com.larswerkman.holocolorpicker.OpacityBar.(OpacityBar.java:175)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:375)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:100)
at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
at android.view.LayoutInflater.inflate(LayoutInflater.java:500)
at android.view.LayoutInflater.inflate(LayoutInflater.java:381)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:395)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:575)
at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:564)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:564)
at com.android.tools.idea.rendering.RenderService.render(RenderService.java:691)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:586)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:80)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$6$1.run(AndroidLayoutPreviewToolWindowManager.java:528)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$6.run(AndroidLayoutPreviewToolWindowManager.java:523)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Library version -
compile 'com.larswerkman:HoloColorPicker:1.4'
am i doing anything wrong ?
my name is hendy, i'm still newbie in this java(android) programming. your library is awesome and look very nice, but sorry for asking this, i already download this librarry, now my problem is how to add this library to my current project? thanks.
Hi, first off, I like your color picker a lot and I want to thank you for developing it and releasing it to the public. I have been trying to make use of your color picker in my own project, however I ran into some problems:
When I try to add a bar to the ColorPicker, my android app crashes with an "Unfortunately, your app has stopped." error.
Code:
Dialog d = new Dialog(this);
d.setTitle("Color Picker:");
d.setContentView(R.layout.dialog_colorpicker);
ColorPicker picker = (ColorPicker) findViewById(R.id.picker);
SVBar svBar = (SVBar) findViewById(R.id.svbar);
OpacityBar opacityBar = (OpacityBar) findViewById(R.id.opacitybar);
picker.addSVBar(svBar);
picker.addOpacityBar(opacityBar);
d.show();
Layout XML:
<com.larswerkman.holocolorpicker.ColorPicker
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.larswerkman.holocolorpicker.SVBar
android:id="@+id/svbar"
android:layout_width="322dp"
android:layout_height="112dp"
android:layout_gravity="center"
android:layout_margin="8dip"/>
<com.larswerkman.holocolorpicker.OpacityBar
android:id="@+id/opacitybar"
android:layout_width="322dp"
android:layout_height="112dp"
android:layout_gravity="center"
android:layout_margin="8dip"/>
If I don't add the bars to the picker, everything runs fine and the dialog gets displayed.
Furthermore I would like to add that viewing the dialog_colorpicker.xml in Design mode gives a "Render error: Render error" in android studio. In Text mode everything is fine.
For the record I am fairly new to android development and have just started using android studio, so it is possible I have included/imported something wrong. But seeing as it displays just fine when I don't add the bars to the picker, everything appears to have been included fine.
We can set just black and white, but cant grey
deleted...
If someone still have interests to this project you can take a look to my "not exactly fork".
I just take sikaiser fork, fixed a couple of bugs and adapted this view to use with androidx:preference
and google.material
libraries.
So in my "fork" you can use ColorPicker
as simple view or already prepared DialogPreference
.
Here is the link
setColor() is only setting the pointer color to the desired color, however, the center sphere is ignored.
SOLUTION:
within setColor(), replace :
mPointerColor.setColor(calculateColor(mAngle));
by:
updateColor(calculateColor(mAngle));
remove the android-support-v4.jar. It's not needed for this library. And it's an outdated version.
Thanks!
When I combine the picker with ValueBar and SaturationBar, the onChangeListener in ColorPicker.setNewCenterColor()
is fired several times. Reason is that each bar does its color calculation on the center circle color value and sets its value to the newly calculated one.
So, having a ValueBar and a SaturationBar fires three events in case I rotate the Picker:
I have no idea how to link color calculation correctly, so my quick and dirty hack is to introduce a boolean mEventMode
with appropriate getter/setter and disable the firing of the Listener from each bar (touchEvent):
mPicker.setEventModeDisabled(true);
mPicker.setNewCenterColor(mColor);
mPicker.setEventModeDisabled(false);
mPicker.changeValueBarColor(mColor);
mPicker.changeOpacityBarColor(mColor);
Since this is dirty, I'll refrain from committing anything :)
Imo, synching color calculation and correct Bar isolation from colorPicker requires major rework, on the bright side, nice UI component...
Thank you for making a very useful library. It really helps. There is a favor to ask. I'd like you to create a release tag of version 1.5 Thank you.
It just occurred to me that ColorPicker does not have any sort of interface for knowing when the color has changed. It would be nice to have this for apps that use the color picker and display a preview of what consequences it has.
An idea that I used in a similar picker written as a jQuery plugin some time ago: when the user goes around the color wheel on the outside, make the colors snap to distinct values. This makes it easier to select standard colors. The required small modification (but it could be beefed up, of course, to elevate it to an attribute to allow enable/disable and specification of the snap frequency):
in ColorPicker.onTouchEvent():
case MotionEvent.ACTION_MOVE:
if (mUserIsMovingPointer) {
mAngle = (float) java.lang.Math.atan2(y - mSlopY, x - mSlopX);
float radius = (float) Math.sqrt(x * x + y * y);
if (radius > mColorWheelRadius) {
float mAngleDeg = (float) (mAngle * 180 / Math.PI);
mAngleDeg = Math.round(mAngleDeg / 15) * 15;
mAngle = (float) (mAngleDeg * Math.PI / 180);
}
mPointerColor.setColor(calculateColor(mAngle));
I'm looking for a good color picker to use in the preferences of my app.
HoloColorPicker looks like a nice library. Any plans to create a "HoloColorPickerPreference"?
sometimes, it is necessary to avoid doing blocking stuff while the user is interacting with the controls. Unfortunately, with the current implementation, the super.isInTouchMode()
always returned true
. Maybe implement an overriden version that utilizes the already present touch event and simply returns false
if neither the colorPicker nor any linked bars are touched by the user.
Would possibly require public getters/setters in colorpicker for the mUserIsMovingPointer
variable, so that that it can be set from bars as well and developers only need to query colorPicker.isInTouchMode()
.
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.