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

More documentation on direct usage of ColorPickerView #4

Closed AkshayChordiya closed 9 years ago

AkshayChordiya commented 9 years ago

Hi @martin-stone

I'm using try to use ColorPickerView directly inside a Dialog specifically AlertDialog but the view doesn't look like the one shown in the screenshot on main page.

P.S: I like your library & I appreciate your work.

AkshayChordiya commented 9 years ago

@martin-stone Extremely sorry I fixed it easily.

Rainer-Lang commented 9 years ago

Maybe you could share your solution. :smiley:

AkshayChordiya commented 9 years ago

@Rainer-Lang Oh yeah sure, thanks for reminding.

  1. Create a Dialog & add the following code:
View view = GET_YOUR_DIALOG_VIEW
colorPickerView = (ColorPickerView) view.findViewById(R.id.colorPicker);
colorPickerView.setColor(YOUR_COLOR);
colorPickerView.showAlpha(true);
colorPickerView.showHex(true);
  1. Set custom view layout to Dialog
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.rarepebble.colorpicker.ColorPickerView
        android:id="@+id/colorPicker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</FrameLayout>
Rainer-Lang commented 9 years ago

Thanks. The color dialog is really big. How about scrolling (older devices)? Put in a scrollview? How about making a pr? ;-)

AkshayChordiya commented 9 years ago

@Rainer-Lang Actually I didn't need a ScrollView so I didn't use it. You can add it as root element in the above example. I'd love to PR but my code is based on upon 3rd Party Dialog library

Rainer-Lang commented 9 years ago

I use also a lib - material-dialogs.

AkshayChordiya commented 9 years ago

@Rainer-Lang Cool. Here's the complete code for Dialog side

MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
                .title(YOUR_TITLE)
                .positiveText(android.R.string.ok)
                .negativeText(android.R.string.cancel)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        // Save color here
                        // Reflect the color on UI
                    }
                })
                .customView(THE_LAYOUT_MENTIONED_ABOVE, false)
                .build();

        View view = dialog.getCustomView();
        colorPickerView = (ColorPickerView) view.findViewById(R.id.colorPicker);
        colorPickerView.setColor(YOUR_COLOR);
        colorPickerView.showAlpha(true);
        colorPickerView.showHex(true);

I hope this helps you

Rainer-Lang commented 9 years ago

@AkshayChordiya WOW cool. :-) I also have a button for neutral="select no color". But I have a problem with scrolling this custom view in material-dialogs. Aidan said, that the material-dialogs are ok and the problem should be searched in the custom view. The height isn't calculated properly. I don't know - I haven't found anything... :-(

AkshayChordiya commented 9 years ago

@martin-stone I feel you copy the code which I pasted above, I mean the MaterialDialog code & then tweak the Layout by wrapping the Views inside with a ScollView This should give you the functionality which you require.

Rainer-Lang commented 9 years ago

@AkshayChordiya Do you think this would help? This would be really awesome! :-)

AkshayChordiya commented 9 years ago

@Rainer-Lang It should help