B4A Library [Class]ClsWheel Input wheels

Attached you find a new CLASS ClsWheel.

It allows to display different data input screens with wheels.

What can be done ?
You can define nine different types of Wheel input screens:
  • DATE a date input : year / month / day
    A default value can be defined or Now, the current date.
    The returned value has the current DateFormat.
  • TIME_HM a time input : hour / minute
    A default value can be defined or Now, the current time.
    The returned value has the current TimeFormat.
  • TIME_HMS a time input : hour / minute / second
    A default value can be defined or Now, the current time.
    The returned value has the current TimeFormat.
  • DATE_TIME a date + time input : year / month / day / hour / minute
    A default value can be defined or Now, the current date and time.
    The returned value has the current DateFormat and TimeFormat.
  • CUSTOM a custom input with user defined input values.
    The number of side by side wheels is user defined (max. 5 wheels).
    A default value can be defined.
    A specific separation character can be defined, a blanc character is default.
  • INTEGER positive and negative integers
  • INTEGER_POS only positive integers
  • NUMBER positive and negative numbers
  • NUMBER_POS only positive numbers
Main functions:
Initialize initializes the wheel class Note: the Initialize routine hasone more parameter cContinusScrolling As Boolean (since version 1.3) .
Example :
whlDate.Initialize(Me, Activity, "Enter date", 3, Null, 24, 0, True)
Me = calling module, the current
Activity =
Enter date = title of the input
3 = number of wheels, this number is used only for CUSTOM input types
Null = no input data, set internally
24 = text size
0 = DATE input type
True = continus scrolling

Show show the input wheel(s)
Example :
whlDate.Show(lblSelection, "11/22/2001")
lblSelection = Label which gets the result
11/22/2001 = Default value to preset the wheels

Show2 show the input wheel(s)
Example :
whlCustum.Show2("whlCustom", "")
"whlCustom" = EventName
"" = no default value
The event is called 'Closed'.
The event routine in the calling module, for the example, must be
Sub whlCustom_Closed(Canceled As Boolean, Selection As String)

The width and height are defined by the program according to the font size.

If the width or the height exceed the screen width or height the font size is downscaled.

You can change most of the colors.

Needs the Reflection library.

Bug reports and suggestions are welcome.

I hope that the code is enough self explanatory, but if you want more explanations I can add them.
Anyway the best way to know what can be done is to test it.

PS. There is no logic in the custom input screen just to demonstrate the possibility.

Best regards.


EDIT: 2020.11.25 Version 2.7
Amended warning in line 946: Comparison of Object to other types will fail if exact types do not match.
EDIT: 2015.04.29 Version 2.0
Added a Tag property

EDIT: 2017.06.27 Version 2.6
Replaced DoEvents by Sleep(0)
Needs B4A version 7.00+

EDIT: 2017.03.30 Version 2.5
Amended the wish expressed HERE
Different font sizes for title and wheels.
With long titles, the font size of both, title and wheels, was reduced.
Now only the title font size is reduced.

EDIT: 2017.03.28 Version 2.4
Amended the error reported HERE
Problem with +/- in number wheels

EDIT: 2015.09.22 Version 2.3
Amended the error reported in post #185

EDIT: 2015.05.10 Version 2.2
Amended the variable declaration problem reported in post #175

EDIT: 2015.05.10 Version 2.1
Amended the timer problem reported in post #170

EDIT: 2014.09.09 Version 1.9
Added number wheels INTEGER, INTEGER_POS, NUMBER, NUMBER_POS wheels
Amended day scroll problem reported in post #141

EDIT: 2014.04.21 Version 1.7
Amended OutOfMemory problem reported HERE.

EDIT: 2013.09.15 Version 1.6
Added min MinYear and NumberOfYears properties to adapt the years to select

EDIT: 2013.08.08 Version 1.5
Added StartScroll and EdnScroll events

EDIT: 2013.06.14 Version 1.4
Modified OK event to Closed event post#37
Amended screen color problem post#36
Amendet getSeparationText error post #41

EDIT: 2013.06.12 Version 1.3
Mofied property routines.
Added Show2 for raising an event when clicking the OK button
Added optional continus scrolling

EDIT: 2013.05.28 Version 1.2
Amended the bug reported in post #32

EDIT: 2012.12.15 Version 1.1
Amended the reported bugs.
 

Attachments

  • Time_input.jpg
    Time_input.jpg
    32.9 KB · Views: 2,262
  • Custom_input.jpg
    Custom_input.jpg
    45.3 KB · Views: 2,179
  • ClsWheelV2_5.zip
    19.1 KB · Views: 464
  • ClsWheelV2_7.zip
    19.3 KB · Views: 478
Last edited:

enrico

Active Member
Licensed User
Longtime User
How can I calculate ItemNb to better fill pnlMainHeight (for bigger screens) ?
 

klaus

Expert
Licensed User
Longtime User
The easiest way would be to add it as a parameter in the Initialize routine and the two lines below:
B4X:
Public Sub Initialize(CallbackModule As Object, Parent As Object, cTitle As String, cWheelNb As Int, cWheelContent() As List, cFontSize As Float, cWheelType As Int, cContinusScrolling As Boolean, cItemNb As Int)
    ItemNb = cItemNb
    ItemNb_2 = Floor(ItemNb / 2)
And add the parameter in the calling routine.
The number must be an odd number.

You might aslo play with the TextSize parameter.
 
Last edited:

enrico

Active Member
Licensed User
Longtime User
So I need a function to calculate the nearest odd integer below a number.
For example if I have 10.8, it has to be 9.

Maybe this ?
floor((x + 1)/2)*2 - 1
 
Last edited:

enrico

Active Member
Licensed User
Longtime User
Ok. I've modified it to pass the Height of the panel :
B4X:
Public Sub Initialize(CallbackModule As Object, Parent As Object, cTitle As String, cWheelNb As Int, cWheelContent() As List, cFontSize As Float, cWheelType As Int, cContinusScrolling As Boolean, cPanelMaxHeight As Int)

And then calculate ItemNb :
B4X:
ItemNb = Floor((PanelMaxHeight/lblHeight + 1)/2)*2 - 1        'Added to set ItemNb according to pnlMainHeight (PanelMaxHeight)

The screen size is good, but now I've some problems with the value selection.
With ItemNb = 9 I get the preceding two places value (sorry for my english).
For example in a time wheel, if I select 05:03, I get 03:01
 

klaus

Expert
Licensed User
Longtime User
You should replace line 876 in Sub getSelection and line 914 in Sub getSelection2 (the number could be different depending on your changes) by :
j = Floor(scvWheel(i).ScrollPosition / lblHeight + 0.5) + ItemNb_2
Replace 2 by ItemNb_2

I wouldn't transmit the pnlMainHeight value because this height is calculated in the class depending on the text size.
I suggest you to calculate ItemNb depending on the physical sceen dimension.
In my opinion you should also adapt the text size to the physical sceen dimension.
Don't forget to calculate ItemNb_2 = Floor(ItemNb / 2) just after ItemNb.
 
Last edited:

Shadow&Max

Active Member
Licensed User
Longtime User
Hi... This is a beautiful class, but I'm trying to get time in AM/PM, Hours & Minutes. I've set DateTime.TimeFormat = "hh:mm" and the wheels in the demo are still showing me 24 hour time. How can I fix this?
 

Harris

Expert
Licensed User
Longtime User
Possible yes.
It would need quite some time to add this and I am not really convinced of the usefullness of this option.
But feel free to adapt it to your wishes, it's an open project.

wheel.PNG


Horizontal example: directional indicator.
 

Harris

Expert
Licensed User
Longtime User
I understand. Just a thought.
Thanks.
 

Shadow&Max

Active Member
Licensed User
Longtime User
This would need to make new wheel variants.
I have never thought about it because I'm used to the 24 hours display.
Note that even the wheels show 24 hours, the returned value is displayed in the format you set in the program.

I'm not sure how to do this Klaus... Love the class though. What I'd like to do is display hours in 12 or 24 hour based upon their phone settings, and display only 4 items in minutes... 0,15,30,45.

I lived in Europe for a year, so I know about the 24 hour format, but if that's presented to most from the US, they wouldn't know how to deal with it!

Do I create three separate lists to do this???
 

klaus

Expert
Licensed User
Longtime User
You can do it with a Custom wheel.
Look at the attached test program.
Click onto the Label to show the wheel.
You can check the settings and depending on the settings you can initialize either the 24h wheel or the 12AM/PM wheel.
In the whlTimeAmPm_Closed routine you can handle the time string to your needs.
 

Attachments

  • ClsWheelAM_PM.zip
    12.5 KB · Views: 162
  • ClsWheelAM_PM.png
    ClsWheelAM_PM.png
    23.1 KB · Views: 177

Shadow&Max

Active Member
Licensed User
Longtime User
Damn you're good! Thanks Klaus... The only change I made was changing "0" to "12"

I'm trying to figure out how to detect the time format chosen in the phone's setup now.

In terms of Harris' question... it would be very helpful for game and flight controls headings could be changed with a horizontal swipe etc... I don't have any need for it personally, but I can see it's use...
 

klaus

Expert
Licensed User
Longtime User
How to use Scale on it?
If you change the TextSize the views dimensions are automaticaly scaled.
If the wheel becomes too wide or too heigh the text size is changed to fit into the screen.
Perhaps it might be useful to transform it into a custom view, also.
Currently, the wheels class is designed as a pseudo modal input dialog and not as a custom view.
There is no scheddule to transform it also to a custom view.
 
Top