TestCalendarSyncAdapterpublic 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 |
Methods Summary |
---|
public void | getServerDiffs(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 boolean | isReadOnly()
return false;
| public void | onAccountsChanged(java.lang.String[] accounts)
| public void | onSyncCanceled()
throw new UnsupportedOperationException("not implemented");
| public void | onSyncEnding(android.content.SyncContext context, boolean success)
| public void | onSyncStarting(android.content.SyncContext context, java.lang.String account, boolean forced, android.content.SyncResult result)
| public void | sendClientDiffs(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();
|
|