Colour Picker

61 views
Skip to first unread message

Steve Garman

unread,
Oct 10, 2015, 4:22:43 AM10/10/15
to androi...@googlegroups.com
I had to write myself a colour picker a bit more traditional than the one that is on the wiki and I wondered if it would be any use to anyone else.

The image file I used was one I found on my PC drive and I am not sure about its copyright status. So if you intend to use the picker, please replace it with an image of your own.

If all else fails, just delete it and the code will create one for you but the colours are not well organised.


Edited August 2018 to replace the spk as the forum no longer allows the old format

colourPicker.spk

Steve Garman

unread,
Oct 10, 2015, 5:06:26 AM10/10/15
to AndroidScript
I suppose not everything about the picker is obvious.

The colour picker is actually a layout which can be added to another layout using lay.AddChild or directly to the app, using app.AddLayout.

The picker is created using the line
cPick = createColorPicker(callback);
where callback is a function that is called when the user presses the " select section"

The picker has two methods
cPick.Show()
cPick.Hide()

When the user touches the multi-colour section, the lower "select" section changes colour to match the colour touched.

When the user touches the "select" section, the picker hides itself and calls the callback function with a single argument ( colour ) which represents the current colour of the "select" section.

Durga Prasad

unread,
Oct 10, 2015, 6:18:48 AM10/10/15
to AndroidScript
Hi Steve,

That's really a good one. I have tried with different colour images. And it's working fine.

Hope it's generating hexa decimal color. Is that also possible to get rgb colours out of this?

Regards,
Durgaprasad.

Steve Garman

unread,
Oct 10, 2015, 6:24:11 AM10/10/15
to AndroidScript
It's generating a 9 character string "#aarrggbb"

You should not have much trouble writing a function to convert that to any format you like.

Durga Prasad

unread,
Oct 10, 2015, 6:45:08 AM10/10/15
to AndroidScript
Great. I will try on this.

Steve Garman

unread,
Oct 10, 2015, 7:00:04 AM10/10/15
to AndroidScript
This may help

function gotColor(colour)
{
    var red, green, blue;
    app.ShowPopup(colour,"short,bottom");
    lay.SetBackColor(colour);
    red = parseInt(colour.substr(3,2),16);
    green=parseInt(colour.substr(5,2),16);
    blue =parseInt(colour.substr(7,2),16);
    app.Alert(red+", " + green+", " +blue)
}

Steve Garman

unread,
Aug 27, 2018, 3:49:29 AM8/27/18
to DroidScript
It was pointed out to me that the spk is in a format that these forums no longer allow.
I have edited the original post to include the spk in the newer format.
The only difference I can remember from the original is that I added code to display individual r,g,b values as well as #aarrggbb format

I was quite pleased with this picker when I wrote it but I have not used it much since as I tend to use the UIExtras plugin https://groups.google.com/d/msg/androidscript/Qbf36sKFHV4/-AIp0kxNCQAJ

For those who don't like either there is a different style of picker on the wiki https://wiki.droidscript.me.uk/doku.php?id=sample_code:colorpicker


Reply all
Reply to author
Forward
0 new messages