Android calendar with events

Asked

Viewed 1,141 times

2

At the moment I only have this calendar.

inserir a descrição da imagem aqui

I’m using the Materialcalendarview

    <com.prolificinteractive.materialcalendarview.MaterialCalendarView
            xmlns: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 intend to schedule events on a certain date, so that these activities are visible in the calendar.

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

inserir a descrição da imagem aqui

Some ideas for what I want?

2 answers

1

Nokas,

To set events you can use the following code:

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

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

In the documentation there is an example of how to place 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 the Decorator:

calendarView.addDecorators(new EventDecorator(this));

You can also set more than one developer for different cases:

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

Adding Custom Designer:

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

https://github.com/prolificinteractive/material-calendarview/blob/master/docs/DECORATORS.md


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: https://stackoverflow.com/a/37881374/5626568

  • 1

    Thank you so much! I will test

  • 1

    I already tested it! I managed to put a colored "stitch" on a certain date, but instead of putting this stitch I put a small string and it didn’t work...

  • 1

    Collection<CalendarDay> colldates;&#xA; colldates = new HashSet<>();&#xA; CalendarDay eventDay2 = CalendarDay.from(2017, 07, 18);&#xA; colldates.add(eventDay2);&#xA; materialCalendarView.addDecorator(new EventDecorator(colldates, "Nokas")); **I changed the Eventdecorator Class or the Decorate ** view.addSpan(new String(n)); What am I doing wrong? Sync and corrections by n17t01

  • 1

    @Nokas edited the answer, put an example at the end...

  • 1

    Thank you but tested and still does not give @ℛɑ?æ is not accepting the new Textspan, does not recognize.

0

You can use the DayViewDecorators. It would be something like:

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

See 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));
    }
}
  • Thank you! I will test!

  • I already tested it! I managed to put a colored "stitch" on a certain date, but instead of putting this stitch I put a small string and it didn’t work...

  • Collection<CalendarDay> colldates; colldates = new HashSet<>(); CalendarDay eventDay2 = CalendarDay.from(2017, 07, 18); colldates.add(eventDay2); materialCalendarView.addDecorator(new EventDecorator(colldates, "Nokas")); **I changed the Eventdecorator Class or the Decorate ** view.addSpan(new String(n)); What am I doing wrong? @acklay

  • @Nokas was changing here to put the string.

  • that’s exactly what I did, as you can see in the example I put in the comment, but it’s not working unfortunately :-( @acklay

  • @Nokas is showing some error?

  • No, @acklay is not showing that the string does not appear due to the dimensions of my Materialcalendarview?

  • @Nokas tries to put only one letter for example. I’m giving a test here.

  • I tested with only one letter and didn’t give @acklay

  • @Nokas you used addEvent as Rafael exemplified?

  • I only used addDecorator... @acklay

  • @Nokas tries to do using addEvent instead of Dayviewdecorator

  • I have a problem, Materialcalendarview does not allow me to do addEvent @acklay

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.