1.1 --- a/src/org/gege/caldavsyncadapter/android/entities/AndroidEvent.java Tue Feb 10 21:55:00 2015 +0100 1.2 +++ b/src/org/gege/caldavsyncadapter/android/entities/AndroidEvent.java Tue Feb 10 22:40:00 2015 +0100 1.3 @@ -1,6 +1,6 @@ 1.4 /** 1.5 * Copyright (c) 2012-2013, Gerald Garcia, Timo Berger 1.6 - * 1.7 + * 1.8 * This file is part of Andoid Caldav Sync Adapter Free. 1.9 * 1.10 * Andoid Caldav Sync Adapter Free is free software: you can redistribute 1.11 @@ -16,13 +16,17 @@ 1.12 * You should have received a copy of the GNU General Public License 1.13 * along with Andoid Caldav Sync Adapter Free. 1.14 * If not, see <http://www.gnu.org/licenses/>. 1.15 - * 1.16 + * 1.17 */ 1.18 1.19 package org.gege.caldavsyncadapter.android.entities; 1.20 1.21 -import java.net.URISyntaxException; 1.22 -import java.text.ParseException; 1.23 +import android.database.Cursor; 1.24 +import android.net.Uri; 1.25 +import android.provider.CalendarContract.Attendees; 1.26 +import android.provider.CalendarContract.Events; 1.27 +import android.provider.CalendarContract.Reminders; 1.28 + 1.29 import net.fortuna.ical4j.model.Calendar; 1.30 import net.fortuna.ical4j.model.Component; 1.31 import net.fortuna.ical4j.model.ComponentList; 1.32 @@ -62,255 +66,258 @@ 1.33 import net.fortuna.ical4j.model.property.Trigger; 1.34 import net.fortuna.ical4j.model.property.Uid; 1.35 import net.fortuna.ical4j.model.property.Version; 1.36 + 1.37 +import org.gege.caldavsyncadapter.caldav.entities.CalendarEvent; 1.38 + 1.39 +import java.net.URISyntaxException; 1.40 +import java.text.ParseException; 1.41 + 1.42 //import android.accounts.Account; 1.43 //import android.content.ContentProviderClient; 1.44 //import android.content.ContentValues; 1.45 //import android.content.SyncStats; 1.46 -import android.database.Cursor; 1.47 -import android.net.Uri; 1.48 //import android.os.RemoteException; 1.49 -import android.provider.CalendarContract.Attendees; 1.50 //import android.provider.CalendarContract.Calendars; 1.51 -import android.provider.CalendarContract.Events; 1.52 -import android.provider.CalendarContract.Reminders; 1.53 - 1.54 //import org.gege.caldavsyncadapter.Event; 1.55 //import org.gege.caldavsyncadapter.caldav.CaldavFacade; 1.56 -import org.gege.caldavsyncadapter.caldav.entities.CalendarEvent; 1.57 //import org.gege.caldavsyncadapter.caldav.entities.DavCalendar; 1.58 //import org.gege.caldavsyncadapter.syncadapter.SyncAdapter; 1.59 1.60 public class AndroidEvent extends org.gege.caldavsyncadapter.Event { 1.61 1.62 - private Uri muri; 1.63 - 1.64 - private Uri mAndroidCalendarUri; 1.65 - 1.66 - /** 1.67 - * the list of attendees 1.68 - */ 1.69 - private PropertyList mAttendees = new PropertyList(); 1.70 - 1.71 - /** 1.72 - * the list of reminders 1.73 - */ 1.74 - private ComponentList mReminders = new ComponentList(); 1.75 + private Uri muri; 1.76 1.77 - private Calendar mCalendar = null; 1.78 + private Uri mAndroidCalendarUri; 1.79 + 1.80 + /** 1.81 + * the list of attendees 1.82 + */ 1.83 + private PropertyList mAttendees = new PropertyList(); 1.84 + 1.85 + /** 1.86 + * the list of reminders 1.87 + */ 1.88 + private ComponentList mReminders = new ComponentList(); 1.89 + 1.90 + private Calendar mCalendar = null; 1.91 1.92 /* private Account mAccount = null; 1.93 - private ContentProviderClient mProvider = null;*/ 1.94 - 1.95 - //public AndroidEvent(Account account, ContentProviderClient provider, Uri uri, Uri calendarUri) { 1.96 - public AndroidEvent(Uri uri, Uri calendarUri) { 1.97 - super(); 1.98 - this.setUri(uri); 1.99 + private ContentProviderClient mProvider = null;*/ 1.100 + 1.101 + //public AndroidEvent(Account account, ContentProviderClient provider, Uri uri, Uri calendarUri) { 1.102 + public AndroidEvent(Uri uri, Uri calendarUri) { 1.103 + super(); 1.104 + this.setUri(uri); 1.105 /* this.mAccount = account; 1.106 - this.mProvider = provider;*/ 1.107 - //this.setCounterpartUri(calendarUri); 1.108 - mAndroidCalendarUri = calendarUri; 1.109 - } 1.110 - 1.111 - public Calendar getIcsEvent() { 1.112 - return mCalendar; 1.113 - } 1.114 - 1.115 - public String getETag() { 1.116 - String Result = ""; 1.117 - if (this.ContentValues.containsKey(ETAG)) 1.118 - Result = this.ContentValues.getAsString(ETAG); 1.119 - return Result; 1.120 - } 1.121 + this.mProvider = provider;*/ 1.122 + //this.setCounterpartUri(calendarUri); 1.123 + mAndroidCalendarUri = calendarUri; 1.124 + } 1.125 1.126 - public void setETag(String eTag) { 1.127 - this.ContentValues.put(ETAG, eTag); 1.128 - } 1.129 - 1.130 - public Uri getUri() { 1.131 - return muri; 1.132 - } 1.133 + public Calendar getIcsEvent() { 1.134 + return mCalendar; 1.135 + } 1.136 1.137 - public void setUri(Uri uri) { 1.138 - this.muri = uri; 1.139 - } 1.140 - 1.141 - public Uri getAndroidCalendarUri() { 1.142 - return mAndroidCalendarUri; 1.143 - } 1.144 - 1.145 - @Override 1.146 - public String toString() { 1.147 - return this.getUri().toString(); 1.148 - } 1.149 - 1.150 - /** 1.151 - * reads an android event from a given cursor into {@link AndroidEvent#ContentValues} 1.152 - * @param cur the cursor with the event 1.153 - * @return success of this funtion 1.154 - * @see AndroidEvent#ContentValues 1.155 - */ 1.156 - public boolean readContentValues(Cursor cur) { 1.157 - this.setETag(cur.getString(cur.getColumnIndex(ETAG))); 1.158 + public String getETag() { 1.159 + String Result = ""; 1.160 + if (this.ContentValues.containsKey(ETAG)) 1.161 + Result = this.ContentValues.getAsString(ETAG); 1.162 + return Result; 1.163 + } 1.164 1.165 - this.ContentValues.put(Events.EVENT_TIMEZONE, cur.getString(cur.getColumnIndex(Events.EVENT_TIMEZONE))); 1.166 - this.ContentValues.put(Events.EVENT_END_TIMEZONE, cur.getString(cur.getColumnIndex(Events.EVENT_END_TIMEZONE))); 1.167 - this.ContentValues.put(Events.DTSTART, cur.getLong(cur.getColumnIndex(Events.DTSTART))); 1.168 - this.ContentValues.put(Events.DTEND, cur.getLong(cur.getColumnIndex(Events.DTEND))); 1.169 - this.ContentValues.put(Events.ALL_DAY, cur.getLong(cur.getColumnIndex(Events.ALL_DAY))); 1.170 - this.ContentValues.put(Events.TITLE, cur.getString(cur.getColumnIndex(Events.TITLE))); 1.171 - this.ContentValues.put(Events.CALENDAR_ID, cur.getString(cur.getColumnIndex(Events.CALENDAR_ID))); 1.172 - this.ContentValues.put(Events._SYNC_ID, cur.getString(cur.getColumnIndex(Events._SYNC_ID))); 1.173 - //this.ContentValues.put(Events.SYNC_DATA1, cur.getString(cur.getColumnIndex(Events.SYNC_DATA1))); //not needed here, eTag has already been read 1.174 - this.ContentValues.put(Events.DESCRIPTION, cur.getString(cur.getColumnIndex(Events.DESCRIPTION))); 1.175 - this.ContentValues.put(Events.EVENT_LOCATION, cur.getString(cur.getColumnIndex(Events.EVENT_LOCATION))); 1.176 - this.ContentValues.put(Events.ACCESS_LEVEL, cur.getInt(cur.getColumnIndex(Events.ACCESS_LEVEL))); 1.177 - 1.178 - this.ContentValues.put(Events.STATUS, cur.getInt(cur.getColumnIndex(Events.STATUS))); 1.179 - 1.180 - this.ContentValues.put(Events.LAST_DATE, cur.getInt(cur.getColumnIndex(Events.LAST_DATE))); 1.181 - this.ContentValues.put(Events.DURATION, cur.getString(cur.getColumnIndex(Events.DURATION))); 1.182 + public void setETag(String eTag) { 1.183 + this.ContentValues.put(ETAG, eTag); 1.184 + } 1.185 1.186 - this.ContentValues.put(Events.RDATE, cur.getString(cur.getColumnIndex(Events.RDATE))); 1.187 - this.ContentValues.put(Events.RRULE, cur.getString(cur.getColumnIndex(Events.RRULE))); 1.188 - this.ContentValues.put(Events.EXRULE, cur.getString(cur.getColumnIndex(Events.EXRULE))); 1.189 - this.ContentValues.put(Events.EXDATE, cur.getString(cur.getColumnIndex(Events.EXDATE))); 1.190 - this.ContentValues.put(Events.DIRTY, cur.getInt(cur.getColumnIndex(Events.DIRTY))); 1.191 - this.ContentValues.put(UID, cur.getString(cur.getColumnIndex(UID))); 1.192 - this.ContentValues.put(RAWDATA, cur.getString(cur.getColumnIndex(RAWDATA))); 1.193 - 1.194 - return true; 1.195 - } 1.196 - 1.197 - /** 1.198 - * reads the attendees from a given cursor 1.199 - * @param cur the cursor with the attendees 1.200 - * @return success of this function 1.201 - * @see AndroidEvent#mAttendees 1.202 - */ 1.203 - public boolean readAttendees(Cursor cur) { 1.204 - Attendee attendee = null; 1.205 - Organizer organizer = null; 1.206 - ParameterList paraList = null; 1.207 + public Uri getUri() { 1.208 + return muri; 1.209 + } 1.210 1.211 - String Name = ""; 1.212 - Cn cn = null; 1.213 + public void setUri(Uri uri) { 1.214 + this.muri = uri; 1.215 + } 1.216 1.217 - String Email = ""; 1.218 + public Uri getAndroidCalendarUri() { 1.219 + return mAndroidCalendarUri; 1.220 + } 1.221 1.222 - int Relationship = 0; 1.223 - 1.224 - 1.225 - int Status = 0; 1.226 - PartStat partstat = null; 1.227 + @Override 1.228 + public String toString() { 1.229 + return this.getUri().toString(); 1.230 + } 1.231 1.232 - int Type = 0; 1.233 - Role role = null; 1.234 - 1.235 - try { 1.236 - while (cur.moveToNext()) { 1.237 - Name = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_NAME)); 1.238 - Email = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_EMAIL)); 1.239 - Relationship = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_RELATIONSHIP)); 1.240 - Type = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_TYPE)); 1.241 - Status = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_STATUS)); 1.242 - 1.243 - if (Relationship == Attendees.RELATIONSHIP_ORGANIZER) { 1.244 - organizer = new Organizer(); 1.245 - organizer.setValue("mailto:" + Email); 1.246 - paraList = organizer.getParameters(); 1.247 - mAttendees.add(organizer); 1.248 - } else { 1.249 - attendee = new Attendee(); 1.250 - attendee.setValue("mailto:" + Email); 1.251 - paraList = attendee.getParameters(); 1.252 - mAttendees.add(attendee); 1.253 - } 1.254 - 1.255 - Rsvp rsvp = new Rsvp(true); 1.256 - paraList.add(rsvp); 1.257 + /** 1.258 + * reads an android event from a given cursor into {@link AndroidEvent#ContentValues} 1.259 + * 1.260 + * @param cur the cursor with the event 1.261 + * @return success of this funtion 1.262 + * @see AndroidEvent#ContentValues 1.263 + */ 1.264 + public boolean readContentValues(Cursor cur) { 1.265 + this.setETag(cur.getString(cur.getColumnIndex(ETAG))); 1.266 1.267 - cn = new Cn(Name); 1.268 - paraList.add(cn); 1.269 - 1.270 - if (Status == Attendees.ATTENDEE_STATUS_INVITED) 1.271 - partstat = new PartStat(PartStat.NEEDS_ACTION.getValue()); 1.272 - else if (Status == Attendees.ATTENDEE_STATUS_ACCEPTED) 1.273 - partstat = new PartStat(PartStat.ACCEPTED.getValue()); 1.274 - else if (Status == Attendees.ATTENDEE_STATUS_DECLINED) 1.275 - partstat = new PartStat(PartStat.DECLINED.getValue()); 1.276 - else if (Status == Attendees.ATTENDEE_STATUS_NONE) 1.277 - partstat = new PartStat(PartStat.COMPLETED.getValue()); 1.278 - else if (Status == Attendees.ATTENDEE_STATUS_TENTATIVE) 1.279 - partstat = new PartStat(PartStat.TENTATIVE.getValue()); 1.280 - else 1.281 - partstat = new PartStat(PartStat.NEEDS_ACTION.getValue()); 1.282 - paraList.add(partstat); 1.283 + this.ContentValues.put(Events.EVENT_TIMEZONE, cur.getString(cur.getColumnIndex(Events.EVENT_TIMEZONE))); 1.284 + this.ContentValues.put(Events.EVENT_END_TIMEZONE, cur.getString(cur.getColumnIndex(Events.EVENT_END_TIMEZONE))); 1.285 + this.ContentValues.put(Events.DTSTART, cur.getLong(cur.getColumnIndex(Events.DTSTART))); 1.286 + this.ContentValues.put(Events.DTEND, cur.getLong(cur.getColumnIndex(Events.DTEND))); 1.287 + this.ContentValues.put(Events.ALL_DAY, cur.getLong(cur.getColumnIndex(Events.ALL_DAY))); 1.288 + this.ContentValues.put(Events.TITLE, cur.getString(cur.getColumnIndex(Events.TITLE))); 1.289 + this.ContentValues.put(Events.CALENDAR_ID, cur.getString(cur.getColumnIndex(Events.CALENDAR_ID))); 1.290 + this.ContentValues.put(Events._SYNC_ID, cur.getString(cur.getColumnIndex(Events._SYNC_ID))); 1.291 + //this.ContentValues.put(Events.SYNC_DATA1, cur.getString(cur.getColumnIndex(Events.SYNC_DATA1))); //not needed here, eTag has already been read 1.292 + this.ContentValues.put(Events.DESCRIPTION, cur.getString(cur.getColumnIndex(Events.DESCRIPTION))); 1.293 + this.ContentValues.put(Events.EVENT_LOCATION, cur.getString(cur.getColumnIndex(Events.EVENT_LOCATION))); 1.294 + this.ContentValues.put(Events.ACCESS_LEVEL, cur.getInt(cur.getColumnIndex(Events.ACCESS_LEVEL))); 1.295 1.296 - if (Type == Attendees.TYPE_OPTIONAL) 1.297 - role = new Role(Role.OPT_PARTICIPANT.getValue()); 1.298 - else if (Type == Attendees.TYPE_NONE) 1.299 - role = new Role(Role.NON_PARTICIPANT.getValue()); //regular participants in android are non required? 1.300 - else if (Type == Attendees.TYPE_REQUIRED) 1.301 - role = new Role(Role.REQ_PARTICIPANT.getValue()); 1.302 - else 1.303 - role = new Role(Role.NON_PARTICIPANT.getValue()); 1.304 - paraList.add(role); 1.305 - } 1.306 + this.ContentValues.put(Events.STATUS, cur.getInt(cur.getColumnIndex(Events.STATUS))); 1.307 1.308 - } catch (URISyntaxException e) { 1.309 - e.printStackTrace(); 1.310 - } 1.311 - return true; 1.312 - } 1.313 - 1.314 - /** 1.315 - * reads the reminders from a given cursor 1.316 - * @param cur the cursor with the reminders 1.317 - * @return success of this function 1.318 - */ 1.319 - public boolean readReminder(Cursor cur) { 1.320 - int Method; 1.321 - int Minutes; 1.322 - VAlarm reminder; 1.323 - while (cur.moveToNext()) { 1.324 - reminder = new VAlarm(); 1.325 - Method = cur.getInt(cur.getColumnIndex(Reminders.METHOD)); 1.326 - Minutes = cur.getInt(cur.getColumnIndex(Reminders.MINUTES)) * -1; 1.327 - 1.328 - 1.329 - Dur dur = new Dur(0, 0, Minutes, 0); 1.330 - Trigger tri = new Trigger(dur); 1.331 - Value val = new Value(Duration.DURATION); 1.332 - tri.getParameters().add(val); 1.333 - reminder.getProperties().add(tri); 1.334 + this.ContentValues.put(Events.LAST_DATE, cur.getInt(cur.getColumnIndex(Events.LAST_DATE))); 1.335 + this.ContentValues.put(Events.DURATION, cur.getString(cur.getColumnIndex(Events.DURATION))); 1.336 1.337 - Description desc = new Description(); 1.338 - desc.setValue("caldavsyncadapter standard description"); 1.339 - reminder.getProperties().add(desc); 1.340 + this.ContentValues.put(Events.RDATE, cur.getString(cur.getColumnIndex(Events.RDATE))); 1.341 + this.ContentValues.put(Events.RRULE, cur.getString(cur.getColumnIndex(Events.RRULE))); 1.342 + this.ContentValues.put(Events.EXRULE, cur.getString(cur.getColumnIndex(Events.EXRULE))); 1.343 + this.ContentValues.put(Events.EXDATE, cur.getString(cur.getColumnIndex(Events.EXDATE))); 1.344 + this.ContentValues.put(Events.DIRTY, cur.getInt(cur.getColumnIndex(Events.DIRTY))); 1.345 + this.ContentValues.put(UID, cur.getString(cur.getColumnIndex(UID))); 1.346 + this.ContentValues.put(RAWDATA, cur.getString(cur.getColumnIndex(RAWDATA))); 1.347 1.348 + return true; 1.349 + } 1.350 1.351 - if (Method == Reminders.METHOD_EMAIL) 1.352 - reminder.getProperties().add(Action.EMAIL); 1.353 - else 1.354 - reminder.getProperties().add(Action.DISPLAY); 1.355 - 1.356 - this.mReminders.add(reminder); 1.357 - } 1.358 - return true; 1.359 - } 1.360 - 1.361 - /** 1.362 - * generates a new ics-file. 1.363 - * uses {@link AndroidEvent#ContentValues} as source. 1.364 - * this should only be used when a new event has been generated within android. 1.365 - * @param strUid the UID for this event. example: UID:e6be67c6-eff0-44f8-a1a0-6c2cb1029944-caldavsyncadapter 1.366 - * @return success of the function 1.367 - * @see CalendarEvent#fetchBody() 1.368 - */ 1.369 - public boolean createIcs(String strUid) { 1.370 - boolean Result = false; 1.371 - TimeZone timezone = null; 1.372 - TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); 1.373 + /** 1.374 + * reads the attendees from a given cursor 1.375 + * 1.376 + * @param cur the cursor with the attendees 1.377 + * @return success of this function 1.378 + * @see AndroidEvent#mAttendees 1.379 + */ 1.380 + public boolean readAttendees(Cursor cur) { 1.381 + Attendee attendee = null; 1.382 + Organizer organizer = null; 1.383 + ParameterList paraList = null; 1.384 + 1.385 + String Name = ""; 1.386 + Cn cn = null; 1.387 + 1.388 + String Email = ""; 1.389 + 1.390 + int Relationship = 0; 1.391 + 1.392 + 1.393 + int Status = 0; 1.394 + PartStat partstat = null; 1.395 + 1.396 + int Type = 0; 1.397 + Role role = null; 1.398 + 1.399 + try { 1.400 + while (cur.moveToNext()) { 1.401 + Name = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_NAME)); 1.402 + Email = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_EMAIL)); 1.403 + Relationship = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_RELATIONSHIP)); 1.404 + Type = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_TYPE)); 1.405 + Status = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_STATUS)); 1.406 + 1.407 + if (Relationship == Attendees.RELATIONSHIP_ORGANIZER) { 1.408 + organizer = new Organizer(); 1.409 + organizer.setValue("mailto:" + Email); 1.410 + paraList = organizer.getParameters(); 1.411 + mAttendees.add(organizer); 1.412 + } else { 1.413 + attendee = new Attendee(); 1.414 + attendee.setValue("mailto:" + Email); 1.415 + paraList = attendee.getParameters(); 1.416 + mAttendees.add(attendee); 1.417 + } 1.418 + 1.419 + Rsvp rsvp = new Rsvp(true); 1.420 + paraList.add(rsvp); 1.421 + 1.422 + cn = new Cn(Name); 1.423 + paraList.add(cn); 1.424 + 1.425 + if (Status == Attendees.ATTENDEE_STATUS_INVITED) 1.426 + partstat = new PartStat(PartStat.NEEDS_ACTION.getValue()); 1.427 + else if (Status == Attendees.ATTENDEE_STATUS_ACCEPTED) 1.428 + partstat = new PartStat(PartStat.ACCEPTED.getValue()); 1.429 + else if (Status == Attendees.ATTENDEE_STATUS_DECLINED) 1.430 + partstat = new PartStat(PartStat.DECLINED.getValue()); 1.431 + else if (Status == Attendees.ATTENDEE_STATUS_NONE) 1.432 + partstat = new PartStat(PartStat.COMPLETED.getValue()); 1.433 + else if (Status == Attendees.ATTENDEE_STATUS_TENTATIVE) 1.434 + partstat = new PartStat(PartStat.TENTATIVE.getValue()); 1.435 + else 1.436 + partstat = new PartStat(PartStat.NEEDS_ACTION.getValue()); 1.437 + paraList.add(partstat); 1.438 + 1.439 + if (Type == Attendees.TYPE_OPTIONAL) 1.440 + role = new Role(Role.OPT_PARTICIPANT.getValue()); 1.441 + else if (Type == Attendees.TYPE_NONE) 1.442 + role = new Role(Role.NON_PARTICIPANT.getValue()); //regular participants in android are non required? 1.443 + else if (Type == Attendees.TYPE_REQUIRED) 1.444 + role = new Role(Role.REQ_PARTICIPANT.getValue()); 1.445 + else 1.446 + role = new Role(Role.NON_PARTICIPANT.getValue()); 1.447 + paraList.add(role); 1.448 + } 1.449 + 1.450 + } catch (URISyntaxException e) { 1.451 + e.printStackTrace(); 1.452 + } 1.453 + return true; 1.454 + } 1.455 + 1.456 + /** 1.457 + * reads the reminders from a given cursor 1.458 + * 1.459 + * @param cur the cursor with the reminders 1.460 + * @return success of this function 1.461 + */ 1.462 + public boolean readReminder(Cursor cur) { 1.463 + int Method; 1.464 + int Minutes; 1.465 + VAlarm reminder; 1.466 + while (cur.moveToNext()) { 1.467 + reminder = new VAlarm(); 1.468 + Method = cur.getInt(cur.getColumnIndex(Reminders.METHOD)); 1.469 + Minutes = cur.getInt(cur.getColumnIndex(Reminders.MINUTES)) * -1; 1.470 + 1.471 + 1.472 + Dur dur = new Dur(0, 0, Minutes, 0); 1.473 + Trigger tri = new Trigger(dur); 1.474 + Value val = new Value(Duration.DURATION); 1.475 + tri.getParameters().add(val); 1.476 + reminder.getProperties().add(tri); 1.477 + 1.478 + Description desc = new Description(); 1.479 + desc.setValue("caldavsyncadapter standard description"); 1.480 + reminder.getProperties().add(desc); 1.481 + 1.482 + 1.483 + if (Method == Reminders.METHOD_EMAIL) 1.484 + reminder.getProperties().add(Action.EMAIL); 1.485 + else 1.486 + reminder.getProperties().add(Action.DISPLAY); 1.487 + 1.488 + this.mReminders.add(reminder); 1.489 + } 1.490 + return true; 1.491 + } 1.492 + 1.493 + /** 1.494 + * generates a new ics-file. 1.495 + * uses {@link AndroidEvent#ContentValues} as source. 1.496 + * this should only be used when a new event has been generated within android. 1.497 + * 1.498 + * @param strUid the UID for this event. example: UID:e6be67c6-eff0-44f8-a1a0-6c2cb1029944-caldavsyncadapter 1.499 + * @return success of the function 1.500 + * @see CalendarEvent#fetchBody() 1.501 + */ 1.502 + public boolean createIcs(String strUid) { 1.503 + boolean Result = false; 1.504 + TimeZone timeZone = null; 1.505 + TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); 1.506 //TODO: do not simply create the ics-file new. take into account the RAWDATA if available 1.507 /* 1.508 * dtstart=1365598800000 1.509 @@ -335,232 +342,239 @@ 1.510 * _sync_id=null 1.511 * dirty=1 1.512 */ 1.513 - 1.514 - try { 1.515 - mCalendar = new Calendar(); 1.516 - PropertyList propCalendar = mCalendar.getProperties(); 1.517 - propCalendar.add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); 1.518 - propCalendar.add(Version.VERSION_2_0); 1.519 - propCalendar.add(CalScale.GREGORIAN); 1.520 - 1.521 - VEvent event = new VEvent(); 1.522 - mCalendar.getComponents().add(event); 1.523 - PropertyList propEvent = event.getProperties(); 1.524 1.525 - // DTSTAMP -> is created by new VEvent() automatical 1.526 - //na 1.527 - 1.528 - // CREATED 1.529 - //na 1.530 - 1.531 - // LAST-MODIFIED 1.532 - //na 1.533 - 1.534 - // SEQUENCE 1.535 - //na 1.536 - 1.537 - // DTSTART 1.538 - long lngStart = this.ContentValues.getAsLong(Events.DTSTART); 1.539 - String strTZStart = this.ContentValues.getAsString(Events.EVENT_TIMEZONE); 1.540 - boolean allDay = this.ContentValues.getAsBoolean(Events.ALL_DAY); 1.541 - if (lngStart > 0) { 1.542 - DtStart dtStart = new DtStart(); 1.543 - if (allDay) { 1.544 - Date dateStart = new Date(); 1.545 - dateStart.setTime(lngStart); 1.546 - dtStart.setDate(dateStart); 1.547 - } else { 1.548 - DateTime datetimeStart = new DateTime(); 1.549 - datetimeStart.setTime(lngStart); 1.550 - dtStart.setDate(datetimeStart); 1.551 + try { 1.552 + mCalendar = new Calendar(); 1.553 + PropertyList propCalendar = mCalendar.getProperties(); 1.554 + propCalendar.add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); 1.555 + propCalendar.add(Version.VERSION_2_0); 1.556 + propCalendar.add(CalScale.GREGORIAN); 1.557 1.558 - timezone = registry.getTimeZone(strTZStart); 1.559 - dtStart.setTimeZone(timezone); 1.560 - 1.561 - // no timezone information for allDay events 1.562 - mCalendar.getComponents().add(timezone.getVTimeZone()); 1.563 - } 1.564 - propEvent.add(dtStart); 1.565 - } 1.566 - 1.567 - // DTEND 1.568 - long lngEnd = this.ContentValues.getAsLong(Events.DTEND); 1.569 - String strTZEnd = this.ContentValues.getAsString(Events.EVENT_END_TIMEZONE); 1.570 - if (strTZEnd == null) 1.571 - strTZEnd = strTZStart; 1.572 - if (lngEnd > 0) { 1.573 - DtEnd dtEnd = new DtEnd(); 1.574 - if (allDay) { 1.575 - Date dateEnd = new Date(); 1.576 - dateEnd.setTime(lngEnd); 1.577 - dtEnd.setDate(dateEnd); 1.578 - } else { 1.579 - DateTime datetimeEnd = new DateTime(); 1.580 - datetimeEnd.setTime(lngEnd); 1.581 - dtEnd.setDate(datetimeEnd); 1.582 - if (strTZEnd != null) 1.583 - timezone = registry.getTimeZone(strTZEnd); 1.584 - dtEnd.setTimeZone(timezone); 1.585 - } 1.586 - propEvent.add(dtEnd); 1.587 - } 1.588 - 1.589 - // DURATION 1.590 - if (this.ContentValues.containsKey(Events.DURATION)) { 1.591 - String strDuration = this.ContentValues.getAsString(Events.DURATION); 1.592 - if (strDuration != null) { 1.593 - Duration duration = new Duration(); 1.594 - duration.setValue(strDuration); 1.595 - 1.596 - propEvent.add(duration); 1.597 - } 1.598 - } 1.599 + VEvent event = new VEvent(); 1.600 + mCalendar.getComponents().add(event); 1.601 + PropertyList propEvent = event.getProperties(); 1.602 1.603 - //RRULE 1.604 - if (this.ContentValues.containsKey(Events.RRULE)) { 1.605 - String strRrule = this.ContentValues.getAsString(Events.RRULE); 1.606 - if (strRrule != null) { 1.607 - if (!strRrule.equals("")) { 1.608 - RRule rrule = new RRule(); 1.609 - rrule.setValue(strRrule); 1.610 - propEvent.add(rrule); 1.611 - } 1.612 - } 1.613 - } 1.614 - 1.615 - //RDATE 1.616 - if (this.ContentValues.containsKey(Events.RDATE)) { 1.617 - String strRdate = this.ContentValues.getAsString(Events.RDATE); 1.618 - if (strRdate != null) { 1.619 - if (!strRdate.equals("")) { 1.620 - RDate rdate = new RDate(); 1.621 - rdate.setValue(strRdate); 1.622 - propEvent.add(rdate); 1.623 - } 1.624 - } 1.625 - } 1.626 - 1.627 - //EXRULE 1.628 - if (this.ContentValues.containsKey(Events.EXRULE)) { 1.629 - String strExrule = this.ContentValues.getAsString(Events.EXRULE); 1.630 - if (strExrule != null) { 1.631 - if (!strExrule.equals("")) { 1.632 - ExRule exrule = new ExRule(); 1.633 - exrule.setValue(strExrule); 1.634 - propEvent.add(exrule); 1.635 - } 1.636 - } 1.637 - } 1.638 - 1.639 - //EXDATE 1.640 - if (this.ContentValues.containsKey(Events.EXDATE)) { 1.641 - String strExdate = this.ContentValues.getAsString(Events.EXDATE); 1.642 - if (strExdate != null) { 1.643 - if (!strExdate.equals("")) { 1.644 - ExDate exdate = new ExDate(); 1.645 - exdate.setValue(strExdate); 1.646 - propEvent.add(exdate); 1.647 - } 1.648 - } 1.649 - } 1.650 - 1.651 - //SUMMARY 1.652 - if (this.ContentValues.containsKey(Events.TITLE)) { 1.653 - String strTitle = this.ContentValues.getAsString(Events.TITLE); 1.654 - if (strTitle != null) { 1.655 - Summary summary = new Summary(strTitle); 1.656 - propEvent.add(summary); 1.657 - } 1.658 - } 1.659 - 1.660 - //DESCIPTION 1.661 - if (this.ContentValues.containsKey(Events.DESCRIPTION)) { 1.662 - String strDescription = this.ContentValues.getAsString(Events.DESCRIPTION); 1.663 - if (strDescription != null) { 1.664 - if (!strDescription.equals("")) { 1.665 - Description description = new Description(strDescription); 1.666 - propEvent.add(description); 1.667 - } 1.668 - } 1.669 - } 1.670 - 1.671 - //LOCATION 1.672 - if (this.ContentValues.containsKey(Events.EVENT_LOCATION)) { 1.673 - String strLocation = this.ContentValues.getAsString(Events.EVENT_LOCATION); 1.674 - if (strLocation != null) { 1.675 - if (!strLocation.equals("")) { 1.676 - Location location = new Location(strLocation); 1.677 - propEvent.add(location); 1.678 - } 1.679 - } 1.680 - } 1.681 - 1.682 - //CLASS / ACCESS_LEVEL 1.683 - if (this.ContentValues.containsKey(Events.ACCESS_LEVEL)) { 1.684 - int accessLevel = this.ContentValues.getAsInteger(Events.ACCESS_LEVEL); 1.685 - Clazz clazz = new Clazz(); 1.686 - if (accessLevel == Events.ACCESS_PUBLIC) 1.687 - clazz.setValue(Clazz.PUBLIC.getValue()); 1.688 - else if (accessLevel == Events.ACCESS_PRIVATE) 1.689 - clazz.setValue(Clazz.PRIVATE.getValue()); 1.690 - else if (accessLevel == Events.ACCESS_CONFIDENTIAL) 1.691 - clazz.setValue(Clazz.CONFIDENTIAL.getValue()); 1.692 - else 1.693 - clazz.setValue(Clazz.PUBLIC.getValue()); 1.694 - 1.695 - propEvent.add(clazz); 1.696 - } 1.697 - 1.698 - //STATUS 1.699 - if (this.ContentValues.containsKey(Events.STATUS)) { 1.700 - int intStatus = this.ContentValues.getAsInteger(Events.STATUS); 1.701 - if (intStatus > -1) { 1.702 - Status status = new Status(); 1.703 - if (intStatus == Events.STATUS_CANCELED) 1.704 - status.setValue(Status.VEVENT_CANCELLED.getValue()); 1.705 - else if (intStatus == Events.STATUS_CONFIRMED) 1.706 - status.setValue(Status.VEVENT_CONFIRMED.getValue()); 1.707 - else if (intStatus == Events.STATUS_TENTATIVE) 1.708 - status.setValue(Status.VEVENT_TENTATIVE.getValue()); 1.709 - 1.710 - propEvent.add(status); 1.711 - } 1.712 - } 1.713 + // DTSTAMP -> is created by new VEvent() automatical 1.714 + //na 1.715 1.716 - //UID 1.717 - Uid uid = new Uid(strUid); 1.718 - propEvent.add(uid); 1.719 + // CREATED 1.720 + //na 1.721 1.722 - // Attendees 1.723 - if (mAttendees.size() > 0) { 1.724 - for (Object objProp: mAttendees) { 1.725 - Property prop = (Property) objProp; 1.726 - propEvent.add(prop); 1.727 - } 1.728 - } 1.729 - 1.730 - // Reminders 1.731 - if (mReminders.size() > 0) { 1.732 - for (Object objComp: mReminders) { 1.733 - Component com = (Component) objComp; 1.734 - event.getAlarms().add(com); 1.735 - } 1.736 - } 1.737 - 1.738 - } catch (ParseException e) { 1.739 - e.printStackTrace(); 1.740 - } 1.741 - 1.742 - return Result; 1.743 - } 1.744 - 1.745 - /** 1.746 - * marks the android event as already handled 1.747 - * @return 1.748 - * @see AndroidEvent#cInternalTag 1.749 - * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) 1.750 - * @throws RemoteException 1.751 - */ 1.752 + // LAST-MODIFIED 1.753 + //na 1.754 + 1.755 + // SEQUENCE 1.756 + //na 1.757 + 1.758 + // DTSTART 1.759 + long lngStart = this.ContentValues.getAsLong(Events.DTSTART); 1.760 + String strTZStart = this.ContentValues.getAsString(Events.EVENT_TIMEZONE); 1.761 + boolean allDay = this.ContentValues.getAsBoolean(Events.ALL_DAY); 1.762 + if (lngStart > 0) { 1.763 + DtStart dtStart = new DtStart(); 1.764 + if (allDay) { 1.765 + Date dateStart = new Date(); 1.766 + dateStart.setTime(lngStart); 1.767 + dtStart.setDate(dateStart); 1.768 + } else { 1.769 + DateTime datetimeStart = new DateTime(); 1.770 + datetimeStart.setTime(lngStart); 1.771 + dtStart.setDate(datetimeStart); 1.772 + 1.773 + timeZone = registry.getTimeZone(strTZStart); 1.774 + if (timeZone == null) { 1.775 + java.util.TimeZone systemTimeZone = TimeZone.getTimeZone(strTZStart); 1.776 + if (systemTimeZone == null) { 1.777 + systemTimeZone = TimeZone.getDefault(); 1.778 + } 1.779 + timeZone = registry.getTimeZone(systemTimeZone.getID()); 1.780 + } 1.781 + dtStart.setTimeZone(timeZone); 1.782 + 1.783 + // no timezone information for allDay events 1.784 + mCalendar.getComponents().add(timeZone.getVTimeZone()); 1.785 + } 1.786 + propEvent.add(dtStart); 1.787 + } 1.788 + 1.789 + // DTEND 1.790 + long lngEnd = this.ContentValues.getAsLong(Events.DTEND); 1.791 + String strTZEnd = this.ContentValues.getAsString(Events.EVENT_END_TIMEZONE); 1.792 + if (strTZEnd == null) 1.793 + strTZEnd = strTZStart; 1.794 + if (lngEnd > 0) { 1.795 + DtEnd dtEnd = new DtEnd(); 1.796 + if (allDay) { 1.797 + Date dateEnd = new Date(); 1.798 + dateEnd.setTime(lngEnd); 1.799 + dtEnd.setDate(dateEnd); 1.800 + } else { 1.801 + DateTime datetimeEnd = new DateTime(); 1.802 + datetimeEnd.setTime(lngEnd); 1.803 + dtEnd.setDate(datetimeEnd); 1.804 + if (strTZEnd != null) 1.805 + timeZone = registry.getTimeZone(strTZEnd); 1.806 + dtEnd.setTimeZone(timeZone); 1.807 + } 1.808 + propEvent.add(dtEnd); 1.809 + } 1.810 + 1.811 + // DURATION 1.812 + if (this.ContentValues.containsKey(Events.DURATION)) { 1.813 + String strDuration = this.ContentValues.getAsString(Events.DURATION); 1.814 + if (strDuration != null) { 1.815 + Duration duration = new Duration(); 1.816 + duration.setValue(strDuration); 1.817 + 1.818 + propEvent.add(duration); 1.819 + } 1.820 + } 1.821 + 1.822 + //RRULE 1.823 + if (this.ContentValues.containsKey(Events.RRULE)) { 1.824 + String strRrule = this.ContentValues.getAsString(Events.RRULE); 1.825 + if (strRrule != null) { 1.826 + if (!strRrule.equals("")) { 1.827 + RRule rrule = new RRule(); 1.828 + rrule.setValue(strRrule); 1.829 + propEvent.add(rrule); 1.830 + } 1.831 + } 1.832 + } 1.833 + 1.834 + //RDATE 1.835 + if (this.ContentValues.containsKey(Events.RDATE)) { 1.836 + String strRdate = this.ContentValues.getAsString(Events.RDATE); 1.837 + if (strRdate != null) { 1.838 + if (!strRdate.equals("")) { 1.839 + RDate rdate = new RDate(); 1.840 + rdate.setValue(strRdate); 1.841 + propEvent.add(rdate); 1.842 + } 1.843 + } 1.844 + } 1.845 + 1.846 + //EXRULE 1.847 + if (this.ContentValues.containsKey(Events.EXRULE)) { 1.848 + String strExrule = this.ContentValues.getAsString(Events.EXRULE); 1.849 + if (strExrule != null) { 1.850 + if (!strExrule.equals("")) { 1.851 + ExRule exrule = new ExRule(); 1.852 + exrule.setValue(strExrule); 1.853 + propEvent.add(exrule); 1.854 + } 1.855 + } 1.856 + } 1.857 + 1.858 + //EXDATE 1.859 + if (this.ContentValues.containsKey(Events.EXDATE)) { 1.860 + String strExdate = this.ContentValues.getAsString(Events.EXDATE); 1.861 + if (strExdate != null) { 1.862 + if (!strExdate.equals("")) { 1.863 + ExDate exdate = new ExDate(); 1.864 + exdate.setValue(strExdate); 1.865 + propEvent.add(exdate); 1.866 + } 1.867 + } 1.868 + } 1.869 + 1.870 + //SUMMARY 1.871 + if (this.ContentValues.containsKey(Events.TITLE)) { 1.872 + String strTitle = this.ContentValues.getAsString(Events.TITLE); 1.873 + if (strTitle != null) { 1.874 + Summary summary = new Summary(strTitle); 1.875 + propEvent.add(summary); 1.876 + } 1.877 + } 1.878 + 1.879 + //DESCIPTION 1.880 + if (this.ContentValues.containsKey(Events.DESCRIPTION)) { 1.881 + String strDescription = this.ContentValues.getAsString(Events.DESCRIPTION); 1.882 + if (strDescription != null) { 1.883 + if (!strDescription.equals("")) { 1.884 + Description description = new Description(strDescription); 1.885 + propEvent.add(description); 1.886 + } 1.887 + } 1.888 + } 1.889 + 1.890 + //LOCATION 1.891 + if (this.ContentValues.containsKey(Events.EVENT_LOCATION)) { 1.892 + String strLocation = this.ContentValues.getAsString(Events.EVENT_LOCATION); 1.893 + if (strLocation != null) { 1.894 + if (!strLocation.equals("")) { 1.895 + Location location = new Location(strLocation); 1.896 + propEvent.add(location); 1.897 + } 1.898 + } 1.899 + } 1.900 + 1.901 + //CLASS / ACCESS_LEVEL 1.902 + if (this.ContentValues.containsKey(Events.ACCESS_LEVEL)) { 1.903 + int accessLevel = this.ContentValues.getAsInteger(Events.ACCESS_LEVEL); 1.904 + Clazz clazz = new Clazz(); 1.905 + if (accessLevel == Events.ACCESS_PUBLIC) 1.906 + clazz.setValue(Clazz.PUBLIC.getValue()); 1.907 + else if (accessLevel == Events.ACCESS_PRIVATE) 1.908 + clazz.setValue(Clazz.PRIVATE.getValue()); 1.909 + else if (accessLevel == Events.ACCESS_CONFIDENTIAL) 1.910 + clazz.setValue(Clazz.CONFIDENTIAL.getValue()); 1.911 + else 1.912 + clazz.setValue(Clazz.PUBLIC.getValue()); 1.913 + 1.914 + propEvent.add(clazz); 1.915 + } 1.916 + 1.917 + //STATUS 1.918 + if (this.ContentValues.containsKey(Events.STATUS)) { 1.919 + int intStatus = this.ContentValues.getAsInteger(Events.STATUS); 1.920 + if (intStatus > -1) { 1.921 + Status status = new Status(); 1.922 + if (intStatus == Events.STATUS_CANCELED) 1.923 + status.setValue(Status.VEVENT_CANCELLED.getValue()); 1.924 + else if (intStatus == Events.STATUS_CONFIRMED) 1.925 + status.setValue(Status.VEVENT_CONFIRMED.getValue()); 1.926 + else if (intStatus == Events.STATUS_TENTATIVE) 1.927 + status.setValue(Status.VEVENT_TENTATIVE.getValue()); 1.928 + 1.929 + propEvent.add(status); 1.930 + } 1.931 + } 1.932 + 1.933 + //UID 1.934 + Uid uid = new Uid(strUid); 1.935 + propEvent.add(uid); 1.936 + 1.937 + // Attendees 1.938 + if (mAttendees.size() > 0) { 1.939 + for (Object objProp : mAttendees) { 1.940 + Property prop = (Property) objProp; 1.941 + propEvent.add(prop); 1.942 + } 1.943 + } 1.944 + 1.945 + // Reminders 1.946 + if (mReminders.size() > 0) { 1.947 + for (Object objComp : mReminders) { 1.948 + Component com = (Component) objComp; 1.949 + event.getAlarms().add(com); 1.950 + } 1.951 + } 1.952 + 1.953 + } catch (ParseException e) { 1.954 + e.printStackTrace(); 1.955 + } 1.956 + 1.957 + return Result; 1.958 + } 1.959 + 1.960 + /** 1.961 + * marks the android event as already handled 1.962 + * @return 1.963 + * @see AndroidEvent#cInternalTag 1.964 + * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) 1.965 + * @throws RemoteException 1.966 + */ 1.967 /* public boolean tagAndroidEvent() throws RemoteException { 1.968 1.969 ContentValues values = new ContentValues();