FileDocCategorySizeDatePackage
TestCalendarSyncAdapter.javaAPI DocAndroid 1.5 API5983Wed May 06 22:42:48 BST 2009com.android.providers.calendar

TestCalendarSyncAdapter

public class TestCalendarSyncAdapter extends android.content.TempProviderSyncAdapter

Fields Summary
private static android.net.Uri
sEventsURL
private static android.net.Uri
sDeletedEventsURL
private int
mClientEventID
private static int
sSyncClock
Constructors Summary
public TestCalendarSyncAdapter(android.content.SyncableContentProvider provider)


       
        super(provider);
    
Methods Summary
public voidgetServerDiffs(android.content.SyncContext context, SyncData syncData, android.content.SyncableContentProvider tempProvider, android.os.Bundle extras, java.lang.Object syncInfo, android.content.SyncResult syncResult)

        switch(sSyncClock) {
            case 1: {
                ContentValues values = new ContentValues();
                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

                values.put("title", "Sync performed");
                values.put("dtstart", DateUtils.writeDateTime(cal, true));
                values.put("duration", "PT1S");
                values.put("_sync_id", "server_event_1");
                values.put("_sync_time", Long.valueOf(System.currentTimeMillis()));

                tempProvider.insert(sEventsURL, values);
                break;
            }

            case 2: {
                ContentValues values = new ContentValues();
                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                cal.clear();
                cal.set(1979, Calendar.APRIL, 6, 0, 0);

                values.put("title", "Jeff's b-day");
                values.put("dtstart", DateUtils.writeDateTime(cal, true));
                values.put("duration", "PT1D");
                values.put("_sync_id", "server_event_2");
                values.put("_sync_time", Long.valueOf(System.currentTimeMillis()));

                tempProvider.insert(sEventsURL, values);
                break;
            }

            case 3: {
                ContentValues values = new ContentValues();
                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                cal.clear();
                cal.set(1979, Calendar.APRIL, 6, 0, 0);

                values.put("title", "Jeff's Birthday");
                values.put("dtstart", DateUtils.writeDateTime(cal, true));
                values.put("duration", "PT1D");
                values.put("_sync_id", "server_event_2");
                values.put("_sync_time", Long.valueOf(System.currentTimeMillis()));

                tempProvider.insert(sEventsURL, values);
                break;
            }

            case 4: {
                ContentValues values = new ContentValues();
                values.put("_sync_id", "server_event_1");
                tempProvider.insert(sDeletedEventsURL, values);
                break;
            }

            case 5: {
                ContentValues values = new ContentValues();
                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                cal.clear();
                cal.set(1979, Calendar.APRIL, 6, 0, 0);

                values.put("title", "Jeff Hamilton's Birthday");
                values.put("dtstart", DateUtils.writeDateTime(cal, true));
                values.put("duration", "PT1D");
                values.put("_sync_id", "server_event_2");
                values.put("_sync_time", Long.valueOf(System.currentTimeMillis()));

                tempProvider.insert(sEventsURL, values);
                break;
            }
        }

        sSyncClock++;
    
public booleanisReadOnly()

        return false;
    
public voidonAccountsChanged(java.lang.String[] accounts)

    
public voidonSyncCanceled()


    
       
        throw new UnsupportedOperationException("not implemented");
    
public voidonSyncEnding(android.content.SyncContext context, boolean success)

    
public voidonSyncStarting(android.content.SyncContext context, java.lang.String account, boolean forced, android.content.SyncResult result)

    
public voidsendClientDiffs(android.content.SyncContext context, android.content.SyncableContentProvider clientDiffs, android.content.SyncableContentProvider serverDiffs, android.content.SyncResult syncResult, boolean dontActuallySendDeletes)

        Cursor cursor = clientDiffs.query(sEventsURL, null, null, null, null);
        if (cursor == null || cursor.getCount() == 0) {
            throw new IllegalStateException("Empty client diffs");
        }

        int syncIDColumn = cursor.getColumnIndex("_sync_id");
        int syncTimeColumn = cursor.getColumnIndex("_sync_time");
        while(cursor.moveToNext()) {
            cursor.updateString(syncIDColumn, "client_event_" + mClientEventID++);
            cursor.updateLong(syncTimeColumn, System.currentTimeMillis());
        }
        cursor.commitUpdates();
        cursor.deactivate();