Is there any way of attaching more than 1 DotSpan\'s to a date with Android MaterialCalendarView? Altough I have 2 DotSpan\'s added to my CalendarView it\'s still displaying onl
You are overriding the first DotSpan with the second. The given DotSpan class, lets you create a centered colored dot below the text, so if you put one on top of the other, the first won't be visible.
I've managed to create few DotSpans at the same DayViewFacade view, I'm not sure if that's the exact solution you searched for but I'm sure it'll be helpful:
So you have to create a custom Decorator class that implements DayViewDecorator, let's call it OrangeDecorator.
You'll have to create another custom class that implements LineBackgroundSpan, and we'll call it MyCustomOrangeSpan.
Both classes are almost the same as the original DotSpan and EventDecorator taken from the original library, but you can customize the classes for your needs.
At the "decorate" function (OrangeDecorator class) use your custom LineBackgroundSpan like so:
@Override
public void decorate(DayViewFacade view) {
view.addSpan(new MyCustomOrangeSpan(6, ContextCompat.getColor(mContext, R.color.AppOrange)));
}
At the "drawBackground" function (MyCustomOrangeSpan class) you'll be able to position the circle inside the canvas, so let's do it:
@Override
public void drawBackground(Canvas canvas, Paint paint, int left, int right, int top, int baseline,
int bottom, CharSequence text, int start, int end, int lnum) {
int oldColor = paint.getColor();
if (color != 0) {
paint.setColor(color);
}
canvas.drawCircle((left + right) / 2 - 20, bottom + radius, radius, paint);
paint.setColor(oldColor);
}
This way, we can create multiple DayViewDecorators and LineBackgroundSpan (for different positioning):
BlueDecorator blueDecorator = new BlueDecorator(getActivity(),eventsDays,eventsMap);
OrangeDecorator orangeDecorator = new OrangeDecorator(getActivity(),eventsDays,eventsMap);
GreenDecorator greenDecorator = new GreenDecorator(getActivity(),eventsDays,eventsMap);
materialCalendarView.addDecorator(blueDecorator);
materialCalendarView.addDecorator(orangeDecorator);
materialCalendarView.addDecorator(greenDecorator);