ApplikeySolutions / CosmoCalendar

📅 CosmoCalendar is a fully customizable calendar with a wide variety of features and displaying modes.
https://applikeysolutions.com
MIT License
1.62k stars 288 forks source link

Adding Marker in Calendar using Connected Days for events, task, note, etc. #93

Open abdulrahmankazi opened 3 years ago

abdulrahmankazi commented 3 years ago

### SOLUTION TO ADD EVENTS

Screenshot_1622012396

I was searching for a way to add marker on particular dates, but didn't find any. However as you can see in above image, I have managed to add marker to Calendar dates. I have used addConnectedDays() provided by Cosmo Calendar. Markers can be added on TOP & BOTTOM of date. Sharing code I used:

                    Set<Long> days = new TreeSet<>();
                    e.g. 
                    String date1 = "05-18-2021";
                    String date2 = "05-09-2021";
                    //........

                    SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd-yyyy");
                    try {
                        Date mDate1 = sdf1.parse(date1);
                        long timeInMilliseconds1 = mDate1.getTime();

                        Date mDate2 = sdf1.parse(date2);
                        long timeInMilliseconds2 = mDate2.getTime();

                        days.add(timeInMilliseconds1);
                        days.add(timeInMilliseconds2);
                        // can add more days to set

                    } catch (Exception e) {
                        Log.e("DateException", e.getMessage());
                    }

                int textColor = Color.parseColor("#0063B0");
                int selectedTextColor = Color.parseColor("#FFFFFF");
                int disabledTextColor = Color.parseColor("#ff8000");
                ConnectedDays connectedDays = new ConnectedDays(days, textColor, selectedTextColor, disabledTextColor);

                //Add Connect days to calendar
                calendarView.addConnectedDays(connectedDays);

                calendarView.setConnectedDayIconRes(R.drawable.ic_baseline_star_24);   // Drawable
                calendarView.setConnectedDayIconPosition(ConnectedDayIconPosition.TOP);// TOP & BOTTOM
                calendarView.update();
sourav-android commented 2 years ago

the calendar keeps to the current month, how do I stop this ?

TakJIAe commented 2 years ago

Thanks for providing the solution. I want multiple markers for that date to be created, do you know how?

abdulrahmankazi commented 2 years ago

Better to use https://github.com/kizitonwose/CalendarView or https://github.com/huanghaibin-dev/CalendarView