47 import android.os.RemoteException; |
31 import android.os.RemoteException; |
48 import android.provider.CalendarContract.Calendars; |
32 import android.provider.CalendarContract.Calendars; |
49 import android.provider.CalendarContract.Events; |
33 import android.provider.CalendarContract.Events; |
50 import android.util.Log; |
34 import android.util.Log; |
51 |
35 |
|
36 import org.apache.http.client.ClientProtocolException; |
|
37 import org.gege.caldavsyncadapter.CalendarColors; |
|
38 import org.gege.caldavsyncadapter.Event; |
|
39 import org.gege.caldavsyncadapter.android.entities.AndroidEvent; |
|
40 import org.gege.caldavsyncadapter.caldav.CaldavFacade; |
|
41 import org.gege.caldavsyncadapter.syncadapter.SyncAdapter; |
|
42 import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; |
|
43 import org.xml.sax.SAXException; |
|
44 |
|
45 import java.io.IOException; |
|
46 import java.net.URI; |
|
47 import java.net.URISyntaxException; |
|
48 import java.util.ArrayList; |
|
49 import java.util.regex.Matcher; |
|
50 import java.util.regex.Pattern; |
|
51 |
|
52 import javax.xml.parsers.ParserConfigurationException; |
|
53 |
52 public class DavCalendar { |
54 public class DavCalendar { |
53 public enum CalendarSource { |
55 public enum CalendarSource { |
54 undefined, Android, CalDAV |
56 undefined, Android, CalDAV |
55 } |
57 } |
56 |
58 |
57 private static final String TAG = "Calendar"; |
59 private static final String TAG = "Calendar"; |
58 |
60 |
59 /** |
61 /** |
60 * stores the CTAG of a calendar |
62 * stores the CTAG of a calendar |
61 */ |
63 */ |
62 public static String CTAG = Calendars.CAL_SYNC1; |
64 public static String CTAG = Calendars.CAL_SYNC1; |
63 |
65 |
64 /** |
66 /** |
65 * stores the URI of a calendar |
67 * stores the URI of a calendar |
66 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname |
68 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname |
67 */ |
69 */ |
68 public static String URI = Calendars._SYNC_ID; |
70 public static String URI = Calendars._SYNC_ID; |
69 |
71 |
70 public static String SERVERURL = Calendars.CAL_SYNC2; |
72 public static String SERVERURL = Calendars.CAL_SYNC2; |
71 |
73 |
72 private String strCalendarColor = ""; |
74 private String strCalendarColor = ""; |
73 |
75 |
74 private ArrayList<Uri> mNotifyList = new ArrayList<Uri>(); |
76 private ArrayList<Uri> mNotifyList = new ArrayList<Uri>(); |
75 |
77 |
76 /** |
78 /** |
77 * the event transformed into ContentValues |
79 * the event transformed into ContentValues |
78 */ |
80 */ |
79 public ContentValues ContentValues = new ContentValues(); |
81 public ContentValues ContentValues = new ContentValues(); |
80 |
82 |
81 private Account mAccount = null; |
83 private Account mAccount = null; |
82 private ContentProviderClient mProvider = null; |
84 private ContentProviderClient mProvider = null; |
83 |
85 |
84 public boolean foundServerSide = false; |
86 public boolean foundServerSide = false; |
85 public boolean foundClientSide = false; |
87 public boolean foundClientSide = false; |
86 public CalendarSource Source = CalendarSource.undefined; |
88 public CalendarSource Source = CalendarSource.undefined; |
87 |
89 |
88 public String ServerUrl = ""; |
90 public String ServerUrl = ""; |
89 |
91 |
90 private ArrayList<CalendarEvent> mCalendarEvents = new ArrayList<CalendarEvent>(); |
92 private ArrayList<CalendarEvent> mCalendarEvents = new ArrayList<CalendarEvent>(); |
91 |
93 |
92 private int mTagCounter = 1; |
94 private int mTagCounter = 1; |
93 |
95 |
94 /** |
96 /** |
95 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname |
97 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname |
96 */ |
98 */ |
97 public URI getURI() { |
99 public URI getURI() { |
98 String strUri = this.getContentValueAsString(DavCalendar.URI); |
100 String strUri = this.getContentValueAsString(DavCalendar.URI); |
99 URI result = null; |
101 URI result = null; |
100 try { |
102 try { |
101 result = new URI(strUri); |
103 result = new URI(strUri); |
102 } catch (URISyntaxException e) { |
104 } catch (URISyntaxException e) { |
103 e.printStackTrace(); |
105 e.printStackTrace(); |
104 } |
106 } |
105 return result; |
107 return result; |
106 } |
108 } |
107 |
109 |
108 /** |
110 /** |
109 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname |
111 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname |
110 */ |
112 */ |
111 public void setURI(URI uri) { |
113 public void setURI(URI uri) { |
112 this.setContentValueAsString(DavCalendar.URI, uri.toString()); |
114 this.setContentValueAsString(DavCalendar.URI, uri.toString()); |
113 } |
115 } |
114 |
116 |
115 /** |
117 /** |
116 * example: Cleartext Display Name |
118 * example: Cleartext Display Name |
117 */ |
119 */ |
118 public String getCalendarDisplayName() { |
120 public String getCalendarDisplayName() { |
119 return this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME); |
121 return this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME); |
120 } |
122 } |
121 |
123 |
122 /** |
124 /** |
123 * example: Cleartext Display Name |
125 * example: Cleartext Display Name |
124 */ |
126 */ |
125 public void setCalendarDisplayName(String displayName) { |
127 public void setCalendarDisplayName(String displayName) { |
126 this.setContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME, displayName); |
128 this.setContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME, displayName); |
127 } |
129 } |
128 |
130 |
129 |
131 |
130 /** |
132 /** |
131 * example: 1143 |
133 * example: 1143 |
132 */ |
134 */ |
133 public void setCTag(String cTag, boolean Update) { |
135 public void setCTag(String cTag, boolean Update) { |
134 this.setContentValueAsString(DavCalendar.CTAG, cTag); |
136 this.setContentValueAsString(DavCalendar.CTAG, cTag); |
135 if (Update) { |
137 if (Update) { |
136 //serverCalendar.updateAndroidCalendar(androidCalendarUri, Calendar.CTAG, serverCalendar.getcTag()); |
138 //serverCalendar.updateAndroidCalendar(androidCalendarUri, Calendar.CTAG, serverCalendar.getcTag()); |
137 try { |
139 try { |
138 this.updateAndroidCalendar(this.getAndroidCalendarUri(), CTAG, cTag); |
140 this.updateAndroidCalendar(this.getAndroidCalendarUri(), CTAG, cTag); |
139 } catch (RemoteException e) { |
141 } catch (RemoteException e) { |
140 e.printStackTrace(); |
142 e.printStackTrace(); |
141 } |
143 } |
142 } |
144 } |
143 } |
145 } |
144 |
146 |
145 /** |
147 /** |
146 * example: 1143 |
148 * example: 1143 |
147 */ |
149 */ |
148 public String getcTag() { |
150 public String getcTag() { |
149 return this.getContentValueAsString(DavCalendar.CTAG); |
151 return this.getContentValueAsString(DavCalendar.CTAG); |
150 } |
152 } |
151 |
153 |
152 /** |
154 /** |
153 * example: #FFCCAA |
155 * example: #FFCCAA |
154 */ |
156 */ |
155 public void setCalendarColorAsString(String color) { |
157 public void setCalendarColorAsString(String color) { |
156 int maxlen = 6; |
158 int maxlen = 6; |
157 |
159 |
158 this.strCalendarColor = color; |
160 this.strCalendarColor = color; |
159 if (!color.equals("")) { |
161 if (!color.equals("")) { |
160 String strColor = color.replace("#", ""); |
162 String strColor = color.replace("#", ""); |
161 if (strColor.length() > maxlen) |
163 if (strColor.length() > maxlen) |
162 strColor = strColor.substring(0, maxlen); |
164 strColor = strColor.substring(0, maxlen); |
163 int intColor = Integer.parseInt(strColor, 16); |
165 int intColor = Integer.parseInt(strColor, 16); |
164 this.setContentValueAsInt(Calendars.CALENDAR_COLOR, intColor); |
166 this.setContentValueAsInt(Calendars.CALENDAR_COLOR, intColor); |
165 } |
167 } |
166 } |
168 } |
167 |
169 |
168 /** |
170 /** |
169 * example: #FFCCAA |
171 * example: #FFCCAA |
170 */ |
172 */ |
171 public String getCalendarColorAsString() { |
173 public String getCalendarColorAsString() { |
172 return this.strCalendarColor; |
174 return this.strCalendarColor; |
173 } |
175 } |
174 |
176 |
175 /** |
177 /** |
176 * example 12345 |
178 * example 12345 |
177 */ |
179 */ |
178 public int getCalendarColor() { |
180 public int getCalendarColor() { |
179 return this.getContentValueAsInt(Calendars.CALENDAR_COLOR); |
181 return this.getContentValueAsInt(Calendars.CALENDAR_COLOR); |
180 } |
182 } |
181 |
183 |
182 /** |
184 /** |
183 * example 12345 |
185 * example 12345 |
184 */ |
186 */ |
185 public void setCalendarColor(int color) { |
187 public void setCalendarColor(int color) { |
186 this.setContentValueAsInt(Calendars.CALENDAR_COLOR, color); |
188 this.setContentValueAsInt(Calendars.CALENDAR_COLOR, color); |
187 } |
189 } |
188 |
190 |
189 /** |
191 /** |
190 * example: |
192 * example: |
191 * should be: calendarname |
193 * should be: calendarname |
192 * but is: http://caldav.example.com/calendarserver.php/calendars/username/calendarname/ |
194 * but is: http://caldav.example.com/calendarserver.php/calendars/username/calendarname/ |
193 */ |
195 */ |
194 public String getCalendarName() { |
196 public String getCalendarName() { |
195 return this.getContentValueAsString(Calendars.NAME); |
197 return this.getContentValueAsString(Calendars.NAME); |
196 } |
198 } |
197 |
199 |
198 /** |
200 /** |
199 * example: |
201 * example: |
200 * should be: calendarname |
202 * should be: calendarname |
201 * but is: http://caldav.example.com/calendarserver.php/calendars/username/calendarname/ |
203 * but is: http://caldav.example.com/calendarserver.php/calendars/username/calendarname/ |
202 */ |
204 */ |
203 public void setCalendarName(String calendarName) { |
205 public void setCalendarName(String calendarName) { |
204 this.setContentValueAsString(Calendars.NAME, calendarName); |
206 this.setContentValueAsString(Calendars.NAME, calendarName); |
205 } |
207 } |
206 |
208 |
207 /** |
209 /** |
208 * example: 8 |
210 * example: 8 |
209 */ |
211 */ |
210 public int getAndroidCalendarId() { |
212 public int getAndroidCalendarId() { |
211 return this.getContentValueAsInt(Calendars._ID); |
213 return this.getContentValueAsInt(Calendars._ID); |
212 } |
214 } |
213 |
215 |
214 /** |
216 /** |
215 * example: 8 |
217 * example: 8 |
216 */ |
218 */ |
217 public void setAndroidCalendarId(int androidCalendarId) { |
219 public void setAndroidCalendarId(int androidCalendarId) { |
218 this.setContentValueAsInt(Calendars._ID, androidCalendarId); |
220 this.setContentValueAsInt(Calendars._ID, androidCalendarId); |
219 } |
221 } |
220 |
222 |
221 /** |
223 /** |
222 * example: content://com.android.calendar/calendars/8 |
224 * example: content://com.android.calendar/calendars/8 |
223 */ |
225 */ |
224 public Uri getAndroidCalendarUri() { |
226 public Uri getAndroidCalendarUri() { |
225 return ContentUris.withAppendedId(Calendars.CONTENT_URI, this.getAndroidCalendarId()); |
227 return ContentUris.withAppendedId(Calendars.CONTENT_URI, this.getAndroidCalendarId()); |
226 } |
228 } |
227 |
229 |
228 /** |
230 /** |
229 * empty constructor |
231 * empty constructor |
230 */ |
232 */ |
231 public DavCalendar(CalendarSource source) { |
233 public DavCalendar(CalendarSource source) { |
232 this.Source = source; |
234 this.Source = source; |
233 } |
235 } |
234 |
236 |
235 /** |
237 /** |
236 * creates an new instance from a cursor |
238 * creates an new instance from a cursor |
237 * @param cur must be a cursor from "ContentProviderClient" with Uri Calendars.CONTENT_URI |
239 * |
238 */ |
240 * @param cur must be a cursor from "ContentProviderClient" with Uri Calendars.CONTENT_URI |
239 public DavCalendar(Account account, ContentProviderClient provider, Cursor cur, CalendarSource source, String serverUrl) { |
241 */ |
240 this.mAccount = account; |
242 public DavCalendar(Account account, ContentProviderClient provider, Cursor cur, CalendarSource source, String serverUrl) { |
241 this.mProvider = provider; |
243 this.mAccount = account; |
242 this.foundClientSide = true; |
244 this.mProvider = provider; |
243 this.Source = source; |
245 this.foundClientSide = true; |
244 this.ServerUrl = serverUrl; |
246 this.Source = source; |
245 |
247 this.ServerUrl = serverUrl; |
246 String strSyncID = cur.getString(cur.getColumnIndex(Calendars._SYNC_ID)); |
248 |
247 String strName = cur.getString(cur.getColumnIndex(Calendars.NAME)); |
249 String strSyncID = cur.getString(cur.getColumnIndex(Calendars._SYNC_ID)); |
248 String strDisplayName = cur.getString(cur.getColumnIndex(Calendars.CALENDAR_DISPLAY_NAME)); |
250 String strName = cur.getString(cur.getColumnIndex(Calendars.NAME)); |
249 String strCTAG = cur.getString(cur.getColumnIndex(DavCalendar.CTAG)); |
251 String strDisplayName = cur.getString(cur.getColumnIndex(Calendars.CALENDAR_DISPLAY_NAME)); |
250 String strServerUrl = cur.getString(cur.getColumnIndex(DavCalendar.SERVERURL)); |
252 String strCTAG = cur.getString(cur.getColumnIndex(DavCalendar.CTAG)); |
251 int intAndroidCalendarId = cur.getInt(cur.getColumnIndex(Calendars._ID)); |
253 String strServerUrl = cur.getString(cur.getColumnIndex(DavCalendar.SERVERURL)); |
252 |
254 String strCalendarColor = cur.getString(cur.getColumnIndex(Calendars.CALENDAR_COLOR)); |
253 this.setCalendarName(strName); |
255 int intAndroidCalendarId = cur.getInt(cur.getColumnIndex(Calendars._ID)); |
254 this.setCalendarDisplayName(strDisplayName); |
256 |
255 this.setCTag(strCTAG, false); |
257 this.setCalendarName(strName); |
256 this.setAndroidCalendarId(intAndroidCalendarId); |
258 this.setCalendarDisplayName(strDisplayName); |
257 |
259 this.setCTag(strCTAG, false); |
258 if (strSyncID == null) { |
260 this.setAndroidCalendarId(intAndroidCalendarId); |
259 this.correctSyncID(strName); |
261 this.setCalendarColor(Integer.parseInt(strCalendarColor)); |
260 strSyncID = strName; |
262 |
261 } |
263 if (strSyncID == null) { |
262 if (strServerUrl == null) { |
264 this.correctSyncID(strName); |
263 this.correctServerUrl(serverUrl); |
265 strSyncID = strName; |
264 } |
266 } |
265 URI uri = null; |
267 if (strServerUrl == null) { |
266 try { |
268 this.correctServerUrl(serverUrl); |
267 uri = new URI(strSyncID); |
269 } |
268 } catch (URISyntaxException e) { |
270 URI uri = null; |
269 e.printStackTrace(); |
271 try { |
270 } |
272 uri = new URI(strSyncID); |
271 this.setURI(uri); |
273 } catch (URISyntaxException e) { |
272 } |
274 e.printStackTrace(); |
273 |
275 } |
274 /** |
276 this.setURI(uri); |
275 * checks a given list of android calendars for a specific android calendar. |
277 } |
276 * this calendar should be a server calendar as it is searched for. |
278 |
277 * if the calendar is not found, it will be created. |
279 /** |
278 * @param androidCalList the list of android calendars |
280 * checks a given list of android calendars for a specific android calendar. |
279 * @param context |
281 * this calendar should be a server calendar as it is searched for. |
280 * @return the found android calendar or null of fails |
282 * if the calendar is not found, it will be created. |
281 * @throws RemoteException |
283 * |
282 */ |
284 * @param androidCalList the list of android calendars |
283 public Uri checkAndroidCalendarList(CalendarList androidCalList, android.content.Context context) throws RemoteException { |
285 * @param context |
284 Uri androidCalendarUri = null; |
286 * @return the found android calendar or null of fails |
285 boolean isCalendarExist = false; |
287 * @throws RemoteException |
286 |
288 */ |
287 DavCalendar androidCalendar = androidCalList.getCalendarByURI(this.getURI()); |
289 public Uri checkAndroidCalendarList(CalendarList androidCalList, android.content.Context context) throws RemoteException { |
288 if (androidCalendar != null) { |
290 Uri androidCalendarUri = null; |
289 isCalendarExist = true; |
291 boolean isCalendarExist = false; |
290 androidCalendar.foundServerSide = true; |
292 |
291 } |
293 DavCalendar androidCalendar = androidCalList.getCalendarByURI(this.getURI()); |
292 |
294 if (androidCalendar != null) { |
293 |
295 isCalendarExist = true; |
294 if (!isCalendarExist) { |
296 androidCalendar.foundServerSide = true; |
295 DavCalendar newCal = this.createNewAndroidCalendar(this, androidCalList.getCalendarList().size(), context); |
297 } |
296 if (newCal != null) { |
298 |
297 androidCalList.addCalendar(newCal); |
299 |
298 androidCalendarUri = newCal.getAndroidCalendarUri(); |
300 if (!isCalendarExist) { |
299 } |
301 DavCalendar newCal = this.createNewAndroidCalendar(this, androidCalList.getCalendarList() |
300 } else { |
302 .size(), context); |
301 androidCalendarUri = androidCalendar.getAndroidCalendarUri(); |
303 if (newCal != null) { |
302 if (!this.getCalendarColorAsString().equals("")) { |
304 androidCalList.addCalendar(newCal); |
303 //serverCalendar.updateCalendarColor(returnedCalendarUri, serverCalendar); |
305 androidCalendarUri = newCal.getAndroidCalendarUri(); |
304 this.updateAndroidCalendar(androidCalendarUri, Calendars.CALENDAR_COLOR, this.getCalendarColor()); |
306 } |
305 } |
307 } else { |
306 if ((this.ContentValues.containsKey(Calendars.CALENDAR_DISPLAY_NAME)) && |
308 androidCalendarUri = androidCalendar.getAndroidCalendarUri(); |
307 (androidCalendar.ContentValues.containsKey(Calendars.CALENDAR_DISPLAY_NAME))) { |
309 if (!this.getCalendarColorAsString().equals("")) { |
308 String serverDisplayName = this.ContentValues.getAsString(Calendars.CALENDAR_DISPLAY_NAME); |
310 this.updateAndroidCalendar(androidCalendarUri, Calendars.CALENDAR_COLOR, getColorAsHex(this.getCalendarColorAsString())); |
309 String clientDisplayName = androidCalendar.ContentValues.getAsString(Calendars.CALENDAR_DISPLAY_NAME); |
311 } |
310 if (!serverDisplayName.equals(clientDisplayName)) |
312 if ((this.ContentValues.containsKey(Calendars.CALENDAR_DISPLAY_NAME)) && |
311 this.updateAndroidCalendar(androidCalendarUri, Calendars.CALENDAR_DISPLAY_NAME, serverDisplayName); |
313 (androidCalendar.ContentValues.containsKey(Calendars.CALENDAR_DISPLAY_NAME))) { |
312 } |
314 String serverDisplayName = this.ContentValues.getAsString(Calendars.CALENDAR_DISPLAY_NAME); |
313 } |
315 String clientDisplayName = androidCalendar.ContentValues.getAsString(Calendars.CALENDAR_DISPLAY_NAME); |
314 |
316 if (!serverDisplayName.equals(clientDisplayName)) |
315 return androidCalendarUri; |
317 this.updateAndroidCalendar(androidCalendarUri, Calendars.CALENDAR_DISPLAY_NAME, serverDisplayName); |
316 } |
318 } |
317 |
319 } |
318 /** |
320 |
319 * COMPAT: the calendar Uri was stored as calendar Name. this function updates the URI (_SYNC_ID) |
321 return androidCalendarUri; |
320 * @param calendarUri the real calendarUri |
322 } |
321 * @return success of this function |
323 |
322 */ |
324 /** |
323 private boolean correctSyncID(String calendarUri) { |
325 * COMPAT: the calendar Uri was stored as calendar Name. this function updates the URI (_SYNC_ID) |
324 boolean Result = false; |
326 * |
325 Log.v(TAG, "correcting SyncID for calendar:" + this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME)); |
327 * @param calendarUri the real calendarUri |
326 |
328 * @return success of this function |
327 ContentValues mUpdateValues = new ContentValues(); |
329 */ |
328 mUpdateValues.put(DavCalendar.URI, calendarUri); |
330 private boolean correctSyncID(String calendarUri) { |
329 |
331 boolean Result = false; |
330 try { |
332 Log.v(TAG, "correcting SyncID for calendar:" + this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME)); |
331 mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null); |
333 |
332 Result = true; |
334 ContentValues mUpdateValues = new ContentValues(); |
333 } catch (RemoteException e) { |
335 mUpdateValues.put(DavCalendar.URI, calendarUri); |
334 e.printStackTrace(); |
336 |
335 } |
337 try { |
336 |
338 mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null); |
337 return Result; |
339 Result = true; |
338 } |
340 } catch (RemoteException e) { |
339 |
341 e.printStackTrace(); |
340 /** |
342 } |
341 * COMPAT: the serverurl (CAL_SYNC2) was not sored within a calendar. this fixes it. (see #98) |
343 |
342 * @param serverUrl the current serverurl |
344 return Result; |
343 * @return success of this function |
345 } |
344 */ |
346 |
345 private boolean correctServerUrl(String serverUrl) { |
347 /** |
346 boolean Result = false; |
348 * COMPAT: the serverurl (CAL_SYNC2) was not sored within a calendar. this fixes it. (see #98) |
347 Log.v(TAG, "correcting ServerUrl for calendar:" + this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME)); |
349 * |
348 |
350 * @param serverUrl the current serverurl |
349 ContentValues mUpdateValues = new ContentValues(); |
351 * @return success of this function |
350 mUpdateValues.put(DavCalendar.SERVERURL, serverUrl); |
352 */ |
351 |
353 private boolean correctServerUrl(String serverUrl) { |
352 try { |
354 boolean Result = false; |
353 mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null); |
355 Log.v(TAG, "correcting ServerUrl for calendar:" + this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME)); |
354 Result = true; |
356 |
355 } catch (RemoteException e) { |
357 ContentValues mUpdateValues = new ContentValues(); |
356 e.printStackTrace(); |
358 mUpdateValues.put(DavCalendar.SERVERURL, serverUrl); |
357 } |
359 |
358 |
360 try { |
359 return Result; |
361 mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null); |
360 } |
362 Result = true; |
361 |
363 } catch (RemoteException e) { |
362 /** |
364 e.printStackTrace(); |
363 * creates a new androidCalendar |
365 } |
364 * @param serverCalendar |
366 |
365 * @param index |
367 return Result; |
366 * @param context |
368 } |
367 * @return the new androidCalendar or null if fails |
369 |
368 */ |
370 /** |
369 private DavCalendar createNewAndroidCalendar(DavCalendar serverCalendar, int index, android.content.Context context) { |
371 * creates a new androidCalendar |
370 Uri newUri = null; |
372 * |
371 DavCalendar Result = null; |
373 * @param serverCalendar |
372 |
374 * @param index |
373 final ContentValues contentValues = new ContentValues(); |
375 * @param context |
374 contentValues.put(DavCalendar.URI, serverCalendar.getURI().toString()); |
376 * @return the new androidCalendar or null if fails |
375 contentValues.put(DavCalendar.SERVERURL, this.ServerUrl); |
377 */ |
376 |
378 private DavCalendar createNewAndroidCalendar(DavCalendar serverCalendar, int index, android.content.Context context) { |
377 contentValues.put(Calendars.VISIBLE, 1); |
379 Uri newUri = null; |
378 contentValues.put(Calendars.CALENDAR_DISPLAY_NAME, serverCalendar.getCalendarDisplayName()); |
380 DavCalendar Result = null; |
379 contentValues.put(Calendars.ACCOUNT_NAME, mAccount.name); |
381 |
380 contentValues.put(Calendars.ACCOUNT_TYPE, mAccount.type); |
382 final ContentValues contentValues = new ContentValues(); |
381 contentValues.put(Calendars.OWNER_ACCOUNT, mAccount.name); |
383 contentValues.put(DavCalendar.URI, serverCalendar.getURI().toString()); |
382 contentValues.put(Calendars.SYNC_EVENTS, 1); |
384 contentValues.put(DavCalendar.SERVERURL, this.ServerUrl); |
383 contentValues.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER); |
385 |
384 |
386 contentValues.put(Calendars.VISIBLE, 1); |
385 if (!serverCalendar.getCalendarColorAsString().equals("")) { |
387 contentValues.put(Calendars.CALENDAR_DISPLAY_NAME, serverCalendar.getCalendarDisplayName()); |
386 contentValues.put(Calendars.CALENDAR_COLOR, serverCalendar.getCalendarColor()); |
388 contentValues.put(Calendars.ACCOUNT_NAME, mAccount.name); |
387 } else { |
389 contentValues.put(Calendars.ACCOUNT_TYPE, mAccount.type); |
388 // find a color |
390 contentValues.put(Calendars.OWNER_ACCOUNT, mAccount.name); |
389 //int index = mList.size(); |
391 contentValues.put(Calendars.SYNC_EVENTS, 1); |
390 index = index % CalendarColors.colors.length; |
392 contentValues.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER); |
391 contentValues.put(Calendars.CALENDAR_COLOR, CalendarColors.colors[index]); |
393 |
392 } |
394 String calendarColorAsString = serverCalendar.getCalendarColorAsString(); |
393 |
395 if (!calendarColorAsString.isEmpty()) { |
394 try { |
396 int color = getColorAsHex(calendarColorAsString); |
395 newUri = mProvider.insert(asSyncAdapter(Calendars.CONTENT_URI, mAccount.name, mAccount.type), contentValues); |
397 contentValues.put(Calendars.CALENDAR_COLOR, color); |
396 } catch (RemoteException e) { |
398 } else { |
397 e.printStackTrace(); |
399 // find a color |
398 } |
400 //int index = mList.size(); |
399 |
401 index = index % CalendarColors.colors.length; |
400 // it is possible that this calendar already exists but the provider failed to find it within isCalendarExist() |
402 contentValues.put(Calendars.CALENDAR_COLOR, CalendarColors.colors[2]); |
401 // the adapter would try to create a new calendar but the provider fails again to create a new calendar. |
403 } |
402 if (newUri != null) { |
404 |
403 long newCalendarId = ContentUris.parseId(newUri); |
405 try { |
404 |
406 newUri = mProvider.insert(asSyncAdapter(Calendars.CONTENT_URI, mAccount.name, mAccount.type), contentValues); |
405 Cursor cur = null; |
407 } catch (RemoteException e) { |
406 Uri uri = Calendars.CONTENT_URI; |
408 e.printStackTrace(); |
407 String selection = "(" + Calendars._ID + " = ?)"; |
409 } |
408 String[] selectionArgs = new String[] {String.valueOf(newCalendarId)}; |
410 |
409 |
411 // it is possible that this calendar already exists but the provider failed to find it within isCalendarExist() |
410 // Submit the query and get a Cursor object back. |
412 // the adapter would try to create a new calendar but the provider fails again to create a new calendar. |
411 try { |
413 if (newUri != null) { |
412 cur = mProvider.query(uri, null, selection, selectionArgs, null); |
414 long newCalendarId = ContentUris.parseId(newUri); |
413 } catch (RemoteException e) { |
415 |
414 e.printStackTrace(); |
416 Cursor cur = null; |
415 } |
417 Uri uri = Calendars.CONTENT_URI; |
416 |
418 String selection = "(" + Calendars._ID + " = ?)"; |
417 if (cur != null) { |
419 String[] selectionArgs = new String[]{String.valueOf(newCalendarId)}; |
418 while (cur.moveToNext()) { |
420 |
419 Result = new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl); |
421 // Submit the query and get a Cursor object back. |
420 Result.foundServerSide = true; |
422 try { |
421 } |
423 cur = mProvider.query(uri, null, selection, selectionArgs, null); |
422 cur.close(); |
424 } catch (RemoteException e) { |
423 //if (Result != null) |
425 e.printStackTrace(); |
424 // this.mList.add(Result); |
426 } |
425 } |
427 |
426 Log.i(TAG, "New calendar created : URI=" + Result.getAndroidCalendarUri()); |
428 if (cur != null) { |
427 NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "new calendar found: " + Result.getCalendarDisplayName()); |
429 while (cur.moveToNext()) { |
428 mNotifyList.add(Result.getAndroidCalendarUri()); |
430 Result = new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl); |
429 } |
431 Result.foundServerSide = true; |
430 |
432 } |
431 return Result; |
433 cur.close(); |
432 } |
434 //if (Result != null) |
433 |
435 // this.mList.add(Result); |
434 /** |
436 } |
435 * there is no corresponding calendar on server side. time to delete this calendar on android side. |
437 Log.i(TAG, "New calendar created : URI=" + Result.getAndroidCalendarUri()); |
436 * @return |
438 NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "new calendar found: " + Result |
437 */ |
439 .getCalendarDisplayName()); |
438 public boolean deleteAndroidCalendar() { |
440 mNotifyList.add(Result.getAndroidCalendarUri()); |
439 boolean Result = false; |
441 } |
440 |
442 |
441 String mSelectionClause = "(" + Calendars._ID + " = ?)"; |
443 return Result; |
442 int calendarId = this.getAndroidCalendarId(); |
444 } |
443 String[] mSelectionArgs = {Long.toString(calendarId)}; |
445 |
444 |
446 private int getColorAsHex(String calendarColorAsString) { |
445 int CountDeleted = 0; |
447 int color = 0x0000FF00; |
446 try { |
448 Pattern p = Pattern.compile("#?(\\p{XDigit}{6})(\\p{XDigit}{2})?"); |
447 CountDeleted = mProvider.delete(this.SyncAdapter(), mSelectionClause, mSelectionArgs); |
449 Matcher m = p.matcher(calendarColorAsString); |
448 Log.i(TAG,"Calendar deleted: " + String.valueOf(calendarId)); |
450 if (m.find()) { |
449 this.mNotifyList.add(this.getAndroidCalendarUri()); |
451 int color_rgb = Integer.parseInt(m.group(1), 16); |
450 Result = true; |
452 int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF; |
451 } catch (RemoteException e) { |
453 color = (color_alpha << 24) | color_rgb; |
452 e.printStackTrace(); |
454 } |
453 } |
455 return color; |
454 Log.d(TAG, "Android Calendars deleted: " + Integer.toString(CountDeleted)); |
456 } |
455 |
457 |
456 return Result; |
458 /** |
457 } |
459 * there is no corresponding calendar on server side. time to delete this calendar on android side. |
458 |
460 * |
459 /** |
461 * @return |
460 * updates the android calendar |
462 */ |
461 * @param calendarUri the uri of the androidCalendar |
463 public boolean deleteAndroidCalendar() { |
462 * @param target must be from android.provider.CalendarContract.Calendars |
464 boolean Result = false; |
463 * @param value the new value for the target |
465 |
464 * @throws RemoteException |
466 String mSelectionClause = "(" + Calendars._ID + " = ?)"; |
465 */ |
467 int calendarId = this.getAndroidCalendarId(); |
466 private void updateAndroidCalendar(Uri calendarUri, String target, int value) throws RemoteException { |
468 String[] mSelectionArgs = {Long.toString(calendarId)}; |
467 ContentValues mUpdateValues = new ContentValues(); |
469 |
468 mUpdateValues.put(target, value); |
470 int CountDeleted = 0; |
469 |
471 try { |
470 mProvider.update(asSyncAdapter(calendarUri, mAccount.name, mAccount.type), mUpdateValues, null, null); |
472 CountDeleted = mProvider.delete(this.SyncAdapter(), mSelectionClause, mSelectionArgs); |
471 } |
473 Log.i(TAG, "Calendar deleted: " + String.valueOf(calendarId)); |
472 |
474 this.mNotifyList.add(this.getAndroidCalendarUri()); |
473 /** |
475 Result = true; |
474 * updates the android calendar |
476 } catch (RemoteException e) { |
475 * @param calendarUri the uri of the androidCalendar |
477 e.printStackTrace(); |
476 * @param target must be from android.provider.CalendarContract.Calendars |
478 } |
477 * @param value the new value for the target |
479 Log.d(TAG, "Android Calendars deleted: " + Integer.toString(CountDeleted)); |
478 * @throws RemoteException |
480 |
479 */ |
481 return Result; |
480 private void updateAndroidCalendar(Uri calendarUri, String target, String value) throws RemoteException { |
482 } |
481 ContentValues mUpdateValues = new ContentValues(); |
483 |
482 mUpdateValues.put(target, value); |
484 /** |
483 |
485 * updates the android calendar |
484 mProvider.update(asSyncAdapter(calendarUri, mAccount.name, mAccount.type), mUpdateValues, null, null); |
486 * |
485 } |
487 * @param calendarUri the uri of the androidCalendar |
486 |
488 * @param target must be from android.provider.CalendarContract.Calendars |
487 /** |
489 * @param value the new value for the target |
488 * marks the android event as already handled |
490 * @throws RemoteException |
489 * @return |
491 */ |
490 * @see AndroidEvent#cInternalTag |
492 private void updateAndroidCalendar(Uri calendarUri, String target, int value) throws RemoteException { |
491 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) |
493 ContentValues mUpdateValues = new ContentValues(); |
492 * @throws RemoteException |
494 mUpdateValues.put(target, value); |
493 */ |
495 |
494 public boolean tagAndroidEvent(AndroidEvent androidEvent) throws RemoteException { |
496 mProvider.update(asSyncAdapter(calendarUri, mAccount.name, mAccount.type), mUpdateValues, null, null); |
495 boolean Result = false; |
497 } |
496 |
498 |
497 ContentValues values = new ContentValues(); |
499 /** |
498 //values.put(Event.INTERNALTAG, 1); |
500 * updates the android calendar |
499 values.put(Event.INTERNALTAG, mTagCounter); |
501 * |
500 //values.put(Event.INTERNALTAG, String.valueOf(mTagCounter)); |
502 * @param calendarUri the uri of the androidCalendar |
501 |
503 * @param target must be from android.provider.CalendarContract.Calendars |
502 int RowCount = this.mProvider.update(asSyncAdapter(androidEvent.getUri(), this.mAccount.name, this.mAccount.type), values, null, null); |
504 * @param value the new value for the target |
503 //Log.v(TAG,"event tag nr: " + String.valueOf(mTagCounter)); |
505 * @throws RemoteException |
504 //Log.v(TAG,"Rows updated: " + String.valueOf(RowCount)); |
506 */ |
505 |
507 private void updateAndroidCalendar(Uri calendarUri, String target, String value) throws RemoteException { |
506 if (RowCount == 1) { |
508 ContentValues mUpdateValues = new ContentValues(); |
507 Result = true; |
509 mUpdateValues.put(target, value); |
508 mTagCounter += 1; |
510 |
509 } else { |
511 mProvider.update(asSyncAdapter(calendarUri, mAccount.name, mAccount.type), mUpdateValues, null, null); |
510 Log.v(TAG,"EVENT NOT TAGGED!"); |
512 } |
511 } |
513 |
512 |
514 /** |
513 return Result; |
515 * marks the android event as already handled |
514 } |
516 * |
515 |
517 * @return |
516 /** |
518 * @throws RemoteException |
517 * removes the tag of all android events |
519 * @see AndroidEvent#cInternalTag |
518 * @return |
520 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) |
519 * @see AndroidEvent#cInternalTag |
521 */ |
520 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) |
522 public boolean tagAndroidEvent(AndroidEvent androidEvent) throws RemoteException { |
521 * @throws RemoteException |
523 boolean Result = false; |
522 */ |
524 |
523 public int untagAndroidEvents() throws RemoteException { |
525 ContentValues values = new ContentValues(); |
524 int RowCount = 0; |
526 //values.put(Event.INTERNALTAG, 1); |
525 int Steps = 100; |
527 values.put(Event.INTERNALTAG, mTagCounter); |
526 ContentValues values = new ContentValues(); |
528 //values.put(Event.INTERNALTAG, String.valueOf(mTagCounter)); |
527 values.put(Event.INTERNALTAG, 0); |
529 |
528 |
530 int RowCount = this.mProvider.update(asSyncAdapter(androidEvent.getUri(), this.mAccount.name, this.mAccount.type), values, null, null); |
529 for (int i=1; i < this.mTagCounter; i = i + Steps) { |
531 //Log.v(TAG,"event tag nr: " + String.valueOf(mTagCounter)); |
530 String mSelectionClause = "(CAST(" + Event.INTERNALTAG + " AS INT) >= ?) AND (CAST(" + Event.INTERNALTAG + " AS INT) < ?) AND (" + Events.CALENDAR_ID + " = ?)"; |
532 //Log.v(TAG,"Rows updated: " + String.valueOf(RowCount)); |
531 String[] mSelectionArgs = {String.valueOf(i), String.valueOf(i + Steps), Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))}; |
533 |
532 RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs); |
534 if (RowCount == 1) { |
533 } |
535 Result = true; |
534 /*String mSelectionClause = "(" + Event.INTERNALTAG + " > ?) AND (" + Events.CALENDAR_ID + " = ?)"; |
536 mTagCounter += 1; |
535 String[] mSelectionArgs = {"0", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))}; |
537 } else { |
|
538 Log.v(TAG, "EVENT NOT TAGGED!"); |
|
539 } |
|
540 |
|
541 return Result; |
|
542 } |
|
543 |
|
544 /** |
|
545 * removes the tag of all android events |
|
546 * |
|
547 * @return |
|
548 * @throws RemoteException |
|
549 * @see AndroidEvent#cInternalTag |
|
550 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) |
|
551 */ |
|
552 public int untagAndroidEvents() throws RemoteException { |
|
553 int RowCount = 0; |
|
554 int Steps = 100; |
|
555 ContentValues values = new ContentValues(); |
|
556 values.put(Event.INTERNALTAG, 0); |
|
557 |
|
558 for (int i = 1; i < this.mTagCounter; i = i + Steps) { |
|
559 String mSelectionClause = "(CAST(" + Event.INTERNALTAG + " AS INT) >= ?) AND (CAST(" + Event.INTERNALTAG + " AS INT) < ?) AND (" + Events.CALENDAR_ID + " = ?)"; |
|
560 String[] mSelectionArgs = {String.valueOf(i), String.valueOf(i + Steps), Long.toString(ContentUris |
|
561 .parseId(this.getAndroidCalendarUri()))}; |
|
562 RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs); |
|
563 } |
|
564 /*String mSelectionClause = "(" + Event.INTERNALTAG + " > ?) AND (" + Events.CALENDAR_ID + " = ?)"; |
|
565 String[] mSelectionArgs = {"0", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))}; |
536 RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs);*/ |
566 RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs);*/ |
537 |
567 |
538 //Log.d(TAG, "Rows reseted: " + RowCount.toString()); |
568 //Log.d(TAG, "Rows reseted: " + RowCount.toString()); |
539 return RowCount; |
569 return RowCount; |
540 } |
570 } |
541 /** |
571 |
542 * Events not being tagged are for deletion |
572 /** |
543 * @return |
573 * Events not being tagged are for deletion |
544 * @see AndroidEvent#cInternalTag |
574 * |
545 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) |
575 * @return |
546 * @throws RemoteException |
576 * @throws RemoteException |
547 */ |
577 * @see AndroidEvent#cInternalTag |
548 public int deleteUntaggedEvents() throws RemoteException { |
578 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats) |
549 String mSelectionClause = "(" + Event.INTERNALTAG + " < ?) AND (" + Events.CALENDAR_ID + " = ?)"; |
579 */ |
550 String[] mSelectionArgs = {"1", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))}; |
580 public int deleteUntaggedEvents() throws RemoteException { |
551 |
581 String mSelectionClause = "(" + Event.INTERNALTAG + " < ?) AND (" + Events.CALENDAR_ID + " = ?)"; |
552 int CountDeleted = this.mProvider.delete(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), mSelectionClause, mSelectionArgs); |
582 String[] mSelectionArgs = {"1", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))}; |
553 //Log.d(TAG, "Rows deleted: " + CountDeleted.toString()); |
583 |
554 return CountDeleted; |
584 int CountDeleted = this.mProvider.delete(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), mSelectionClause, mSelectionArgs); |
555 } |
585 //Log.d(TAG, "Rows deleted: " + CountDeleted.toString()); |
556 |
586 return CountDeleted; |
557 private Uri SyncAdapterCalendar() { |
587 } |
558 return asSyncAdapter(this.getAndroidCalendarUri(), mAccount.name, mAccount.type); |
588 |
559 } |
589 private Uri SyncAdapterCalendar() { |
560 private Uri SyncAdapter() { |
590 return asSyncAdapter(this.getAndroidCalendarUri(), mAccount.name, mAccount.type); |
561 return asSyncAdapter(Calendars.CONTENT_URI, mAccount.name, mAccount.type); |
591 } |
562 } |
592 |
563 private static Uri asSyncAdapter(Uri uri, String account, String accountType) { |
593 private Uri SyncAdapter() { |
564 return uri.buildUpon() |
594 return asSyncAdapter(Calendars.CONTENT_URI, mAccount.name, mAccount.type); |
565 .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true") |
595 } |
566 .appendQueryParameter(Calendars.ACCOUNT_NAME, account) |
596 |
567 .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build(); |
597 private static Uri asSyncAdapter(Uri uri, String account, String accountType) { |
568 } |
598 return uri.buildUpon() |
569 |
599 .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER, "true") |
570 public void setAccount(Account account) { |
600 .appendQueryParameter(Calendars.ACCOUNT_NAME, account) |
571 this.mAccount = account; |
601 .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build(); |
572 } |
602 } |
573 public void setProvider(ContentProviderClient provider) { |
603 |
574 this.mProvider = provider; |
604 public void setAccount(Account account) { |
575 } |
605 this.mAccount = account; |
576 |
606 } |
577 /** |
607 |
578 * general access function to ContentValues |
608 public void setProvider(ContentProviderClient provider) { |
579 * @param Item the item name from Calendars.* |
609 this.mProvider = provider; |
580 * @return the value for the item |
610 } |
581 */ |
611 |
582 private String getContentValueAsString(String Item) { |
612 /** |
583 String Result = ""; |
613 * general access function to ContentValues |
584 if (this.ContentValues.containsKey(Item)) |
614 * |
585 Result = this.ContentValues.getAsString(Item); |
615 * @param Item the item name from Calendars.* |
586 return Result; |
616 * @return the value for the item |
587 } |
617 */ |
588 /** |
618 private String getContentValueAsString(String Item) { |
589 * general access function to ContentValues |
619 String Result = ""; |
590 * @param Item the item name from Calendars.* |
620 if (this.ContentValues.containsKey(Item)) |
591 * @return the value for the item |
621 Result = this.ContentValues.getAsString(Item); |
592 */ |
622 return Result; |
593 private int getContentValueAsInt(String Item) { |
623 } |
594 int Result = 0; |
624 |
595 if (this.ContentValues.containsKey(Item)) |
625 /** |
596 Result = this.ContentValues.getAsInteger(Item); |
626 * general access function to ContentValues |
597 return Result; |
627 * |
598 } |
628 * @param Item the item name from Calendars.* |
599 |
629 * @return the value for the item |
600 /** |
630 */ |
601 * general access function to ContentValues |
631 private int getContentValueAsInt(String Item) { |
602 * @param Item the item name from Calendars.* |
632 int Result = 0; |
603 * @param Value the value for the item |
633 if (this.ContentValues.containsKey(Item)) |
604 * @return success of this function |
634 Result = this.ContentValues.getAsInteger(Item); |
605 */ |
635 return Result; |
606 private boolean setContentValueAsString(String Item, String Value) { |
636 } |
607 boolean Result = false; |
637 |
608 |
638 /** |
609 if (this.ContentValues.containsKey(Item)) |
639 * general access function to ContentValues |
610 this.ContentValues.remove(Item); |
640 * |
611 this.ContentValues.put(Item, Value); |
641 * @param Item the item name from Calendars.* |
612 |
642 * @param Value the value for the item |
613 return Result; |
643 * @return success of this function |
614 } |
644 */ |
615 |
645 private boolean setContentValueAsString(String Item, String Value) { |
616 /** |
646 boolean Result = false; |
617 * general access function to ContentValues |
647 |
618 * @param Item the item name from Calendars.* |
648 if (this.ContentValues.containsKey(Item)) |
619 * @param Value the value for the item |
649 this.ContentValues.remove(Item); |
620 * @return success of this function |
650 this.ContentValues.put(Item, Value); |
621 */ |
651 |
622 private boolean setContentValueAsInt(String Item, int Value) { |
652 return Result; |
623 boolean Result = false; |
653 } |
624 |
654 |
625 if (this.ContentValues.containsKey(Item)) |
655 /** |
626 this.ContentValues.remove(Item); |
656 * general access function to ContentValues |
627 this.ContentValues.put(Item, Value); |
657 * |
628 |
658 * @param Item the item name from Calendars.* |
629 return Result; |
659 * @param Value the value for the item |
630 } |
660 * @return success of this function |
631 |
661 */ |
632 public ArrayList<Uri> getNotifyList() { |
662 private boolean setContentValueAsInt(String Item, int Value) { |
633 return this.mNotifyList; |
663 boolean Result = false; |
634 } |
664 |
635 |
665 if (this.ContentValues.containsKey(Item)) |
636 public ArrayList<CalendarEvent> getCalendarEvents() { |
666 this.ContentValues.remove(Item); |
637 return this.mCalendarEvents; |
667 this.ContentValues.put(Item, Value); |
638 } |
668 |
639 |
669 return Result; |
640 public boolean readCalendarEvents(CaldavFacade facade) { |
670 } |
641 boolean Result = false; |
671 |
642 |
672 public ArrayList<Uri> getNotifyList() { |
643 try { |
673 return this.mNotifyList; |
644 this.mCalendarEvents = facade.getCalendarEvents(this); |
674 } |
645 Result = true; |
675 |
646 } catch (ClientProtocolException e) { |
676 public ArrayList<CalendarEvent> getCalendarEvents() { |
647 e.printStackTrace(); |
677 return this.mCalendarEvents; |
648 Result = false; |
678 } |
649 } catch (URISyntaxException e) { |
679 |
650 e.printStackTrace(); |
680 public boolean readCalendarEvents(CaldavFacade facade) { |
651 Result = false; |
681 boolean Result = false; |
652 } catch (IOException e) { |
682 |
653 e.printStackTrace(); |
683 try { |
654 Result = false; |
684 this.mCalendarEvents = facade.getCalendarEvents(this); |
655 } catch (ParserConfigurationException e) { |
685 Result = true; |
656 e.printStackTrace(); |
686 } catch (ClientProtocolException e) { |
657 Result = false; |
687 e.printStackTrace(); |
658 } catch (SAXException e) { |
688 Result = false; |
659 e.printStackTrace(); |
689 } catch (URISyntaxException e) { |
660 Result = false; |
690 e.printStackTrace(); |
661 } |
691 Result = false; |
662 |
692 } catch (IOException e) { |
663 return Result; |
693 e.printStackTrace(); |
664 } |
694 Result = false; |
665 |
695 } catch (ParserConfigurationException e) { |
|
696 e.printStackTrace(); |
|
697 Result = false; |
|
698 } catch (SAXException e) { |
|
699 e.printStackTrace(); |
|
700 Result = false; |
|
701 } |
|
702 |
|
703 return Result; |
|
704 } |
|
705 |
666 } |
706 } |