martin-stone / hsv-alpha-color-picker-android

A color picker and a color preference for use in Android applications.
Apache License 2.0
290 stars 60 forks source link

When creating ColorPreference programmatically defaultValue not works #45

Closed matzrm closed 6 years ago

matzrm commented 6 years ago

I'm creating preference screen programmatically and I'm putting a ColorPrefrence inside it in this way:

ColorPreference pref= new ColorPreference(getActivity(),null);
pref.setTitle("Color");
pref.setKey("pref_color");
pref.setDefaultValue("#000000"); // or Color.WHITE

The problem is that until I change the color the thumbail isn't shown, because in method onSetInitialValue() of ColorPreference defaultValue is loaded right but not used as argument into setColor(). Programmatically there'isnt a way to set the defaultColor. Isn't it?

@Override
protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
    setColor(restorePersistedValue ? getColor() : defaultColor);
}
martin-stone commented 6 years ago

Yes I think onGetDefaultValue and onSetInitialValue may not be doing quite the right thing at the moment. Looking into it.

martin-stone commented 6 years ago

Fixed in 2.4.0.