diff --git a/ACalDAV/AndroidManifest.xml b/ACalDAV/AndroidManifest.xml index a947472..d73ecc5 100644 --- a/ACalDAV/AndroidManifest.xml +++ b/ACalDAV/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="005" + android:versionName="0.0.5"> getComparableItems() { - java.util.ArrayList Result = new java.util.ArrayList(); - Result.add(Events.DTSTART); - Result.add(Events.DTEND); - Result.add(Events.EVENT_TIMEZONE); - Result.add(Events.EVENT_END_TIMEZONE); - Result.add(Events.ALL_DAY); - Result.add(Events.DURATION); - Result.add(Events.TITLE); - Result.add(Events.CALENDAR_ID); - Result.add(Events._SYNC_ID); - //Result.add(Events.SYNC_DATA1); - Result.add(ETAG); - Result.add(Events.DESCRIPTION); - Result.add(Events.EVENT_LOCATION); - Result.add(Events.ACCESS_LEVEL); - Result.add(Events.STATUS); - Result.add(Events.RDATE); - Result.add(Events.RRULE); - Result.add(Events.EXRULE); - Result.add(Events.EXDATE); - Result.add(UID); - - return Result; + ArrayList lcResult = new ArrayList(); + lcResult.add(Events.DTSTART); + lcResult.add(Events.DTEND); + lcResult.add(Events.EVENT_TIMEZONE); + lcResult.add(Events.EVENT_END_TIMEZONE); + lcResult.add(Events.ALL_DAY); + lcResult.add(Events.DURATION); + lcResult.add(Events.TITLE); + lcResult.add(Events.CALENDAR_ID); + lcResult.add(Events._SYNC_ID); + lcResult.add(ETAG); + lcResult.add(Events.DESCRIPTION); + lcResult.add(Events.EVENT_LOCATION); + lcResult.add(Events.ACCESS_LEVEL); + lcResult.add(Events.STATUS); + lcResult.add(Events.RDATE); + lcResult.add(Events.RRULE); + lcResult.add(Events.EXRULE); + lcResult.add(Events.EXDATE); + lcResult.add(UID); + + return lcResult; } abstract public String getETag(); @@ -104,11 +105,11 @@ public static java.util.ArrayList getComparableItems() { * @return the AndroidCalendarId for this event */ public long getAndroidCalendarId() { - long Result = -1; + long lcResult = -1; if (this.ContentValues.containsKey(Events.CALENDAR_ID)) { - Result = this.ContentValues.getAsLong(Events.CALENDAR_ID); + lcResult = this.ContentValues.getAsLong(Events.CALENDAR_ID); } - return Result; + return lcResult; } /** @@ -132,12 +133,12 @@ public void setAndroidCalendarId(long ID) { * @return the UID for this event */ public String getUID() { - String Result = ""; + String lcResult = ""; if (this.ContentValues.containsKey(UID)) { - Result = this.ContentValues.getAsString(UID); + lcResult = this.ContentValues.getAsString(UID); } - return Result; + return lcResult; } /** @@ -147,54 +148,54 @@ public String getUID() { * @return if the events are different */ public boolean checkEventValuesChanged(ContentValues calendarEventValues) { - boolean Result = false; - Object ValueAndroid = null; - Object ValueCalendar = null; - java.util.ArrayList CompareItems = Event.getComparableItems(); + boolean lcResult = false; + Object lcValueAndroid = null; + Object lcValueCalendar = null; + java.util.ArrayList lcCompareItems = Event.getComparableItems(); - for (String Key : CompareItems) { + for (String key : lcCompareItems) { - if (this.ContentValues.containsKey(Key)) { - ValueAndroid = this.ContentValues.get(Key); + if (this.ContentValues.containsKey(key)) { + lcValueAndroid = this.ContentValues.get(key); } else { - ValueAndroid = null; + lcValueAndroid = null; } - if (calendarEventValues.containsKey(Key)) { - ValueCalendar = calendarEventValues.get(Key); + if (calendarEventValues.containsKey(key)) { + lcValueCalendar = calendarEventValues.get(key); } else { - ValueCalendar = null; + lcValueCalendar = null; } /* * TODO: Sync is designed to "Server always wins", should be a general option for this adapter */ - if (ValueAndroid != null) { - if (ValueCalendar != null) { - if (!ValueAndroid.toString().equals(ValueCalendar.toString())) { - Log.d(TAG, "difference in " + Key.toString() + ":" + ValueAndroid.toString() - + " <> " + ValueCalendar.toString()); - this.ContentValues.put(Key, ValueCalendar.toString()); - Result = true; + if (lcValueAndroid != null) { + if (lcValueCalendar != null) { + if (!lcValueAndroid.toString().equals(lcValueCalendar.toString())) { + Log.d(TAG, "difference in " + key.toString() + ":" + lcValueAndroid.toString() + + " <> " + lcValueCalendar.toString()); + this.ContentValues.put(key, lcValueCalendar.toString()); + lcResult = true; } } else { - Log.d(TAG, "difference in " + Key.toString() + ":" + ValueAndroid.toString() + Log.d(TAG, "difference in " + key.toString() + ":" + lcValueAndroid.toString() + " <> null"); - this.ContentValues.putNull(Key); - Result = true; + this.ContentValues.putNull(key); + lcResult = true; } } else { - if (ValueCalendar != null) { - Log.d(TAG, "difference in " + Key.toString() + ":null <> " + ValueCalendar + if (lcValueCalendar != null) { + Log.d(TAG, "difference in " + key.toString() + ":null <> " + lcValueCalendar .toString()); - this.ContentValues.put(Key, ValueCalendar.toString()); - Result = true; + this.ContentValues.put(key, lcValueCalendar.toString()); + lcResult = true; } else { // both null -> this is ok } } } - return Result; + return lcResult; } } diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/android/entities/AndroidEvent.java b/ACalDAV/src/org/gege/caldavsyncadapter/android/entities/AndroidEvent.java index 245c63b..1807e84 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/android/entities/AndroidEvent.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/android/entities/AndroidEvent.java @@ -26,6 +26,7 @@ import android.provider.CalendarContract.Attendees; import android.provider.CalendarContract.Events; import android.provider.CalendarContract.Reminders; +import android.util.Log; import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.Component; @@ -103,16 +104,9 @@ public class AndroidEvent extends org.gege.caldavsyncadapter.Event { private Calendar mCalendar = null; -/* private Account mAccount = null; - private ContentProviderClient mProvider = null;*/ - - //public AndroidEvent(Account account, ContentProviderClient provider, Uri uri, Uri calendarUri) { public AndroidEvent(Uri uri, Uri calendarUri) { super(); this.setUri(uri); -/* this.mAccount = account; - this.mProvider = provider;*/ - //this.setCounterpartUri(calendarUri); mAndroidCalendarUri = calendarUri; } @@ -170,7 +164,6 @@ public boolean readContentValues(Cursor cur) { this.ContentValues .put(Events.CALENDAR_ID, cur.getString(cur.getColumnIndex(Events.CALENDAR_ID))); this.ContentValues.put(Events._SYNC_ID, cur.getString(cur.getColumnIndex(Events._SYNC_ID))); - //this.ContentValues.put(Events.SYNC_DATA1, cur.getString(cur.getColumnIndex(Events.SYNC_DATA1))); //not needed here, eTag has already been read this.ContentValues .put(Events.DESCRIPTION, cur.getString(cur.getColumnIndex(Events.DESCRIPTION))); this.ContentValues.put(Events.EVENT_LOCATION, @@ -274,7 +267,7 @@ public boolean readAttendees(Cursor cur) { } } catch (URISyntaxException e) { - e.printStackTrace(); + Log.e(getETag(), e.getMessage()); } return true; } @@ -329,30 +322,8 @@ public boolean createIcs(String strUid) { TimeZone timeZone = null; Thread.currentThread().setContextClassLoader(App.getContext().getClassLoader()); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); + //TODO: do not simply create the ics-file new. take into account the RAWDATA if available - /* - * dtstart=1365598800000 - * dtend=1365602400000 - * eventTimezone=Europe/Berlin - * eventEndTimezone=null - * duration=null - * allDay=0 - * rrule=null - * rdate=null - * exrule=null - * exdate=null - * title=Einurlner Termin - * description=null - * eventLocation=null - * accessLevel=0 - * eventStatus=0 - * - * calendar_id=4 - * lastDate=-197200128 - * sync_data1=null - * _sync_id=null - * dirty=1 - */ try { mCalendar = new Calendar(); @@ -365,18 +336,6 @@ public boolean createIcs(String strUid) { mCalendar.getComponents().add(event); PropertyList propEvent = event.getProperties(); - // DTSTAMP -> is created by new VEvent() automatical - //na - - // CREATED - //na - - // LAST-MODIFIED - //na - - // SEQUENCE - //na - // DTSTART long lngStart = this.ContentValues.getAsLong(Events.DTSTART); String strTZStart = this.ContentValues.getAsString(Events.EVENT_TIMEZONE); @@ -577,37 +536,10 @@ public boolean createIcs(String strUid) { } } catch (ParseException e) { - e.printStackTrace(); + Log.e(getETag(), e.getMessage()); } return result; } - - /** - * marks the android event as already handled - * - * @see AndroidEvent#cInternalTag - * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, - * DavCalendar, SyncStats) - */ -// public boolean tagAndroidEvent() throws RemoteException { -// -// ContentValues values = new ContentValues(); -// values.put(Event.INTERNALTAG, 1); -// -// int RowCount = this.mProvider -// .update(asSyncAdapter(this.getUri(), this.mAccount.name, this.mAccount.type), -// values, null, null); -// //Log.e(TAG,"Rows updated: " + RowCount.toString()); -// -// return (RowCount == 1); -// } - -/* private static Uri asSyncAdapter(Uri uri, String account, String accountType) { - return uri.buildUpon() - .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true") - .appendQueryParameter(Calendars.ACCOUNT_NAME, account) - .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build(); - }*/ } diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/CaldavFacade.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/CaldavFacade.java index c39962d..2e49ee4 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/CaldavFacade.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/CaldavFacade.java @@ -60,6 +60,9 @@ import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; +import org.gege.caldavsyncadapter.caldav.discovery.DefaultDiscoveryStrategy; +import org.gege.caldavsyncadapter.caldav.discovery.DiscoveryStrategy; +import org.gege.caldavsyncadapter.caldav.discovery.GoogleDiscoveryStrategy; import org.gege.caldavsyncadapter.caldav.entities.CalendarEvent; import org.gege.caldavsyncadapter.caldav.entities.CalendarList; import org.gege.caldavsyncadapter.caldav.entities.DavCalendar; @@ -90,6 +93,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.net.ssl.SSLException; @@ -121,12 +125,7 @@ public class CaldavFacade { private final static String PROPFIND_CALENDER_LIST = XML_VERSION + "" + "" - // + - // "" - // + - // " + "" - //" + ""; private static HttpClient httpClient; @@ -201,6 +200,12 @@ public void process(final HttpRequest request, final HttpContext context) private ContentProviderClient mProvider; + private static DiscoveryStrategy discoveryStrategy; + + private static List discoveryStrategies = Arrays.asList( + new DiscoveryStrategy[] {new GoogleDiscoveryStrategy()}); + private static DiscoveryStrategy defaultDiscoveryStrategy = new DefaultDiscoveryStrategy(); + public CaldavFacade(String mUser, String mPassword, String mURL, String trustAll) throws MalformedURLException { url = new URL(mURL); @@ -243,23 +248,21 @@ public CaldavFacade(String mUser, String mPassword, String mURL, String trustAll } } targetHost = new HttpHost(url.getHost(), port, proto); + + discoveryStrategy = resolveDiscoveryStrategy(); } - private static HttpReport createReportRequest(URI uri, String data, int depth) { - HttpReport request = new HttpReport(); - request.setURI(uri); - //request.setHeader("Host", targetHost.getHostName()); - request.setHeader("Host", - targetHost.getHostName() + ":" + String.valueOf(targetHost.getPort())); - request.setHeader("Depth", Integer.toString(depth)); - request.setHeader("Content-Type", "application/xml;charset=\"UTF-8\""); - //request.setHeader("Content-Type", "text/xml;charset=\"UTF-8\""); - try { - request.setEntity(new StringEntity(data)); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("UTF-8 is unknown"); - } - return request; + private DiscoveryStrategy resolveDiscoveryStrategy() { + for (DiscoveryStrategy ds : discoveryStrategies) { + if (ds.supportsTargetHost(targetHost)) { + return ds; + } + } + return defaultDiscoveryStrategy; + } + + private static HttpReport createReportRequest(URI uri, String data, int depth) { + return discoveryStrategy.createReportRequest(uri, data, depth, targetHost); } public static void fetchEvent_old(CalendarEvent calendarEvent) @@ -301,7 +304,6 @@ public static boolean getEvent(CalendarEvent calendarEvent) } catch (URISyntaxException e) { e.printStackTrace(); } - //request = createReportRequest(calendarEvent.getUri(), data, 1); request = createReportRequest(calendarURI, data, 1); HttpResponse response = httpClient.execute(targetHost, request); @@ -389,21 +391,18 @@ private List forceGetCalendarsFromUri(Context context, URI uri) if (context != null) { NotificationsHelper .signalSyncErrors(context, "Caldav sync problem", e.getMessage()); - //NotificationsHelper.getCurrentSyncLog().addException(e); } exception = e; } catch (FileNotFoundException e) { if (context != null) { NotificationsHelper .signalSyncErrors(context, "Caldav sync problem", e.getMessage()); - //NotificationsHelper.getCurrentSyncLog().addException(e); } throw e; } catch (IOException e) { if (context != null) { NotificationsHelper .signalSyncErrors(context, "Caldav sync problem", e.getMessage()); - //NotificationsHelper.getCurrentSyncLog().addException(e); } exception = e; } catch (CaldavProtocolException e) { @@ -411,7 +410,6 @@ private List forceGetCalendarsFromUri(Context context, URI uri) if (context != null) { NotificationsHelper .signalSyncErrors(context, "Caldav sync problem", e.getMessage()); - //NotificationsHelper.getCurrentSyncLog().addException(e); } exception = e; } @@ -511,7 +509,6 @@ private List getCalendarsFromSet(URI calendarSet) * @throws URISyntaxException url in Constructor malformed * @throws CaldavProtocolException caldav protocol error */ - //public Iterable getCalendarList(Context context) throws ClientProtocolException, public CalendarList getCalendarList(Context context) throws ClientProtocolException, IOException, URISyntaxException, ParserConfigurationException, CaldavProtocolException { @@ -520,9 +517,7 @@ public CalendarList getCalendarList(Context context) throws ClientProtocolExcept CalendarSource.CalDAV, this.url .toString() ); - List calendars = new ArrayList(); - - calendars = forceGetCalendarsFromUri(context, this.url.toURI()); + List calendars = forceGetCalendarsFromUri(context, this.url.toURI()); if (calendars.size() == 0) { // no calendars found, try the home-set @@ -544,7 +539,6 @@ public CalendarList getCalendarList(Context context) throws ClientProtocolExcept } } - //public Iterable getCalendarEvents(DavCalendar calendar) public ArrayList getCalendarEvents(DavCalendar calendar) throws URISyntaxException, ClientProtocolException, IOException, ParserConfigurationException, SAXException { @@ -559,17 +553,6 @@ public ArrayList getCalendarEvents(DavCalendar calendar) String EventUri; - /*request = new HttpPropFind(); - request.setURI(calendar.getURI()); - request.setHeader("Host", targetHost.getHostName()); - request.setHeader("Depth", "1"); - request.setHeader("Content-Type", "application/xml;charset=\"UTF-8\""); - - try { - request.setEntity(new StringEntity(requestBody, "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("UTF-8 is unknown"); - }*/ request = this.createPropFindRequest(calendar.getURI(), requestBody, 1); Log.d(TAG, "Getting eTag by PROPFIND at " + request.getURI()); @@ -598,7 +581,6 @@ public ArrayList getCalendarEvents(DavCalendar calendar) } calendarEvent.setETag(node.getTextContent().trim()); - //calendarEvent.calendarURL = this.url; calendarEvent.calendarURL = calendar.getURI().toURL(); node = node.getParentNode(); // prop @@ -627,14 +609,6 @@ public ArrayList getCalendarEvents(DavCalendar calendar) private void parseXML(HttpResponse response, ContentHandler contentHandler) throws IOException, CaldavProtocolException { InputStream is = response.getEntity().getContent(); - /*BufferedReader bReader = new BufferedReader(new InputStreamReader(is, "UTF-8")); - String Content = ""; - String Line = bReader.readLine(); - - while (Line != null) { - Content += Line; - Line = bReader.readLine(); - }*/ SAXParserFactory factory = SAXParserFactory.newInstance(); try { @@ -686,47 +660,15 @@ private void checkStatus(HttpResponse response) } private HttpPropFind createPropFindRequest(URI uri, String data, int depth) { - HttpPropFind request = new HttpPropFind(); - - request.setURI(uri); - //request.setHeader("Host", targetHost.getHostName()); - request.setHeader("Host", - targetHost.getHostName() + ":" + String.valueOf(targetHost.getPort())); - request.setHeader("Depth", Integer.toString(depth)); - request.setHeader("Content-Type", "application/xml;charset=\"UTF-8\""); - try { - request.setEntity(new StringEntity(data, "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("UTF-8 is unknown"); - } - return request; + return discoveryStrategy.createPropFindRequest(uri, data, depth, targetHost); } private HttpDelete createDeleteRequest(URI uri) { - HttpDelete request = new HttpDelete(); - request.setURI(uri); - //request.setHeader("Host", targetHost.getHostName()); - request.setHeader("Host", - targetHost.getHostName() + ":" + String.valueOf(targetHost.getPort())); - request.setHeader("Content-Type", "application/xml;charset=\"UTF-8\""); - return request; + return discoveryStrategy.createDeleteRequest(uri, targetHost); } private HttpPut createPutRequest(URI uri, String data, int depth) { - HttpPut request = new HttpPut(); - request.setURI(uri); - //request.setHeader("Host", targetHost.getHostName()); - request.setHeader("Host", - targetHost.getHostName() + ":" + String.valueOf(targetHost.getPort())); - //request.setHeader("Content-Type", "application/xml;charset=\"UTF-8\""); - request.setHeader("Content-Type", "text/calendar; charset=UTF-8"); - try { - request.setEntity(new StringEntity(data, "UTF-8")); - //request.setEntity(new StringEntity(data)); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("UTF-8 is unknown"); - } - return request; + return discoveryStrategy.createPutRequest(uri, data, depth, targetHost); } /** @@ -739,7 +681,7 @@ private HttpPut createPutRequest(URI uri, String data, int depth) { * only to update this version */ public boolean updateEvent(URI uri, String data, String ETag) { - boolean Result = false; + boolean lcResult = false; try { HttpPut request = createPutRequest(uri, data, 1); @@ -747,24 +689,24 @@ public boolean updateEvent(URI uri, String data, String ETag) { HttpResponse response = httpClient.execute(targetHost, request, mContext); checkStatus(response); if ((lastStatusCode == 200) || (lastStatusCode == 201) || (lastStatusCode == 204)) { - Result = true; + lcResult = true; } else if (lastStatusCode == 412) { //Precondition failed - Result = false; + lcResult = false; } else if (lastStatusCode == 409) { //Conflict - Result = false; + lcResult = false; } else { Log.w(TAG, "Unkown StatusCode during creation of an event"); } } catch (ClientProtocolException e) { - e.printStackTrace(); + Log.e(getLastETag(),e.getMessage()); } catch (IOException e) { - e.printStackTrace(); + Log.e(getLastETag(), e.getMessage()); } catch (AuthenticationException e) { - e.printStackTrace(); + Log.e(getLastETag(), e.getMessage()); } - return Result; + return lcResult; } /** @@ -775,7 +717,7 @@ public boolean updateEvent(URI uri, String data, String ETag) { * @return success of this function */ public boolean createEvent(URI uri, String data) { - boolean Result = false; + boolean lcResult = false; try { HttpPut request = createPutRequest(uri, data, 1); @@ -783,18 +725,18 @@ public boolean createEvent(URI uri, String data) { HttpResponse response = httpClient.execute(targetHost, request, mContext); checkStatus(response); if (lastStatusCode == 201) { - Result = true; + lcResult = true; } else { Log.w(TAG, "Unkown StatusCode during creation of an event"); } } catch (ClientProtocolException e) { - e.printStackTrace(); + Log.e(getLastETag(), e.getMessage()); } catch (IOException e) { - e.printStackTrace(); + Log.e(getLastETag(), e.getMessage()); } catch (AuthenticationException e) { - e.printStackTrace(); + Log.e(getLastETag(), e.getMessage()); } - return Result; + return lcResult; } /** @@ -807,7 +749,7 @@ public boolean createEvent(URI uri, String data) { * @return success of this function */ public boolean deleteEvent(URI calendarEventUri, String ETag) { - boolean Result = false; + boolean lcResult = false; try { HttpDelete request = createDeleteRequest(calendarEventUri); @@ -815,24 +757,24 @@ public boolean deleteEvent(URI calendarEventUri, String ETag) { HttpResponse response = httpClient.execute(targetHost, request, mContext); checkStatus(response); if ((lastStatusCode == 204) || (lastStatusCode == 200)) { - Result = true; + lcResult = true; } else { Log.w(TAG, "Unkown StatusCode during deletion of an event"); } } catch (ClientProtocolException e) { - e.printStackTrace(); + Log.e(getLastETag(),e.getMessage()); } catch (IOException e) { if (lastStatusCode == 404) { //the event has already been deleted on server side. no action needed - Result = true; + lcResult = true; } else { - e.printStackTrace(); + Log.e(getLastETag(),e.getMessage()); } } catch (AuthenticationException e) { - e.printStackTrace(); + Log.e(getLastETag(),e.getMessage()); } - return Result; + return lcResult; } /** diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/EasySSLSocketFactory.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/EasySSLSocketFactory.java index 6814a0f..b49e13a 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/EasySSLSocketFactory.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/EasySSLSocketFactory.java @@ -84,11 +84,9 @@ public X509Certificate[] getAcceptedIssuers() { this.sslcontext.init(null, tm, new SecureRandom()); this.socketfactory = this.sslcontext.getSocketFactory(); } catch (NoSuchAlgorithmException e) { - Log.e(TAG, - "Faild to instantiate TrustAllSSLSocketFactory!", e); + Log.e(this.getClass().getName(), e.getMessage()); } catch (KeyManagementException e) { - Log.e(TAG, - "Failed to instantiate TrustAllSSLSocketFactory!", e); + Log.e(this.getClass().getName(), e.getMessage()); } } @@ -100,7 +98,8 @@ public X509Certificate[] getAcceptedIssuers() { @Override public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { - SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket( + SSLSocket sslSocket; + sslSocket = (SSLSocket) this.socketfactory.createSocket( socket, host, port, autoClose); return sslSocket; } diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/DefaultDiscoveryStrategy.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/DefaultDiscoveryStrategy.java new file mode 100644 index 0000000..a546e92 --- /dev/null +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/DefaultDiscoveryStrategy.java @@ -0,0 +1,103 @@ +/** + * Copyright (c) 2012-2013, Gerald Garcia + * + * This file is part of Andoid Caldav Sync Adapter Free. + * + * Andoid Caldav Sync Adapter Free is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or at your option any later version. + * + * Andoid Caldav Sync Adapter Free is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Andoid Caldav Sync Adapter Free. + * If not, see . + * + */ +package org.gege.caldavsyncadapter.caldav.discovery; + +import java.io.UnsupportedEncodingException; +import java.net.URI; + +import org.apache.http.HttpHost; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.entity.StringEntity; +import org.gege.caldavsyncadapter.caldav.http.HttpPropFind; +import org.gege.caldavsyncadapter.caldav.http.HttpReport; + +public class DefaultDiscoveryStrategy implements DiscoveryStrategy { + + @Override + public boolean supportsTargetHost(HttpHost targetHost) { + return true; + } + + @Override + public HttpPropFind createPropFindRequest(URI uri, String data, int depth, HttpHost targetHost) { + HttpPropFind request = new HttpPropFind(); + request.setURI(uri); + try { + request.setEntity(new StringEntity(data)); + } catch (UnsupportedEncodingException e) { + throw new AssertionError("UTF-8 is unknown"); + } + + injectDefaultHeaders(request, depth, targetHost); + return request; + } + + @Override + public HttpReport createReportRequest(URI uri, String data, int depth, + HttpHost targetHost) { + HttpReport request = new HttpReport(); + request.setURI(uri); + try { + request.setEntity(new StringEntity(data)); + } catch (UnsupportedEncodingException e) { + throw new AssertionError("UTF-8 is unknown"); + } + + injectDefaultHeaders(request, depth, targetHost); + return request; + } + + private void injectDefaultHeaders(HttpUriRequest request, int depth, HttpHost targetHost) { + request.setHeader("Host", + targetHost.getHostName() + ":" + String.valueOf(targetHost.getPort())); + request.setHeader("Depth", Integer.toString(depth)); + request.setHeader("Content-Type", "application/xml;charset=\"UTF-8\""); + + } + + @Override + public HttpDelete createDeleteRequest(URI uri, HttpHost targetHost) { + HttpDelete request = new HttpDelete(); + request.setURI(uri); + injectDefaultHeaders(request, 0, targetHost); + request.removeHeaders("Depth"); + return request; + } + + @Override + public HttpPut createPutRequest(URI uri, String data, int depth, + HttpHost targetHost) { + HttpPut request = new HttpPut(); + request.setURI(uri); + injectDefaultHeaders(request, depth, targetHost); + request.removeHeaders("Depth"); + request.setHeader("Content-Type", "text/calendar; charset=utf-8"); + try { + request.setEntity(new StringEntity(data, "UTF-8")); + } catch (UnsupportedEncodingException e) { + throw new AssertionError("UTF-8 is unknown"); + } + return request; + } + +} diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/DiscoveryStrategy.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/DiscoveryStrategy.java new file mode 100644 index 0000000..3d72c05 --- /dev/null +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/DiscoveryStrategy.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2012-2013, Gerald Garcia + * + * This file is part of Andoid Caldav Sync Adapter Free. + * + * Andoid Caldav Sync Adapter Free is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or at your option any later version. + * + * Andoid Caldav Sync Adapter Free is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Andoid Caldav Sync Adapter Free. + * If not, see . + * + */ +package org.gege.caldavsyncadapter.caldav.discovery; + +import java.net.URI; + +import org.apache.http.HttpHost; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpPut; +import org.gege.caldavsyncadapter.caldav.http.HttpPropFind; +import org.gege.caldavsyncadapter.caldav.http.HttpReport; + +/** + * This interface deals with the preparation of requests. + * Some hosts/server implementations have their peculiarities + * that an implementation can challenge. + */ +public interface DiscoveryStrategy { + + /** + * method is used to determine a matching strategy implementation + * + * An implementation shall only return true, if it supports host specific + * features. + * + * @param targetHost the host + * @return true if this strategy instance supports the given host + */ + boolean supportsTargetHost(HttpHost targetHost); + + /** + * create a strategy specific version of a PROPFIND request + * + * @param uri the target uri + * @param data the data payload + * @param depth the "Depth" header value + * @param targetHost the target host, used for "Host" header + * @return the prepared request + */ + HttpPropFind createPropFindRequest(URI uri, String data, int depth, HttpHost targetHost); + + /** + * create a strategy specific version of a Report request + * + * @param uri the target uri + * @param data the data payload + * @param depth the "Depth" header value + * @param targetHost the target host, used for "Host" header + * @return the prepared request + */ + HttpReport createReportRequest(URI uri, String data, int depth, + HttpHost targetHost); + + /** + * create a strategy specific version of a DELETE request + * + * @param uri the target uri + * @param targetHost the target host, used for "Host" header + * @return the prepared request + */ + HttpDelete createDeleteRequest(URI uri, HttpHost targetHost); + + /** + * create a strategy specific version of a PUT request + * + * @param uri the target uri + * @param data the data payload + * @param depth the "Depth" header value + * @param targetHost the target host, used for "Host" header + * @return the prepared request + */ + HttpPut createPutRequest(URI uri, String data, int depth, + HttpHost targetHost); + +} diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/GoogleDiscoveryStrategy.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/GoogleDiscoveryStrategy.java new file mode 100644 index 0000000..034f48a --- /dev/null +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/discovery/GoogleDiscoveryStrategy.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2012-2013, Gerald Garcia + * + * This file is part of Andoid Caldav Sync Adapter Free. + * + * Andoid Caldav Sync Adapter Free is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or at your option any later version. + * + * Andoid Caldav Sync Adapter Free is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Andoid Caldav Sync Adapter Free. + * If not, see . + * + */ +package org.gege.caldavsyncadapter.caldav.discovery; + +import java.net.URI; + +import org.apache.http.HttpHost; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpUriRequest; +import org.gege.caldavsyncadapter.caldav.http.HttpPropFind; +import org.gege.caldavsyncadapter.caldav.http.HttpReport; + +public class GoogleDiscoveryStrategy extends DefaultDiscoveryStrategy { + + @Override + public boolean supportsTargetHost(HttpHost targetHost) { + if (targetHost != null && targetHost.getHostName() != null) { + return targetHost.getHostName().contains("google.com"); + } + return false; + } + + @Override + public HttpPropFind createPropFindRequest(URI uri, String data, int depth, + HttpHost targetHost) { + HttpPropFind result = super.createPropFindRequest(uri, data, depth, targetHost); + filterHostSpecifics(targetHost, result); + return result; + } + + @Override + public HttpReport createReportRequest(URI uri, String data, int depth, + HttpHost targetHost) { + HttpReport result = super.createReportRequest(uri, data, depth, targetHost); + filterHostSpecifics(targetHost, result); + return result; + } + + @Override + public HttpDelete createDeleteRequest(URI uri, HttpHost targetHost) { + HttpDelete result = super.createDeleteRequest(uri, targetHost); + filterHostSpecifics(targetHost, result); + return result; + } + + @Override + public HttpPut createPutRequest(URI uri, String data, int depth, + HttpHost targetHost) { + HttpPut result = super.createPutRequest(uri, data, depth, targetHost); + filterHostSpecifics(targetHost, result); + return result; + } + + private HttpUriRequest filterHostSpecifics(HttpHost targetHost, HttpUriRequest result) { + result.setHeader("Host", targetHost.getHostName()); + return result; + } +} diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarEvent.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarEvent.java index 26b3537..ebc844c 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarEvent.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarEvent.java @@ -25,7 +25,6 @@ import android.content.ContentProviderClient; import android.content.ContentUris; import android.content.ContentValues; -import android.content.SyncStats; import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; @@ -67,7 +66,6 @@ import org.gege.caldavsyncadapter.caldav.xml.sax.Prop; import org.gege.caldavsyncadapter.caldav.xml.sax.PropStat; import org.gege.caldavsyncadapter.caldav.xml.sax.Response; -import org.gege.caldavsyncadapter.syncadapter.SyncAdapter; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; @@ -173,7 +171,7 @@ public boolean setICSasMultiStatus(String stringMultiStatus) { multistatus = contentHandler.mMultiStatus; if (multistatus != null) { - responselist = multistatus.ResponseList; + responselist = multistatus.responseList; if (responselist.size() == 1) { response = responselist.get(0); //HINT: bugfix for google calendar, zimbra replace("@", "%40") @@ -210,48 +208,24 @@ public Uri getAndroidEventUri() { return mAndroidEventUri; } - /** - * sets the Uri of the android event - * - * @see org.gege.caldavsyncadapter.syncadapter.SyncAdapter#createAndroidEvent(ContentProviderClient - * provider, Account account, Uri calendarUri, CalendarEvent calendarEvent) - * @see org.gege.caldavsyncadapter.syncadapter.SyncAdapter#updateAndroidEvent(ContentProviderClient - * provider, Account account, AndroidEvent androidEvent, CalendarEvent calendarEvent) - */ public void setAndroidEventUri(Uri uri) { mAndroidEventUri = uri; } - /** - * reads all ContentValues from the caldav source - * - * @see org.gege.caldavsyncadapter.syncadapter.SyncAdapter#createAndroidEvent(ContentProviderClient - * provider, Account account, Uri calendarUri, CalendarEvent calendarEvent) - * @see org.gege.caldavsyncadapter.syncadapter.SyncAdapter#updateAndroidEvent(ContentProviderClient - * provider, Account account, AndroidEvent androidEvent, CalendarEvent calendarEvent) - */ public boolean readContentValues() { this.ContentValues.put(Events.DTSTART, this.getStartTime()); this.ContentValues.put(Events.EVENT_TIMEZONE, this.getTimeZoneStart()); - //if (this.getRRule().isEmpty() && this.getRDate().isEmpty()) { if (this.getRRule() == null && this.getRDate() == null) { - //if (AllDay.equals(1)) //{ - // values.put(Events.ALL_DAY, AllDay); - //} else { this.ContentValues.put(Events.DTEND, this.getEndTime()); this.ContentValues.put(Events.EVENT_END_TIMEZONE, this.getTimeZoneEnd()); - //} } else { - //if (AllDay.equals(1)) - // values.put(Events.ALL_DAY, AllDay); this.ContentValues.put(Events.DURATION, this.getDuration()); } int AllDay = this.getAllDay(); this.ContentValues.put(Events.ALL_DAY, AllDay); this.ContentValues.put(Events.TITLE, this.getTitle()); - //this.ContentValues.put(Events.CALENDAR_ID, ContentUris.parseId(calendarUri)); this.ContentValues.put(Events._SYNC_ID, this.getUri().toString()); this.ContentValues.put(ETAG, this.getETag()); this.ContentValues.put(Events.DESCRIPTION, this.getDescription()); @@ -278,8 +252,6 @@ public boolean fetchBody() throws ClientProtocolException, IOException, CaldavProtocolException, ParserException { boolean error = false; - //replaced fetchEvent() with getEvent() - //CaldavFacade.fetchEvent(this); CaldavFacade.getEvent(this); boolean parsed = this.parseIcs(); @@ -291,7 +263,7 @@ public boolean fetchBody() } public java.util.ArrayList getReminders() { - java.util.ArrayList Result = new java.util.ArrayList(); + java.util.ArrayList lcResult = new java.util.ArrayList(); ContentValues Reminder; /* @@ -300,7 +272,6 @@ public java.util.ArrayList getReminders() { net.fortuna.ical4j.model.component.VEvent event = (VEvent) this.calendarComponent; - //ComponentList ComList = this.calendar.getComponents(Component.VALARM); ComponentList ComList = event.getAlarms(); if (ComList != null) { @@ -308,11 +279,9 @@ public java.util.ArrayList getReminders() { Component Com = (Component) objCom; Reminder = new ContentValues(); - //Property ACTION = Com.getProperty("ACTION"); Property TRIGGER = Com.getProperty("TRIGGER"); if (TRIGGER != null) { Dur Duration = new Dur(TRIGGER.getValue()); - //if (ACTION.getValue().equals("DISPLAY")) int intDuration = Duration.getMinutes() + Duration.getHours() * 60 + Duration.getDays() * 60 * 24; @@ -321,49 +290,48 @@ public java.util.ArrayList getReminders() { Reminder.put(Reminders.METHOD, Reminders.METHOD_ALERT); Reminder.put(Reminders.MINUTES, intDuration); - Result.add(Reminder); + lcResult.add(Reminder); } } } - return Result; + return lcResult; } public java.util.ArrayList getAttandees() { - java.util.ArrayList Result = new java.util.ArrayList(); + java.util.ArrayList lcResult = new java.util.ArrayList(); ContentValues Attendee; - PropertyList Propertys = calendarComponent.getProperties(Property.ATTENDEE); - if (Propertys != null) { - for (Object objProperty : Propertys) { + PropertyList lcPropertys = calendarComponent.getProperties(Property.ATTENDEE); + if (lcPropertys != null) { + for (Object objProperty : lcPropertys) { Property property = (Property) objProperty; Attendee = ReadAttendeeProperties(property, Property.ATTENDEE); if (Attendee != null) { - Result.add(Attendee); + lcResult.add(Attendee); } } } - Propertys = calendarComponent.getProperties(Property.ORGANIZER); - if (Propertys != null) { - for (Object objProperty : Propertys) { + lcPropertys = calendarComponent.getProperties(Property.ORGANIZER); + if (lcPropertys != null) { + for (Object objProperty : lcPropertys) { Property property = (Property) objProperty; Attendee = ReadAttendeeProperties(property, Property.ORGANIZER); if (Attendee != null) { - Result.add(Attendee); + lcResult.add(Attendee); } } } - return Result; + return lcResult; } private ContentValues ReadAttendeeProperties(Property property, String Type) { - ContentValues Attendee = null; + ContentValues lcAttendee = null; - ParameterList Parameters = property.getParameters(); - Parameter CN = Parameters.getParameter(Cn.CN); - Parameter ROLE = Parameters.getParameter(Role.ROLE); - Parameter CUTYPE = Parameters.getParameter(CuType.CUTYPE); - //Parameter RSVP = Parameters.getParameter("RSVP"); - Parameter PARTSTAT = Parameters.getParameter(PartStat.PARTSTAT); + ParameterList lcParameters = property.getParameters(); + Parameter lcCN = lcParameters.getParameter(Cn.CN); + Parameter lcROLE = lcParameters.getParameter(Role.ROLE); + Parameter lcCUTYPE = lcParameters.getParameter(CuType.CUTYPE); + Parameter lcPARTSTAT = lcParameters.getParameter(PartStat.PARTSTAT); String strCN = ""; String strROLE = ""; @@ -376,21 +344,21 @@ private ContentValues ReadAttendeeProperties(Property property, String Type) { try { strValue = URLDecoder.decode(strValue, "UTF-8"); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + Log.e(getETag(), e.getMessage()); } } - if (CN != null) { - strCN = CN.getValue(); + if (lcCN != null) { + strCN = lcCN.getValue(); } - if (ROLE != null) { - strROLE = ROLE.getValue(); + if (lcROLE != null) { + strROLE = lcROLE.getValue(); } - if (CUTYPE != null) { - strCUTYPE = CUTYPE.getValue(); + if (lcCUTYPE != null) { + strCUTYPE = lcCUTYPE.getValue(); } - if (PARTSTAT != null) { - strPARTSTAT = PARTSTAT.getValue(); + if (lcPARTSTAT != null) { + strPARTSTAT = lcPARTSTAT.getValue(); } if (strCN.equals("")) { @@ -401,108 +369,108 @@ private ContentValues ReadAttendeeProperties(Property property, String Type) { if (!strCN.equals("")) { if (strCUTYPE.equals("") || strCUTYPE.equals("INDIVIDUAL")) { - Attendee = new ContentValues(); + lcAttendee = new ContentValues(); - Attendee.put(Attendees.EVENT_ID, ContentUris.parseId(mAndroidEventUri)); + lcAttendee.put(Attendees.EVENT_ID, ContentUris.parseId(mAndroidEventUri)); - Attendee.put(Attendees.ATTENDEE_NAME, strCN); - Attendee.put(Attendees.ATTENDEE_EMAIL, strValue); + lcAttendee.put(Attendees.ATTENDEE_NAME, strCN); + lcAttendee.put(Attendees.ATTENDEE_EMAIL, strValue); if (strROLE.equals("OPT-PARTICIPANT")) { - Attendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_OPTIONAL); + lcAttendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_OPTIONAL); } else if (strROLE.equals("NON-PARTICIPANT")) { - Attendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_NONE); + lcAttendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_NONE); } else if (strROLE.equals("REQ-PARTICIPANT")) { - Attendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_REQUIRED); + lcAttendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_REQUIRED); } else if (strROLE.equals("CHAIR")) { - Attendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_REQUIRED); + lcAttendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_REQUIRED); } else { - Attendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_NONE); + lcAttendee.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_NONE); } if (Type.equals(Property.ATTENDEE)) { - Attendee.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE); + lcAttendee.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE); } else if (Type.equals(Property.ORGANIZER)) { - Attendee.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ORGANIZER); + lcAttendee.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ORGANIZER); } else { - Attendee.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_NONE); + lcAttendee.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_NONE); } if (strPARTSTAT.equals(PartStat.NEEDS_ACTION.getValue())) { - Attendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED); + lcAttendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED); } else if (strPARTSTAT.equals(PartStat.ACCEPTED.getValue())) { - Attendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_ACCEPTED); + lcAttendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_ACCEPTED); } else if (strPARTSTAT.equals(PartStat.DECLINED.getValue())) { - Attendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_DECLINED); + lcAttendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_DECLINED); } else if (strPARTSTAT.equals(PartStat.COMPLETED.getValue())) { - Attendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_NONE); + lcAttendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_NONE); } else if (strPARTSTAT.equals(PartStat.TENTATIVE.getValue())) { - Attendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_TENTATIVE); + lcAttendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_TENTATIVE); } else { - Attendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED); + lcAttendee.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED); } } } - return Attendee; + return lcAttendee; } private long getAccessLevel() { - long Result = Events.ACCESS_DEFAULT; - String Value = ""; + long lcResult = Events.ACCESS_DEFAULT; + String lcValue = ""; Property property = calendarComponent.getProperty(Property.CLASS); if (property != null) { - Value = property.getValue(); - if (Value.equals(Clazz.PUBLIC)) { - Result = Events.ACCESS_PUBLIC; - } else if (Value.equals(Clazz.PRIVATE)) { - Result = Events.ACCESS_PRIVATE; - } else if (Value.equals(Clazz.CONFIDENTIAL)) { - Result + lcValue = property.getValue(); + if (lcValue.equals(Clazz.PUBLIC)) { + lcResult = Events.ACCESS_PUBLIC; + } else if (lcValue.equals(Clazz.PRIVATE)) { + lcResult = Events.ACCESS_PRIVATE; + } else if (lcValue.equals(Clazz.CONFIDENTIAL)) { + lcResult = Events.ACCESS_PRIVATE; // should be ACCESS_CONFIDENTIAL, but is not implemented within Android } } - return Result; + return lcResult; } private int getStatus() { - int Result = -1; - String Value = ""; + int lcResult = -1; + String lcValue = ""; Property property = calendarComponent.getProperty(Property.STATUS); if (property != null) { - Value = property.getValue(); - if (Value.equals(Status.VEVENT_CONFIRMED.getValue())) { - Result = Events.STATUS_CONFIRMED; - } else if (Value.equals(Status.VEVENT_CANCELLED.getValue())) { - Result = Events.STATUS_CANCELED; - } else if (Value.equals(Status.VEVENT_TENTATIVE.getValue())) { - Result = Events.STATUS_TENTATIVE; + lcValue = property.getValue(); + if (lcValue.equals(Status.VEVENT_CONFIRMED.getValue())) { + lcResult = Events.STATUS_CONFIRMED; + } else if (lcValue.equals(Status.VEVENT_CANCELLED.getValue())) { + lcResult = Events.STATUS_CANCELED; + } else if (lcValue.equals(Status.VEVENT_TENTATIVE.getValue())) { + lcResult = Events.STATUS_TENTATIVE; } } - return Result; + return lcResult; } private String getDescription() { - String Result = null; + String lcResult = null; Property property = calendarComponent.getProperty(Property.DESCRIPTION); if (property != null) { - Result = property.getValue(); + lcResult = property.getValue(); } - return Result; + return lcResult; } private String getLocation() { - String Result = null; + String lcResult = null; Property property = calendarComponent.getProperty(Property.LOCATION); if (property != null) { - Result = property.getValue(); + lcResult = property.getValue(); } - return Result; + return lcResult; } private String getTitle() { @@ -515,102 +483,100 @@ private String getTitle() { } private String getRRule() { - String Result = null; + String lcResult = null; Property property = calendarComponent.getProperty(Property.RRULE); if (property != null) { - Result = property.getValue(); + lcResult = property.getValue(); } - return Result; + return lcResult; } private String getExRule() { - String Result = null; + String lcResult = null; Property property = calendarComponent.getProperty(Property.EXRULE); if (property != null) { - Result = property.getValue(); + lcResult = property.getValue(); } - return Result; + return lcResult; } private String getRDate() { - String Result = null; + String lcResult = null; - java.util.ArrayList ExDates = this.getRDates(); - for (String Value : ExDates) { - if (Result == null) { - Result = ""; + java.util.ArrayList lcExDates = this.getRDates(); + for (String lcValue : lcExDates) { + if (lcResult == null) { + lcResult = ""; } - if (!Result.isEmpty()) { - Result += ","; + if (!lcResult.isEmpty()) { + lcResult += ","; } - Result += Value; + lcResult += lcValue; } - return Result; + return lcResult; } private java.util.ArrayList getRDates() { - java.util.ArrayList Result = new java.util.ArrayList(); + ArrayList lcResult = new ArrayList(); PropertyList Propertys = calendarComponent.getProperties(Property.RDATE); if (Propertys != null) { Property property; for (Object objProperty : Propertys) { property = (Property) objProperty; - Result.add(property.getValue()); + lcResult.add(property.getValue()); } } - return Result; + return lcResult; } private String getExDate() { - String Result = null; + String lcResult = null; - java.util.ArrayList ExDates = this.getExDates(); - for (String Value : ExDates) { - if (Result == null) { - Result = ""; + java.util.ArrayList lcExDates = this.getExDates(); + for (String lcValue : lcExDates) { + if (lcResult == null) { + lcResult = ""; } - if (!Result.isEmpty()) { - Result += ","; + if (!lcResult.isEmpty()) { + lcResult += ","; } - Result += Value; + lcResult += lcValue; } - return Result; + return lcResult; } private java.util.ArrayList getExDates() { - java.util.ArrayList Result = new java.util.ArrayList(); - PropertyList Propertys = calendarComponent.getProperties(Property.EXDATE); - if (Propertys != null) { + ArrayList lcResult = new ArrayList(); + PropertyList lcCalendarComponentPropertys = calendarComponent.getProperties(Property.EXDATE); + if (lcCalendarComponentPropertys != null) { Property property; - for (Object objProperty : Propertys) { + for (Object objProperty : lcCalendarComponentPropertys) { property = (Property) objProperty; - Result.add(property.getValue()); + lcResult.add(property.getValue()); } } - return Result; + return lcResult; } private String getUid() { - String Result = ""; + String lcResult = ""; Property prop = calendarComponent.getProperty(Property.UID); if (prop != null) { - Result = prop.getValue(); + lcResult = prop.getValue(); } - return Result; + return lcResult; } private Long getTimestamp(Property prop) { - Long Result = null; + Long lcResult = null; String strTimeZone = ""; - //TimeZone timeZone = null; - try { String strDate = prop.getValue(); @@ -626,91 +592,76 @@ private Long getTimestamp(Property prop) { if (propTZ != null) { strTimeZone = propTZ.getValue(); } - - //TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); - //if (!strTimeZone.equals("")) - // timeZone = registry.getTimeZone(strTimeZone); - - //if (timeZone != null) { if (!strTimeZone.equals("")) { - //Result = new DateTime(strDate, timeZone); - //Result1 = Result.getTime(); //20130331T120000 - int Year = Integer.parseInt(strDate.substring(0, 4)); - int Month = Integer.parseInt(strDate.substring(4, 6)) - 1; - int Day = Integer.parseInt(strDate.substring(6, 8)); - int Hour = Integer.parseInt(strDate.substring(9, 11)); - int Minute = Integer.parseInt(strDate.substring(11, 13)); - int Second = Integer.parseInt(strDate.substring(13, 15)); + int lcYear = Integer.parseInt(strDate.substring(0, 4)); + int lcMonth = Integer.parseInt(strDate.substring(4, 6)) - 1; + int lcDay = Integer.parseInt(strDate.substring(6, 8)); + int lcHour = Integer.parseInt(strDate.substring(9, 11)); + int lcMinute = Integer.parseInt(strDate.substring(11, 13)); + int lcSecond = Integer.parseInt(strDate.substring(13, 15)); // time in UTC java.util.TimeZone jtz = java.util.TimeZone.getTimeZone("UTC"); java.util.Calendar cal = java.util.GregorianCalendar.getInstance(jtz); - cal.set(Year, Month, Day, Hour, Minute, Second); + cal.set(lcYear, lcMonth, lcDay, lcHour, lcMinute, lcSecond); cal.set(java.util.Calendar.MILLISECOND, 0); - Result = cal.getTimeInMillis(); + lcResult = cal.getTimeInMillis(); // get the timezone - String[] IDs = java.util.TimeZone.getAvailableIDs(); - Boolean Found = false; - for (int i = 0; i < IDs.length; i++) { - Found = Found || IDs[i].equals(strTimeZone); + String[] lcIDs = java.util.TimeZone.getAvailableIDs(); + Boolean lcFound = false; + for (int i = 0; i < lcIDs.length; i++) { + lcFound = lcFound || lcIDs[i].equals(strTimeZone); } - if (Found) { + if (lcFound) { jtz = java.util.TimeZone.getTimeZone(strTimeZone); // subtract the offset - Result -= jtz.getRawOffset(); + lcResult -= jtz.getRawOffset(); // remove dst - if (jtz.inDaylightTime(new java.util.Date(Result))) { - Result -= jtz.getDSTSavings(); + if (jtz.inDaylightTime(new java.util.Date(lcResult))) { + lcResult -= jtz.getDSTSavings(); } } else { if (mTimeZone != null) { // subtract the offset - Result -= mTimeZone.getRawOffset(); + lcResult -= mTimeZone.getRawOffset(); // remove dst - if (mTimeZone.inDaylightTime(new java.util.Date(Result))) { - Result -= mTimeZone.getDSTSavings(); + if (mTimeZone.inDaylightTime(new java.util.Date(lcResult))) { + lcResult -= mTimeZone.getDSTSavings(); } } else { // unknown Time? // treat as local time, should not happen too often :) - Result = new DateTime(strDate).getTime(); + lcResult = new DateTime(strDate).getTime(); } } } else { if (strDate.endsWith("Z")) { // GMT or UTC - Result = new DateTime(strDate).getTime(); + lcResult = new DateTime(strDate).getTime(); } else { // unknown Time? // treat as local time, should not happen too often :) - Result = new DateTime(strDate).getTime(); + lcResult = new DateTime(strDate).getTime(); } } } catch (ParseException e) { - e.printStackTrace(); + Log.e(getETag(), e.getMessage()); } - return Result; + return lcResult; } private long getStartTime() { - long Result = 0; + long lcResult = 0; Property prop; - /* - * DTSTART;TZID=Europe/Berlin:20120425T080000 - * DTSTART;TZID=(GMT+01.00) Sarajevo/Warsaw/Zagreb:20120305T104500 - * DTSTART:20120308T093000Z - * DTSTART;VALUE=DATE:20120709 - * DTSTART;TZID=Europe/Berlin:20130330T100000 - */ prop = calendarComponent.getProperty(Property.DTSTART); if (prop != null) { @@ -718,14 +669,14 @@ private long getStartTime() { if (propTZ != null) { mstrTimeZoneStart = propTZ.getValue(); } - Result = getTimestamp(prop); + lcResult = getTimestamp(prop); } - return Result; + return lcResult; } private long getEndTime() { - long Result = 0; + long lcResult = 0; Property propDtEnd; Property propDuration; @@ -736,14 +687,13 @@ private long getEndTime() { if (propTZ != null) { mstrTimeZoneEnd = propTZ.getValue(); } - Result = getTimestamp(propDtEnd); + lcResult = getTimestamp(propDtEnd); } else if (propDuration != null) { - Result = 0; long Start = this.getStartTime(); String strDuration = propDuration.getValue(); Dur dur = new Dur(strDuration); - Result = Start + lcResult = Start + dur.getSeconds() * 1000 + dur.getMinutes() * 60 * 1000 + dur.getHours() * 60 * 60 * 1000 @@ -752,81 +702,81 @@ private long getEndTime() { mstrTimeZoneEnd = mstrTimeZoneStart; } - return Result; + return lcResult; } private String getTimeZoneStart() { - String Result = "GMT"; + String lcResult = "GMT"; if (!mstrTimeZoneStart.equals("")) { - Result = mstrTimeZoneStart; + lcResult = mstrTimeZoneStart; } - return Result; + return lcResult; } private String getTimeZoneEnd() { - String Result = "GMT"; + String lcResult = "GMT"; if (!mstrTimeZoneEnd.equals("")) { - Result = mstrTimeZoneEnd; + lcResult = mstrTimeZoneEnd; } - return Result; + return lcResult; } private String getDuration() { - String Result = ""; + String lcResult = ""; Property prop = calendarComponent.getProperty("DURATION"); if (prop != null) { //DURATION:PT1H - Result = prop.getValue(); + lcResult = prop.getValue(); } else { // no DURATION given by this event. we have to calculate it by ourself - Result = "P"; - long Start = this.getStartTime(); - long End = this.getEndTime(); - long Duration = 0; - if (End != 0) { - Duration = (End - Start) + lcResult = "P"; + long lcStartTime = this.getStartTime(); + long lcEndTime = this.getEndTime(); + long lcDurationTime = 0; + if (lcEndTime != 0) { + lcDurationTime = (lcEndTime - lcStartTime) / 1000; // get rid of the milliseconds, they cann't be described with RFC2445-Duration } - if (Duration < 0) { - Duration = 0; + if (lcDurationTime < 0) { + lcDurationTime = 0; } - int Days = (int) Math.ceil(Duration / 24 / 60 / 60); - int Hours = (int) Math.ceil((Duration - (Days * 24 * 60 * 60)) / 60 / 60); + int Days = (int) Math.ceil(lcDurationTime / 24 / 60 / 60); + int Hours = (int) Math.ceil((lcDurationTime - (Days * 24 * 60 * 60)) / 60 / 60); int Minutes = (int) Math - .ceil((Duration - (Days * 24 * 60 * 60) - (Hours * 60 * 60)) / 60); - int Seconds = (int) (Duration - (Days * 24 * 60 * 60) - (Hours * 60 * 60) - (Minutes + .ceil((lcDurationTime - (Days * 24 * 60 * 60) - (Hours * 60 * 60)) / 60); + int Seconds = (int) (lcDurationTime - (Days * 24 * 60 * 60) - (Hours * 60 * 60) - (Minutes * 60)); if (Days > 0) { - Result += String.valueOf(Days) + "D"; + lcResult += String.valueOf(Days) + "D"; } if (!mAllDay) { //if a ALL_DAY event occurs, there is no need for hours, minutes and seconds (Android doesn't understand them) - Result += "T"; - Result += String.valueOf(Hours) + "H"; - Result += String.valueOf(Minutes) + "M"; - Result += String.valueOf(Seconds) + "S"; + lcResult += "T"; + lcResult += String.valueOf(Hours) + "H"; + lcResult += String.valueOf(Minutes) + "M"; + lcResult += String.valueOf(Seconds) + "S"; } } - return Result; + return lcResult; } private int getAllDay() { - int Result = 0; + int lcResult = 0; if (mAllDay) { - Result = 1; + lcResult = 1; } - return Result; + return lcResult; } /** @@ -837,7 +787,7 @@ private int getAllDay() { * @see CalendarEvent#fetchBody() */ private boolean parseIcs() throws CaldavProtocolException, IOException, ParserException { - boolean Error = false; + boolean lcError = false; Thread.currentThread().setContextClassLoader(App.getContext().getClassLoader()); CalendarBuilder builder = new CalendarBuilder(); CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING, true); @@ -851,10 +801,10 @@ private boolean parseIcs() throws CaldavProtocolException, IOException, ParserEx } catch (ParserException ex) { // ical4j fails with this: "Cannot set timezone for UTC properties" // CREATED;TZID=America/New_York:20130129T140250 - Error = true; + lcError = true; } - if (!Error) { + if (!lcError) { ComponentList components = null; components = this.calendar.getComponents(Component.VEVENT); if (components.size() == 0) { @@ -863,7 +813,7 @@ private boolean parseIcs() throws CaldavProtocolException, IOException, ParserEx throw new CaldavProtocolException("unknown events in ICS"); } else { Log.e(TAG, "unsupported event TODO in ICS"); - Error = true; + lcError = true; } } else if (components.size() > 1) { Log.e(TAG, "Several events in ICS -> only first will be processed"); @@ -878,12 +828,12 @@ private boolean parseIcs() throws CaldavProtocolException, IOException, ParserEx mTimeZone = new TimeZone(mVTimeZone); } - if (!Error) { + if (!lcError) { calendarComponent = (Component) components.get(0); } } - return !Error; + return !lcError; } /** @@ -892,7 +842,7 @@ private boolean parseIcs() throws CaldavProtocolException, IOException, ParserEx * @return the android event */ public AndroidEvent getAndroidEvent(DavCalendar androidCalendar) throws RemoteException { - boolean Error = false; + boolean lcError = false; Uri uriEvents = Events.CONTENT_URI; Uri uriAttendee = Attendees.CONTENT_URI; Uri uriReminder = Reminders.CONTENT_URI; @@ -906,20 +856,19 @@ public AndroidEvent getAndroidEvent(DavCalendar androidCalendar) throws RemoteEx Cursor curReminder = null; if (curEvent == null) { - Error = true; + lcError = true; } - if (!Error) { + if (!lcError) { if (curEvent.getCount() == 0) { - Error = true; + lcError = true; } } - if (!Error) { + if (!lcError) { curEvent.moveToNext(); long EventID = curEvent.getLong(curEvent.getColumnIndex(Events._ID)); Uri returnedUri = ContentUris.withAppendedId(uriEvents, EventID); - //androidEvent = new AndroidEvent(this.mAccount, this.mProvider, returnedUri, androidCalendar.getAndroidCalendarUri()); androidEvent = new AndroidEvent(returnedUri, androidCalendar.getAndroidCalendarUri()); androidEvent.readContentValues(curEvent); @@ -934,27 +883,25 @@ public AndroidEvent getAndroidEvent(DavCalendar androidCalendar) throws RemoteEx curAttendee.close(); curReminder.close(); } - curEvent.close(); + if (curEvent != null) { + curEvent.close(); + } return androidEvent; } /** * creates a new androidEvent from a given calendarEvent - * - * @see {@link SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, - * DavCalendar, SyncStats)} */ public boolean createAndroidEvent(DavCalendar androidCalendar) throws ClientProtocolException, IOException, CaldavProtocolException, RemoteException, ParserException { - boolean Result = false; - boolean BodyFetched = this.fetchBody(); - int CountAttendees = 0; - int CountReminders = 0; + boolean lcResult = false; + boolean lcBodyFetched = this.fetchBody(); + int lcCountAttendees = 0; + int lcCountReminders = 0; - if (BodyFetched) { - //calendarEvent.readContentValues(calendarUri); + if (lcBodyFetched) { this.readContentValues(); this.setAndroidCalendarId(ContentUris.parseId(androidCalendar.getAndroidCalendarUri())); @@ -972,17 +919,17 @@ public boolean createAndroidEvent(DavCalendar androidCalendar) ArrayList AttendeeList = this.getAttandees(); for (ContentValues Attendee : AttendeeList) { this.mProvider.insert(Attendees.CONTENT_URI, Attendee); - CountAttendees += 1; + lcCountAttendees += 1; } //check the reminders ArrayList ReminderList = this.getReminders(); for (ContentValues Reminder : ReminderList) { this.mProvider.insert(Reminders.CONTENT_URI, Reminder); - CountReminders += 1; + lcCountReminders += 1; } - if ((CountAttendees > 0) || (CountReminders > 0)) { + if ((lcCountAttendees > 0) || (lcCountReminders > 0)) { //the events gets dirty when attendees or reminders were added AndroidEvent androidEvent = this.getAndroidEvent(androidCalendar); @@ -990,27 +937,24 @@ public boolean createAndroidEvent(DavCalendar androidCalendar) int RowCount = this.mProvider .update(asSyncAdapter(androidEvent.getUri(), this.mAccount.name, this.mAccount.type), androidEvent.ContentValues, null, null); - Result = (RowCount == 1); + lcResult = (RowCount == 1); } else { - Result = true; + lcResult = true; } } - return Result; + return lcResult; } /** * the android event is getting updated - * - * @see {@link SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, - * Calendar, SyncStats)} */ public boolean updateAndroidEvent(AndroidEvent androidEvent) throws ClientProtocolException, IOException, CaldavProtocolException, RemoteException, ParserException { boolean BodyFetched = this.fetchBody(); - int Rows = 0; + int lcRows = 0; if (BodyFetched) { this.readContentValues(); @@ -1035,7 +979,7 @@ public boolean updateAndroidEvent(AndroidEvent androidEvent) androidEvent.ContentValues.put(Events.DIRTY, 0); // the event is now in sync Log.d(TAG, "Update calendar event: for " + androidEvent.getUri()); - Rows = mProvider + lcRows = mProvider .update(asSyncAdapter(androidEvent.getUri(), mAccount.name, mAccount.type), androidEvent.ContentValues, null, null); //Log.i(TAG, "Updated calendar event: rows effected " + Rows.toString()); @@ -1043,18 +987,15 @@ public boolean updateAndroidEvent(AndroidEvent androidEvent) Log.d(TAG, "Update calendar event not needed: for " + androidEvent.getUri()); } } - return (Rows == 1); + return (lcRows == 1); } /** * updates the attendees from a calendarEvent to its androidEvent. * the calendarEvent has to know its androidEvent via {@link CalendarEvent#setAndroidEventUri(Uri)} - * - * @see SyncAdapter#updateAndroidEvent(ContentProviderClient, Account, AndroidEvent, - * CalendarEvent) */ private boolean updateAndroidAttendees() { - boolean Result = false; + boolean lcResult = false; try { String mSelectionClause = "(" + Attendees.EVENT_ID + " = ?)"; @@ -1070,47 +1011,44 @@ private boolean updateAndroidAttendees() { this.mProvider.insert(Attendees.CONTENT_URI, Attendee); } Log.d(TAG, "Attendees Inserted:" + String.valueOf(AttendeeList.size())); - Result = true; + lcResult = true; } catch (RemoteException e) { - e.printStackTrace(); + Log.e(getETag(),e.getMessage()); } - return Result; + return lcResult; } /** * update the reminders from a calendarEvent to its androidEvent. * the calendarEvent has to know its androidEvent via {@link CalendarEvent#setAndroidEventUri(Uri)} - * - * @see SyncAdapter#updateAndroidEvent(ContentProviderClient, Account, AndroidEvent, - * CalendarEvent) */ private boolean updateAndroidReminder() { - boolean Result = false; + boolean lcResult = false; try { String mSelectionClause = "(" + Reminders.EVENT_ID + " = ?)"; String[] mSelectionArgs = { Long.toString(ContentUris.parseId(this.getAndroidEventUri()))}; - int RowDelete; - RowDelete = this.mProvider + int lcRowDelete; + lcRowDelete = this.mProvider .delete(Reminders.CONTENT_URI, mSelectionClause, mSelectionArgs); - Log.d(TAG, "Reminders Deleted:" + String.valueOf(RowDelete)); + Log.d(TAG, "Reminders Deleted:" + String.valueOf(lcRowDelete)); - Uri ReminderUri; + Uri lcReminderUri; java.util.ArrayList ReminderList = this.getReminders(); for (ContentValues Reminder : ReminderList) { - ReminderUri = this.mProvider.insert(Reminders.CONTENT_URI, Reminder); - System.out.println(ReminderUri); + lcReminderUri = this.mProvider.insert(Reminders.CONTENT_URI, Reminder); + System.out.println(lcReminderUri); } Log.d(TAG, "Reminders Inserted:" + String.valueOf(ReminderList.size())); - Result = true; + lcResult = true; } catch (RemoteException e) { - e.printStackTrace(); + Log.e(getETag(),e.getMessage()); } - return Result; + return lcResult; } } diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java index b1b7b31..547c61f 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java @@ -6,6 +6,7 @@ import android.net.Uri; import android.os.RemoteException; import android.provider.CalendarContract.Calendars; +import android.util.Log; import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource; import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; @@ -39,46 +40,35 @@ public CalendarList(Account account, ContentProviderClient provider, CalendarSou this.ServerUrl = serverUrl; } -/* public Calendar getCalendarByAndroidCalendarId(int calendarId) { - Calendar Result = null; - - for (Calendar Item : mList) { - if (Item.getAndroidCalendarId() == calendarId) - Result = Item; - } - - return Result; - }*/ - public DavCalendar getCalendarByURI(URI calendarURI) { - DavCalendar Result = null; + DavCalendar lcResult = null; for (DavCalendar Item : mList) { if (Item.getURI().equals(calendarURI)) { - Result = Item; + lcResult = Item; } } - return Result; + return lcResult; } public DavCalendar getCalendarByAndroidUri(Uri androidCalendarUri) { - DavCalendar Result = null; + DavCalendar lcResult = null; - for (DavCalendar Item : mList) { - if (Item.getAndroidCalendarUri().equals(androidCalendarUri)) { - Result = Item; + for (DavCalendar lcDavCalendars : mList) { + if (lcDavCalendars.getAndroidCalendarUri().equals(androidCalendarUri)) { + lcResult = lcDavCalendars; } } - return Result; + return lcResult; } /** * function to get all calendars from client side android */ public boolean readCalendarFromClient() { - boolean Result = false; + boolean lcResult = false; Cursor cur = null; Uri uri = Calendars.CONTENT_URI; @@ -108,21 +98,21 @@ public boolean readCalendarFromClient() { try { cur = mProvider.query(uri, null, selection, selectionArgs, Calendars._ID + " ASC"); } catch (RemoteException e) { - e.printStackTrace(); + Log.e(this.getClass().getCanonicalName(), e.getMessage()); } if (cur != null) { while (cur.moveToNext()) { mList.add(new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl)); } cur.close(); - Result = true; + lcResult = true; } - return Result; + return lcResult; } public boolean deleteCalendarOnClientSideOnly(android.content.Context context) { - boolean Result = false; + boolean lcResult = false; for (DavCalendar androidCalendar : this.mList) { if (!androidCalendar.foundServerSide) { @@ -133,7 +123,7 @@ public boolean deleteCalendarOnClientSideOnly(android.content.Context context) { } } - return Result; + return lcResult; } public void addCalendar(DavCalendar item) { @@ -143,7 +133,7 @@ public void addCalendar(DavCalendar item) { this.mList.add(item); } - public java.util.ArrayList getCalendarList() { + public ArrayList getCalendarList() { return this.mList; } @@ -156,12 +146,12 @@ public void setProvider(ContentProviderClient provider) { } public ArrayList getNotifyList() { - ArrayList Result = new ArrayList(); + ArrayList lcResult = new ArrayList(); for (DavCalendar cal : this.mList) { - Result.addAll(cal.getNotifyList()); + lcResult.addAll(cal.getNotifyList()); } - return Result; + return lcResult; } } diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/DavCalendar.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/DavCalendar.java index 9605643..ac4b136 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/DavCalendar.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/entities/DavCalendar.java @@ -29,6 +29,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; +import android.provider.CalendarContract; import android.provider.CalendarContract.Calendars; import android.provider.CalendarContract.Events; import android.util.Log; @@ -138,7 +139,7 @@ public DavCalendar(Account account, ContentProviderClient provider, Cursor cur, try { uri = new URI(strSyncID); } catch (URISyntaxException e) { - e.printStackTrace(); + Log.e(getcTag(), e.getMessage()); } this.setURI(uri); } @@ -160,7 +161,7 @@ public URI getURI() { try { result = new URI(strUri); } catch (URISyntaxException e) { - e.printStackTrace(); + Log.e(getcTag(), e.getMessage()); } return result; } @@ -192,7 +193,6 @@ public void setCalendarDisplayName(String displayName) { public void setCTag(String cTag, boolean Update) { this.setContentValueAsString(DavCalendar.CTAG, cTag); if (Update) { - //serverCalendar.updateAndroidCalendar(androidCalendarUri, Calendar.CTAG, serverCalendar.getcTag()); try { this.updateAndroidCalendar(this.getAndroidCalendarUri(), CTAG, cTag); } catch (RemoteException e) { @@ -342,7 +342,7 @@ public Uri checkAndroidCalendarList(CalendarList androidCalList, * @return success of this function */ private boolean correctSyncID(String calendarUri) { - boolean Result = false; + boolean lcResult = false; Log.v(TAG, "correcting SyncID for calendar:" + this .getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME)); @@ -351,12 +351,12 @@ private boolean correctSyncID(String calendarUri) { try { mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null); - Result = true; + lcResult = true; } catch (RemoteException e) { - e.printStackTrace(); + Log.e(getcTag(), e.getMessage()); } - return Result; + return lcResult; } /** @@ -366,7 +366,7 @@ private boolean correctSyncID(String calendarUri) { * @return success of this function */ private boolean correctServerUrl(String serverUrl) { - boolean Result = false; + boolean lcResult = false; Log.v(TAG, "correcting ServerUrl for calendar:" + this .getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME)); @@ -375,12 +375,12 @@ private boolean correctServerUrl(String serverUrl) { try { mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null); - Result = true; + lcResult = true; } catch (RemoteException e) { - e.printStackTrace(); + Log.e(getcTag(), e.getMessage()); } - return Result; + return lcResult; } /** @@ -391,7 +391,7 @@ private boolean correctServerUrl(String serverUrl) { private DavCalendar createNewAndroidCalendar(DavCalendar serverCalendar, int index, android.content.Context context) { Uri newUri = null; - DavCalendar Result = null; + DavCalendar lcResult = null; final ContentValues contentValues = new ContentValues(); contentValues.put(DavCalendar.URI, serverCalendar.getURI().toString()); @@ -411,7 +411,6 @@ private DavCalendar createNewAndroidCalendar(DavCalendar serverCalendar, int ind contentValues.put(Calendars.CALENDAR_COLOR, color); } else { // find a color - //int index = mList.size(); index = index % CalendarColors.colors.length; contentValues.put(Calendars.CALENDAR_COLOR, CalendarColors.colors[2]); } @@ -443,21 +442,21 @@ private DavCalendar createNewAndroidCalendar(DavCalendar serverCalendar, int ind if (cur != null) { while (cur.moveToNext()) { - Result = new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl); - Result.foundServerSide = true; + lcResult = new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl); + lcResult.foundServerSide = true; } cur.close(); - //if (Result != null) - // this.mList.add(Result); } - Log.i(TAG, "New calendar created : URI=" + Result.getAndroidCalendarUri()); - NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", - "new calendar found: " + Result - .getCalendarDisplayName()); - mNotifyList.add(Result.getAndroidCalendarUri()); + if (lcResult != null) { + Log.i(TAG, "New calendar created : URI=" + lcResult.getAndroidCalendarUri()); + NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", + "new calendar found: " + lcResult + .getCalendarDisplayName()); + mNotifyList.add(lcResult.getAndroidCalendarUri()); + } } - return Result; + return lcResult; } private int getColorAsHex(String calendarColorAsString) { @@ -477,24 +476,24 @@ private int getColorAsHex(String calendarColorAsString) { * side. */ public boolean deleteAndroidCalendar() { - boolean Result = false; + boolean lcResult = false; String mSelectionClause = "(" + Calendars._ID + " = ?)"; int calendarId = this.getAndroidCalendarId(); String[] mSelectionArgs = {Long.toString(calendarId)}; - int CountDeleted = 0; + int lcCountDeleted = 0; try { - CountDeleted = mProvider.delete(this.SyncAdapter(), mSelectionClause, mSelectionArgs); + lcCountDeleted = mProvider.delete(this.SyncAdapter(), mSelectionClause, mSelectionArgs); Log.i(TAG, "Calendar deleted: " + String.valueOf(calendarId)); this.mNotifyList.add(this.getAndroidCalendarUri()); - Result = true; + lcResult = true; } catch (RemoteException e) { - e.printStackTrace(); + Log.e(getcTag(),e.getMessage()); } - Log.d(TAG, "Android Calendars deleted: " + Integer.toString(CountDeleted)); + Log.d(TAG, "Android Calendars deleted: " + Integer.toString(lcCountDeleted)); - return Result; + return lcResult; } /** @@ -531,71 +530,50 @@ private void updateAndroidCalendar(Uri calendarUri, String target, String value) /** * marks the android event as already handled - * - * @see AndroidEvent#cInternalTag - * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, - * DavCalendar, SyncStats) */ public boolean tagAndroidEvent(AndroidEvent androidEvent) throws RemoteException { - boolean Result = false; + boolean lcResult = false; ContentValues values = new ContentValues(); - //values.put(Event.INTERNALTAG, 1); values.put(Event.INTERNALTAG, mTagCounter); - //values.put(Event.INTERNALTAG, String.valueOf(mTagCounter)); - int RowCount = this.mProvider + int lcRowCount = this.mProvider .update(asSyncAdapter(androidEvent.getUri(), this.mAccount.name, this.mAccount.type), values, null, null); - //Log.v(TAG,"event tag nr: " + String.valueOf(mTagCounter)); - //Log.v(TAG,"Rows updated: " + String.valueOf(RowCount)); - if (RowCount == 1) { - Result = true; + if (lcRowCount == 1) { + lcResult = true; mTagCounter += 1; } else { Log.v(TAG, "EVENT NOT TAGGED!"); } - return Result; + return lcResult; } /** * removes the tag of all android events - * - * @see AndroidEvent#cInternalTag - * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, - * DavCalendar, SyncStats) */ public int untagAndroidEvents() throws RemoteException { - int RowCount = 0; - int Steps = 100; + int lcRowCount = 0; + int lcSteps = 100; ContentValues values = new ContentValues(); values.put(Event.INTERNALTAG, 0); - for (int i = 1; i < this.mTagCounter; i = i + Steps) { + for (int i = 1; i < this.mTagCounter; i = i + lcSteps) { String mSelectionClause = "(CAST(" + Event.INTERNALTAG + " AS INT) >= ?) AND (CAST(" + Event.INTERNALTAG + " AS INT) < ?) AND (" + Events.CALENDAR_ID + " = ?)"; - String[] mSelectionArgs = {String.valueOf(i), String.valueOf(i + Steps), + String[] mSelectionArgs = {String.valueOf(i), String.valueOf(i + lcSteps), Long.toString(ContentUris .parseId(this.getAndroidCalendarUri()))}; - RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, + lcRowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs); } - /*String mSelectionClause = "(" + Event.INTERNALTAG + " > ?) AND (" + Events.CALENDAR_ID + " = ?)"; - String[] mSelectionArgs = {"0", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))}; - RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs);*/ - - //Log.d(TAG, "Rows reseted: " + RowCount.toString()); - return RowCount; + return lcRowCount; } /** * Events not being tagged are for deletion - * - * @see AndroidEvent#cInternalTag - * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, - * DavCalendar, SyncStats) */ public int deleteUntaggedEvents() throws RemoteException { String mSelectionClause = "(" + Event.INTERNALTAG + " < ?) AND (" + Events.CALENDAR_ID @@ -603,11 +581,12 @@ public int deleteUntaggedEvents() throws RemoteException { String[] mSelectionArgs = {"1", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))}; - int CountDeleted = this.mProvider + int lcCountDeleted; + lcCountDeleted = this.mProvider .delete(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), mSelectionClause, mSelectionArgs); - //Log.d(TAG, "Rows deleted: " + CountDeleted.toString()); - return CountDeleted; + + return lcCountDeleted; } private Uri SyncAdapterCalendar() { @@ -633,11 +612,11 @@ public void setProvider(ContentProviderClient provider) { * @return the value for the item */ private String getContentValueAsString(String Item) { - String Result = ""; + String lcResult = ""; if (this.ContentValues.containsKey(Item)) { - Result = this.ContentValues.getAsString(Item); + lcResult = this.ContentValues.getAsString(Item); } - return Result; + return lcResult; } /** @@ -647,11 +626,11 @@ private String getContentValueAsString(String Item) { * @return the value for the item */ private int getContentValueAsInt(String Item) { - int Result = 0; + int lcResult = 0; if (this.ContentValues.containsKey(Item)) { - Result = this.ContentValues.getAsInteger(Item); + lcResult = this.ContentValues.getAsInteger(Item); } - return Result; + return lcResult; } /** @@ -662,14 +641,14 @@ private int getContentValueAsInt(String Item) { * @return success of this function */ private boolean setContentValueAsString(String Item, String Value) { - boolean Result = false; + boolean lcResult = false; if (this.ContentValues.containsKey(Item)) { this.ContentValues.remove(Item); } this.ContentValues.put(Item, Value); - return Result; + return lcResult; } /** @@ -680,14 +659,14 @@ private boolean setContentValueAsString(String Item, String Value) { * @return success of this function */ private boolean setContentValueAsInt(String Item, int Value) { - boolean Result = false; + boolean lcResult = false; if (this.ContentValues.containsKey(Item)) { this.ContentValues.remove(Item); } this.ContentValues.put(Item, Value); - return Result; + return lcResult; } public ArrayList getNotifyList() { @@ -699,29 +678,29 @@ public ArrayList getCalendarEvents() { } public boolean readCalendarEvents(CaldavFacade facade) { - boolean Result = false; + boolean lcResult = false; try { this.mCalendarEvents = facade.getCalendarEvents(this); - Result = true; + lcResult = true; } catch (ClientProtocolException e) { - e.printStackTrace(); - Result = false; + Log.e(getcTag(),e.getMessage()); + lcResult = false; } catch (URISyntaxException e) { - e.printStackTrace(); - Result = false; + Log.e(getcTag(),e.getMessage()); + lcResult = false; } catch (IOException e) { - e.printStackTrace(); - Result = false; + Log.e(getcTag(),e.getMessage()); + lcResult = false; } catch (ParserConfigurationException e) { - e.printStackTrace(); - Result = false; + Log.e(getcTag(),e.getMessage()); + lcResult = false; } catch (SAXException e) { - e.printStackTrace(); - Result = false; + Log.e(getcTag(),e.getMessage()); + lcResult = false; } - return Result; + return lcResult; } public enum CalendarSource { diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarHomeHandler.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarHomeHandler.java index 3bd9bcf..225e182 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarHomeHandler.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarHomeHandler.java @@ -90,7 +90,6 @@ public void endElement(String uri, String localName, String qName) "uri malformed in calendar-home-set/href"); } } - //stringBuilder.setLength(0); } if (CALENDAR_HOME_SET.equals(localName)) { isInCalendarHomeSet = false; diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarsHandler.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarsHandler.java index d658e68..7a8642b 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarsHandler.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/CalendarsHandler.java @@ -125,7 +125,6 @@ public void endElement(String uri, String localName, String qName) calendar.setCalendarColorAsString(stringBuilder.toString()); } } - //stringBuilder.setLength(0); } else if (RESPONSE.equals(localName)) { if (isCalendarResource && isValidCalendar(calendar)) { calendars.add(calendar); diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/MultiStatusHandler.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/MultiStatusHandler.java index 2750608..967320b 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/MultiStatusHandler.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/MultiStatusHandler.java @@ -50,7 +50,7 @@ public void startElement(String uri, String localName, String qName, Attributes mCurrentValue = ""; if (localName.equals(RESPONSE)) { mResponse = new Response(); - mMultiStatus.ResponseList.add(mResponse); + mMultiStatus.responseList.add(mResponse); } else if (localName.equals(PROPSTAT)) { mPropStat = new PropStat(); mResponse.propstat = mPropStat; diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/ServerInfoHandler.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/ServerInfoHandler.java index 5081d8e..5d0a1f4 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/ServerInfoHandler.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/ServerInfoHandler.java @@ -70,7 +70,6 @@ public void characters(char[] ch, int start, int length) @Override public void endElement(String uri, String localName, String qName) throws SAXException { - //if (TAGS.contains(inParentElement)) { if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) { if (CURRENT_USER_PRINCIPAL.equals(inParentElement)) { currentUserPrincipal = stringBuilder.toString(); @@ -80,7 +79,6 @@ public void endElement(String uri, String localName, String qName) } if (TAGS.contains(localName)) { inParentElement = null; - //stringBuilder.setLength(0); } currentElement = null; diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/sax/MultiStatus.java b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/sax/MultiStatus.java index d601e03..67874e1 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/sax/MultiStatus.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/caldav/xml/sax/MultiStatus.java @@ -4,5 +4,5 @@ public class MultiStatus { - public ArrayList ResponseList = new ArrayList(); + public ArrayList responseList = new ArrayList(); } diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/SyncAdapter.java b/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/SyncAdapter.java index 610df67..56b4e9c 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/SyncAdapter.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/SyncAdapter.java @@ -92,7 +92,7 @@ public SyncAdapter(Context context, boolean autoInitialize) { mVersion = context.getPackageManager() .getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage()); } } @@ -123,23 +123,22 @@ public void onPerformSync(Account account, Bundle extras, String authority, ArrayList notifyList = new ArrayList(); try { - String Username = ""; - String UserDataVersion = mAccountManager + String lcUsername = ""; + String lcUserDataVersion = mAccountManager .getUserData(account, AuthenticatorActivity.USER_DATA_VERSION); - if (UserDataVersion == null) { - Username = account.name; + if (lcUserDataVersion == null) { + lcUsername = account.name; } else { - Username = mAccountManager + lcUsername = mAccountManager .getUserData(account, AuthenticatorActivity.USER_DATA_USERNAME); } - CaldavFacade facade = new CaldavFacade(Username, mAccountManager.getPassword(account), + CaldavFacade facade = new CaldavFacade(lcUsername, mAccountManager.getPassword(account), url, trust); facade.setAccount(account); facade.setProvider(provider); facade.setVersion(mVersion); serverCalList = facade.getCalendarList(this.getContext()); - //String davProperties = facade.getLastDav(); Log.i(TAG, String.valueOf(androidCalList.getCalendarList() .size()) + " calendars found at android"); @@ -265,12 +264,6 @@ public void onSyncCanceled() { /** * both calender event and android event have been found. * server wins always at the moment. - * - * @see SyncAdapter#updateAndroidEvent(ContentProviderClient, Account, AndroidEvent, - * CalendarEvent) - * @see SyncAdapter#tagAndroidEvent(ContentProviderClient, Account, AndroidEvent) - * @see SyncAdapter#untagAndroidEvents(ContentProviderClient, Account, Uri) - * @see SyncAdapter#deleteUntaggedEvents(ContentProviderClient, Account, Uri) */ private void synchroniseEvents( DavCalendar androidCalendar, @@ -295,7 +288,7 @@ private void synchroniseEvents( .toString() + " androidUri=" + androidEvent); if (androidEvent == null) { - /* new android event */ + /* new android event */ if (calendarEvent.createAndroidEvent(androidCalendar)) { rowInsert += 1; androidEvent = calendarEvent.getAndroidEvent(androidCalendar); @@ -304,7 +297,7 @@ private void synchroniseEvents( rowSkip += 1; } } else { - /* the android exists */ + /* the android exists */ String androidETag = androidEvent.getETag(); if (androidETag == null) { androidETag = ""; @@ -313,7 +306,7 @@ private void synchroniseEvents( .toString()); if ((androidEvent.getETag() == null) || (!androidETag .equals(calendarEvent.getETag()))) { - // the android event is getting updated + // the android event is getting updated if (calendarEvent.updateAndroidEvent(androidEvent)) { rowUpdate += 1; notifyList.add(androidEvent.getUri()); @@ -322,8 +315,7 @@ private void synchroniseEvents( } } } - if (androidEvent != null) - { + if (androidEvent != null) { if (androidCalendar.tagAndroidEvent(androidEvent)) { rowTag += 1; } @@ -378,8 +370,8 @@ private int checkDirtyAndroidEvents( Cursor curEvent = null; Cursor curAttendee = null; Cursor curReminder = null; - Long EventID; - Long CalendarID; + Long lcEventID; + Long lcCalendarID; AndroidEvent androidEvent = null; int rowDirty = 0; int rowInsert = 0; @@ -387,24 +379,24 @@ private int checkDirtyAndroidEvents( int rowDelete = 0; try { - CalendarID = ContentUris.parseId(calendarUri); + lcCalendarID = ContentUris.parseId(calendarUri); String selection = "(" + Events.DIRTY + " = ?) AND (" + Events.CALENDAR_ID + " = ?)"; - String[] selectionArgs = new String[]{"1", CalendarID.toString()}; + String[] selectionArgs = new String[]{"1", lcCalendarID.toString()}; curEvent = provider.query(Events.CONTENT_URI, null, selection, selectionArgs, null); while (curEvent.moveToNext()) { - EventID = curEvent.getLong(curEvent.getColumnIndex(Events._ID)); - Uri returnedUri = ContentUris.withAppendedId(Events.CONTENT_URI, EventID); + lcEventID = curEvent.getLong(curEvent.getColumnIndex(Events._ID)); + Uri returnedUri = ContentUris.withAppendedId(Events.CONTENT_URI, lcEventID); androidEvent = new AndroidEvent(returnedUri, calendarUri); androidEvent.readContentValues(curEvent); selection = "(" + Attendees.EVENT_ID + " = ?)"; - selectionArgs = new String[]{String.valueOf(EventID)}; + selectionArgs = new String[]{String.valueOf(lcEventID)}; curAttendee = provider .query(Attendees.CONTENT_URI, null, selection, selectionArgs, null); selection = "(" + Reminders.EVENT_ID + " = ?)"; - selectionArgs = new String[]{String.valueOf(EventID)}; + selectionArgs = new String[]{String.valueOf(lcEventID)}; curReminder = provider .query(Reminders.CONTENT_URI, null, selection, selectionArgs, null); androidEvent.readAttendees(curAttendee); @@ -442,8 +434,8 @@ private int checkDirtyAndroidEvents( CalendarEvent calendarEvent = new CalendarEvent(account, provider); calendarEvent.calendarURL = caldavCalendarUri.toURL(); - URI SyncURI = new URI(SyncID); - calendarEvent.setUri(SyncURI); + URI lcSyncURI = new URI(SyncID); + calendarEvent.setUri(lcSyncURI); CaldavFacade.getEvent(calendarEvent); values.put(Event.ETAG, calendarEvent.getETag()); @@ -463,7 +455,7 @@ private int checkDirtyAndroidEvents( // deleted Android event if (facade.deleteEvent(URI.create(SyncID), androidEvent.getETag())) { String mSelectionClause = "(" + Events._ID + "= ?)"; - String[] mSelectionArgs = {String.valueOf(EventID)}; + String[] mSelectionArgs = {String.valueOf(lcEventID)}; int countDeleted = provider .delete(asSyncAdapter(Events.CONTENT_URI, account.name, @@ -494,7 +486,7 @@ private int checkDirtyAndroidEvents( if (facade.updateEvent(URI.create(SyncID), androidEvent.getIcsEvent() .toString(), androidEvent.getETag())) { selection = "(" + Events._ID + "= ?)"; - selectionArgs = new String[]{EventID.toString()}; + selectionArgs = new String[]{lcEventID.toString()}; androidEvent.ContentValues.put(Events.DIRTY, 0); //google doesn't send the etag after update @@ -536,22 +528,17 @@ private int checkDirtyAndroidEvents( stats.numSkippedEntries += rowDirty; stats.numEntries += rowInsert + rowUpdate + rowDelete; } catch (RemoteException e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage()); } catch (URISyntaxException e) { - // TODO Automatisch generierter Erfassungsblock - e.printStackTrace(); + Log.e(TAG, e.getMessage()); } catch (ClientProtocolException e) { - // TODO Automatisch generierter Erfassungsblock - e.printStackTrace(); + Log.e(TAG, e.getMessage()); } catch (IOException e) { - // TODO Automatisch generierter Erfassungsblock - e.printStackTrace(); + Log.e(TAG, e.getMessage()); } catch (CaldavProtocolException e) { - // TODO Automatisch generierter Erfassungsblock - e.printStackTrace(); + Log.e(TAG, e.getMessage()); } catch (ParserException e) { - // TODO Automatisch generierter Erfassungsblock - e.printStackTrace(); + Log.e(TAG, e.getMessage()); } return rowDirty; diff --git a/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/notifications/NotificationsHelper.java b/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/notifications/NotificationsHelper.java index 1df5a1d..23692f1 100644 --- a/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/notifications/NotificationsHelper.java +++ b/ACalDAV/src/org/gege/caldavsyncadapter/syncadapter/notifications/NotificationsHelper.java @@ -6,14 +6,8 @@ import de.we.acaldav.R; -//import android.app.PendingIntent; -//import android.content.Intent; -//import android.support.v4.app.TaskStackBuilder; - public class NotificationsHelper { - /*static SyncLog currentSyncLog = new SyncLog(); - doesn't exist */ public static void signalSyncErrors(Context context, String title, String text) { NotificationCompat.Builder mBuilder = @@ -22,26 +16,6 @@ public static void signalSyncErrors(Context context, String title, String text) .setContentTitle(title) .setContentText(text); - // Creates an explicit intent for an Activity in your app -/* Intent resultIntent = new Intent(context, SyncStatusReportActivity.class); - - // The stack builder object will contain an artificial back stack for the - // started Activity. - // This ensures that navigating backward from the Activity leads out of - // your application to the Home screen. - TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); - // Adds the back stack for the Intent (but not the Intent itself) - stackBuilder.addParentStack(SyncStatusReportActivity.class); - // Adds the Intent that starts the Activity to the top of the stack - stackBuilder.addNextIntent(resultIntent); - PendingIntent resultPendingIntent = - stackBuilder.getPendingIntent( - 0, - PendingIntent.FLAG_UPDATE_CURRENT - ); - mBuilder.setContentIntent(resultPendingIntent); -*/ - NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); @@ -49,9 +23,4 @@ public static void signalSyncErrors(Context context, String title, String text) int mId = 0; mNotificationManager.notify(mId, mBuilder.build()); } - - /*public static SyncLog getCurrentSyncLog() { - return currentSyncLog; - }*/ - }