skydoves / ColorPickerView

🎨 Android colorpicker for getting colors from any images by tapping on the desired color.
Apache License 2.0
1.57k stars 211 forks source link

The ColorPickerDialog is not supporting an initialColor and a FlagView #104

Open juliswer opened 1 year ago

juliswer commented 1 year ago

Overview

Bug: As in the ColorPickerView component, I'd expect to have the same options on the ColorPickerDialog. What do I mean with the same options? Im talking about the method .setInitialColor() and the ability to set a flagView as well.

Do you have some solution to set an initial color in a ColorPickerDialog?

skydoves commented 10 months ago

Hey @juliswer, have you ever tried the way below?

ColorPickerView colorPickerView = builder.getColorPickerView();
colorPickerView.setFlagView(new CustomFlag(this, R.layout.layout_flag)); // sets a custom flagView
colorPickerView. setInitialColor(..)
juliswer commented 10 months ago

hey @skydoves. Yes, i did. The issue is that the code you provided me with is referred to a ColorPickerView, but I'm using a ColorPickerDialog.

This ColorPickerDIalog is not allowing the same methods (setInitialColor & setFlagView) than the ColorPickerView.

this is my implementation:

val colorPickerDialog = ColorPickerDialog.Builder(context, R.style.ColorPickerDialog)
            .setTitle("Pick a Color")
            .setPreferenceName("ColorPickerDialog")
            .setPositiveButton("Apply",
                ColorEnvelopeListener { envelope, _ ->
                    // beauty color
                })
            .setNegativeButton(
                "Cancel"
            ) { dialogInterface, _ -> dialogInterface.dismiss() }
            .setNeutralButton("Delete color") { _, _ -> deleteColor(colorPosition) }
            .attachAlphaSlideBar(false)
            .attachBrightnessSlideBar(true)
            .setBottomSpace(12)
            .show()
floyder commented 2 months ago

@juliswer You can extend the class and use something like this

public Builder setDefaultColor(int code) {
    if (getColorPickerView() != null) {
        getColorPickerView().setInitialColor(code);
    }
    return this;
}