void populateReminders(Event e) throws RemoteException { // reminders Uri remindersUri = Reminders.CONTENT_URI .buildUpon() .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true") .build(); @Cleanup Cursor c = providerClient.query( remindersUri, new String[] { /* 0 */ Reminders.MINUTES, Reminders.METHOD }, Reminders.EVENT_ID + "=?", new String[] {String.valueOf(e.getLocalID())}, null); while (c != null && c.moveToNext()) { VAlarm alarm = new VAlarm(new Dur(0, 0, -c.getInt(0), 0)); PropertyList props = alarm.getProperties(); switch (c.getInt(1)) { /*case Reminders.METHOD_EMAIL: props.add(Action.EMAIL); break;*/ default: props.add(Action.DISPLAY); props.add(new Description(e.getSummary())); } e.addAlarm(alarm); } }
public List<Event> getEvents(String filter) { if ("".equals(filter)) { return new ArrayList<Event>(events); } List<Event> filteredEvents = new ArrayList<Event>(); for (Event event : events) { if (event.getDescription().toLowerCase().contains(filter.toLowerCase()) || event.getLocation().toLowerCase().contains(filter.toLowerCase()) || event.getSummary().toLowerCase().contains(filter.toLowerCase())) { filteredEvents.add(event); } } return filteredEvents; }
@Override protected Builder buildEntry(Builder builder, Resource resource) { Event event = (Event) resource; builder = builder .withValue(Events.CALENDAR_ID, id) .withValue(entryColumnRemoteName(), event.getName()) .withValue(entryColumnETag(), event.getETag()) .withValue(entryColumnUID(), event.getUid()) .withValue(Events.ALL_DAY, event.isAllDay() ? 1 : 0) .withValue(Events.DTSTART, event.getDtStartInMillis()) .withValue(Events.EVENT_TIMEZONE, event.getDtStartTzID()) .withValue(Events.HAS_ATTENDEE_DATA, event.getAttendees().isEmpty() ? 0 : 1) .withValue(Events.GUESTS_CAN_INVITE_OTHERS, 1) .withValue(Events.GUESTS_CAN_MODIFY, 1) .withValue(Events.GUESTS_CAN_SEE_GUESTS, 1); boolean recurring = false; if (event.getRrule() != null) { recurring = true; builder = builder.withValue(Events.RRULE, event.getRrule().getValue()); } if (event.getRdate() != null) { recurring = true; builder = builder.withValue(Events.RDATE, event.getRdate().getValue()); } if (event.getExrule() != null) builder = builder.withValue(Events.EXRULE, event.getExrule().getValue()); if (event.getExdate() != null) builder = builder.withValue(Events.EXDATE, event.getExdate().getValue()); // set either DTEND for single-time events or DURATION for recurring events // because that's the way Android likes it (see docs) if (recurring) { // calculate DURATION from start and end date Duration duration = new Duration(event.getDtStart().getDate(), event.getDtEnd().getDate()); builder = builder.withValue(Events.DURATION, duration.getValue()); } else { builder = builder .withValue(Events.DTEND, event.getDtEndInMillis()) .withValue(Events.EVENT_END_TIMEZONE, event.getDtEndTzID()); } if (event.getSummary() != null) builder = builder.withValue(Events.TITLE, event.getSummary()); if (event.getLocation() != null) builder = builder.withValue(Events.EVENT_LOCATION, event.getLocation()); if (event.getDescription() != null) builder = builder.withValue(Events.DESCRIPTION, event.getDescription()); if (event.getOrganizer() != null && event.getOrganizer().getCalAddress() != null) { URI organizer = event.getOrganizer().getCalAddress(); if (organizer.getScheme() != null && organizer.getScheme().equalsIgnoreCase("mailto")) builder = builder.withValue(Events.ORGANIZER, organizer.getSchemeSpecificPart()); } Status status = event.getStatus(); if (status != null) { int statusCode = Events.STATUS_TENTATIVE; if (status == Status.VEVENT_CONFIRMED) statusCode = Events.STATUS_CONFIRMED; else if (status == Status.VEVENT_CANCELLED) statusCode = Events.STATUS_CANCELED; builder = builder.withValue(Events.STATUS, statusCode); } builder = builder.withValue( Events.AVAILABILITY, event.isOpaque() ? Events.AVAILABILITY_BUSY : Events.AVAILABILITY_FREE); if (event.getForPublic() != null) builder = builder.withValue( Events.ACCESS_LEVEL, event.getForPublic() ? Events.ACCESS_PUBLIC : Events.ACCESS_PRIVATE); return builder; }