复发biWeekly库

时间:2016-10-07 12:48:50

标签: java android calendar icalendar

BEGIN:VEVENT
DTSTART;TZID=America/Los_Angeles:20151116T123000
DTEND;TZID=America/Los_Angeles:20151116T140000
EXDATE;TZID=America/Los_Angeles:20160215T123000
EXDATE;TZID=America/Los_Angeles:20160530T123000
EXDATE;TZID=America/Los_Angeles:20160704T123000
EXDATE;TZID=America/Los_Angeles:20160905T123000
EXDATE;TZID=America/Los_Angeles:20170220T123000
EXDATE;TZID=America/Los_Angeles:20170529T123000
RRULE:FREQ=WEEKLY;BYDAY=MO
DTSTAMP:20161007T103007Z
UID:up5l07cp40qiqia1evqjk02r9c@google.com
CREATED:20151116T002427Z
DESCRIPTION:
LAST-MODIFIED:20160829T190451Z
LOCATION:
SEQUENCE:2
STATUS:CONFIRMED
SUMMARY:iOS Today
TRANSP:OPAQUE
END:VEVENT 

我正在尝试使用库https://github.com/alamkanak/Android-Week-View和此库https://github.com/mangstadt/biweekly为Android应用程序构建calenderView来解析ICS。但是,我在创建具有重复发生的事件时遇到问题,如示例中所示。

protected  TreeMap<Integer,TreeMap<Integer,List<WeekViewEvent>>>  doInBackground(String... params) {
        ICalendar ical = Biweekly.parse(params[0]).first();
        List<VEvent> le = ical.getEvents();
        for(VEvent ev: le){
            Calendar startTime = Calendar.getInstance();
            startTime.setTimeInMillis(ev.getDateStart().getValue().getTime());
            if(ev.getRecurrenceRule()!=null){
                //Don't know what do I do here

            }

            int year = startTime.get(Calendar.YEAR);
            int month = startTime.get(Calendar.MONTH);
            //Log.v("Calendar",year+" Ano " + month +" Mes");
            Calendar endTime = Calendar.getInstance();
            if(ev.getDateEnd()==null){
                continue;
            }
            endTime.setTimeInMillis(ev.getDateEnd().getValue().getTime());
            WeekViewEvent we = new WeekViewEvent(0,ev.getSummary().getValue(),startTime,endTime);
            if(eventos.get(we.getStartTime().get(Calendar.YEAR))==null){
                TreeMap<Integer,List<WeekViewEvent>> as = new TreeMap<>();
                List<WeekViewEvent> listEv = new ArrayList<>();
                listEv.add(we);
                as.put(we.getStartTime().get(Calendar.MONTH),listEv);
                eventos.put(we.getStartTime().get(Calendar.YEAR),as);
            }
            else {
                TreeMap<Integer, List <WeekViewEvent>> as = eventos.get(we.getStartTime().get(Calendar.YEAR));
                if(as.containsKey(we.getStartTime().get(Calendar.MONTH))){
                    as.get(we.getStartTime().get(Calendar.MONTH)).add(we);
                }else {
                    List<WeekViewEvent> listEv= new ArrayList<>();
                    listEv.add(we);
                    as.put(we.getStartTime().get(Calendar.MONTH),listEv);
                }
            }
        }
        return eventos;
    }

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

也许您应该在http://jfxtras.org/

尝试iCalendarAgenda

它利用了一个名为iCalendarFX的新的iCalendar API for Java。虽然我还没有在Android上使用它,但我知道Tom Eugelink已经获得了在Android上运行的Agenda控制(iCalendarAgenda扩展)。

我写了iCalendarFx,它很容易解析你在那里的VEVENT。