B4A Library [Class] AnotherDatePicker - A simple "web style" date picker

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
This is an old version. Latest version is included in XUI Views: https://www.b4x.com/android/forum/threads/100836/#content

AnotherDatePicker is an inline date picker:



The advantage of this class over the built-in dialog (DateDialog from the Dialogs library) is that you can easily customize it as needed.

Most of the layout is created with the visual designer and designer script.

ADP.GetDate returns the selected date.

The months names and days names are based on the device locale.

In order to use this class in your code you should add AnotherDatePicker class, reference DateUtils library and add DatePicker layout file to the Files tab.

Starting from v2.0, ADP should be added as a custom view from the designer:



v2.0 - Better support for visual designer and more configurable options (including first day of week).
v1.11 - Fixes an issue with SetDate that is called before the view is ready.
v1.10 - Adds a Closed event. See the attached example.
 

Attachments

Last edited:

barx

Well-Known Member
Licensed User
Been looking for a good alternative to the date dialog as that seems to go all wrong looking when target sdk is high e.g. 17
 

barx

Well-Known Member
Licensed User
I would just like to post an 'in use' pic of this date picker in action. I like this class and it has helped solve my issue with the date dialog available in the dialogs library. I have made s few UI tweak (but that is the joy of classes, right?)

datepicker.png

Thanks Erel
 

Erel

Administrator
Staff member
Licensed User
Looks great!

Can you upload your class (its looks better than the original...)?
 

barx

Well-Known Member
Licensed User
I just want to check that it works good in a couple more devices then yes, of course I will upload it. I didn't change alot to be honest. Just a couple of tweaks.
 

barx

Well-Known Member
Licensed User
As promised here is my edit (See attached below). Please note that I only edited a few minor UI things, nothing special or functional.

A few of the colors are slightly different to my screenshot, mainly due to, the app I posted screenshot from uses a Custom Light theme, so default texts are dark. Applying that to the sample would just complicate matters.

Anybody that uses Erel original class files, one thing I would add to the DatePicker designer layout script is:

Add
B4X:
Base.Height = Min(300dip, 100%y)
Just after
B4X:
AutoScaleAll
If Erel agrees with this, maybe he will update the original for those that don't read past post #1 :cool:
On my phone 480x800 I found that the bottom of the date picker would be cropped slightly in landscape mode. Adding the above line solves that issue.

Updated to reflect Erels update to DateUtils (now v1.03)

Thanks again Erel, great class.
 

Attachments

Last edited:

NJDude

Expert
Licensed User
NICE!!

However, there are some issues:

1- Today is March 29th, and I don't see that date HERE (March has 31 days)

2- Tapping on the TODAY button at the button, brings the right date to the label, however the "blank square" still remains.

3- If you tap on March 28, the "blank square" goes away, but, tapping on the TODAY button brings it back.

4- There are other months containing the wrong number of days, check December 2013 for example.

I've tried that on 4 different devices, same deal.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Do you get these errors with the original class as well? Works fine here.
 

NJDude

Expert
Licensed User
Same thing on both, the original and the modified.

These are the results (2013):

Jan: OK
Feb: OK
Mar: WRONG
Apr: OK
May: WRONG
Jun: OK
Jul: WRONG
Aug: OK
Sep: OK
Oct: WRONG
Nov: OK
Dec: WRONG
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Which locale is set on your device?

What is the value of:
B4X:
Log(DateUtils.NumberOfDaysInMonth(3, 2013))
 

Erel

Administrator
Staff member
Licensed User
Which locale is selected in your device? You can see it under Settings - Language and Input (or Locale and text).
 

Erel

Administrator
Staff member
Licensed User
Good. I believe that I found the problem. Please update DateUtils.NumberOfDaysInMonth with this code and test it again:
B4X:
Public Sub NumberOfDaysInMonth(Month As Int, Year As Int) As Int
   Dim Ticks As Long = SetDate(Year, Month, 1)
   Dim nextMonth As Long = DateTime.Add(Ticks, 0, 1, 0)
   Dim res As Int =  Round((nextMonth - Ticks) / DateTime.TicksPerDay)
   Return res
End Sub
 

Erel

Administrator
Staff member
Licensed User
Great. Thank you for your help. I will update the relevant files.
 

Erel

Administrator
Staff member
Licensed User
The project in the first post was updated with DateUtils v1.03. This is an important update.

The following line was added to the designer script:
B4X:
Base.Height = Min(100%y, Base.Height)
This is relevant for phones in landscape orientation.
 
Status
Not open for further replies.
Top