Android calendar with events

2

At the moment I only have this calendar.

I'musingMaterialCalendarView

<com.prolificinteractive.materialcalendarview.MaterialCalendarViewxmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/calendarView"
            android:layout_centerInParent = "true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:mcv_showOtherDates="all"
            app:mcv_selectionColor="#00FFFF" />
    </android.support.constraint.ConstraintLayout>

I want to schedule events on a particular date, so that these activities are visible in the calendar .

example : If on August 5th I have a birthday scheduled, I would like something to be described on that day . Or by images or texts. As illustrated in the following figure.

Some ideas for what I want?

    
asked by anonymous 01.08.2017 / 15:36

2 answers

1

Nokas,

To define events you can use the following code:

calendarView.addEvent(new Event(date, "Feriado X"));

To highlight the events, you will need to use decorators on specific dates, where you define how this customization should be according to the date type.

In the documentation there is an example of how to put a point on specific dates:

public class EventDecorator implements DayViewDecorator {

    private final int color;
    private final HashSet<CalendarDay> dates;

    public EventDecorator(int color, Collection<CalendarDay> dates) {
        this.color = color;
        this.dates = new HashSet<>(dates);
    }

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

    @Override
    public void decorate(DayViewFacade view) {
        view.addSpan(new DotSpan(5, color));
    }
}

Calling decorator :

calendarView.addDecorators(new EventDecorator(this));

You can also define more than one decorator for different cases:

public class FeriadoDecorator implements DayViewDecorator{
    @Override
    public void decorate(DayView view,Context context) {
        view.setBackground(generateCircleDrawable(color));
    }
}

Adding custom decorator:

widget.addDayViewDecorator(new FeriadoDecorator (), dates);

link

You can use custom styles for the first day of the month, for example:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
          android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:state_checked="true" android:drawable="@drawable/selected_bg_color" />
<item android:state_pressed="true" android:drawable="@drawable/selected_bg_color" />
<item android:drawable="@drawable/red_circle" />

red_circle:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:innerRadius="0dp"
   android:shape="ring"
   android:thicknessRatio="2"
   android:useLevel="false" >
<solid android:color="@android:color/transparent" />
<stroke android:width="2dp" android:color="@color/selected_color" />

selected_bg_color:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/selected_color"/>
<size android:width="120dp" android:height="120dp"/>

Source: link

    
01.08.2017 / 16:02
0

You can use DayViewDecorators . It would look something like:

calendarView.addDecorators(new EventDecorator(
    getResources().getColor(R.color.coarCalendar), calendarDays))

Here's a simple example that is in the documentation :

public class EventDecorator implements DayViewDecorator {

    private final int color;
    private final HashSet<CalendarDay> dates;

    public EventDecorator(int color, Collection<CalendarDay> dates) {
        this.color = color;
        this.dates = new HashSet<>(dates);
    }

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

    @Override
    public void decorate(DayViewFacade view) {
        view.addSpan(new DotSpan(5, color));
    }
}
    
01.08.2017 / 16:03