A calendar made easy

PaulMeuris

Active Member
Licensed User
Check out the new version of Calendar notes in message #3 and/or #5!
A period calendar is an option see message #10 and the source code is in message #12


tut2_001_01.png


In this new tutorial you can find out how easy it is to make a calendar app.
Once the app is running you can learn more on how to use a standard calendar class in a project.
In the fine tuning section the calendar class will then be compiled into a library.
You are invited to expand the project to build a year overview using the calendar library.
Have a look at: B4A-Calendar
Happy coding!
Paul
 
Last edited:

PaulMeuris

Active Member
Licensed User
View attachment 128855

In this new tutorial you can find out how easy it is to make a calendar app.
Once the app is running you can learn more on how to use a standard calendar class in a project.
In the fine tuning section the calendar class will then be compiled into a library.
You are invited to expand the project to build a year overview using the calendar library.
Have a look at: B4A-Calendar
Happy coding!
Paul
Check out the newly added chapter Calendar notes.
This assignment invites you to create an app using the calendar_library and code from the B4A-lists tutorial.
The changes to the calendar_library are described in the text.
If you finish the assignment successfully then you will have a personal appointment calendar!
Happy coding!
Paul
 

PaulMeuris

Active Member
Licensed User
You can download a new version of the Calendar_notes app.
1709455314125.png

This version should work on a device with Android version 14.
1709455502916.png

Tapping on a day opens a note dialog.
1709455670206.png
1709455782072.png

The notes are stored in text files.
1709455996974.png

The app works in landscape and portrait.
1709456353587.png
1709456413048.png

The app works fine when the user changes the font size and/or the screen zoom on the device.
1709456207888.png
1709456536084.png

The Today menu item scrolls the calendar to the current month and day (in red).
A few extracts from the source code:
Added permission in the Manifest:
AddPermission(android.permission.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
Runtimepermissions:
Public folder As String
Public rp As RuntimePermissions
folder = rp.GetSafeDirDefaultExternal("")
Read or write a note text file:
Sub load_note(ticks As String) As String
    If File.Exists(folder,ticks & "_notes.txt") Then
        Return File.ReadString(folder,ticks & "_notes.txt")
    Else
        Return ""
    End If
End Sub
Sub save_note(ticks As String,note As String)
    File.Delete(folder,ticks & "_notes.txt")
    File.WriteString(folder,ticks & "_notes.txt",note)
End Sub
screen adjustments:
    Dim scale As Float = GetDeviceLayoutValues.Scale
    Dim screensize As Double = GetDeviceLayoutValues.ApproximateScreenSize
    Dim devwidth As Int = GetDeviceLayoutValues.Width/scale
    Dim devheight As Int = (GetDeviceLayoutValues.height/scale) - 40dip     ' title bar height not included
    If screensize > 8 Then
        Dim devwidth As Int = GetDeviceLayoutValues.Width
        Dim devheight As Int = GetDeviceLayoutValues.height - 80dip     ' title bar height not included
    End If
    Private boxwidth As Int = DipToCurrent(devwidth/7)
    Private boxheight As Int = DipToCurrent(devheight/8)
check if a note exists for the day:
                    If File.Exists(folder,DateUtils.SetDate(yr,mnth,daynumber) & "_notes.txt") Then
                        If daynumber = currentday And mnth = currentmonth And yr = currentyear Then
                            Private lbl As Label = set_label(daynumber,Colors.ARGB(100,255,165,0),"lblday")
                        Else
                            Private lbl As Label = set_label(daynumber,Colors.ARGB(100,255,255,0),"lblday")
                        End If
                    End If
And that's it. Try it out and let me know if you have some issue with it.
 

Attachments

  • calendar_notes_new.zip
    13.9 KB · Views: 150

Xfood

Expert
Licensed User
very nice congratulations, it would be very useful if you could choose the departure day of the week, and start from Monday,
it would be like this:
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
 

a.consorti

Member
Licensed User
Hi Paul, I updated your library to make it more customizable.

You did a nice job.
It would be very convenient to be able to give a start date and an end date to the calendar.
For example, if I give today August 4th as the start date and September 15th as the end date, it would be convenient to see only the months of August and September on the calendar but to be able to click only on the dates of the interval provided.
Could you implement it?
 

Attachments

  • calendar_notes_new.zip
    16.1 KB · Views: 69

a.consorti

Member
Licensed User
The implementation of the changes you ask for will require a different approach.
I will see what i can do. It's on my to do list for a new app.
Thank you for your time. In the meantime I will also try to implement what I have asked you. What I need is to have the calendar on the screen that shows from a start date to an end date, where I can select a date within it, highlighting the selected date (which does not happen at the moment). In my use case I don't have to highlight the days with notes and therefore I have to have the cleanest calendar possible. If you want, we can collaborate and divide the efforts. Good luck with your work
 

a.consorti

Member
Licensed User
Hi Paul,
I finally did it and I attach a screenshot of the component shown on the video.
While I was at it, I also made all the colors parameterizable so that the user could define them as if it were a sort of calendar template. Just to give you an example, below you will find the Class_Globals

Class_Globals:
Sub Class_Globals
    Private xui As XUI
    Private act As Activity    'ignore
    Private mCallback As Object
    Private mEventname As String
    Public lblticks As Long
    Private pnlpicker As Panel
    Public lblseldate As Label
    
    Public PreviousSelectedDate As String=""
    
    Public folder As String
    Public rp As RuntimePermissions
    
    Public date_from As Long = DateTime.Now
    Public date_to As Long = DateTime.Add(DateTime.Now,0,1,0) 'default date_to = date_from + 1 month
    '----------------------------------------------
    ' Default color initializations of the calendar
    '----------------------------------------------
    
    
    Public color_empty_day As Int = Colors.ARGB(100,230,230,230)
    Public color_current_day As Int = Colors.ARGB(100,255,50,50)
    Public color_current_day_with_notes As Int = Colors.ARGB(100,255,165,0)
    Public color_day_with_notes As Int = Colors.ARGB(100,255,255,0)
    Public color_weekend_bg As Int = Colors.ARGB(100,255,210,179)
    
    Public color_working_days_bg As Int = Colors.ARGB(100,158,255,150)
    Public color_working_days_text As Int = Colors.Black
    
    Public color_day_border As Int = Colors.Black
    Public color_day_selected_bg As Int = Colors.Red
    Public color_day_selected_border As Int = Colors.Black
    Public color_day_text As Int = Colors.Black
    
    ' Months
    Public month_name_color As Int = Colors.Black
    Public month_name_bg_color As Int = Colors.ARGB(100,182,221,249)
    
    Public month_january As String = "January"
    Public month_february As String = "February"
    Public month_march As String = "March"
    Public month_april As String = "April"
    Public month_may As String = "May"
    Public month_june As String = "June"
    Public month_july As String = "July"
    Public month_august As String = "August"
    Public month_september As String = "September"
    Public month_october As String = "October"
    Public month_november As String = "November"
    Public month_december As String = "December"
    
    ' Days of week name
    Public color_week_title As Int = Colors.Black
    Public color_week_bg_title As Int = Colors.ARGB(100,255,255,135)
    Public day_monday As String = "Mo"
    Public day_tuesday As String = "Tu"
    Public day_wednesday As String = "We"
    Public day_thursday As String = "Th"
    Public day_friday As String = "Fr"
    Public day_saturday As String = "Sa"
    Public day_sunday As String = "Su"
End Sub

The code I wrote is not completely finished but only adapted to my purposes and therefore it is useless to post it here. What I would like to have would be a calendar component that exposes all the properties as a normal component and can therefore be modified via GUI and not only via code as in the part of code that I showed you (I hope I explained myself well).
I will continue to follow your progress in the calendar.
See you soon
 

Attachments

  • Calendar1.png
    Calendar1.png
    21.8 KB · Views: 54

PaulMeuris

Active Member
Licensed User
@a.consorti, it's good to see that you have found a solution that works for you.
As for the calendar component you would like to have, i suggest you search this forum for a more complete scheduler/calendar library...
Here's some code i used to create my calendar_with_periods version.
Set the parameters:
Private Sub show_calendar
    If startyear = 0 Then
        startyear = currentyear
        startmonth = 1
        startday = 1
        endyear = currentyear
        endmonth = 12
        endday = 31
    Else
        startyear = cbxstartyear.SelectedItem
        startmonth = cbxstartmonth.SelectedItem
        startday = cbxstartday.SelectedItem
        endyear = cbxendyear.SelectedItem
        endmonth = cbxendmonth.SelectedItem
        endday = cbxendday.SelectedItem
    End If
Create a months list:
    Dim monthslst As List
    monthslst.Initialize
    If startyear = endyear Then
        For m = 1 To 12
            If m >= startmonth And m <= endmonth Then monthslst.Add(startyear & "|" & m)
        Next
    End If
    If startyear <> endyear Then
        For y = startyear To endyear
            For m = 1 To 12
                If y = endyear Then
                    If m <= endmonth Then monthslst.Add(y & "|" & m)
                Else
                    If y = startyear Then
                        If m >= startmonth Then monthslst.Add(y & "|" & m)
                    Else
                        monthslst.Add(y & "|" & m)
                    End If
                End If
            Next
        Next
    End If
    Log(monthslst)
Call the calendar class method with the extra parameters:
    For i = 0 To monthslst.Size -1
        Dim yearmonth As String = monthslst.Get(i)
        Dim yy As Int = yearmonth.SubString2(0,yearmonth.IndexOf("|"))
        Dim mm As Int = yearmonth.SubString(yearmonth.IndexOf("|")+1)
        pnl = cal.set_month_panel(mm,yy,seq,startyear,startmonth,startday,endyear,endmonth,endday)    ' sequence 1 = mo - su, 2 = su - sa
        If monthcnt = 1 Then
            sv1.panel.AddView(pnl,1dip,toppos,pnl.Width,pnl.Height)
        Else
            sv1.panel.AddView(pnl,1dip,(pnl.Height*(monthcnt-1)),pnl.Width,pnl.Height)
        End If
        monthcnt = monthcnt + 1
    Next
Add tests to the set_month_panel method of the calendar class:
                    If daynumber < startday And mnth = startmonth And yr = startyear Then
                        Private lbl As Label = set_label("",Colors.ARGB(100,230,230,230),"")
                    Else
                        If endday > 0 And daynumber > endday And mnth = endmonth And yr = endyear Then
                            Private lbl As Label = set_label("", Colors.ARGB(100,230,230,230),"")
                        Else       
                            If daynumber = currentday And mnth = currentmonth And yr = currentyear Then
                                Private lbl As Label = set_label(daynumber, Colors.ARGB(100,255,50,50),"lblday")
                            Else
                                ' test for sequence sunday to saturday (seq = 2)
                                If seq = 2 Then
                                    If c = 1 Or c = 7 Then
                                        Private lbl As Label = set_label(daynumber, Colors.ARGB(100,255,210,179),"lblday")
                                    Else
                                        Private lbl As Label = set_label(daynumber,Colors.ARGB(100,158,255,150),"lblday")
                                    End If
                                Else
                                    ' monday to sunday (seq = 1)
                                    If c > 5 Then
                                        Private lbl As Label = set_label(daynumber, Colors.ARGB(100,255,210,179),"lblday")
                                    Else
                                        Private lbl As Label = set_label(daynumber,Colors.ARGB(100,158,255,150),"lblday")
                                    End If
                                End If
                            End If
                        End If
                    End If
I have added 2 items to the menu: Periods to show the selected period and Reset to show the current year calendar.
Change the year, month and day comboboxes and tap on the Show button to see the result.
You can find the source code of this version in the attachment (calendar_with_periods.zip)
 

Attachments

  • calendar_with_periods.zip
    15.6 KB · Views: 50
Top