
EDIT (09/25): Added a screenshot of the color picker in action.
I had a need in my Yahtzee! app for a color picker so that I could let my users customize the colors of the panels on the game screen, so I started using the Color Dialog in agraham's excellent Dialogs library. Unfortunately, when I received a report from one of my users that the dialog didn't fit on his small (3.7") screen, I discovered that it's not resizable - so I decided to create my own.
So what I have attached is a *very* simple color picker that I really only created for my own specific use, but that some might find useful. It has basically the same functionality as agraham's Color dialog with 2 exceptions:
1) It will resize itself to fit on very small screens (I have tested it on a 3.2" 240 x 320 screen);
2) It allows you to choose either a solid or gradient (left->right) color;
It's not modal (but does use a "shield" panel with a semi-transparent alpha to prevent the user tapping the activity behind), so you can't access any of it's properties after it has been shown - so you get around this limitation by sending it the view that you want to change the color of & it sets the view .Color property (for a solid color) or .Background property (for a gradient color) & the .Tag property with the color type (0 for solid, or 1 for gradient) & color in the format of "ColorType, Color". You can then access the .Tag property & use Regex.Split to get the color type & color:
B4X:
Private sParts() = Regex.Split(",", View.Tag)
Log("Color Type: " & sParts(0))
Log("Color: " & sParts(1))
There are 3 public methods:
* .Initialize(Activity, View)
* .IsInitialized
* .Show
You send the Activity that you want the picker displayed in & the view that you want to change the color of in the .Initialize call. The .Show call makes the picker visible.
There are 3 properties:
* .Title
* .ColorType
* .Color
You can use .Title to display a title (duh!) like "Left Panel Color". The .ColorType & .Color properties are used to set the initial color of the picker when it's shown - so .ColorType must be 0 for Solid, or 1 for Gradient & .Color is whatever color you want it to be - either in the form of Colors.someColor or RGB(redColor, greenColor, blueColor) (any int that represents a color).
When you select the color & tap "OK", the .Tag property of the view you provided in the initializer will be set with the ColorType & Color & either the .Color or .Background property will be set with the color (depending on the ColorType).
Attached Files:
* CSColorPickerLibTest - demo project
* CSColorPicker - Library files (v1.0)
As I said at the beginning of this post, I created this library to address a specific need I had - so I'm not planning on doing any further development of it. If anyone wants to modify it, let me know & I'd be happy to share the source with you. It's a single B4A class file.
Attachments
Last edited: