Android monthview calendar- event custamization

2 posts, 0 answers
  1. rincy
    rincy avatar
    14 posts
    Member since:
    Nov 2014

    Posted 27 Jan 2015 Link to this post

    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.
  2. Antony Jekov
    Admin
    Antony Jekov avatar
    88 posts

    Posted 27 Jan 2015 Link to this post

    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.

     
  3. DevCraft banner
Back to Top