# HG changeset patch # User Nikita Kozlov # Date 1291594004 -3600 # Node ID 2ef1c609606977ad5e920108b090852670f4c681 # Parent bcafceecd837bacd2de9e6df460e29480282c3d3# Parent 9d3a7af41ec2d6c66acd006814427b00ddb83e11 merge diff -r bcafceecd837 -r 2ef1c6096069 .hgignore diff -r bcafceecd837 -r 2ef1c6096069 .hgtags diff -r bcafceecd837 -r 2ef1c6096069 AndroidManifest.xml diff -r bcafceecd837 -r 2ef1c6096069 COPYING diff -r bcafceecd837 -r 2ef1c6096069 CREDITS diff -r bcafceecd837 -r 2ef1c6096069 INSTALL diff -r bcafceecd837 -r 2ef1c6096069 README diff -r bcafceecd837 -r 2ef1c6096069 build.properties diff -r bcafceecd837 -r 2ef1c6096069 build.xml diff -r bcafceecd837 -r 2ef1c6096069 default.properties diff -r bcafceecd837 -r 2ef1c6096069 doc/UmlGraph.jar diff -r bcafceecd837 -r 2ef1c6096069 doc/android/package-list diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/README.txt diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem-build-process.patch diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem_patches/10-PubSubManager-non-final.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/asmack-beem/beem_patches/10-PubSubManager-non-final.patch Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,13 @@ +Index: org/jivesoftware/smackx/pubsub/PubSubManager.java +=================================================================== +--- org/jivesoftware/smackx/pubsub/PubSubManager.java (revision 11464) ++++ org/jivesoftware/smackx/pubsub/PubSubManager.java (working copy) +@@ -41,7 +41,7 @@ + * + * @author Robin Collier + */ +-final public class PubSubManager ++public class PubSubManager + { + private XMPPConnection con; + private String to; diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem_patches/50-fix-chatmanager.patch diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem_patches/50-fix-sasl-incorrect-encoding.patch diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem_patches/50-improved-pubsub.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/asmack-beem/beem_patches/50-improved-pubsub.patch Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,46 @@ +--- ../../../src/smack/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java (révision 11644) ++++ org/jivesoftware/smackx/pubsub/provider/ItemProvider.java (copie de travail) +@@ -45,6 +45,8 @@ + } + else + { ++ while (tag != XmlPullParser.START_TAG) ++ tag = parser.next(); + String payloadElemName = parser.getName(); + String payloadNS = parser.getNamespace(); + +--- ../../../src/org/jivesoftware/smackx/pubsub/Node.java (révision 11644) ++++ org/jivesoftware/smackx/pubsub/Node.java (copie de travail) +@@ -60,7 +60,7 @@ + * + * For example, OpenFire requires the server to be prefixed by pubsub + */ +- void setTo(String toAddress) ++ public void setTo(String toAddress) + { + to = toAddress; + } +--- ../../../src/org/jivesoftware/smackx/pubsub/LeafNode.java (révision 11644) ++++ org/jivesoftware/smackx/pubsub/LeafNode.java (copie de travail) +@@ -34,7 +34,7 @@ + */ + public class LeafNode extends Node + { +- LeafNode(Connection connection, String nodeName) ++ public LeafNode(Connection connection, String nodeName) + { + super(connection, nodeName); + } +--- ../../../src/org/jivesoftware/smackx/pubsub/PubSubManager.java (révision 11644) ++++ org/jivesoftware/smackx/pubsub/PubSubManager.java (copie de travail) +@@ -43,8 +43,8 @@ + */ + final public class PubSubManager + { +- private Connection con; +- private String to; ++ protected Connection con; ++ protected String to; + private Map nodeMap = new ConcurrentHashMap(); + + /** diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem_patches/50-public-info-features.patch diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem_patches/COPYING diff -r bcafceecd837 -r 2ef1c6096069 doc/asmack-beem/beem_patches/README.txt diff -r bcafceecd837 -r 2ef1c6096069 doc/favicon.ico diff -r bcafceecd837 -r 2ef1c6096069 doc/smack/package-list diff -r bcafceecd837 -r 2ef1c6096069 libs/README.txt diff -r bcafceecd837 -r 2ef1c6096069 libs/asmack-android-7-beem.jar Binary file libs/asmack-android-7-beem.jar has changed diff -r bcafceecd837 -r 2ef1c6096069 res/anim/rotate_and_scale.xml diff -r bcafceecd837 -r 2ef1c6096069 res/drawable-hdpi/beem_icon_launcher_color.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable-ldpi/beem_icon_launcher_color.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable-mdpi/beem_icon_launcher_color.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/background.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/beem_launcher_icon_silver.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/beem_status_icon.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/bottombar.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/button_indicator_next.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/button_indicator_prev.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_add.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_blocked_user.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_chat_dashboard.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_close_clear_cancel.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_end_conversation.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_friendslist.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_invite.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_login.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/ic_menu_manage.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/icon.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/logo.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/not_in_the_roster.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/scrollbar_vertical_thumb.xml diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/scrollbar_vertical_track.xml diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/shape_border_green.xml diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/shape_line_green.xml diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_available.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_away.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_blocked.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_dnd.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_error.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_icon.xml diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_idle.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_invisible.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_new_message.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_offline.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_requested.png diff -r bcafceecd837 -r 2ef1c6096069 res/drawable/status_typing.png diff -r bcafceecd837 -r 2ef1c6096069 res/layout/addcontact.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/changestatus.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/chat.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/chat_msg_row.xml --- a/res/layout/chat_msg_row.xml Mon Dec 06 01:06:22 2010 +0100 +++ b/res/layout/chat_msg_row.xml Mon Dec 06 01:06:44 2010 +0100 @@ -1,35 +1,20 @@ + android:orientation="vertical" android:layout_width="fill_parent" + android:layout_height="wrap_content"> - - - - - + + + diff -r bcafceecd837 -r 2ef1c6096069 res/layout/contactdialogaliasdialog.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/contactlist.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/contactlist_group.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/contactlist_groupstub.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/contactlistcontact.xml --- a/res/layout/contactlistcontact.xml Mon Dec 06 01:06:22 2010 +0100 +++ b/res/layout/contactlistcontact.xml Mon Dec 06 01:06:44 2010 +0100 @@ -1,20 +1,30 @@ - + - + diff -r bcafceecd837 -r 2ef1c6096069 res/layout/create_account.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/group_list.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/jingle_call_activity.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/login.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/login_anim.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/preferences.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/privacy_list.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/privacy_list_create_dialog.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/subscription.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/wizard_account.xml diff -r bcafceecd837 -r 2ef1c6096069 res/layout/wizard_account_configure.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/chat.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/contact_list.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/contactlist_context.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/create_account.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/edit_settings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/login.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/privacy_list.xml diff -r bcafceecd837 -r 2ef1c6096069 res/menu/privacy_list_context.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values-de/strings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values-es/strings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values-fr/strings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values-ru/strings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values-zh-rCN/strings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values-zh-rTW/strings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values/arrays.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values/colors.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values/strings.xml diff -r bcafceecd837 -r 2ef1c6096069 res/values/styles.xml diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/BeemApplication.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Mon Dec 06 01:06:22 2010 +0100 +++ b/src/com/beem/project/beem/BeemService.java Mon Dec 06 01:06:44 2010 +0100 @@ -57,6 +57,10 @@ import org.jivesoftware.smack.proxy.ProxyInfo; import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType; import org.jivesoftware.smack.util.StringUtils; +import org.jivesoftware.smackx.pubsub.provider.PubSubProvider; +import org.jivesoftware.smackx.pubsub.provider.ItemsProvider; +import org.jivesoftware.smackx.pubsub.provider.ItemProvider; +import org.jivesoftware.smackx.pubsub.provider.EventProvider; import android.app.Notification; import android.app.NotificationManager; @@ -80,6 +84,8 @@ import com.beem.project.beem.utils.BeemBroadcastReceiver; import com.beem.project.beem.utils.BeemConnectivity; import com.beem.project.beem.utils.Status; +import com.beem.project.beem.smack.avatar.AvatarMetadataProvider; +import com.beem.project.beem.smack.avatar.AvatarProvider; import com.beem.project.beem.smack.caps.CapsProvider; /** @@ -148,7 +154,7 @@ || mSettings.getBoolean("settings_key_gmail", false)) { mConnectionConfiguration.setSecurityMode(SecurityMode.required); } - mConnectionConfiguration.setDebuggerEnabled(false); + mConnectionConfiguration.setDebuggerEnabled(true); mConnectionConfiguration.setSendPresence(true); // maybe not the universal path, but it works on most devices (Samsung Galaxy, Google Nexus One) mConnectionConfiguration.setTruststoreType("BKS"); @@ -317,6 +323,12 @@ * @param pm The ProviderManager. */ private void configure(ProviderManager pm) { + Log.d(TAG, "configure"); + // Service Discovery # Items + pm.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider()); + // Service Discovery # Info + pm.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider()); + // Privacy pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider()); // Delayed Delivery only the new version @@ -335,7 +347,29 @@ pm.addExtensionProvider("paused", "http://jabber.org/protocol/chatstates", chatState); pm.addExtensionProvider("inactive", "http://jabber.org/protocol/chatstates", chatState); pm.addExtensionProvider("gone", "http://jabber.org/protocol/chatstates", chatState); + // capabilities pm.addExtensionProvider("c", "http://jabber.org/protocol/caps", new CapsProvider()); + //Pubsub + pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider()); + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); + pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub", new ItemProvider()); + + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new ItemsProvider()); + pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub#event", new ItemProvider()); + pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", new EventProvider()); + //TODO rajouter les manquants pour du full pubsub + + + //PEP avatar + pm.addExtensionProvider("metadata", "urn:xmpp:avatar:metadata", new AvatarMetadataProvider()); + pm.addExtensionProvider("data", "urn:xmpp:avatar:data", new AvatarProvider()); + +// PEPProvider pep = new PEPProvider(); +// AvatarMetadataProvider avaMeta = new AvatarMetadataProvider(); +// pep.registerPEPParserExtension("urn:xmpp:avatar:metadata", avaMeta); +// pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", pep); + /* // Private Data Storage pm.addIQProvider("query", "jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider()); diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/package-info.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/BeemCapsManager.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/BeemChatManager.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/ChatAdapter.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/Contact.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Mon Dec 06 01:06:22 2010 +0100 +++ b/src/com/beem/project/beem/service/Contact.java Mon Dec 06 01:06:44 2010 +0100 @@ -85,6 +85,7 @@ private List mRes; private final List mGroups = new ArrayList(); private String mName; + private String mAvatarId; /** * Construct a contact from a parcel. @@ -97,6 +98,7 @@ mSelectedRes = in.readString(); mName = in.readString(); mMsgState = in.readString(); + mAvatarId = in.readString(); mRes = new ArrayList(); in.readStringList(mRes); in.readStringList(mGroups); @@ -148,6 +150,7 @@ dest.writeString(mSelectedRes); dest.writeString(mName); dest.writeString(mMsgState); + dest.writeString(mAvatarId); dest.writeStringList(getMRes()); dest.writeStringList(getGroups()); } @@ -259,6 +262,15 @@ } /** + * Get the avatar id of the contact. + * + * @return the avatar id or null if there is not + */ + public String getAvatarId() { + return mAvatarId; + } + + /** * Set the groups the contact is in. * @param groups list of groups */ @@ -287,6 +299,15 @@ } /** + * Set the avatar id of the contact. + * + * @param avatarId the avatar id + */ + public void setAvatarId(String avatarId) { + mAvatarId = avatarId; + } + + /** * Set the resource of the contact. * @param resource to set. */ diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/LoginAsyncTask.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/Message.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/Message.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/PresenceAdapter.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/PresenceAdapter.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/PrivacyListItem.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/PrivacyListItem.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/PrivacyListManagerAdapter.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Mon Dec 06 01:06:22 2010 +0100 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Mon Dec 06 01:06:44 2010 +0100 @@ -66,6 +66,9 @@ import com.beem.project.beem.R; import com.beem.project.beem.service.aidl.IBeemRosterListener; import com.beem.project.beem.utils.Status; +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info; +import com.beem.project.beem.smack.avatar.AvatarManager; +import com.beem.project.beem.smack.avatar.AvatarListener; /** * This class implement a Roster adapter for BEEM. @@ -78,6 +81,8 @@ new RemoteCallbackList(); private final Map mDefaultStatusMessages; private final RosterListenerAdapter mRosterListener = new RosterListenerAdapter(); + private Map mAvatarIdmap = new HashMap(); + private AvatarManager mAvatarManager; /** * Constructor. @@ -91,6 +96,22 @@ } /** + * Constructor. + * @param roster The roster to adapt. + * @param context The context of the RosterAdapter. + * @param avatarMgr The AvatarManager of the connection + */ + public RosterAdapter(final Roster roster, final Context context, final AvatarManager avatarMgr) { + mAdaptee = roster; + roster.addRosterListener(mRosterListener); + mDefaultStatusMessages = createDefaultStatusMessagesMap(context); + mAvatarManager = avatarMgr; + if (mAvatarManager != null) + mAvatarManager.addAvatarListener(new AvatarEventListener()); + } + + + /** * {@inheritDoc} */ @Override @@ -242,7 +263,7 @@ try { c.setGroups(entry.getGroups()); } catch (NullPointerException e) { - Log.d(TAG, "Group list not ready"); + Log.d(TAG, "Group list not ready", e); } Iterator iPres = mAdaptee.getPresences(user); while (iPres.hasNext()) { @@ -251,6 +272,7 @@ c.addRes(StringUtils.parseResource(p.getFrom())); } c.setName(entry.getName()); + c.setAvatarId(mAvatarIdmap.get(user)); return c; } @@ -357,6 +379,8 @@ for (int i = 0; i < n; i++) { IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i); try { + if (!presence.isAvailable()) + mAvatarIdmap.remove(StringUtils.parseBareAddress(presence.getFrom())); if (presence.getStatus() == null || "".equals(presence.getStatus())) { presence.setStatus(mDefaultStatusMessages.get(Status.getStatusFromPresence(presence))); } @@ -368,4 +392,26 @@ mRemoteRosListeners.finishBroadcast(); } } + + /** + * Listener on avatar metadata event. + * + */ + private class AvatarEventListener implements AvatarListener { + + /** + * Constructor. + */ + public AvatarEventListener() { } + + @Override + public void onAvatarChange(String from, String avatarId, List avatarInfos) { + String bare = StringUtils.parseBareAddress(from); + if (avatarId == null) + mAvatarIdmap.remove(bare); + else { + mAvatarIdmap.put(bare, avatarId); + } + } + } } diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Mon Dec 06 01:06:22 2010 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Mon Dec 06 01:06:44 2010 +0100 @@ -55,6 +55,7 @@ import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smackx.ChatStateManager; import org.jivesoftware.smackx.ServiceDiscoveryManager; +import org.jivesoftware.smackx.packet.DiscoverInfo; import android.app.Notification; import android.app.PendingIntent; @@ -63,8 +64,12 @@ import android.content.SharedPreferences; import android.os.RemoteCallbackList; import android.os.RemoteException; +import android.os.Environment; import android.util.Log; +import java.util.Iterator; +import java.io.File; + import com.beem.project.beem.BeemService; import com.beem.project.beem.R; import com.beem.project.beem.BeemApplication; @@ -76,6 +81,10 @@ import com.beem.project.beem.ui.Subscription; import com.beem.project.beem.utils.BeemBroadcastReceiver; import com.beem.project.beem.utils.Status; +import com.beem.project.beem.smack.pep.PepSubManager; +import com.beem.project.beem.smack.avatar.AvatarCache; +import com.beem.project.beem.smack.avatar.FileAvatarCache; +import com.beem.project.beem.smack.avatar.AvatarManager; /** * This class implements an adapter for XMPPConnection. @@ -104,6 +113,8 @@ private ChatStateManager mChatStateManager; private final BeemService mService; private BeemApplication mApplication; + private AvatarManager mAvatarManager; + private PepSubManager mPepManager; private final RemoteCallbackList mRemoteConnListeners = new RemoteCallbackList(); private final SubscribePacketListener mSubscribePacketListener = new SubscribePacketListener(); @@ -229,7 +240,9 @@ mPrivacyListManager = new PrivacyListManagerAdapter(PrivacyListManager.getInstanceFor(mAdaptee)); mService.resetStatus(); mService.initJingle(mAdaptee); + discoverServerFeatures(); + mRoster = new RosterAdapter(mAdaptee.getRoster(), mService, mAvatarManager); mApplication.setConnected(true); changeStatus(Status.CONTACT_STATUS_AVAILABLE, mService.getServicePreference().getString("status_text", "")); return true; @@ -311,6 +324,15 @@ } /** + * Get the AvatarManager of this connection. + * + * @return the AvatarManager or null if there is not + */ + public AvatarManager getAvatarManager() { + return mAvatarManager; + } + + /** * get the previous status. * @return previous status. */ @@ -379,26 +401,10 @@ Roster adap = mAdaptee.getRoster(); if (adap == null) return null; - mRoster = new RosterAdapter(adap, mService); + mRoster = new RosterAdapter(adap, mService, mAvatarManager); return mRoster; } - /** - * enregistre les features dispo dans notre version Liste de features que Telepathy supporte. - */ - private void initFeatures() { - ServiceDiscoveryManager.setIdentityName("Beem"); - ServiceDiscoveryManager.setIdentityType("phone"); - ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee); - if (sdm == null) - sdm = new ServiceDiscoveryManager(mAdaptee); - sdm.addFeature("http://jabber.org/protocol/disco#info"); - sdm.addFeature("jabber:iq:privacy"); - sdm.addFeature("http://jabber.org/protocol/caps"); - mChatStateManager = ChatStateManager.getInstance(mAdaptee); - BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService); - caps.setNode("http://www.beem-project.com"); - } /** * Returns true if currently authenticated by successfully calling the login method. @@ -442,6 +448,64 @@ } /** + * Initialize the features provided by beem. + */ + private void initFeatures() { + ServiceDiscoveryManager.setIdentityName("Beem"); + ServiceDiscoveryManager.setIdentityType("phone"); + ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee); + if (sdm == null) + sdm = new ServiceDiscoveryManager(mAdaptee); + + sdm.addFeature("http://jabber.org/protocol/disco#info"); + sdm.addFeature("jabber:iq:privacy"); + sdm.addFeature("http://jabber.org/protocol/caps"); + sdm.addFeature("urn:xmpp:avatar:metadata"); + sdm.addFeature("urn:xmpp:avatar:metadata+notify"); + sdm.addFeature("urn:xmpp:avatar:data"); + sdm.addFeature("http://jabber.org/protocol/nick"); + sdm.addFeature("http://jabber.org/protocol/nick+notify"); + + mChatStateManager = ChatStateManager.getInstance(mAdaptee); + BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService); + caps.setNode("http://www.beem-project.com"); + } + + /** + * Discover the features provided by the server. + */ + private void discoverServerFeatures() { + try { + // jid et server + ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee); + DiscoverInfo info = sdm.discoverInfo("elyzion.net"); + Iterator it = info.getIdentities(); + while (it.hasNext()) { + DiscoverInfo.Identity identity = it.next(); + if ("pubsub".equals(identity.getCategory()) && "pep".equals(identity.getType())) { + initPEP(); + } + } + } catch (XMPPException e) { + // No Pep + } + } + + /** + * Initialize PEP. + */ + private void initPEP() { + // Enable pep sending + // API 8 + // mService.getExternalCacheDir() + mPepManager = new PepSubManager(mAdaptee); + File cacheDir = Environment.getExternalStorageDirectory(); + cacheDir = new File(cacheDir, "/Android/data/com.beem.project.beem/cache/"); + AvatarCache avatarCache = new FileAvatarCache(cacheDir); + mAvatarManager = new AvatarManager(mAdaptee, mPepManager, avatarCache, true); + } + + /** * Listener for XMPP connection events. It will calls the remote listeners for connection events. * @author darisk */ diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/XmppFacade.java --- a/src/com/beem/project/beem/service/XmppFacade.java Mon Dec 06 01:06:22 2010 +0100 +++ b/src/com/beem/project/beem/service/XmppFacade.java Mon Dec 06 01:06:44 2010 +0100 @@ -43,9 +43,7 @@ */ package com.beem.project.beem.service; -import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smackx.packet.VCard; import android.os.RemoteException; @@ -55,6 +53,7 @@ import com.beem.project.beem.service.aidl.IXmppConnection; import com.beem.project.beem.service.aidl.IXmppFacade; import com.beem.project.beem.utils.PresenceType; +import com.beem.project.beem.smack.avatar.AvatarManager; /** * This class is a facade for the Beem Service. @@ -150,19 +149,12 @@ public void call(String jid) throws RemoteException { } - /* (non-Javadoc) - * @see com.beem.project.beem.service.aidl.IXmppFacade#getVcardAvatar(java.lang.String) - */ @Override - public byte[] getVcardAvatar(String jid) throws RemoteException { - VCard vcard = new VCard(); + public byte[] getAvatar(String avatarId) throws RemoteException { + AvatarManager mgr = mConnexion.getAvatarManager(); + if (mgr == null) + return null; - try { - vcard.load(mConnexion.getAdaptee(), jid); - return vcard.getAvatar(); - } catch (XMPPException e) { - e.printStackTrace(); - } - return null; + return mgr.getAvatar(avatarId); } } diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IChat.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IChatManager.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IChatManagerListener.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IContact.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IMessageListener.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IPrivacyListListener.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IRoster.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IXmppConnection.aidl diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/aidl/IXmppFacade.aidl --- a/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Mon Dec 06 01:06:22 2010 +0100 +++ b/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Mon Dec 06 01:06:44 2010 +0100 @@ -97,10 +97,10 @@ void call(in String jid); /** - * get the user vcard avatar - * @param jid the user jid + * get the an avatar + * @param id the id of the avatar */ - byte[] getVcardAvatar(in String jid); + byte[] getAvatar(in String id); IPrivacyListManager getPrivacyListManager(); } diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/service/package-info.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarCache.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarCache.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,90 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Interface for an AvatarCache. + * This can be improved to a generic cache. + * + */ +public interface AvatarCache { + + /** + * Put some datas in cache. + * + * @param id the key id of the data + * @param data the datato cache + * @throws IOException if an IO error occurs while caching the data + */ + void put(String id, byte[] data) throws IOException; + + /** + * Put some datas in cache. + * + * @param id the key id of the data + * @param data an InputStream to the data to cache + * @throws IOException if an IO error occurs while caching the data + */ + void put(String id, InputStream data) throws IOException; + + /** + * Get some data from the cache. + * + * @param id the id of the data to get + * @return the cached data + * @throws IOException if an IO error occurs while geting the data + */ + byte[] get(String id) throws IOException; + + /** + * Test if a data is in cache. + * + * @param id the id of the data + * @return true if data is in cache false otherwise + */ + boolean contains(String id); +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarExtension.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,111 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import org.jivesoftware.smack.util.Base64; +import org.jivesoftware.smack.packet.PacketExtension; + +/** + * PacketExtension to represent the Avatar data. + * XML namespace urn:xmpp:avatar:data + * + */ +public class AvatarExtension implements PacketExtension { + + private String mData; + + /** + * Create an AvatarExtension. + * @param base64 the data of the avatar as a base64 string + */ + public AvatarExtension(final String base64) { + mData = base64; + } + + /** + * Create an AvatarExtension. + * @param data the data of the avatar + */ + public AvatarExtension(final byte[] data) { + mData = Base64.encodeBytes(data); + } + + /** + * Get the avatar data as a Base64 string. + * + * @return a base64 string. + */ + public String getBase64() { + return mData; + } + + /** + * Get the avatar data. + * + * @return the decoded data + */ + public byte[] getData() { + return Base64.decode(mData); + } + + @Override + public String getElementName() { + return "data"; + } + + @Override + public String getNamespace() { + return "urn:xmpp:avatar:data"; + } + + @Override + public String toXML() { + StringBuilder builder = new StringBuilder(""); + builder.append(mData); + builder.append(""); + return builder.toString(); + } + +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarListener.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,64 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.util.List; +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info; + +/** + * A listener for avatar changes event. + * + */ +public interface AvatarListener { + + /** + * Event which is fired when a contact change avatar. + * + * @param from the contact who change his avatar + * @param avatarId the new avatar id, may be null if the contact set no avatar + * @param avatarInfos the metadata infos of the avatar, may be empty if the contact set no avatar + */ + void onAvatarChange(String from, String avatarId, List avatarInfos); + +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarManager.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,204 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info; +import com.beem.project.beem.smack.pep.PEPListener; +import com.beem.project.beem.smack.pep.PepSubManager; + +import java.io.IOException; + +import java.util.List; +import java.util.LinkedList; + +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smackx.pubsub.Item; +import org.jivesoftware.smackx.pubsub.PayloadItem; + +/** + * This class deals with the avatar data. + * It can be configured to auto retrieve the avatar and put it in cache. + * + */ +public class AvatarManager { + + private PepSubManager mPep; + private Connection mCon; + private boolean mAutoDownload; + private AvatarCache mCache; + private final List mListeners = new LinkedList(); + + /** + * Create an AvatarManager. + * + * @param con the connection + * @param pepMgr the PepSubManager of the Connection + * @param cache the cache which will store the avatars + * @param autoDownload true to enable auto download of avatars + */ + public AvatarManager(final Connection con, final PepSubManager pepMgr, final AvatarCache cache, final boolean autoDownload) { + mCon = con; + mPep = pepMgr; + mAutoDownload = autoDownload; + mCache = cache; + mPep.addPEPListener(new Listener()); + } + + /** + * Get an avatar from the cache. + * + * @param avatarId the id of the avatar + * @return the avatar or null if it cannot be retrieved from the cache + */ + public byte[] getAvatar(String avatarId) { + if (avatarId == null) + return null; + try { + return mCache.get(avatarId); + } catch (IOException e) { + return null; + } + } + + /** + * Add an AvatarListener. + * + * @param listener the AvatarListener to add + */ + public void addAvatarListener(AvatarListener listener) { + if (!mListeners.contains(listener)) + mListeners.add(listener); + } + + /** + * Remove an AvatarListener. + * + * @param listener the AvatarListener to remove + */ + public void removeAvatarListener(AvatarListener listener) { + mListeners.remove(listener); + } + + + /** + * Select the avatar to download. + * Subclass should override this method to take control over the selection process. + * This implementation select the first element. + * + * @param available list of the avatar metadata information + * @return the metadata of the avatar to download + */ + protected Info selectAvatar(List available) { + return available.get(0); + } + + /** + * Fire the listeners for avatar change. + * + * @param from the jid of the contact + * @param avatarId the new avatar id + * @param avatarInfos the metadata infos of the avatar + */ + private void fireListeners(String from, String avatarId, List avatarInfos) { + for (AvatarListener l : mListeners) + l.onAvatarChange(from, avatarId, avatarInfos); + } + + /** + * Download an avatar. + * + * @param from The jid of the user + * @param avatarId the id of the avatar + * @param info the metadata information of the avatar to download + * @return true if the download was successfull + */ + public boolean downloadAvatar(String from, String avatarId, Info info) { + try { + AvatarRetriever retriever = AvatarRetrieverFactory.getRetriever(mCon, from, info); + byte[] avatar = retriever.getAvatar(); + // TODO check the hash before store + mCache.put(avatarId, avatar); + return true; + } catch (IOException e) { + System.err.println("Error while downloading avatar"); + e.printStackTrace(); + return false; + } + } + + /** + * A listener to PEPEevent. + */ + private class Listener implements PEPListener { + + /** + * Create a listener. + */ + public Listener() { + } + + @Override + public void eventReceived(String from, String node, List items) { + if (!"urn:xmpp:avatar:metadata".equals(node)) + return; + Item i = items.get(0); + if (i instanceof PayloadItem) { + PayloadItem pi = (PayloadItem) i; + PacketExtension ex = pi.getPayload(); + if (ex instanceof AvatarMetadataExtension) { + AvatarMetadataExtension ext = (AvatarMetadataExtension) ex; + String id = i.getId(); + List infos = ext.getInfos(); + if (infos.size() > 0 && mAutoDownload) { + Info info = selectAvatar(infos); + if (!mCache.contains(id)) + downloadAvatar(from, id, info); + } + fireListeners(from, id, infos); + } + } + } + } +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarMetadataExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarMetadataExtension.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,257 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.util.LinkedList; +import java.util.List; + +import org.jivesoftware.smack.packet.PacketExtension; + +/** + * PacketExtension to represent the Avatar metadata. + * XML namespace urn:xmpp:avatar:metadata + * + */ +public class AvatarMetadataExtension implements PacketExtension { + private List mInfos = new LinkedList(); + + /** + * Create an AvatarMetadataExtension. + */ + public AvatarMetadataExtension() { + } + + /** + * Get the metadata informations. + * + * @return a list of informations + */ + public List getInfos() { + return mInfos; + } + + /** + * Add a metadate information. + * + * @param info the metadata information to add + */ + public void addInfo(Info info) { + mInfos.add(info); + } + + @Override + public String getElementName() { + return "metadata"; + } + + @Override + public String getNamespace() { + return "urn:xmpp:avatar:metadata"; + } + + @Override + public String toXML() { + StringBuilder builder = new StringBuilder(""); + for (Info info : mInfos) { + builder.append(info.toXML()); + } + builder.append(""); + return builder.toString(); + } + + /** + * A metadata information element. + */ + public static class Info { + private int mBytes; + private int mHeight; + private int mWidth; + private String mId; + private String mType; + private String mUrl; + + /** + * Create an Info. + * + * @param id the id of the info + * @param type the MIME type of the avatar + * @param bytes the size of the avatar in bytes + */ + public Info(final String id, final String type, final int bytes) { + mId = id; + mType = type; + mBytes = bytes; + } + + /** + * Set the size of the avatar in bytes. + * + * @param bytes the size + */ + public void setBytes(int bytes) { + this.mBytes = bytes; + } + + /** + * Set the size of the avatar in bytes. + * + * @return the size + */ + public int getBytes() { + return mBytes; + } + + /** + * Set the height. + * + * @param height the height + */ + public void setHeight(int height) { + this.mHeight = height; + } + + /** + * Get the height. + * + * @return the height + */ + public int getHeight() { + return mHeight; + } + + /** + * Set the width. + * + * @param width the width + */ + public void setWidth(int width) { + this.mWidth = width; + } + + /** + * Get the width. + * + * @return the width + */ + public int getWidth() { + return mWidth; + } + + /** + * Set the url. + * + * @param url the url + */ + public void setUrl(String url) { + this.mUrl = url; + } + + /** + * Get the url. + * + * @return the url, null if no url is present + */ + public String getUrl() { + return mUrl; + } + + /** + * Get the id. + * + * @return the id + */ + public String getId() { + return mId; + } + + /** + * Set the id. + * + * @param id the id + */ + public void setId(String id) { + this.mId = id; + } + + /** + * Set the MIME type of the avatar. + * + * @param type the type + */ + public void setType(String type) { + this.mType = type; + } + + /** + * Get the MIME type of the avatar. + * + * @return the type, null if no type is present + */ + public String getType() { + return mType; + } + + /** + * Return this information as an xml element. + * + * @return an xml element representing this information + */ + public String toXML() { + StringBuilder builder = new StringBuilder(" 0) + builder.append(" height=\"" + mHeight + "\""); + if (mWidth > 0) + builder.append(" width=\"" + mWidth + "\""); + if (mUrl != null) + builder.append(" url=\"" + mUrl + "\""); + builder.append(" />"); + return builder.toString(); + } + } +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarMetadataProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarMetadataProvider.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,93 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.xmlpull.v1.XmlPullParser; + +/** + * A PacketExtensionProvider to parse the Avatar metadata. + * XML namespace urn:xmpp:avatar:metadata + */ +public class AvatarMetadataProvider implements PacketExtensionProvider { + + /** + * Creates a new AvatarMetadataProvider. + * ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor + */ + public AvatarMetadataProvider() { + } + + @Override + public PacketExtension parseExtension(XmlPullParser parser) + throws Exception { + AvatarMetadataExtension metadata = new AvatarMetadataExtension(); + boolean done = false; + StringBuilder buffer = new StringBuilder(); + while (!done) { + int eventType = parser.next(); + if (eventType == XmlPullParser.START_TAG) { + if ("info".equals(parser.getName())) { + int bytes = Integer.parseInt(parser.getAttributeValue(null, "bytes")); + int height = Integer.parseInt(parser.getAttributeValue(null, "height")); + int width = Integer.parseInt(parser.getAttributeValue(null, "width")); + String id = parser.getAttributeValue(null, "id"); + String type = parser.getAttributeValue(null, "type"); + String url = parser.getAttributeValue(null, "url"); + AvatarMetadataExtension.Info info = new AvatarMetadataExtension.Info(id, type, bytes); + info.setHeight(height); + info.setWidth(width); + info.setUrl(url); + metadata.addInfo(info); + } + } else if (eventType == XmlPullParser.END_TAG) { + if (parser.getName().equals(metadata.getElementName())) { + done = true; + } + } + } + return metadata; + } +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarProvider.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,82 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.xmlpull.v1.XmlPullParser; + +/** + * A PacketExtensionProvider to parse the Avatar data. + * XML namespace urn:xmpp:avatar:data + */ +public class AvatarProvider implements PacketExtensionProvider { + + /** + * Creates a new AvatarProvider. + * ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor + */ + public AvatarProvider() { + } + + @Override + public PacketExtension parseExtension(XmlPullParser parser) + throws Exception { + AvatarMetadataExtension metadata = new AvatarMetadataExtension(); + boolean done = false; + StringBuilder buffer = new StringBuilder(); + while (!done) { + int eventType = parser.getEventType(); + if (eventType == XmlPullParser.START_TAG) { + if ("data".equals(parser.getName())) { + String data = parser.nextText(); + AvatarExtension avatar = new AvatarExtension(data); + return avatar; + } + } + parser.next(); + } + return null; + } +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarRetriever.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarRetriever.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,60 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.io.IOException; + +/** + * Interface for an AvatarRetriever. + */ +public interface AvatarRetriever { + + /** + * Retrieve the avatar. + * + * @return the avatar + * @throws IOException if an IO error occurs while retrieving the avatar + */ + byte[] getAvatar() throws IOException; +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/AvatarRetrieverFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/AvatarRetrieverFactory.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,80 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info; +import org.jivesoftware.smack.Connection; +// API level 8 +//import android.net.http.AndroidHttpClient; +//import org.apache.http.client.HttpClient; + +/** + * A factory for AvatarRetriever. + */ +public final class AvatarRetrieverFactory { + + /** + * Private constructor. + */ + private AvatarRetrieverFactory() { + } + + /** + * Get a AvatarRetriever to retrieve this avatar. + * + * @param con the connection + * @param from the user which own the avatar + * @param info the metadata information of the avatar to retrieve + * @return an AvatarRetriever null if none can retrieve this avatar + */ + public static AvatarRetriever getRetriever(Connection con, String from, Info info) { + String url = info.getUrl(); + if (url != null) { + // return new HttpAvatarRetriever(url); + // HttpClient client = AndroidHttpClient.newInstance("Beem"); + return new HttpClientAvatarRetriever(url); + } + return new XmppAvatarRetriever(con, from, info.getId()); + } +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/FileAvatarCache.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/FileAvatarCache.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,121 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * An implementation of an AvatarCache which store the data of the filesystem. + */ +public class FileAvatarCache implements AvatarCache { + + private File mStoreDir; + + /** + * Create a FileAvatarCache. + * + * @param storedir The directory used to store the data. + */ + public FileAvatarCache(final File storedir) { + if (storedir.exists() && !storedir.isDirectory()) + throw new IllegalArgumentException("The store directory must be a directory"); + mStoreDir = storedir; + mStoreDir.mkdirs(); + } + + @Override + public void put(String key, byte[] data) throws IOException { + File f = new File(mStoreDir, key); + OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); + try { + os.write(data); + } finally { + os.close(); + } + } + + @Override + public void put(String key, InputStream in) throws IOException { + File f = new File(mStoreDir, key); + OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); + try { + byte[] data = new byte[1024]; + int nbread; + while ((nbread = in.read(data)) != -1) + os.write(data, 0, nbread); + } finally { + in.close(); + os.close(); + } + } + + @Override + public byte[] get(String key) throws IOException { + File f = new File(mStoreDir, key); + InputStream is = new BufferedInputStream(new FileInputStream(f)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + byte[] data = new byte[1024]; + is.read(data); + bos.write(data); + } finally { + is.close(); + } + return bos.toByteArray(); + } + + @Override + public boolean contains(String key) { + File f = new File(mStoreDir, key); + return f.exists(); + } +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/HttpAvatarRetriever.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/HttpAvatarRetriever.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,96 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.io.InputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.URL; + +/** + * An AvatarRetriever which retrieve the avatar over HTTP. + */ +public class HttpAvatarRetriever implements AvatarRetriever { + + private URL mUrl; + private String mUrlString; + + /** + * Create a HttpAvatarRetriever. + * + * @param url the url of the avatar to download. + */ + public HttpAvatarRetriever(final URL url) { + mUrl = url; + } + + /** + * Create a HttpAvatarRetriever. + * + * @param url the url of the avatar to download. + */ + public HttpAvatarRetriever(final String url) { + mUrlString = url; + } + + @Override + public byte[] getAvatar() throws IOException { + if (mUrl == null) + mUrl = new URL(mUrlString); + InputStream in = mUrl.openStream(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try { + byte[] data = new byte[1024]; + int nbread; + while ((nbread = in.read(data)) != -1) { + os.write(data, 0, nbread); + } + } finally { + in.close(); + os.close(); + } + return os.toByteArray(); + } + +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/HttpClientAvatarRetriever.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/HttpClientAvatarRetriever.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,112 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.io.InputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.HttpResponse; +import org.apache.http.HttpEntity; + +/** + * An AvatarRetriever which retrieve the avatar over HTTP using the Apache HttpClient. + */ +public class HttpClientAvatarRetriever implements AvatarRetriever { + + private String mUrl; + private HttpClient mClient; + + /** + * Create a HttpAvatarRetriever. + * + * @param client the custom HttpClient to use to downlowad + * @param url the url of the avatar to download. + */ + public HttpClientAvatarRetriever(final HttpClient client, final String url) { + mUrl = url; + mClient = client; + } + + /** + * Create a HttpAvatarRetriever. + * + * @param url the url of the avatar to download. + */ + public HttpClientAvatarRetriever(final String url) { + mUrl = url; + mClient = new DefaultHttpClient(); + } + + @Override + public byte[] getAvatar() throws IOException { + HttpUriRequest request; + try { + request = new HttpGet(mUrl); + } catch (IllegalArgumentException e) { + IOException ioe = new IOException("Invalid url " + mUrl); + ioe.initCause(e); + throw ioe; + } + HttpResponse response = mClient.execute(request); + HttpEntity entity = response.getEntity(); + InputStream in = entity.getContent(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try { + byte[] data = new byte[1024]; + int nbread; + while ((nbread = in.read(data)) != -1) { + os.write(data, 0, nbread); + } + } finally { + in.close(); + os.close(); + } + return os.toByteArray(); + } + +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/XmppAvatarRetriever.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/XmppAvatarRetriever.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,92 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.avatar; + +import java.util.List; +import java.util.Arrays; +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.pubsub.LeafNode; +import org.jivesoftware.smackx.pubsub.Item; +import org.jivesoftware.smackx.pubsub.PayloadItem; + +import com.beem.project.beem.smack.pep.PepSubManager; + +/** + * An AvatarRetriever which retrieve the avatar over the XMPP connection. + */ +public class XmppAvatarRetriever implements AvatarRetriever { + + private static String AVATARDATANODE = "urn:xmpp:avatar:data"; + private PepSubManager mPubsub; + private String mFrom; + private String mId; + + /** + * Create an XmppAvatarRetriever. + * + * @param con the xmpp connection + * @param from the contact from which we retrieve the avatar + * @param id the id of the avatar to retrieve + */ + public XmppAvatarRetriever(final Connection con, final String from, final String id) { + mPubsub = new PepSubManager(con, from); + mFrom = from; + mId = id; + } + + @Override + public byte[] getAvatar() { + try { + LeafNode node = mPubsub.getPEPNode(AVATARDATANODE); + List items = node.getItems(Arrays.asList(mId)); + PayloadItem item = (PayloadItem) items.get(0); + AvatarExtension avatar = item.getPayload(); + return avatar.getData(); + } catch (XMPPException e) { + return null; + } + } + +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/avatar/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/package-info.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,48 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ + +/** + * This package contains implementation of XEP-0084 User Avatar. + */ +package com.beem.project.beem.smack.avatar; diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/caps/CapsExtension.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/caps/CapsManager.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/caps/CapsProvider.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/caps/package-info.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/pep/PEPListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/pep/PEPListener.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,63 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.pep; + +import org.jivesoftware.smackx.pubsub.Item; +import java.util.List; + +/** + * A listener that is fired anytime a PEP event message is received. + */ +public interface PEPListener { + + /** + * Called when PEP events are received. + * + * @param from the JID of the user who send the event + * @param node the node of the items in the event + * @param items the different items of the event + */ + void eventReceived(String from, String node, List items); + +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/pep/PepSubManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/pep/PepSubManager.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,158 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.smack.pep; + +import java.util.ArrayList; +import java.util.List; + +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.filter.PacketExtensionFilter; +import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smackx.pubsub.EventElement; +import org.jivesoftware.smackx.pubsub.EventElementType; +import org.jivesoftware.smackx.pubsub.Item; +import org.jivesoftware.smackx.pubsub.ItemsExtension; +import org.jivesoftware.smackx.pubsub.PubSubManager; +import org.jivesoftware.smackx.pubsub.LeafNode; + +/** + * Little extension of {@link PubSubManager} which allows to add {@link PEPListener}. + * + */ +public class PepSubManager extends PubSubManager { + private List mPepListeners = new ArrayList(); + private PacketFilter mPacketFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event"); + + /** + * Create a PepSubManager. + * + * @param connection the connection + */ + public PepSubManager(final Connection connection) { + super(connection); + init(connection); + } + + /** + * Create a PepSubManager associated to the specified connection where the pubsub + * requests require a specific to address for packets. + * + * @param connection the connection + * @param toAddress The pubsub specific to address (required for some servers) + */ + public PepSubManager(final Connection connection, final String toAddress) { + super(connection, toAddress); + init(connection); + } + + /** + * Add a listener to PEP event. + * + * @param listener the listener + */ + public void addPEPListener(PEPListener listener) { + if (!mPepListeners.contains(listener)) + mPepListeners.add(listener); + } + + /** + * Remove a listener to PEP event. + * + * @param listener the listener + */ + public void removePEPListener(PEPListener listener) { + mPepListeners.remove(listener); + } + + /** + * Get a PepNode. + * This node is obtain without checking its existence as PEP should auto create it. + * + * @param nodeName the node name + * @return the node + */ + public LeafNode getPEPNode(String nodeName) { + LeafNode node = new LeafNode(con, nodeName); + node.setTo(to); + return node; + } + + /** + * Initialize the PepSubManager. + * + * @param con the connection + */ + private void init(Connection con) { + PacketListener packetListener = new PacketListener() { + + @Override + public void processPacket(Packet packet) { + EventElement e = (EventElement) packet.getExtension("event", "http://jabber.org/protocol/pubsub#event"); + if (e.getEventType() != EventElementType.items) + return; + ItemsExtension it = (ItemsExtension) e.getEvent(); + if (it.getItemsElementType() != ItemsExtension.ItemsElementType.items) + return; + List items = (List) it.getItems(); + firePEPListeners(packet.getFrom(), it.getNode(), items); + } + }; + con.addPacketListener(packetListener, mPacketFilter); + } + + /** + * Fire the PEP listeners. + * + * @param from the JID of the user who send the event + * @param node the node of the items in the event + * @param items the different items of the event + */ + private void firePEPListeners(String from, String node, List items) { + for (PEPListener listener : mPepListeners) { + listener.eventReceived(from, node, items); + } + } +} diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/smack/pep/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/pep/package-info.java Mon Dec 06 01:06:44 2010 +0100 @@ -0,0 +1,49 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ + +/** + * This package contains an implementation of XEP-0163 Personnal Eventing Protocol based on the pubsub implementation. + */ +package com.beem.project.beem.smack.pep; + diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/AddContact.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/ChangeStatus.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/Chat.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Mon Dec 06 01:06:22 2010 +0100 +++ b/src/com/beem/project/beem/ui/ContactList.java Mon Dec 06 01:06:44 2010 +0100 @@ -49,6 +49,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.io.ByteArrayInputStream; import org.jivesoftware.smack.util.StringUtils; @@ -81,9 +82,11 @@ import android.widget.Filter; import android.widget.Filterable; import android.widget.Gallery; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; +import android.graphics.drawable.Drawable; import com.beem.project.beem.R; import com.beem.project.beem.service.Contact; @@ -660,6 +663,22 @@ v.setText(curContact.getName()); v = (TextView) view.findViewById(R.id.contactlistmsgperso); v.setText(curContact.getMsgState()); + Drawable d = null; + try { + String avatarId = curContact.getAvatarId(); + byte[] avatar = mXmppFacade.getAvatar(avatarId); + if (avatar != null) { + ByteArrayInputStream in = new ByteArrayInputStream(avatar); + d = Drawable.createFromStream(in, avatarId); + } + } catch (RemoteException e) { + Log.e(TAG, "Error while setting the avatar", e); + } + ImageView img = (ImageView) view.findViewById(R.id.avatar); + if (d != null) + img.setImageDrawable(d); + else + img.setImageResource(R.drawable.beem_launcher_icon_silver); } } diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/CreateAccount.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/GroupList.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/Login.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/LoginAnim.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/PrivacyList.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/Settings.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/Subscription.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/dialogs/builders/Alias.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/dialogs/builders/ChatList.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/dialogs/builders/CreatePrivacyList.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/dialogs/builders/DeleteContact.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/dialogs/builders/DeletePrivacyList.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/dialogs/builders/ResendSubscription.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/dialogs/builders/package-info.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/package-info.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/wizard/Account.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/wizard/AccountConfigure.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/ui/wizard/package-info.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/utils/BeemBroadcastReceiver.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/utils/BeemConnectivity.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/utils/FreePort.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/utils/PresenceType.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/utils/SortedList.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/utils/Status.java diff -r bcafceecd837 -r 2ef1c6096069 src/com/beem/project/beem/utils/package-info.java diff -r bcafceecd837 -r 2ef1c6096069 tools/JavaHeaderCheck.regex diff -r bcafceecd837 -r 2ef1c6096069 tools/LicenseHeader.txt diff -r bcafceecd837 -r 2ef1c6096069 tools/README diff -r bcafceecd837 -r 2ef1c6096069 tools/checkstyle.xml diff -r bcafceecd837 -r 2ef1c6096069 tools/eclipse_formatter.xml