Revert "updating the SampleSyncAdapter sample to add stream item and photo code"
This reverts commit 7a98345fc5229a23b4490713991f78170374dd11
diff --git a/samples/SampleSyncAdapter/AndroidManifest.xml b/samples/SampleSyncAdapter/AndroidManifest.xml
index 48f6fad..285abfb 100644
--- a/samples/SampleSyncAdapter/AndroidManifest.xml
+++ b/samples/SampleSyncAdapter/AndroidManifest.xml
@@ -45,12 +45,8 @@
android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission
android:name="android.permission.WRITE_SYNC_SETTINGS" />
- <uses-permission
- android:name="android.permission.READ_SOCIAL_STREAM" />
- <uses-permission
- android:name="android.permission.WRITE_SOCIAL_STREAM" />
- <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
+ <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/>
<application
android:icon="@drawable/icon"
diff --git a/samples/SampleSyncAdapter/res/raw/img1.jpg b/samples/SampleSyncAdapter/res/raw/img1.jpg
deleted file mode 100644
index 24a492c..0000000
--- a/samples/SampleSyncAdapter/res/raw/img1.jpg
+++ /dev/null
Binary files differ
diff --git a/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/BatchOperation.java b/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/BatchOperation.java
index f70547b..3a9c879 100644
--- a/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/BatchOperation.java
+++ b/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/BatchOperation.java
@@ -26,7 +26,6 @@
import android.util.Log;
import java.util.ArrayList;
-import java.util.List;
/**
* This class handles execution of batch mOperations on Contacts provider.
@@ -53,27 +52,24 @@
mOperations.add(cpo);
}
- public List<Uri> execute() {
- List<Uri> resultUris = new ArrayList<Uri>();
+ public Uri execute() {
+ Uri result = null;
if (mOperations.size() == 0) {
- return resultUris;
+ return result;
}
// Apply the mOperations to the content provider
try {
ContentProviderResult[] results = mResolver.applyBatch(ContactsContract.AUTHORITY,
mOperations);
- if ((results != null) && (results.length > 0)){
- for (int i = 0; i < results.length; i++){
- resultUris.add(results[i].uri);
- }
- }
+ if ((results != null) && (results.length > 0))
+ result = results[0].uri;
} catch (final OperationApplicationException e1) {
Log.e(TAG, "storing contact data failed", e1);
} catch (final RemoteException e2) {
Log.e(TAG, "storing contact data failed", e2);
}
mOperations.clear();
- return resultUris;
+ return result;
}
}
diff --git a/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/ContactManager.java b/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/ContactManager.java
index dbda0b6..6b2dfb1 100644
--- a/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/ContactManager.java
+++ b/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/ContactManager.java
@@ -24,10 +24,7 @@
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
-import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
@@ -41,14 +38,8 @@
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.Settings;
import android.provider.ContactsContract.StatusUpdates;
-import android.provider.ContactsContract.StreamItemPhotos;
-import android.provider.ContactsContract.StreamItems;
import android.util.Log;
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -244,43 +235,6 @@
}
/**
- * Demonstrate how to add stream items and stream item photos to a raw
- * contact. This just adds items for all of the contacts for this sync
- * adapter with some locally created text and an image. You should check
- * for stream items on the server that you are syncing with and use the
- * text and photo data from there instead.
- *
- * @param context The context of Authenticator Activity
- * @param rawContacts The list of users we want to update
- */
- public static void addStreamItems(Context context, List<RawContact> 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<Uri> 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'
* flag on the synced contacts - but we also have to finish the DELETE operation
@@ -564,7 +518,7 @@
* But it's a useful demo to see how it's done.
*
* @param context the Authenticator Activity context
- * @param rawContact the contact whose status we should update
+ * @param rawContact the contact who's status we should update
* @param batchOperation allow us to batch together multiple operations
*/
private static void updateContactStatus(Context context, RawContact rawContact,
@@ -596,59 +550,6 @@
}
/**
- * 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.
*
* @param context the Authenticator Activity context
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 eeb0830..0f570cd 100644
--- a/samples/SampleSyncAdapter/src/com/example/android/samplesync/syncadapter/SyncAdapter.java
+++ b/samples/SampleSyncAdapter/src/com/example/android/samplesync/syncadapter/SyncAdapter.java
@@ -115,21 +115,8 @@
// 2-way contact sync providers - it's more likely that one-way
// sync providers (IM clients, social networking apps, etc) would
// use this feature.
-
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);