Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add circular decorator in calendar dayview?

I am using npanigrahy:Custom-Calendar-View to show my custom calendar but my problem is how can I add circular bullets on event created in calendar?

like image 337
Jabes Pauya Avatar asked Jun 16 '16 09:06

Jabes Pauya


1 Answers

It is the best way to use this library. I have impelemented like this:

calendarView.addDecorators(new CurrentDayDecorator(this));

and here CurrentDayDecatator class:

package com.calendar.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;

import com.calendar.MainActivity;
import com.calendar.R;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;

import java.util.Calendar;
import java.util.Collection;
import java.util.Date;

/**
 * Created by Navruz on 17.06.2016.
*/
public class CurrentDayDecorator implements DayViewDecorator {

private Drawable drawable;

CalendarDay currentDay = CalendarDay.from(new Date());

public CurrentDayDecorator(Activity context) {
    drawable = ContextCompat.getDrawable(context,     R.drawable.first_day_month);

}

@Override
public boolean shouldDecorate(CalendarDay day) {
    return day.equals(currentDay);
}

@Override
public void decorate(DayViewFacade view) {
    view.setSelectionDrawable(drawable);
}
}

And here itis circele drawable which is named first_day_month

<?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"/>

like image 200
nAkhmedov Avatar answered Oct 07 '22 19:10

nAkhmedov