QuadFlask / colorpicker

🍭color picker for android
1.22k stars 219 forks source link

currentColorCircle is null if the ColorPickerView doesn't get a chance to render #106

Closed nathansbird closed 4 years ago

nathansbird commented 5 years ago

I added the flower color picker view into an alert dialog to allow my users to be able to pick a color in a popup. A bug I just noticed is that if the ColorPickerView's visibility is set to View.GONE before the popup is displayed, calling something like setLightness() throws a NullPointerException stating that the currentColorCircle is null. I'll just have to find a workaround for this in the meantime but looking around in the source code for this library, I noticed the root cause of this issue is that a lot of the logic relies on a render to happen at some point in time.

Crash report for reference:

java.lang.NullPointerException: Attempt to invoke virtual method 'float[] com.flask.colorpicker.ColorCircle.getHsvWithLightness(float)' on a null object reference
        at com.flask.colorpicker.ColorPickerView.setLightness(ColorPickerView.java:361)
        at com.symetium.common_base.Settings.ColorPickerDialog$4.run(ColorPickerDialog.java:172)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6680)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
PaulBreugnot commented 5 years ago

Same issue, personally I have this problem when I want to initialize the ColorPicker (and especially the LightnessSlider) with a predefined value before it appears for the first time.

EDIT : The problem doesn't show up if the visibility of the ColorPickerView is initially set to View.INVISIBLE instead of View.GONE. Of course, it's not the same behavior, but this can be a good workaround in some cases.