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

Sat, 14 Feb 2015 21:21:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 14 Feb 2015 21:21:19 +0100
changeset 30
842945e5b782
parent 17
b9ad6f933bc9
permissions
-rw-r--r--

Correct import and other build configuration to use assertions.

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

mercurial