QuadFlask / colorpicker

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

Add a listener of slider? #69

Open frog1014 opened 7 years ago

frog1014 commented 7 years ago

Is it possible to add the listener for sliders? And we can get the final selected color without one more click on color hue

QuadFlask commented 7 years ago

If you use layout xml, you can add listener when value changed like

final AlphaSlider alphaSlider = (AlphaSlider) rootView.findViewById(R.id.v_alpha_slider);
alphaSlider.setOnValueChangedListener(new OnValueChangedListener() {
    @Override
    public void onValueChanged(float value) {
        // do something
    }
})

or if you using version 0.0.13 and dialog builder, you can add color changed listener like this

// 
ColorPickerDialogBuilder.with(context)
.setOnColorChangedListener(new OnColorChangedListener() {
    @Override
    public void onColorChanged(int selectedColor) {
        // Handle on color change
        Log.d("ColorPicker", "onColorChanged: 0x" + Integer.toHexString(selectedColor));
    }
})
frog1014 commented 7 years ago

I got the build error with v0.0.13

C:\work\android\app\build\intermediates\res\merged\debug\values-v24\values-v24.xml Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'. Error:(4) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'. Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'. Error:(4) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.

my config:

compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 21 targetSdkVersion 23

v0.0.12 works fine. May I have your help?

QuadFlask commented 7 years ago

I think android buildtool version is too old. Could you update compileSdkVersion 25 and targetSdkVersion 25 in app's build.gradle and update classpath 'com.android.tools.build:gradle:2.3.0-beta3' in project's build.gradle? I think This error relate to compile 'com.android.support:appcompat-v7:25.1.1'.

frog1014 commented 7 years ago

Thanks ! It works! But I have an issue: There is a similar debounce principle in OnColorSelectedListener(), but not in OnColorChangedListener(). Thus it makes too many events when sliding in hue or slider with OnColorChangedListener(). Is there a good way to avoid this?

Thanks much again!

QuadFlask commented 7 years ago

34 should be implement to do that