Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onColorChangedListener triggers way to often (and first values are not valid) #60

Open
buttairfly opened this issue Nov 25, 2014 · 4 comments

Comments

@buttairfly
Copy link

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

@kj800x
Copy link

kj800x commented Apr 19, 2015

This is a major issue that I'm also experiencing.

@kj800x
Copy link

kj800x commented Apr 20, 2015

I've looked into the suggestion buttairfly gave, but that just delegates the event triggering to the bars (0 bars = 0 events, 1 bar = 1 event, 2 bars = 2 events). A better way to approach the problem would be for the colorpicker to ask the bars for their values, and use that to calculate the new color, and then only the colorpicker should be allowed to trigger the event. I'm working on a pull request for this.

ilueckel added a commit to ilueckel/HoloColorPicker that referenced this issue Jun 14, 2015
…, circle touch change with color manipulation through bars) to "int" (containing the color value). With a few additional tweaks the listener does not get notified about the intermediate steps when bars are attached to ColorPicker. Fixes LarsWerkman#60 of the original repository.
@jlarysz
Copy link

jlarysz commented Nov 23, 2015

I can't get this color picker to work in Android IDE 1.5. I'm stuck on a duplicate class in the build:

Execution failed for task ':app:transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/larswerkman/holocolorpicker/ColorPicker$OnColorChangedListener.class

and I can't find it. I've been looking all day - I think I have to try another color picker.

@holgi-s
Copy link

holgi-s commented Jan 8, 2016

Using the 1.5 version I also noticd that when using a SVBar the onColorChanged is triggered twice, and the 1st event actually contains the wrong color.

In ColorPicker.onTouchEvent()
1st event on line 631:
setNewCenterColor(mCenterNewColor = calculateColor(mAngle));
with the color of the circle, not respecting saturation and value

2nd event on line 646:
mSVbar.setColor(mColor);
this time with the correct color

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants