# HG changeset patch # User "Vincent Veronis" # Date 1304881005 -7200 # Node ID 45bbdf20aa9d20cda91758ed62543d318dedf8e0 # Parent 9ffd19d0249cb502a7e9f92624c5b9977a420d82 Add raw contact informations diff -r 9ffd19d0249c -r 45bbdf20aa9d AndroidManifest.xml --- a/AndroidManifest.xml Sun May 08 12:04:31 2011 +0200 +++ b/AndroidManifest.xml Sun May 08 20:56:45 2011 +0200 @@ -55,7 +55,26 @@ android:label="Beem Connection"> - + + + + + + + + + + + + GetSharedPreferences() con.login(beemco.getLogin(), beemco.getPassword(), "BEEM_SYNC_ADAPTER"); roster = con.getRoster(); } catch (XMPPException e) { @@ -151,7 +156,8 @@ if (roster != null) { manageRoster(roster, account); } - con.disconnect(); + //TODO: Dont disco ?! + //con.disconnect(); } /** @@ -177,7 +183,8 @@ ArrayList ops = new ArrayList(); for (RosterEntry entry : r.getEntries()) { if (entry != null) { - manageEntry(ops, a, entry); + long rawContactID = manageEntry(ops, a, entry); + addUpdateStatus(ops, entry, r.getPresence(entry.getUser()), rawContactID); } if (ops.size() > 100) executeOperation(ops); @@ -191,8 +198,9 @@ * @param ops The content provider operation * @param account The account related * @param entry The roster entry to sync + * @return The raw contact ID */ - 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() + " RawContactID : " + rawContactID); if (rawContactID == -1) { // Not found in database, add new @@ -205,12 +213,13 @@ values.clear(); ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, true); ops.add(builder.build()); - builder = addUpdateIm(entry, rawContactID, true); + builder = addUpdateIm(entry, rawContactID, account, true); ops.add(builder.build()); } else { // Found, update ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, false); ops.add(builder.build()); } + return rawContactID; } /** @@ -250,7 +259,8 @@ * @param isInsert Insert boolean * @return */ - private static ContentProviderOperation.Builder addUpdateIm(RosterEntry entry, long rawContactID, boolean isInsert) { + private static ContentProviderOperation.Builder addUpdateIm(RosterEntry entry, long rawContactID, Account account, + boolean isInsert) { String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); ContentProviderOperation.Builder builder; if (isInsert) { @@ -268,6 +278,32 @@ } /** + * Method to insert or update IM informations. + * @param entry The roster entry to sync + * @param rawContactID The contact ID in the android database + * @param isInsert Insert boolean + * @return + */ + private static void addUpdateStatus(ArrayList ops, RosterEntry entry, Presence p, + long rawContactID) { + String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); + Log.i(TAG + "UPDATESTATUS", "Contact : " + displayName + " Presence status : " + p.getStatus() + " Presence status state : " + Status.getStatusFromPresence(p)); + ContentProviderOperation.Builder builder; + builder = ContentProviderOperation.newInsert(ContactsContract.StatusUpdates.CONTENT_URI); + builder.withValue(ContactsContract.StatusUpdates.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER); + builder.withValue(ContactsContract.StatusUpdates.IM_HANDLE, displayName); + builder.withValue(ContactsContract.StatusUpdates.IM_ACCOUNT, "beem@elyzion.net"); + builder.withValue(ContactsContract.StatusUpdates.STATUS, p.getStatus()); + builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "com.beem.project.beem"); + builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); + //TODO: Get status icon + builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.beem_status_icon); + //TODO: Pb presence ... 2 appear on 3 raw .... random appear + builder.withValue(ContactsContract.StatusUpdates.PRESENCE, Status.getStatusFromPresence(p)); + ops.add(builder.build()); + } + + /** * Get contact ID from android database. * @param account The account related * @param jid The jid related diff -r 9ffd19d0249c -r 45bbdf20aa9d src/com/beem/project/beem/ui/Chat.java --- a/src/com/beem/project/beem/ui/Chat.java Sun May 08 12:04:31 2011 +0200 +++ b/src/com/beem/project/beem/ui/Chat.java Sun May 08 20:56:45 2011 +0200 @@ -201,26 +201,14 @@ @Override protected void onResume() { super.onResume(); - Uri tmpuri = getIntent().getData(); - Log.e(TAG, "URI : " + tmpuri.getLastPathSegment()); - Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI, - new String[] { ContactsContract.Data.CONTACT_ID }, - ContactsContract.Data.CONTACT_ID + " = " + tmpuri.getLastPathSegment(), null, null); - if (c.getCount() > 0) { - Log.e(TAG, "ID : " + c.getInt(0)); - c = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, - new String[] { ContactsContract.RawContacts.SOURCE_ID }, - ContactsContract.RawContacts.CONTACT_ID + " = " + c.getInt(0), 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; - // } + // When coming from account contact + Uri contactURI = getIntent().getData(); + String jid = contactURI.getPathSegments().get(0); + mContact = new Contact(jid); +// if (!mBinded) { +// bindService(SERVICE_INTENT, mConn, BIND_AUTO_CREATE); +// mBinded = true; +// } } /** diff -r 9ffd19d0249c -r 45bbdf20aa9d src/com/beem/project/beem/utils/Status.java --- a/src/com/beem/project/beem/utils/Status.java Sun May 08 12:04:31 2011 +0200 +++ b/src/com/beem/project/beem/utils/Status.java Sun May 08 20:56:45 2011 +0200 @@ -46,6 +46,8 @@ import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence.Mode; +import android.provider.ContactsContract; + /** * Utility class to deal with status and presence value. * @author marseille @@ -111,32 +113,32 @@ * @return an int representing the status */ public static int getStatusFromPresence(final Presence presence) { - int res = Status.CONTACT_STATUS_DISCONNECT; + int res = ContactsContract.StatusUpdates.OFFLINE; if (presence.getType().equals(Presence.Type.unavailable)) { - res = Status.CONTACT_STATUS_DISCONNECT; + res = ContactsContract.StatusUpdates.OFFLINE; } else { Mode mode = presence.getMode(); if (mode == null) { - res = Status.CONTACT_STATUS_AVAILABLE; + res = ContactsContract.StatusUpdates.AVAILABLE; } else { switch (mode) { case available: - res = Status.CONTACT_STATUS_AVAILABLE; + res = ContactsContract.StatusUpdates.AVAILABLE; break; case away: - res = Status.CONTACT_STATUS_AWAY; + res = ContactsContract.StatusUpdates.AWAY; break; case chat: - res = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT; + res = ContactsContract.StatusUpdates.AVAILABLE; break; case dnd: - res = Status.CONTACT_STATUS_BUSY; + res = ContactsContract.StatusUpdates.DO_NOT_DISTURB; break; case xa: - res = Status.CONTACT_STATUS_UNAVAILABLE; + res = ContactsContract.StatusUpdates.INVISIBLE; break; default: - res = Status.CONTACT_STATUS_DISCONNECT; + res = ContactsContract.StatusUpdates.OFFLINE; break; } }