skydoves / ColorPickerView

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

ColorPicker behaving differently! #4

Closed IAmSarthakVerma closed 7 years ago

IAmSarthakVerma commented 7 years ago

When I am selecting a drawable for palette from java code and returning the int color, the color is different from what it actually should be. Please help Here is the code for color picker view xml file -

<LinearLayout
            android:id="@+id/custom_picker_layout"
            android:layout_width="0dp"
            android:layout_height="232dp"
            android:layout_marginTop="16dp"
            android:layout_weight="3"
            android:visibility="gone">

            <com.skydoves.colorpickerview.ColorPickerView
                android:id="@+id/custom_picker"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:selector="@drawable/dot" />

        </LinearLayout>

Here is the java code for setting the drawable and listening color change-

                Uri myuri = Uri.fromFile(new File(images.get(i).path));
                LinearLayout customPickerLayout = (LinearLayout) findViewById(R.id.custom_picker_layout);
                LinearLayout colorPickerLayout = (LinearLayout) findViewById(R.id.color_picker_layout);

                customPicker = (ColorPickerView) findViewById(R.id.custom_picker);

                try {
                    InputStream inputStream = getContentResolver().openInputStream(myuri);
                    myDrawable = Drawable.createFromStream(inputStream, myuri.toString() );
                } catch (FileNotFoundException e) {

                    {
                        Snackbar.make(findViewById(android.R.id.content), "Error loading image", Snackbar.LENGTH_LONG).setAction("Error", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                            }
                        }).show();
                    }

                }

                customPicker.setPaletteDrawable(myDrawable);

                colorPickerLayout.setVisibility(View.GONE);
                customPickerLayout.setVisibility(View.VISIBLE);
                customPicker.setPaletteDrawable(myDrawable);

                customPicker.setColorListener(new ColorPickerView.ColorListener() {
                    @Override
                    public void onColorSelected(int color) {

                        setbtn.setBackgroundColor(customPicker.getColor());

                    }
                });
skydoves commented 7 years ago

Hey guy, did you solved that issue?