Closed eku closed 4 years ago
@eku Hi,
I think you can solve it using selectByHsv
method.
But there are some constraints for using the method.
The palette should be used the default palette in the internal ColorPickerView.
And here is the demo project.
@skydoves thanks for the hint. I'm using the default palette.
There's only one problem. At what point can you call the method to make it work? The calculated radius
is always zero, so the point is centered. Even in the onResume
of the fragment that uses the ColorPickerView
in its layout, this still seems to be too early.
@eku A view tree observer is used to register listeners that can be notified of global changes in the view tree. You can get notified when view loading finished.
colorPickerView.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
colorPickerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
else {
colorPickerView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
// doSomething
}
});
That worked somehow. But the calculation of the position is wrong.
What if I use the Dialog, what to do then?
For anyone who looks for workaround, I found out that selectByHsv works correctly only, if that palette is used:
@xinaiz I would prefer a correct calculation rather than another palette image.
Is there a way to go around this then? I'd like to set a pure color and get the selector and brightness bar updated correctly
Just to explain the problem with code:
colorPickerView.colorListener = ColorEnvelopeListener { envelope: ColorEnvelope, fromUser ->
if (fromUser) {
println("""First color: ${envelope.hexCode}""")
colorPickerView.selectByHsv(envelope.color)
println("""Second color: ${colorPickerView.colorEnvelope.hexCode}""")
}
}
This will print out two different colors.
Which means if you feed the colorPickerView
with the same color it gives you, it produces a different color
Any news about this issue? @eku
@barkantoprak I switched to Android-Color-Picker.
colorPickerView.selectByHsv(Color.parseColor("#FF0099CC")); is not working for me. It would be better for this to work so we can add default value.
I would also like to be able to do this. I am using setPureColor just to get the color initially selected correctly but as others have pointed out it doesn't move the selector properly.
@eku The calculation is correct, it's the palette image which needs to be changed.
@skydoves The palette can be circular (it doesn't have to be the hexagon mentioned above), but it cannot be what it is now. It needs to be HSV/HSL color model palette, for example something like this:
Notice how the colors are laid out a bit differently when compared to the old palette: Red is always on the right side (0°), but then the colors are a bit shifted (e.g. cyan should correctly be exactly at 180°, but it's at cca 225° on the original palette).
I took a look at your code and you're not doing anything wrong. You're calling the android.graphics.Color.colorToHSV(color, hsv);
method which converts the given ARGB color (the alpha component is ignored) to its HSV components. You just need to use the HSV palette, otherwise the first HSV component (hue) (hsv[0]
) (which is basically the angle) won't be represented correctly on the palette.
I couldn't find the required palette in better resolution, though. I tried making it as xml drawable, but I failed.
Is there a way to have the palette drawn by Android at runtime instead of bringing it as a drawable resource?
The above mentioned Android-Color-Picker draws it at runtime.
Hi, @teapack, @eku! I'm actually already worked on solutions and below functions will be released in the next version.
The default palette drawable is ColorHsvPalette
if not set a palette. This method can be used for changing as ColorHsvPalette
from another palette drawable.
changes selector's selected point by a specific color.
changes selector's selected point by a specific color resource.
The default palette will be drawn using ColorHuePalette. ColorHuePalette is a default drawable palette build by HSV (hue, saturation, value) color model for alternating representations of the RGB color model.
And now you can build and test using the demo project. Thank you for your issue :)
Hey guys,
It is released a new version 2.1.9!
Now we can use the selectByHsvColor(color)
and selectByHsvColorRes(resource)
properly in the new release.
Thank you for your conversations and issues. 👍
After all, after more than a year we now have a solution to the problem. Thanks for that.
Thanks to everyone who made conversations and tried to resolve this issue. 🎉
When creating ColorPickerView, I want to specify an RGB color initially and expect the selector to be placed on the corresponding color in the color wheel as well as in the brightness slider.
The method setPureColor is not suitable for this.
Persisting via the PreferencesManager is not desired.