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