question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(solved) How to add multiple event dots per day

See original GitHub issue

[Fairly new ti github, if this is not the correct way of spreading knowledge, do tell]

First off, you need a custom DotSpan class, which is just ever so slightly altered:

public class CustmMultipleDotSpan implements LineBackgroundSpan {


    private final float radius;
    private int[] color = new int[0];


    public CustmMultipleDotSpan() {
        this.radius = DEFAULT_RADIUS;
        this.color[0] = 0;
    }


    public CustmMultipleDotSpan(int color) {
        this.radius = DEFAULT_RADIUS;
        this.color[0] = 0;
    }


    public CustmMultipleDotSpan(float radius) {
        this.radius = radius;
        this.color[0] = 0;
    }


    public CustmMultipleDotSpan(float radius, int[] color) {
        this.radius = radius;
        this.color = color;
    }

    @Override
    public void drawBackground(
            Canvas canvas, Paint paint,
            int left, int right, int top, int baseline, int bottom,
            CharSequence charSequence,
            int start, int end, int lineNum
    ) {

        int total = color.length > 5 ? 5 : color.length;
        int leftMost = (total - 1) * -10;

        for (int i = 0; i < total; i++) {
            int oldColor = paint.getColor();
            if (color[i] != 0) {
                paint.setColor(color[i]);
            }
            canvas.drawCircle((left + right) / 2 - leftMost, bottom + radius, radius, paint);
            paint.setColor(oldColor);
            leftMost = leftMost + 20;
        }
    }
}

You will also need an ever so slightly altered EventDecorator:

public class EventDecorator implements DayViewDecorator {

    private final int[] colors;
    private final HashSet<CalendarDay> dates;


    public EventDecorator(Collection<CalendarDay> dates, int[] colors) {
        //this.color = color;
        this.dates = new HashSet<>(dates);

        this.colors = colors;

    }


    public EventDecorator(List<MainActivity.Filter> filteredEvents) {
        //this.color = color;

        this.dates = new HashSet<>(filteredEvents.get(0).calDayArr);
        int[] colors = new int[1];
        colors[0] = filteredEvents.get(0).color;
        this.colors = colors;

    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return dates.contains(day);
    }

    @Override
    public void decorate(DayViewFacade view) {

        view.addSpan((new CustmMultipleDotSpan(5,colors)));

    }


}

And that is basically it.

Now find your calendarview in your activity, and give it some dates, and colors to show on those dates. In my particular case, I sort my dates in 5 different lists based on the amount of events per day, so you will end up with something like

calendarView.addDecorator(new EventDecorator(threeEventDays,threeColors)); Where threeEventDays is a Collection of CalendarDay and threeColors is an int array int[] threeColors = { Color.rgb(0, 0, 255), Color.rgb(0, 255, 0), Color.rgb(255, 0, 0)};

It’s nowhere near as ideal as it should be, but what it does is it expects an array of colors. Calculates the leftmost position, based on the array size, so for a size one, the left most position is the middle dot we all know and love. For size 2 the left most position is -10, for size 3 it’s -20 and so on. Then loops through and paints the dots.

It’s limited to 5 event dots as it gets quite ugly above that, and though currently not on my roadmap, if it turns out to be a requirement I might add support for a second line of dots.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
teneketocommented, Jun 13, 2018

@Jake21x

In your CalendarActivity, provided you have the dates in an object:

Collection<CalendarDay> eventsToDisplayInTheCalendar= new ArrayList<>();

int[] arrayOfColorDotsToDisplay={Color.rgb(255,0,0),Color.rgb(0,255,0),Color.rgb(255,255,0),Color.rgb(0,255,255),Color.rgb(0,0,255)};

//You show the evevnts on the calendar using this code, right calendarView.addDecorator(new OneDayDecorator(arrayOfColorDotsToDisplay, eventsToDisplayInTheCalendar));

Then create these two classes into your project and reference them in your CalendarActivity:

CustmMultipleDotSpan.java

import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.style.LineBackgroundSpan;

public class CustmMultipleDotSpan implements LineBackgroundSpan {

    public static final float DEFAULT_RADIUS = 3;

    private final float radius;
    private int[] color = new int[0];


    public CustmMultipleDotSpan() {
        this.radius = DEFAULT_RADIUS;
        this.color[0] = 0;
    }


    public CustmMultipleDotSpan(int color) {
        this.radius = DEFAULT_RADIUS;
        this.color[0] = 0;
    }


    public CustmMultipleDotSpan(float radius) {
        this.radius = radius;
        this.color[0] = 0;
    }


    public CustmMultipleDotSpan(float radius, int[] color) {
        this.radius = radius;
        this.color = color;
    }

    @Override
    public void drawBackground(
            Canvas canvas, Paint paint,
            int left, int right, int top, int baseline, int bottom,
            CharSequence charSequence,
            int start, int end, int lineNum
    ) {

        int total = color.length > 5 ? 5 : color.length;
        int leftMost = (total - 1) * -10;

        for (int i = 0; i < total; i++) {
            int oldColor = paint.getColor();
            if (color[i] != 0) {
                paint.setColor(color[i]);
            }
            canvas.drawCircle((left + right) / 2 - leftMost, bottom + radius, radius, paint);
            paint.setColor(oldColor);
            leftMost = leftMost + 20;
        }
    }
}

OneDayDecorator.java

import java.util.Collection;
import java.util.HashSet;
import java.util.List;

/**
 * Decorate a day by making the text big and bold
 */
public class OneDayDecorator implements DayViewDecorator {

    private final int[] colors;
    private final HashSet<CalendarDay> dates;


    public OneDayDecorator(Collection<CalendarDay> dates, int[] colors) {
        //this.color = color;
        this.dates = new HashSet<>(dates);

        this.colors = colors;

    }


    public OneDayDecorator(List<CalendarFilter> filteredEvents) {
        //this.color = color;

        this.dates = new HashSet<>(filteredEvents.get(0).calDayArr);
        int[]colors = {0};
        colors[0]= filteredEvents.get(0).color;
        this.colors = colors;

    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {

        return dates.contains(day);
    }


    @Override
    public void decorate(DayViewFacade view) {
        view.addSpan((new CustmMultipleDotSpan(9, colors)));
    }
}

0reactions
ashish-dhimancommented, Jul 5, 2019

screen shot of the result: I got this https://imgur.com/CBUlIW4

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get multiple Dots for multiple Events in Calender
I am getting single Dot for multiple events in calender app as show in ... multiple Indication dots if we create multiple events...
Read more >
Import Multiple Events From a CSV file into Google Calendar
Instructions: https://it.stonybrook.edu/help/kb/importing-calendar- events -from-csv-to-google-calendarThese are the headers you can use in ...
Read more >
Multi-day, Spanning Event Calendar - YouTube
The first in the "Reinventing the Wheel" category, we explore how to create an event calendar with events that span multiple days.
Read more >
Code the calendar gallery small dots (circles)
Solved : Hi, hope someone can help me. I have made a calendar gallery based on a SharePoint list. I wanna code the...
Read more >
How to add multiple events to the same date as opposed to ...
The code I have only allows me to add one event in the calendar for each day; I need to be able to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found