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

Tue, 10 Feb 2015 22:55:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 22:55:00 +0100
changeset 10
262b0d479a96
parent 8
ec8af0e3fbc2
child 17
b9ad6f933bc9
child 21
af4693956263
permissions
-rw-r--r--

Port to VAlarm class behaviour of upgraded ical4j version 1.0.6.

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

mercurial