B4J Library Basic Calendar custom view using designer script extension

This is a very basic calendar view which is drawn using a designer script extension. Just based on my experience with this project, the result feels a little more fluid than doing it in the normal code flow.

1690212867257.png

V1.02


It is very simple to use. There is a Callback to the parent class / module that requests text describing entries for each day as they are displayed, keyed on a long date. So when you match a date it should contain no time information. Other than that, how you collect and store the data is up to you.

Attached are an example project and a b4xlib version. To use the b4xlib you will need to copy the 3 layout files from the example to your project (not Layout1.bjl). I didn't include them in the library as it is very unlikely that you would use it without wanting to modify the layouts in some way so it's just easier to deal with them separately.

For ease of use, I have incorporated scrolling with a mouse wheel, press control to scroll through years (there's a song in there somewhere), and a drop down selector for each. You can limit the years in the dropdown, but it does not stop moving outside of the range with the buttons.

You can also choose to start the week on a Sunday or a Monday, and set the month and day names.

There are no external dependencies.

Updates
V1.00 initial version​
V1.01 19 Jul 2023​
Update to change internal date parsing from text to numbers, and set the month and day names.​
V1.02 24 Jul 2023​
Added LineColor to allow for dark mode​
Added Today button (Displays current month)​
Download at least the B4xlib and caledarlayout.zip file. I've zipped the calendarlayout file , if it doesn't unzip correctly, grab the layout from the project file.​
Enjoy
 

Attachments

  • calendarlayout.zip
    1.9 KB · Views: 103
  • CalendarLayout v1.02.zip
    14.3 KB · Views: 102
  • CalendarLayout-b4xlib.b4xlib
    7.1 KB · Views: 96
Last edited:

giannimaione

Well-Known Member
Licensed User
Longtime User
hi,
in sub
B4X:
Private Sub ShowDates
''
''
''
    Dim Format As String = DateTime.DateFormat
    DateTime.DateFormat = "dd MMM yyyy"
    Dim FirstDayPos As Int = DateTime.GetDayOfWeek(DateTime.DateParse($"1 ${lblMonth.Text} ${lblYear.Text}"$)) - 1
''
''
End Sub
there is error:
B4X:
java.text.ParseException: Unparseable date: "1 Jul 2023"
at java.base/java.text.DateFormat.parse(DateFormat.java:395)
 

stevel05

Expert
Licensed User
Longtime User
That's very strange, I've been using it for a few days without issue. I'll see what I can find.

Can you try this one. I've just moved a few things about.

Atttachment removed
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Can you normally parse dates in that format? I am wondering if the JVM locale is set for your locality.
 

giannimaione

Well-Known Member
Licensed User
Longtime User
same error

B4X:
DateTime.DateFormat = "dd MMM yyyy" '   or DateTime.DateFormat = "dd MM yyyy"
Dim lng As Long = DateTime.DateParse("01/01/2023") ' or DateTime.DateParse("01 01 2023")
'error : java.text.ParseException: Unparseable date: "01/01/2023"
'bad
else
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
Dim lng As Long = DateTime.DateParse("19/07/2023") 'italy
'lng = 1689717600000
'ok
 

stevel05

Expert
Licensed User
Longtime User
OK, I am working on changing the parsing to use dd/MM/yyyy, which seems to be more commonly acceptable. I'll post an update when I've done it.
 

stevel05

Expert
Licensed User
Longtime User
Can you try this one please, if it works I'll release an update.

Attachment removed.

Edit: I've changed it now, please download it again. Let me know if it solves the issue.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
The lesson for today is only use text in dates for display :)
 

imbault

Well-Known Member
Licensed User
Longtime User
Adding a "Today" button left to month would be great
Good job anyway!!!
 

stevel05

Expert
Licensed User
Longtime User
Update V1.02 24 Jul 2023
Added LineColor to allow for dark mode​
Added Today button (Displays current month)​
Download at least the B4xlib and caledarlayout.zip file. I've zipped the calendarlayout file , if it doesn't unzip correctly, grab the layout from the project file.​
 

stevel05

Expert
Licensed User
Longtime User
Hi David,

The Designer Script Extension (calendarlayout_Utils) should work as is, but the Gui interface relies heavily on the Java event handling. It would be possible to convert it, just time consuming.

Steve
 

David Hawkins

Active Member
Licensed User
Longtime User
Hi SteveI05, thank you for the quick response, I thought that may have been the case but one can hope LOL. OK I'm fairly busy at the moment but will revisit in the near future.

Many regards
David
 
Top