SeslColorPickerDialogFragment

A DialogFragment that shows a color picker.

The basic SeslColorPickerDialogFragment is created using newInstance and the show method.

The newInstance constructor can be used to provide an initial color for the dialog.

The newInstance constructor can be used to provide an array of recently used colors.

The newInstance constructor can be used to provide an initial color, an array of recently used colors and whether to show the opacity bar.

The newInstance constructor can be used to provide an initial color, an array of recently used colors, whether to show the opacity bar, and whether to show only the spectrum view.

Note: You should pay attention to fragment lifecycle. When the activity is recreated (e.g. on configuration change), the fragment will also be recreated. In this case, you should use the setOnColorChangedListener method to set the listener again in the onCreate method of your activity.

If you want to use the eye dropper feature, your Activity must implement SeslColorPickerDialogFragment.OnBitmapSetListener. The onBitmapSet method will be called to get the Bitmap to be used for the eye dropper.

Example:

public class MyActivity extends AppCompatActivity implements SeslColorPickerDialogFragment.OnBitmapSetListener {
    private SeslColorPickerDialogFragment mColorPickerDialogFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create the color picker dialog fragment with a color set listener
        mColorPickerDialogFragment = SeslColorPickerDialogFragment.newInstance(
            new SeslColorPickerDialogFragment.OnColorSetListener() {
                @Override
                public void onColorSet(int color) {
                    // Handle the selected color
                    findViewById(R.id.colorPreview).setBackgroundColor(color);
                }
            },
            Color.RED, // initial color
            new int[] {Color.RED, Color.GREEN, Color.BLUE}, // recently used colors
            true, // show opacity bar
            false // show only spectrum
        );

        // Optionally set a color changed listener (e.g., for live preview)
        mColorPickerDialogFragment.setOnColorChangedListener(new SeslColorPicker.OnColorChangedListener() {
            @Override
            public void onColorChanged(int color) {
                // Live update preview
                findViewById(R.id.colorPreview).setBackgroundColor(color);
            }
        });

        // Show the dialog when needed, e.g., on button click
        findViewById(R.id.showColorPickerButton).setOnClickListener(v -> {
            mColorPickerDialogFragment.show(getSupportFragmentManager(), "color_picker");
        });
    }

    // Implement the OnBitmapSetListener for the eye dropper feature
    @NonNull
    @Override
    public Bitmap onBitmapSet() {
       return BitmapFactory.decodeResource(getResources(), R.drawable.your_drawable)
    }
}

Replace R.id.colorPreview and R.id.showColorPickerButton with actual view IDs from your layout. The onBitmapSet() method should return the bitmap you want to use for the eye dropper feature. Remember to set the listeners again after configuration changes if needed, as described above.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
Interface definition for a callback to be invoked to get the Bitmap for the eye dropper.
Link copied to clipboard
Interface definition for a callback to be invoked when a color is set in the dialog.

Functions

Link copied to clipboard
open fun disableEyeDropper(disable: Boolean)
Link copied to clipboard
Link copied to clipboard
@NonNull
open fun newInstance(@Nullable listener: @Nullable SeslColorPickerDialogFragment.OnColorSetListener): @NonNull SeslColorPickerDialogFragment
@NonNull
open fun newInstance(@Nullable listener: @Nullable SeslColorPickerDialogFragment.OnColorSetListener, currentColor: Int): @NonNull SeslColorPickerDialogFragment
@NonNull
open fun newInstance(@Nullable onColorSetListener: @Nullable SeslColorPickerDialogFragment.OnColorSetListener, recentlyUsedColors: Array<Int>): @NonNull SeslColorPickerDialogFragment
@NonNull
open fun newInstance(@Nullable onColorSetListener: @Nullable SeslColorPickerDialogFragment.OnColorSetListener, currentColor: Int, recentlyUsedColors: Array<Int>, showOpacityBar: Boolean): @NonNull SeslColorPickerDialogFragment
@NonNull
open fun newInstance(@Nullable onColorSetListener: @Nullable SeslColorPickerDialogFragment.OnColorSetListener, currentColor: Int, recentlyUsedColors: Array<Int>, showOpacityBar: Boolean, showOnlySpectrum: Boolean): @NonNull SeslColorPickerDialogFragment
Link copied to clipboard
open fun onActivityCreated(@Nullable bundle: @Nullable Bundle)
Link copied to clipboard
open fun onClick(dialog: DialogInterface, whichButton: Int)
Link copied to clipboard
open fun onCreate(@Nullable savedInstanceState: @Nullable Bundle)
Link copied to clipboard
@NonNull
open fun onCreateDialog(@Nullable savedInstanceState: @Nullable Bundle): @NonNull Dialog
Link copied to clipboard
open fun onCreateView(@NonNull inflater: @NonNull LayoutInflater, @Nullable container: @Nullable ViewGroup, @Nullable savedInstanceState: @Nullable Bundle): @Nullable View
Link copied to clipboard
open fun onSaveInstanceState(@NonNull outState: @NonNull Bundle)
Link copied to clipboard
open fun setNewColor(@Nullable newColor: @Nullable Integer)
Link copied to clipboard
open fun setOnColorChangedListener(@Nullable listener: @Nullable SeslColorPicker.OnColorChangedListener)
Sets the listener to be called when the color is changed.
Link copied to clipboard
Link copied to clipboard