--- a/src/com/beem/project/beem/service/Contact.java Sat Apr 04 19:02:11 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java Sat Apr 04 20:03:43 2009 +0200
@@ -3,6 +3,9 @@
*/
package com.beem.project.beem.service;
+import java.util.ArrayList;
+import java.util.List;
+
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
@@ -17,179 +20,200 @@
*/
public class Contact implements Parcelable {
- public static final int CONTACT_STATUS_DISCONNECT = 100;
- public static final int CONTACT_STATUS_UNAVAILABLE = 200;
- public static final int CONTACT_STATUS_AWAY = 300;
- public static final int CONTACT_STATUS_BUSY = 400;
- public static final int CONTACT_STATUS_AVAILABLE = 500;
- public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
-
-
- /**
- * Parcelable.Creator needs by Android.
- */
- public static final Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator<Contact>() {
-
- @Override
- public Contact createFromParcel(Parcel source) {
- return new Contact(source);
- }
-
- @Override
- public Contact[] newArray(int size) {
- return new Contact[size];
- }
- };
- private static final String TAG = "Contact";
-
- private String mJID;
- private int mID;
- private int mStatus;
-
- /**
- * @return the mID
- */
- public int getID() {
- return mID;
- }
-
- /**
- * @param mid the mID to set
- */
- public void setID(int mid) {
- mID = mid;
- }
+ public static final int CONTACT_STATUS_DISCONNECT = 100;
+ public static final int CONTACT_STATUS_UNAVAILABLE = 200;
+ public static final int CONTACT_STATUS_AWAY = 300;
+ public static final int CONTACT_STATUS_BUSY = 400;
+ public static final int CONTACT_STATUS_AVAILABLE = 500;
+ public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
+ private static final String TAG = "Contact";
- /**
- * @return the mStatus
- */
- public int getStatus() {
- return mStatus;
- }
-
- /**
- * @param status the mStatus to set
- */
- public void setStatus(int status) {
- mStatus = status;
- }
-
- /**
- * @return the mMsgState
- */
- public String getMMsgState() {
- return mMsgState;
- }
+ private int mID;
+ private int mStatus;
+ private String mJID;
+ private String mMsgState;
+ private List<String> mRes;
- /**
- * @param msgState the mMsgState to set
- */
- public void setMMsgState(String msgState) {
- mMsgState = msgState;
- }
-
- private String mMsgState;
+ /**
+ * Parcelable.Creator needs by Android.
+ */
+ public static final Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator<Contact>() {
- /**
- * Constructor.
- */
- public Contact() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructor.
- * @param jid JID of the contact
- */
- public Contact(final String jid) {
- mJID = jid;
+ @Override
+ public Contact createFromParcel(Parcel source) {
+ return new Contact(source);
}
- public Contact(RosterEntry entry, Presence presence) {
- mJID = entry.getUser();
- Log.w(TAG, "Contact Name: " + entry.getUser());
- if (presence.getType().equals(Presence.Type.unavailable)) {
- mStatus = Contact.CONTACT_STATUS_DISCONNECT;
- Log.w(TAG, "Error while creating Contact");
- } else {
- setStatus(presence.getMode());
- }
+ @Override
+ public Contact[] newArray(int size) {
+ return new Contact[size];
}
+ };
- /**
- * @param status the XMPP presence mode
- */
- public void setStatus(Mode mode) {
- switch (mode) {
+ /**
+ * Construct a contact from a parcel.
+ * @param in parcel to use for construction
+ */
+ private Contact(final Parcel in) {
+ mID = in.readInt();
+ mStatus = in.readInt();
+ mJID = in.readString();
+ mMsgState = in.readString();
+ mRes = new ArrayList<String>();
+ in.readStringList(mRes);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mID);
+ dest.writeInt(mStatus);
+ dest.writeString(mJID);
+ dest.writeString(mMsgState);
+ dest.writeStringList(getMRes());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int describeContents() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /**
+ * Constructor.
+ */
+ public Contact() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ * @param jid JID of the contact
+ */
+ public Contact(final String jid) {
+ mJID = jid;
+ mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+ mRes = new ArrayList<String>();
+ mRes.add("none");
+ }
+
+ /**
+ * @return the mID
+ */
+ public int getID() {
+ return mID;
+ }
+
+ /**
+ * @param mid the mID to set
+ */
+ public void setID(int mid) {
+ mID = mid;
+ }
+
+ /**
+ * @return the mStatus
+ */
+ public int getStatus() {
+ return mStatus;
+ }
+
+ /**
+ * @param status the mStatus to set
+ */
+ public void setStatus(int status) {
+ mStatus = status;
+ }
+
+ /**
+ * @param presence the presence containing status
+ */
+ public void setStatus(Presence presence) {
+ if (presence.getType().equals(Presence.Type.unavailable)) {
+ Log.d(TAG, "Presence pas dispo");
+ mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+ } else {
+ Log.d(TAG,"Presence OK");
+ Mode mode = presence.getMode();
+ switch (mode) {
case available:
- mStatus = Contact.CONTACT_STATUS_AVAILABLE;
- break;
+ mStatus = Contact.CONTACT_STATUS_AVAILABLE;
+ break;
case away:
- mStatus = Contact.CONTACT_STATUS_AWAY;
- break;
+ mStatus = Contact.CONTACT_STATUS_AWAY;
+ break;
case chat:
- mStatus = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
- break;
+ mStatus = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+ break;
case dnd:
- mStatus = Contact.CONTACT_STATUS_BUSY;
- break;
+ mStatus = Contact.CONTACT_STATUS_BUSY;
+ break;
case xa:
- mStatus = Contact.CONTACT_STATUS_UNAVAILABLE;
- break;
+ mStatus = Contact.CONTACT_STATUS_UNAVAILABLE;
+ break;
default:
- Log.e("RosterAdapter", "Status mode non gere");
+ Log.e("RosterAdapter", "Status mode non gere");
mStatus = Contact.CONTACT_STATUS_DISCONNECT;
break;
- }
- }
-
- /**
- * Construct a contact from a parcel.
- * @param in parcel to use for construction
- */
- private Contact(final Parcel in) {
- mID = in.readInt();
- mStatus = in.readInt();
- mJID = in.readString();
- mMsgState = in.readString();
+ }
}
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- // TODO Auto-generated method stub
- dest.writeInt(mID);
- dest.writeInt(mStatus);
- dest.writeString(mJID);
- dest.writeString(mMsgState);
- }
+ /**
+ * @return the mMsgState
+ */
+ public String getMMsgState() {
+ return mMsgState;
+ }
+
+ /**
+ * @param msgState the mMsgState to set
+ */
+ public void setMMsgState(String msgState) {
+ mMsgState = msgState;
+ }
+
+ /**
+ * Get the Jabber ID of the contact.
+ * @return the Jabber ID
+ */
+ public String getJID() {
+ return mJID;
+ }
- /**
- * Get the Jabber ID of the contact.
- * @return the Jabber ID
- */
- public String getJID() {
- return mJID;
- }
+ /**
+ * Set the Jabber ID of the contact.
+ * @param mjid the jabber ID to set
+ */
+ public void setJID(String mjid) {
+ mJID = mjid;
+ }
+
+ public void addRes(String res) {
+ if (!mRes.contains(res))
+ mRes.add(res);
+ }
- /**
- * Set the Jabber ID of the contact.
- * @param mjid the jabber ID to set
- */
- public void setJID(String mjid) {
- mJID = mjid;
- }
+ public void delRes(String res) {
+ mRes.remove(res);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public int describeContents() {
- // TODO Auto-generated method stub
- return 0;
- }
+ /**
+ * @param mRes the mRes to set
+ */
+ public void setMRes(List<String> mRes) {
+ this.mRes = mRes;
+ }
-
+ /**
+ * @return the mRes
+ */
+ public List<String> getMRes() {
+ return mRes;
+ }
}
--- a/src/com/beem/project/beem/service/RosterAdapter.java Sat Apr 04 19:02:11 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java Sat Apr 04 20:03:43 2009 +0200
@@ -15,6 +15,7 @@
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smack.util.StringUtils;
import com.beem.project.beem.service.aidl.IBeemRosterListener;
@@ -28,208 +29,183 @@
*/
public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
- private static final String TAG = "RosterAdapter";
- private Roster mAdaptee;
- private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners =
- new RemoteCallbackList<IBeemRosterListener>();
- private Map<String, Contact> mContacts = new HashMap<String, Contact>();
-
- private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
-
- /**
- * Constructor.
- * @param roster the roster to adapt
- */
- public RosterAdapter(final Roster roster) {
- mAdaptee = roster;
- roster.addRosterListener(mRosterListener);
- for (RosterEntry entry : roster.getEntries()) {
- String user = entry.getUser();
- if ( !mContacts.containsKey(user))
- mContacts.put(user, new Contact(entry, roster.getPresence(user)));
- }
+ private static final String TAG = "RosterAdapter";
+ private Roster mAdaptee;
+ private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners =
+ new RemoteCallbackList<IBeemRosterListener>();
+ private Map<String, Contact> mContacts = new HashMap<String, Contact>();
+
+ private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
+
+ /**
+ * Constructor.
+ * @param roster the roster to adapt
+ */
+ public RosterAdapter(final Roster roster) {
+ mAdaptee = roster;
+ roster.addRosterListener(mRosterListener);
+ for (RosterEntry entry : roster.getEntries()) {
+ String user = StringUtils.parseBareAddress(entry.getUser());
+ if ( !mContacts.containsKey(user))
+ mContacts.put(user, new Contact(user));
+ }
+ }
+
+ @Override
+ public void createGroup(String groupname) throws RemoteException {
+ mAdaptee.createGroup(groupname);
+ }
+
+ @Override
+ public Contact addContact(String user, String name, String[] groups) throws RemoteException {
+ try {
+ mAdaptee.createEntry(user, name, groups);
+ Contact res = new Contact(user);
+ mContacts.put(user, res);
+ return res;
+ } catch (XMPPException e) {
+ return null;
}
+ }
- @Override
- public void createGroup(String groupname) throws RemoteException {
- mAdaptee.createGroup(groupname);
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void deleteContact(Contact contact) throws RemoteException {
+ mContacts.remove(contact.getJID());
+ }
+
+ @Override
+ public void addConnectionListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.register(listen);
+ }
+
+ @Override
+ public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.unregister(listen);
+ }
+
+ @Override
+ public Contact getContact(String jid) throws RemoteException {
+ return mContacts.get(jid);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Contact> getContactList() throws RemoteException {
+ List<Contact> res = new ArrayList<Contact>();
+ res.addAll(mContacts.values());
+ return res;
+ }
+
+ private class RosterListenerAdapter implements RosterListener {
@Override
- public Contact addContact(String user, String name, String[] groups) throws RemoteException {
- try {
- mAdaptee.createEntry(user, name, groups);
- Contact res = new Contact(user);
- mContacts.put(user, res);
- return res;
- } catch (XMPPException e) {
- return null;
- }
- }
+ public void entriesAdded(Collection<String> addresses) {
+ Log.i(TAG, "Ajout de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
- /**
- * {@inheritDoc}
- */
- @Override
- public void deleteContact(Contact contact) throws RemoteException {
- mContacts.remove(contact.getJID());
- }
-
- @Override
- public void addConnectionListener(IBeemRosterListener listen) throws RemoteException {
- if (listen != null)
- mRemoteRosListeners.register(listen);
- }
-
- @Override
- public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException {
- if (listen != null)
- mRemoteRosListeners.unregister(listen);
+ List<String> tab = new ArrayList<String>();
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ tab.addAll(addresses);
+ listener.onEntriesAdded(tab);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while adding roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
}
@Override
- public Contact getContact(String jid) throws RemoteException {
- return mContacts.get(jid);
+ public void entriesDeleted(Collection<String> addresses) {
+ Log.i(TAG, "Suppression de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ tab.addAll(addresses);
+ listener.onEntriesDeleted(tab);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while deleting roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<Contact> getContactList() throws RemoteException {
- List<Contact> res = new ArrayList<Contact>();
- res.addAll(mContacts.values());
- return res;
+ public void entriesUpdated(Collection<String> addresses) {
+ Log.i(TAG, "Update de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ tab.addAll(addresses);
+ listener.onEntriesUpdated(tab);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while updating roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
}
- private class RosterListenerAdapter implements RosterListener {
-
- @Override
- public void entriesAdded(Collection<String> addresses) {
- final int n = mRemoteRosListeners.beginBroadcast();
-
- List<String> tab = new ArrayList<String>();
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- tab.addAll(addresses);
- listener.onEntriesAdded(tab);
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while adding roster entries", e);
- }
- }
- mRemoteRosListeners.finishBroadcast();
-
- }
-
- @Override
- public void entriesDeleted(Collection<String> addresses) {
- final int n = mRemoteRosListeners.beginBroadcast();
-
- List<String> tab = new ArrayList<String>();
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- tab.addAll(addresses);
- listener.onEntriesDeleted(tab);
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while deleting roster entries", e);
- }
- }
- mRemoteRosListeners.finishBroadcast();
- }
-
- @Override
- public void entriesUpdated(Collection<String> addresses) {
- final int n = mRemoteRosListeners.beginBroadcast();
-
- List<String> tab = new ArrayList<String>();
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- tab.addAll(addresses);
- listener.onEntriesUpdated(tab);
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while updating roster entries", e);
- }
- }
- mRemoteRosListeners.finishBroadcast();
- }
+ @Override
+ public void presenceChanged(Presence presence) {
+ Log.i(TAG, "Changement de Presence");
+ /* gestion du roster coter sedirvice */
+ String user = StringUtils.parseBareAddress(presence.getFrom());
+ Log.d(TAG, "User : "+user);
+ Contact c = mContacts.get(StringUtils.parseBareAddress(user));
+ if (c == null) {
+ c = new Contact(user);
+ mContacts.put(user, c);
+ }
+ c.addRes(StringUtils.parseResource(presence.getFrom()));
+ c.setStatus(mAdaptee.getPresence(presence.getFrom()));
+ /* redispatch vers les IBeemRosterListener */
+ final int n = mRemoteRosListeners.beginBroadcast();
- @Override
- public void presenceChanged(Presence presence) {
- Log.w(TAG, "Changement de Presence");
- /* gestion du roster coter service */
- String user = presence.getFrom();
- //Presence bestPresence = mAdaptee.getPresence(user);
- Contact c = mContacts.get(user);
- if (c == null) {
- c = new Contact(user);
- mContacts.put(user, c);
- }
- int status;
- if (presence.getType().equals(Presence.Type.unavailable))
- status = Contact.CONTACT_STATUS_DISCONNECT;
- else {
- switch (presence.getMode()) {
- case available:
- status = Contact.CONTACT_STATUS_AVAILABLE;
- break;
- case away:
- status = Contact.CONTACT_STATUS_AWAY;
- break;
- case chat:
- status = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
- break;
- case dnd:
- status = Contact.CONTACT_STATUS_BUSY;
- break;
- case xa:
- status = Contact.CONTACT_STATUS_UNAVAILABLE;
- break;
- default:
- Log.e("RosterAdapter", "Status mode non gere");
- status = Contact.CONTACT_STATUS_DISCONNECT;
- break;
- }
- }
- c.setStatus(status);
-
- /* redispatch vers les IBeemRosterListener */
- final int n = mRemoteRosListeners.beginBroadcast();
-
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- listener.onPresenceChanged(new PresenceAdapter(presence));
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while updating roster entries", e);
- }
- }
- mRemoteRosListeners.finishBroadcast();
- }
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onPresenceChanged(new PresenceAdapter(presence));
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while updating roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<String> getGroupsNames() throws RemoteException {
+ Collection<RosterGroup> groups = mAdaptee.getGroups();
+ ArrayList<String> result = new ArrayList<String>(groups.size());
+ for (RosterGroup rosterGroup : groups) {
+ result.add(rosterGroup.getName());
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<String> getGroupsNames() throws RemoteException {
- Collection<RosterGroup> groups = mAdaptee.getGroups();
- ArrayList<String> result = new ArrayList<String>(groups.size());
- for (RosterGroup rosterGroup : groups) {
- result.add(rosterGroup.getName());
- }
- return result;
- }
+ return result;
+ }
}
--- a/src/com/beem/project/beem/service/aidl/IRoster.aidl Sat Apr 04 19:02:11 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Sat Apr 04 20:03:43 2009 +0200
@@ -13,7 +13,7 @@
void createGroup(in String groupname);
- List<Contact> getContactList();
+ List<Contact> getContactList();
List<String> getGroupsNames();