skydoves / ColorPickerPreference

🎨 A library that lets you implement ColorPicker, ColorPickerDialog, ColorPickerPreference.
Apache License 2.0
477 stars 51 forks source link

support building preference in code #29

Closed ethanmdavidson closed 2 years ago

ethanmdavidson commented 2 years ago

This PR allows the preference configuration to be set in code, allowing this library to be used when programmatically building a preference screen. For example:

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
    val context = preferenceManager.context
    val screen = preferenceManager.createPreferenceScreen(context)

    val colorPref = ColorPickerPreference(context).apply {
        key = getString(R.string.bgColorKey)
        title = "Background Color"
        defaultColor = R.color.black
        attachAlphaSlideBar = false
        positive = "Confirm"
        negative = "Cancel"
        onInit()
        getColorPickerView().flagView = BubbleFlag(context)
    }
    screen.addPreference(colorPref)

    preferenceScreen = screen
}

Types of changes

What types of changes does your code introduce?

The only changes needed were making a couple fields/methods public.

skydoves commented 2 years ago

This fix was included in the new release 2.0.6. Thank you for your contribution!

ethanmdavidson commented 2 years ago

You're welcome! Thank you for this wonderful color picker! I'm using it in my app https://github.com/ethanmdavidson/DeathProgress

skydoves commented 2 years ago

Very motivational application. :] Amazing. Your application description and this article are very interesting. I'm following Year Progress on Twitter for planning and retrospective of my life (this year), this kind of concept would be also helpful. 😃

ethanmdavidson commented 2 years ago

I hadn't seen that before! I really like the idea of a year one as well, or maybe even letting the user pick which bar they want to display. Thanks for sharing, I've got a ton more ideas now! :grin: