# HG changeset patch # User "Vincent Veronis" # Date 1304764005 -7200 # Node ID 5d3163053c425bed132c216769c6e98830fd7f1a # Parent 193a934390ba914545ae649abc5c1bc1b081459b SyncContact OK BuildRaw Contact OK diff -r 193a934390ba -r 5d3163053c42 AndroidManifest.xml --- a/AndroidManifest.xml Thu Apr 21 21:05:25 2011 +0200 +++ b/AndroidManifest.xml Sat May 07 12:26:45 2011 +0200 @@ -56,6 +56,15 @@ + + + + + + android:syncable="true" + android:exported="true" /> + + + diff -r 193a934390ba -r 5d3163053c42 res/xml/preferences.xml --- a/res/xml/preferences.xml Thu Apr 21 21:05:25 2011 +0200 +++ b/res/xml/preferences.xml Sat May 07 12:26:45 2011 +0200 @@ -23,14 +23,9 @@ - - - + android:title="Prefer WiFi"> + + \ No newline at end of file diff -r 193a934390ba -r 5d3163053c42 res/xml/sync_contacts.xml --- a/res/xml/sync_contacts.xml Thu Apr 21 21:05:25 2011 +0200 +++ b/res/xml/sync_contacts.xml Sat May 07 12:26:45 2011 +0200 @@ -1,3 +1,5 @@ - \ No newline at end of file + \ No newline at end of file diff -r 193a934390ba -r 5d3163053c42 src/com/beem/project/beem/account/SyncAdapterService.java --- a/src/com/beem/project/beem/account/SyncAdapterService.java Thu Apr 21 21:05:25 2011 +0200 +++ b/src/com/beem/project/beem/account/SyncAdapterService.java Sat May 07 12:26:45 2011 +0200 @@ -51,6 +51,7 @@ import org.jivesoftware.smack.RosterGroup; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.packet.Presence; import android.accounts.Account; import android.accounts.OperationCanceledException; @@ -69,11 +70,18 @@ import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; +import android.provider.BaseColumns; import android.provider.ContactsContract; -import android.provider.ContactsContract.CommonDataKinds.StructuredName; +import android.provider.ContactsContract.RawContacts; +import android.provider.ContactsContract.RawContacts.Entity; import android.util.Log; +import android.widget.ImageButton; +import android.widget.ImageView; import com.beem.project.beem.BeemConnection; +import com.beem.project.beem.R; +import com.beem.project.beem.providers.AvatarProvider; +import com.beem.project.beem.utils.Status; /** * Class to integrate beem in android's account @@ -120,7 +128,7 @@ * @param authority authority * @param provider provider * @param syncResult syncResult - * @throws OperationCanceledException OperationCanceledException + * @throws OperationCanceledException OperationCanceledException */ public static void performSync(Context context, final Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException { @@ -135,7 +143,6 @@ con.connect(); con.login(beemco.getLogin(), beemco.getPassword(), "BEEM_SYNC_ADAPTER"); roster = con.getRoster(); - } catch (XMPPException e) { Log.e(TAG, "Error while connecting with syncAdapter", e); } catch (IllegalStateException e) { @@ -144,9 +151,7 @@ if (roster != null) { manageRoster(roster, account); } - con.disconnect(); - } private static void executeOperation(ArrayList ops) { @@ -161,26 +166,29 @@ private static void manageRoster(final Roster r, final Account a) { ArrayList ops = new ArrayList(); - for (RosterEntry entry : r.getEntries()) { if (entry != null) { - manageEntry(ops, a, entry); + long rawContactID = manageEntry(ops, a, entry); + if (rawContactID != -1) + updateContactStatus(ops, entry, rawContactID, r.getPresence(entry.getUser())); } if (ops.size() > 100) executeOperation(ops); } - for (RosterGroup group : r.getGroups()) { - if (group != null) { - manageGroup(ops, a, group); - } - } + // TODO: dont know how to ttest + // for (RosterGroup group : r.getGroups()) { + // if (group != null) + // manageGroup(ops, a, group); + // if (ops.size() > 0) + // executeOperation(ops); + // } if (ops.size() > 0) executeOperation(ops); } - private static void manageEntry(ArrayList ops, Account account, RosterEntry entry) { + private static long manageEntry(ArrayList ops, Account account, RosterEntry entry) { long rawContactID = getRawContactID(account.name, entry.getUser()); - Log.i(TAG, "Sync Contact : " + entry.getUser()); + Log.i(TAG, "Sync Contact : " + entry.getUser() + " RawContactID : " + rawContactID); if (rawContactID == -1) { // Not found in database, add new ContentValues values = new ContentValues(); values.put(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type); @@ -189,43 +197,77 @@ Uri rawContactUri = mContentResolver.insert(ContactsContract.RawContacts.CONTENT_URI, values); rawContactID = ContentUris.parseId(rawContactUri); values.clear(); - ContentProviderOperation.Builder builder = buildStructuredName(ContentProviderOperation - .newInsert(ContactsContract.Data.CONTENT_URI), entry, rawContactID); + ContentProviderOperation.Builder builder = BuildProfile(entry, rawContactID); + ops.add(builder.build()); + builder = buildStructuredName(entry, rawContactID); ops.add(builder.build()); } else { // Found, update - // if newUpdate instead of newInster ... fail update : all rows = 1 row - ContentProviderOperation.Builder builder = buildStructuredName(ContentProviderOperation - .newInsert(ContactsContract.Data.CONTENT_URI), entry, rawContactID); + ContentProviderOperation.Builder builder = buildStructuredName(entry, rawContactID); ops.add(builder.build()); } + return rawContactID; } - + private static void manageGroup(ArrayList ops, Account account, RosterGroup group) { Log.i(TAG, "Sync Group : " + group.getName()); - ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.Groups.CONTENT_URI ); + ContentProviderOperation.Builder builder = ContentProviderOperation + .newInsert(ContactsContract.Groups.CONTENT_URI); builder.withValue(ContactsContract.Groups.TITLE, group.getName()); + builder.withValue(ContactsContract.Settings.UNGROUPED_VISIBLE, true); } - - - private static ContentProviderOperation.Builder buildStructuredName(ContentProviderOperation.Builder builder, - RosterEntry entry, long rawContactID) { + private static ContentProviderOperation.Builder buildStructuredName(RosterEntry entry, long rawContactID) { + ContentProviderOperation.Builder builder = ContentProviderOperation + .newInsert(ContactsContract.Data.CONTENT_URI); String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); - builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); - builder.withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); - builder.withValue(StructuredName.DISPLAY_NAME, displayName); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, rawContactID); + builder.withValue(ContactsContract.Data.MIMETYPE, + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName); return builder; } - private static ContentProviderOperation.Builder BuildImProtocol(RosterEntry entry, long rawContactID) { + private static ContentProviderOperation.Builder BuildProfile(RosterEntry entry, long rawContactID) { ContentProviderOperation.Builder builder = ContentProviderOperation - .newInsert(ContactsContract.StatusUpdates.CONTENT_URI); - builder.withValue(ContactsContract.StatusUpdates.DATA_ID, rawContactID); - builder.withValue(ContactsContract.StatusUpdates.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER); - //TODO: ajouter le protocol jabber + .newInsert(ContactsContract.Data.CONTENT_URI); + String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); + builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); + builder.withValue(ContactsContract.Data.MIMETYPE, + "vnd.android.cursor.item/vnd.com.beem.project.beem.android.profile"); + builder.withValue(ContactsContract.Data.DATA2, displayName); + //builder.withValue(ContactsContract.Data.DATA2, R.string.chat_name); return builder; } + private static void updateContactStatus(ArrayList operationList, RosterEntry entry, + long rawContactId, Presence p) { + Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); + Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); + Cursor c = mContentResolver.query(entityUri, new String[] { Entity.DATA_ID }, Entity.MIMETYPE + + " = 'vnd.android.cursor.item/vnd.com.beem.project.beem.android.profile'", null, null); + try { + if (c.moveToNext()) { + if (!c.isNull(0)) { + Log.e(TAG + "UPDATECONTACTSTATUS", "Entity.DATA_ID : " + c.getLong(0)); + // Build raw Contact after click on it + ContentProviderOperation.Builder builder = ContentProviderOperation + .newInsert(ContactsContract.StatusUpdates.CONTENT_URI); + builder.withValue(ContactsContract.StatusUpdates.DATA_ID, c.getLong(0)); + //TODO: Get status message + builder.withValue(ContactsContract.StatusUpdates.STATUS, "BEEM STATUS"); + builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "com.beem.project.beem"); + builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); + //TODO: GET Status Logo + // Actually getting default logo in the xml +// builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, img); + operationList.add(builder.build()); + } + } + } finally { + c.close(); + } + } + private static long getRawContactID(String account, String jid) { long authorId = -1; final Cursor c = mContentResolver.query(ContactsContract.RawContacts.CONTENT_URI, new String[] { diff -r 193a934390ba -r 5d3163053c42 src/com/beem/project/beem/ui/Chat.java --- a/src/com/beem/project/beem/ui/Chat.java Thu Apr 21 21:05:25 2011 +0200 +++ b/src/com/beem/project/beem/ui/Chat.java Sat May 07 12:26:45 2011 +0200 @@ -64,6 +64,7 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.SharedPreferences; +import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; @@ -75,6 +76,8 @@ import android.os.IBinder; import android.os.RemoteException; import android.preference.PreferenceManager; +import android.provider.ContactsContract; +import android.provider.ContactsContract.RawContacts.Entity; import android.text.util.Linkify; import android.util.Log; import android.view.KeyEvent; @@ -197,11 +200,20 @@ @Override protected void onResume() { super.onResume(); - mContact = new Contact(getIntent().getData()); - if (!mBinded) { - bindService(SERVICE_INTENT, mConn, BIND_AUTO_CREATE); - mBinded = true; + Uri tmpuri = getIntent().getData(); + Log.e(TAG, "URI : " + tmpuri.getLastPathSegment()); + Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI, + new String[] { ContactsContract.Data.DISPLAY_NAME }, + ContactsContract.Data._ID + " = " + tmpuri.getLastPathSegment(), null, null); + if (c.getCount() > 0) { + Log.e(TAG, "JID : " + c.getString(0)); } + //makeXmppUri + //mContact = new Contact(getIntent().getData()); + // if (!mBinded) { + // bindService(SERVICE_INTENT, mConn, BIND_AUTO_CREATE); + // mBinded = true; + // } } /** @@ -950,14 +962,14 @@ public class MyReceiver extends BroadcastReceiver { @Override - public void onReceive(Context context, Intent intent) { - Context c = getApplicationContext(); - Intent sendIntent = new Intent(); - if ( intent.getAction().equals(Intent.ACTION_SENDTO) ) { - sendIntent.setClass(c, Chat.class); - context.startActivity(sendIntent); - } - } + public void onReceive(Context context, Intent intent) { + Context c = getApplicationContext(); + Intent sendIntent = new Intent(); + if (intent.getAction().equals(Intent.ACTION_SENDTO)) { + sendIntent.setClass(c, Chat.class); + context.startActivity(sendIntent); + } + } } } diff -r 193a934390ba -r 5d3163053c42 src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Thu Apr 21 21:05:25 2011 +0200 +++ b/src/com/beem/project/beem/ui/Login.java Sat May 07 12:26:45 2011 +0200 @@ -211,8 +211,6 @@ Account allAccount[] = am.getAccountsByType("com.beem.project.com"); for (Account account : allAccount) { mListAccount.add(account.name); - mListAccount.add(account.name); - } }