From cf2c2eedc56dfd3b4b116b82a907ce72c59b942b Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Sun, 8 Apr 2012 18:41:23 +0200 Subject: [PATCH] send contacts to oc instance --- AndroidManifest.xml | 161 ++++++++++++++------- res/xml/contacts.xml | 2 +- .../FileContentProvider.java} | 4 +- .../owncloud/syncadapter/ContactSyncAdapter.java | 98 +++++++++++++ .../owncloud/syncadapter/ContactSyncService.java | 25 ++++ .../owncloud/syncadapter/FileSyncAdapter.java | 2 +- src/eu/alefzero/owncloud/ui/fragment/FileList.java | 42 ++++++ 7 files changed, 276 insertions(+), 58 deletions(-) rename src/eu/alefzero/owncloud/{cp.java => providers/FileContentProvider.java} (96%) create mode 100644 src/eu/alefzero/owncloud/syncadapter/ContactSyncAdapter.java create mode 100644 src/eu/alefzero/owncloud/syncadapter/ContactSyncService.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 12cd5911..4c1ac1ca 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,76 +1,129 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + - - - + + + + + + + + - - - + + + + + + - + + - + + + + + + + + - + + + android:resource="@xml/syncadapter_contacts" /> + + + + + + + + + + - - - - - - - + + + + + + - + + \ No newline at end of file diff --git a/res/xml/contacts.xml b/res/xml/contacts.xml index 88709417..e55f1264 100644 --- a/res/xml/contacts.xml +++ b/res/xml/contacts.xml @@ -20,7 +20,7 @@ operationList = new ArrayList(); + + //Create our RawContact + ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); + builder.withValue(RawContacts.ACCOUNT_NAME, account.name); + builder.withValue(RawContacts.ACCOUNT_TYPE, account.type); + builder.withValue(RawContacts.SYNC1, username); + operationList.add(builder.build()); + + //Create a Data record of common type 'StructuredName' for our RawContact + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name); + operationList.add(builder.build()); + + //Create a Data record of custom type "vnd.android.cursor.item/vnd.fm.last.android.profile" to display a link to the Last.fm profile + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); + builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.owncloud.contact.profile"); + builder.withValue(ContactsContract.Data.DATA1, username); + builder.withValue(ContactsContract.Data.DATA2, "Last.fm Profile"); + builder.withValue(ContactsContract.Data.DATA3, "View profile"); + operationList.add(builder.build()); + + try { + getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList); + } catch (Exception e) { + Log.e("ASD", "Something went wrong during creation! " + e); + e.printStackTrace(); + } + } + } -- 2.11.0