Calendar DayView for Android

Published by Igor Khrupin on

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:

  1. Sort events by start time and end time.
  2. Find events which have shared time. Even that just 1 minute. This group of events called Clique.
  3. Find cliques which have shared events. This group of cliques called Clusters.

Cliques and clusters you can see in the attached image.

Cliques – blue ovals, Clusters – red ovals.

After that we can start draw the clusters.

  1. Y coordinate for event calculated from start and end event time.
  2. X coordinate for event calculated based on event width and position in cluster.
  3. 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

Download it from github

 


1 Comment

Aryan Sharma · 24 November, 2019 at 07:06

Very helpful.

Leave a Reply to Aryan Sharma Cancel reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.