am 27305158: Remove stream activities from sample sync adapter

* commit '27305158a1b408255885797adfd2c2102b8add2b':
  Remove stream activities from sample sync adapter
This commit is contained in:
Brian Attwell
2014-04-10 19:23:23 +00:00
committed by Android Git Automerger
9 changed files with 1 additions and 299 deletions

View File

@@ -104,7 +104,7 @@
</activity> </activity>
<activity <activity
android:name=".activites.InviteContactActivity" android:name=".activities.InviteContactActivity"
android:theme="@android:style/Theme.Dialog"> android:theme="@android:style/Theme.Dialog">
<!-- <!--
We use the INVITE intent to add a raw contact to an existing contact. We use the INVITE intent to add a raw contact to an existing contact.
@@ -133,34 +133,5 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".activities.ViewStreamItemActivity"
android:theme="@android:style/Theme.Dialog">
<!--
We use the VIEW intent to view a stream item in our app.
It always comes with a lookup URI.
-->
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<data
android:mimeType="vnd.android.cursor.item/stream_item" />
</intent-filter>
</activity>
<activity
android:name=".activities.ViewStreamItemPhotoActivity"
android:theme="@android:style/Theme.Dialog">
<!--
We use the VIEW intent to view a stream item photo in our app.
It always comes with a lookup URI.
-->
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<data
android:mimeType="vnd.android.cursor.item/stream_item_photo" />
</intent-filter>
</activity>
</application> </application>
</manifest> </manifest>

View File

@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
/**
* Copyright (c) 2011, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="@string/view_stream_item_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/view_stream_item_uri"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
/**
* Copyright (c) 2011, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="@string/view_stream_item_photo_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/view_stream_item_photo_uri"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@@ -129,14 +129,4 @@
This is the group uri:</string> This is the group uri:</string>
<!-- The description for the view stream item -->
<string name="view_stream_item_description">This would now show the details of the stream item.
This is the uri of the stream item:</string>
<!-- The description for the view stream item photo -->
<string name="view_stream_item_photo_description">This would now show the details of the stream item photo.
This is the uri of the photo:</string>
</resources> </resources>

View File

@@ -24,8 +24,6 @@
viewContactNotifyService="com.example.android.samplesync.notifier.NotifierService" viewContactNotifyService="com.example.android.samplesync.notifier.NotifierService"
viewGroupActivity="com.example.android.samplesync.activities.ViewGroupActivity" viewGroupActivity="com.example.android.samplesync.activities.ViewGroupActivity"
viewGroupActionLabel="@string/view_group_action_label" viewGroupActionLabel="@string/view_group_action_label"
viewStreamItemActivity="com.example.android.samplesync.activities.ViewStreamItemActivity"
viewStreamItemPhotoActivity="com.example.android.samplesync.activities.ViewStreamItemPhotoActivity"
> >
<ContactsDataKind <ContactsDataKind

View File

@@ -1,41 +0,0 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.example.android.samplesync.activities;
import com.example.android.samplesync.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
* Activity to handle view a stream-item. In a real app, this would show a rich view of the
* item.
*/
public class ViewStreamItemActivity extends Activity {
private static final String TAG = "ViewStreamItemActivity";
private TextView mUriTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_stream_item_activity);
mUriTextView = (TextView) findViewById(R.id.view_stream_item_uri);
mUriTextView.setText(getIntent().getDataString());
}
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.example.android.samplesync.activities;
import com.example.android.samplesync.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
* Activity to view a stream-item-photo. In a real app, this would show a fullscreen view of the
* photo, potentially with ways to interact with it
*/
public class ViewStreamItemPhotoActivity extends Activity {
private static final String TAG = "ViewStreamItemPhotoActivity";
private TextView mUriTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_stream_item_photo_activity);
mUriTextView = (TextView) findViewById(R.id.view_stream_item_photo_uri);
mUriTextView.setText(getIntent().getDataString());
}
}

View File

@@ -24,10 +24,7 @@ import android.content.ContentResolver;
import android.content.ContentUris; import android.content.ContentUris;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Email;
@@ -41,14 +38,8 @@ import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.Settings; import android.provider.ContactsContract.Settings;
import android.provider.ContactsContract.StatusUpdates; import android.provider.ContactsContract.StatusUpdates;
import android.provider.ContactsContract.StreamItemPhotos;
import android.provider.ContactsContract.StreamItems;
import android.util.Log; 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.ArrayList;
import java.util.List; import java.util.List;
@@ -243,43 +234,6 @@ public class ContactManager {
batchOperation.execute(); batchOperation.execute();
} }
/**
* 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 * 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' * 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. * Clear the local system 'dirty' flag for a contact.
* *

View File

@@ -119,18 +119,6 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
ContactManager.updateStatusMessages(mContext, updatedContacts); 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 // Save off the new sync marker. On our next sync, we only want to receive
// contacts that have changed since this sync... // contacts that have changed since this sync...
setServerSyncMarker(account, newSyncState); setServerSyncMarker(account, newSyncState);