QuadFlask / colorpicker

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

Setting an initial color #103

Closed Colonieves closed 6 years ago

Colonieves commented 6 years ago

Hi, I think the .initialColor(int i) is not working when used as a dialog box. It is working fine when used as a widget.

Here you have both codes using the same testColor <colorname="testColor">#34FF00

Could you tell me please if I am doing anything wrong or if it is the component that is not working as expected?

Cheers!

AS A DIALOG BOX (displaying a gray-ish color)

 pickColorButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Context context = EditItemActivity.this;

                ColorPickerDialogBuilder
                        .with(context)
                        .setTitle("Choose color")
                        .initialColor(R.color.testColor)
                        .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
                        .density(10)
                        .setOnColorSelectedListener(new OnColorSelectedListener() {
                            @Override
                            public void onColorSelected(int selectedColor) {
                                toast("onColorSelected: 0x" + Integer.toHexString(selectedColor));
                            }
                        })
                        .setPositiveButton("ok", new ColorPickerClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
                                changeBackgroundColor(selectedColor);
                            }
                        })
                        .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        })
                        .build()
                        .show();
            }
        });

whatsapp image 2018-07-13 at 16 13 06

AS A WIDGET (displaying the correct color)

<com.flask.colorpicker.ColorPickerView
                android:id="@+id/color_picker_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:alphaSlider="true"
                app:density="12"
                app:lightnessSlider="true"
                app:wheelType="FLOWER"
                app:lightnessSliderView="@+id/v_lightness_slider"
                app:alphaSliderView="@+id/v_alpha_slider"
                app:initialColor="@color/testColor"
                />

            <com.flask.colorpicker.slider.LightnessSlider
                android:id="@+id/v_lightness_slider"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                />

            <com.flask.colorpicker.slider.AlphaSlider
                android:id="@+id/v_alpha_slider"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                />

whatsapp image 2018-07-13 at 16 13 05

Colonieves commented 6 years ago

My mistake is that R.color.testColor should be in the shape of 0xffffffff Once I formatted it like that, it worked. I am closing this issue as it is not valid.