Search in sources :

Example 1 with Attendee

use of com.android.calendar.icalendar.Attendee in project Etar-Calendar by Etar-Group.

the class ImportActivity method parseCalFile.

private void parseCalFile() {
    Uri uri = getIntent().getData();
    VCalendar calendar = IcalendarUtils.readCalendarFromFile(this, uri);
    if (calendar == null) {
        showErrorToast();
        return;
    }
    Intent calIntent = new Intent(Intent.ACTION_INSERT);
    calIntent.setType("vnd.android.cursor.item/event");
    LinkedList<VEvent> events = calendar.getAllEvents();
    if (events == null) {
        showErrorToast();
        return;
    }
    VEvent firstEvent = calendar.getAllEvents().getFirst();
    calIntent.putExtra(CalendarContract.Events.TITLE, IcalendarUtils.uncleanseString(firstEvent.getProperty(VEvent.SUMMARY)));
    calIntent.putExtra(CalendarContract.Events.EVENT_LOCATION, IcalendarUtils.uncleanseString(firstEvent.getProperty(VEvent.LOCATION)));
    calIntent.putExtra(CalendarContract.Events.DESCRIPTION, IcalendarUtils.uncleanseString(firstEvent.getProperty(VEvent.DESCRIPTION)));
    calIntent.putExtra(CalendarContract.Events.ORGANIZER, IcalendarUtils.uncleanseString(firstEvent.getProperty(VEvent.ORGANIZER)));
    if (firstEvent.mAttendees.size() > 0) {
        StringBuilder builder = new StringBuilder();
        for (Attendee attendee : firstEvent.mAttendees) {
            builder.append(attendee.mEmail);
            builder.append(",");
        }
        calIntent.putExtra(Intent.EXTRA_EMAIL, builder.toString());
    }
    String dtStart = firstEvent.getProperty(VEvent.DTSTART);
    if (!TextUtils.isEmpty(dtStart)) {
        calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, getLocalTimeFromString(dtStart));
    }
    String dtEnd = firstEvent.getProperty(VEvent.DTEND);
    if (!TextUtils.isEmpty(dtEnd)) {
        calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, getLocalTimeFromString(dtEnd));
    }
    calIntent.putExtra(EditEventActivity.EXTRA_READ_ONLY, true);
    try {
        startActivity(calIntent);
    } catch (ActivityNotFoundException e) {
    // Oh well...
    } finally {
        finish();
    }
}
Also used : VEvent(com.android.calendar.icalendar.VEvent) VCalendar(com.android.calendar.icalendar.VCalendar) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) Uri(android.net.Uri) Attendee(com.android.calendar.icalendar.Attendee)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Attendee (com.android.calendar.icalendar.Attendee)1 VCalendar (com.android.calendar.icalendar.VCalendar)1 VEvent (com.android.calendar.icalendar.VEvent)1