B4J Library BCColorPicker - nice color picker

K1EiGqbdWu.gif

(this is an animated gif, it looks better in real use)

This is a powerful color picker, based on XUI Views B4XColorTemplate. It is a B4J control, though it should be simple to port it to B4A and B4i.
Note that it uses the new CLVSelections class: https://www.b4x.com/android/forum/t...modes-for-xcustomlistview.114364/#post-714398

Usage is simple, add with the designer and handle the ColorSet event.

Depends on: XUI Views and ByteConverter

Note that it runs better in release mode due to the many TextChanged event that are raised internally.

Updates:

v1.02 - Bug fixes and improvements
 

Attachments

  • BCColorPickerExample.zip
    3 KB · Views: 525
  • BCColorPicker.b4xlib
    9.4 KB · Views: 572
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
Is the color value 64 bit? It kept blowing up on me until I removed the leading F.
 

MrKim

Well-Known Member
Licensed User
Longtime User
Is there any way to just get the list of colors on the right and have it return the value when clicked? I covet that list. It is the same. I believe, as in the Designer and just that alone would suit my needs perfectly.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is the color value 64 bit? It kept blowing up on me until I removed the leading F.
Color values in B4X are Ints (32 bits)

Is there any way to just get the list of colors on the right and have it return the value when clicked?
I'm not sure that I understand what you mean however you can use the source code of this library and change it to behave as you like.
 

MrKim

Well-Known Member
Licensed User
Longtime User
Color values in B4X are Ints (32 bits)
I was fiddling around with the example and added a BBLabel and was setting the color.
B4X:
Sub BCColorPicker1_ColorSet (ColorValue As Int)
    Pane1.Color = ColorValue
    Try
    'Colors.Text = NumberFormat(ColorValue, 20, 0)
        'Log("[color=#" & BCColorPicker1.ColorToHex(ColorValue) & "]" & NumberFormat(ColorValue, 20, 0) & "[/color]")
        Colors.Text = "[color=#" & BCColorPicker1.ColorToHex(ColorValue).SubString(1) & "]Xx" & BCColorPicker1.ColorToHex(ColorValue)  & "xxxX[/color]"
        Colors.Text = "[color=#" & BCColorPicker1.ColorToHex(ColorValue) & "]Xx" & BCColorPicker1.ColorToHex(ColorValue)  & "xxxX[/color]"
    Catch
        Log(LastException)
    End Try
End Sub
This line works and sets the color correctly:
B4X:
        Colors.Text = "[color=#" & BCColorPicker1.ColorToHex(ColorValue).SubString(1) & "]Xx" & BCColorPicker1.ColorToHex(ColorValue)  & "xxxX[/color]"
This line fails:
B4X:
        Colors.Text = "[color=#" & BCColorPicker1.ColorToHex(ColorValue) & "]Xx" & BCColorPicker1.ColorToHex(ColorValue)  & "xxxX[/color]"
With the following error:
B4X:
Error occurred on line: 308 (BBCodeParser)
java.lang.NumberFormatException: For input string: "ff0000ff"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:583)
    at anywheresoftware.b4a.keywords.Bit.ParseInt(Bit.java:86)
    at b4j.example.bbcodeparser._parsecolorstring(bbcodeparser.java:1160)
    at b4j.example.bbcodeparser._texttorun(bbcodeparser.java:322)
    at b4j.example.bbcodeparser._createruns(bbcodeparser.java:174)
    at b4j.example.bblabel._parseanddraw(bblabel.java:136)
    at b4j.example.bblabel._settext(bblabel.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:442)
    at b4j.example.bccolorpicker._raiseevent(bccolorpicker.java:493)
    at b4j.example.bccolorpicker._btnsetnew_click(bccolorpicker.java:478)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:748)
(Exception) java.lang.Exception:  java.lang.NumberFormatException: For input string: "ff0000ff"
 
Top