chiralcode / Android-Color-Picker

Color picker for Android
Apache License 2.0
193 stars 65 forks source link

Preview for PreferenceCategory #2

Closed vanniktech closed 8 years ago

vanniktech commented 10 years ago

Originally, I wanted to fork the project and create a pull request. Since there were unstaged files directly from the beginning (after git pull from my work), I will write the change here. I added a preview to the ColorPickerPreference, where the color will be drawn in a Rectangle on the right side of the category.

Simply add this stuff to the ColorPickerPreference class:

private LinearLayout preview;

@Override
protected View onCreateView(ViewGroup parent) {
    final LinearLayout view = (LinearLayout) super.onCreateView(parent);

    preview = new LinearLayout(getContext());
    preview.setLayoutParams(new LinearLayout.LayoutParams(60, 60));
    preview.setBackgroundColor(selectedColor);
    preview.invalidate();

    view.addView(preview);

    return view;
}

Overrite the onDialogClosed function with:

@Override
protected void onDialogClosed(boolean positiveResult) {
    if (positiveResult && shouldPersist()) {
        if (callChangeListener(colorPickerView.getColor())) {
            selectedColor = colorPickerView.getColor();
            persistInt(selectedColor);
            preview.setBackgroundColor(selectedColor);
        }
    }
}

You may want to merge this, you may not. It's up to you. I just felt the need to share it, since I find it kinda nice to see the color in a little preview.

vanniktech commented 8 years ago

@chiralcode Do you want to me to submit a PR?

vanniktech commented 8 years ago

If so please reopen this one.