B4A Library dgPickers - pick up a color, a thickness..

Edit: library updated to version 0.30 (see post #10 for its specific notes)
Edit: library updated to version 0.20 (see post #9 for its specific notes)

Hi all,

while developing a new app, I felt the need for a unified way to manage different pickers. So last weekend I wrote the dgPickers library.
Although yet in its alpha stage, it seems to work as expected.

Please find attached both the library itself (dgPickers_009.zip) and a demo program (dgPickersEx_009.zip).

Version 0.09 sports a Color Picker and a Thickness Picker.

The library approach is very simple.
The programmer should be on full command, so almost anything is parameterized.
As of current version, you prepare an integer array whose values represent the data to be displayed through a specialized picker.
Then you set desidered properties for both the inner tiles showing your data and the picker containing those tiles.
Finally, you attach the picker to a view in your current activity. The picker can show on any side of the view, provided there's a minimum of available space.
Last step, call the ShowPicker method.

Once the desidered picker is showed, the user can select one of its values by tapping on it, scroll the list (swipe along the length of the picker) or just swipe out of it (swipe orthogonal to the picker).
I didn't test yet the lib against those nice and useful ActionBars available for B4A, but it should work.

Any suggestion about how to improve it and any error report is welcomed.

Umberto

Files attached:
  • dgPickers_030.zip - latest version (see post #10 for its notes)
  • dgPickersEx_030.zip - example on how to use the lib
  • dgPickers_020.zip - latest version (see post #9 for its notes)
  • dgPickersEx_020.zip - example on how to use the lib
  • dgPickers_014.zip - version 0.14
  • dgPickers_100.zip - version 0.10, misspelled name
  • dgPickers_009.ip - version 0.09
  • dgPickersEx_009 - example on how to use the lib
 

Attachments

  • dgPickers_009.zip
    6.9 KB · Views: 285
  • dgPickersEx_009.zip
    6.7 KB · Views: 309
  • dgPickers_100.zip
    7 KB · Views: 388
  • dgPickers_014.zip
    7.1 KB · Views: 248
  • dgPickers_020.zip
    7.6 KB · Views: 353
  • dgPickersEx_020.zip
    40 KB · Views: 355
  • dgPickers_030.zip
    7.6 KB · Views: 279
  • dgPickersEx_030.zip
    45 KB · Views: 280
Last edited:

udg

Expert
Licensed User
Longtime User
A few braves among you downloaded version 0.06 of dgPickers, I guess out of curiosity.
Meanwhile I found a bug and revised some code, so please update to newer version 0.09 as published in post #1.

Library: dgPickers v. 0.09
Class: cl_dgpickers
Properties
  • ChosenValue As Int
  • IsValueSet As Boolean
  • LastPickerType As Byte
  • Verbose as Boolean
Methods
  • Initialize(CallbackModule As Object, EventName As String)
  • setAnchorView(ActivityView As View, Side As Byte)
  • setIntArray(aIntArray() As Int)
  • setPickerProperties(CallingAct As Activity, aPickerType As Byte, BkgColor As Int)
  • setTileProperties(Hdim As Int, Vdim As Int, TPadding As Int)
  • ShowPicker
Events
  • _Done
What's in version 0.09?
The key word is parameterized.
With setTileProperties you define the appearance of the inner tiles, setting their dimensions and the padding space between the picker's borders and the tiles and the one among tiles.
With setPickerProperties you define the Activity on which the picker will superimpose, the picker type and its background color (visible only if your tiles' padding is greater than zero).
Finally, now we have a single calling function, ShowPicker, that understands which specialized picker to show.

Minor changes:
I removed the label above the sample line in the thickness picker. This is because I'd like to check better about its appearance on different devices.
Anyway, when eventually a size label will top again those thickness lines, the word "dip" following the size won't be restored since anyone should be free to assign the desidered meaning (dip, pixel..) to that size number.

Umberto
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi all,

please find version 0.10 (misspelled as dgPickers_100.zip) attached to post #1.
This version simply integrates better with my newest library: dgActionBar.

Umberto
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi Björn,

did you try the code in dgPickersEx_009.zip file?
Picker_Done should be called :
  • when user click (action down followed by action up, no moving) on a tile
  • when user orthogonally swipes across the picker bar (this closes the picker with no item selected)
B4X:
'Picker returned a value or closed without a selection
Sub picker_Done
  If dgpicker.LastPickerType = dgpicker.pck_TYP_COLOR Then
    'change panel color only if user selected a color
  If dgpicker.IsValueSet Then TestPanel.Color=dgpicker.ChosenValue
  Else
    'change thickness label only if user selected a thickness size
    If dgpicker.IsValueSet Then TestLabel.Text="Thickness: "&dgpicker.ChosenValue
  End If     
End Sub

In the above code, dgPicker.IsValueSet tells whether an item was choosen and, in that case, only dgPicker.ChosenValue tells you what was choosen.

If I can be of any further help, let me know.

Umberto
 

udg

Expert
Licensed User
Longtime User
Hi Björn,

dgPickers doesn't use any other lib but the Core one. My current B4 installation is version 3.50 (so I have Core 3.41) but I doubt this could be the problem because the objects consuming the touch events (and consequently the swipe action) are a ScrollView and an HorizontalScrollView that should have been part of B4A from very older versions.

Today I tried again my dgPickersEx_009 example against the dPickers_100 lib and it all worked as exepected, but...
I "discovered" that the orthogonal swipe to close the picker's bar should start inside the bar itself to function properly (otherwise it's ignored).
This is an aspect I have to correct with next lib version.

Umberto
 

udg

Expert
Licensed User
Longtime User
Hi all,

please find dgPickers version 0.14 attached to post#1 above.

This version sports a minor correction about the proper placement of the picker panel relative to the calling AnchorView.
After some investigation it seems that the API could return whole or decimal values depending on the device running the code for the Touch event. This, along with a questionable decision I originally took, could have caused issues like the one outlined by Björn in post #4 above.

My apologies for any inconvenience caused so far.

Umberto
 

udg

Expert
Licensed User
Longtime User
Hi all,

please find dgPickers version 0.20 attached to post #1 above.

New to this version is the ability to configure an Image Picker, a long awaited feature indeed.
The newly added picker lets you choose among a few images you provide by a bitmap array initialized in your Main module. Due to compatibility reasons its mandatory to initialize a companion int array having as values the indices of the bitmaps in their array (so it goes from 0 to number of images -1).
This second array is never really used, but it still needed to be there!

Have a look at the demo program attached to post#1 as dgPickersEx_020.zip to see how the new feature is used.

Umberto
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi all,

please find dgPickers version 0.30 attached to post #1 above.

New to this release is public method ClosePicker. You can call it to programmatically close a picker not selecting any item on it.
A couple of uses come to mind: a button placed on your UI to close the picker at any time or a timer to automatically close the picker if the user doesn't make any selection in the set time.

Have a look at the demo program attached to post#1 as dgPickersEx_030.zip to see how the new feature is used.

Umberto
 
Top