martin-stone / hsv-alpha-color-picker-android

A color picker and a color preference for use in Android applications.
Apache License 2.0
290 stars 60 forks source link

Set Thump Position #31

Closed badeesindi closed 6 years ago

badeesindi commented 7 years ago

Thank you for your helpful solution. I have a question regarding positioning the thump. I've inflated the view but I can't set the thump on 100. I tried xml: android:progress="100" but it didn't work. Can you please provide me with a solution?

Here's my code:

edittextcolortext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LayoutInflater layoutInflaterco = LayoutInflater.from(MainActivity.this);
                final View promptViewco = layoutInflaterco.inflate(R.layout.cpicker, null);
                AlertDialog.Builder builderco = new AlertDialog.Builder(MainActivity.this);
                builderco.setView(promptViewco);

                final EditText colorpickeret = (EditText) promptViewco.findViewById(com.rarepebble.colorpicker.R.id.hexEdit);
                builderco.setPositiveButton(getString(R.string.savedialogyes), new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // Do nothing but close the dialog

                    }
                });

                builderco.setCancelable(false)
                        .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, final int id) {
                                String s = "#"+colorpickeret.getText().toString();
                                textsample.setTextColor(Color.parseColor(s));
                            }
                        });

                builderco.setNegativeButton(getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });

                // create an alert dialog
                AlertDialog alertco = builderco.create();
                alertco.show();

            }
        });
martin-stone commented 7 years ago

I'm not sure what you mean by "thump". What exactly are you trying to do?

badeesindi commented 7 years ago

I'm talking about the circle shaped object that changes ValueView and AlphaView when scrolled right or left. By default, I get 100% transparent AlphaView color unless I slide it to the other side for example. I'm trying to get 0% transparent color when I start the activity, then I get the option to increase the transparency.

in XML I tried to set the progress to 100 and 50 but nothing happened, I still get full transparency: The mover doesn't change its position.

<com.rarepebble.colorpicker.AlphaView
        android:progress="50"
        android:id="@+id/alphaView"
        android:layout_width="match_parent"
        android:layout_height="@dimen/sliderWidth"
        android:layout_marginBottom="@dimen/margin"
        />
martin-stone commented 7 years ago

The positions of the circles are determined by the color that you set. If you want to start with a particular transparency, then set the color with that transparency with ColorPickerView.setColor:

https://github.com/martin-stone/hsv-alpha-color-picker-android/blob/master/demo_app/src/main/java/com/rarepebble/colorpickerdemo/ViewDemoActivity.java#L18

Or in the preferences.xml with defaultValue:

https://github.com/martin-stone/hsv-alpha-color-picker-android/blob/master/demo_app/src/main/res/xml/preferences.xml#L9

The alpha view does not understand any XML configuration on its own. Only the ColorPickerView and the ColorPreference do anything with XML.

badeesindi commented 7 years ago

That worked just great. I had to make a few changes in my code. I appreciate your hardworking. Keep it up :)