This is a migrated thread and some comments may be shown as answers.

Android monthview calendar- event custamization

1 Answer 91 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
rincy
Top achievements
Rank 1
rincy asked on 27 Jan 2015, 09:21 AM
Hi,

I want to customize event indication in month view,

1.If any event is scheduled on a day it has to show as a triangle on the corner(no need to indicate if it having multiple days).
2.when user select a day, event color has to change from blue to white.

Please help me out on this items.

1 Answer, 1 is accepted

Sort by
0
Antony Jekov
Telerik team
answered on 27 Jan 2015, 02:21 PM
Hello Rincy,

Thank you for contacting the Android team.

I made a simple implementation of the screenshot you provided. Here is the code to get you started:

private RadCalendarView calendarView;
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 
    this.calendarView = new RadCalendarView(this);
    this.calendarView.setAdapter(new CustomCalendarAdapter(this.calendarView));
    this.calendarView.getEventAdapter().setRenderer(new CustomEventRenderer(this));
 
    List<Event> events = new ArrayList<>();
    events.add(new Event("Event", Calendar.getInstance().getTimeInMillis(), Calendar.getInstance().getTimeInMillis() + 1));
    this.calendarView.getEventAdapter().setEvents(events);
 
    this.calendarView.getAdapter().setStyle(CalendarStyles.light(this));
    setContentView(this.calendarView);
}
 
private static class CustomCalendarAdapter extends CalendarAdapter {
 
    public CustomCalendarAdapter(RadCalendarView owner) {
        super(owner);
    }
 
    @Override
    protected CalendarDayCell generateCalendarDayCell() {
        return new CustomCalendarDayCell(this.owner);
    }
}
 
private static class CustomCalendarDayCell extends CalendarDayCell {
 
    public CustomCalendarDayCell(RadCalendarView owner) {
        super(owner);
    }
 
    @Override
    protected void drawEvents(Canvas canvas) {
        if (this.getEvents() != null && this.getEvents().size() > 0)
            this.owner.getEventAdapter().getRenderer().renderEvents(canvas, this);
    }
}
 
private static class CustomEventRenderer extends EventRenderer {
 
    private static final int COLOR_IDLE = Color.parseColor("#38b4db");
    private static final int COLOR_SELECTED = Color.parseColor("#ffffff");
 
    private float size;
    private Paint paint;
 
    public CustomEventRenderer(Context context) {
        super(context);
 
        this.size = Util.getDimen(TypedValue.COMPLEX_UNIT_DIP, 20);
        this.paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }
 
    @Override
    public void renderEvents(Canvas canvas, CalendarDayCell cell) {
        Path path = new Path();
        path.moveTo(cell.getRight() - this.size, cell.getBottom());
        path.lineTo(cell.getRight(), cell.getBottom());
        path.lineTo(cell.getRight(), cell.getBottom() - this.size);
        path.close();
 
        if (cell.isSelected())
            this.paint.setColor(COLOR_SELECTED);
        else
            this.paint.setColor(COLOR_IDLE);
 
        canvas.drawPath(path, this.paint);
    }
}

This should be close to the desired result. Please let me know if you need some further assistance.

Thank you for your time and all best!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Calendar
Asked by
rincy
Top achievements
Rank 1
Answers by
Antony Jekov
Telerik team
Share this question
or