--- /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;
--- /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 <b>pubsub</b>
+ */
+- 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<String, Node> nodeMap = new ConcurrentHashMap<String, Node>();
+
+ /**
Binary file libs/asmack-android-7-beem.jar has changed
--- 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 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
+ android:orientation="vertical" android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
- <TextView android:id="@+id/chatmessagename"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:textSize="16sp"
- android:textColor="#FFFFFF"
- android:textStyle="bold"
- android:paddingBottom="1dp"
- />
- <TextView android:id="@+id/chatmessagedate"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentRight="true"
- android:autoLink="all"
- />
- <TextView android:id="@+id/chatmessagetext"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@id/chatmessagename"
- android:autoLink="all"
- />
-
-
+ <TextView android:id="@+id/chatmessagename"
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
+ android:textSize="16sp" android:textColor="#FFFFFF" android:textStyle="bold"
+ android:paddingBottom="1dp" />
+ <TextView android:id="@+id/chatmessagedate"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:layout_alignParentTop="true" android:layout_alignParentRight="true"
+ android:autoLink="none" />
+ <TextView android:id="@+id/chatmessagetext"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true" android:layout_below="@id/chatmessagename"
+ android:autoLink="all" />
</RelativeLayout>
--- 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 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
android:layout_height="wrap_content" android:paddingLeft="10px"
android:paddingRight="10px" android:paddingTop="8dip"
android:paddingBottom="8dip" >
+ <ImageView android:id="@+id/avatar"
+ android:layout_width="48dip" android:layout_height="48dip"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ />
<TextView android:id="@+id/contactlistpseudo"
android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_toRightOf="@id/avatar"
android:singleLine="true"
android:maxLines="1" android:textColor="@color/white"
android:drawablePadding="12px"
+ android:paddingLeft="10dip"
android:textSize="18sp" android:textStyle="bold" />
<TextView android:id="@+id/contactlistmsgperso"
android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:layout_below="@id/contactlistpseudo"
+ android:layout_toRightOf="@id/avatar"
android:paddingLeft="30px" android:singleLine="true"
android:maxLines="1" android:linksClickable="false" android:autoLink="all"
android:scrollHorizontally="true" android:textColorLink="@color/white"
android:textSize="12sp" />
-</LinearLayout>
+</RelativeLayout>
--- 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());
--- 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<String> mRes;
private final List<String> mGroups = new ArrayList<String>();
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<String>();
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.
*/
--- 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<IBeemRosterListener>();
private final Map<Integer, String> mDefaultStatusMessages;
private final RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
+ private Map<String, String> mAvatarIdmap = new HashMap<String, String>();
+ 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<Presence> 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<Info> avatarInfos) {
+ String bare = StringUtils.parseBareAddress(from);
+ if (avatarId == null)
+ mAvatarIdmap.remove(bare);
+ else {
+ mAvatarIdmap.put(bare, avatarId);
+ }
+ }
+ }
}
--- 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<IBeemConnectionListener> mRemoteConnListeners =
new RemoteCallbackList<IBeemConnectionListener>();
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<DiscoverInfo.Identity> 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
*/
--- 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);
}
}
--- 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();
}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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);
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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("<data xmlns=\"");
+ builder.append(getNamespace()).append("\">");
+ builder.append(mData);
+ builder.append("</data>");
+ return builder.toString();
+ }
+
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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<Info> avatarInfos);
+
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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<AvatarListener> mListeners = new LinkedList<AvatarListener>();
+
+ /**
+ * 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<Info> 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<Info> 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<Item> items) {
+ if (!"urn:xmpp:avatar:metadata".equals(node))
+ return;
+ Item i = items.get(0);
+ if (i instanceof PayloadItem) {
+ PayloadItem<PacketExtension> pi = (PayloadItem<PacketExtension>) i;
+ PacketExtension ex = pi.getPayload();
+ if (ex instanceof AvatarMetadataExtension) {
+ AvatarMetadataExtension ext = (AvatarMetadataExtension) ex;
+ String id = i.getId();
+ List<Info> infos = ext.getInfos();
+ if (infos.size() > 0 && mAutoDownload) {
+ Info info = selectAvatar(infos);
+ if (!mCache.contains(id))
+ downloadAvatar(from, id, info);
+ }
+ fireListeners(from, id, infos);
+ }
+ }
+ }
+ }
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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<Info> mInfos = new LinkedList<Info>();
+
+ /**
+ * Create an AvatarMetadataExtension.
+ */
+ public AvatarMetadataExtension() {
+ }
+
+ /**
+ * Get the metadata informations.
+ *
+ * @return a list of informations
+ */
+ public List<Info> 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("<metadata xmlns=\"");
+ builder.append(getNamespace()).append("\">");
+ for (Info info : mInfos) {
+ builder.append(info.toXML());
+ }
+ builder.append("</metadata>");
+ 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("<info ");
+ builder.append("id=\"" + mId + "\"");
+ builder.append(" type=\"" + mType + "\"");
+ builder.append(" bytes=\"" + mBytes + "\"");
+
+ if (mHeight > 0)
+ builder.append(" height=\"" + mHeight + "\"");
+ if (mWidth > 0)
+ builder.append(" width=\"" + mWidth + "\"");
+ if (mUrl != null)
+ builder.append(" url=\"" + mUrl + "\"");
+ builder.append(" />");
+ return builder.toString();
+ }
+ }
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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;
+ }
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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;
+ }
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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;
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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());
+ }
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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();
+ }
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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();
+ }
+
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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();
+ }
+
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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<Item> items = node.getItems(Arrays.asList(mId));
+ PayloadItem<AvatarExtension> item = (PayloadItem<AvatarExtension>) items.get(0);
+ AvatarExtension avatar = item.getPayload();
+ return avatar.getData();
+ } catch (XMPPException e) {
+ return null;
+ }
+ }
+
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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;
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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<Item> items);
+
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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<PEPListener> mPepListeners = new ArrayList<PEPListener>();
+ 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<Item> items = (List<Item>) 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<Item> items) {
+ for (PEPListener listener : mPepListeners) {
+ listener.eventReceived(from, node, items);
+ }
+ }
+}
--- /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 <http://www.gnu.org/licenses/>.
+
+ 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;
+
--- 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);
}
}