merge
authornikita@localhost
Tue, 23 Jun 2009 13:45:19 +0200
changeset 271 e5040078e3bb
parent 270 728e2d6b4e2b (current diff)
parent 268 68eb7cb08ba3 (diff)
child 272 08effaddeaa4
child 277 48eaf4f08062
merge
res/layout/contactdialog.xml
res/values/strings.xml
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/service/Contact.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/ui/ContactDialog.java
--- a/AndroidManifest.xml	Tue Jun 23 13:36:16 2009 +0200
+++ b/AndroidManifest.xml	Tue Jun 23 13:45:19 2009 +0200
@@ -20,7 +20,8 @@
 		<activity android:name=".ui.Subscription" android:label="@string/app_name" />
 		<activity android:name=".ui.EditSettings" android:label="@string/edit_settings_name" />
 		<activity android:name=".ui.CreateAccount" android:label="@string/create_account_name" />
-		<activity android:name=".ui.ContactList" android:label="@string/contact_list_name" android:launchMode="singleTask" />
+		<activity android:name=".ui.ContactList" android:label="@string/contact_list_name"
+			android:launchMode="singleTask" />
 		<service android:name="BeemService" android:enabled="true"
 			android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE">
 			<intent-filter>
--- a/res/layout/contactdialog.xml	Tue Jun 23 13:36:16 2009 +0200
+++ b/res/layout/contactdialog.xml	Tue Jun 23 13:45:19 2009 +0200
@@ -9,8 +9,8 @@
 	<Button android:id="@+id/CDAlias" android:layout_width="fill_parent"
 		android:layout_height="wrap_content" android:text="@string/CDAlias" />
 
-	<Button android:id="@+id/CDGroup" android:layout_width="fill_parent"
-		android:layout_height="wrap_content" android:text="@string/CDGroup" />
+	<Button android:id="@+id/CDDelete" android:layout_width="fill_parent"
+		android:layout_height="wrap_content" android:text="@string/CDDelete" />
 
 	<Button android:id="@+id/CDResend" android:layout_width="fill_parent"
 		android:layout_height="wrap_content" android:text="@string/CDResend" />
--- a/res/values/strings.xml	Tue Jun 23 13:36:16 2009 +0200
+++ b/res/values/strings.xml	Tue Jun 23 13:45:19 2009 +0200
@@ -5,23 +5,23 @@
 	<string name="ClearButton">Clear</string>
 	<string name="AcceptButton">Accept</string>
 	<string name="RefuseButton">Refuse</string>
-	
+
 	<!--  Beem class -->
-	
+
 	<string name="BeemJabberID">Jabber ID</string>
-	
+
 	<!--  BeemApplication class -->
-	
+
 	<string name="BeemApplicationConnect">Connecting...</string>
-	
+
 	<!--  BeemService class -->
-	
+
 	<string name="BeemServiceDescription">Use the Beem Service</string>
 	<string name="BeemServiceCreated">BeemService Created</string>
 	<string name="BeemServiceDestroyed">BeemService destroyed</string>
 
 	<!--  Preferences informations -->
-	
+
 	<string name="PreferenceFileName">Beem</string>
 	<string name="PreferenceHostKey">host</string>
 	<string name="PreferenceJID">Jabber ID</string>
@@ -51,15 +51,18 @@
 	<string name="CLSProxyInfo">Proxy informations</string>
 	<string name="CLSLogin">Login:</string>
 	<string name="CLSOkButton">Ok</string>
-	
+
 	<!--  ContactDialog class -->
 	<string name="CDChat">Chat</string>
 	<string name="CDAlias">Alias</string>
-	<string name="CDGroup">Change group</string>
 	<string name="CDResend">Resend suscription</string>
 	<string name="CDInfos">User infos</string>
 	<string name="CDBlock">Block user</string>
-	
+	<string name="CDDelete">Delete user</string>
+	<string name="CDSure2Delete">Are you sure you want to delete this contact?
+	</string>
+	<string name="CDSure2DeleteYes">Yes</string>
+	<string name="CDSure2DeleteNo">No</string>
 	<!-- AccountCreation class -->
 	<string name="ACLogin">Login:</string>
 	<string name="ACEmail">Email:</string>
@@ -69,7 +72,7 @@
 	<string name="ACOkLoginButton">Log with</string>
 	<string name="ACBadForm">Bad form</string>
 	<string name="ACCreated">Account created</string>
-	
+
 	<!-- AddContact class -->
 	<string name="AddCActTitle">Beem - Add contact</string>
 	<string name="AddCLogin">Login:</string>
@@ -78,7 +81,7 @@
 	<string name="AddCOkButton">Ok</string>
 	<string name="AddCContactAdded">Contact added</string>
 	<string name="AddCBadForm">Bad form</string>
-	
+
 	<!--  SendIM class -->
 
 	<string name="SendIMActTitle">Beem - Chat</string>
--- a/src/com/beem/project/beem/BeemService.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Tue Jun 23 13:45:19 2009 +0200
@@ -17,6 +17,7 @@
 import android.app.PendingIntent;
 import android.app.Service;
 import android.content.Intent;
+import android.content.ServiceConnection;
 import android.content.SharedPreferences;
 import android.os.IBinder;
 import android.os.RemoteException;
@@ -211,9 +212,8 @@
      */
     @Override
     public IBinder onBind(Intent intent) {
+	Log.e("BEEMSERVICE", "ONBIND()");
 	return mBind;
-	// to forbid a client to bind
-	// return null;
     }
 
     /**
@@ -229,6 +229,7 @@
 	mHost = mSettings.getString(getString(R.string.settings_key_xmpp_server), "");
 	mPort = Integer.parseInt(mSettings.getString(getString(R.string.settings_key_xmpp_port), "5222"));
 
+	Log.i("BEEEMSERVICE", mLogin);
 	if (mHost.equals("talk.google.com"))
 	    mService = "gmail.com";
 	else
@@ -245,8 +246,11 @@
      */
     @Override
     public void onDestroy() {
+	super.onDestroy();
+	Log.e("BEEEMSERVICE", "ONDESTROY");
 	closeConnection();
 	mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
+	Log.e("BEEEMSERVICE", "ONDESTROY");
     }
 
     /**
@@ -254,6 +258,7 @@
      */
     @Override
     public void onStart(Intent intent, int startId) {
+	super.onStart(intent, startId);
 	try {
 	    mConnection.connectAsync();
 	} catch (RemoteException e) {
--- a/src/com/beem/project/beem/service/Contact.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java	Tue Jun 23 13:45:19 2009 +0200
@@ -19,7 +19,6 @@
 
 /**
  * This class contains informations on a jabber contact.
- * 
  * @author darisk
  */
 public class Contact implements Parcelable {
@@ -40,13 +39,13 @@
 	}
     };
 
-    private int                                     mID;
-    private int                                     mStatus;
-    private String                                  mJID;
-    private String                                  mMsgState;
-    private List<String>                            mRes;
-    private List<String>                            mGroups;
-    private String                                  mName;
+    private int mID;
+    private int mStatus;
+    private String mJID;
+    private String mMsgState;
+    private List<String> mRes;
+    private List<String> mGroups;
+    private String mName;
 
     /**
      * Constructor.
@@ -56,9 +55,7 @@
 
     /**
      * Construct a contact from a parcel.
-     * 
-     * @param in
-     *            parcel to use for construction
+     * @param in parcel to use for construction
      */
     private Contact(final Parcel in) {
 	mID = in.readInt();
@@ -74,9 +71,7 @@
 
     /**
      * Constructor.
-     * 
-     * @param jid
-     *            JID of the contact
+     * @param jid JID of the contact
      */
     public Contact(final String jid) {
 	mJID = jid;
@@ -89,11 +84,8 @@
 
     /**
      * Create a contact from a Uri.
-     * 
-     * @param uri
-     *            an uri for the contact
-     * @throws IllegalArgumentException
-     *             if it is not a xmpp uri
+     * @param uri an uri for the contact
+     * @throws IllegalArgumentException if it is not a xmpp uri
      */
     public Contact(Uri uri) {
 	if (!uri.getScheme().equals("xmpp"))
@@ -103,19 +95,20 @@
 
     /**
      * Add a group for the contact.
-     * 
-     * @param group
-     *            the group
+     * @param group the group
      */
     public void addGroup(String group) {
-	mGroups.add(group);
+	if (!mGroups.contains(group))
+	    mGroups.add(group);
+    }
+
+    public void delGroup(String group) {
+	mGroups.remove(group);
     }
 
     /**
      * Add a resource for this contact.
-     * 
-     * @param res
-     *            the resource to add
+     * @param res the resource to add
      */
     public void addRes(String res) {
 	if (!mRes.contains(res))
@@ -124,9 +117,7 @@
 
     /**
      * Delete a resource for this contact.
-     * 
-     * @param res
-     *            the resource de delete
+     * @param res the resource de delete
      */
     public void delRes(String res) {
 	mRes.remove(res);
@@ -143,7 +134,6 @@
 
     /**
      * Get the groups the contact is in.
-     * 
      * @return the mGroups
      */
     public List<String> getGroups() {
@@ -152,7 +142,6 @@
 
     /**
      * Get the id of the contact on the phone contact list.
-     * 
      * @return the mID
      */
     public int getID() {
@@ -161,7 +150,6 @@
 
     /**
      * Get the Jabber ID of the contact.
-     * 
      * @return the Jabber ID
      */
     public String getJID() {
@@ -170,7 +158,6 @@
 
     /**
      * Get the list of resource for the contact.
-     * 
      * @return the mRes
      */
     public List<String> getMRes() {
@@ -179,7 +166,6 @@
 
     /**
      * Get the message status of the contact.
-     * 
      * @return the message status of the contact.
      */
     public String getMsgState() {
@@ -195,7 +181,6 @@
 
     /**
      * Get the status of the contact.
-     * 
      * @return the mStatus
      */
     public int getStatus() {
@@ -204,9 +189,7 @@
 
     /**
      * Set the groups the contact is in.
-     * 
-     * @param groups
-     *            list of groups
+     * @param groups list of groups
      */
     public void setGroups(Collection<RosterGroup> groups) {
 	this.mGroups.clear();
@@ -217,9 +200,7 @@
 
     /**
      * Set the groups the contact is in.
-     * 
-     * @param mGroups
-     *            the mGroups to set
+     * @param mGroups the mGroups to set
      */
     public void setGroups(List<String> mGroups) {
 	this.mGroups = mGroups;
@@ -227,9 +208,7 @@
 
     /**
      * set the id of te contact on the phone contact list.
-     * 
-     * @param mid
-     *            the mID to set
+     * @param mid the mID to set
      */
     public void setID(int mid) {
 	mID = mid;
@@ -237,9 +216,7 @@
 
     /**
      * Set the Jabber ID of the contact.
-     * 
-     * @param jid
-     *            the jabber ID to set
+     * @param jid the jabber ID to set
      */
     public void setJID(String jid) {
 	mJID = jid;
@@ -247,9 +224,7 @@
 
     /**
      * Set a list of resource for the contact.
-     * 
-     * @param mRes
-     *            the mRes to set
+     * @param mRes the mRes to set
      */
     public void setMRes(List<String> mRes) {
 	this.mRes = mRes;
@@ -257,17 +232,14 @@
 
     /**
      * Set the message status of the contact.
-     * 
-     * @param msgState
-     *            the message status of the contact to set
+     * @param msgState the message status of the contact to set
      */
     public void setMsgState(String msgState) {
 	mMsgState = msgState;
     }
 
     /**
-     * @param mName
-     *            the mName to set
+     * @param mName the mName to set
      */
     public void setName(String mName) {
 	if (mName != null)
@@ -276,9 +248,7 @@
 
     /**
      * Set the status of the contact.
-     * 
-     * @param status
-     *            the mStatus to set
+     * @param status the mStatus to set
      */
     public void setStatus(int status) {
 	mStatus = status;
@@ -286,9 +256,7 @@
 
     /**
      * Set the status of the contact using a presence packet.
-     * 
-     * @param presence
-     *            the presence containing status
+     * @param presence the presence containing status
      */
     public void setStatus(Presence presence) {
 	mStatus = Status.getStatusFromPresence(presence);
@@ -297,9 +265,7 @@
 
     /**
      * Set status for the contact.
-     * 
-     * @param presence
-     *            The presence packet which contains the status
+     * @param presence The presence packet which contains the status
      */
     public void setStatus(PresenceAdapter presence) {
 	mStatus = presence.getStatus();
@@ -319,7 +285,6 @@
 
     /**
      * Get a URI to access the contact.
-     * 
      * @return the URI
      */
     public Uri toUri() {
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Tue Jun 23 13:45:19 2009 +0200
@@ -25,133 +25,21 @@
 
 /**
  * This class implement a Roster adapter for BEEM.
- * 
  * @author darisk
  */
 public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
 
-    /**
-     * Listener for the roster events. It will call the remote listeners registered.
-     * 
-     * @author darisk
-     */
-    private class RosterListenerAdapter implements RosterListener {
-
-	/**
-	 * Constructor.
-	 */
-	public RosterListenerAdapter() {
-	    // TODO Auto-generated constructor stub
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void entriesAdded(Collection<String> addresses) {
-	    Log.i(TAG, "Ajout de l'entry");
-	    final int n = mRemoteRosListeners.beginBroadcast();
-
-	    List<String> tab = new ArrayList<String>();
-	    tab.addAll(addresses);
-	    for (int i = 0; i < n; i++) {
-		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-		try {					
-		    listener.onEntriesAdded(tab);
-		} catch (RemoteException e) {
-		    Log.w(TAG, "Error while adding roster entries", e);
-		}
-	    }
-	    mRemoteRosListeners.finishBroadcast();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void entriesDeleted(Collection<String> addresses) {
-	    Log.i(TAG, "Suppression de l'entry");
-	    final int n = mRemoteRosListeners.beginBroadcast();
-
-	    List<String> tab = new ArrayList<String>();
-	    tab.addAll(addresses);
-	    for (int i = 0; i < n; i++) {
-		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-		try {					
-		    listener.onEntriesDeleted(tab);
-		} catch (RemoteException e) {
-		    Log.w(TAG, "Error while deleting roster entries", e);
-		}
-	    }
-	    mRemoteRosListeners.finishBroadcast();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void entriesUpdated(Collection<String> addresses) {
-	    Log.d(TAG, "Update de l'entry");
-	    final int n = mRemoteRosListeners.beginBroadcast();
-
-	    List<String> tab = new ArrayList<String>();
-	    tab.addAll(addresses);
-	    for (int i = 0; i < n; i++) {
-		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-		try {					
-		    listener.onEntriesUpdated(tab);
-		} catch (RemoteException e) {
-		    Log.w(TAG, "Error while updating roster entries", e);
-		}
-	    }
-	    mRemoteRosListeners.finishBroadcast();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void presenceChanged(Presence presence) {
-	    String user = StringUtils.parseBareAddress(presence.getFrom());
-	    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()));
-	    c.setMsgState(presence.getStatus());
-	    c.setName(mAdaptee.getEntry(user).getName());
-	    /* 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();
-	}
-    }
-
-    private static final String                     TAG                 = "RosterAdapter";
-    private Roster                                  mAdaptee;
+    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 Map<String, Contact> mContacts = new HashMap<String, Contact>();
 
-    private RosterListenerAdapter                   mRosterListener     = new RosterListenerAdapter();
+    private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
 
     /**
      * Constructor.
-     * 
-     * @param roster
-     *            the roster to adapt
+     * @param roster the roster to adapt
      */
     public RosterAdapter(final Roster roster) {
 	mAdaptee = roster;
@@ -184,43 +72,47 @@
     public Contact addContact(String user, String name, String[] groups) throws RemoteException {
 	Contact res = null;
 	RosterEntry contact = mAdaptee.getEntry(user);
-	if (contact != null)  {
+	if (contact != null) {
 	    res = mContacts.get(user);
-	    for (String groupStr : groups) {
-		boolean found = false;
-		for (RosterGroup group: mAdaptee.getGroups()) {
-		    if (group.getName().equals(groupStr) && !group.contains(contact)) {
+	    if (groups != null) {
+		for (String groupStr : groups) {
+		    boolean found = false;
+		    for (RosterGroup group : mAdaptee.getGroups()) {
+			if (group.getName().equals(groupStr) && !group.contains(contact)) {
+			    try {
+				group.addEntry(contact);
+				res.addGroup(groupStr);
+				found = true;
+			    } catch (XMPPException e) {
+				e.printStackTrace();
+			    }
+			}
+		    }
+		    if (!found) {
 			try {
-			    group.addEntry(contact);
-			    res.addGroup(groupStr);
-			    found = true;
+			    mAdaptee.createGroup(groupStr).addEntry(contact);
 			} catch (XMPPException e) {
 			    e.printStackTrace();
+			} catch (IllegalArgumentException e) {
 			}
+			res.addGroup(groupStr);
 		    }
 		}
-		if (!found) {
-		    try {
-			mAdaptee.createGroup(groupStr).addEntry(contact);
-		    } catch (XMPPException e) {
-			e.printStackTrace();
-		    } catch (IllegalArgumentException e) {
-		    }
-		    res.addGroup(groupStr);
-		}
 	    }
 	} else {
 	    try {
 		mAdaptee.createEntry(user, name, groups);
 		res = new Contact(user);
 		mContacts.put(user, res);
-		for (String groupStr : groups) {
-		    try {
-			mAdaptee.createGroup(groupStr);
-		    } catch (IllegalArgumentException e) {
-			//e.printStackTrace();
+		if (groups != null) {
+		    for (String groupStr : groups) {
+			try {
+			    mAdaptee.createGroup(groupStr);
+			} catch (IllegalArgumentException e) {
+			    // e.printStackTrace();
+			}
+			res.addGroup(groupStr);
 		    }
-		    res.addGroup(groupStr);
 		}
 	    } catch (XMPPException e) {
 		Log.e(TAG, "Error while adding new contact", e);
@@ -234,16 +126,21 @@
      * {@inheritDoc}
      */
     @Override
-    public void createGroup(String groupname) throws RemoteException {
-	mAdaptee.createGroup(groupname);
+    public void deleteContact(Contact contact, String group) throws RemoteException {
+	mContacts.get(contact.getJID()).delGroup(group);
+	try {
+	    mAdaptee.getGroup(group).removeEntry(mAdaptee.getEntry(contact.getJID()));
+	} catch (XMPPException e) {
+	    e.printStackTrace();
+	}
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public void deleteContact(Contact contact) throws RemoteException {
-	mContacts.remove(contact.getJID());
+    public void createGroup(String groupname) throws RemoteException {
+	mAdaptee.createGroup(groupname);
     }
 
     /**
@@ -300,4 +197,112 @@
 	return new PresenceAdapter(mAdaptee.getPresence(jid));
     }
 
+    /**
+     * Listener for the roster events. It will call the remote listeners registered.
+     * @author darisk
+     */
+    private class RosterListenerAdapter implements RosterListener {
+
+	/**
+	 * Constructor.
+	 */
+	public RosterListenerAdapter() {
+	    // TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void entriesAdded(Collection<String> addresses) {
+	    Log.i(TAG, "Ajout de l'entry");
+	    final int n = mRemoteRosListeners.beginBroadcast();
+
+	    List<String> tab = new ArrayList<String>();
+	    tab.addAll(addresses);
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    listener.onEntriesAdded(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while adding roster entries", e);
+		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void entriesDeleted(Collection<String> addresses) {
+	    Log.i(TAG, "Suppression de l'entry");
+	    final int n = mRemoteRosListeners.beginBroadcast();
+
+	    List<String> tab = new ArrayList<String>();
+	    tab.addAll(addresses);
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    listener.onEntriesDeleted(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while deleting roster entries", e);
+		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void entriesUpdated(Collection<String> addresses) {
+	    Log.d(TAG, "Update de l'entry");
+	    final int n = mRemoteRosListeners.beginBroadcast();
+
+	    List<String> tab = new ArrayList<String>();
+	    tab.addAll(addresses);
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    listener.onEntriesUpdated(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while updating roster entries", e);
+		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void presenceChanged(Presence presence) {
+	    String user = StringUtils.parseBareAddress(presence.getFrom());
+	    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()));
+	    c.setMsgState(presence.getStatus());
+	    c.setName(mAdaptee.getEntry(user).getName());
+	    /* 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();
+	}
+    }
+
 }
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Jun 23 13:45:19 2009 +0200
@@ -248,7 +248,8 @@
 	    for (int i = 0; i < n; i++) {
 		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-		    listener.connectionClosed();
+		    if (listener != null)
+			listener.connectionClosed();
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
 		    // dead listeners.
@@ -269,7 +270,8 @@
 	    for (int i = 0; i < n; i++) {
 		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-		    listener.connectionClosedOnError();
+		    if (listener != null)
+			listener.connectionClosedOnError();
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
 		    // dead listeners.
@@ -286,7 +288,8 @@
 	    for (int i = 0; i < n; i++) {
 		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-		    listener.connectionFailed(errorMsg);
+		    if (listener != null)
+			listener.connectionFailed(errorMsg);
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
 		    // dead listeners.
@@ -305,7 +308,8 @@
 	    for (int i = 0; i < n; i++) {
 		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-		    listener.onConnect();
+		    if (listener != null)
+			listener.onConnect();
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
 		    // dead listeners.
@@ -325,7 +329,8 @@
 	    for (int i = 0; i < n; i++) {
 		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-		    listener.reconnectingIn(arg0);
+		    if (listener != null)
+			listener.reconnectingIn(arg0);
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
 		    // dead listeners.
@@ -345,7 +350,8 @@
 	    for (int i = 0; i < r; i++) {
 		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-		    listener.reconnectionFailed();
+		    if (listener != null)
+			listener.reconnectionFailed();
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
 		    // dead listeners.
@@ -365,7 +371,8 @@
 	    for (int i = 0; i < n; i++) {
 		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
 		try {
-		    listener.reconnectionSuccessful();
+		    if (listener != null)
+			listener.reconnectionSuccessful();
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
 		    // dead listeners.
--- a/src/com/beem/project/beem/service/aidl/IRoster.aidl	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl	Tue Jun 23 13:45:19 2009 +0200
@@ -8,7 +8,7 @@
     
     Contact addContact(in String user, in String name, in String[] groups);
     
-    void deleteContact(in Contact contact);
+    void deleteContact(in Contact contact, in String group);
     
     Contact getContact(in String jid);
     void setContactName(in String jid, in String name);
--- a/src/com/beem/project/beem/ui/AddContact.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/AddContact.java	Tue Jun 23 13:45:19 2009 +0200
@@ -28,81 +28,79 @@
  */
 public class AddContact extends Activity {
 
-    protected static final String TAG = "AddContact";
-    private String mLogin;
-    private String mAlias;
-    private final List<String> mGroup = new ArrayList<String>();
-    private IXmppFacade xmppFacade;
-    private final ServiceConnection mServConn = new BeemServiceConnection();
-
-    private final OnClickListener mOkListener = new OnClickListener() {
+	protected static final String TAG = "AddContact";
+	private String mLogin;
+	private String mAlias;
+	private final List<String> mGroup = new ArrayList<String>();
+	private IXmppFacade xmppFacade;
+	private final ServiceConnection mServConn = new BeemServiceConnection();
 
 	@Override
-	public void onClick(View v) {
-	    boolean valid = true;
-	    if (getWidgetText(R.id.addc_login).length() == 0) {
-		valid = false;
-	    } else {
-		mLogin = getWidgetText(R.id.addc_login);
-	    }
-	    if (getWidgetText(R.id.addc_alias).length() == 0) {
-		valid = false;
-	    } else {
-		mAlias = getWidgetText(R.id.addc_alias);
-	    }
-	    if (getWidgetText(R.id.addc_group).length() == 0) {
-		valid = false;
-	    } else {
-		mGroup.add(getWidgetText(R.id.addc_group));
-	    }
-	    if (valid) {
-		try {
-		    xmppFacade.getRoster().addContact(mLogin, mAlias, mGroup.toArray(new String[mGroup.size()]));
-		    Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT).show();
-		    finish();
-		} catch (RemoteException e) {
-		    Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show();
-		    e.printStackTrace();
-		}
-		setResult(RESULT_OK);
-	    } else {
-		Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
-		setResult(RESULT_CANCELED);
-	    }
-
-	}
-    };
-
-    private String getWidgetText(int id) {
-	EditText widget = (EditText) this.findViewById(id);
-	return widget.getText().toString();
-    }
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-	super.onCreate(savedInstanceState);
-	setContentView(R.layout.addcontact);
-	Button ok = (Button) findViewById(R.id.addc_ok);
-	ok.setOnClickListener(mOkListener);
-	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-    }
-
-    @Override
-    protected void onDestroy() {
-	super.onDestroy();
-	unbindService(mServConn);
-    }
-
-    private class BeemServiceConnection implements ServiceConnection {
-
-	@Override
-	public void onServiceConnected(ComponentName name, IBinder service) {
-	    xmppFacade = IXmppFacade.Stub.asInterface(service);
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.addcontact);
+		Button ok = (Button) findViewById(R.id.addc_ok);
+		ok.setOnClickListener(mOkListener);
+		bindService(new Intent(this, BeemService.class), mServConn,
+				BIND_AUTO_CREATE);
 	}
 
 	@Override
-	public void onServiceDisconnected(ComponentName name) {
-	    xmppFacade = null;
+	protected void onDestroy() {
+		super.onDestroy();
+		unbindService(mServConn);
+	}
+
+	private class BeemServiceConnection implements ServiceConnection {
+
+		@Override
+		public void onServiceConnected(ComponentName name, IBinder service) {
+			xmppFacade = IXmppFacade.Stub.asInterface(service);
+		}
+
+		@Override
+		public void onServiceDisconnected(ComponentName name) {
+			xmppFacade = null;
+		}
+	}
+
+	private String getWidgetText(int id) {
+		EditText widget = (EditText) this.findViewById(id);
+		return widget.getText().toString();
 	}
-    }
+
+	private final OnClickListener mOkListener = new OnClickListener() {
+	
+		@Override
+		public void onClick(View v) {
+			boolean valid = true;
+			mLogin = getWidgetText(R.id.addc_login);
+			mAlias = getWidgetText(R.id.addc_alias);
+			if (mLogin.length() == 0)
+				valid = false;
+			if (getWidgetText(R.id.addc_group).length() != 0)
+				mGroup.add(getWidgetText(R.id.addc_group));
+			if (valid) {
+				try {
+					xmppFacade.getRoster().addContact(mLogin, mAlias,
+							mGroup.toArray(new String[mGroup.size()]));
+					Toast.makeText(AddContact.this,
+							getString(R.string.AddCContactAdded),
+							Toast.LENGTH_SHORT).show();
+					finish();
+				} catch (RemoteException e) {
+					Toast.makeText(AddContact.this, e.getMessage(),
+							Toast.LENGTH_SHORT).show();
+					e.printStackTrace();
+				}
+				setResult(RESULT_OK);
+			} else {
+				Toast.makeText(AddContact.this,
+						getString(R.string.AddCBadForm), Toast.LENGTH_SHORT)
+						.show();
+				setResult(RESULT_CANCELED);
+			}
+	
+		}
+	};
 }
--- a/src/com/beem/project/beem/ui/ContactDialog.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactDialog.java	Tue Jun 23 13:45:19 2009 +0200
@@ -3,10 +3,12 @@
 import org.jivesoftware.smack.packet.Presence;
 
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.Service;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.ServiceConnection;
 import android.os.IBinder;
@@ -25,23 +27,25 @@
 
     public static final String TAG = "Option Dialog";
     private final Contact mContact;
+    private final String mGroup;
     private final Context mContext;
     private IXmppFacade xmppFacade = null;
     private final ServiceConnection mServConn = new BeemServiceConnection();
 
-    public ContactDialog(final Context context, Contact curContact) {
+    public ContactDialog(final Context context, Contact curContact, String group) {
 	super(context);
 	mContext = context;
 
 	setContentView(R.layout.contactdialog);
 	mContact = curContact;
+	mGroup = group;
 	setTitle(curContact.getJID());
 
 	Button button = (Button) findViewById(R.id.CDChat);
 	button.setOnClickListener(new chatListener());
 	button = (Button) findViewById(R.id.CDAlias);
 	button.setOnClickListener(new aliasListener());
-	button = (Button) findViewById(R.id.CDGroup);
+	button = (Button) findViewById(R.id.CDDelete);
 	button.setOnClickListener(new groupListener());
 	button = (Button) findViewById(R.id.CDResend);
 	button.setOnClickListener(new resendListener());
@@ -53,6 +57,12 @@
 	mContext.bindService(new Intent(mContext, BeemService.class), mServConn, Service.BIND_AUTO_CREATE);
     }
 
+    @Override
+    public void dismiss() {
+	super.dismiss();
+	mContext.unbindService(mServConn);
+    }
+
     class aliasListener implements View.OnClickListener {
 
 	@Override
@@ -65,7 +75,7 @@
 	}
 
     }
-    
+
     class blockListener implements View.OnClickListener {
 
 	@Override
@@ -95,10 +105,28 @@
     class groupListener implements View.OnClickListener {
 
 	@Override
-	public void onClick(View v) {	   
-	    dismiss();
+	public void onClick(View v) {
+	    final Activity a = ContactDialog.this.getOwnerActivity();
+	    AlertDialog.Builder builder = new AlertDialog.Builder(a);
+	    builder.setMessage(a.getString(R.string.CDDelete)).setCancelable(false).setPositiveButton(
+		a.getString(R.string.CDSure2DeleteYes), new DialogInterface.OnClickListener() {
+		    public void onClick(DialogInterface dialog, int id) {
+			try {
+			    xmppFacade.getRoster().deleteContact(mContact, mGroup);
+			    Log.i("CONTACTDIALOG", "CONTACT DELETED");
+			} catch (RemoteException e) {
+			    e.printStackTrace();
+			}
+			dismiss();
+		    }
+		}).setNegativeButton(a.getString(R.string.CDSure2DeleteNo), new DialogInterface.OnClickListener() {
+		    public void onClick(DialogInterface dialog, int id) {
+			dialog.cancel();
+		    }
+		});
+	    AlertDialog alert = builder.create();
+	    alert.show();
 	}
-
     }
 
     class infosListener implements View.OnClickListener {
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Tue Jun 23 13:45:19 2009 +0200
@@ -44,449 +44,475 @@
 
 public class ContactList extends ExpandableListActivity {
 
-	private static final String TAG = "CONTACTLIST_ACT";
-	private static final String DEFAULT_GROUP = "Default";
-	private MyExpandableListAdapter mAdapter;
-	private IRoster mRoster;
-	private Map<String, List<Contact>> groupMap;
-	private List<String> groupName;
-	private List<Contact> mListContact;
-	private Handler mHandler;
-	private IXmppFacade xmppFacade = null;
-	private final ServiceConnection mServConn = new BeemServiceConnection();
+    private static final String TAG = "CONTACTLIST_ACT";
+    private static final String DEFAULT_GROUP = "Default";
+    private MyExpandableListAdapter mAdapter;
+    private IRoster mRoster;
+    private Map<String, List<Contact>> groupMap;
+    private List<String> groupName;
+    private List<Contact> mListContact;
+    private Handler mHandler;
+    public IXmppFacade xmppFacade = null;
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private int REQUEST_CODE = 1;
+
+    /**
+     * Callback for menu creation.
+     * @param menu the menu created
+     * @return true on success, false otherwise
+     */
+    @Override
+    public final boolean onCreateOptionsMenu(Menu menu) {
+	super.onCreateOptionsMenu(menu);
+	MenuInflater inflater = getMenuInflater();
+	inflater.inflate(R.menu.contact_list, menu);
+	return true;
+    }
 
-	/**
-	 * Callback for menu creation.
-	 * @param menu the menu created
-	 * @return true on success, false otherwise
-	 */
+    /**
+     * Callback for menu item selected.
+     * @param item the item selected
+     * @return true on success, false otherwise
+     */
+    @Override
+    public final boolean onOptionsItemSelected(MenuItem item) {
+	switch (item.getItemId()) {
+	    case R.id.contact_list_menu_settings:
+		startActivityForResult(new Intent(this, EditSettings.class), REQUEST_CODE);
+		return true;
+	    case R.id.contact_list_menu_add_contact:
+		startActivity(new Intent(ContactList.this, AddContact.class));
+		return true;
+	    default:
+		return false;
+	}
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+	super.onActivityResult(requestCode, resultCode, data);
+	if (requestCode == REQUEST_CODE) {
+	    if (resultCode == 69) {
+		stopService(new Intent(this, BeemService.class));
+		finish();
+		startActivity(new Intent(this, Login.class));
+	    }
+	}
+    }
+
+    @Override
+    protected void onCreate(Bundle saveBundle) {
+	super.onCreate(saveBundle);
+	mHandler = new Handler();
+	groupMap = new HashMap<String, List<Contact>>();
+	groupName = new ArrayList<String>();
+    }
+
+    @Override
+    protected void onStart() {
+	super.onStart();
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+    }
+
+    @Override
+    protected void onStop() {
+	super.onStop();
+	unbindService(mServConn);
+    }
+
+    class ComparatorContactListByName<T> implements Comparator<T> {
 	@Override
-	public final boolean onCreateOptionsMenu(Menu menu) {
-		super.onCreateOptionsMenu(menu);
-		MenuInflater inflater = getMenuInflater();
-		inflater.inflate(R.menu.contact_list, menu);
-		return true;
+	public int compare(T c1, T c2) {
+	    return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
 	}
+    }
 
-	/**
-	 * Callback for menu item selected.
-	 * @param item the item selected
-	 * @return true on success, false otherwise
-	 */
+    class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
 	@Override
-	public final boolean onOptionsItemSelected(MenuItem item) {
-		switch (item.getItemId()) {
-		case R.id.contact_list_menu_settings:
-			startActivity(new Intent(this, EditSettings.class));
-			return true;
-		case R.id.contact_list_menu_add_contact:
-			startActivity(new Intent(ContactList.this, AddContact.class));
-			return true;
-		default:
-			return false;
+	public int compare(T c1, T c2) {
+	    if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) {
+		return 1;
+	    } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) {
+		return -1;
+	    } else
+		return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
+	}
+    }
+
+    private void buildContactList(List<Contact> listContact) {
+	mListContact = listContact;
+	Collections.sort(mListContact, new ComparatorContactListByStatusAndName<Contact>());
+	for (Contact contact : mListContact) {
+	    for (String group : contact.getGroups()) {
+		if (!groupMap.containsKey(group)) {
+		    groupMap.put(group, new ArrayList<Contact>());
+		    Collections.sort(groupMap.get(group), new ComparatorContactListByStatusAndName<Contact>());
+		    groupName.add(group);
 		}
+		try {
+		    if (!groupMap.get(group).contains(contact))
+			groupMap.get(group).add(contact);
+		} catch (NullPointerException e) {
+		    Log.e(TAG, "Failed to find group in groupMap", e);
+		}
+	    }
+	    if (contact.getGroups().isEmpty()) {
+		if (!groupMap.containsKey(DEFAULT_GROUP)) {
+		    groupMap.put(DEFAULT_GROUP, new ArrayList<Contact>());
+		    groupName.add(DEFAULT_GROUP);
+		}
+		groupMap.get(DEFAULT_GROUP).add(contact);
+	    }
 	}
+	mAdapter = new MyExpandableListAdapter();
+	setListAdapter(mAdapter);
+    }
+
+    private class BeemRosterListener extends IBeemRosterListener.Stub {
 
 	@Override
-	protected void onCreate(Bundle saveBundle) {
-		super.onCreate(saveBundle);
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		mHandler = new Handler();
-		groupMap = new HashMap<String, List<Contact>>();
-		groupName = new ArrayList<String>();
+	public void onEntriesAdded(List<String> addresses) throws RemoteException {
+	    for (String str : addresses) {
+		Contact curContact = mRoster.getContact(str);
+		for (String group : curContact.getGroups()) {
+		    if (!groupMap.containsKey(group)) {
+			groupMap.put(group, new ArrayList<Contact>());
+			groupName.add(group);
+		    }
+		    try {
+			groupMap.get(group).add(curContact);
+		    } catch (NullPointerException e) {
+			Log.e(TAG, "Failed to find group in groupMap", e);
+		    }
+		}
+	    }
+	    mHandler.post(new RunnableChange());
 	}
 
 	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		unbindService(mServConn);
-	}
-
-	class ComparatorContactListByName<T> implements Comparator<T> {
-		@Override
-		public int compare(T c1, T c2) {
-			return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
-		}
-	}
-
-	class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
-		@Override
-		public int compare(T c1, T c2) {
-			if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) {
-				return 1;
-			} else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) {
-				return -1;
-			} else
-				return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
+	public void onEntriesDeleted(List<String> addresses) throws RemoteException {
+	    Log.i("CONTACTLIST", "EntreiesDeleted");
+	    for (List<Contact> cList : groupMap.values()) {
+		for (Contact curContact : cList) {
+		    for (String addr : addresses) {
+			if (addr.equals(curContact.getJID())) {
+			    cList.remove(curContact);
+			    if (cList.isEmpty()) {
+				groupMap.values().remove(cList);
+			    }
+			}
+		    }
 		}
-	}
-
-	private void buildContactList(List<Contact> listContact) {
-		mListContact = listContact;
-		Collections.sort(mListContact, new ComparatorContactListByStatusAndName<Contact>());
-		for (Contact contact : mListContact) {
-			for (String group : contact.getGroups()) {
-				if (!groupMap.containsKey(group)) {
-					groupMap.put(group, new ArrayList<Contact>());
-					Collections.sort(groupMap.get(group), new ComparatorContactListByStatusAndName<Contact>());
-					groupName.add(group);
-				}
-				try {
-					if (!groupMap.get(group).contains(contact))
-						groupMap.get(group).add(contact);
-				} catch (NullPointerException e) {
-					Log.e(TAG, "Failed to find group in groupMap", e);
-				}
-			}
-			if (contact.getGroups().isEmpty()) {
-				if (!groupMap.containsKey(DEFAULT_GROUP)) {
-					groupMap.put(DEFAULT_GROUP, new ArrayList<Contact>());
-					groupName.add(DEFAULT_GROUP);
-				}
-				groupMap.get(DEFAULT_GROUP).add(contact);
-			}
-		}
-		mAdapter = new MyExpandableListAdapter();
-		setListAdapter(mAdapter);
+	    }
+	    mHandler.post(new RunnableChange());
 	}
 
-	private class BeemRosterListener extends IBeemRosterListener.Stub {
-
-		@Override
-		public void onEntriesAdded(List<String> addresses) throws RemoteException {
-			for (String str : addresses) {
-				Contact curContact = mRoster.getContact(str);
-				for (String group : curContact.getGroups()) {
-					if (!groupMap.containsKey(group)) {
-						groupMap.put(group, new ArrayList<Contact>());
-						groupName.add(group);
-					}
-					try {
-						groupMap.get(group).add(curContact);
-					} catch (NullPointerException e) {
-						Log.e(TAG, "Failed to find group in groupMap", e);
-					}
-				}
+	
+	/**
+	 * TODO: sur la suppression de contact, on passe tt le temps dans entries updated ...
+	 * probleme comment reconnaitre si on supprime ou ajoute un contact ....
+	 */
+	@Override
+	public void onEntriesUpdated(List<String> addresses) throws RemoteException {
+	    Log.e("CONTACTLIST", "ENTRIESUPDATED");
+	    for (String str : addresses) {
+		Contact curContact = mRoster.getContact(str);
+		for (String group : curContact.getGroups()) {
+		    if (!groupMap.containsKey(group)) {
+			groupMap.put(group, new ArrayList<Contact>());
+			groupName.add(group);
+			groupMap.get(group).add(curContact);
+		    } else {
+			boolean found = false;
+			for (Contact tempContact : groupMap.get(group)) {
+			    if (tempContact.getJID().equals(str)) {
+				found = true;
+				break;
+			    }
 			}
-			mHandler.post(new RunnableChange());
+			if (!found) {
+			    groupMap.get(group).add(curContact);
+			}
+		    }
 		}
-
-		@Override
-		public void onEntriesDeleted(List<String> addresses) throws RemoteException {
-			for (List<Contact> cList : groupMap.values()) {
-				for (Contact curContact : cList) {
-					for (String addr : addresses) {
-						if (addr.equals(curContact.getJID())) {
-							cList.remove(curContact);
-							if (cList.isEmpty()) {
-								groupMap.values().remove(cList);
-							}
-						}
-					}
-				}
-			}
-			mHandler.post(new RunnableChange());
-		}
+	    }
+	    mHandler.post(new RunnableChange());
+	}
 
-		@Override
-		public void onEntriesUpdated(List<String> addresses) throws RemoteException {
-			for (String str : addresses) {
-				Contact curContact = mRoster.getContact(str);
-				for (String group : curContact.getGroups()) {
-					if (!groupMap.containsKey(group)) {
-						groupMap.put(group, new ArrayList<Contact>());
-						groupName.add(group);
-						groupMap.get(group).add(curContact);
-					} else {
-						boolean found = false;
-						for (Contact tempContact : groupMap.get(group)) {
-							if (tempContact.getJID().equals(str)) {
-								found = true;
-								break;
-							}
-						}
-						if (!found) {
-							groupMap.get(group).add(curContact);
-						}
-					}
-				}
-			}
-			mHandler.post(new RunnableChange());
+	@Override
+	public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
+	    for (Contact curContact : mListContact) {
+		if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
+		    curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
+		    mHandler.post(new RunnableChange());
+		    return;
 		}
+	    }
+	}
 
-		@Override
-		public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
-			for (Contact curContact : mListContact) {
-				if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
-					curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
-					mHandler.post(new RunnableChange());
-					return;
-				}
-			}
-		}
+	private class RunnableChange implements Runnable {
+	    @Override
+	    public void run() {
+		mAdapter.changed();
+	    }
+	}
+
+    }
+
+    private class MyExpandableListAdapter implements ExpandableListAdapter {
+
+	class MyOnClickListener implements OnClickListener {
 
-		private class RunnableChange implements Runnable {
-			@Override
-			public void run() {
-				mAdapter.changed();
-			}
-		}
+	    private final Contact mContact;
+
+	    public MyOnClickListener(Contact contact) {
+		mContact = contact;
+	    }
+
+	    @Override
+	    public void onClick(View v) {
+		Intent i = new Intent(ContactList.this, SendIM.class);
+		i.setData(mContact.toUri());
+		startActivity(i);
+	    }
 
 	}
 
-	private class MyExpandableListAdapter implements ExpandableListAdapter {
+	class MyOnLongClickListener implements OnLongClickListener {
 
-		class MyOnClickListener implements OnClickListener {
+	    private final Contact mContact;
+	    private final String mGroup;
 
-			private final Contact mContact;
-
-			public MyOnClickListener(Contact contact) {
-				mContact = contact;
-			}
+	    public MyOnLongClickListener(Contact contact, String group) {
+		mContact = contact;
+		mGroup = group;
+	    }
 
-			@Override
-			public void onClick(View v) {
-				Intent i = new Intent(ContactList.this, SendIM.class);
-				i.setData(mContact.toUri());
-				startActivity(i);
-			}
+	    @Override
+	    public boolean onLongClick(View v) {
+		createDialog(mContact, mGroup);
+		return true;
+	    }
+	}
+
+	private final List<DataSetObserver> observers;
 
-		}
+	public MyExpandableListAdapter() {
+	    observers = new ArrayList<DataSetObserver>();
+	}
 
-		class MyOnLongClickListener implements OnLongClickListener {
+	@Override
+	public boolean areAllItemsEnabled() {
+	    return true;
+	}
+
+	private void bindView(View view, Contact curContact) {
 
-			private final Contact mContact;
-
-			public MyOnLongClickListener(Contact contact) {
-				mContact = contact;
-			}
-
-			@Override
-			public boolean onLongClick(View v) {
-				createDialog(mContact);
-				return true;
-			}
+	    if (curContact != null) {
+		ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
+		Drawable imageDrawable = null;
+		switch (curContact.getStatus()) {
+		    case Status.CONTACT_STATUS_AVAILABLE:
+			imageDrawable = getResources().getDrawable(R.drawable.online);
+			break;
+		    case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+			imageDrawable = getResources().getDrawable(R.drawable.chat);
+			break;
+		    case Status.CONTACT_STATUS_AWAY:
+			imageDrawable = getResources().getDrawable(R.drawable.away);
+			break;
+		    case Status.CONTACT_STATUS_BUSY:
+			imageDrawable = getResources().getDrawable(R.drawable.dnd);
+			break;
+		    case Status.CONTACT_STATUS_DISCONNECT:
+			imageDrawable = getResources().getDrawable(R.drawable.offline);
+			break;
+		    case Status.CONTACT_STATUS_UNAVAILABLE:
+			imageDrawable = getResources().getDrawable(R.drawable.requested);
+			break;
+		    default:
+			imageDrawable = getResources().getDrawable(R.drawable.error);
+			break;
 		}
-
-		private final List<DataSetObserver> observers;
+		imgV.setImageDrawable(imageDrawable);
 
-		public MyExpandableListAdapter() {
-			observers = new ArrayList<DataSetObserver>();
-		}
-		
-
-		@Override
-		public boolean areAllItemsEnabled() {
-			return true;
+		TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
+		if (v != null) {
+		    v.setText(curContact.getName());
 		}
 
-		private void bindView(View view, Contact curContact) {
-
-			if (curContact != null) {
-				ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
-				Drawable imageDrawable = null;
-				switch (curContact.getStatus()) {
-				case Status.CONTACT_STATUS_AVAILABLE:
-					imageDrawable = getResources().getDrawable(R.drawable.online);
-					break;
-				case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
-					imageDrawable = getResources().getDrawable(R.drawable.chat);
-					break;
-				case Status.CONTACT_STATUS_AWAY:
-					imageDrawable = getResources().getDrawable(R.drawable.away);
-					break;
-				case Status.CONTACT_STATUS_BUSY:
-					imageDrawable = getResources().getDrawable(R.drawable.dnd);
-					break;
-				case Status.CONTACT_STATUS_DISCONNECT:
-					imageDrawable = getResources().getDrawable(R.drawable.offline);
-					break;
-				case Status.CONTACT_STATUS_UNAVAILABLE:
-					imageDrawable = getResources().getDrawable(R.drawable.requested);
-					break;
-				default:
-					imageDrawable = getResources().getDrawable(R.drawable.error);
-				break;
-				}
-				imgV.setImageDrawable(imageDrawable);
-
-				TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
-				if (v != null) {
-					v.setText(curContact.getName());
-				}
-
-				v = (TextView) view.findViewById(R.id.contactlistmsgperso);
-				if (v != null) {
-					v.setText(curContact.getMsgState());
-					Linkify.addLinks(v, Linkify.WEB_URLS);
-				}
-
-				// TODO: Rajouter l'avatar du contact getAvatar() dans la classe
-				imgV = (ImageView) view.findViewById(R.id.contactlistavatar);
-				if (imgV != null) {
-					imageDrawable = getResources().getDrawable(R.drawable.avatar);
-					imgV.setImageDrawable(imageDrawable);
-				}
-			}
-		}
-
-		public void changed() {
-			for (String name : groupName) {
-				Collections.sort(groupMap.get(name), new ComparatorContactListByStatusAndName<Contact>());
-			}
-			for (DataSetObserver obs : observers) {
-				obs.onChanged();
-			}			
-		}
-
-		void createDialog(Contact contact) {
-			ContactDialog dialogContact = new ContactDialog(ContactList.this, contact);
-			dialogContact.setOwnerActivity(ContactList.this);
-			dialogContact.show();
-		}
-
-		@Override
-		public Object getChild(int groupPosition, int childPosition) {
-			try {
-				return groupMap.get(groupName.get(groupPosition)).get(childPosition);
-			} catch (NullPointerException e) {
-				Log.e(TAG, "Child not found", e);
-				return null;
-			}
+		v = (TextView) view.findViewById(R.id.contactlistmsgperso);
+		if (v != null) {
+		    v.setText(curContact.getMsgState());
+		    Linkify.addLinks(v, Linkify.WEB_URLS);
 		}
 
-		@Override
-		public long getChildId(int groupPosition, int childPosition) {
-			try {
-				groupMap.get(groupName.get(groupPosition)).get(childPosition);
-			} catch (NullPointerException e) {
-				Log.e(TAG, "Child not found", e);
-				return 0;
-			}
-			return childPosition;
+		// TODO: Rajouter l'avatar du contact getAvatar() dans la classe
+		imgV = (ImageView) view.findViewById(R.id.contactlistavatar);
+		if (imgV != null) {
+		    imageDrawable = getResources().getDrawable(R.drawable.avatar);
+		    imgV.setImageDrawable(imageDrawable);
 		}
-
-		@Override
-		public int getChildrenCount(int groupPosition) {
-			try {
-				return groupMap.get(groupName.get(groupPosition)).size();
-			} catch (NullPointerException e) {
-				Log.e(TAG, "Child not found", e);
-				return 0;
-			}
-		}
+	    }
+	}
 
-		@Override
-		public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
-				ViewGroup parent) {
-			View v;
-			if (convertView == null) {
-				v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null);
-			} else {
-				v = convertView;
-			}
-			Contact contact = groupMap.get(groupName.get(groupPosition)).get(childPosition);
-			bindView(v, contact);
+	public void changed() {
+	    for (String name : groupName) {
+		Collections.sort(groupMap.get(name), new ComparatorContactListByStatusAndName<Contact>());
+	    }
+	    for (DataSetObserver obs : observers) {
+		obs.onChanged();
+	    }
+	}
 
-			v.setOnLongClickListener(new MyOnLongClickListener(contact));
-			v.setOnClickListener(new MyOnClickListener(contact));
-			return v;
-		}
+	void createDialog(Contact contact, String group) {
+	    ContactDialog dialogContact = new ContactDialog(ContactList.this, contact, group);
+	    dialogContact.setOwnerActivity(ContactList.this);
+	    dialogContact.show();
+	}
 
-		@Override
-		public long getCombinedChildId(long groupId, long childId) {
-			return 1000 * groupId + childId;
-		}
-
-		@Override
-		public long getCombinedGroupId(long groupId) {
-			return 1000 * groupId;
-		}
+	@Override
+	public Object getChild(int groupPosition, int childPosition) {
+	    try {
+		return groupMap.get(groupName.get(groupPosition)).get(childPosition);
+	    } catch (NullPointerException e) {
+		Log.e(TAG, "Child not found", e);
+		return null;
+	    }
+	}
 
-		@Override
-		public Object getGroup(int groupPosition) {
-			try {
-				return groupMap.get(groupName.get(groupPosition));
-			} catch (NullPointerException e) {
-				Log.e(TAG, "Group not found", e);
-				return null;
-			}
-		}
-
-		@Override
-		public int getGroupCount() {
-			return groupMap.size();
-		}
+	@Override
+	public long getChildId(int groupPosition, int childPosition) {
+	    try {
+		groupMap.get(groupName.get(groupPosition)).get(childPosition);
+	    } catch (NullPointerException e) {
+		Log.e(TAG, "Child not found", e);
+		return 0;
+	    }
+	    return childPosition;
+	}
 
-		@Override
-		public long getGroupId(int groupPosition) {
-			return groupPosition;
-		}
-
-		@Override
-		public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
-			if (convertView == null) {
-				convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null);
-			}
-			TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup);
-			groupTextView.setText(groupName.get(groupPosition));
-			return convertView;
-		}
+	@Override
+	public int getChildrenCount(int groupPosition) {
+	    try {
+		return groupMap.get(groupName.get(groupPosition)).size();
+	    } catch (NullPointerException e) {
+		Log.e(TAG, "Child not found", e);
+		return 0;
+	    }
+	}
 
-		@Override
-		public boolean hasStableIds() {
-			return false;
-		}
-
-		@Override
-		public boolean isChildSelectable(int groupPosition, int childPosition) {
-			return true;
-		}
-
-		@Override
-		public boolean isEmpty() {
-			return groupMap.isEmpty();
-		}
+	@Override
+	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
+	    ViewGroup parent) {
+	    View v;
+	    if (convertView == null) {
+		v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null);
+	    } else {
+		v = convertView;
+	    }
+	    Contact contact = groupMap.get(groupName.get(groupPosition)).get(childPosition);
+	    bindView(v, contact);
 
-		@Override
-		public void onGroupCollapsed(int groupPosition) {
-		}
-
-		@Override
-		public void onGroupExpanded(int groupPosition) {
-		}
+	    v.setOnLongClickListener(new MyOnLongClickListener(contact, groupName.get(groupPosition)));
+	    v.setOnClickListener(new MyOnClickListener(contact));
+	    return v;
+	}
 
-		@Override
-		public void registerDataSetObserver(DataSetObserver observer) {
-			observers.add(observer);
-		}
+	@Override
+	public long getCombinedChildId(long groupId, long childId) {
+	    return 1000 * groupId + childId;
+	}
 
-		@Override
-		public void unregisterDataSetObserver(DataSetObserver observer) {
-			observers.remove(observer);
-		}
+	@Override
+	public long getCombinedGroupId(long groupId) {
+	    return 1000 * groupId;
 	}
 
-	private class BeemServiceConnection implements ServiceConnection {
+	@Override
+	public Object getGroup(int groupPosition) {
+	    try {
+		return groupMap.get(groupName.get(groupPosition));
+	    } catch (NullPointerException e) {
+		Log.e(TAG, "Group not found", e);
+		return null;
+	    }
+	}
+
+	@Override
+	public int getGroupCount() {
+	    return groupMap.size();
+	}
+
+	@Override
+	public long getGroupId(int groupPosition) {
+	    return groupPosition;
+	}
+
+	@Override
+	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
+	    if (convertView == null) {
+		convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null);
+	    }
+	    TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup);
+	    groupTextView.setText(groupName.get(groupPosition));
+	    return convertView;
+	}
+
+	@Override
+	public boolean hasStableIds() {
+	    return false;
+	}
+
+	@Override
+	public boolean isChildSelectable(int groupPosition, int childPosition) {
+	    return true;
+	}
 
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			xmppFacade = IXmppFacade.Stub.asInterface(service);
-			try {
-				mRoster = xmppFacade.getRoster();
-				if (mRoster != null) {
-					mRoster.addRosterListener(new BeemRosterListener());
-					buildContactList(mRoster.getContactList());
-				}
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
+	@Override
+	public boolean isEmpty() {
+	    return groupMap.isEmpty();
+	}
+
+	@Override
+	public void onGroupCollapsed(int groupPosition) {
+	}
+
+	@Override
+	public void onGroupExpanded(int groupPosition) {
+	}
+
+	@Override
+	public void registerDataSetObserver(DataSetObserver observer) {
+	    observers.add(observer);
+	}
+
+	@Override
+	public void unregisterDataSetObserver(DataSetObserver observer) {
+	    observers.remove(observer);
+	}
+    }
+
+    private class BeemServiceConnection implements ServiceConnection {
+
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    xmppFacade = IXmppFacade.Stub.asInterface(service);
+	    try {
+		mRoster = xmppFacade.getRoster();
+		if (mRoster != null) {
+		    mRoster.addRosterListener(new BeemRosterListener());
+		    buildContactList(mRoster.getContactList());
 		}
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
+	}
 
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			xmppFacade = null;
-			mRoster = null;
-		}
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    xmppFacade = null;
+	    mRoster = null;
 	}
+    }
 }
--- a/src/com/beem/project/beem/ui/CreateAccount.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/CreateAccount.java	Tue Jun 23 13:45:19 2009 +0200
@@ -238,8 +238,8 @@
 
 		if (!checkPasswords())
 		    createErrorDialog(getString(R.string.create_account_err_passwords));
-		else
-		    createAccount(usernameFieldValue, passwordFieldValue);
+		else if (createAccount(usernameFieldValue, passwordFieldValue))
+			finish();
 	    }
 	});
 	Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button);
--- a/src/com/beem/project/beem/ui/EditSettings.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/EditSettings.java	Tue Jun 23 13:45:19 2009 +0200
@@ -20,7 +20,6 @@
 import android.widget.TabHost;
 import android.widget.Toast;
 
-import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
 
 /**
@@ -291,6 +290,7 @@
 
 		public void onClick(View v) {
 		    saveSettings();
+		    setResult(69);
 		}
 	    });
 	}
@@ -351,7 +351,6 @@
 	    startActivity(i);
 	    return true;
 	case R.id.settings_menu_login:
-	    setResult(69);
 	    finish();
 	    return true;
 	}
@@ -487,7 +486,5 @@
 	    displayNotification(getText(R.string.settings_saved_ok));
 	    Log.i(getString(R.string.edit_settings_tag), LOG_MSG_SETTINGS_SAVED);
 	}
-
-	stopService(new Intent(this, BeemService.class));
     }
 }
--- a/src/com/beem/project/beem/ui/Login.java	Tue Jun 23 13:36:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/Login.java	Tue Jun 23 13:45:19 2009 +0200
@@ -72,7 +72,7 @@
 
 	    @Override
 	    public void onClick(View v) {
-		startActivityForResult(new Intent(Login.this, EditSettings.class), REQUEST_CODE);
+		startActivity(new Intent(Login.this, EditSettings.class));
 	    }
 
 	});
@@ -82,16 +82,20 @@
 	    @Override
 	    public void onClick(View v) {
 		bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+		Log.e("LOGIN", "bindService()");
 	    }
 
 	});
+	progressDialog = new ProgressDialog(this);
     }
 
     @Override
     protected void onDestroy() {
 	super.onDestroy();
-	if (mIsConnected)
+	if (mIsConnected) {
+	    Log.e("LOGIN", "unbindService()");
 	    unbindService(mServConn);
+	}
     }
 
     /**
@@ -100,10 +104,8 @@
     @Override
     public void onStart() {
 	super.onStart();
-	Log.i(TAG, "OnStart()");
-	progressDialog = new ProgressDialog(this);
-	if (!mIsConnected)
-	    bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+	Log.e("Login", "bindService");
+	bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
     }
 
     private class BeemConnectionListener extends IBeemConnectionListener.Stub {
@@ -125,11 +127,10 @@
 
 	@Override
 	public void connectionClosed() throws RemoteException {
-	    if (mIsConnected) {
-		mIsConnected = false;
-		Login.this.unbindService(mServConn);
-		Login.this.stopService(SERVICE_INTENT);
-	    }
+	    mIsConnected = false;
+	    Log.e("Login", "CONNECTIONCLOSED");
+	    Login.this.unbindService(mServConn);
+	    Login.this.stopService(SERVICE_INTENT);
 	}
 
 	@Override
@@ -144,8 +145,6 @@
 	@Override
 	public void connectionFailed(String errorMsg) throws RemoteException {
 	    mIsConnected = false;
-	    Login.this.unbindService(mServConn);
-	    Login.this.stopService(SERVICE_INTENT);
 	    connectionHandler.post(new ErrorRunnable(errorMsg));
 	    dismissProgressDialog();
 	    showToast(errorMsg);