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