OneUIProject/OneUI-Design-Library

Question!!!. ClassicColorPickerDialog.java

Closed this issue · 2 comments

I have a question about 'ClassicColorPickerDialog.java'.

in the method 'public void onClick(DialogInterface dialogInterface, int i) {}' part,

this.mOnColorSetListener.onColorSet(this.mColorPicker.getRecentColorInfo().getSelectedColor().intValue());

I'd like to know where the onColorSet function is implemented.
It is declared an abstract method in 'public interface OnColorSetListener{}'.

I would like to understand the process of color selection and processing in ClassicColorPickerDialog.
It may be cumbersome, but if you know, please answer.

The onColorSet method in the dialogs is abstract because it needs to be declared in each dialog instance you create. Here's a little example:

ClassicColorPickerDialog mClassicColorPickerDialog;
mClassicColorPickerDialog = new ClassicColorPickerDialog(this,
    new ClassicColorPickerDialog.OnColorSetListener() {
        @Override
        public void onColorSet(int i) {
        // do stuff
        },
    Color.WHITE);
mClassicColorPickerDialog.show();

ClassicColorPickerDialog in this case needs three arguments to be passed: Context, a OnColorSetListener instance and the starting color for the ColorPicker. The dialog once instatiated will save the given listener in a field and call it when the dialog positive button is pressed:

@Override
public void onClick(DialogInterface dialogInterface, int i) {
    Integer num;
    if (i == -1) {
        this.mColorPicker.saveSelectedColor();
        if (this.mOnColorSetListener == null) {
            return;
        }
        if (this.mColorPicker.isUserInputValid() || (num = this.mCurrentColor) == null) {
            this.mOnColorSetListener.onColorSet(this.mColorPicker.getRecentColorInfo().getSelectedColor().intValue());
        } else {
            this.mOnColorSetListener.onColorSet(num.intValue());
        }
    }
}

I understand!. Thanks.