B4J Library [Custom View] Year Planner View

This Year Planner View is my first effort at a custom view!

It depends on jXUI, XUI Views, & B4XCollections.

It displays every day in the selected year and returns the clicked day(s).
A bunch of Designer Script Extensions are used to keep everything neat as the form is resized (credit to @Erel for the examples in the DDD class on which they're all based :)).

Each day is made of a label with its tag set to a custom type:
'date in yyyy-MM-dd. dayInYear is the day of the year, 1 to 366. dayNum with Sunday=1, row is equivalent to month number.
    Type DayLabelData (label As B4XView, date As String, dayInYear As Int, dayNum As Int, row As Int, column As Int)

The class maintains two important objects:
YearPlannerView.VisibleDayLabels is a map that holds every date in the selected year as the keys, with the corresponding DayLabelData as the values.
YearPlannerView.SelectedDays is a B4XSet of every date that has been selected in yyyy-MM-dd.
There are two methods allowing removal of items from the SelectedDays B4XSet:
'clear the selected days B4XSet
Public Sub ClearSelectedDays
End Sub

'Remove the specified date from the selected days set
'date supplied must be in yyyy-MM-dd format
'Returns False if date is in an incorrect format or does not exist in the Selected Days set.
Public Sub RemoveFromSelectedDays (date As String) As Boolean
    If Not(IsValidDate(date)) Then Return False
    If Not(setSelectedDays.Contains(date)) Then Return False
    Return True

End Sub

Clicking one of the Days Header labels:

adds all instances of that day (i.e. days with the same day number) in the selected year to the SelectedDays set.
Clicking one of the months adds all days in that month to the SelectedDays set.

DayLabelClick (EventData As MouseEvent, ClickedDate as string)
DaysHeaderLabelClick (EventData As MouseEvent, DayNumber as Int)
MonthLabelClick (EventData As MouseEvent, MonthNumber as Int)
YearChanged (year as int)

The b4xlib and example are attached.

All comments, criticisms, complaints, & congratulations will be gratefully received!


  • YearPlannerView.b4xlib
    8.9 KB · Views: 26
  • YPVExample.zip
    2.6 KB · Views: 25