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

Tue, 10 Feb 2015 22:40:00 +0100

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

Merge https://github.com/gggard/AndroidCaldavSyncAdapater/pull/206/

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

mercurial