src/org/gege/caldavsyncadapter/caldav/entities/DavCalendar.java

Tue, 10 Feb 2015 18:12:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 18:12:00 +0100
changeset 0
fb9019fb1bf7
child 8
ec8af0e3fbc2
permissions
-rw-r--r--

Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.

     1 /**
     2  * Copyright (c) 2012-2013, Gerald Garcia, Timo Berger
     3  * 
     4  * This file is part of Andoid Caldav Sync Adapter Free.
     5  *
     6  * Andoid Caldav Sync Adapter Free is free software: you can redistribute 
     7  * it and/or modify it under the terms of the GNU General Public License 
     8  * as published by the Free Software Foundation, either version 3 of the 
     9  * License, or at your option any later version.
    10  *
    11  * Andoid Caldav Sync Adapter Free is distributed in the hope that 
    12  * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
    13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License
    17  * along with Andoid Caldav Sync Adapter Free.  
    18  * If not, see <http://www.gnu.org/licenses/>.
    19  * 
    20  */
    22 package org.gege.caldavsyncadapter.caldav.entities;
    24 import java.io.IOException;
    25 import java.net.URI;
    26 import java.net.URISyntaxException;
    27 import java.util.ArrayList;
    29 import javax.xml.parsers.ParserConfigurationException;
    31 import org.apache.http.client.ClientProtocolException;
    32 import org.gege.caldavsyncadapter.CalendarColors;
    33 import org.gege.caldavsyncadapter.Event;
    34 import org.gege.caldavsyncadapter.android.entities.AndroidEvent;
    35 import org.gege.caldavsyncadapter.caldav.CaldavFacade;
    36 import org.gege.caldavsyncadapter.syncadapter.SyncAdapter;
    37 import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper;
    38 import org.xml.sax.SAXException;
    40 import android.accounts.Account;
    41 import android.content.ContentProviderClient;
    42 import android.content.ContentUris;
    43 import android.content.ContentValues;
    44 import android.content.SyncStats;
    45 import android.database.Cursor;
    46 import android.net.Uri;
    47 import android.os.RemoteException;
    48 import android.provider.CalendarContract.Calendars;
    49 import android.provider.CalendarContract.Events;
    50 import android.util.Log;
    52 public class DavCalendar {
    53 	public enum CalendarSource {
    54 		undefined, Android, CalDAV
    55 	}
    57 	private static final String TAG = "Calendar";
    59 	/**
    60 	 * stores the CTAG of a calendar
    61 	 */
    62 	public static String CTAG = Calendars.CAL_SYNC1;
    64 	/**
    65 	 * stores the URI of a calendar
    66 	 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname
    67 	 */
    68 	public static String URI = Calendars._SYNC_ID;
    70 	public static String SERVERURL = Calendars.CAL_SYNC2;
    72 	private String strCalendarColor = "";
    74 	private ArrayList<Uri> mNotifyList = new ArrayList<Uri>(); 
    76 	/**
    77 	 * the event transformed into ContentValues
    78 	 */
    79 	public ContentValues ContentValues = new ContentValues();
    81 	private Account mAccount = null;
    82 	private ContentProviderClient mProvider = null;
    84 	public boolean foundServerSide = false;
    85 	public boolean foundClientSide = false;
    86 	public CalendarSource Source = CalendarSource.undefined;
    88 	public String ServerUrl = "";
    90 	private ArrayList<CalendarEvent> mCalendarEvents = new ArrayList<CalendarEvent>();
    92 	private int mTagCounter = 1;
    94 	/**
    95 	 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname
    96 	 */
    97 	public URI getURI() {
    98 		String strUri = this.getContentValueAsString(DavCalendar.URI);
    99 		URI result = null;
   100 		try {
   101 			result = new URI(strUri);
   102 		} catch (URISyntaxException e) {
   103 			e.printStackTrace();
   104 		}
   105 		return result;
   106 	}
   108 	/**
   109 	 * example: http://caldav.example.com/calendarserver.php/calendars/username/calendarname
   110 	 */
   111 	public void setURI(URI uri) {
   112 		this.setContentValueAsString(DavCalendar.URI, uri.toString());
   113 	}
   115 	/**
   116 	 * example: Cleartext Display Name 
   117 	 */
   118 	public String getCalendarDisplayName() {
   119 		return this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME);
   120 	}
   122 	/**
   123 	 * example: Cleartext Display Name 
   124 	 */
   125 	public void setCalendarDisplayName(String displayName) {
   126 		this.setContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME, displayName);
   127 	}
   130 	/**
   131 	 * example: 1143
   132 	 */
   133 	public void setCTag(String cTag, boolean Update) {
   134 		this.setContentValueAsString(DavCalendar.CTAG, cTag);
   135 		if (Update) {
   136 			//serverCalendar.updateAndroidCalendar(androidCalendarUri, Calendar.CTAG, serverCalendar.getcTag());
   137 			try {
   138 				this.updateAndroidCalendar(this.getAndroidCalendarUri(), CTAG, cTag);
   139 			} catch (RemoteException e) {
   140 				e.printStackTrace();
   141 			}
   142 		}
   143 	}
   145 	/**
   146 	 * example: 1143
   147 	 */
   148 	public String getcTag() {
   149 		return this.getContentValueAsString(DavCalendar.CTAG);
   150 	}
   152 	/**
   153 	 * example: #FFCCAA 
   154 	 */
   155 	public void setCalendarColorAsString(String color) {
   156 		int maxlen = 6;
   158 		this.strCalendarColor = color;
   159 		if (!color.equals("")) {
   160 			String strColor = color.replace("#", "");
   161 			if (strColor.length() > maxlen)
   162 				strColor = strColor.substring(0, maxlen);
   163 			int intColor = Integer.parseInt(strColor, 16);
   164 			this.setContentValueAsInt(Calendars.CALENDAR_COLOR, intColor);
   165 		}
   166 	}
   168 	/**
   169 	 * example: #FFCCAA 
   170 	 */
   171 	public String getCalendarColorAsString() {
   172 		return this.strCalendarColor;
   173 	}
   175 	/**
   176 	 * example 12345 
   177 	 */
   178 	public int getCalendarColor() {
   179 		return this.getContentValueAsInt(Calendars.CALENDAR_COLOR);
   180 	}
   182 	/**
   183 	 * example 12345 
   184 	 */
   185 	public void setCalendarColor(int color) {
   186 		this.setContentValueAsInt(Calendars.CALENDAR_COLOR, color);
   187 	}
   189 	/**
   190 	 * example: 
   191 	 * 		should be: calendarname
   192 	 * 		but is:    http://caldav.example.com/calendarserver.php/calendars/username/calendarname/
   193 	 */
   194 	public String getCalendarName() {
   195 		return this.getContentValueAsString(Calendars.NAME);
   196 	}
   198 	/**
   199 	 * example: 
   200 	 * 		should be: calendarname
   201 	 * 		but is:    http://caldav.example.com/calendarserver.php/calendars/username/calendarname/
   202 	 */
   203 	public void setCalendarName(String calendarName) {
   204 		this.setContentValueAsString(Calendars.NAME, calendarName);
   205 	}
   207 	/**
   208 	 * example: 8
   209 	 */
   210 	public int getAndroidCalendarId() {
   211 		return this.getContentValueAsInt(Calendars._ID);
   212 	}
   214 	/**
   215 	 * example: 8
   216 	 */
   217 	public void setAndroidCalendarId(int androidCalendarId) {
   218 		this.setContentValueAsInt(Calendars._ID, androidCalendarId);
   219 	}
   221 	/**
   222 	 * example: content://com.android.calendar/calendars/8
   223 	 */
   224 	public Uri getAndroidCalendarUri() {
   225 		return ContentUris.withAppendedId(Calendars.CONTENT_URI, this.getAndroidCalendarId());
   226 	}
   228 	/**
   229 	 * empty constructor
   230 	 */
   231 	public DavCalendar(CalendarSource source) {
   232 		this.Source = source;
   233 	}
   235 	/**
   236 	 * creates an new instance from a cursor
   237 	 * @param cur must be a cursor from "ContentProviderClient" with Uri Calendars.CONTENT_URI
   238 	 */
   239 	public DavCalendar(Account account, ContentProviderClient provider, Cursor cur, CalendarSource source, String serverUrl) {
   240 		this.mAccount = account;
   241 		this.mProvider = provider;
   242 		this.foundClientSide = true;
   243 		this.Source = source;
   244 		this.ServerUrl = serverUrl;
   246 		String strSyncID = cur.getString(cur.getColumnIndex(Calendars._SYNC_ID));
   247 		String strName = cur.getString(cur.getColumnIndex(Calendars.NAME));
   248 		String strDisplayName = cur.getString(cur.getColumnIndex(Calendars.CALENDAR_DISPLAY_NAME));
   249 		String strCTAG = cur.getString(cur.getColumnIndex(DavCalendar.CTAG));
   250 		String strServerUrl = cur.getString(cur.getColumnIndex(DavCalendar.SERVERURL));
   251 		int intAndroidCalendarId = cur.getInt(cur.getColumnIndex(Calendars._ID));
   253 		this.setCalendarName(strName);
   254 		this.setCalendarDisplayName(strDisplayName);
   255 		this.setCTag(strCTAG, false);
   256 		this.setAndroidCalendarId(intAndroidCalendarId);
   258 		if (strSyncID == null) {
   259 			this.correctSyncID(strName);
   260 			strSyncID = strName;
   261 		}
   262 		if (strServerUrl == null) {
   263 			this.correctServerUrl(serverUrl);
   264 		}
   265 		URI uri = null;
   266 		try {
   267 			uri = new URI(strSyncID);
   268 		} catch (URISyntaxException e) {
   269 			e.printStackTrace();
   270 		}
   271 		this.setURI(uri);
   272 	}
   274 	/**
   275 	 * checks a given list of android calendars for a specific android calendar.
   276 	 * this calendar should be a server calendar as it is searched for.
   277 	 * if the calendar is not found, it will be created.
   278 	 * @param androidCalList the list of android calendars
   279 	 * @param context
   280 	 * @return the found android calendar or null of fails
   281 	 * @throws RemoteException
   282 	 */
   283 	public Uri checkAndroidCalendarList(CalendarList androidCalList, android.content.Context context) throws RemoteException {
   284 		Uri androidCalendarUri = null;
   285 		boolean isCalendarExist = false;
   287 		DavCalendar androidCalendar = androidCalList.getCalendarByURI(this.getURI());
   288 		if (androidCalendar != null) {
   289 			isCalendarExist = true;
   290 			androidCalendar.foundServerSide = true;
   291 		}
   294 		if (!isCalendarExist) {
   295 			DavCalendar newCal = this.createNewAndroidCalendar(this, androidCalList.getCalendarList().size(), context);
   296 			if (newCal != null) {
   297 				androidCalList.addCalendar(newCal);
   298 				androidCalendarUri = newCal.getAndroidCalendarUri();
   299 			}
   300 		} else {
   301 			androidCalendarUri = androidCalendar.getAndroidCalendarUri();
   302 			if (!this.getCalendarColorAsString().equals("")) {
   303 				//serverCalendar.updateCalendarColor(returnedCalendarUri, serverCalendar);
   304 				this.updateAndroidCalendar(androidCalendarUri, Calendars.CALENDAR_COLOR, this.getCalendarColor());
   305 			}
   306 			if ((this.ContentValues.containsKey(Calendars.CALENDAR_DISPLAY_NAME)) && 
   307 				(androidCalendar.ContentValues.containsKey(Calendars.CALENDAR_DISPLAY_NAME))) {
   308 				String serverDisplayName = this.ContentValues.getAsString(Calendars.CALENDAR_DISPLAY_NAME);
   309 				String clientDisplayName = androidCalendar.ContentValues.getAsString(Calendars.CALENDAR_DISPLAY_NAME);
   310 				if (!serverDisplayName.equals(clientDisplayName))
   311 					this.updateAndroidCalendar(androidCalendarUri, Calendars.CALENDAR_DISPLAY_NAME, serverDisplayName);
   312 			}
   313 		}
   315 		return androidCalendarUri;
   316 	}
   318 	/**
   319 	 * COMPAT: the calendar Uri was stored as calendar Name. this function updates the URI (_SYNC_ID)
   320 	 * @param calendarUri the real calendarUri
   321 	 * @return success of this function
   322 	 */
   323 	private boolean correctSyncID(String calendarUri) {
   324 		boolean Result = false;
   325 		Log.v(TAG, "correcting SyncID for calendar:" + this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME));
   327 		ContentValues mUpdateValues = new ContentValues();
   328 		mUpdateValues.put(DavCalendar.URI, calendarUri);
   330 		try {
   331 			mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null);
   332 			Result = true;
   333 		} catch (RemoteException e) {
   334 			e.printStackTrace();
   335 		}
   337 		return Result;
   338 	}
   340 	/**
   341 	 * COMPAT: the serverurl (CAL_SYNC2) was not sored within a calendar. this fixes it. (see #98)
   342 	 * @param serverUrl the current serverurl
   343 	 * @return success of this function
   344 	 */
   345 	private boolean correctServerUrl(String serverUrl) {
   346 		boolean Result = false;
   347 		Log.v(TAG, "correcting ServerUrl for calendar:" + this.getContentValueAsString(Calendars.CALENDAR_DISPLAY_NAME));
   349 		ContentValues mUpdateValues = new ContentValues();
   350 		mUpdateValues.put(DavCalendar.SERVERURL, serverUrl);
   352 		try {
   353 			mProvider.update(this.SyncAdapterCalendar(), mUpdateValues, null, null);
   354 			Result = true;
   355 		} catch (RemoteException e) {
   356 			e.printStackTrace();
   357 		}
   359 		return Result;
   360 	}
   362 	/**
   363 	 * creates a new androidCalendar
   364 	 * @param serverCalendar
   365 	 * @param index
   366 	 * @param context
   367 	 * @return the new androidCalendar or null if fails
   368 	 */
   369 	private DavCalendar createNewAndroidCalendar(DavCalendar serverCalendar, int index, android.content.Context context) {
   370 		Uri newUri = null;
   371 		DavCalendar Result = null;
   373 		final ContentValues contentValues = new ContentValues();
   374 		contentValues.put(DavCalendar.URI, serverCalendar.getURI().toString());
   375 		contentValues.put(DavCalendar.SERVERURL, this.ServerUrl);
   377 		contentValues.put(Calendars.VISIBLE, 1);
   378 		contentValues.put(Calendars.CALENDAR_DISPLAY_NAME, serverCalendar.getCalendarDisplayName());
   379 		contentValues.put(Calendars.ACCOUNT_NAME, mAccount.name);
   380 		contentValues.put(Calendars.ACCOUNT_TYPE, mAccount.type);
   381 		contentValues.put(Calendars.OWNER_ACCOUNT, mAccount.name);
   382 		contentValues.put(Calendars.SYNC_EVENTS, 1);
   383 		contentValues.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
   385 		if (!serverCalendar.getCalendarColorAsString().equals("")) {
   386 			contentValues.put(Calendars.CALENDAR_COLOR, serverCalendar.getCalendarColor());
   387 		} else {
   388 			// find a color
   389 			//int index = mList.size();
   390 			index = index % CalendarColors.colors.length;
   391 			contentValues.put(Calendars.CALENDAR_COLOR, CalendarColors.colors[index]);
   392 		}
   394 		try {
   395 			newUri = mProvider.insert(asSyncAdapter(Calendars.CONTENT_URI, mAccount.name, mAccount.type), contentValues);
   396 		} catch (RemoteException e) {
   397 			e.printStackTrace();
   398 		}
   400 		// it is possible that this calendar already exists but the provider failed to find it within isCalendarExist()
   401 		// the adapter would try to create a new calendar but the provider fails again to create a new calendar.
   402 		if (newUri != null) {
   403 			long newCalendarId = ContentUris.parseId(newUri);
   405 			Cursor cur = null;
   406 			Uri uri = Calendars.CONTENT_URI;   
   407 			String selection = "(" + Calendars._ID +  " = ?)";
   408 			String[] selectionArgs = new String[] {String.valueOf(newCalendarId)}; 
   410 			// Submit the query and get a Cursor object back. 
   411 			try {
   412 				cur = mProvider.query(uri, null, selection, selectionArgs, null);
   413 			} catch (RemoteException e) {
   414 				e.printStackTrace();
   415 			}
   417 			if (cur != null) {
   418 				while (cur.moveToNext()) {
   419 					Result = new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl);
   420 					Result.foundServerSide = true;
   421 				}
   422 				cur.close();
   423 				//if (Result != null)
   424 				//	this.mList.add(Result);
   425 			}
   426 			Log.i(TAG, "New calendar created : URI=" + Result.getAndroidCalendarUri());
   427 			NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "new calendar found: " + Result.getCalendarDisplayName());
   428 			mNotifyList.add(Result.getAndroidCalendarUri());
   429 		}
   431 		return Result;
   432 	}
   434 	/**
   435 	 * there is no corresponding calendar on server side. time to delete this calendar on android side.
   436 	 * @return 
   437 	 */
   438 	public boolean deleteAndroidCalendar() {
   439 		boolean Result = false;
   441 		String mSelectionClause = "(" + Calendars._ID + " = ?)";
   442 		int calendarId  = this.getAndroidCalendarId();
   443 		String[] mSelectionArgs = {Long.toString(calendarId)};
   445 		int CountDeleted = 0;
   446 		try {
   447 			CountDeleted = mProvider.delete(this.SyncAdapter(), mSelectionClause, mSelectionArgs);
   448 			Log.i(TAG,"Calendar deleted: " + String.valueOf(calendarId));
   449 			this.mNotifyList.add(this.getAndroidCalendarUri());
   450 			Result = true;
   451 		} catch (RemoteException e) {
   452 			e.printStackTrace();
   453 		}	
   454 		Log.d(TAG, "Android Calendars deleted: " + Integer.toString(CountDeleted));
   456 		return Result;
   457 	}
   459 	/**
   460 	 * updates the android calendar
   461 	 * @param calendarUri the uri of the androidCalendar
   462 	 * @param target must be from android.provider.CalendarContract.Calendars
   463 	 * @param value the new value for the target
   464 	 * @throws RemoteException
   465 	 */
   466 	private void updateAndroidCalendar(Uri calendarUri, String target, int value) throws RemoteException {
   467 		ContentValues mUpdateValues = new ContentValues();
   468 		mUpdateValues.put(target, value);
   470 		mProvider.update(asSyncAdapter(calendarUri, mAccount.name, mAccount.type), mUpdateValues, null, null);
   471 	}
   473 	/**
   474 	 * updates the android calendar
   475 	 * @param calendarUri the uri of the androidCalendar
   476 	 * @param target must be from android.provider.CalendarContract.Calendars
   477 	 * @param value the new value for the target
   478 	 * @throws RemoteException
   479 	 */
   480 	private void updateAndroidCalendar(Uri calendarUri, String target, String value) throws RemoteException {
   481 		ContentValues mUpdateValues = new ContentValues();
   482 		mUpdateValues.put(target, value);
   484 		mProvider.update(asSyncAdapter(calendarUri, mAccount.name, mAccount.type), mUpdateValues, null, null);
   485 	}
   487 	/**
   488 	 * marks the android event as already handled
   489 	 * @return
   490 	 * @see AndroidEvent#cInternalTag
   491 	 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats)
   492 	 * @throws RemoteException
   493 	 */
   494 	public boolean tagAndroidEvent(AndroidEvent androidEvent) throws RemoteException {
   495 		boolean Result = false;
   497 		ContentValues values = new ContentValues();
   498 		//values.put(Event.INTERNALTAG, 1);
   499 		values.put(Event.INTERNALTAG, mTagCounter);
   500 		//values.put(Event.INTERNALTAG, String.valueOf(mTagCounter));
   502 		int RowCount = this.mProvider.update(asSyncAdapter(androidEvent.getUri(), this.mAccount.name, this.mAccount.type), values, null, null);
   503 		//Log.v(TAG,"event tag nr: " + String.valueOf(mTagCounter));
   504 		//Log.v(TAG,"Rows updated: " + String.valueOf(RowCount));
   506 		if (RowCount == 1) {
   507 			Result = true;
   508 			mTagCounter += 1;
   509 		} else {
   510 			Log.v(TAG,"EVENT NOT TAGGED!");
   511 		}
   513 		return Result;
   514 	} 
   516 	/**
   517 	 * removes the tag of all android events
   518 	 * @return
   519 	 * @see AndroidEvent#cInternalTag
   520 	 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats)
   521 	 * @throws RemoteException
   522 	 */
   523 	public int untagAndroidEvents() throws RemoteException {
   524 		int RowCount = 0;
   525 		int Steps = 100;
   526 		ContentValues values = new ContentValues();
   527 		values.put(Event.INTERNALTAG, 0);
   529 		for (int i=1; i < this.mTagCounter; i = i + Steps) {
   530 			String mSelectionClause = "(CAST(" + Event.INTERNALTAG +  " AS INT) >= ?) AND (CAST(" + Event.INTERNALTAG +  " AS INT) < ?) AND (" + Events.CALENDAR_ID + " = ?)";
   531 			String[] mSelectionArgs = {String.valueOf(i), String.valueOf(i + Steps), Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))};
   532 			RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs);
   533 		}
   534 		/*String mSelectionClause = "(" + Event.INTERNALTAG +  " > ?) AND (" + Events.CALENDAR_ID + " = ?)";
   535 		String[] mSelectionArgs = {"0", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))};
   536 		RowCount += this.mProvider.update(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), values, mSelectionClause, mSelectionArgs);*/
   538 		//Log.d(TAG, "Rows reseted: " + RowCount.toString());
   539 		return RowCount;
   540 	}
   541 	/**
   542 	 * Events not being tagged are for deletion 
   543 	 * @return
   544 	 * @see AndroidEvent#cInternalTag
   545 	 * @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats)
   546 	 * @throws RemoteException
   547 	 */
   548 	public int deleteUntaggedEvents() throws RemoteException {
   549 		String mSelectionClause = "(" + Event.INTERNALTAG +  " < ?) AND (" + Events.CALENDAR_ID + " = ?)";
   550 		String[] mSelectionArgs = {"1", Long.toString(ContentUris.parseId(this.getAndroidCalendarUri()))};
   552 		int CountDeleted = this.mProvider.delete(asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), mSelectionClause, mSelectionArgs);	
   553 		//Log.d(TAG, "Rows deleted: " + CountDeleted.toString());
   554 		return CountDeleted;
   555 	}
   557 	private Uri SyncAdapterCalendar() {
   558 		return asSyncAdapter(this.getAndroidCalendarUri(), mAccount.name, mAccount.type);
   559 	}
   560 	private Uri SyncAdapter() {
   561 		return asSyncAdapter(Calendars.CONTENT_URI, mAccount.name, mAccount.type);
   562 	}
   563 	private static Uri asSyncAdapter(Uri uri, String account, String accountType) {
   564 	    return uri.buildUpon()
   565 	        .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true")
   566 	        .appendQueryParameter(Calendars.ACCOUNT_NAME, account)
   567 	        .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
   568 	}
   570 	public void setAccount(Account account) {
   571 		this.mAccount = account;
   572 	}
   573 	public void setProvider(ContentProviderClient provider) {
   574 		this.mProvider = provider;
   575 	}
   577 	/**
   578 	 * general access function to ContentValues
   579 	 * @param Item the item name from Calendars.*
   580 	 * @return the value for the item
   581 	 */
   582 	private String getContentValueAsString(String Item) {
   583 		String Result = "";
   584 		if (this.ContentValues.containsKey(Item))
   585 			Result = this.ContentValues.getAsString(Item);
   586 		return Result;
   587 	}
   588 	/**
   589 	 * general access function to ContentValues
   590 	 * @param Item the item name from Calendars.*
   591 	 * @return the value for the item
   592 	 */
   593 	private int getContentValueAsInt(String Item) {
   594 		int Result = 0;
   595 		if (this.ContentValues.containsKey(Item))
   596 			Result = this.ContentValues.getAsInteger(Item);
   597 		return Result;
   598 	}
   600 	/**
   601 	 * general access function to ContentValues
   602 	 * @param Item the item name from Calendars.*
   603 	 * @param Value the value for the item
   604 	 * @return success of this function
   605 	 */
   606 	private boolean setContentValueAsString(String Item, String Value) {
   607 		boolean Result = false;
   609 		if (this.ContentValues.containsKey(Item))
   610 			this.ContentValues.remove(Item);
   611 		this.ContentValues.put(Item, Value);
   613 		return Result;
   614 	}
   616 	/**
   617 	 * general access function to ContentValues
   618 	 * @param Item the item name from Calendars.*
   619 	 * @param Value the value for the item
   620 	 * @return success of this function
   621 	 */
   622 	private boolean setContentValueAsInt(String Item, int Value) {
   623 		boolean Result = false;
   625 		if (this.ContentValues.containsKey(Item))
   626 			this.ContentValues.remove(Item);
   627 		this.ContentValues.put(Item, Value);
   629 		return Result;
   630 	}
   632 	public ArrayList<Uri> getNotifyList() {
   633 		return this.mNotifyList;
   634 	}
   636 	public ArrayList<CalendarEvent> getCalendarEvents() {
   637 		return this.mCalendarEvents;
   638 	}
   640 	public boolean readCalendarEvents(CaldavFacade facade) {
   641 		boolean Result = false;
   643 		try {
   644 			this.mCalendarEvents = facade.getCalendarEvents(this);
   645 			Result = true;
   646 		} catch (ClientProtocolException e) {
   647 			e.printStackTrace();
   648 			Result = false;
   649 		} catch (URISyntaxException e) {
   650 			e.printStackTrace();
   651 			Result = false;
   652 		} catch (IOException e) {
   653 			e.printStackTrace();
   654 			Result = false;
   655 		} catch (ParserConfigurationException e) {
   656 			e.printStackTrace();
   657 			Result = false;
   658 		} catch (SAXException e) {
   659 			e.printStackTrace();
   660 			Result = false;
   661 		}
   663 		return Result;
   664 	}
   666 }

mercurial