summaryrefslogtreecommitdiffstats
path: root/core/java/android/pim/vcard
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2009-09-17 16:39:11 -0700
committerDaisuke Miyakawa <dmiyakawa@google.com>2009-09-17 18:40:03 -0700
commit5fd2ae90d300b271895e29dde8a185c46ba214a8 (patch)
tree96fb5997b880fa5ceb2a5a57fdb6c2d6bee55122 /core/java/android/pim/vcard
parent6449eb06acc934ba4007475680f236721181ee47 (diff)
downloadframeworks_base-5fd2ae90d300b271895e29dde8a185c46ba214a8.zip
frameworks_base-5fd2ae90d300b271895e29dde8a185c46ba214a8.tar.gz
frameworks_base-5fd2ae90d300b271895e29dde8a185c46ba214a8.tar.bz2
Add each contact in vCard into "My Groups" if account is for Google's and it has such a group.
This fix should be temporal. Should be fixed in the near future. Internal issue id: 2126265
Diffstat (limited to 'core/java/android/pim/vcard')
-rw-r--r--core/java/android/pim/vcard/ContactStruct.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/java/android/pim/vcard/ContactStruct.java b/core/java/android/pim/vcard/ContactStruct.java
index 06b0636..b212f5a 100644
--- a/core/java/android/pim/vcard/ContactStruct.java
+++ b/core/java/android/pim/vcard/ContactStruct.java
@@ -20,11 +20,14 @@ import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.OperationApplicationException;
+import android.database.Cursor;
import android.os.RemoteException;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Data;
+import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.Email;
+import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
import android.provider.ContactsContract.CommonDataKinds.Im;
import android.provider.ContactsContract.CommonDataKinds.Miscellaneous;
import android.provider.ContactsContract.CommonDataKinds.Nickname;
@@ -1023,14 +1026,37 @@ public class ContactStruct {
}
}
+ // From HardCodedSources.java in Contacts app.
+ // TODO: fix this.
+ private static final String ACCOUNT_TYPE_GOOGLE = "com.google.GAIA";
+ private static final String GOOGLE_MY_CONTACTS_GROUP = "System Group: My Contacts";
+
public void pushIntoContentResolver(ContentResolver resolver) {
ArrayList<ContentProviderOperation> operationList =
new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder =
ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
+ String myGroupsId = null;
if (mAccount != null) {
builder.withValue(RawContacts.ACCOUNT_NAME, mAccount.name);
builder.withValue(RawContacts.ACCOUNT_TYPE, mAccount.type);
+
+ // TODO: temporal fix for "My Groups" issue. Need to be refactored.
+ if (ACCOUNT_TYPE_GOOGLE.equals(mAccount.type)) {
+ final Cursor cursor = resolver.query(Groups.CONTENT_URI, new String[] {
+ Groups.SOURCE_ID },
+ Groups.TITLE + "=?", new String[] {
+ GOOGLE_MY_CONTACTS_GROUP }, null);
+ try {
+ if (cursor != null && cursor.moveToFirst()) {
+ myGroupsId = cursor.getString(0);
+ }
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ }
} else {
builder.withValues(new ContentValues());
}
@@ -1196,6 +1222,14 @@ public class ContactStruct {
operationList.add(builder.build());
}
+ if (myGroupsId != null) {
+ builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
+ builder.withValueBackReference(GroupMembership.RAW_CONTACT_ID, 0);
+ builder.withValue(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE);
+ builder.withValue(GroupMembership.GROUP_SOURCE_ID, myGroupsId);
+ operationList.add(builder.build());
+ }
+
try {
resolver.applyBatch(ContactsContract.AUTHORITY, operationList);
} catch (RemoteException e) {