From 27305158a1b408255885797adfd2c2102b8add2b Mon Sep 17 00:00:00 2001 From: Brian Attwell Date: Tue, 11 Feb 2014 19:20:32 -0800 Subject: [PATCH] Remove stream activities from sample sync adapter Also fixed existing bug that prevented the "Add Connection" from working for the Ssample Sync Adapter. Bug: 11629361 Change-Id: I17940cc97ebef3e05dc53e534d5765395ba353a3 --- samples/SampleSyncAdapter/AndroidManifest.xml | 31 +----- .../res/layout/view_stream_item_activity.xml | 32 ------ .../view_stream_item_photo_activity.xml | 32 ------ .../SampleSyncAdapter/res/values/strings.xml | 10 -- .../res/xml-v14/contacts.xml | 2 - .../activities/ViewStreamItemActivity.java | 41 -------- .../ViewStreamItemPhotoActivity.java | 41 -------- .../samplesync/platform/ContactManager.java | 99 ------------------- .../samplesync/syncadapter/SyncAdapter.java | 12 --- 9 files changed, 1 insertion(+), 299 deletions(-) delete mode 100644 samples/SampleSyncAdapter/res/layout/view_stream_item_activity.xml delete mode 100644 samples/SampleSyncAdapter/res/layout/view_stream_item_photo_activity.xml delete mode 100644 samples/SampleSyncAdapter/src/com/example/android/samplesync/activities/ViewStreamItemActivity.java delete mode 100644 samples/SampleSyncAdapter/src/com/example/android/samplesync/activities/ViewStreamItemPhotoActivity.java diff --git a/samples/SampleSyncAdapter/AndroidManifest.xml b/samples/SampleSyncAdapter/AndroidManifest.xml index 48f6fadcd..7402f9d52 100644 --- a/samples/SampleSyncAdapter/AndroidManifest.xml +++ b/samples/SampleSyncAdapter/AndroidManifest.xml @@ -104,7 +104,7 @@ - - - - - - - - - - - - - diff --git a/samples/SampleSyncAdapter/res/layout/view_stream_item_activity.xml b/samples/SampleSyncAdapter/res/layout/view_stream_item_activity.xml deleted file mode 100644 index a04d07fe2..000000000 --- a/samples/SampleSyncAdapter/res/layout/view_stream_item_activity.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - diff --git a/samples/SampleSyncAdapter/res/layout/view_stream_item_photo_activity.xml b/samples/SampleSyncAdapter/res/layout/view_stream_item_photo_activity.xml deleted file mode 100644 index ddc09d098..000000000 --- a/samples/SampleSyncAdapter/res/layout/view_stream_item_photo_activity.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - diff --git a/samples/SampleSyncAdapter/res/values/strings.xml b/samples/SampleSyncAdapter/res/values/strings.xml index 22fe14ec7..84c94d1c5 100644 --- a/samples/SampleSyncAdapter/res/values/strings.xml +++ b/samples/SampleSyncAdapter/res/values/strings.xml @@ -129,14 +129,4 @@ This is the group uri: - - This would now show the details of the stream item. - - This is the uri of the stream item: - - - This would now show the details of the stream item photo. - - This is the uri of the photo: - \ No newline at end of file diff --git a/samples/SampleSyncAdapter/res/xml-v14/contacts.xml b/samples/SampleSyncAdapter/res/xml-v14/contacts.xml index 48e079adc..b4ad2a0fd 100644 --- a/samples/SampleSyncAdapter/res/xml-v14/contacts.xml +++ b/samples/SampleSyncAdapter/res/xml-v14/contacts.xml @@ -24,8 +24,6 @@ viewContactNotifyService="com.example.android.samplesync.notifier.NotifierService" viewGroupActivity="com.example.android.samplesync.activities.ViewGroupActivity" viewGroupActionLabel="@string/view_group_action_label" - viewStreamItemActivity="com.example.android.samplesync.activities.ViewStreamItemActivity" - viewStreamItemPhotoActivity="com.example.android.samplesync.activities.ViewStreamItemPhotoActivity" > rawContacts, - String accountName, String accountType) { - final ContentResolver resolver = context.getContentResolver(); - final BatchOperation batchOperation = new BatchOperation(context, resolver); - String text = "This is a test stream item!"; - String message = "via SampleSyncAdapter"; - for (RawContact rawContact : rawContacts) { - addContactStreamItem(context, lookupRawContact(resolver, - rawContact.getServerContactId()), accountName, accountType, - text, message, batchOperation ); - } - List streamItemUris = batchOperation.execute(); - - // Stream item photos are added after the stream items that they are - // associated with, using the stream item's ID as a reference. - - for (Uri uri : streamItemUris){ - // All you need is the ID of the stream item, which is the last index - // path segment returned by getPathSegments(). - long streamItemId = Long.parseLong(uri.getPathSegments().get( - uri.getPathSegments().size()-1)); - addStreamItemPhoto(context, resolver, streamItemId, accountName, - accountType, batchOperation); - } - batchOperation.execute(); - } - /** * After we've finished up a sync operation, we want to clean up the sync-state * so that we're ready for the next time. This involves clearing out the 'dirty' @@ -595,59 +549,6 @@ public class ContactManager { } } - /** - * Adds a stream item to a raw contact. The stream item is usually obtained - * from the server you are syncing with, but we create it here locally as an - * example. - * - * @param context the Authenticator Activity context - * @param rawContactId the raw contact ID that the stream item is associated with - * @param accountName the account name of the sync adapter - * @param accountType the account type of the sync adapter - * @param text the text of the stream item - * @param comments the comments for the stream item, such as where the stream item came from - * @param batchOperation allow us to batch together multiple operations - */ - private static void addContactStreamItem(Context context, long rawContactId, - String accountName, String accountType, String text, String comments, - BatchOperation batchOperation) { - - final ContentValues values = new ContentValues(); - final ContentResolver resolver = context.getContentResolver(); - if (rawContactId > 0){ - values.put(StreamItems.RAW_CONTACT_ID, rawContactId); - values.put(StreamItems.TEXT, text); - values.put(StreamItems.TIMESTAMP, System.currentTimeMillis()); - values.put(StreamItems.COMMENTS, comments); - values.put(StreamItems.ACCOUNT_NAME, accountName); - values.put(StreamItems.ACCOUNT_TYPE, accountType); - - batchOperation.add(ContactOperations.newInsertCpo( - StreamItems.CONTENT_URI, false, true).withValues(values).build()); - } - } - - private static void addStreamItemPhoto(Context context, ContentResolver - resolver, long streamItemId, String accountName, String accountType, - BatchOperation batchOperation){ - - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), - R.raw.img1); - bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream); - byte[] photoData = stream.toByteArray(); - - final ContentValues values = new ContentValues(); - values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); - values.put(StreamItemPhotos.SORT_INDEX, 1); - values.put(StreamItemPhotos.PHOTO, photoData); - values.put(StreamItems.ACCOUNT_NAME, accountName); - values.put(StreamItems.ACCOUNT_TYPE, accountType); - - batchOperation.add(ContactOperations.newInsertCpo( - StreamItems.CONTENT_PHOTO_URI, false, true).withValues(values).build()); - } - /** * Clear the local system 'dirty' flag for a contact. * diff --git a/samples/SampleSyncAdapter/src/com/example/android/samplesync/syncadapter/SyncAdapter.java b/samples/SampleSyncAdapter/src/com/example/android/samplesync/syncadapter/SyncAdapter.java index 8aa078481..714452445 100644 --- a/samples/SampleSyncAdapter/src/com/example/android/samplesync/syncadapter/SyncAdapter.java +++ b/samples/SampleSyncAdapter/src/com/example/android/samplesync/syncadapter/SyncAdapter.java @@ -119,18 +119,6 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { ContactManager.updateStatusMessages(mContext, updatedContacts); - // This is a demo of how you can add stream items for contacts on - // the client. This probably won't apply to - // 2-way contact sync providers - it's more likely that one-way - // sync providers (IM clients, social networking apps, etc) would - // use this feature. This is only supported in ICS MR1 or above. - - if (Build.VERSION.SDK_INT >= - Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { - ContactManager.addStreamItems(mContext, updatedContacts, - account.name, account.type); - } - // Save off the new sync marker. On our next sync, we only want to receive // contacts that have changed since this sync... setServerSyncMarker(account, newSyncState);