QuadFlask / colorpicker

🍭color picker for android
1.22k stars 219 forks source link

How to get selected color in view mode #55

Closed Nirvanatin closed 8 years ago

Nirvanatin commented 8 years ago

I would appreciate it If you could help me to get the selected color in view mode (not dialog). How should I write the listener for each color which has been selected?

Thank you in advance.

ghost commented 8 years ago

This is how ColorPickerDialogBuilder did it: https://github.com/QuadFlask/colorpicker/blob/2d4081c73df36d5db30b2d68712d2b44469a1eed/library/src/main/java/com/flask/colorpicker/builder/ColorPickerDialogBuilder.java#L89

    public ColorPickerDialogBuilder setOnColorSelectedListener(OnColorSelectedListener onColorSelectedListener) {
        colorPickerView.addOnColorSelectedListener(onColorSelectedListener);
        return this;
    }
Nirvanatin commented 8 years ago

I'm trying to call that method from SampleActivity2 but couldn't. Can I ask you for help with this?

QuadFlask commented 8 years ago

@JToward How did you write the code?

Nirvanatin commented 8 years ago

I mess up with the code and gave up. Is it possible for you to write that part of the code to get the selected color and show it in a toast message in view mode? I would greatly appreciate it if you could help me. Thank you.

QuadFlask commented 8 years ago

@JToward you can use addOnColorSelectedListener method to get selected color.

ColorPickerView colorPickerView = (ColorPickerView) findViewById(R.id.color_picker_view);
        colorPickerView.addOnColorSelectedListener(new OnColorSelectedListener() {
            @Override
            public void onColorSelected(int selectedColor) {
                Toast.makeText(
                        SampleActivity2.this,
                        "selectedColor: " + Integer.toHexString(selectedColor).toUpperCase(),
                        Toast.LENGTH_SHORT).show();
            }
        });

I updated SampleActivity2 code, check out this

Nirvanatin commented 8 years ago

Thanks a lot.