Calendar DayView for Android
I had to create logic which should arrange events properly on DayView timeline.
I’ve researched many solutions in the internet and here is solution which can be easy implemented in Android.
I’ve implemented this task visually like Google Calendar. Like this.
Please have a look my solution.
To draw the DayView we need do the next steps:
- Sort events by start time and end time.
- Find events which have shared time. Even that just 1 minute. This group of events called Clique.
- Find cliques which have shared events. This group of cliques called Clusters.
Cliques and clusters you can see in the attached image.
After that we can start draw the clusters.
- Y coordinate for event calculated from start and end event time.
- X coordinate for event calculated based on event width and position in cluster.
- WIDTH for event = SCREEN_WIDTH / MAX_CLIQUE_SIZE_IN_CLUSTER.
Example:
Cluster contains 5 events arranged by start and end time.
Max clique size = 3;
Event Width = screen_width / 3;
Event1:
X = 0 * width = 0;
Event2:
X = 1 * width;
Event1:
X = 2 * width;
Event1:
X = 0 * width = 0;
Event1:
X = 1 * width;
That’s all.
The source code on github.
Please let me know what you think about this solution in comments
1 Comment
Aryan Sharma · 24 November, 2019 at 07:06
Very helpful.