src/org/gege/caldavsyncadapter/android/entities/AndroidEvent.java

Tue, 10 Feb 2015 18:12:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 18:12:00 +0100
changeset 0
fb9019fb1bf7
child 8
ec8af0e3fbc2
permissions
-rw-r--r--

Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.

michael@0 1 /**
michael@0 2 * Copyright (c) 2012-2013, Gerald Garcia, Timo Berger
michael@0 3 *
michael@0 4 * This file is part of Andoid Caldav Sync Adapter Free.
michael@0 5 *
michael@0 6 * Andoid Caldav Sync Adapter Free is free software: you can redistribute
michael@0 7 * it and/or modify it under the terms of the GNU General Public License
michael@0 8 * as published by the Free Software Foundation, either version 3 of the
michael@0 9 * License, or at your option any later version.
michael@0 10 *
michael@0 11 * Andoid Caldav Sync Adapter Free is distributed in the hope that
michael@0 12 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
michael@0 13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
michael@0 14 * GNU General Public License for more details.
michael@0 15 *
michael@0 16 * You should have received a copy of the GNU General Public License
michael@0 17 * along with Andoid Caldav Sync Adapter Free.
michael@0 18 * If not, see <http://www.gnu.org/licenses/>.
michael@0 19 *
michael@0 20 */
michael@0 21
michael@0 22 package org.gege.caldavsyncadapter.android.entities;
michael@0 23
michael@0 24 import java.net.URISyntaxException;
michael@0 25 import java.text.ParseException;
michael@0 26 import net.fortuna.ical4j.model.Calendar;
michael@0 27 import net.fortuna.ical4j.model.Component;
michael@0 28 import net.fortuna.ical4j.model.ComponentList;
michael@0 29 import net.fortuna.ical4j.model.Date;
michael@0 30 import net.fortuna.ical4j.model.DateTime;
michael@0 31 import net.fortuna.ical4j.model.Dur;
michael@0 32 import net.fortuna.ical4j.model.ParameterList;
michael@0 33 import net.fortuna.ical4j.model.Property;
michael@0 34 import net.fortuna.ical4j.model.PropertyList;
michael@0 35 import net.fortuna.ical4j.model.TimeZone;
michael@0 36 import net.fortuna.ical4j.model.TimeZoneRegistry;
michael@0 37 import net.fortuna.ical4j.model.TimeZoneRegistryFactory;
michael@0 38 import net.fortuna.ical4j.model.component.VAlarm;
michael@0 39 import net.fortuna.ical4j.model.component.VEvent;
michael@0 40 import net.fortuna.ical4j.model.parameter.Cn;
michael@0 41 import net.fortuna.ical4j.model.parameter.PartStat;
michael@0 42 import net.fortuna.ical4j.model.parameter.Role;
michael@0 43 import net.fortuna.ical4j.model.parameter.Rsvp;
michael@0 44 import net.fortuna.ical4j.model.parameter.Value;
michael@0 45 import net.fortuna.ical4j.model.property.Action;
michael@0 46 import net.fortuna.ical4j.model.property.Attendee;
michael@0 47 import net.fortuna.ical4j.model.property.CalScale;
michael@0 48 import net.fortuna.ical4j.model.property.Clazz;
michael@0 49 import net.fortuna.ical4j.model.property.Description;
michael@0 50 import net.fortuna.ical4j.model.property.DtEnd;
michael@0 51 import net.fortuna.ical4j.model.property.DtStart;
michael@0 52 import net.fortuna.ical4j.model.property.Duration;
michael@0 53 import net.fortuna.ical4j.model.property.ExDate;
michael@0 54 import net.fortuna.ical4j.model.property.ExRule;
michael@0 55 import net.fortuna.ical4j.model.property.Location;
michael@0 56 import net.fortuna.ical4j.model.property.Organizer;
michael@0 57 import net.fortuna.ical4j.model.property.ProdId;
michael@0 58 import net.fortuna.ical4j.model.property.RDate;
michael@0 59 import net.fortuna.ical4j.model.property.RRule;
michael@0 60 import net.fortuna.ical4j.model.property.Status;
michael@0 61 import net.fortuna.ical4j.model.property.Summary;
michael@0 62 import net.fortuna.ical4j.model.property.Trigger;
michael@0 63 import net.fortuna.ical4j.model.property.Uid;
michael@0 64 import net.fortuna.ical4j.model.property.Version;
michael@0 65 //import android.accounts.Account;
michael@0 66 //import android.content.ContentProviderClient;
michael@0 67 //import android.content.ContentValues;
michael@0 68 //import android.content.SyncStats;
michael@0 69 import android.database.Cursor;
michael@0 70 import android.net.Uri;
michael@0 71 //import android.os.RemoteException;
michael@0 72 import android.provider.CalendarContract.Attendees;
michael@0 73 //import android.provider.CalendarContract.Calendars;
michael@0 74 import android.provider.CalendarContract.Events;
michael@0 75 import android.provider.CalendarContract.Reminders;
michael@0 76
michael@0 77 //import org.gege.caldavsyncadapter.Event;
michael@0 78 //import org.gege.caldavsyncadapter.caldav.CaldavFacade;
michael@0 79 import org.gege.caldavsyncadapter.caldav.entities.CalendarEvent;
michael@0 80 //import org.gege.caldavsyncadapter.caldav.entities.DavCalendar;
michael@0 81 //import org.gege.caldavsyncadapter.syncadapter.SyncAdapter;
michael@0 82
michael@0 83 public class AndroidEvent extends org.gege.caldavsyncadapter.Event {
michael@0 84
michael@0 85 private Uri muri;
michael@0 86
michael@0 87 private Uri mAndroidCalendarUri;
michael@0 88
michael@0 89 /**
michael@0 90 * the list of attendees
michael@0 91 */
michael@0 92 private PropertyList mAttendees = new PropertyList();
michael@0 93
michael@0 94 /**
michael@0 95 * the list of reminders
michael@0 96 */
michael@0 97 private ComponentList mReminders = new ComponentList();
michael@0 98
michael@0 99 private Calendar mCalendar = null;
michael@0 100
michael@0 101 /* private Account mAccount = null;
michael@0 102 private ContentProviderClient mProvider = null;*/
michael@0 103
michael@0 104 //public AndroidEvent(Account account, ContentProviderClient provider, Uri uri, Uri calendarUri) {
michael@0 105 public AndroidEvent(Uri uri, Uri calendarUri) {
michael@0 106 super();
michael@0 107 this.setUri(uri);
michael@0 108 /* this.mAccount = account;
michael@0 109 this.mProvider = provider;*/
michael@0 110 //this.setCounterpartUri(calendarUri);
michael@0 111 mAndroidCalendarUri = calendarUri;
michael@0 112 }
michael@0 113
michael@0 114 public Calendar getIcsEvent() {
michael@0 115 return mCalendar;
michael@0 116 }
michael@0 117
michael@0 118 public String getETag() {
michael@0 119 String Result = "";
michael@0 120 if (this.ContentValues.containsKey(ETAG))
michael@0 121 Result = this.ContentValues.getAsString(ETAG);
michael@0 122 return Result;
michael@0 123 }
michael@0 124
michael@0 125 public void setETag(String eTag) {
michael@0 126 this.ContentValues.put(ETAG, eTag);
michael@0 127 }
michael@0 128
michael@0 129 public Uri getUri() {
michael@0 130 return muri;
michael@0 131 }
michael@0 132
michael@0 133 public void setUri(Uri uri) {
michael@0 134 this.muri = uri;
michael@0 135 }
michael@0 136
michael@0 137 public Uri getAndroidCalendarUri() {
michael@0 138 return mAndroidCalendarUri;
michael@0 139 }
michael@0 140
michael@0 141 @Override
michael@0 142 public String toString() {
michael@0 143 return this.getUri().toString();
michael@0 144 }
michael@0 145
michael@0 146 /**
michael@0 147 * reads an android event from a given cursor into {@link AndroidEvent#ContentValues}
michael@0 148 * @param cur the cursor with the event
michael@0 149 * @return success of this funtion
michael@0 150 * @see AndroidEvent#ContentValues
michael@0 151 */
michael@0 152 public boolean readContentValues(Cursor cur) {
michael@0 153 this.setETag(cur.getString(cur.getColumnIndex(ETAG)));
michael@0 154
michael@0 155 this.ContentValues.put(Events.EVENT_TIMEZONE, cur.getString(cur.getColumnIndex(Events.EVENT_TIMEZONE)));
michael@0 156 this.ContentValues.put(Events.EVENT_END_TIMEZONE, cur.getString(cur.getColumnIndex(Events.EVENT_END_TIMEZONE)));
michael@0 157 this.ContentValues.put(Events.DTSTART, cur.getLong(cur.getColumnIndex(Events.DTSTART)));
michael@0 158 this.ContentValues.put(Events.DTEND, cur.getLong(cur.getColumnIndex(Events.DTEND)));
michael@0 159 this.ContentValues.put(Events.ALL_DAY, cur.getLong(cur.getColumnIndex(Events.ALL_DAY)));
michael@0 160 this.ContentValues.put(Events.TITLE, cur.getString(cur.getColumnIndex(Events.TITLE)));
michael@0 161 this.ContentValues.put(Events.CALENDAR_ID, cur.getString(cur.getColumnIndex(Events.CALENDAR_ID)));
michael@0 162 this.ContentValues.put(Events._SYNC_ID, cur.getString(cur.getColumnIndex(Events._SYNC_ID)));
michael@0 163 //this.ContentValues.put(Events.SYNC_DATA1, cur.getString(cur.getColumnIndex(Events.SYNC_DATA1))); //not needed here, eTag has already been read
michael@0 164 this.ContentValues.put(Events.DESCRIPTION, cur.getString(cur.getColumnIndex(Events.DESCRIPTION)));
michael@0 165 this.ContentValues.put(Events.EVENT_LOCATION, cur.getString(cur.getColumnIndex(Events.EVENT_LOCATION)));
michael@0 166 this.ContentValues.put(Events.ACCESS_LEVEL, cur.getInt(cur.getColumnIndex(Events.ACCESS_LEVEL)));
michael@0 167
michael@0 168 this.ContentValues.put(Events.STATUS, cur.getInt(cur.getColumnIndex(Events.STATUS)));
michael@0 169
michael@0 170 this.ContentValues.put(Events.LAST_DATE, cur.getInt(cur.getColumnIndex(Events.LAST_DATE)));
michael@0 171 this.ContentValues.put(Events.DURATION, cur.getString(cur.getColumnIndex(Events.DURATION)));
michael@0 172
michael@0 173 this.ContentValues.put(Events.RDATE, cur.getString(cur.getColumnIndex(Events.RDATE)));
michael@0 174 this.ContentValues.put(Events.RRULE, cur.getString(cur.getColumnIndex(Events.RRULE)));
michael@0 175 this.ContentValues.put(Events.EXRULE, cur.getString(cur.getColumnIndex(Events.EXRULE)));
michael@0 176 this.ContentValues.put(Events.EXDATE, cur.getString(cur.getColumnIndex(Events.EXDATE)));
michael@0 177 this.ContentValues.put(Events.DIRTY, cur.getInt(cur.getColumnIndex(Events.DIRTY)));
michael@0 178 this.ContentValues.put(UID, cur.getString(cur.getColumnIndex(UID)));
michael@0 179 this.ContentValues.put(RAWDATA, cur.getString(cur.getColumnIndex(RAWDATA)));
michael@0 180
michael@0 181 return true;
michael@0 182 }
michael@0 183
michael@0 184 /**
michael@0 185 * reads the attendees from a given cursor
michael@0 186 * @param cur the cursor with the attendees
michael@0 187 * @return success of this function
michael@0 188 * @see AndroidEvent#mAttendees
michael@0 189 */
michael@0 190 public boolean readAttendees(Cursor cur) {
michael@0 191 Attendee attendee = null;
michael@0 192 Organizer organizer = null;
michael@0 193 ParameterList paraList = null;
michael@0 194
michael@0 195 String Name = "";
michael@0 196 Cn cn = null;
michael@0 197
michael@0 198 String Email = "";
michael@0 199
michael@0 200 int Relationship = 0;
michael@0 201
michael@0 202
michael@0 203 int Status = 0;
michael@0 204 PartStat partstat = null;
michael@0 205
michael@0 206 int Type = 0;
michael@0 207 Role role = null;
michael@0 208
michael@0 209 try {
michael@0 210 while (cur.moveToNext()) {
michael@0 211 Name = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_NAME));
michael@0 212 Email = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_EMAIL));
michael@0 213 Relationship = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_RELATIONSHIP));
michael@0 214 Type = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_TYPE));
michael@0 215 Status = cur.getInt(cur.getColumnIndex(Attendees.ATTENDEE_STATUS));
michael@0 216
michael@0 217 if (Relationship == Attendees.RELATIONSHIP_ORGANIZER) {
michael@0 218 organizer = new Organizer();
michael@0 219 organizer.setValue("mailto:" + Email);
michael@0 220 paraList = organizer.getParameters();
michael@0 221 mAttendees.add(organizer);
michael@0 222 } else {
michael@0 223 attendee = new Attendee();
michael@0 224 attendee.setValue("mailto:" + Email);
michael@0 225 paraList = attendee.getParameters();
michael@0 226 mAttendees.add(attendee);
michael@0 227 }
michael@0 228
michael@0 229 Rsvp rsvp = new Rsvp(true);
michael@0 230 paraList.add(rsvp);
michael@0 231
michael@0 232 cn = new Cn(Name);
michael@0 233 paraList.add(cn);
michael@0 234
michael@0 235 if (Status == Attendees.ATTENDEE_STATUS_INVITED)
michael@0 236 partstat = new PartStat(PartStat.NEEDS_ACTION.getValue());
michael@0 237 else if (Status == Attendees.ATTENDEE_STATUS_ACCEPTED)
michael@0 238 partstat = new PartStat(PartStat.ACCEPTED.getValue());
michael@0 239 else if (Status == Attendees.ATTENDEE_STATUS_DECLINED)
michael@0 240 partstat = new PartStat(PartStat.DECLINED.getValue());
michael@0 241 else if (Status == Attendees.ATTENDEE_STATUS_NONE)
michael@0 242 partstat = new PartStat(PartStat.COMPLETED.getValue());
michael@0 243 else if (Status == Attendees.ATTENDEE_STATUS_TENTATIVE)
michael@0 244 partstat = new PartStat(PartStat.TENTATIVE.getValue());
michael@0 245 else
michael@0 246 partstat = new PartStat(PartStat.NEEDS_ACTION.getValue());
michael@0 247 paraList.add(partstat);
michael@0 248
michael@0 249 if (Type == Attendees.TYPE_OPTIONAL)
michael@0 250 role = new Role(Role.OPT_PARTICIPANT.getValue());
michael@0 251 else if (Type == Attendees.TYPE_NONE)
michael@0 252 role = new Role(Role.NON_PARTICIPANT.getValue()); //regular participants in android are non required?
michael@0 253 else if (Type == Attendees.TYPE_REQUIRED)
michael@0 254 role = new Role(Role.REQ_PARTICIPANT.getValue());
michael@0 255 else
michael@0 256 role = new Role(Role.NON_PARTICIPANT.getValue());
michael@0 257 paraList.add(role);
michael@0 258 }
michael@0 259
michael@0 260 } catch (URISyntaxException e) {
michael@0 261 e.printStackTrace();
michael@0 262 }
michael@0 263 return true;
michael@0 264 }
michael@0 265
michael@0 266 /**
michael@0 267 * reads the reminders from a given cursor
michael@0 268 * @param cur the cursor with the reminders
michael@0 269 * @return success of this function
michael@0 270 */
michael@0 271 public boolean readReminder(Cursor cur) {
michael@0 272 int Method;
michael@0 273 int Minutes;
michael@0 274 VAlarm reminder;
michael@0 275 while (cur.moveToNext()) {
michael@0 276 reminder = new VAlarm();
michael@0 277 Method = cur.getInt(cur.getColumnIndex(Reminders.METHOD));
michael@0 278 Minutes = cur.getInt(cur.getColumnIndex(Reminders.MINUTES)) * -1;
michael@0 279
michael@0 280
michael@0 281 Dur dur = new Dur(0, 0, Minutes, 0);
michael@0 282 Trigger tri = new Trigger(dur);
michael@0 283 Value val = new Value(Duration.DURATION);
michael@0 284 tri.getParameters().add(val);
michael@0 285 reminder.getProperties().add(tri);
michael@0 286
michael@0 287 Description desc = new Description();
michael@0 288 desc.setValue("caldavsyncadapter standard description");
michael@0 289 reminder.getProperties().add(desc);
michael@0 290
michael@0 291
michael@0 292 if (Method == Reminders.METHOD_EMAIL)
michael@0 293 reminder.getProperties().add(Action.EMAIL);
michael@0 294 else
michael@0 295 reminder.getProperties().add(Action.DISPLAY);
michael@0 296
michael@0 297 this.mReminders.add(reminder);
michael@0 298 }
michael@0 299 return true;
michael@0 300 }
michael@0 301
michael@0 302 /**
michael@0 303 * generates a new ics-file.
michael@0 304 * uses {@link AndroidEvent#ContentValues} as source.
michael@0 305 * this should only be used when a new event has been generated within android.
michael@0 306 * @param strUid the UID for this event. example: UID:e6be67c6-eff0-44f8-a1a0-6c2cb1029944-caldavsyncadapter
michael@0 307 * @return success of the function
michael@0 308 * @see CalendarEvent#fetchBody()
michael@0 309 */
michael@0 310 public boolean createIcs(String strUid) {
michael@0 311 boolean Result = false;
michael@0 312 TimeZone timezone = null;
michael@0 313 TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
michael@0 314 //TODO: do not simply create the ics-file new. take into account the RAWDATA if available
michael@0 315 /*
michael@0 316 * dtstart=1365598800000
michael@0 317 * dtend=1365602400000
michael@0 318 * eventTimezone=Europe/Berlin
michael@0 319 * eventEndTimezone=null
michael@0 320 * duration=null
michael@0 321 * allDay=0
michael@0 322 * rrule=null
michael@0 323 * rdate=null
michael@0 324 * exrule=null
michael@0 325 * exdate=null
michael@0 326 * title=Einurlner Termin
michael@0 327 * description=null
michael@0 328 * eventLocation=null
michael@0 329 * accessLevel=0
michael@0 330 * eventStatus=0
michael@0 331 *
michael@0 332 * calendar_id=4
michael@0 333 * lastDate=-197200128
michael@0 334 * sync_data1=null
michael@0 335 * _sync_id=null
michael@0 336 * dirty=1
michael@0 337 */
michael@0 338
michael@0 339 try {
michael@0 340 mCalendar = new Calendar();
michael@0 341 PropertyList propCalendar = mCalendar.getProperties();
michael@0 342 propCalendar.add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
michael@0 343 propCalendar.add(Version.VERSION_2_0);
michael@0 344 propCalendar.add(CalScale.GREGORIAN);
michael@0 345
michael@0 346 VEvent event = new VEvent();
michael@0 347 mCalendar.getComponents().add(event);
michael@0 348 PropertyList propEvent = event.getProperties();
michael@0 349
michael@0 350 // DTSTAMP -> is created by new VEvent() automatical
michael@0 351 //na
michael@0 352
michael@0 353 // CREATED
michael@0 354 //na
michael@0 355
michael@0 356 // LAST-MODIFIED
michael@0 357 //na
michael@0 358
michael@0 359 // SEQUENCE
michael@0 360 //na
michael@0 361
michael@0 362 // DTSTART
michael@0 363 long lngStart = this.ContentValues.getAsLong(Events.DTSTART);
michael@0 364 String strTZStart = this.ContentValues.getAsString(Events.EVENT_TIMEZONE);
michael@0 365 boolean allDay = this.ContentValues.getAsBoolean(Events.ALL_DAY);
michael@0 366 if (lngStart > 0) {
michael@0 367 DtStart dtStart = new DtStart();
michael@0 368 if (allDay) {
michael@0 369 Date dateStart = new Date();
michael@0 370 dateStart.setTime(lngStart);
michael@0 371 dtStart.setDate(dateStart);
michael@0 372 } else {
michael@0 373 DateTime datetimeStart = new DateTime();
michael@0 374 datetimeStart.setTime(lngStart);
michael@0 375 dtStart.setDate(datetimeStart);
michael@0 376
michael@0 377 timezone = registry.getTimeZone(strTZStart);
michael@0 378 dtStart.setTimeZone(timezone);
michael@0 379
michael@0 380 // no timezone information for allDay events
michael@0 381 mCalendar.getComponents().add(timezone.getVTimeZone());
michael@0 382 }
michael@0 383 propEvent.add(dtStart);
michael@0 384 }
michael@0 385
michael@0 386 // DTEND
michael@0 387 long lngEnd = this.ContentValues.getAsLong(Events.DTEND);
michael@0 388 String strTZEnd = this.ContentValues.getAsString(Events.EVENT_END_TIMEZONE);
michael@0 389 if (strTZEnd == null)
michael@0 390 strTZEnd = strTZStart;
michael@0 391 if (lngEnd > 0) {
michael@0 392 DtEnd dtEnd = new DtEnd();
michael@0 393 if (allDay) {
michael@0 394 Date dateEnd = new Date();
michael@0 395 dateEnd.setTime(lngEnd);
michael@0 396 dtEnd.setDate(dateEnd);
michael@0 397 } else {
michael@0 398 DateTime datetimeEnd = new DateTime();
michael@0 399 datetimeEnd.setTime(lngEnd);
michael@0 400 dtEnd.setDate(datetimeEnd);
michael@0 401 if (strTZEnd != null)
michael@0 402 timezone = registry.getTimeZone(strTZEnd);
michael@0 403 dtEnd.setTimeZone(timezone);
michael@0 404 }
michael@0 405 propEvent.add(dtEnd);
michael@0 406 }
michael@0 407
michael@0 408 // DURATION
michael@0 409 if (this.ContentValues.containsKey(Events.DURATION)) {
michael@0 410 String strDuration = this.ContentValues.getAsString(Events.DURATION);
michael@0 411 if (strDuration != null) {
michael@0 412 Duration duration = new Duration();
michael@0 413 duration.setValue(strDuration);
michael@0 414
michael@0 415 propEvent.add(duration);
michael@0 416 }
michael@0 417 }
michael@0 418
michael@0 419 //RRULE
michael@0 420 if (this.ContentValues.containsKey(Events.RRULE)) {
michael@0 421 String strRrule = this.ContentValues.getAsString(Events.RRULE);
michael@0 422 if (strRrule != null) {
michael@0 423 if (!strRrule.equals("")) {
michael@0 424 RRule rrule = new RRule();
michael@0 425 rrule.setValue(strRrule);
michael@0 426 propEvent.add(rrule);
michael@0 427 }
michael@0 428 }
michael@0 429 }
michael@0 430
michael@0 431 //RDATE
michael@0 432 if (this.ContentValues.containsKey(Events.RDATE)) {
michael@0 433 String strRdate = this.ContentValues.getAsString(Events.RDATE);
michael@0 434 if (strRdate != null) {
michael@0 435 if (!strRdate.equals("")) {
michael@0 436 RDate rdate = new RDate();
michael@0 437 rdate.setValue(strRdate);
michael@0 438 propEvent.add(rdate);
michael@0 439 }
michael@0 440 }
michael@0 441 }
michael@0 442
michael@0 443 //EXRULE
michael@0 444 if (this.ContentValues.containsKey(Events.EXRULE)) {
michael@0 445 String strExrule = this.ContentValues.getAsString(Events.EXRULE);
michael@0 446 if (strExrule != null) {
michael@0 447 if (!strExrule.equals("")) {
michael@0 448 ExRule exrule = new ExRule();
michael@0 449 exrule.setValue(strExrule);
michael@0 450 propEvent.add(exrule);
michael@0 451 }
michael@0 452 }
michael@0 453 }
michael@0 454
michael@0 455 //EXDATE
michael@0 456 if (this.ContentValues.containsKey(Events.EXDATE)) {
michael@0 457 String strExdate = this.ContentValues.getAsString(Events.EXDATE);
michael@0 458 if (strExdate != null) {
michael@0 459 if (!strExdate.equals("")) {
michael@0 460 ExDate exdate = new ExDate();
michael@0 461 exdate.setValue(strExdate);
michael@0 462 propEvent.add(exdate);
michael@0 463 }
michael@0 464 }
michael@0 465 }
michael@0 466
michael@0 467 //SUMMARY
michael@0 468 if (this.ContentValues.containsKey(Events.TITLE)) {
michael@0 469 String strTitle = this.ContentValues.getAsString(Events.TITLE);
michael@0 470 if (strTitle != null) {
michael@0 471 Summary summary = new Summary(strTitle);
michael@0 472 propEvent.add(summary);
michael@0 473 }
michael@0 474 }
michael@0 475
michael@0 476 //DESCIPTION
michael@0 477 if (this.ContentValues.containsKey(Events.DESCRIPTION)) {
michael@0 478 String strDescription = this.ContentValues.getAsString(Events.DESCRIPTION);
michael@0 479 if (strDescription != null) {
michael@0 480 if (!strDescription.equals("")) {
michael@0 481 Description description = new Description(strDescription);
michael@0 482 propEvent.add(description);
michael@0 483 }
michael@0 484 }
michael@0 485 }
michael@0 486
michael@0 487 //LOCATION
michael@0 488 if (this.ContentValues.containsKey(Events.EVENT_LOCATION)) {
michael@0 489 String strLocation = this.ContentValues.getAsString(Events.EVENT_LOCATION);
michael@0 490 if (strLocation != null) {
michael@0 491 if (!strLocation.equals("")) {
michael@0 492 Location location = new Location(strLocation);
michael@0 493 propEvent.add(location);
michael@0 494 }
michael@0 495 }
michael@0 496 }
michael@0 497
michael@0 498 //CLASS / ACCESS_LEVEL
michael@0 499 if (this.ContentValues.containsKey(Events.ACCESS_LEVEL)) {
michael@0 500 int accessLevel = this.ContentValues.getAsInteger(Events.ACCESS_LEVEL);
michael@0 501 Clazz clazz = new Clazz();
michael@0 502 if (accessLevel == Events.ACCESS_PUBLIC)
michael@0 503 clazz.setValue(Clazz.PUBLIC.getValue());
michael@0 504 else if (accessLevel == Events.ACCESS_PRIVATE)
michael@0 505 clazz.setValue(Clazz.PRIVATE.getValue());
michael@0 506 else if (accessLevel == Events.ACCESS_CONFIDENTIAL)
michael@0 507 clazz.setValue(Clazz.CONFIDENTIAL.getValue());
michael@0 508 else
michael@0 509 clazz.setValue(Clazz.PUBLIC.getValue());
michael@0 510
michael@0 511 propEvent.add(clazz);
michael@0 512 }
michael@0 513
michael@0 514 //STATUS
michael@0 515 if (this.ContentValues.containsKey(Events.STATUS)) {
michael@0 516 int intStatus = this.ContentValues.getAsInteger(Events.STATUS);
michael@0 517 if (intStatus > -1) {
michael@0 518 Status status = new Status();
michael@0 519 if (intStatus == Events.STATUS_CANCELED)
michael@0 520 status.setValue(Status.VEVENT_CANCELLED.getValue());
michael@0 521 else if (intStatus == Events.STATUS_CONFIRMED)
michael@0 522 status.setValue(Status.VEVENT_CONFIRMED.getValue());
michael@0 523 else if (intStatus == Events.STATUS_TENTATIVE)
michael@0 524 status.setValue(Status.VEVENT_TENTATIVE.getValue());
michael@0 525
michael@0 526 propEvent.add(status);
michael@0 527 }
michael@0 528 }
michael@0 529
michael@0 530 //UID
michael@0 531 Uid uid = new Uid(strUid);
michael@0 532 propEvent.add(uid);
michael@0 533
michael@0 534 // Attendees
michael@0 535 if (mAttendees.size() > 0) {
michael@0 536 for (Object objProp: mAttendees) {
michael@0 537 Property prop = (Property) objProp;
michael@0 538 propEvent.add(prop);
michael@0 539 }
michael@0 540 }
michael@0 541
michael@0 542 // Reminders
michael@0 543 if (mReminders.size() > 0) {
michael@0 544 for (Object objComp: mReminders) {
michael@0 545 Component com = (Component) objComp;
michael@0 546 event.getAlarms().add(com);
michael@0 547 }
michael@0 548 }
michael@0 549
michael@0 550 } catch (ParseException e) {
michael@0 551 e.printStackTrace();
michael@0 552 }
michael@0 553
michael@0 554 return Result;
michael@0 555 }
michael@0 556
michael@0 557 /**
michael@0 558 * marks the android event as already handled
michael@0 559 * @return
michael@0 560 * @see AndroidEvent#cInternalTag
michael@0 561 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats)
michael@0 562 * @throws RemoteException
michael@0 563 */
michael@0 564 /* public boolean tagAndroidEvent() throws RemoteException {
michael@0 565
michael@0 566 ContentValues values = new ContentValues();
michael@0 567 values.put(Event.INTERNALTAG, 1);
michael@0 568
michael@0 569 int RowCount = this.mProvider.update(asSyncAdapter(this.getUri(), this.mAccount.name, this.mAccount.type), values, null, null);
michael@0 570 //Log.e(TAG,"Rows updated: " + RowCount.toString());
michael@0 571
michael@0 572 return (RowCount == 1);
michael@0 573 }*/
michael@0 574
michael@0 575 /* private static Uri asSyncAdapter(Uri uri, String account, String accountType) {
michael@0 576 return uri.buildUpon()
michael@0 577 .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true")
michael@0 578 .appendQueryParameter(Calendars.ACCOUNT_NAME, account)
michael@0 579 .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
michael@0 580 }*/
michael@0 581 }
michael@0 582

mercurial