B4A Class Extended B4XDateTemplate

Name: TDB4XDateTemplate
Version: 1.0
Code: B4X
Licence: free

TDB4XDateTemplate.png
TD_DBXDateTemplate2.png


This Template may be used with B4XDialog.showTemplate. The basic code is taken from the Standard DateTemplate of XUI library.

Modifications/Enhancement:
  • Added a Time pane to select a time.
  • Added possibility to mark special Dates with comments shown by Toastmessage.
  • Individual customization of Colors (Textcolors, Highlight, Selected, Marked)
  • Individual setup of strings for localization.
  • If Time pane is customized the pane is shown otherwise it is hidden.
  • If Datetime.TimeFormat contains "hh" AM/PM selector is shown otherwise it's hidden.
In the Dialog result you may return the selected values by use the properties getDate and getTime as Ticks.

Custom Properies:
  • setDate, getDate
  • setTime, getTime, custTime
  • and a couple of public globals
Code to customize and to get result:
'# show TD DateTime dialog
    DateTime.DateFormat ="yyyy/MM/dd" ' format used by template
    DateTime.TimeFormat = "HH:mm:ss" ' format used by template
    ' customize date template
    Dim DTtemplate As TDB4XDateTemplate : DTtemplate.Initialize
    DTtemplate.DaysInMonthColor = XUI.Color_white
    DTtemplate.DaysInWeekColor = XUI.color_black ' week days text color
    DTtemplate.DaysMarkedColor = XUI.Color_red ' marked date text color
    DTtemplate.DaysWeekendColor = Colors.Magenta ' weekend days text color
    DTtemplate.HighlightedColor = XUI.Color_yellow
    DTtemplate.SelectedColor = XUI.color_green ' selected day text color
    DTtemplate.DaysMarked.put("2024/12/25","1st X-Mas Day") 'key = date, Value=Toastmessage
    DTtemplate.DaysMarked.put("2024/12/26","2nd X-Mas Day")
    DTtemplate.DaysMarked.put("2024/12/31","Sylvester")
    DTtemplate.DaysOfWeekNames = Array As String("Mo","Di","Mi","Do","Fr","Sa","So")
    DTtemplate.MonthsNames = Array As String("Januar","Februar","März","April","Mai","Juni","Juli", _
        "August","September","Oktober","November", "Dezember") 
    DTtemplate.custTime( Array As String("Stunde","Minute","Sekunde"), _
        XUI.Color_Black) ' this shows the time pane otherwise it's hidden
    DTtemplate.setTime(True,0,0,0) ' initial time
    DTtemplate.Date = DateTime.now ' initial date
    DTtemplate.FirstDay = 0 ' Monday
  
    ' customize dialog
    Dim dialog As B4XDialog
    dialog.Initialize(Root)
    dialog.TitleBarColor = 0xFFFFA500 ' orange
    dialog.TitleBarTextColor=XUI.Color_Black
    dialog.Title = "Select Date & Time"
    dialog.BorderCornersRadius=5dip
    dialog.BorderColor=XUI.Color_Black
    dialog.BorderWidth=2dip
    dialog.BackgroundColor=XUI.color_white
  
    ' wait for button click
    Wait For (dialog.ShowTemplate(DTtemplate, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        Log ("Date: " & DateTime.Date(DTtemplate.date))
        Log ("Time: " & DateTime.Time(DTtemplate.getTime))
    End If

For detailed example see attached Example Project (Download). Project includes Class in clear code for examin and own modification.
P.S. 2024/12(24 Checked the Link should no work without clearance.

Notice!
Please you to test it. Reply any errors or comments. Thank you.
 
Last edited:
Top