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,007
  • Custom_input.jpg
    Custom_input.jpg
    45.3 KB · Views: 1,916
  • ClsWheelV2_5.zip
    19.1 KB · Views: 232
  • ClsWheelV2_7.zip
    19.3 KB · Views: 175
Last edited:

NJDude

Expert
Licensed User
Great!!.

The background panel sometimes looks like THIS or THIS on my Nexus 7 (JB 4.2), it seems is there because I can't tap on the buttons, it just looks weird.
 

MLDev

Active Member
Licensed User
Nice class klaus!

There's a bug in the date input. When you first select a date you can get an "jave.text.ParseExcetion: Unparseable date" error. It's possible to select an invalid date like November 31.
 
Last edited:

MLDev

Active Member
Licensed User
Hi klaus,

Is there a way to make the wheels rotate continuously? When it gets to the end of the list it starts over.
 

klaus

Expert
Licensed User
Thank you for your bug reports.

@NJDude
It needed a DoEvent after setting the color to make the full screen panel dispaly it's color correctly.
Added AutoScale to make the main screen 'nicer'.

@MLDev
Bug november 31 amended, missed that one.
I will have a look for continuse scrolling wheels.

@javiers
Possible, probably yes.
But I won't do it I don't think having the words vertically would be interesting.

A new version is updated in post #1.

Best regards.
 

javiers

Active Member
Licensed User
I thought that showed a control wind direction in degrees and above the compass rose that corresponds ... Surely someone else comes up with apps ... Again a great job, Klaus.

Suggestion (I know it's difficult):

Making the wheels "engage". An example showing the equivalence of the wind speed:

knots Beaufort km / h Denomination
1 0 1 Calm
1 to 3 1 1-5 Light air
4 to 6 2 6-11 breeze
................................
 

Attachments

  • Wind.gif
    Wind.gif
    10 KB · Views: 708
Last edited:

susu

Well-Known Member
Licensed User
Thank you Klaus for another useful class. :sign0098:

I think this code is not correct:
B4X:
Sub lblCustom_Click
whlCustom.Show(lblCustom, lblCustom.Text)
End Sub

It should be:
B4X:
Sub lblCustom_Click
whlCustom.Show(edtSelection, edtSelection.Text)
End Sub

And I add some code into your class to disable VeticalScrollbar:
B4X:
Private Sub scv_ScrollChanged(Position As Int)
CurrentScrollView = Sender
   
Dim r As Reflector
r.Target = CurrentScrollView
r.RunMethod2("setVerticalScrollBarEnabled", False, "java.lang.boolean")
   
If (WheelType = DATE OR WheelType = DATE_TIME) AND CurrentScrollView = scvWheel(2)  AND Position > ScrollPosMax Then
      CurrentScrollView.ScrollPosition = ScrollPosMax
End If
End Sub
 

klaus

Expert
Licensed User
No, this code is correct !
B4X:
Sub lblCustom_Click
    whlCustom.Show(lblCustom, lblCustom.Text)
End Sub
I want to show the result of the selection in the Label not in the EditText and also use the current content of the Label as the preset value.
I find this even more useful because the user can't make any editing.
You can return the selection result onto any TextView.

To remove the VerticalScrollBar the place where you added the code is not optimal because at every ScrollChange you run the code and there are lots of ScrollChanges.
The best place to add this code is in the Initialize routine. The first line in the code below is line 193 :
B4X:
Dim scvWheel(WheelNb) As ScrollView
Dim objWheel(WheelNb) As Reflector
For i = 0 To WheelNb - 1
   scvWheel(i).Initialize2(lblHeight * (WheelContent(i).Size + ItemNb - 1), "scv")
   pnlBackGround.AddView(scvWheel(i), TotalColWidths(i), 0, ColWidths(i), pnlBackGroundHeight)
      scvWheel(i).Tag = i
      objWheel(i).Target = scvWheel(i)
      objWheel(i).SetOnTouchListener("scv_Touch")
      objWheel(i).RunMethod2("setVerticalScrollBarEnabled", False, "java.lang.boolean")
      For j = 0 To WheelContent(i).Size + ItemNb
         Dim lbl As Label
         lbl.Initialize("")
In this case the reflection object already exits and the routine is called only once for each ScrollView.

Best regards.
 
Last edited:

susu

Well-Known Member
Licensed User
Ok, I understand now.
One question: How can I disable Wheel by pressing Back button? Now the app will exit if I press Back.
 

Omar

Member
Licensed User
Hey susu,

You can intercept the back keypress and then simply hide the Wheel.

If it's already hidden then you can call Activity.Finish




Ok, I understand now.
One question: How can I disable Wheel by pressing Back button? Now the app will exit if I press Back.
 

susu

Well-Known Member
Licensed User
Hey susu,

You can intercept the back keypress and then simply hide the Wheel.

If it's already hidden then you can call Activity.Finish

I don't see Hide method so I add it by myself, it's ok now.
 

Dogbonesix

Active Member
Licensed User
Wheel Error?

My B4A version 2.30
I get this error when trying to compile:

Compiling code. Error
Error parsing program.
Error description: Unknown type: reflector
Are you missing a library reference?
Occurred on line: 18
Private objWheel() As Reflector

Cool idea but I am stuck...
 

Harris

Expert
Licensed User
B4X:
Private Sub GetTimeHM(Time1 As String) As String
   Dim TimeFormat, Time2 As String
   Dim TimeTicks As Long
   
   TimeFormat = DateTime.TimeFormat
   DateTime.TimeFormat = "HH:mm"
   
   TimeTicks = DateTime.TimeParse(Time1)
   DateTime.TimeFormat = TimeFormat
   Time2 = DateTime.TIME(TimeTicks)
'   Msgbox(" Time: "&Time2,"")
   Return Time1
'   Return Time2
   
End Sub

When Time2 is returned, the selected time is always 1 hour later (15:00 returns 16:00). When the passed time is returned (Time1), the value is correct. It seems this function is to return a formatted time string - however, it seems the the format is changed back to the original before the return value is set.

My problem is time2 is one hour later than selected time.

Thanks
 

rboeck

Well-Known Member
Licensed User
Clickwheel idea

I used the wheel lib for a longer time and one of my problems is, that the scrolllists sometimes get to long if would use them for birthdate, especially for the year input. In this case, you must fill the year wheel with 100 entries.
One possibility is, to make for the year four wheels, but this needs very much space.

Another idea is, to make an clickwheal with two levels: the first level makes let you choose the year in 10 steps like "1990-2000" and so on. You get in to the second step with a long click on the wheel, the wheel get's now filled with the details like "1991" , "1992" and anyone can choose now the details.
My question is, are the internal listviews in the wheel able to get the long_click event and could this event raised for the programmer? How to you think about this idea?
 

klaus

Expert
Licensed User
@Harris,
I'm afraid that this is an error in the DateTime.TimeFormat function because it works for most time zones and there is one hour difference for some time zones like Greenwich time.
I sent a bug report to Erel.

Best regards.
 
Top