Le formatter a encore frappé.
authorJean-Manuel ¨dasilvj¨ Da Silva
Wed, 11 Nov 2009 19:34:04 +0100
changeset 503 93e5d2d9953f
parent 502 3091acfe31f4
child 504 2674b5a97537
Le formatter a encore frappé.
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/jingle/JingleService.java
src/com/beem/project/beem/jingle/MicrophoneRTPManager.java
src/com/beem/project/beem/jingle/MicrophoneRTPSession.java
src/com/beem/project/beem/jingle/PCMTransmitter.java
src/com/beem/project/beem/jingle/RTPReceiver.java
src/com/beem/project/beem/jingle/RTPTransmitter.java
src/com/beem/project/beem/jingle/demo/JingleCallActivity.java
src/com/beem/project/beem/provider/Beem.java
src/com/beem/project/beem/provider/BeemDatabaseHelper.java
src/com/beem/project/beem/provider/ContactProvider.java
src/com/beem/project/beem/provider/UserProvider.java
src/com/beem/project/beem/service/BeemChatManager.java
src/com/beem/project/beem/service/ChatAdapter.java
src/com/beem/project/beem/service/Contact.java
src/com/beem/project/beem/service/Message.java
src/com/beem/project/beem/service/PresenceAdapter.java
src/com/beem/project/beem/service/PrivacyListManagerAdapter.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/service/XmppFacade.java
src/com/beem/project/beem/ui/AddContact.java
src/com/beem/project/beem/ui/ChangeStatus.java
src/com/beem/project/beem/ui/Chat.java
src/com/beem/project/beem/ui/ContactDialog.java
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/CreateAccount.java
src/com/beem/project/beem/ui/GroupList.java
src/com/beem/project/beem/ui/Login.java
src/com/beem/project/beem/ui/SendIM.java
src/com/beem/project/beem/ui/SendIMDialogSmiley.java
src/com/beem/project/beem/ui/Settings.java
src/com/beem/project/beem/ui/Subscription.java
src/com/beem/project/beem/ui/UserInfo.java
src/com/beem/project/beem/utils/BeemBroadcastReceiver.java
src/com/beem/project/beem/utils/FreePort.java
src/com/beem/project/beem/utils/PresenceType.java
src/com/beem/project/beem/utils/Status.java
--- a/src/com/beem/project/beem/BeemService.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/BeemService.java	Wed Nov 11 19:34:04 2009 +0100
@@ -26,188 +26,180 @@
 import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
- * This class is for the Beem service. The connection to the xmpp server will be
- * made asynchronously when the service will start.
- * 
+ * This class is for the Beem service. The connection to the xmpp server will be made asynchronously when the service
+ * will start.
  * @author darisk
  */
 public class BeemService extends Service {
 
-	/**
-	 * The id to use for status notification.
-	 */
-	public static final int NOTIFICATION_STATUS_ID = 100;
-	private static final int DEFAULT_XMPP_PORT = 5222;
+    /**
+     * The id to use for status notification.
+     */
+    public static final int NOTIFICATION_STATUS_ID = 100;
+    private static final int DEFAULT_XMPP_PORT = 5222;
 
-	private NotificationManager mNotificationManager;
-	private XmppConnectionAdapter mConnection;
-	private JingleService mJingle;
-	private SharedPreferences mSettings;
-	private String mLogin;
-	private String mPassword;
-	private String mHost;
-	private String mService;
-	private int mPort;
-	private ConnectionConfiguration mConnectionConfiguration;
-	private ProxyInfo mProxyInfo;
-	private boolean mUseProxy;
-	private IXmppFacade.Stub mBind;
+    private NotificationManager mNotificationManager;
+    private XmppConnectionAdapter mConnection;
+    private JingleService mJingle;
+    private SharedPreferences mSettings;
+    private String mLogin;
+    private String mPassword;
+    private String mHost;
+    private String mService;
+    private int mPort;
+    private ConnectionConfiguration mConnectionConfiguration;
+    private ProxyInfo mProxyInfo;
+    private boolean mUseProxy;
+    private IXmppFacade.Stub mBind;
 
-	/**
-	 * Constructor.
-	 */
-	public BeemService() {
-	}
+    /**
+     * Constructor.
+     */
+    public BeemService() {
+    }
 
-	/**
-	 * Initialise la configuration de la connexion.
-	 */
-	private void initConnectionConfig() {
-		java.security.Security.addProvider(new com.sun.security.sasl.Provider());
-		mUseProxy = mSettings.getBoolean("settings_key_proxy_use", false);
-		if (mUseProxy) {
-			String stype = mSettings.getString("settings_key_proxy_type", "HTTP");
-			String phost = mSettings.getString("settings_key_proxy_server", "");
-			String puser = mSettings.getString("settings_key_proxy_username", "");
-			String ppass = mSettings.getString("settings_key_proxy_password", "");
-			int pport = Integer.parseInt(mSettings.getString("settings_key_proxy_port", "1080"));
-			ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
-			mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
-			if (mService != null)
-				mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService, mProxyInfo);
-			else
-				mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mProxyInfo);
-		} else {
-			if (mService != null)
-				mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService);
-			else
-				mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort);
-		}
-		if (mSettings.getBoolean("settings_key_xmpp_tls_use", false)
-				|| mSettings.getBoolean("settings_key_gmail", false)) {
-			mConnectionConfiguration.setSecurityMode(SecurityMode.required);
-		}
-		mConnectionConfiguration.setDebuggerEnabled(false);
-		mConnectionConfiguration.setSendPresence(true);
+    /**
+     * Initialise la configuration de la connexion.
+     */
+    private void initConnectionConfig() {
+	java.security.Security.addProvider(new com.sun.security.sasl.Provider());
+	mUseProxy = mSettings.getBoolean("settings_key_proxy_use", false);
+	if (mUseProxy) {
+	    String stype = mSettings.getString("settings_key_proxy_type", "HTTP");
+	    String phost = mSettings.getString("settings_key_proxy_server", "");
+	    String puser = mSettings.getString("settings_key_proxy_username", "");
+	    String ppass = mSettings.getString("settings_key_proxy_password", "");
+	    int pport = Integer.parseInt(mSettings.getString("settings_key_proxy_port", "1080"));
+	    ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
+	    mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
+	    if (mService != null)
+		mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService, mProxyInfo);
+	    else
+		mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mProxyInfo);
+	} else {
+	    if (mService != null)
+		mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService);
+	    else
+		mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort);
+	}
+	if (mSettings.getBoolean("settings_key_xmpp_tls_use", false)
+	    || mSettings.getBoolean("settings_key_gmail", false)) {
+	    mConnectionConfiguration.setSecurityMode(SecurityMode.required);
 	}
+	mConnectionConfiguration.setDebuggerEnabled(false);
+	mConnectionConfiguration.setSendPresence(true);
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public IBinder onBind(Intent intent) {
-		Log.d("BEEMSERVICE", "ONBIND()");
-		return mBind;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IBinder onBind(Intent intent) {
+	Log.d("BEEMSERVICE", "ONBIND()");
+	return mBind;
+    }
+
+    @Override
+    public boolean onUnbind(Intent intent) {
+	Log.d("BEEMSERVICE", "ONUNBIND()");
+	if (!mConnection.getAdaptee().isConnected()) {
+	    Log.d("BEEMSERVICE", "DESTROYED");
+	    this.stopSelf();
 	}
+	return true;
+    }
 
-	@Override
-	public boolean onUnbind(Intent intent) {
-		Log.d("BEEMSERVICE", "ONUNBIND()");
-		if (!mConnection.getAdaptee().isConnected()) {
-			Log.d("BEEMSERVICE", "DESTROYED");
-			this.stopSelf();
-		}
-		return true;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onCreate() {
+
+	super.onCreate();
+	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+	String tmpJid = mSettings.getString("settings_key_account_username", "");
+	mLogin = StringUtils.parseName(tmpJid);
+	mPassword = mSettings.getString("settings_key_account_password", "");
+	mPort = DEFAULT_XMPP_PORT;
+	mService = StringUtils.parseServer(tmpJid);
+	mHost = StringUtils.parseServer(tmpJid);
+
+	if (mSettings.getBoolean("settings_key_specific_server", false)) {
+	    mHost = mSettings.getString("settings_key_xmpp_server", "");
+	    mPort = Integer.parseInt(mSettings.getString("settings_key_xmpp_port", "5222"));
+	}
+	if (mSettings.getBoolean("settings_key_gmail", false)) {
+	    mHost = "talk.google.com";
+	    mLogin = tmpJid;
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onCreate() {
+	initConnectionConfig();
+	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+	mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this);
 
-		super.onCreate();
-		mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-		String tmpJid = mSettings.getString("settings_key_account_username", "");
-		mLogin = StringUtils.parseName(tmpJid);
-		mPassword = mSettings.getString("settings_key_account_password", "");
-		mPort = DEFAULT_XMPP_PORT;
-		mService = StringUtils.parseServer(tmpJid);
-		mHost = StringUtils.parseServer(tmpJid);
+	Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
+	mJingle = new JingleService(mConnection.getAdaptee());
+	mBind = new XmppFacade(mConnection, this, mJingle);
+	Log.d("BEEEMSERVICE", "ONCREATE");
+    }
 
-		if (mSettings.getBoolean("settings_key_specific_server", false)) {
-			mHost = mSettings.getString("settings_key_xmpp_server", "");
-			mPort = Integer.parseInt(mSettings.getString("settings_key_xmpp_port", "5222"));
-		}
-		if (mSettings.getBoolean("settings_key_gmail", false)) {
-			mHost = "talk.google.com";
-			mLogin = tmpJid;
-		}
-
-		initConnectionConfig();
-		mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-		mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this);
-
-		Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
-		mJingle = new JingleService(mConnection.getAdaptee());
-		mBind = new XmppFacade(mConnection, this, mJingle);
-		Log.d("BEEEMSERVICE", "ONCREATE");
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
-		if (mConnection.isAuthentificated())
-			mConnection.disconnect();
-		Log.d("BEEEMSERVICE", "ONDESTROY");
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onDestroy() {
+	super.onDestroy();
+	mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
+	if (mConnection.isAuthentificated())
+	    mConnection.disconnect();
+	Log.d("BEEEMSERVICE", "ONDESTROY");
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onStart(Intent intent, int startId) {
-		super.onStart(intent, startId);
-		Log.d("BEEMSERVICE", "onStart");
-		try {
-			mConnection.connectAsync();
-		} catch (RemoteException e) {
-			e.printStackTrace();
-		}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onStart(Intent intent, int startId) {
+	super.onStart(intent, startId);
+	Log.d("BEEMSERVICE", "onStart");
+	try {
+	    mConnection.connectAsync();
+	} catch (RemoteException e) {
+	    e.printStackTrace();
 	}
+    }
 
-	/**
-	 * Show a notification.
-	 * 
-	 * @param id
-	 *            the id of the notification.
-	 * @param notif
-	 *            the notification to show
-	 */
-	public void sendNotification(int id, Notification notif) {
-		mNotificationManager.notify(id, notif);
-	}
+    /**
+     * Show a notification.
+     * @param id the id of the notification.
+     * @param notif the notification to show
+     */
+    public void sendNotification(int id, Notification notif) {
+	mNotificationManager.notify(id, notif);
+    }
 
-	/**
-	 * Delete a notification.
-	 * 
-	 * @param id
-	 *            the id of the notification
-	 */
-	public void deleteNotification(int id) {
-		mNotificationManager.cancel(id);
-	}
+    /**
+     * Delete a notification.
+     * @param id the id of the notification
+     */
+    public void deleteNotification(int id) {
+	mNotificationManager.cancel(id);
+    }
 
-	/**
-	 * Reset the status to online after a deconnection.
-	 */
-	public void resetStatus() {
-		Editor edit = mSettings.edit();
-		edit.putInt(getString(R.string.PreferenceStatus), 1);
-		edit.commit();
-	}
+    /**
+     * Reset the status to online after a deconnection.
+     */
+    public void resetStatus() {
+	Editor edit = mSettings.edit();
+	edit.putInt(getString(R.string.PreferenceStatus), 1);
+	edit.commit();
+    }
 
-	/**
-	 * init jingle from XmppConnectionAdapter.
-	 * 
-	 * @param adaptee
-	 *            XmppConntection used for jingle.
-	 */
-	public void initJingle(XMPPConnection adaptee) {
-		mJingle.initWhenConntected(adaptee);
-	}
+    /**
+     * init jingle from XmppConnectionAdapter.
+     * @param adaptee XmppConntection used for jingle.
+     */
+    public void initJingle(XMPPConnection adaptee) {
+	mJingle.initWhenConntected(adaptee);
+    }
 }
--- a/src/com/beem/project/beem/jingle/JingleService.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/jingle/JingleService.java	Wed Nov 11 19:34:04 2009 +0100
@@ -22,221 +22,209 @@
 
 /**
  * Beem Jingle Service, manage jingle call.
- * 
  * @author nikita
  */
 public class JingleService {
-	private static final String TAG = "JingleService";
-	private JingleManager mJingleManager;
-	private final List<JingleMediaManager> mMediaManagers;
-	private JingleSession mIn;
-	private JingleSession mOut;
+    private static final String TAG = "JingleService";
+    private JingleManager mJingleManager;
+    private final List<JingleMediaManager> mMediaManagers;
+    private JingleSession mIn;
+    private JingleSession mOut;
+
+    /**
+     * JingleService constructor.
+     * @param xmppConnection a valid XMPPConnection
+     */
+    public JingleService(final XMPPConnection xmppConnection) {
+	BasicTransportManager bt = new BasicTransportManager();
+	// JingleTransportManager tm = new ICETransportManager();
+
+	mMediaManagers = new ArrayList<JingleMediaManager>();
+	mMediaManagers.add(new MicrophoneRTPManager(bt));
+    }
+
+    /**
+     * finish to construct the instance.
+     * @param conn the xmppConnection used with constructor
+     */
+    public void initWhenConntected(XMPPConnection conn) {
+	mJingleManager = new JingleManager(conn, mMediaManagers);
+	mJingleManager.addJingleSessionRequestListener(new BeemJingleSessionRequestListener());
+    }
 
-	/**
-	 * JingleService constructor.
-	 * 
-	 * @param xmppConnection
-	 *            a valid XMPPConnection
-	 */
-	public JingleService(final XMPPConnection xmppConnection) {
-		BasicTransportManager bt = new BasicTransportManager();
-		// JingleTransportManager tm = new ICETransportManager();
+    /**
+     * begin a jingle call.
+     * @param receiver the call receiver
+     */
+    public void call(final String receiver) {
+	try {
+	    mOut = mJingleManager.createOutgoingJingleSession(receiver);
+	    // TODO configure out avec addMediaSession et addNegociator
+	    mOut.addListener(new BeemJingleCallerSessionListener());
+	    mOut.startOutgoing();
+	} catch (XMPPException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+    }
 
-		mMediaManagers = new ArrayList<JingleMediaManager>();
-		mMediaManagers.add(new MicrophoneRTPManager(bt));
-	}
+    /*
+     * private void receiveData(String ip, int port) throws IOException { Socket s = null; try { s = new Socket(ip,
+     * port); System.out.println("Waiting data"); InputStream in = s.getInputStream(); int a; while ((a = in.read()) !=
+     * -1) { System.out.println("Received " + a); } System.out.println("End receiving data"); } finally { if (s != null)
+     * s.close(); } }
+     */
+    /**
+     * Listen on receiver session events.
+     * @author nikita
+     */
+    private class BeemJingleReceiverSessionListener implements JingleSessionListener {
 
 	/**
-	 * finish to construct the instance.
-	 * 
-	 * @param conn
-	 *            the xmppConnection used with constructor
+	 * constructor.
 	 */
-	public void initWhenConntected(XMPPConnection conn) {
-		mJingleManager = new JingleManager(conn, mMediaManagers);
-		mJingleManager.addJingleSessionRequestListener(new BeemJingleSessionRequestListener());
+	public BeemJingleReceiverSessionListener() {
+	    super();
+	    // TODO Auto-generated constructor stub
+	}
+
+	@Override
+	public void sessionClosed(String reason, JingleSession jingleSession) {
+	    // System.out.println("Session " + jingleSession.getResponder() +
+	    // "closedd because " + reason);
+	}
+
+	@Override
+	public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
+	    // TODO Auto-generated method stub
+	    // System.out.println("Session " + jingleSession.getResponder() +
+	    // " closed");
+
 	}
 
-	/**
-	 * begin a jingle call.
-	 * 
-	 * @param receiver
-	 *            the call receiver
-	 */
-	public void call(final String receiver) {
-		try {
-			mOut = mJingleManager.createOutgoingJingleSession(receiver);
-			// TODO configure out avec addMediaSession et addNegociator
-			mOut.addListener(new BeemJingleCallerSessionListener());
-			mOut.startOutgoing();
-		} catch (XMPPException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
+	@Override
+	public void sessionDeclined(String reason, JingleSession jingleSession) {
+	    Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
+	}
+
+	@Override
+	public void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate,
+	    TransportCandidate localCandidate, JingleSession jingleSession) {
+	    // System.out.println("Session established");
+	    // System.out.println("Je recois sur " + remoteCandidate.getIp() +
+	    // ":" + remoteCandidate.getPort());
+	    // TODO choose the right RTPReceiver depending on the payload type
+	    // RTPReceiver rtpReceiver = new
+	    // RTPReceiver(remoteCandidate.getPort());
+	    Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
+	}
+
+	@Override
+	public void sessionMediaReceived(JingleSession jingleSession, String participant) {
+	    // System.out.println("Session Media received from " + participant);
 	}
 
-	/*
-	 * private void receiveData(String ip, int port) throws IOException { Socket
-	 * s = null; try { s = new Socket(ip, port);
-	 * System.out.println("Waiting data"); InputStream in = s.getInputStream();
-	 * int a; while ((a = in.read()) != -1) { System.out.println("Received " +
-	 * a); } System.out.println("End receiving data"); } finally { if (s !=
-	 * null) s.close(); } }
-	 */
-	/**
-	 * Listen on receiver session events.
-	 * 
-	 * @author nikita
-	 */
-	private class BeemJingleReceiverSessionListener implements JingleSessionListener {
-
-		/**
-		 * constructor.
-		 */
-		public BeemJingleReceiverSessionListener() {
-			super();
-			// TODO Auto-generated constructor stub
-		}
-
-		@Override
-		public void sessionClosed(String reason, JingleSession jingleSession) {
-			// System.out.println("Session " + jingleSession.getResponder() +
-			// "closedd because " + reason);
-		}
+	@Override
+	public void sessionRedirected(String redirection, JingleSession jingleSession) {
+	}
+    }
 
-		@Override
-		public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
-			// TODO Auto-generated method stub
-			// System.out.println("Session " + jingleSession.getResponder() +
-			// " closed");
-
-		}
-
-		@Override
-		public void sessionDeclined(String reason, JingleSession jingleSession) {
-			Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
-		}
+    /**
+     * Listen on caller session events.
+     * @author nikita
+     */
+    private class BeemJingleCallerSessionListener implements JingleSessionListener {
 
-		@Override
-		public void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate,
-				TransportCandidate localCandidate, JingleSession jingleSession) {
-			// System.out.println("Session established");
-			// System.out.println("Je recois sur " + remoteCandidate.getIp() +
-			// ":" + remoteCandidate.getPort());
-			// TODO choose the right RTPReceiver depending on the payload type
-			// RTPReceiver rtpReceiver = new
-			// RTPReceiver(remoteCandidate.getPort());
-			Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
-		}
-
-		@Override
-		public void sessionMediaReceived(JingleSession jingleSession, String participant) {
-			// System.out.println("Session Media received from " + participant);
-		}
-
-		@Override
-		public void sessionRedirected(String redirection, JingleSession jingleSession) {
-		}
-	}
+	private static final int SLP_DURATION = 20000;
 
 	/**
-	 * Listen on caller session events.
-	 * 
-	 * @author nikita
+	 * constructor.
 	 */
-	private class BeemJingleCallerSessionListener implements JingleSessionListener {
-
-		private static final int SLP_DURATION = 20000;
+	public BeemJingleCallerSessionListener() {
+	    super();
+	    // TODO Auto-generated constructor stub
+	}
 
-		/**
-		 * constructor.
-		 */
-		public BeemJingleCallerSessionListener() {
-			super();
-			// TODO Auto-generated constructor stub
-		}
-
-		@Override
-		public void sessionClosed(final String reason, final JingleSession jingleSession) {
-			// System.out.println("Session " + jingleSession.getResponder() +
-			// "closed because " + reason);
-		}
-
-		@Override
-		public void sessionClosedOnError(final XMPPException e, final JingleSession jingleSession) {
-			// System.out.println("Session " + jingleSession.getResponder() +
-			// " closed on error");
-
-		}
+	@Override
+	public void sessionClosed(final String reason, final JingleSession jingleSession) {
+	    // System.out.println("Session " + jingleSession.getResponder() +
+	    // "closed because " + reason);
+	}
 
-		@Override
-		public void sessionDeclined(final String reason, final JingleSession jingleSession) {
-			// System.out.println("Session " + jingleSession.getResponder() +
-			// "declined because " + reason);
-			Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
-		}
-
-		@Override
-		public void sessionEstablished(final PayloadType pt, final TransportCandidate remoteCandidate,
-				final TransportCandidate localCandidate, final JingleSession jingleSession) {
-			Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
-			// String name = localCandidate.getName();
-			String ip = localCandidate.getIp();
-			int port = localCandidate.getPort();
-			// System.out.println("Session established waiting connection on " +
-			// ip + ":" + port);
-
-			RTPTransmitter transm = new PCMTransmitter(ip, port);
+	@Override
+	public void sessionClosedOnError(final XMPPException e, final JingleSession jingleSession) {
+	    // System.out.println("Session " + jingleSession.getResponder() +
+	    // " closed on error");
 
-			transm.run();
-			try {
-				Thread.sleep(SLP_DURATION);
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-			transm.stop();
-			// System.out.println("End of transfer");
+	}
 
-		}
-
-		@Override
-		public void sessionMediaReceived(final JingleSession jingleSession, final String participant) {
-			// TODO Auto-generated method stub
-			System.out.println("Session Media received from " + participant);
-		}
-
-		@Override
-		public void sessionRedirected(final String redirection, final JingleSession jingleSession) {
-			// TODO Auto-generated method stub
-		}
+	@Override
+	public void sessionDeclined(final String reason, final JingleSession jingleSession) {
+	    // System.out.println("Session " + jingleSession.getResponder() +
+	    // "declined because " + reason);
+	    Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
 	}
 
-	/**
-	 * Listen for a Jingle session request.
-	 * 
-	 * @author nikita
-	 */
-	private class BeemJingleSessionRequestListener implements JingleSessionRequestListener {
+	@Override
+	public void sessionEstablished(final PayloadType pt, final TransportCandidate remoteCandidate,
+	    final TransportCandidate localCandidate, final JingleSession jingleSession) {
+	    Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
+	    // String name = localCandidate.getName();
+	    String ip = localCandidate.getIp();
+	    int port = localCandidate.getPort();
+	    // System.out.println("Session established waiting connection on " +
+	    // ip + ":" + port);
+
+	    RTPTransmitter transm = new PCMTransmitter(ip, port);
 
-		/**
-		 * Constructor.
-		 */
-		public BeemJingleSessionRequestListener() {
-			super();
-		}
+	    transm.run();
+	    try {
+		Thread.sleep(SLP_DURATION);
+	    } catch (InterruptedException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	    }
+	    transm.stop();
+	    // System.out.println("End of transfer");
 
-		@Override
-		public void sessionRequested(JingleSessionRequest request) {
-			System.out.println("Jingle Session request from " + request.getFrom());
-			try {
-				mIn = request.accept();
-				mIn.addListener(new BeemJingleReceiverSessionListener());
-				mIn.startIncoming();
-			} catch (XMPPException e) {
-				e.printStackTrace();
-			}
-		}
+	}
+
+	@Override
+	public void sessionMediaReceived(final JingleSession jingleSession, final String participant) {
+	    // TODO Auto-generated method stub
+	    System.out.println("Session Media received from " + participant);
 	}
 
+	@Override
+	public void sessionRedirected(final String redirection, final JingleSession jingleSession) {
+	    // TODO Auto-generated method stub
+	}
+    }
+
+    /**
+     * Listen for a Jingle session request.
+     * @author nikita
+     */
+    private class BeemJingleSessionRequestListener implements JingleSessionRequestListener {
+
+	/**
+	 * Constructor.
+	 */
+	public BeemJingleSessionRequestListener() {
+	    super();
+	}
+
+	@Override
+	public void sessionRequested(JingleSessionRequest request) {
+	    System.out.println("Jingle Session request from " + request.getFrom());
+	    try {
+		mIn = request.accept();
+		mIn.addListener(new BeemJingleReceiverSessionListener());
+		mIn.startIncoming();
+	    } catch (XMPPException e) {
+		e.printStackTrace();
+	    }
+	}
+    }
+
 }
--- a/src/com/beem/project/beem/jingle/MicrophoneRTPManager.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/jingle/MicrophoneRTPManager.java	Wed Nov 11 19:34:04 2009 +0100
@@ -12,53 +12,50 @@
 
 /**
  * RTPMediaManager, gere les payloads et renvoie une session RTP.
- * 
  * @author nikita
  */
 public class MicrophoneRTPManager extends JingleMediaManager {
-	/**
-	 * RTP media name.
-	 */
-	public static final String MEDIA_NAME = "Microphone";
+    /**
+     * RTP media name.
+     */
+    public static final String MEDIA_NAME = "Microphone";
 
-	private List<PayloadType> mPayloads;
+    private List<PayloadType> mPayloads;
 
-	/**
-	 * Manage Microphone data transmission trough RTP.
-	 * 
-	 * @param transportManager
-	 *            current jingle transport manager(basic,upnp,ice...).
-	 */
-	public MicrophoneRTPManager(final JingleTransportManager transportManager) {
-		super(transportManager);
-		// TODO Auto-generated constructor stub
-		setupPayloads();
-	}
+    /**
+     * Manage Microphone data transmission trough RTP.
+     * @param transportManager current jingle transport manager(basic,upnp,ice...).
+     */
+    public MicrophoneRTPManager(final JingleTransportManager transportManager) {
+	super(transportManager);
+	// TODO Auto-generated constructor stub
+	setupPayloads();
+    }
 
-	@Override
-	public JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
-			TransportCandidate local, JingleSession jingleSession) {
-		// TODO Auto-generated method stub
-		return new MicrophoneRTPSession(payloadType, remote, local, null, jingleSession);
-	}
+    @Override
+    public JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
+	TransportCandidate local, JingleSession jingleSession) {
+	// TODO Auto-generated method stub
+	return new MicrophoneRTPSession(payloadType, remote, local, null, jingleSession);
+    }
 
-	@Override
-	public String getName() {
-		return MEDIA_NAME;
-	}
+    @Override
+    public String getName() {
+	return MEDIA_NAME;
+    }
 
-	@Override
-	public List<PayloadType> getPayloads() {
-		// TODO Auto-generated method stub
-		return mPayloads;
-	}
+    @Override
+    public List<PayloadType> getPayloads() {
+	// TODO Auto-generated method stub
+	return mPayloads;
+    }
 
-	/**
-	 * Supported payload list.
-	 */
-	private void setupPayloads() {
-		mPayloads = new ArrayList<PayloadType>();
-		mPayloads.add(new PayloadType.Audio(0, "PCMU"));
-		mPayloads.add(new PayloadType.Audio(8, "PCMA"));
-	}
+    /**
+     * Supported payload list.
+     */
+    private void setupPayloads() {
+	mPayloads = new ArrayList<PayloadType>();
+	mPayloads.add(new PayloadType.Audio(0, "PCMU"));
+	mPayloads.add(new PayloadType.Audio(8, "PCMA"));
+    }
 }
--- a/src/com/beem/project/beem/jingle/MicrophoneRTPSession.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/jingle/MicrophoneRTPSession.java	Wed Nov 11 19:34:04 2009 +0100
@@ -7,69 +7,62 @@
 
 /**
  * Manage microphone RTP session.
- * 
  * @author nikita
  */
 public class MicrophoneRTPSession extends JingleMediaSession {
 
-	private RTPTransmitter mTransmitter;
-	private RTPReceiver mReceiver;
+    private RTPTransmitter mTransmitter;
+    private RTPReceiver mReceiver;
 
-	/**
-	 * constructor.
-	 * 
-	 * @param payloadType
-	 *            the payload typ used
-	 * @param remote
-	 *            the remote transport info
-	 * @param local
-	 *            the local tranport info
-	 * @param mediaLocator
-	 *            don't know
-	 * @param jingleSession
-	 *            the current jingle session
-	 */
-	public MicrophoneRTPSession(final PayloadType payloadType, final TransportCandidate remote,
-			final TransportCandidate local, final String mediaLocator, final JingleSession jingleSession) {
-		super(payloadType, remote, local, mediaLocator, jingleSession);
+    /**
+     * constructor.
+     * @param payloadType the payload typ used
+     * @param remote the remote transport info
+     * @param local the local tranport info
+     * @param mediaLocator don't know
+     * @param jingleSession the current jingle session
+     */
+    public MicrophoneRTPSession(final PayloadType payloadType, final TransportCandidate remote,
+	final TransportCandidate local, final String mediaLocator, final JingleSession jingleSession) {
+	super(payloadType, remote, local, mediaLocator, jingleSession);
 
-		// TODO le transmitter ne devrait peut etre pas etre init ici, c'est
-		// peut etre encore un peu tot, a voir.
-		mTransmitter = new PCMTransmitter(remote.getIp(), getRemote().getPort());
-		// mReceiver = new MicroRTPReceiver(getLocal().getPort());
-	}
+	// TODO le transmitter ne devrait peut etre pas etre init ici, c'est
+	// peut etre encore un peu tot, a voir.
+	mTransmitter = new PCMTransmitter(remote.getIp(), getRemote().getPort());
+	// mReceiver = new MicroRTPReceiver(getLocal().getPort());
+    }
 
-	@Override
-	public void initialize() {
-		// TODO Auto-generated method stub
+    @Override
+    public void initialize() {
+	// TODO Auto-generated method stub
+
+    }
 
-	}
+    @Override
+    public void setTrasmit(boolean active) {
+    }
 
-	@Override
-	public void setTrasmit(boolean active) {
-	}
+    @Override
+    public void startReceive() {
+
+    }
 
-	@Override
-	public void startReceive() {
+    @Override
+    public void startTrasmit() {
+
+    }
 
-	}
-
-	@Override
-	public void startTrasmit() {
-
+    @Override
+    public void stopReceive() {
+	if (mReceiver != null) {
+	    mReceiver.stop();
 	}
-
-	@Override
-	public void stopReceive() {
-		if (mReceiver != null) {
-			mReceiver.stop();
-		}
-	}
+    }
 
-	@Override
-	public void stopTrasmit() {
-		if (mTransmitter != null) {
-			mTransmitter.stop();
-		}
+    @Override
+    public void stopTrasmit() {
+	if (mTransmitter != null) {
+	    mTransmitter.stop();
 	}
+    }
 }
--- a/src/com/beem/project/beem/jingle/PCMTransmitter.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/jingle/PCMTransmitter.java	Wed Nov 11 19:34:04 2009 +0100
@@ -6,44 +6,40 @@
 
 /**
  * Transmit Microphone data through RTP.
- * 
  * @author nikita
  */
 public class PCMTransmitter extends RTPTransmitter {
 
-	private static final int BUFF_SIZE = 1024;
-	private static final int RATE_IN_HZ = 8000;
-	private static final int SLP_DURATION = 200;
+    private static final int BUFF_SIZE = 1024;
+    private static final int RATE_IN_HZ = 8000;
+    private static final int SLP_DURATION = 200;
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param remoteIP
-	 *            receiver IP.
-	 * @param remotePort
-	 *            receiver port.
-	 */
-	public PCMTransmitter(final String remoteIP, final int remotePort) {
-		super(remoteIP, remotePort);
-	}
+    /**
+     * Constructor.
+     * @param remoteIP receiver IP.
+     * @param remotePort receiver port.
+     */
+    public PCMTransmitter(final String remoteIP, final int remotePort) {
+	super(remoteIP, remotePort);
+    }
 
-	@Override
-	void start() {
-		AudioRecord audRec = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, RATE_IN_HZ,
-				AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(
-						RATE_IN_HZ, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4);
-		byte[] audioData = new byte[BUFF_SIZE];
-		int byteReaded = 0;
-		while (!isKillme()) {
-			byteReaded = audRec.read(audioData, byteReaded, BUFF_SIZE);
-			System.out.println("readed " + byteReaded);
-			getRtpSession().sendData(audioData);
-		}
-		try {
-			Thread.sleep(SLP_DURATION);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		this.getRtpSession().endSession();
+    @Override
+    void start() {
+	AudioRecord audRec = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, RATE_IN_HZ,
+	    AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(
+		RATE_IN_HZ, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4);
+	byte[] audioData = new byte[BUFF_SIZE];
+	int byteReaded = 0;
+	while (!isKillme()) {
+	    byteReaded = audRec.read(audioData, byteReaded, BUFF_SIZE);
+	    System.out.println("readed " + byteReaded);
+	    getRtpSession().sendData(audioData);
 	}
+	try {
+	    Thread.sleep(SLP_DURATION);
+	} catch (InterruptedException e) {
+	    e.printStackTrace();
+	}
+	this.getRtpSession().endSession();
+    }
 }
--- a/src/com/beem/project/beem/jingle/RTPReceiver.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/jingle/RTPReceiver.java	Wed Nov 11 19:34:04 2009 +0100
@@ -9,78 +9,72 @@
 
 /**
  * abstract RTP receiver class.
- * 
  * @author nikita
  */
 public abstract class RTPReceiver implements Runnable, RTPAppIntf {
 
-	private boolean mKillme;
-	private RTPSession mRtpSession;
+    private boolean mKillme;
+    private RTPSession mRtpSession;
 
-	/**
-	 * constructor.
-	 * 
-	 * @param rtpPort
-	 *            local or distant?.
-	 */
-	public RTPReceiver(final int rtpPort) {
-		DatagramSocket rtpSocket = null;
+    /**
+     * constructor.
+     * @param rtpPort local or distant?.
+     */
+    public RTPReceiver(final int rtpPort) {
+	DatagramSocket rtpSocket = null;
 
-		try {
-			rtpSocket = new DatagramSocket(rtpPort);
-		} catch (SocketException e) {
-			e.printStackTrace();
-			return;
-		}
-		mRtpSession = new RTPSession(rtpSocket, null);
-		mRtpSession.naivePktReception(true);
-		mRtpSession.RTPSessionRegister(this, null, null);
+	try {
+	    rtpSocket = new DatagramSocket(rtpPort);
+	} catch (SocketException e) {
+	    e.printStackTrace();
+	    return;
 	}
+	mRtpSession = new RTPSession(rtpSocket, null);
+	mRtpSession.naivePktReception(true);
+	mRtpSession.RTPSessionRegister(this, null, null);
+    }
 
-	@Override
-	public int frameSize(int payloadType) {
-		return 1;
-	}
+    @Override
+    public int frameSize(int payloadType) {
+	return 1;
+    }
 
-	@Override
-	public void run() {
-		start();
-		this.mRtpSession.endSession();
-	}
+    @Override
+    public void run() {
+	start();
+	this.mRtpSession.endSession();
+    }
 
-	/**
-	 * main reception loop.
-	 */
-	protected abstract void start();
+    /**
+     * main reception loop.
+     */
+    protected abstract void start();
 
-	/**
-	 * Stop the reception.
-	 */
-	public void stop() {
-		this.setKillme(true);
-	}
+    /**
+     * Stop the reception.
+     */
+    public void stop() {
+	this.setKillme(true);
+    }
 
-	@Override
-	public void userEvent(int arg0, Participant[] arg1) {
-		// TODO Auto-generated method stub
-	}
+    @Override
+    public void userEvent(int arg0, Participant[] arg1) {
+	// TODO Auto-generated method stub
+    }
 
-	/**
-	 * mKillme setter.
-	 * 
-	 * @param killme
-	 *            the mKillme to set
-	 */
-	public void setKillme(final boolean killme) {
-		this.mKillme = killme;
-	}
+    /**
+     * mKillme setter.
+     * @param killme the mKillme to set
+     */
+    public void setKillme(final boolean killme) {
+	this.mKillme = killme;
+    }
 
-	/**
-	 * mKillme getter.
-	 * 
-	 * @return the mKillme
-	 */
-	public boolean isKillme() {
-		return mKillme;
-	}
+    /**
+     * mKillme getter.
+     * @return the mKillme
+     */
+    public boolean isKillme() {
+	return mKillme;
+    }
 }
--- a/src/com/beem/project/beem/jingle/RTPTransmitter.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/jingle/RTPTransmitter.java	Wed Nov 11 19:34:04 2009 +0100
@@ -12,113 +12,103 @@
 
 /**
  * abstract RTP transmitter class.
- * 
  * @author nikita
  */
 public abstract class RTPTransmitter implements Runnable, RTPAppIntf {
-	/**
-	 * RTPSession instance.
-	 */
-	private RTPSession mRtpSession;
-	/**
-	 * process status manipulation.
-	 */
-	private boolean mKillme;
+    /**
+     * RTPSession instance.
+     */
+    private RTPSession mRtpSession;
+    /**
+     * process status manipulation.
+     */
+    private boolean mKillme;
 
-	/**
-	 * constructor.
-	 * 
-	 * @param remoteIP
-	 *            receiver IP.
-	 * @param remotePort
-	 *            receiver port.
-	 */
-	public RTPTransmitter(final String remoteIP, final int remotePort) {
-		DatagramSocket rtpSocket = null;
-		int rtpPort = 0;
+    /**
+     * constructor.
+     * @param remoteIP receiver IP.
+     * @param remotePort receiver port.
+     */
+    public RTPTransmitter(final String remoteIP, final int remotePort) {
+	DatagramSocket rtpSocket = null;
+	int rtpPort = 0;
 
-		try {
-			rtpPort = FreePort.getFreePort();
-			rtpSocket = new DatagramSocket(rtpPort);
-		} catch (SocketException e) {
-			e.printStackTrace();
-			return;
-		}
-		setRtpSession(new RTPSession(rtpSocket, null));
-		getRtpSession().naivePktReception(true);
-		getRtpSession().RTPSessionRegister(this, null, null);
-		getRtpSession().addParticipant(new Participant(remoteIP, remotePort, 0));
+	try {
+	    rtpPort = FreePort.getFreePort();
+	    rtpSocket = new DatagramSocket(rtpPort);
+	} catch (SocketException e) {
+	    e.printStackTrace();
+	    return;
 	}
+	setRtpSession(new RTPSession(rtpSocket, null));
+	getRtpSession().naivePktReception(true);
+	getRtpSession().RTPSessionRegister(this, null, null);
+	getRtpSession().addParticipant(new Participant(remoteIP, remotePort, 0));
+    }
 
-	@Override
-	public int frameSize(int payloadType) {
-		return 1;
-	}
+    @Override
+    public int frameSize(int payloadType) {
+	return 1;
+    }
 
-	@Override
-	public void receiveData(DataFrame frame, Participant participant) {
-		// On envoie uniquement
-	}
+    @Override
+    public void receiveData(DataFrame frame, Participant participant) {
+	// On envoie uniquement
+    }
 
-	@Override
-	public void run() {
-		start();
-	}
+    @Override
+    public void run() {
+	start();
+    }
 
-	/**
-	 * A implementer pour chaque type d'envoi specifique.
-	 */
-	abstract void start();
-
-	/**
-	 * Stop the transmission.
-	 */
-	public void stop() {
-		mKillme = true;
-	}
+    /**
+     * A implementer pour chaque type d'envoi specifique.
+     */
+    abstract void start();
 
-	@Override
-	public void userEvent(int type, Participant[] participant) {
-		// je sais pas ce que c'est
-
-	}
+    /**
+     * Stop the transmission.
+     */
+    public void stop() {
+	mKillme = true;
+    }
 
-	/**
-	 * mKillme setter.
-	 * 
-	 * @param killme
-	 *            the mKillme to set
-	 */
-	public void setKillme(final boolean killme) {
-		this.mKillme = killme;
-	}
+    @Override
+    public void userEvent(int type, Participant[] participant) {
+	// je sais pas ce que c'est
+
+    }
 
-	/**
-	 * mKillme getter.
-	 * 
-	 * @return the mKillme.
-	 */
-	public boolean isKillme() {
-		return mKillme;
-	}
+    /**
+     * mKillme setter.
+     * @param killme the mKillme to set
+     */
+    public void setKillme(final boolean killme) {
+	this.mKillme = killme;
+    }
+
+    /**
+     * mKillme getter.
+     * @return the mKillme.
+     */
+    public boolean isKillme() {
+	return mKillme;
+    }
 
-	/**
-	 * mRtpSession setter.
-	 * 
-	 * @param rtpSession
-	 *            the mRtpSession to set.
-	 */
-	public void setRtpSession(RTPSession rtpSession) {
-		this.mRtpSession = rtpSession;
-	}
+    /**
+     * mRtpSession setter.
+     * @param rtpSession the mRtpSession to set.
+     */
+    public void setRtpSession(RTPSession rtpSession) {
+	this.mRtpSession = rtpSession;
+    }
 
-	/**
-	 * mRtpSession getter.
-	 * 
-	 * @return the mRtpSession
-	 */
-	public RTPSession getRtpSession() {
-		return mRtpSession;
-	}
+    /**
+     * mRtpSession getter.
+     * @return the mRtpSession
+     */
+    public RTPSession getRtpSession() {
+	return mRtpSession;
+    }
 
 }
--- a/src/com/beem/project/beem/jingle/demo/JingleCallActivity.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/jingle/demo/JingleCallActivity.java	Wed Nov 11 19:34:04 2009 +0100
@@ -19,83 +19,82 @@
 
 /**
  * Activity used to test Jingle call.
- * 
  * @author darisk
  */
 public class JingleCallActivity extends Activity {
 
-	private static final int SLP_DURATION = 3000;
-	private static final int DEFAULT_XMPP_PORT = 5222;
+    private static final int SLP_DURATION = 3000;
+    private static final int DEFAULT_XMPP_PORT = 5222;
 
-	private XMPPConnection mConnection;
-	private ConnectionConfiguration mConf;
-	private JingleService mJingle;
+    private XMPPConnection mConnection;
+    private ConnectionConfiguration mConf;
+    private JingleService mJingle;
 
-	private Button mBtconnect;
-	private Button mBtcall;
-	private EditText mEdJID;
-	private EditText mEdPassword;
-	private EditText mEdReceiver;
+    private Button mBtconnect;
+    private Button mBtcall;
+    private EditText mEdJID;
+    private EditText mEdPassword;
+    private EditText mEdReceiver;
 
-	/**
-	 * Constructor.
-	 */
-	public JingleCallActivity() {
-	}
+    /**
+     * Constructor.
+     */
+    public JingleCallActivity() {
+    }
 
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		java.security.Security.addProvider(new com.sun.security.sasl.Provider());
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.jingle_call_activity);
-		mConf = new ConnectionConfiguration("10.0.2.2", 5222);
-		// mConf = new ConnectionConfiguration("elyzion.net",
-		// DEFAULT_XMPP_PORT);
-		mConf.setSecurityMode(SecurityMode.required);
-		mEdJID = (EditText) findViewById(R.id.jingledemocalljid);
-		mEdPassword = (EditText) findViewById(R.id.jingledemocallpassword);
-		mEdReceiver = (EditText) findViewById(R.id.jingledemocallreceiver);
-		mBtconnect = (Button) findViewById(R.id.jingledemocallconnectbutton);
-		mBtconnect.setOnClickListener(new OnClickListener() {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	java.security.Security.addProvider(new com.sun.security.sasl.Provider());
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.jingle_call_activity);
+	mConf = new ConnectionConfiguration("10.0.2.2", 5222);
+	// mConf = new ConnectionConfiguration("elyzion.net",
+	// DEFAULT_XMPP_PORT);
+	mConf.setSecurityMode(SecurityMode.required);
+	mEdJID = (EditText) findViewById(R.id.jingledemocalljid);
+	mEdPassword = (EditText) findViewById(R.id.jingledemocallpassword);
+	mEdReceiver = (EditText) findViewById(R.id.jingledemocallreceiver);
+	mBtconnect = (Button) findViewById(R.id.jingledemocallconnectbutton);
+	mBtconnect.setOnClickListener(new OnClickListener() {
 
-			@Override
-			public void onClick(View arg0) {
-				String jid = mEdJID.getText().toString();
-				String login = StringUtils.parseName(jid);
-				mConnection = new XMPPConnection(mConf);
-				String password = mEdPassword.getText().toString();
-				try {
-					mConnection.connect();
-					Thread.sleep(SLP_DURATION);
-					mConnection.login(login, password);
-					mJingle = new JingleService(mConnection);
-					mJingle.initWhenConntected(mConnection);
-					mBtcall.setEnabled(true);
-					Toast.makeText(JingleCallActivity.this, "Connected", Toast.LENGTH_SHORT);
-				} catch (XMPPException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				} catch (InterruptedException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}
-			}
+	    @Override
+	    public void onClick(View arg0) {
+		String jid = mEdJID.getText().toString();
+		String login = StringUtils.parseName(jid);
+		mConnection = new XMPPConnection(mConf);
+		String password = mEdPassword.getText().toString();
+		try {
+		    mConnection.connect();
+		    Thread.sleep(SLP_DURATION);
+		    mConnection.login(login, password);
+		    mJingle = new JingleService(mConnection);
+		    mJingle.initWhenConntected(mConnection);
+		    mBtcall.setEnabled(true);
+		    Toast.makeText(JingleCallActivity.this, "Connected", Toast.LENGTH_SHORT);
+		} catch (XMPPException e) {
+		    // TODO Auto-generated catch block
+		    e.printStackTrace();
+		} catch (InterruptedException e) {
+		    // TODO Auto-generated catch block
+		    e.printStackTrace();
+		}
+	    }
 
-		});
-		mBtcall = (Button) findViewById(R.id.jingledemocallbutton);
-		mBtcall.setOnClickListener(new OnClickListener() {
-			@Override
-			public void onClick(View arg0) {
-				String jid = mEdReceiver.getText().toString();
-				if (!"".equals(jid)) {
-					mJingle.call(jid);
-					Toast.makeText(JingleCallActivity.this, "Appel en cours", Toast.LENGTH_SHORT);
-				} else
-					Toast.makeText(JingleCallActivity.this, "Remplir le champ (JID complet en  toto@tutu.com/truc)",
-							Toast.LENGTH_SHORT);
-			}
-		});
+	});
+	mBtcall = (Button) findViewById(R.id.jingledemocallbutton);
+	mBtcall.setOnClickListener(new OnClickListener() {
+	    @Override
+	    public void onClick(View arg0) {
+		String jid = mEdReceiver.getText().toString();
+		if (!"".equals(jid)) {
+		    mJingle.call(jid);
+		    Toast.makeText(JingleCallActivity.this, "Appel en cours", Toast.LENGTH_SHORT);
+		} else
+		    Toast.makeText(JingleCallActivity.this, "Remplir le champ (JID complet en  toto@tutu.com/truc)",
+			Toast.LENGTH_SHORT);
+	    }
+	});
 
-	}
+    }
 
 }
--- a/src/com/beem/project/beem/provider/Beem.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/provider/Beem.java	Wed Nov 11 19:34:04 2009 +0100
@@ -8,186 +8,183 @@
  */
 public final class Beem {
 
-	/**
-	 * Contacts table.
-	 */
-	public static final class Contacts implements BaseColumns {
+    /**
+     * Contacts table.
+     */
+    public static final class Contacts implements BaseColumns {
 
-		/**
-		 * The query used to create the table.
-		 */
-		public static final String QUERY_CREATE = "CREATE TABLE " + Beem.CONTACTS_TABLE_NAME + " (" + BaseColumns._ID
-				+ " INTEGER PRIMARY KEY AUTOINCREMENT," + Contacts.UID + " INTEGER, " + Contacts.JID + " INTEGER,"
-				+ Contacts.NICKNAME + " TEXT," + Contacts.ALIAS + " TEXT," + Contacts.DATE_CREATED + " INTEGER,"
-				+ Contacts.DATE_MODIFIED + " INTEGER" + ");";
-
-		/**
-		 * The content:// style URL for Contacts table.
-		 */
-		public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/contacts");
+	/**
+	 * The query used to create the table.
+	 */
+	public static final String QUERY_CREATE = "CREATE TABLE " + Beem.CONTACTS_TABLE_NAME + " (" + BaseColumns._ID
+	    + " INTEGER PRIMARY KEY AUTOINCREMENT," + Contacts.UID + " INTEGER, " + Contacts.JID + " INTEGER,"
+	    + Contacts.NICKNAME + " TEXT," + Contacts.ALIAS + " TEXT," + Contacts.DATE_CREATED + " INTEGER,"
+	    + Contacts.DATE_MODIFIED + " INTEGER" + ");";
 
-		/**
-		 * The MIME type of {@link #CONTENT_URI} providing a directory of
-		 * contacts.
-		 */
-		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.contact";
+	/**
+	 * The content:// style URL for Contacts table.
+	 */
+	public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/contacts");
 
-		/**
-		 * The MIME type of a {@link #CONTENT_URI} sub-directory of a single
-		 * contact.
-		 */
-		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.contact";
+	/**
+	 * The MIME type of {@link #CONTENT_URI} providing a directory of contacts.
+	 */
+	public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.contact";
 
-		/**
-		 * The default sort order for this table.
-		 */
-		public static final String DEFAULT_SORT_ORDER = "nickname ASC";
+	/**
+	 * The MIME type of a {@link #CONTENT_URI} sub-directory of a single contact.
+	 */
+	public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.contact";
 
-		/**
-		 * The user id having the contact
-		 * <P>
-		 * Type: INTEGER
-		 * </P>
-		 * .
-		 */
-		public static final String UID = "uid";
+	/**
+	 * The default sort order for this table.
+	 */
+	public static final String DEFAULT_SORT_ORDER = "nickname ASC";
 
-		/**
-		 * The JabberID of the contact
-		 * <P>
-		 * Type: INTEGER
-		 * </P>
-		 * .
-		 */
-		public static final String JID = "jid";
+	/**
+	 * The user id having the contact
+	 * <P>
+	 * Type: INTEGER
+	 * </P>
+	 * .
+	 */
+	public static final String UID = "uid";
 
-		/**
-		 * The nickname of the contact
-		 * <P>
-		 * Type: TEXT
-		 * </P>
-		 * .
-		 */
-		public static final String NICKNAME = "nickname";
+	/**
+	 * The JabberID of the contact
+	 * <P>
+	 * Type: INTEGER
+	 * </P>
+	 * .
+	 */
+	public static final String JID = "jid";
 
-		/**
-		 * The alias of the contact
-		 * <P>
-		 * Type: TEXT
-		 * </P>
-		 * .
-		 */
-		public static final String ALIAS = "alias";
+	/**
+	 * The nickname of the contact
+	 * <P>
+	 * Type: TEXT
+	 * </P>
+	 * .
+	 */
+	public static final String NICKNAME = "nickname";
 
-		/**
-		 * The timestamp for when the contact was created
-		 * <P>
-		 * Type: INTEGER (long from System.curentTimeMillis())
-		 * </P>
-		 * .
-		 */
-		public static final String DATE_CREATED = "created";
+	/**
+	 * The alias of the contact
+	 * <P>
+	 * Type: TEXT
+	 * </P>
+	 * .
+	 */
+	public static final String ALIAS = "alias";
 
-		/**
-		 * The timestamp for when the contact was last modified
-		 * <P>
-		 * Type: INTEGER (long from System.curentTimeMillis())
-		 * </P>
-		 * .
-		 */
-		public static final String DATE_MODIFIED = "modified";
-
-	}
+	/**
+	 * The timestamp for when the contact was created
+	 * <P>
+	 * Type: INTEGER (long from System.curentTimeMillis())
+	 * </P>
+	 * .
+	 */
+	public static final String DATE_CREATED = "created";
 
 	/**
-	 * Users table.
+	 * The timestamp for when the contact was last modified
+	 * <P>
+	 * Type: INTEGER (long from System.curentTimeMillis())
+	 * </P>
+	 * .
 	 */
-	public static final class Users implements BaseColumns {
-
-		/**
-		 * The query used to create the table.
-		 */
-		public static final String QUERY_CREATE = "CREATE TABLE " + Beem.USERS_TABLE_NAME + " (" + BaseColumns._ID
-				+ " INTEGER PRIMARY KEY AUTOINCREMENT," + Users.JUSERNAME + " TEXT," + Users.DATE_CREATED + " INTEGER,"
-				+ Users.DATE_MODIFIED + " INTEGER" + ");";
+	public static final String DATE_MODIFIED = "modified";
 
-		/**
-		 * The content:// style URL for Contacts table.
-		 */
-		public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/users");
+    }
 
-		/**
-		 * The MIME type of {@link #CONTENT_URI} providing a directory of users.
-		 */
-		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.user";
-
-		/**
-		 * The MIME type of a {@link #CONTENT_URI} sub-directory of a single
-		 * user.
-		 */
-		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.user";
+    /**
+     * Users table.
+     */
+    public static final class Users implements BaseColumns {
 
-		/**
-		 * The default sort order for this table.
-		 */
-		public static final String DEFAULT_SORT_ORDER = "_id ASC";
+	/**
+	 * The query used to create the table.
+	 */
+	public static final String QUERY_CREATE = "CREATE TABLE " + Beem.USERS_TABLE_NAME + " (" + BaseColumns._ID
+	    + " INTEGER PRIMARY KEY AUTOINCREMENT," + Users.JUSERNAME + " TEXT," + Users.DATE_CREATED + " INTEGER,"
+	    + Users.DATE_MODIFIED + " INTEGER" + ");";
 
-		/**
-		 * The Jabber username of the user
-		 * <P>
-		 * Type: TEXT
-		 * </P>
-		 * .
-		 */
-		public static final String JUSERNAME = "username";
+	/**
+	 * The content:// style URL for Contacts table.
+	 */
+	public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/users");
 
-		/**
-		 * The timestamp for when the user was created
-		 * <P>
-		 * Type: INTEGER (long from System.curentTimeMillis())
-		 * </P>
-		 * .
-		 */
-		public static final String DATE_CREATED = "created";
+	/**
+	 * The MIME type of {@link #CONTENT_URI} providing a directory of users.
+	 */
+	public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.user";
 
-		/**
-		 * The timestamp for when the user was last modified
-		 * <P>
-		 * Type: INTEGER (long from System.curentTimeMillis())
-		 * </P>
-		 * .
-		 */
-		public static final String DATE_MODIFIED = "modified";
-	}
+	/**
+	 * The MIME type of a {@link #CONTENT_URI} sub-directory of a single user.
+	 */
+	public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.user";
+
+	/**
+	 * The default sort order for this table.
+	 */
+	public static final String DEFAULT_SORT_ORDER = "_id ASC";
 
 	/**
-	 * AUTHORITY.
+	 * The Jabber username of the user
+	 * <P>
+	 * Type: TEXT
+	 * </P>
+	 * .
 	 */
-	public static final String AUTHORITY = "com.beem.project.provider";
+	public static final String JUSERNAME = "username";
 
 	/**
-	 * DB Name.
+	 * The timestamp for when the user was created
+	 * <P>
+	 * Type: INTEGER (long from System.curentTimeMillis())
+	 * </P>
+	 * .
 	 */
-	public static final String DB_NAME = "beem.db";
-
-	/**
-	 * DB Version.
-	 */
-	public static final int DB_VERSION = 2;
+	public static final String DATE_CREATED = "created";
 
 	/**
-	 * Name of the users table.
-	 */
-	public static final String USERS_TABLE_NAME = "users";
-
-	/**
-	 * Name of the contacts table.
+	 * The timestamp for when the user was last modified
+	 * <P>
+	 * Type: INTEGER (long from System.curentTimeMillis())
+	 * </P>
+	 * .
 	 */
-	public static final String CONTACTS_TABLE_NAME = "contacts";
+	public static final String DATE_MODIFIED = "modified";
+    }
+
+    /**
+     * AUTHORITY.
+     */
+    public static final String AUTHORITY = "com.beem.project.provider";
+
+    /**
+     * DB Name.
+     */
+    public static final String DB_NAME = "beem.db";
 
-	/**
-	 * Constructor.
-	 */
-	private Beem() {
-	}
+    /**
+     * DB Version.
+     */
+    public static final int DB_VERSION = 2;
+
+    /**
+     * Name of the users table.
+     */
+    public static final String USERS_TABLE_NAME = "users";
+
+    /**
+     * Name of the contacts table.
+     */
+    public static final String CONTACTS_TABLE_NAME = "contacts";
+
+    /**
+     * Constructor.
+     */
+    private Beem() {
+    }
 }
--- a/src/com/beem/project/beem/provider/BeemDatabaseHelper.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/provider/BeemDatabaseHelper.java	Wed Nov 11 19:34:04 2009 +0100
@@ -7,46 +7,40 @@
 
 /**
  * BeemDatabaseHelper class.
- * 
  * @author Jamu
  */
 public class BeemDatabaseHelper extends SQLiteOpenHelper {
 
-	private final String mTag;
-	private final String mTableName;
-	private final String mCreationQuery;
+    private final String mTag;
+    private final String mTableName;
+    private final String mCreationQuery;
+
+    /**
+     * BeemDatabaseHelper class.
+     * @param context the context.
+     * @param tag the tag.
+     * @param tableName the tableName.
+     * @param creationQuery the creation query.
+     */
+    public BeemDatabaseHelper(final Context context, final String tag, final String tableName,
+	final String creationQuery) {
+	super(context, Beem.DB_NAME, null, Beem.DB_VERSION);
 
-	/**
-	 * BeemDatabaseHelper class.
-	 * 
-	 * @param context
-	 *            the context.
-	 * @param tag
-	 *            the tag.
-	 * @param tableName
-	 *            the tableName.
-	 * @param creationQuery
-	 *            the creation query.
-	 */
-	public BeemDatabaseHelper(final Context context, final String tag, final String tableName,
-			final String creationQuery) {
-		super(context, Beem.DB_NAME, null, Beem.DB_VERSION);
+	this.mTag = tag;
+	this.mTableName = tableName;
+	this.mCreationQuery = creationQuery;
+    }
 
-		this.mTag = tag;
-		this.mTableName = tableName;
-		this.mCreationQuery = creationQuery;
-	}
+    @Override
+    public void onCreate(SQLiteDatabase db) {
+	db.execSQL(this.mCreationQuery);
+    }
 
-	@Override
-	public void onCreate(SQLiteDatabase db) {
-		db.execSQL(this.mCreationQuery);
-	}
-
-	@Override
-	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-		Log.w(this.mTag, "Upgrading database from version " + oldVersion + " to " + newVersion
-				+ ", which will destroy all old data");
-		db.execSQL("DROP TABLE IF EXISTS " + this.mTableName + ";");
-		onCreate(db);
-	}
+    @Override
+    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+	Log.w(this.mTag, "Upgrading database from version " + oldVersion + " to " + newVersion
+	    + ", which will destroy all old data");
+	db.execSQL("DROP TABLE IF EXISTS " + this.mTableName + ";");
+	onCreate(db);
+    }
 }
--- a/src/com/beem/project/beem/provider/ContactProvider.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/provider/ContactProvider.java	Wed Nov 11 19:34:04 2009 +0100
@@ -16,192 +16,191 @@
 
 /**
  * ContactProvider class.
- * 
  * @author dasilvj
  */
 public class ContactProvider extends ContentProvider {
 
-	private static final String TAG = "ContactProvider";
+    private static final String TAG = "ContactProvider";
+
+    private static HashMap<String, String> sContactsProjectionMap;
 
-	private static HashMap<String, String> sContactsProjectionMap;
+    private static final int CONTACTS = 1;
+    private static final int CONTACT_ID = 2;
 
-	private static final int CONTACTS = 1;
-	private static final int CONTACT_ID = 2;
+    private static final UriMatcher S_URI_MATCHER;
+    static {
+	S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
+	S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts", CONTACTS);
+	S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts/#", CONTACT_ID);
 
-	private static final UriMatcher S_URI_MATCHER;
-	static {
-		S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
-		S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts", CONTACTS);
-		S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts/#", CONTACT_ID);
+	sContactsProjectionMap = new HashMap<String, String>();
+	sContactsProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
+	sContactsProjectionMap.put(Beem.Contacts.UID, Beem.Contacts.UID);
+	sContactsProjectionMap.put(Beem.Contacts.JID, Beem.Contacts.JID);
+	sContactsProjectionMap.put(Beem.Contacts.NICKNAME, Beem.Contacts.NICKNAME);
+	sContactsProjectionMap.put(Beem.Contacts.ALIAS, Beem.Contacts.ALIAS);
+	sContactsProjectionMap.put(Beem.Contacts.DATE_CREATED, Beem.Contacts.DATE_CREATED);
+	sContactsProjectionMap.put(Beem.Contacts.DATE_MODIFIED, Beem.Contacts.DATE_MODIFIED);
+    }
+
+    private BeemDatabaseHelper mOpenHelper;
 
-		sContactsProjectionMap = new HashMap<String, String>();
-		sContactsProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
-		sContactsProjectionMap.put(Beem.Contacts.UID, Beem.Contacts.UID);
-		sContactsProjectionMap.put(Beem.Contacts.JID, Beem.Contacts.JID);
-		sContactsProjectionMap.put(Beem.Contacts.NICKNAME, Beem.Contacts.NICKNAME);
-		sContactsProjectionMap.put(Beem.Contacts.ALIAS, Beem.Contacts.ALIAS);
-		sContactsProjectionMap.put(Beem.Contacts.DATE_CREATED, Beem.Contacts.DATE_CREATED);
-		sContactsProjectionMap.put(Beem.Contacts.DATE_MODIFIED, Beem.Contacts.DATE_MODIFIED);
+    @Override
+    public int delete(Uri uri, String selection, String[] selectionArgs) {
+	SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+	int count;
+
+	switch (S_URI_MATCHER.match(uri)) {
+	    case CONTACTS:
+		count = db.delete(Beem.CONTACTS_TABLE_NAME, selection, selectionArgs);
+		break;
+
+	    case CONTACT_ID:
+		String contactId = uri.getPathSegments().get(1);
+		count = db.delete(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID + "=" + contactId
+		    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+		break;
+
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
 	}
 
-	private BeemDatabaseHelper mOpenHelper;
+	getContext().getContentResolver().notifyChange(uri, null);
+	return count;
+    }
 
-	@Override
-	public int delete(Uri uri, String selection, String[] selectionArgs) {
-		SQLiteDatabase db = mOpenHelper.getWritableDatabase();
-		int count;
-
-		switch (S_URI_MATCHER.match(uri)) {
-		case CONTACTS:
-			count = db.delete(Beem.CONTACTS_TABLE_NAME, selection, selectionArgs);
-			break;
+    @Override
+    public String getType(Uri uri) {
+	switch (S_URI_MATCHER.match(uri)) {
+	    case CONTACTS:
+		return Beem.Contacts.CONTENT_TYPE;
 
-		case CONTACT_ID:
-			String contactId = uri.getPathSegments().get(1);
-			count = db.delete(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID + "=" + contactId
-					+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
-			break;
+	    case CONTACT_ID:
+		return Beem.Contacts.CONTENT_ITEM_TYPE;
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
+	}
+    }
 
-		getContext().getContentResolver().notifyChange(uri, null);
-		return count;
+    @Override
+    public Uri insert(Uri uri, ContentValues initialValues) {
+	// Validate the requested uri
+	if (S_URI_MATCHER.match(uri) != CONTACTS) {
+	    throw new IllegalArgumentException("Unknown URI " + uri);
 	}
 
-	@Override
-	public String getType(Uri uri) {
-		switch (S_URI_MATCHER.match(uri)) {
-		case CONTACTS:
-			return Beem.Contacts.CONTENT_TYPE;
+	ContentValues values;
+	if (initialValues != null) {
+	    values = new ContentValues(initialValues);
+	} else {
+	    values = new ContentValues();
+	}
+
+	Long now = Long.valueOf(System.currentTimeMillis());
 
-		case CONTACT_ID:
-			return Beem.Contacts.CONTENT_ITEM_TYPE;
+	// Make sure that the fields are all set
+	if (!values.containsKey(Beem.Contacts.UID)) {
+	    // TODO :: Must check that the UID exists using UserProvider
+	    throw new SQLException("No UID specified. Failed to insert row into " + uri);
+	}
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	if (!values.containsKey(Beem.Contacts.JID)) {
+	    values.put(Beem.Contacts.JID, "");
 	}
 
-	@Override
-	public Uri insert(Uri uri, ContentValues initialValues) {
-		// Validate the requested uri
-		if (S_URI_MATCHER.match(uri) != CONTACTS) {
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
-
-		ContentValues values;
-		if (initialValues != null) {
-			values = new ContentValues(initialValues);
-		} else {
-			values = new ContentValues();
-		}
-
-		Long now = Long.valueOf(System.currentTimeMillis());
-
-		// Make sure that the fields are all set
-		if (!values.containsKey(Beem.Contacts.UID)) {
-			// TODO :: Must check that the UID exists using UserProvider
-			throw new SQLException("No UID specified. Failed to insert row into " + uri);
-		}
-
-		if (!values.containsKey(Beem.Contacts.JID)) {
-			values.put(Beem.Contacts.JID, "");
-		}
+	if (!values.containsKey(Beem.Contacts.NICKNAME)) {
+	    values.put(Beem.Contacts.JID, "");
+	}
 
-		if (!values.containsKey(Beem.Contacts.NICKNAME)) {
-			values.put(Beem.Contacts.JID, "");
-		}
-
-		if (!values.containsKey(Beem.Contacts.ALIAS)) {
-			values.put(Beem.Contacts.JID, "");
-		}
-
-		if (!values.containsKey(Beem.Contacts.DATE_CREATED)) {
-			values.put(Beem.Contacts.DATE_CREATED, now);
-		}
-
-		if (!values.containsKey(Beem.Contacts.DATE_MODIFIED)) {
-			values.put(Beem.Contacts.DATE_MODIFIED, now);
-		}
-
-		SQLiteDatabase db = mOpenHelper.getWritableDatabase();
-		long rowId = db.insert(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID, values);
-		if (rowId > 0) {
-			Uri contactUri = ContentUris.withAppendedId(Beem.Contacts.CONTENT_URI, rowId);
-			getContext().getContentResolver().notifyChange(contactUri, null);
-			return contactUri;
-		}
-
-		throw new SQLException("Failed to insert row into " + uri);
+	if (!values.containsKey(Beem.Contacts.ALIAS)) {
+	    values.put(Beem.Contacts.JID, "");
 	}
 
-	@Override
-	public boolean onCreate() {
-		mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.CONTACTS_TABLE_NAME, Beem.Contacts.QUERY_CREATE);
-		return true;
+	if (!values.containsKey(Beem.Contacts.DATE_CREATED)) {
+	    values.put(Beem.Contacts.DATE_CREATED, now);
+	}
+
+	if (!values.containsKey(Beem.Contacts.DATE_MODIFIED)) {
+	    values.put(Beem.Contacts.DATE_MODIFIED, now);
+	}
+
+	SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+	long rowId = db.insert(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID, values);
+	if (rowId > 0) {
+	    Uri contactUri = ContentUris.withAppendedId(Beem.Contacts.CONTENT_URI, rowId);
+	    getContext().getContentResolver().notifyChange(contactUri, null);
+	    return contactUri;
 	}
 
-	@Override
-	public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
-		SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+	throw new SQLException("Failed to insert row into " + uri);
+    }
 
-		switch (S_URI_MATCHER.match(uri)) {
-		case CONTACTS:
-			qb.setTables(Beem.CONTACTS_TABLE_NAME);
-			qb.setProjectionMap(sContactsProjectionMap);
-			break;
+    @Override
+    public boolean onCreate() {
+	mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.CONTACTS_TABLE_NAME, Beem.Contacts.QUERY_CREATE);
+	return true;
+    }
 
-		case CONTACT_ID:
-			qb.setTables(Beem.USERS_TABLE_NAME);
-			qb.setProjectionMap(sContactsProjectionMap);
-			qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
-			break;
+    @Override
+    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+	SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	switch (S_URI_MATCHER.match(uri)) {
+	    case CONTACTS:
+		qb.setTables(Beem.CONTACTS_TABLE_NAME);
+		qb.setProjectionMap(sContactsProjectionMap);
+		break;
 
-		// If no sort order is specified use the default
-		String orderBy;
-		if (TextUtils.isEmpty(sortOrder)) {
-			orderBy = Beem.Contacts.DEFAULT_SORT_ORDER;
-		} else {
-			orderBy = sortOrder;
-		}
+	    case CONTACT_ID:
+		qb.setTables(Beem.USERS_TABLE_NAME);
+		qb.setProjectionMap(sContactsProjectionMap);
+		qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
+		break;
 
-		// Get the database and run the query
-		SQLiteDatabase db = mOpenHelper.getReadableDatabase();
-		Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
-
-		// Tell the cursor what uri to watch, so it knows when its source data
-		// changes
-		c.setNotificationUri(getContext().getContentResolver(), uri);
-		return c;
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
 	}
 
-	@Override
-	public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
-		SQLiteDatabase db = mOpenHelper.getWritableDatabase();
-		int count;
+	// If no sort order is specified use the default
+	String orderBy;
+	if (TextUtils.isEmpty(sortOrder)) {
+	    orderBy = Beem.Contacts.DEFAULT_SORT_ORDER;
+	} else {
+	    orderBy = sortOrder;
+	}
 
-		switch (S_URI_MATCHER.match(uri)) {
-		case CONTACTS:
-			count = db.update(Beem.CONTACTS_TABLE_NAME, values, selection, selectionArgs);
-			break;
+	// Get the database and run the query
+	SQLiteDatabase db = mOpenHelper.getReadableDatabase();
+	Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
+
+	// Tell the cursor what uri to watch, so it knows when its source data
+	// changes
+	c.setNotificationUri(getContext().getContentResolver(), uri);
+	return c;
+    }
 
-		case CONTACT_ID:
-			String contactId = uri.getPathSegments().get(1);
-			count = db.update(Beem.CONTACTS_TABLE_NAME, values, BaseColumns._ID + "=" + contactId
-					+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
-			break;
+    @Override
+    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+	SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+	int count;
+
+	switch (S_URI_MATCHER.match(uri)) {
+	    case CONTACTS:
+		count = db.update(Beem.CONTACTS_TABLE_NAME, values, selection, selectionArgs);
+		break;
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	    case CONTACT_ID:
+		String contactId = uri.getPathSegments().get(1);
+		count = db.update(Beem.CONTACTS_TABLE_NAME, values, BaseColumns._ID + "=" + contactId
+		    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+		break;
 
-		getContext().getContentResolver().notifyChange(uri, null);
-		return count;
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
 	}
+
+	getContext().getContentResolver().notifyChange(uri, null);
+	return count;
+    }
 }
--- a/src/com/beem/project/beem/provider/UserProvider.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/provider/UserProvider.java	Wed Nov 11 19:34:04 2009 +0100
@@ -16,176 +16,175 @@
 
 /**
  * UserProvider class.
- * 
  * @author Jamu
  */
 public class UserProvider extends ContentProvider {
 
-	private static final String TAG = "UserProvider";
+    private static final String TAG = "UserProvider";
+
+    private static HashMap<String, String> sUsersProjectionMap;
+
+    private static final int USERS = 1;
+    private static final int USER_ID = 2;
 
-	private static HashMap<String, String> sUsersProjectionMap;
+    private static final UriMatcher S_URI_MATCHER;
+    static {
+	S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
+	S_URI_MATCHER.addURI(Beem.AUTHORITY, "users", USERS);
+	S_URI_MATCHER.addURI(Beem.AUTHORITY, "users/#", USER_ID);
 
-	private static final int USERS = 1;
-	private static final int USER_ID = 2;
+	sUsersProjectionMap = new HashMap<String, String>();
+	sUsersProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
+	sUsersProjectionMap.put(Beem.Users.JUSERNAME, Beem.Users.JUSERNAME);
+	sUsersProjectionMap.put(Beem.Users.DATE_CREATED, Beem.Users.DATE_CREATED);
+	sUsersProjectionMap.put(Beem.Users.DATE_MODIFIED, Beem.Users.DATE_MODIFIED);
+    }
 
-	private static final UriMatcher S_URI_MATCHER;
-	static {
-		S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
-		S_URI_MATCHER.addURI(Beem.AUTHORITY, "users", USERS);
-		S_URI_MATCHER.addURI(Beem.AUTHORITY, "users/#", USER_ID);
+    private BeemDatabaseHelper mOpenHelper;
+
+    @Override
+    public int delete(Uri uri, String selection, String[] selectionArgs) {
+	SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+	int count;
 
-		sUsersProjectionMap = new HashMap<String, String>();
-		sUsersProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
-		sUsersProjectionMap.put(Beem.Users.JUSERNAME, Beem.Users.JUSERNAME);
-		sUsersProjectionMap.put(Beem.Users.DATE_CREATED, Beem.Users.DATE_CREATED);
-		sUsersProjectionMap.put(Beem.Users.DATE_MODIFIED, Beem.Users.DATE_MODIFIED);
+	switch (S_URI_MATCHER.match(uri)) {
+	    case USERS:
+		count = db.delete(Beem.USERS_TABLE_NAME, selection, selectionArgs);
+		break;
+
+	    case USER_ID:
+		String userID = uri.getPathSegments().get(1);
+		count = db.delete(Beem.USERS_TABLE_NAME, BaseColumns._ID + "=" + userID
+		    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+		break;
+
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
 	}
 
-	private BeemDatabaseHelper mOpenHelper;
+	getContext().getContentResolver().notifyChange(uri, null);
+	return count;
+    }
 
-	@Override
-	public int delete(Uri uri, String selection, String[] selectionArgs) {
-		SQLiteDatabase db = mOpenHelper.getWritableDatabase();
-		int count;
-
-		switch (S_URI_MATCHER.match(uri)) {
-		case USERS:
-			count = db.delete(Beem.USERS_TABLE_NAME, selection, selectionArgs);
-			break;
+    @Override
+    public String getType(Uri uri) {
+	switch (S_URI_MATCHER.match(uri)) {
+	    case USERS:
+		return Beem.Users.CONTENT_TYPE;
 
-		case USER_ID:
-			String userID = uri.getPathSegments().get(1);
-			count = db.delete(Beem.USERS_TABLE_NAME, BaseColumns._ID + "=" + userID
-					+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
-			break;
+	    case USER_ID:
+		return Beem.Users.CONTENT_ITEM_TYPE;
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
+	}
+    }
 
-		getContext().getContentResolver().notifyChange(uri, null);
-		return count;
+    @Override
+    public Uri insert(Uri uri, ContentValues initialValues) {
+	// Validate the requested uri
+	if (S_URI_MATCHER.match(uri) != USERS) {
+	    throw new IllegalArgumentException("Unknown URI " + uri);
 	}
 
-	@Override
-	public String getType(Uri uri) {
-		switch (S_URI_MATCHER.match(uri)) {
-		case USERS:
-			return Beem.Users.CONTENT_TYPE;
+	ContentValues values;
+	if (initialValues != null) {
+	    values = new ContentValues(initialValues);
+	} else {
+	    values = new ContentValues();
+	}
 
-		case USER_ID:
-			return Beem.Users.CONTENT_ITEM_TYPE;
+	Long now = Long.valueOf(System.currentTimeMillis());
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	// Make sure that the fields are all set
+	if (!values.containsKey(Beem.Users.JUSERNAME)) {
+	    throw new SQLException("No JUSERNAME specified. Failed to insert row into " + uri);
 	}
 
-	@Override
-	public Uri insert(Uri uri, ContentValues initialValues) {
-		// Validate the requested uri
-		if (S_URI_MATCHER.match(uri) != USERS) {
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
-
-		ContentValues values;
-		if (initialValues != null) {
-			values = new ContentValues(initialValues);
-		} else {
-			values = new ContentValues();
-		}
-
-		Long now = Long.valueOf(System.currentTimeMillis());
-
-		// Make sure that the fields are all set
-		if (!values.containsKey(Beem.Users.JUSERNAME)) {
-			throw new SQLException("No JUSERNAME specified. Failed to insert row into " + uri);
-		}
-
-		if (!values.containsKey(Beem.Users.DATE_CREATED)) {
-			values.put(Beem.Users.DATE_CREATED, now);
-		}
-
-		if (!values.containsKey(Beem.Users.DATE_MODIFIED)) {
-			values.put(Beem.Users.DATE_MODIFIED, now);
-		}
-
-		SQLiteDatabase db = mOpenHelper.getWritableDatabase();
-		long rowId = db.insert(Beem.USERS_TABLE_NAME, BaseColumns._ID, values);
-		if (rowId > 0) {
-			Uri userUri = ContentUris.withAppendedId(Beem.Users.CONTENT_URI, rowId);
-			getContext().getContentResolver().notifyChange(userUri, null);
-			return userUri;
-		}
-
-		throw new SQLException("Failed to insert row into " + uri);
+	if (!values.containsKey(Beem.Users.DATE_CREATED)) {
+	    values.put(Beem.Users.DATE_CREATED, now);
 	}
 
-	@Override
-	public boolean onCreate() {
-		mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.USERS_TABLE_NAME, Beem.Users.QUERY_CREATE);
-		return true;
+	if (!values.containsKey(Beem.Users.DATE_MODIFIED)) {
+	    values.put(Beem.Users.DATE_MODIFIED, now);
+	}
+
+	SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+	long rowId = db.insert(Beem.USERS_TABLE_NAME, BaseColumns._ID, values);
+	if (rowId > 0) {
+	    Uri userUri = ContentUris.withAppendedId(Beem.Users.CONTENT_URI, rowId);
+	    getContext().getContentResolver().notifyChange(userUri, null);
+	    return userUri;
 	}
 
-	@Override
-	public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
-		SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+	throw new SQLException("Failed to insert row into " + uri);
+    }
 
-		switch (S_URI_MATCHER.match(uri)) {
-		case USERS:
-			qb.setTables(Beem.USERS_TABLE_NAME);
-			qb.setProjectionMap(sUsersProjectionMap);
-			break;
+    @Override
+    public boolean onCreate() {
+	mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.USERS_TABLE_NAME, Beem.Users.QUERY_CREATE);
+	return true;
+    }
 
-		case USER_ID:
-			qb.setTables(Beem.USERS_TABLE_NAME);
-			qb.setProjectionMap(sUsersProjectionMap);
-			qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
-			break;
+    @Override
+    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+	SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	switch (S_URI_MATCHER.match(uri)) {
+	    case USERS:
+		qb.setTables(Beem.USERS_TABLE_NAME);
+		qb.setProjectionMap(sUsersProjectionMap);
+		break;
 
-		// If no sort order is specified use the default
-		String orderBy;
-		if (TextUtils.isEmpty(sortOrder)) {
-			orderBy = Beem.Users.DEFAULT_SORT_ORDER;
-		} else {
-			orderBy = sortOrder;
-		}
+	    case USER_ID:
+		qb.setTables(Beem.USERS_TABLE_NAME);
+		qb.setProjectionMap(sUsersProjectionMap);
+		qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
+		break;
 
-		// Get the database and run the query
-		SQLiteDatabase db = mOpenHelper.getReadableDatabase();
-		Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
-
-		// Tell the cursor what uri to watch, so it knows when its source data
-		// changes
-		c.setNotificationUri(getContext().getContentResolver(), uri);
-		return c;
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
 	}
 
-	@Override
-	public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
-		SQLiteDatabase db = mOpenHelper.getWritableDatabase();
-		int count;
+	// If no sort order is specified use the default
+	String orderBy;
+	if (TextUtils.isEmpty(sortOrder)) {
+	    orderBy = Beem.Users.DEFAULT_SORT_ORDER;
+	} else {
+	    orderBy = sortOrder;
+	}
 
-		switch (S_URI_MATCHER.match(uri)) {
-		case USERS:
-			count = db.update(Beem.USERS_TABLE_NAME, values, selection, selectionArgs);
-			break;
+	// Get the database and run the query
+	SQLiteDatabase db = mOpenHelper.getReadableDatabase();
+	Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
+
+	// Tell the cursor what uri to watch, so it knows when its source data
+	// changes
+	c.setNotificationUri(getContext().getContentResolver(), uri);
+	return c;
+    }
 
-		case USER_ID:
-			String userId = uri.getPathSegments().get(1);
-			count = db.update(Beem.USERS_TABLE_NAME, values, BaseColumns._ID + "=" + userId
-					+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
-			break;
+    @Override
+    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+	SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+	int count;
+
+	switch (S_URI_MATCHER.match(uri)) {
+	    case USERS:
+		count = db.update(Beem.USERS_TABLE_NAME, values, selection, selectionArgs);
+		break;
 
-		default:
-			throw new IllegalArgumentException("Unknown URI " + uri);
-		}
+	    case USER_ID:
+		String userId = uri.getPathSegments().get(1);
+		count = db.update(Beem.USERS_TABLE_NAME, values, BaseColumns._ID + "=" + userId
+		    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+		break;
 
-		getContext().getContentResolver().notifyChange(uri, null);
-		return count;
+	    default:
+		throw new IllegalArgumentException("Unknown URI " + uri);
 	}
+
+	getContext().getContentResolver().notifyChange(uri, null);
+	return count;
+    }
 }
--- a/src/com/beem/project/beem/service/BeemChatManager.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/BeemChatManager.java	Wed Nov 11 19:34:04 2009 +0100
@@ -27,244 +27,225 @@
 import com.beem.project.beem.service.aidl.IMessageListener;
 
 /**
- * An adapter for smack's ChatManager. This class provides functionnality to
- * handle chats.
- * 
+ * An adapter for smack's ChatManager. This class provides functionnality to handle chats.
  * @author darisk
  */
 public class BeemChatManager extends IChatManager.Stub {
 
-	/**
-	 * A listener for all the chat creation event that happens on the
-	 * connection.
-	 * 
-	 * @author darisk
-	 */
-	private class ChatListener implements ChatStateListener, ChatManagerListener, MessageListener {
-
-		/**
-		 * Constructor.
-		 */
-		public ChatListener() {
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void chatCreated(Chat chat, boolean locally) {
-			IChat newchat = getChat(chat);
-			chat.addMessageListener(mChatListener);
-			final int n = mRemoteChatCreationListeners.beginBroadcast();
+    /**
+     * A listener for all the chat creation event that happens on the connection.
+     * @author darisk
+     */
+    private class ChatListener implements ChatStateListener, ChatManagerListener, MessageListener {
 
-			for (int i = 0; i < n; i++) {
-				IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i);
-				try {
-					listener.chatCreated(newchat, locally);
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, " Error while triggering remote connection listeners in chat creation", e);
-				}
-			}
-			mRemoteChatCreationListeners.finishBroadcast();
-		}
-
-		/**
-		 * Create the PendingIntent to launch our activity if the user select
-		 * this chat notification.
-		 * 
-		 * @param chat
-		 * @return
-		 */
-		private PendingIntent makeChatIntent(IChat chat) {
-			Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class);
-			chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
-			try {
-				chatIntent.setData(chat.getParticipant().toUri());
-			} catch (RemoteException e) {
-				Log.e(TAG, e.getMessage());
-			}
-			PendingIntent contentIntent = PendingIntent.getActivity(mService, 0, chatIntent,
-					PendingIntent.FLAG_UPDATE_CURRENT);
-			return (contentIntent);
-		}
+	/**
+	 * Constructor.
+	 */
+	public ChatListener() {
+	}
 
-		/**
-		 * Set a notification of a new chat.
-		 * 
-		 * @param chat
-		 *            The chat to access by the notification
-		 */
-		private void notifyNewChat(IChat chat) {
-			try {
-				CharSequence tickerText = chat.getParticipant().getName();
-				Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System
-						.currentTimeMillis());
-				notification.defaults = Notification.DEFAULT_ALL;
-				notification.flags = Notification.FLAG_AUTO_CANCEL;
-				notification.setLatestEventInfo(mService, tickerText, mService
-						.getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat));
-				mService.sendNotification(chat.hashCode(), notification);
-			} catch (RemoteException e) {
-				Log.e(TAG, e.getMessage());
-			}
-		}
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void chatCreated(Chat chat, boolean locally) {
+	    IChat newchat = getChat(chat);
+	    chat.addMessageListener(mChatListener);
+	    final int n = mRemoteChatCreationListeners.beginBroadcast();
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void processMessage(Chat chat, Message message) {
-			ChatAdapter newchat = getChat(chat);
-			try {
-				if (message.getBody() != null)
-					newchat.addMessage(new com.beem.project.beem.service.Message(message));
-				final int n = mRemoteMessageListeners.beginBroadcast();
-				for (int i = 0; i < n; i++) {
-					IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
-					listener.processMessage(newchat, new com.beem.project.beem.service.Message(message));
-				}
-				mRemoteMessageListeners.finishBroadcast();
-				if (!newchat.isOpen() && message.getBody() != null) {
-					notifyNewChat(newchat);
-				}
-			} catch (RemoteException e) {
-				Log.w(TAG, e.getMessage());
-			}
+	    for (int i = 0; i < n; i++) {
+		IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i);
+		try {
+		    listener.chatCreated(newchat, locally);
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, " Error while triggering remote connection listeners in chat creation", e);
 		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void stateChanged(Chat chat, ChatState state) {
-			IChat newchat = getChat(chat);
-			try {
-				newchat.setState(state.name());
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-			final int n = mRemoteMessageListeners.beginBroadcast();
-
-			for (int i = 0; i < n; i++) {
-				IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
-				try {
-					listener.stateChanged(newchat);
-				} catch (RemoteException e) {
-					Log.w(TAG, e.getMessage());
-				}
-			}
-			mRemoteMessageListeners.finishBroadcast();
-		}
+	    }
+	    mRemoteChatCreationListeners.finishBroadcast();
 	}
 
 	/**
-	 * Tag to use with log methods.
+	 * Create the PendingIntent to launch our activity if the user select this chat notification.
+	 * @param chat
+	 * @return
 	 */
-	public static final String TAG = "BeemChatManager";
-	private final ChatManager mAdaptee;
-	private final Map<String, ChatAdapter> mChats = new HashMap<String, ChatAdapter>();
-	private final ChatListener mChatListener = new ChatListener();
-	private final RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners = new RemoteCallbackList<IChatManagerListener>();
-	private final RemoteCallbackList<IMessageListener> mRemoteMessageListeners = new RemoteCallbackList<IMessageListener>();
-
-	private final BeemService mService;
+	private PendingIntent makeChatIntent(IChat chat) {
+	    Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class);
+	    chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+	    try {
+		chatIntent.setData(chat.getParticipant().toUri());
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+	    PendingIntent contentIntent = PendingIntent.getActivity(mService, 0, chatIntent,
+		PendingIntent.FLAG_UPDATE_CURRENT);
+	    return (contentIntent);
+	}
 
 	/**
-	 * Constructor.
-	 * 
-	 * @param chatManager
-	 *            the smack ChatManager to adapt
-	 * @param service
-	 *            the service which runs the chat manager
+	 * Set a notification of a new chat.
+	 * @param chat The chat to access by the notification
 	 */
-	public BeemChatManager(final ChatManager chatManager, final BeemService service) {
-		mService = service;
-		mAdaptee = chatManager;
-		mAdaptee.addChatListener(mChatListener);
+	private void notifyNewChat(IChat chat) {
+	    try {
+		CharSequence tickerText = chat.getParticipant().getName();
+		Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System
+		    .currentTimeMillis());
+		notification.defaults = Notification.DEFAULT_ALL;
+		notification.flags = Notification.FLAG_AUTO_CANCEL;
+		notification.setLatestEventInfo(mService, tickerText, mService
+		    .getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat));
+		mService.sendNotification(chat.hashCode(), notification);
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void processMessage(Chat chat, Message message) {
+	    ChatAdapter newchat = getChat(chat);
+	    try {
+		if (message.getBody() != null)
+		    newchat.addMessage(new com.beem.project.beem.service.Message(message));
+		final int n = mRemoteMessageListeners.beginBroadcast();
+		for (int i = 0; i < n; i++) {
+		    IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
+		    listener.processMessage(newchat, new com.beem.project.beem.service.Message(message));
+		}
+		mRemoteMessageListeners.finishBroadcast();
+		if (!newchat.isOpen() && message.getBody() != null) {
+		    notifyNewChat(newchat);
+		}
+	    } catch (RemoteException e) {
+		Log.w(TAG, e.getMessage());
+	    }
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void addChatCreationListener(IChatManagerListener listener) throws RemoteException {
-		mRemoteChatCreationListeners.register(listener);
-	}
+	public void stateChanged(Chat chat, ChatState state) {
+	    IChat newchat = getChat(chat);
+	    try {
+		newchat.setState(state.name());
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
+	    final int n = mRemoteMessageListeners.beginBroadcast();
 
-	/**
-	 * Create a chat session.
-	 * 
-	 * @param contact
-	 *            the contact you want to chat with
-	 * @param listener
-	 *            listener to use for chat events on this chat session
-	 * @return the chat session
-	 */
-	public IChat createChat(Contact contact, IMessageListener listener) {
-		String jid = contact.getJID();
-		return createChat(jid, listener);
+	    for (int i = 0; i < n; i++) {
+		IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
+		try {
+		    listener.stateChanged(newchat);
+		} catch (RemoteException e) {
+		    Log.w(TAG, e.getMessage());
+		}
+	    }
+	    mRemoteMessageListeners.finishBroadcast();
 	}
+    }
 
-	/**
-	 * Create a chat session.
-	 * 
-	 * @param jid
-	 *            the jid of the contact you want to chat with
-	 * @param listener
-	 *            listener to use for chat events on this chat session
-	 * @return the chat session
-	 */
-	public IChat createChat(String jid, IMessageListener listener) {
-		mRemoteMessageListeners.register(listener);
-		String key = StringUtils.parseBareAddress(jid);
-		if (mChats.containsKey(key)) {
-			return mChats.get(key);
-		}
-		mAdaptee.createChat(key, mChatListener);
-		return mChats.get(key);
-	}
+    /**
+     * Tag to use with log methods.
+     */
+    public static final String TAG = "BeemChatManager";
+    private final ChatManager mAdaptee;
+    private final Map<String, ChatAdapter> mChats = new HashMap<String, ChatAdapter>();
+    private final ChatListener mChatListener = new ChatListener();
+    private final RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners = new RemoteCallbackList<IChatManagerListener>();
+    private final RemoteCallbackList<IMessageListener> mRemoteMessageListeners = new RemoteCallbackList<IMessageListener>();
+
+    private final BeemService mService;
+
+    /**
+     * Constructor.
+     * @param chatManager the smack ChatManager to adapt
+     * @param service the service which runs the chat manager
+     */
+    public BeemChatManager(final ChatManager chatManager, final BeemService service) {
+	mService = service;
+	mAdaptee = chatManager;
+	mAdaptee.addChatListener(mChatListener);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void addChatCreationListener(IChatManagerListener listener) throws RemoteException {
+	mRemoteChatCreationListeners.register(listener);
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void destroyChat(IChat chat) throws RemoteException {
-		Log.d(TAG, "destroyChat - jid = " + chat.getParticipant().getJID());
-		IChat c = mChats.remove(chat.getParticipant().getJID());
-		if (c == null)
-			Log.w(TAG, "destroyChat - chat = null, jid = " + chat.getParticipant().getJID());
+    /**
+     * Create a chat session.
+     * @param contact the contact you want to chat with
+     * @param listener listener to use for chat events on this chat session
+     * @return the chat session
+     */
+    public IChat createChat(Contact contact, IMessageListener listener) {
+	String jid = contact.getJID();
+	return createChat(jid, listener);
+    }
+
+    /**
+     * Create a chat session.
+     * @param jid the jid of the contact you want to chat with
+     * @param listener listener to use for chat events on this chat session
+     * @return the chat session
+     */
+    public IChat createChat(String jid, IMessageListener listener) {
+	mRemoteMessageListeners.register(listener);
+	String key = StringUtils.parseBareAddress(jid);
+	if (mChats.containsKey(key)) {
+	    return mChats.get(key);
 	}
-
-	@Override
-	public void deleteChatNotification(IChat chat) {
-		mService.deleteNotification(chat.hashCode());
-	}
+	mAdaptee.createChat(key, mChatListener);
+	return mChats.get(key);
+    }
 
-	/**
-	 * Get an existing ChatAdapter or create it if necessary.
-	 * 
-	 * @param chat
-	 *            The real instance of smack chat
-	 * @return a chat adapter register in the manager
-	 */
-	private ChatAdapter getChat(Chat chat) {
-		String key = StringUtils.parseBareAddress(chat.getParticipant());
-		if (mChats.containsKey(key)) {
-			return mChats.get(key);
-		}
-		ChatAdapter res = new ChatAdapter(chat);
-		mChats.put(key, res);
-		return res;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void destroyChat(IChat chat) throws RemoteException {
+	Log.d(TAG, "destroyChat - jid = " + chat.getParticipant().getJID());
+	IChat c = mChats.remove(chat.getParticipant().getJID());
+	if (c == null)
+	    Log.w(TAG, "destroyChat - chat = null, jid = " + chat.getParticipant().getJID());
+    }
+
+    @Override
+    public void deleteChatNotification(IChat chat) {
+	mService.deleteNotification(chat.hashCode());
+    }
+
+    /**
+     * Get an existing ChatAdapter or create it if necessary.
+     * @param chat The real instance of smack chat
+     * @return a chat adapter register in the manager
+     */
+    private ChatAdapter getChat(Chat chat) {
+	String key = StringUtils.parseBareAddress(chat.getParticipant());
+	if (mChats.containsKey(key)) {
+	    return mChats.get(key);
 	}
+	ChatAdapter res = new ChatAdapter(chat);
+	mChats.put(key, res);
+	return res;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void removeChatCreationListener(IChatManagerListener listener) throws RemoteException {
-		mRemoteChatCreationListeners.unregister(listener);
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void removeChatCreationListener(IChatManagerListener listener) throws RemoteException {
+	mRemoteChatCreationListeners.unregister(listener);
+    }
 
 }
--- a/src/com/beem/project/beem/service/ChatAdapter.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/ChatAdapter.java	Wed Nov 11 19:34:04 2009 +0100
@@ -13,119 +13,113 @@
 
 /**
  * An adapter for smack's Chat class.
- * 
  * @author darisk
  */
 public class ChatAdapter extends IChat.Stub {
-	private static final int HISTORY_MAX_SIZE = 50;
+    private static final int HISTORY_MAX_SIZE = 50;
 
-	private final Chat mAdaptee;
-	private final Contact mParticipant;
-	private String mState;
-	private boolean mIsOpen;
-	private final List<Message> mMessages;
+    private final Chat mAdaptee;
+    private final Contact mParticipant;
+    private String mState;
+    private boolean mIsOpen;
+    private final List<Message> mMessages;
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param chat
-	 *            The chat to adapt
-	 */
-	public ChatAdapter(final Chat chat) {
-		mAdaptee = chat;
-		mParticipant = new Contact(chat.getParticipant());
-		mMessages = new LinkedList<Message>();
-	}
+    /**
+     * Constructor.
+     * @param chat The chat to adapt
+     */
+    public ChatAdapter(final Chat chat) {
+	mAdaptee = chat;
+	mParticipant = new Contact(chat.getParticipant());
+	mMessages = new LinkedList<Message>();
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public Contact getParticipant() throws RemoteException {
-		return mParticipant;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Contact getParticipant() throws RemoteException {
+	return mParticipant;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void sendMessage(com.beem.project.beem.service.Message message) throws RemoteException {
-		org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message();
-		send.setTo(message.getTo());
-		send.setBody(message.getBody());
-		send.setThread(message.getThread());
-		send.setSubject(message.getSubject());
-		send.setType(org.jivesoftware.smack.packet.Message.Type.chat);
-		// TODO gerer les messages contenant des XMPPError
-		// send.set
-		try {
-			mAdaptee.sendMessage(send);
-			mMessages.add(message);
-		} catch (XMPPException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void sendMessage(com.beem.project.beem.service.Message message) throws RemoteException {
+	org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message();
+	send.setTo(message.getTo());
+	send.setBody(message.getBody());
+	send.setThread(message.getThread());
+	send.setSubject(message.getSubject());
+	send.setType(org.jivesoftware.smack.packet.Message.Type.chat);
+	// TODO gerer les messages contenant des XMPPError
+	// send.set
+	try {
+	    mAdaptee.sendMessage(send);
+	    mMessages.add(message);
+	} catch (XMPPException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
 	}
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public String getState() throws RemoteException {
-		return mState;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getState() throws RemoteException {
+	return mState;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void setState(String state) throws RemoteException {
-		mState = state;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setState(String state) throws RemoteException {
+	mState = state;
+    }
 
-	/**
-	 * Get the adaptee for the Chat.
-	 * 
-	 * @return The real chat object
-	 */
-	public Chat getAdaptee() {
-		return mAdaptee;
-	}
+    /**
+     * Get the adaptee for the Chat.
+     * @return The real chat object
+     */
+    public Chat getAdaptee() {
+	return mAdaptee;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void setOpen(boolean isOpen) {
-		this.mIsOpen = isOpen;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setOpen(boolean isOpen) {
+	this.mIsOpen = isOpen;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean isOpen() {
-		return mIsOpen;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isOpen() {
+	return mIsOpen;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public List<Message> getMessages() throws RemoteException {
-		return Collections.unmodifiableList(mMessages);
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<Message> getMessages() throws RemoteException {
+	return Collections.unmodifiableList(mMessages);
+    }
 
-	/**
-	 * Add a message in the chat history.
-	 * 
-	 * @param msg
-	 *            the message to add
-	 */
-	void addMessage(Message msg) {
-		if (mMessages.size() == HISTORY_MAX_SIZE)
-			mMessages.remove(0);
-		mMessages.add(msg);
-	}
+    /**
+     * Add a message in the chat history.
+     * @param msg the message to add
+     */
+    void addMessage(Message msg) {
+	if (mMessages.size() == HISTORY_MAX_SIZE)
+	    mMessages.remove(0);
+	mMessages.add(msg);
+    }
 
 }
--- a/src/com/beem/project/beem/service/Contact.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/Contact.java	Wed Nov 11 19:34:04 2009 +0100
@@ -19,384 +19,338 @@
 
 /**
  * This class contains informations on a jabber contact.
- * 
  * @author darisk
  */
 public class Contact implements Parcelable {
 
-	/**
-	 * 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 int mID;
-	private int mStatus;
-	private String mJID;
-	private String mMsgState;
-	private List<String> mRes;
-	private List<String> mGroups;
-	private String mName;
-
-	/**
-	 * Constructor.
-	 */
-	public Contact() {
-	}
-
-	/**
-	 * 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();
-		mName = in.readString();
-		mMsgState = in.readString();
-		mRes = new ArrayList<String>();
-		mGroups = new ArrayList<String>();
-		in.readStringList(mRes);
-		in.readStringList(mGroups);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void writeToParcel(Parcel dest, int flags) {
-		dest.writeInt(mID);
-		dest.writeInt(mStatus);
-		dest.writeString(mJID);
-		dest.writeString(mName);
-		dest.writeString(mMsgState);
-		dest.writeStringList(getMRes());
-		dest.writeStringList(getGroups());
-	}
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param jid
-	 *            JID of the contact
-	 */
-	public Contact(final String jid) {
-		mJID = StringUtils.parseBareAddress(jid);
-		mName = mJID;
-		mStatus = Status.CONTACT_STATUS_DISCONNECT;
-		mMsgState = null;
-		mRes = new ArrayList<String>();
-		String res = StringUtils.parseResource(jid);
-		if (!"".equals(res))
-			mRes.add(res);
-		mGroups = new ArrayList<String>();
-	}
+    /**
+     * Parcelable.Creator needs by Android.
+     */
+    public static final Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator<Contact>() {
 
-	/**
-	 * Create a contact from a Uri.
-	 * 
-	 * @param uri
-	 *            an uri for the contact
-	 * @throws IllegalArgumentException
-	 *             if it is not a xmpp uri
-	 */
-	public Contact(final Uri uri) {
-		if (!"xmpp".equals(uri.getScheme()))
-			throw new IllegalArgumentException();
-		String enduri = uri.getEncodedSchemeSpecificPart();
-		mJID = StringUtils.parseBareAddress(enduri);
-		mName = mJID;
-		mStatus = Status.CONTACT_STATUS_DISCONNECT;
-		mMsgState = null;
-		mRes = new ArrayList<String>();
-		mRes.add(StringUtils.parseResource(enduri));
-		mGroups = new ArrayList<String>();
-	}
-
-	/**
-	 * Add a group for the contact.
-	 * 
-	 * @param group
-	 *            the group
-	 */
-	public void addGroup(String group) {
-		if (!mGroups.contains(group))
-			mGroups.add(group);
-	}
-
-	/**
-	 * Remove the contact from a group.
-	 * 
-	 * @param group
-	 *            the group to delete the contact from.
-	 */
-	public void delGroup(String group) {
-		mGroups.remove(group);
-	}
-
-	/**
-	 * Add a resource for this contact.
-	 * 
-	 * @param res
-	 *            the resource to add
-	 */
-	public void addRes(String res) {
-		if (!mRes.contains(res))
-			mRes.add(res);
-	}
-
-	/**
-	 * Delete a resource for this contact.
-	 * 
-	 * @param res
-	 *            the resource de delete
-	 */
-	public void delRes(String res) {
-		mRes.remove(res);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
 	@Override
-	public int describeContents() {
-		// TODO Auto-generated method stub
-		return 0;
-	}
-
-	/**
-	 * Get the groups the contact is in.
-	 * 
-	 * @return the mGroups
-	 */
-	public List<String> getGroups() {
-		return mGroups;
-	}
-
-	/**
-	 * Get the id of the contact on the phone contact list.
-	 * 
-	 * @return the mID
-	 */
-	public int getID() {
-		return mID;
-	}
-
-	/**
-	 * Get the Jabber ID of the contact.
-	 * 
-	 * @return the Jabber ID
-	 */
-	public String getJID() {
-		return mJID;
-	}
-
-	/**
-	 * Get the list of resource for the contact.
-	 * 
-	 * @return the mRes
-	 */
-	public List<String> getMRes() {
-		return mRes;
+	public Contact createFromParcel(Parcel source) {
+	    return new Contact(source);
 	}
 
-	/**
-	 * Get the message status of the contact.
-	 * 
-	 * @return the message status of the contact.
-	 */
-	public String getMsgState() {
-		return mMsgState;
+	@Override
+	public Contact[] newArray(int size) {
+	    return new Contact[size];
 	}
+    };
 
-	/**
-	 * Get the name of the contact.
-	 * 
-	 * @return the mName
-	 */
-	public String getName() {
-		return 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.
+     */
+    public Contact() {
+    }
 
-	/**
-	 * Get the status of the contact.
-	 * 
-	 * @return the mStatus
-	 */
-	public int getStatus() {
-		return mStatus;
-	}
+    /**
+     * 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();
+	mName = in.readString();
+	mMsgState = in.readString();
+	mRes = new ArrayList<String>();
+	mGroups = new ArrayList<String>();
+	in.readStringList(mRes);
+	in.readStringList(mGroups);
+    }
 
-	/**
-	 * Set the groups the contact is in.
-	 * 
-	 * @param groups
-	 *            list of groups
-	 */
-	public void setGroups(Collection<RosterGroup> groups) {
-		this.mGroups.clear();
-		for (RosterGroup rosterGroup : groups) {
-			mGroups.add(rosterGroup.getName());
-		}
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+	dest.writeInt(mID);
+	dest.writeInt(mStatus);
+	dest.writeString(mJID);
+	dest.writeString(mName);
+	dest.writeString(mMsgState);
+	dest.writeStringList(getMRes());
+	dest.writeStringList(getGroups());
+    }
+
+    /**
+     * Constructor.
+     * @param jid JID of the contact
+     */
+    public Contact(final String jid) {
+	mJID = StringUtils.parseBareAddress(jid);
+	mName = mJID;
+	mStatus = Status.CONTACT_STATUS_DISCONNECT;
+	mMsgState = null;
+	mRes = new ArrayList<String>();
+	String res = StringUtils.parseResource(jid);
+	if (!"".equals(res))
+	    mRes.add(res);
+	mGroups = new ArrayList<String>();
+    }
 
-	/**
-	 * Set the groups the contact is in.
-	 * 
-	 * @param groups
-	 *            the mGroups to set
-	 */
-	public void setGroups(List<String> groups) {
-		this.mGroups = groups;
-	}
+    /**
+     * Create a contact from a Uri.
+     * @param uri an uri for the contact
+     * @throws IllegalArgumentException if it is not a xmpp uri
+     */
+    public Contact(final Uri uri) {
+	if (!"xmpp".equals(uri.getScheme()))
+	    throw new IllegalArgumentException();
+	String enduri = uri.getEncodedSchemeSpecificPart();
+	mJID = StringUtils.parseBareAddress(enduri);
+	mName = mJID;
+	mStatus = Status.CONTACT_STATUS_DISCONNECT;
+	mMsgState = null;
+	mRes = new ArrayList<String>();
+	mRes.add(StringUtils.parseResource(enduri));
+	mGroups = new ArrayList<String>();
+    }
 
-	/**
-	 * set the id of te contact on the phone contact list.
-	 * 
-	 * @param mid
-	 *            the mID to set
-	 */
-	public void setID(int mid) {
-		mID = mid;
-	}
+    /**
+     * Add a group for the contact.
+     * @param group the group
+     */
+    public void addGroup(String group) {
+	if (!mGroups.contains(group))
+	    mGroups.add(group);
+    }
+
+    /**
+     * Remove the contact from a group.
+     * @param group the group to delete the contact from.
+     */
+    public void delGroup(String group) {
+	mGroups.remove(group);
+    }
+
+    /**
+     * Add a resource for this contact.
+     * @param res the resource to add
+     */
+    public void addRes(String res) {
+	if (!mRes.contains(res))
+	    mRes.add(res);
+    }
 
-	/**
-	 * Set the Jabber ID of the contact.
-	 * 
-	 * @param jid
-	 *            the jabber ID to set
-	 */
-	public void setJID(String jid) {
-		mJID = jid;
-	}
+    /**
+     * Delete a resource for this contact.
+     * @param res the resource de delete
+     */
+    public void delRes(String res) {
+	mRes.remove(res);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int describeContents() {
+	// TODO Auto-generated method stub
+	return 0;
+    }
 
-	/**
-	 * Set a list of resource for the contact.
-	 * 
-	 * @param mRes
-	 *            the mRes to set
-	 */
-	public void setMRes(List<String> mRes) {
-		this.mRes = mRes;
-	}
+    /**
+     * Get the groups the contact is in.
+     * @return the mGroups
+     */
+    public List<String> getGroups() {
+	return mGroups;
+    }
+
+    /**
+     * Get the id of the contact on the phone contact list.
+     * @return the mID
+     */
+    public int getID() {
+	return mID;
+    }
 
-	/**
-	 * Set the message status of the contact.
-	 * 
-	 * @param msgState
-	 *            the message status of the contact to set
-	 */
-	public void setMsgState(String msgState) {
-		mMsgState = msgState;
-	}
+    /**
+     * Get the Jabber ID of the contact.
+     * @return the Jabber ID
+     */
+    public String getJID() {
+	return mJID;
+    }
+
+    /**
+     * Get the list of resource for the contact.
+     * @return the mRes
+     */
+    public List<String> getMRes() {
+	return mRes;
+    }
 
-	/**
-	 * Set the name of the contact.
-	 * 
-	 * @param name
-	 *            the mName to set
-	 */
-	public void setName(String name) {
-		if (name == null || "".equals(name)) {
-			this.mName = this.mJID;
-			this.mName = StringUtils.parseName(this.mName);
-			if (this.mName == null || "".equals(this.mName))
-				this.mName = this.mJID;
-		} else {
-			this.mName = name;
-		}
-	}
+    /**
+     * Get the message status of the contact.
+     * @return the message status of the contact.
+     */
+    public String getMsgState() {
+	return mMsgState;
+    }
+
+    /**
+     * Get the name of the contact.
+     * @return the mName
+     */
+    public String getName() {
+	return mName;
+    }
 
-	/**
-	 * Set the status of the contact.
-	 * 
-	 * @param status
-	 *            the mStatus to set
-	 */
-	public void setStatus(int status) {
-		mStatus = status;
-	}
+    /**
+     * Get the status of the contact.
+     * @return the mStatus
+     */
+    public int getStatus() {
+	return mStatus;
+    }
 
-	/**
-	 * Set the status of the contact using a presence packet.
-	 * 
-	 * @param presence
-	 *            the presence containing status
-	 */
-	public void setStatus(Presence presence) {
-		mStatus = Status.getStatusFromPresence(presence);
-		mMsgState = presence.getStatus();
-	}
-
-	/**
-	 * Set status for the contact.
-	 * 
-	 * @param presence
-	 *            The presence packet which contains the status
-	 */
-	public void setStatus(PresenceAdapter presence) {
-		mStatus = presence.getStatus();
-		mMsgState = presence.getStatusText();
-
+    /**
+     * Set the groups the contact is in.
+     * @param groups list of groups
+     */
+    public void setGroups(Collection<RosterGroup> groups) {
+	this.mGroups.clear();
+	for (RosterGroup rosterGroup : groups) {
+	    mGroups.add(rosterGroup.getName());
 	}
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public String toString() {
-		if (mJID != null)
-			return mJID;
-		return super.toString();
+    /**
+     * Set the groups the contact is in.
+     * @param groups the mGroups to set
+     */
+    public void setGroups(List<String> groups) {
+	this.mGroups = groups;
+    }
+
+    /**
+     * set the id of te contact on the phone contact list.
+     * @param mid the mID to set
+     */
+    public void setID(int mid) {
+	mID = mid;
+    }
+
+    /**
+     * Set the Jabber ID of the contact.
+     * @param jid the jabber ID to set
+     */
+    public void setJID(String jid) {
+	mJID = jid;
+    }
+
+    /**
+     * Set a list of resource for the contact.
+     * @param mRes the mRes to set
+     */
+    public void setMRes(List<String> mRes) {
+	this.mRes = mRes;
+    }
+
+    /**
+     * Set the message status of the contact.
+     * @param msgState the message status of the contact to set
+     */
+    public void setMsgState(String msgState) {
+	mMsgState = msgState;
+    }
+
+    /**
+     * Set the name of the contact.
+     * @param name the mName to set
+     */
+    public void setName(String name) {
+	if (name == null || "".equals(name)) {
+	    this.mName = this.mJID;
+	    this.mName = StringUtils.parseName(this.mName);
+	    if (this.mName == null || "".equals(this.mName))
+		this.mName = this.mJID;
+	} else {
+	    this.mName = name;
 	}
+    }
+
+    /**
+     * Set the status of the contact.
+     * @param status the mStatus to set
+     */
+    public void setStatus(int status) {
+	mStatus = status;
+    }
 
-	/**
-	 * Get a URI to access the contact.
-	 * 
-	 * @return the URI
-	 */
-	public Uri toUri() {
-		StringBuilder build = new StringBuilder("xmpp:");
-		String name = StringUtils.parseName(mJID);
-		build.append(name);
-		if (!"".equals(name))
-			build.append('@');
-		build.append(StringUtils.parseServer(mJID));
-		Uri u = Uri.parse(build.toString());
-		return u;
-	}
+    /**
+     * Set the status of the contact using a presence packet.
+     * @param presence the presence containing status
+     */
+    public void setStatus(Presence presence) {
+	mStatus = Status.getStatusFromPresence(presence);
+	mMsgState = presence.getStatus();
+    }
+
+    /**
+     * Set status for the contact.
+     * @param presence The presence packet which contains the status
+     */
+    public void setStatus(PresenceAdapter presence) {
+	mStatus = presence.getStatus();
+	mMsgState = presence.getStatusText();
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+	if (mJID != null)
+	    return mJID;
+	return super.toString();
+    }
 
-	/**
-	 * Get a URI to access the specific contact on this resource.
-	 * 
-	 * @param resource
-	 *            the resource of the contact
-	 * @return the URI
-	 */
-	public Uri toUri(String resource) {
-		StringBuilder build = new StringBuilder("xmpp:");
-		String name = StringUtils.parseName(mJID);
-		build.append(name);
-		if (!"".equals(name))
-			build.append('@');
-		build.append(StringUtils.parseServer(mJID));
-		if (!"".equals(resource)) {
-			build.append('/');
-			build.append(resource);
-		}
-		Uri u = Uri.parse(build.toString());
-		return u;
+    /**
+     * Get a URI to access the contact.
+     * @return the URI
+     */
+    public Uri toUri() {
+	StringBuilder build = new StringBuilder("xmpp:");
+	String name = StringUtils.parseName(mJID);
+	build.append(name);
+	if (!"".equals(name))
+	    build.append('@');
+	build.append(StringUtils.parseServer(mJID));
+	Uri u = Uri.parse(build.toString());
+	return u;
+    }
+
+    /**
+     * Get a URI to access the specific contact on this resource.
+     * @param resource the resource of the contact
+     * @return the URI
+     */
+    public Uri toUri(String resource) {
+	StringBuilder build = new StringBuilder("xmpp:");
+	String name = StringUtils.parseName(mJID);
+	build.append(name);
+	if (!"".equals(name))
+	    build.append('@');
+	build.append(StringUtils.parseServer(mJID));
+	if (!"".equals(resource)) {
+	    build.append('/');
+	    build.append(resource);
 	}
+	Uri u = Uri.parse(build.toString());
+	return u;
+    }
 }
--- a/src/com/beem/project/beem/service/Message.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/Message.java	Wed Nov 11 19:34:04 2009 +0100
@@ -8,275 +8,247 @@
 
 /**
  * This class represents a instant message.
- * 
  * @author darisk
  */
 public class Message implements Parcelable {
 
-	/**
-	 * Normal message type. Theese messages are like an email, with subject.
-	 */
-	public static final int MSG_TYPE_NORMAL = 100;
-
-	/**
-	 * Chat message type.
-	 */
-	public static final int MSG_TYPE_CHAT = 200;
-
-	/**
-	 * Group chat message type.
-	 */
-	public static final int MSG_TYPE_GROUP_CHAT = 300;
-
-	/**
-	 * Error message type.
-	 */
-	public static final int MSG_TYPE_ERROR = 400;
-	/**
-	 * Parcelable.Creator needs by Android.
-	 */
-	public static final Parcelable.Creator<Message> CREATOR = new Parcelable.Creator<Message>() {
-
-		@Override
-		public Message createFromParcel(Parcel source) {
-			return new Message(source);
-		}
+    /**
+     * Normal message type. Theese messages are like an email, with subject.
+     */
+    public static final int MSG_TYPE_NORMAL = 100;
 
-		@Override
-		public Message[] newArray(int size) {
-			return new Message[size];
-		}
-	};
-
-	private int mType;
-	private String mBody;
-	private String mSubject;
-	private String mTo;
-	private String mFrom;
-	private String mThread;
-
-	// TODO ajouter l'erreur
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param to
-	 *            the destinataire of the message
-	 * @param type
-	 *            the message type
-	 */
-	public Message(final String to, final int type) {
-		mTo = to;
-		mType = type;
-		mBody = "";
-		mSubject = "";
-		mThread = "";
-		mFrom = null;
-	}
+    /**
+     * Chat message type.
+     */
+    public static final int MSG_TYPE_CHAT = 200;
 
-	/**
-	 * Constructor a message of type chat.
-	 * 
-	 * @param to
-	 *            the destinataire of the message
-	 */
-	public Message(final String to) {
-		this(to, MSG_TYPE_CHAT);
-	}
+    /**
+     * Group chat message type.
+     */
+    public static final int MSG_TYPE_GROUP_CHAT = 300;
 
-	/**
-	 * Construct a message from a smack message packet.
-	 * 
-	 * @param smackMsg
-	 *            Smack message packet
-	 */
-	public Message(final org.jivesoftware.smack.packet.Message smackMsg) {
-		this(smackMsg.getTo());
-		switch (smackMsg.getType()) {
-		case chat:
-			mType = MSG_TYPE_CHAT;
-			break;
-		case groupchat:
-			mType = MSG_TYPE_GROUP_CHAT;
-			break;
-		case normal:
-			mType = MSG_TYPE_NORMAL;
-			break;
-		// TODO gerer les message de type error
-		// this a little work around waiting for a better handling of error
-		// messages
-		case error:
-			mType = MSG_TYPE_ERROR;
-			break;
-		default:
-			Log.w("BEEM_MESSAGE", "type de message non gerer" + smackMsg.getType());
-			break;
-		}
-		this.mFrom = smackMsg.getFrom();
-		if (mType == MSG_TYPE_ERROR) {
-			XMPPError er = smackMsg.getError();
-			String msg = er.getMessage();
-			if (msg != null)
-				mBody = msg;
-			else
-				mBody = er.getCondition();
-		} else {
-			mBody = smackMsg.getBody();
-			mSubject = smackMsg.getSubject();
-			mThread = smackMsg.getThread();
-		}
-	}
+    /**
+     * Error message type.
+     */
+    public static final int MSG_TYPE_ERROR = 400;
+    /**
+     * Parcelable.Creator needs by Android.
+     */
+    public static final Parcelable.Creator<Message> CREATOR = new Parcelable.Creator<Message>() {
 
-	/**
-	 * Construct a message from a parcel.
-	 * 
-	 * @param in
-	 *            parcel to use for construction
-	 */
-	private Message(final Parcel in) {
-		mType = in.readInt();
-		mTo = in.readString();
-		mBody = in.readString();
-		mSubject = in.readString();
-		mThread = in.readString();
-		mFrom = in.readString();
+	@Override
+	public Message createFromParcel(Parcel source) {
+	    return new Message(source);
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
 	@Override
-	public void writeToParcel(Parcel dest, int flags) {
-		// TODO Auto-generated method stub
-		dest.writeInt(mType);
-		dest.writeString(mTo);
-		dest.writeString(mBody);
-		dest.writeString(mSubject);
-		dest.writeString(mThread);
-		dest.writeString(mFrom);
+	public Message[] newArray(int size) {
+	    return new Message[size];
 	}
+    };
 
-	/**
-	 * Get the type of the message.
-	 * 
-	 * @return the type of the message.
-	 */
-	public int getType() {
-		return mType;
-	}
+    private int mType;
+    private String mBody;
+    private String mSubject;
+    private String mTo;
+    private String mFrom;
+    private String mThread;
+
+    // TODO ajouter l'erreur
+
+    /**
+     * Constructor.
+     * @param to the destinataire of the message
+     * @param type the message type
+     */
+    public Message(final String to, final int type) {
+	mTo = to;
+	mType = type;
+	mBody = "";
+	mSubject = "";
+	mThread = "";
+	mFrom = null;
+    }
+
+    /**
+     * Constructor a message of type chat.
+     * @param to the destinataire of the message
+     */
+    public Message(final String to) {
+	this(to, MSG_TYPE_CHAT);
+    }
 
-	/**
-	 * Set the type of the message.
-	 * 
-	 * @param type
-	 *            the type to set
-	 */
-	public void setType(int type) {
-		mType = type;
+    /**
+     * Construct a message from a smack message packet.
+     * @param smackMsg Smack message packet
+     */
+    public Message(final org.jivesoftware.smack.packet.Message smackMsg) {
+	this(smackMsg.getTo());
+	switch (smackMsg.getType()) {
+	    case chat:
+		mType = MSG_TYPE_CHAT;
+		break;
+	    case groupchat:
+		mType = MSG_TYPE_GROUP_CHAT;
+		break;
+	    case normal:
+		mType = MSG_TYPE_NORMAL;
+		break;
+	    // TODO gerer les message de type error
+	    // this a little work around waiting for a better handling of error
+	    // messages
+	    case error:
+		mType = MSG_TYPE_ERROR;
+		break;
+	    default:
+		Log.w("BEEM_MESSAGE", "type de message non gerer" + smackMsg.getType());
+		break;
 	}
-
-	/**
-	 * Get the body of the message.
-	 * 
-	 * @return the Body of the message
-	 */
-	public String getBody() {
-		return mBody;
+	this.mFrom = smackMsg.getFrom();
+	if (mType == MSG_TYPE_ERROR) {
+	    XMPPError er = smackMsg.getError();
+	    String msg = er.getMessage();
+	    if (msg != null)
+		mBody = msg;
+	    else
+		mBody = er.getCondition();
+	} else {
+	    mBody = smackMsg.getBody();
+	    mSubject = smackMsg.getSubject();
+	    mThread = smackMsg.getThread();
 	}
+    }
 
-	/**
-	 * Set the body of the message.
-	 * 
-	 * @param body
-	 *            the body to set
-	 */
-	public void setBody(String body) {
-		mBody = body;
-	}
+    /**
+     * Construct a message from a parcel.
+     * @param in parcel to use for construction
+     */
+    private Message(final Parcel in) {
+	mType = in.readInt();
+	mTo = in.readString();
+	mBody = in.readString();
+	mSubject = in.readString();
+	mThread = in.readString();
+	mFrom = in.readString();
+    }
 
-	/**
-	 * Get the subject of the message.
-	 * 
-	 * @return the subject
-	 */
-	public String getSubject() {
-		return mSubject;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+	// TODO Auto-generated method stub
+	dest.writeInt(mType);
+	dest.writeString(mTo);
+	dest.writeString(mBody);
+	dest.writeString(mSubject);
+	dest.writeString(mThread);
+	dest.writeString(mFrom);
+    }
 
-	/**
-	 * Set the subject of the message.
-	 * 
-	 * @param subject
-	 *            the subject to set
-	 */
-	public void setSubject(String subject) {
-		mSubject = subject;
-	}
+    /**
+     * Get the type of the message.
+     * @return the type of the message.
+     */
+    public int getType() {
+	return mType;
+    }
+
+    /**
+     * Set the type of the message.
+     * @param type the type to set
+     */
+    public void setType(int type) {
+	mType = type;
+    }
+
+    /**
+     * Get the body of the message.
+     * @return the Body of the message
+     */
+    public String getBody() {
+	return mBody;
+    }
 
-	/**
-	 * Get the destinataire of the message.
-	 * 
-	 * @return the destinataire of the message
-	 */
-	public String getTo() {
-		return mTo;
-	}
+    /**
+     * Set the body of the message.
+     * @param body the body to set
+     */
+    public void setBody(String body) {
+	mBody = body;
+    }
 
-	/**
-	 * Set the destinataire of the message.
-	 * 
-	 * @param to
-	 *            the destinataire to set
-	 */
-	public void setTo(String to) {
-		mTo = to;
-	}
+    /**
+     * Get the subject of the message.
+     * @return the subject
+     */
+    public String getSubject() {
+	return mSubject;
+    }
+
+    /**
+     * Set the subject of the message.
+     * @param subject the subject to set
+     */
+    public void setSubject(String subject) {
+	mSubject = subject;
+    }
 
-	/**
-	 * Set the from field of the message.
-	 * 
-	 * @param from
-	 *            the mFrom to set
-	 */
-	public void setFrom(String from) {
-		this.mFrom = from;
-	}
+    /**
+     * Get the destinataire of the message.
+     * @return the destinataire of the message
+     */
+    public String getTo() {
+	return mTo;
+    }
 
-	/**
-	 * Get the from field of the message.
-	 * 
-	 * @return the mFrom
-	 */
-	public String getFrom() {
-		return mFrom;
-	}
+    /**
+     * Set the destinataire of the message.
+     * @param to the destinataire to set
+     */
+    public void setTo(String to) {
+	mTo = to;
+    }
+
+    /**
+     * Set the from field of the message.
+     * @param from the mFrom to set
+     */
+    public void setFrom(String from) {
+	this.mFrom = from;
+    }
 
-	/**
-	 * Get the thread of the message.
-	 * 
-	 * @return the thread
-	 */
-	public String getThread() {
-		return mThread;
-	}
+    /**
+     * Get the from field of the message.
+     * @return the mFrom
+     */
+    public String getFrom() {
+	return mFrom;
+    }
+
+    /**
+     * Get the thread of the message.
+     * @return the thread
+     */
+    public String getThread() {
+	return mThread;
+    }
 
-	/**
-	 * Set the thread of the message.
-	 * 
-	 * @param thread
-	 *            the thread to set
-	 */
-	public void setThread(String thread) {
-		mThread = thread;
-	}
+    /**
+     * Set the thread of the message.
+     * @param thread the thread to set
+     */
+    public void setThread(String thread) {
+	mThread = thread;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public int describeContents() {
-		// TODO Auto-generated method stub
-		return 0;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int describeContents() {
+	// TODO Auto-generated method stub
+	return 0;
+    }
 
 }
--- a/src/com/beem/project/beem/service/PresenceAdapter.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/PresenceAdapter.java	Wed Nov 11 19:34:04 2009 +0100
@@ -10,168 +10,148 @@
 
 /**
  * this class contain contact presence informations.
- * 
  * @author nikita
  */
 public class PresenceAdapter implements Parcelable {
 
-	/**
-	 * Parcelable.Creator needs by Android.
-	 */
-	public static final Parcelable.Creator<PresenceAdapter> CREATOR = new Parcelable.Creator<PresenceAdapter>() {
-
-		@Override
-		public PresenceAdapter createFromParcel(Parcel source) {
-			return new PresenceAdapter(source);
-		}
-
-		@Override
-		public PresenceAdapter[] newArray(int size) {
-			return new PresenceAdapter[size];
-		}
-	};
-
-	private int mType;
-	private int mStatus;
-	private String mTo;
-	private String mFrom;
-	private String mStatusText;
+    /**
+     * Parcelable.Creator needs by Android.
+     */
+    public static final Parcelable.Creator<PresenceAdapter> CREATOR = new Parcelable.Creator<PresenceAdapter>() {
 
-	/**
-	 * constructor from Parcel.
-	 * 
-	 * @param source
-	 *            parcelable presence.
-	 */
-	public PresenceAdapter(final Parcel source) {
-		mType = source.readInt();
-		mStatus = source.readInt();
-		mTo = source.readString();
-		mFrom = source.readString();
-		mStatusText = source.readString();
-	}
-
-	/**
-	 * constructor from smack Presence.
-	 * 
-	 * @param presence
-	 *            smack presence.
-	 */
-	public PresenceAdapter(final Presence presence) {
-		mType = PresenceType.getPresenceType(presence);
-		mStatus = Status.getStatusFromPresence(presence);
-		mTo = presence.getTo();
-		mFrom = presence.getFrom();
-		mStatusText = presence.getStatus();
+	@Override
+	public PresenceAdapter createFromParcel(Parcel source) {
+	    return new PresenceAdapter(source);
 	}
 
 	@Override
-	public int describeContents() {
-		// TODO Auto-generated method stub
-		return 0;
+	public PresenceAdapter[] newArray(int size) {
+	    return new PresenceAdapter[size];
 	}
+    };
+
+    private int mType;
+    private int mStatus;
+    private String mTo;
+    private String mFrom;
+    private String mStatusText;
 
-	/**
-	 * mFrom getter.
-	 * 
-	 * @return the mFrom
-	 */
-	public String getFrom() {
-		return mFrom;
-	}
-
-	/**
-	 * mStatus getter.
-	 * 
-	 * @return the mStatus
-	 */
-	public int getStatus() {
-		return mStatus;
-	}
+    /**
+     * constructor from Parcel.
+     * @param source parcelable presence.
+     */
+    public PresenceAdapter(final Parcel source) {
+	mType = source.readInt();
+	mStatus = source.readInt();
+	mTo = source.readString();
+	mFrom = source.readString();
+	mStatusText = source.readString();
+    }
 
-	/**
-	 * mStatusText getter.
-	 * 
-	 * @return the mStatusText
-	 */
-	public String getStatusText() {
-		return mStatusText;
-	}
+    /**
+     * constructor from smack Presence.
+     * @param presence smack presence.
+     */
+    public PresenceAdapter(final Presence presence) {
+	mType = PresenceType.getPresenceType(presence);
+	mStatus = Status.getStatusFromPresence(presence);
+	mTo = presence.getTo();
+	mFrom = presence.getFrom();
+	mStatusText = presence.getStatus();
+    }
+
+    @Override
+    public int describeContents() {
+	// TODO Auto-generated method stub
+	return 0;
+    }
 
-	/**
-	 * mTo getter.
-	 * 
-	 * @return the mTo
-	 */
-	public String getTo() {
-		return mTo;
-	}
+    /**
+     * mFrom getter.
+     * @return the mFrom
+     */
+    public String getFrom() {
+	return mFrom;
+    }
 
-	/**
-	 * mType getter.
-	 * 
-	 * @return the mType
-	 */
-	public int getType() {
-		return mType;
-	}
+    /**
+     * mStatus getter.
+     * @return the mStatus
+     */
+    public int getStatus() {
+	return mStatus;
+    }
+
+    /**
+     * mStatusText getter.
+     * @return the mStatusText
+     */
+    public String getStatusText() {
+	return mStatusText;
+    }
 
-	/**
-	 * mFrom setter.
-	 * 
-	 * @param from
-	 *            the mFrom to set
-	 */
-	public void setFrom(final String from) {
-		this.mFrom = from;
-	}
+    /**
+     * mTo getter.
+     * @return the mTo
+     */
+    public String getTo() {
+	return mTo;
+    }
+
+    /**
+     * mType getter.
+     * @return the mType
+     */
+    public int getType() {
+	return mType;
+    }
 
-	/**
-	 * mStatus setter.
-	 * 
-	 * @param status
-	 *            the mStatus to set
-	 */
-	public void setStatus(final int status) {
-		this.mStatus = status;
-	}
+    /**
+     * mFrom setter.
+     * @param from the mFrom to set
+     */
+    public void setFrom(final String from) {
+	this.mFrom = from;
+    }
 
-	/**
-	 * mStatusText setter.
-	 * 
-	 * @param statusText
-	 *            the mStatusText to set
-	 */
-	public void setStatusText(final String statusText) {
-		this.mStatusText = statusText;
-	}
+    /**
+     * mStatus setter.
+     * @param status the mStatus to set
+     */
+    public void setStatus(final int status) {
+	this.mStatus = status;
+    }
 
-	/**
-	 * mTo setter.
-	 * 
-	 * @param to
-	 *            the mTo to set
-	 */
-	public void setTo(final String to) {
-		this.mTo = to;
-	}
+    /**
+     * mStatusText setter.
+     * @param statusText the mStatusText to set
+     */
+    public void setStatusText(final String statusText) {
+	this.mStatusText = statusText;
+    }
+
+    /**
+     * mTo setter.
+     * @param to the mTo to set
+     */
+    public void setTo(final String to) {
+	this.mTo = to;
+    }
 
-	/**
-	 * mType setter.
-	 * 
-	 * @param type
-	 *            the type to set
-	 */
-	public void setType(int type) {
-		this.mType = type;
-	}
+    /**
+     * mType setter.
+     * @param type the type to set
+     */
+    public void setType(int type) {
+	this.mType = type;
+    }
 
-	@Override
-	public void writeToParcel(Parcel dest, int flags) {
-		dest.writeInt(mType);
-		dest.writeInt(mStatus);
-		dest.writeString(mTo);
-		dest.writeString(mFrom);
-		dest.writeString(mStatusText);
-	}
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+	dest.writeInt(mType);
+	dest.writeInt(mStatus);
+	dest.writeString(mTo);
+	dest.writeString(mFrom);
+	dest.writeString(mStatusText);
+    }
 }
--- a/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java	Wed Nov 11 19:34:04 2009 +0100
@@ -17,130 +17,122 @@
 
 /**
  * Privacy list manager in beem.
- * 
  * @author nikita
  */
 public class PrivacyListManagerAdapter extends IPrivacyListManager.Stub {
 
-	/**
-	 * Tag.
-	 */
-	public static final String TAG = "PrivacyListManagerAdapter";
-	/**
-	 * default privacy list name.
-	 */
-	public static final String DEFAULT_PRIVACYLIST = "default";
+    /**
+     * Tag.
+     */
+    public static final String TAG = "PrivacyListManagerAdapter";
+    /**
+     * default privacy list name.
+     */
+    public static final String DEFAULT_PRIVACYLIST = "default";
+
+    private PrivacyListManager mAdaptee;
+    private List<String> mBlockedUser = new ArrayList<String>();
+    private XMPPConnection mConnection;
+    private MyPrivacyListListener mPrivacyPacketListener = new MyPrivacyListListener();
 
-	private PrivacyListManager mAdaptee;
-	private List<String> mBlockedUser = new ArrayList<String>();
-	private XMPPConnection mConnection;
-	private MyPrivacyListListener mPrivacyPacketListener = new MyPrivacyListListener();
+    /**
+     * Privacy list constructor.
+     * @param connection xmppconnection used.
+     */
+    public PrivacyListManagerAdapter(final XMPPConnection connection) {
+	mConnection = connection;
+	mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
+	mAdaptee.addListener(mPrivacyPacketListener);
+    }
+
+    /**
+     * return the blocked user list.
+     * @return blocked user list
+     */
+    public List<String> getBlockedUsers() {
+	return mBlockedUser;
+    }
 
-	/**
-	 * Privacy list constructor.
-	 * 
-	 * @param connection
-	 *            xmppconnection used.
-	 */
-	public PrivacyListManagerAdapter(final XMPPConnection connection) {
-		mConnection = connection;
-		mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
-		mAdaptee.addListener(mPrivacyPacketListener);
+    /**
+     * add an user to the blocked user list.
+     * @param jid blocked user jid
+     */
+    public synchronized void addBlockedUser(final String jid) {
+	if (mAdaptee == null) {
+	    mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
+	    mAdaptee.addListener(mPrivacyPacketListener);
 	}
+	List<PrivacyItem> pItemList = new ArrayList<PrivacyItem>();
+	PrivacyItem pItem = new PrivacyItem("jid", true, 1);
+	pItem.setFilterMessage(true);
+	pItem.setValue(jid);
+	pItemList.add(pItem);
 
-	/**
-	 * return the blocked user list.
-	 * 
-	 * @return blocked user list
-	 */
-	public List<String> getBlockedUsers() {
-		return mBlockedUser;
+	pItem = new PrivacyItem("subscription", true, 2);
+	pItem.setValue(PrivacyRule.SUBSCRIPTION_BOTH);
+	pItemList.add(pItem);
+
+	try {
+	    if (mAdaptee.getPrivacyList(DEFAULT_PRIVACYLIST) == null) {
+		mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
+	    }
+
+	} catch (XMPPException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	} catch (ClassCastException e) {
+	    e.printStackTrace();
+	    try {
+		mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
+	    } catch (XMPPException e1) {
+		// TODO Auto-generated catch block
+		e1.printStackTrace();
+	    }
+	}
+	try {
+	    mAdaptee.setActiveListName(DEFAULT_PRIVACYLIST);
+	    mAdaptee.setDefaultListName(DEFAULT_PRIVACYLIST);
+	} catch (XMPPException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
 	}
 
-	/**
-	 * add an user to the blocked user list.
-	 * 
-	 * @param jid
-	 *            blocked user jid
-	 */
-	public synchronized void addBlockedUser(final String jid) {
-		if (mAdaptee == null) {
-			mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
-			mAdaptee.addListener(mPrivacyPacketListener);
-		}
-		List<PrivacyItem> pItemList = new ArrayList<PrivacyItem>();
-		PrivacyItem pItem = new PrivacyItem("jid", true, 1);
-		pItem.setFilterMessage(true);
-		pItem.setValue(jid);
-		pItemList.add(pItem);
-
-		pItem = new PrivacyItem("subscription", true, 2);
-		pItem.setValue(PrivacyRule.SUBSCRIPTION_BOTH);
-		pItemList.add(pItem);
-
-		try {
-			if (mAdaptee.getPrivacyList(DEFAULT_PRIVACYLIST) == null) {
-				mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
-			}
+	Log.d(TAG, "addBlockedUser");
+    }
 
-		} catch (XMPPException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		} catch (ClassCastException e) {
-			e.printStackTrace();
-			try {
-				mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
-			} catch (XMPPException e1) {
-				// TODO Auto-generated catch block
-				e1.printStackTrace();
-			}
-		}
-		try {
-			mAdaptee.setActiveListName(DEFAULT_PRIVACYLIST);
-			mAdaptee.setDefaultListName(DEFAULT_PRIVACYLIST);
-		} catch (XMPPException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-		Log.d(TAG, "addBlockedUser");
-	}
-
+    /**
+     * privacy list listener.
+     * @author nikita
+     */
+    class MyPrivacyListListener implements PrivacyListListener {
 	/**
-	 * privacy list listener.
-	 * 
-	 * @author nikita
+	 * constructor.
 	 */
-	class MyPrivacyListListener implements PrivacyListListener {
-		/**
-		 * constructor.
-		 */
-		public MyPrivacyListListener() {
-		}
-
-		@Override
-		public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
-			Log.d(TAG, "setPrivacyList");
-		}
-
-		@Override
-		public void updatedPrivacyList(String listName) {
-			Log.d(TAG, "updatedPrivacyList");
-		}
+	public MyPrivacyListListener() {
 	}
 
 	@Override
-	public List<String> getBlockedUsersByList(String listName) throws RemoteException {
-		// TODO Auto-generated method stub
-		return null;
+	public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
+	    Log.d(TAG, "setPrivacyList");
 	}
 
-	/**
-	 * adaptee getter.
-	 * 
-	 * @return the current PrivacyListManager instance
-	 */
-	public PrivacyListManager getManager() {
-		return mAdaptee;
+	@Override
+	public void updatedPrivacyList(String listName) {
+	    Log.d(TAG, "updatedPrivacyList");
 	}
+    }
+
+    @Override
+    public List<String> getBlockedUsersByList(String listName) throws RemoteException {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    /**
+     * adaptee getter.
+     * @return the current PrivacyListManager instance
+     */
+    public PrivacyListManager getManager() {
+	return mAdaptee;
+    }
 }
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Wed Nov 11 19:34:04 2009 +0100
@@ -20,348 +20,336 @@
 
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.aidl.IBeemRosterListener;
-import com.beem.project.beem.utils.PresenceType;
 import com.beem.project.beem.utils.Status;
 
 /**
  * This class implement a Roster adapter for BEEM.
- * 
  * @author darisk
  */
 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<Integer, String> mDefaultStatusMessages;
-	private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
+    private static final String TAG = "RosterAdapter";
+    private Roster mAdaptee;
+    private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = new RemoteCallbackList<IBeemRosterListener>();
+    private Map<Integer, String> mDefaultStatusMessages;
+    private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
+
+    /**
+     * Constructor.
+     * @param roster the roster to adapt
+     */
+    public RosterAdapter(final Roster roster, Context context) {
+	mAdaptee = roster;
+	roster.addRosterListener(mRosterListener);
+	mDefaultStatusMessages = createDefaultStatusMessagesMap(context);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteRosListeners.register(listen);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Contact addContact(String user, String name, String[] groups) throws RemoteException {
+	RosterEntry contact = mAdaptee.getEntry(user);
+	try {
+	    mAdaptee.createEntry(user, name, groups);
+	    contact = mAdaptee.getEntry(user);
+	} catch (XMPPException e) {
+	    Log.e(TAG, "Error while adding new contact", e);
+	    return null;
+	}
+	if (groups != null) {
+	    for (String groupStr : groups) {
+		RosterGroup group = mAdaptee.getGroup(groupStr);
+		if (group == null) {
+		    group = mAdaptee.createGroup(groupStr);
+		}
+		try {
+		    group.addEntry(contact);
+		} catch (XMPPException e) {
+		    e.printStackTrace();
+		    return null;
+		}
+	    }
+	}
+	return getContactFromRosterEntry(contact);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void deleteContact(Contact contact) throws RemoteException {
+	try {
+	    RosterEntry entry = mAdaptee.getEntry(contact.getJID());
+	    mAdaptee.removeEntry(entry);
+	} catch (XMPPException e) {
+	    e.printStackTrace();
+	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void createGroup(String groupname) throws RemoteException {
+	try {
+	    mAdaptee.createGroup(groupname);
+	} catch (IllegalArgumentException e) {
+	    Log.e(TAG, "Error while creating group", e);
+	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Contact getContact(String jid) throws RemoteException {
+	if (mAdaptee.contains(jid))
+	    return getContactFromRosterEntry(mAdaptee.getEntry(jid));
+	return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<Contact> getContactList() throws RemoteException {
+	List<Contact> coList = new ArrayList<Contact>(mAdaptee.getEntries().size());
+	for (RosterEntry entry : mAdaptee.getEntries()) {
+	    coList.add(getContactFromRosterEntry(entry));
+	}
+	return coList;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<String> getGroupsNames() throws RemoteException {
+	Collection<RosterGroup> groups = mAdaptee.getGroups();
+	List<String> result = new ArrayList<String>(groups.size());
+	for (RosterGroup rosterGroup : groups) {
+	    result.add(rosterGroup.getName());
+	}
+	return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteRosListeners.unregister(listen);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setContactName(String jid, String name) throws RemoteException {
+	mAdaptee.getEntry(jid).setName(name);
+    }
+
+    @Override
+    public PresenceAdapter getPresence(String jid) throws RemoteException {
+	return new PresenceAdapter(mAdaptee.getPresence(jid));
+    }
+
+    @Override
+    public void addContactToGroup(String groupName, String jid) throws RemoteException {
+	createGroup(groupName);
+	RosterGroup group = mAdaptee.getGroup(groupName);
+	try {
+	    group.addEntry(mAdaptee.getEntry(jid));
+	} catch (XMPPException e) {
+	    e.printStackTrace();
+	}
+    }
+
+    @Override
+    public void removeContactFromGroup(String groupName, String jid) throws RemoteException {
+	RosterGroup group = mAdaptee.getGroup(groupName);
+	try {
+	    group.removeEntry(mAdaptee.getEntry(jid));
+	} catch (XMPPException e) {
+	    e.printStackTrace();
+	}
+    }
+
+    /**
+     * Get a contact from a RosterEntry.
+     * @param entry a roster entry containing information for the contact.
+     * @return a contact for this entry.
+     */
+    private Contact getContactFromRosterEntry(RosterEntry entry) {
+	String user = entry.getUser();
+	Contact c = new Contact(user);
+	Presence p = mAdaptee.getPresence(user);
+
+	if (p.getStatus() == null || p.getStatus().equals(""))
+	    p.setStatus(mDefaultStatusMessages.get(Status.getStatusFromPresence(p)));
+	c.setStatus(p);
+	try {
+	    c.setGroups(entry.getGroups());
+	} catch (NullPointerException e) {
+	    Log.d(TAG, "Group list not ready");
+	}
+	c.setName(entry.getName());
+	return c;
+    }
+
+    /**
+     * Create a map which contains default status messages.
+     * @return
+     */
+    private Map<Integer, String> createDefaultStatusMessagesMap(Context context) {
+	Map<Integer, String> defaultStatusMessages = new HashMap<Integer, String>();
+	defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE, context
+	    .getString(R.string.contact_status_msg_available));
+	defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, context
+	    .getString(R.string.contact_status_msg_available_chat));
+	defaultStatusMessages.put(Status.CONTACT_STATUS_AWAY, context.getString(R.string.contact_status_msg_away));
+	defaultStatusMessages.put(Status.CONTACT_STATUS_BUSY, context.getString(R.string.contact_status_msg_dnd));
+	defaultStatusMessages.put(Status.CONTACT_STATUS_DISCONNECT, context
+	    .getString(R.string.contact_status_msg_offline));
+	defaultStatusMessages.put(Status.CONTACT_STATUS_UNAVAILABLE, context.getString(R.string.contact_status_msg_xa));
+
+	return (defaultStatusMessages);
+    }
+
+    /**
+     * Listener for the roster events. It will call the remote listeners registered.
+     * @author darisk
+     */
+    private class RosterListenerAdapter implements RosterListener {
 
 	/**
 	 * Constructor.
-	 * 
-	 * @param roster
-	 *            the roster to adapt
 	 */
-	public RosterAdapter(final Roster roster, Context context) {
-		mAdaptee = roster;
-		roster.addRosterListener(mRosterListener);
-		mDefaultStatusMessages = createDefaultStatusMessagesMap(context);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
-		if (listen != null)
-			mRemoteRosListeners.register(listen);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public Contact addContact(String user, String name, String[] groups) throws RemoteException {
-		RosterEntry contact = mAdaptee.getEntry(user);
-		try {
-			mAdaptee.createEntry(user, name, groups);
-			contact = mAdaptee.getEntry(user);
-		} catch (XMPPException e) {
-			Log.e(TAG, "Error while adding new contact", e);
-			return null;
-		}
-		if (groups != null) {
-			for (String groupStr : groups) {
-				RosterGroup group = mAdaptee.getGroup(groupStr);
-				if (group == null) {
-					group = mAdaptee.createGroup(groupStr);
-				}
-				try {
-					group.addEntry(contact);
-				} catch (XMPPException e) {
-					e.printStackTrace();
-					return null;
-				}
-			}
-		}
-		return getContactFromRosterEntry(contact);
+	public RosterListenerAdapter() {
 	}
 
 	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void deleteContact(Contact contact) throws RemoteException {
-		try {
-			RosterEntry entry = mAdaptee.getEntry(contact.getJID());
-			mAdaptee.removeEntry(entry);
-		} catch (XMPPException e) {
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void createGroup(String groupname) throws RemoteException {
-		try {
-			mAdaptee.createGroup(groupname);
-		} catch (IllegalArgumentException e) {
-			Log.e(TAG, "Error while creating group", e);
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
+	 * Event which is fired when an entry is deleted for a group.
+	 * @param group the group the entry was.
+	 * @param jid the jid of the entry which is deleted.
 	 */
-	@Override
-	public Contact getContact(String jid) throws RemoteException {
-		if (mAdaptee.contains(jid))
-			return getContactFromRosterEntry(mAdaptee.getEntry(jid));
-		return null;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public List<Contact> getContactList() throws RemoteException {
-		List<Contact> coList = new ArrayList<Contact>(mAdaptee.getEntries().size());
-		for (RosterEntry entry : mAdaptee.getEntries()) {
-			coList.add(getContactFromRosterEntry(entry));
+	@SuppressWarnings("unused")
+	public void onEntryDeleteFromGroup(final String group, final String jid) {
+	    // Log.i(TAG, "entry delete listener");
+	    final int n = mRemoteRosListeners.beginBroadcast();
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    listener.onEntryDeleteFromGroup(group, jid);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "entry delete listener", e);
 		}
-		return coList;
-	}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public List<String> getGroupsNames() throws RemoteException {
-		Collection<RosterGroup> groups = mAdaptee.getGroups();
-		List<String> result = new ArrayList<String>(groups.size());
-		for (RosterGroup rosterGroup : groups) {
-			result.add(rosterGroup.getName());
-		}
-		return result;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
-		if (listen != null)
-			mRemoteRosListeners.unregister(listen);
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void setContactName(String jid, String name) throws RemoteException {
-		mAdaptee.getEntry(jid).setName(name);
-	}
+	public void entriesAdded(Collection<String> addresses) {
+	    // Log.i(TAG, "Ajout de l'entry " + addresses.size() + " " +
+	    // addresses.toArray()[0]);
+	    final int n = mRemoteRosListeners.beginBroadcast();
 
-	@Override
-	public PresenceAdapter getPresence(String jid) throws RemoteException {
-		return new PresenceAdapter(mAdaptee.getPresence(jid));
-	}
-
-	@Override
-	public void addContactToGroup(String groupName, String jid) throws RemoteException {
-		createGroup(groupName);
-		RosterGroup group = mAdaptee.getGroup(groupName);
+	    List<String> tab = new ArrayList<String>();
+	    tab.addAll(addresses);
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
 		try {
-			group.addEntry(mAdaptee.getEntry(jid));
-		} catch (XMPPException e) {
-			e.printStackTrace();
+		    listener.onEntriesAdded(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while adding roster entries", e);
 		}
-	}
-
-	@Override
-	public void removeContactFromGroup(String groupName, String jid) throws RemoteException {
-		RosterGroup group = mAdaptee.getGroup(groupName);
-		try {
-			group.removeEntry(mAdaptee.getEntry(jid));
-		} catch (XMPPException e) {
-			e.printStackTrace();
-		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
 	}
 
 	/**
-	 * Get a contact from a RosterEntry.
-	 * 
-	 * @param entry
-	 *            a roster entry containing information for the contact.
-	 * @return a contact for this entry.
+	 * {@inheritDoc}
 	 */
-	private Contact getContactFromRosterEntry(RosterEntry entry) {
-		String user = entry.getUser();
-		Contact c = new Contact(user);
-		Presence p = mAdaptee.getPresence(user);
-		
-		if (p.getStatus() == null || p.getStatus().equals(""))
-			p.setStatus(mDefaultStatusMessages.get(Status.getStatusFromPresence(p)));
-		c.setStatus(p);
+	@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 {
-			c.setGroups(entry.getGroups());
-		} catch (NullPointerException e) {
-			Log.d(TAG, "Group list not ready");
+		    listener.onEntriesDeleted(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while deleting roster entries", e);
 		}
-		c.setName(entry.getName());
-		return c;
-	}
-
-	/**
-	 * Create a map which contains default status messages.
-	 * 
-	 * @return
-	 */
-	private Map<Integer, String> createDefaultStatusMessagesMap(Context context) {
-		Map<Integer, String> defaultStatusMessages = new HashMap<Integer, String>();
-		defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE, context
-				.getString(R.string.contact_status_msg_available));
-		defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, context
-				.getString(R.string.contact_status_msg_available_chat));
-		defaultStatusMessages.put(Status.CONTACT_STATUS_AWAY, context.getString(R.string.contact_status_msg_away));
-		defaultStatusMessages.put(Status.CONTACT_STATUS_BUSY, context.getString(R.string.contact_status_msg_dnd));
-		defaultStatusMessages.put(Status.CONTACT_STATUS_DISCONNECT, context
-				.getString(R.string.contact_status_msg_offline));
-		defaultStatusMessages.put(Status.CONTACT_STATUS_UNAVAILABLE, context.getString(R.string.contact_status_msg_xa));
-
-		return (defaultStatusMessages);
+	    }
+	    mRemoteRosListeners.finishBroadcast();
 	}
 
 	/**
-	 * Listener for the roster events. It will call the remote listeners
-	 * registered.
-	 * 
-	 * @author darisk
+	 * {@inheritDoc}
 	 */
-	private class RosterListenerAdapter implements RosterListener {
-
-		/**
-		 * Constructor.
-		 */
-		public RosterListenerAdapter() {
-		}
+	@Override
+	public void entriesUpdated(Collection<String> addresses) {
+	    // Log.i(TAG, "Update de l'entry " + addresses.size() + " " +
+	    // addresses.toArray()[0]);
+	    final int n = mRemoteRosListeners.beginBroadcast();
 
-		/**
-		 * Event which is fired when an entry is deleted for a group.
-		 * 
-		 * @param group
-		 *            the group the entry was.
-		 * @param jid
-		 *            the jid of the entry which is deleted.
-		 */
-		@SuppressWarnings("unused")
-		public void onEntryDeleteFromGroup(final String group, final String jid) {
-			// Log.i(TAG, "entry delete listener");
-			final int n = mRemoteRosListeners.beginBroadcast();
-			for (int i = 0; i < n; i++) {
-				IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-				try {
-					listener.onEntryDeleteFromGroup(group, jid);
-				} catch (RemoteException e) {
-					Log.w(TAG, "entry delete listener", e);
-				}
-			}
-			mRemoteRosListeners.finishBroadcast();
-
+	    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);
 		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void entriesAdded(Collection<String> addresses) {
-			// Log.i(TAG, "Ajout de l'entry " + addresses.size() + " " +
-			// addresses.toArray()[0]);
-			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();
-		}
+	    }
+	    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.i(TAG, "Update de l'entry " + addresses.size() + " " +
-			// addresses.toArray()[0]);
-			final int n = mRemoteRosListeners.beginBroadcast();
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void presenceChanged(Presence presence) {
+	    // Log.i(TAG, "presence Changed");
+	    /* redispatch vers les IBeemRosterListener */
+	    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();
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    Log.d(TAG, ">>> Presence changed.");
+		    if (presence.getStatus() == null || presence.getStatus().equals("")) {
+			presence.setStatus(mDefaultStatusMessages.get(Status.getStatusFromPresence(presence)));
+			Log.d(TAG, ">>> Default status added.");
+		    }
+		    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 presence entries", e);
 		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void presenceChanged(Presence presence) {
-			// Log.i(TAG, "presence Changed");
-			/* redispatch vers les IBeemRosterListener */
-			final int n = mRemoteRosListeners.beginBroadcast();
-
-			for (int i = 0; i < n; i++) {
-				IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-				try {
-					Log.d(TAG, ">>> Presence changed.");
-					if (presence.getStatus() == null || presence.getStatus().equals("")) {
-						presence.setStatus(mDefaultStatusMessages.get(Status.getStatusFromPresence(presence)));
-						Log.d(TAG, ">>> Default status added.");
-					}
-					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 presence entries", e);
-				}
-			}
-			mRemoteRosListeners.finishBroadcast();
-		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
 	}
+    }
 }
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Wed Nov 11 19:34:04 2009 +0100
@@ -32,473 +32,445 @@
 
 /**
  * This class implements an adapter for XMPPConnection.
- * 
  * @author darisk
  */
 public class XmppConnectionAdapter extends IXmppConnection.Stub {
 
-	/**
-	 * Beem connection closed Intent name.
-	 */
+    /**
+     * Beem connection closed Intent name.
+     */
+
+    private static final String TAG = "XMPPConnectionAdapter";
+    private static final int PRESENCE_PRIORITY = 128;
 
-	private static final String TAG = "XMPPConnectionAdapter";
-	private static final int PRESENCE_PRIORITY = 128;
+    private final XMPPConnection mAdaptee;
+    private IChatManager mChatManager;
+    private final String mLogin;
+    private final String mPassword;
+    private RosterAdapter mRoster;
+    private PrivacyListManagerAdapter mPrivacyList;
+    private final BeemService mService;
+    private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
+
+    private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
 
-	private final XMPPConnection mAdaptee;
-	private IChatManager mChatManager;
-	private final String mLogin;
-	private final String mPassword;
-	private RosterAdapter mRoster;
-	private PrivacyListManagerAdapter mPrivacyList;
-	private final BeemService mService;
-	private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
+    /**
+     * Constructor.
+     * @param config Configuration to use in order to connect
+     * @param login login to use on connect
+     * @param password password to use on connect
+     * @param service the background service associated with the connection.
+     */
+    public XmppConnectionAdapter(final ConnectionConfiguration config, final String login, final String password,
+	final BeemService service) {
+	this(new XMPPConnection(config), login, password, service);
+    }
+
+    /**
+     * Constructor.
+     * @param serviceName name of the service to connect to
+     * @param login login to use on connect
+     * @param password password to use on connect
+     * @param service the background service associated with the connection.
+     */
+    public XmppConnectionAdapter(final String serviceName, final String login, final String password,
+	final BeemService service) {
+	this(new XMPPConnection(serviceName), login, password, service);
+    }
 
-	private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
+    /**
+     * Constructor.
+     * @param con The connection to adapt
+     * @param login The login to use
+     * @param password The password to use
+     * @param service the background service associated with the connection.
+     */
+    public XmppConnectionAdapter(final XMPPConnection con, final String login, final String password,
+	final BeemService service) {
+	mAdaptee = con;
+	PrivacyListManager.getInstanceFor(mAdaptee);
+	mLogin = login;
+	mPassword = password;
+	mService = service;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteConnListeners.register(listen);
+    }
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param config
-	 *            Configuration to use in order to connect
-	 * @param login
-	 *            login to use on connect
-	 * @param password
-	 *            password to use on connect
-	 * @param service
-	 *            the background service associated with the connection.
-	 */
-	public XmppConnectionAdapter(final ConnectionConfiguration config, final String login, final String password,
-			final BeemService service) {
-		this(new XMPPConnection(config), login, password, service);
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void connectAsync() throws RemoteException {
+	Thread t = new Thread(new Runnable() {
+
+	    @Override
+	    public void run() {
+		try {
+		    connectSync();
+		} catch (RemoteException e) {
+		    Log.e(TAG, "Error while connecting asynchronously", e);
+		}
+	    }
+	});
+	t.start();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean connectSync() throws RemoteException {
+	try {
+	    mAdaptee.connect();
+	    mAdaptee.addConnectionListener(mConListener);
+	    mAdaptee.login(mLogin, mPassword, "BEEM");
+
+	    mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
+	    mPrivacyList = new PrivacyListManagerAdapter(mAdaptee);
+
+	    this.initFeatures(); // pour declarer les features xmpp qu'on
+	    // supporte
+	    ChatStateManager.getInstance(mAdaptee);
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param serviceName
-	 *            name of the service to connect to
-	 * @param login
-	 *            login to use on connect
-	 * @param password
-	 *            password to use on connect
-	 * @param service
-	 *            the background service associated with the connection.
-	 */
-	public XmppConnectionAdapter(final String serviceName, final String login, final String password,
-			final BeemService service) {
-		this(new XMPPConnection(serviceName), login, password, service);
+	    triggerAsynchronousConnectEvent();
+	    // Priority between -128 and 128
+	    Presence p = new Presence(Presence.Type.available, "Beem : http://www.beem-project.com", PRESENCE_PRIORITY,
+		Presence.Mode.available);
+	    mAdaptee.sendPacket(p);
+	    return true;
+	} catch (XMPPException e) {
+	    Log.d(TAG, "Error while connecting", e);
+	    if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null)
+		mConListener.connectionFailed(e.getXMPPError().getMessage());
+	    else if (e.getMessage() != null)
+		mConListener.connectionFailed(e.getMessage());
+	    else
+		mConListener.connectionFailed("Error On Connection");
+	} catch (IllegalStateException e) {
+	    mConListener.connectionFailed(e.getMessage());
 	}
+	return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean disconnect() {
+	if (mAdaptee != null && mAdaptee.isConnected())
+	    mAdaptee.disconnect();
+	return true;
+    }
+
+    /**
+     * Get the Smack XmppConnection.
+     * @return Smack XmppConnection
+     */
+    public XMPPConnection getAdaptee() {
+	return mAdaptee;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IChatManager getChatManager() throws RemoteException {
+	return mChatManager;
+    }
+
+    /**
+     * Get the context of the adapter.
+     * @return The context of the adapter
+     */
+    public BeemService getContext() {
+	return mService;
+    }
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param con
-	 *            The connection to adapt
-	 * @param login
-	 *            The login to use
-	 * @param password
-	 *            The password to use
-	 * @param service
-	 *            the background service associated with the connection.
-	 */
-	public XmppConnectionAdapter(final XMPPConnection con, final String login, final String password,
-			final BeemService service) {
-		mAdaptee = con;
-		PrivacyListManager.getInstanceFor(mAdaptee);
-		mLogin = login;
-		mPassword = password;
-		mService = service;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IRoster getRoster() throws RemoteException {
+	if (mRoster != null)
+	    return mRoster;
+	Roster adap = mAdaptee.getRoster();
+	if (adap == null)
+	    return null;
+	mRoster = new RosterAdapter(adap, mService.getApplicationContext());
+	return mRoster;
+    }
+
+    /**
+     * enregistre les features dispo dans notre version Liste de features que Telepathy supporte.
+     */
+    private void initFeatures() {
+	ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+	if (sdm == null)
+	    sdm = new ServiceDiscoveryManager(mAdaptee);
+	sdm.addFeature("http://jabber.org/protocol/disco#info");
+	JingleManager.setJingleServiceEnabled();
+	sdm.addFeature("jabber:iq:privacy");
+    }
+
+    /**
+     * Returns true if currently authenticated by successfully calling the login method.
+     * @return true when successfully authenticated
+     */
+    public boolean isAuthentificated() {
+	return mAdaptee.isAuthenticated();
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
-		if (listen != null)
-			mRemoteConnListeners.register(listen);
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteConnListeners.unregister(listen);
+    }
+
+    /**
+     * Trigger Connection event.
+     */
+    private void triggerAsynchronousConnectEvent() {
+	mConListener.onConnect();
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public final void connectAsync() throws RemoteException {
-		Thread t = new Thread(new Runnable() {
+    /**
+     * Set the privacy list to use.
+     * @param privacyList the mPrivacyList to set
+     */
+    public void setPrivacyList(PrivacyListManagerAdapter privacyList) {
+	this.mPrivacyList = privacyList;
+    }
 
-			@Override
-			public void run() {
-				try {
-					connectSync();
-				} catch (RemoteException e) {
-					Log.e(TAG, "Error while connecting asynchronously", e);
-				}
-			}
-		});
-		t.start();
-	}
+    /**
+     * Get the privacy list in use.
+     * @return the mPrivacyList
+     */
+    public PrivacyListManagerAdapter getPrivacyList() {
+	return mPrivacyList;
+    }
+
+    /**
+     * Listener for XMPP connection events. It will calls the remote listeners for connection events.
+     * @author darisk
+     */
+    private class ConnexionListenerAdapter implements ConnectionListener {
 
 	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean connectSync() throws RemoteException {
-		try {
-			mAdaptee.connect();
-			mAdaptee.addConnectionListener(mConListener);
-			mAdaptee.login(mLogin, mPassword, "BEEM");
-
-			mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
-			mPrivacyList = new PrivacyListManagerAdapter(mAdaptee);
-
-			this.initFeatures(); // pour declarer les features xmpp qu'on
-			// supporte
-			ChatStateManager.getInstance(mAdaptee);
-
-			triggerAsynchronousConnectEvent();
-			// Priority between -128 and 128
-			Presence p = new Presence(Presence.Type.available, "Beem : http://www.beem-project.com", PRESENCE_PRIORITY,
-					Presence.Mode.available);
-			mAdaptee.sendPacket(p);
-			return true;
-		} catch (XMPPException e) {
-			Log.d(TAG, "Error while connecting", e);
-			if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null)
-				mConListener.connectionFailed(e.getXMPPError().getMessage());
-			else if (e.getMessage() != null)
-				mConListener.connectionFailed(e.getMessage());
-			else
-				mConListener.connectionFailed("Error On Connection");
-		} catch (IllegalStateException e) {
-			mConListener.connectionFailed(e.getMessage());
-		}
-		return false;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean disconnect() {
-		if (mAdaptee != null && mAdaptee.isConnected())
-			mAdaptee.disconnect();
-		return true;
-	}
-
-	/**
-	 * Get the Smack XmppConnection.
-	 * 
-	 * @return Smack XmppConnection
+	 * Defaut constructor.
 	 */
-	public XMPPConnection getAdaptee() {
-		return mAdaptee;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public IChatManager getChatManager() throws RemoteException {
-		return mChatManager;
-	}
-
-	/**
-	 * Get the context of the adapter.
-	 * 
-	 * @return The context of the adapter
-	 */
-	public BeemService getContext() {
-		return mService;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public IRoster getRoster() throws RemoteException {
-		if (mRoster != null)
-			return mRoster;
-		Roster adap = mAdaptee.getRoster();
-		if (adap == null)
-			return null;
-		mRoster = new RosterAdapter(adap, mService.getApplicationContext());
-		return mRoster;
-	}
-
-	/**
-	 * enregistre les features dispo dans notre version Liste de features que
-	 * Telepathy supporte.
-	 */
-	private void initFeatures() {
-		ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
-		if (sdm == null)
-			sdm = new ServiceDiscoveryManager(mAdaptee);
-		sdm.addFeature("http://jabber.org/protocol/disco#info");
-		JingleManager.setJingleServiceEnabled();
-		sdm.addFeature("jabber:iq:privacy");
-	}
-
-	/**
-	 * Returns true if currently authenticated by successfully calling the login
-	 * method.
-	 * 
-	 * @return true when successfully authenticated
-	 */
-	public boolean isAuthentificated() {
-		return mAdaptee.isAuthenticated();
+	public ConnexionListenerAdapter() {
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
-		if (listen != null)
-			mRemoteConnListeners.unregister(listen);
-	}
-
-	/**
-	 * Trigger Connection event.
-	 */
-	private void triggerAsynchronousConnectEvent() {
-		mConListener.onConnect();
+	public void connectionClosed() {
+	    Log.d(TAG, "closing connection");
+	    mRoster = null;
+	    Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
+	    intent.putExtra("message", mService.getString(R.string.BeemBroadcastReceiverDisconnect));
+	    intent.putExtra("normally", true);
+	    mService.sendBroadcast(intent);
+	    mService.stopSelf();
 	}
 
 	/**
-	 * Set the privacy list to use.
-	 * 
-	 * @param privacyList
-	 *            the mPrivacyList to set
+	 * {@inheritDoc}
 	 */
-	public void setPrivacyList(PrivacyListManagerAdapter privacyList) {
-		this.mPrivacyList = privacyList;
+	@Override
+	public void connectionClosedOnError(Exception exception) {
+	    Log.d(TAG, "connectionClosedOnError");
+	    mRoster = null;
+	    Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
+	    intent.putExtra("message", exception.getMessage());
+	    mService.sendBroadcast(intent);
+	    mService.stopSelf();
 	}
 
 	/**
-	 * Get the privacy list in use.
-	 * 
-	 * @return the mPrivacyList
+	 * Connection failed callback.
+	 * @param errorMsg smack failure message
 	 */
-	public PrivacyListManagerAdapter getPrivacyList() {
-		return mPrivacyList;
+	public void connectionFailed(String errorMsg) {
+	    Log.d(TAG, "Connection Failed");
+	    final int n = mRemoteConnListeners.beginBroadcast();
+
+	    for (int i = 0; i < n; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.connectionFailed(errorMsg);
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
+		}
+	    }
+	    mRemoteConnListeners.finishBroadcast();
+	    mService.stopSelf();
 	}
 
 	/**
-	 * Listener for XMPP connection events. It will calls the remote listeners
-	 * for connection events.
-	 * 
-	 * @author darisk
+	 * Method to execute when a connection event occurs.
 	 */
-	private class ConnexionListenerAdapter implements ConnectionListener {
+	public void onConnect() {
+	    PacketFilter filter = new PacketFilter() {
 
-		/**
-		 * Defaut constructor.
-		 */
-		public ConnexionListenerAdapter() {
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
 		@Override
-		public void connectionClosed() {
-			Log.d(TAG, "closing connection");
-			mRoster = null;
-			Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
-			intent.putExtra("message", mService.getString(R.string.BeemBroadcastReceiverDisconnect));
-			intent.putExtra("normally", true);
-			mService.sendBroadcast(intent);
-			mService.stopSelf();
+		public boolean accept(Packet packet) {
+		    if (packet instanceof Presence) {
+			Presence pres = (Presence) packet;
+			if (pres.getType() == Presence.Type.subscribe)
+			    return true;
+		    }
+		    return false;
 		}
+	    };
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void connectionClosedOnError(Exception exception) {
-			Log.d(TAG, "connectionClosedOnError");
-			mRoster = null;
-			Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
-			intent.putExtra("message", exception.getMessage());
-			mService.sendBroadcast(intent);
-			mService.stopSelf();
-		}
-
-		/**
-		 * Connection failed callback.
-		 * 
-		 * @param errorMsg
-		 *            smack failure message
-		 */
-		public void connectionFailed(String errorMsg) {
-			Log.d(TAG, "Connection Failed");
-			final int n = mRemoteConnListeners.beginBroadcast();
+	    mAdaptee.addPacketListener(new PacketListener() {
 
-			for (int i = 0; i < n; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.connectionFailed(errorMsg);
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
-			mService.stopSelf();
+		@Override
+		public void processPacket(Packet packet) {
+		    String from = packet.getFrom();
+		    Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
+			.getString(R.string.AcceptContactRequest), System.currentTimeMillis());
+		    notif.defaults = Notification.DEFAULT_ALL;
+		    notif.flags = Notification.FLAG_AUTO_CANCEL;
+		    Intent intent = new Intent(mService, Subscription.class);
+		    intent.putExtra("from", from);
+		    notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
+			+ from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
+		    int id = packet.hashCode();
+		    mService.sendNotification(id, notif);
 		}
-
-		/**
-		 * Method to execute when a connection event occurs.
-		 */
-		public void onConnect() {
-			PacketFilter filter = new PacketFilter() {
+	    }, filter);
 
-				@Override
-				public boolean accept(Packet packet) {
-					if (packet instanceof Presence) {
-						Presence pres = (Presence) packet;
-						if (pres.getType() == Presence.Type.subscribe)
-							return true;
-					}
-					return false;
-				}
-			};
-
-			mAdaptee.addPacketListener(new PacketListener() {
-
-				@Override
-				public void processPacket(Packet packet) {
-					String from = packet.getFrom();
-					Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
-							.getString(R.string.AcceptContactRequest), System.currentTimeMillis());
-					notif.defaults = Notification.DEFAULT_ALL;
-					notif.flags = Notification.FLAG_AUTO_CANCEL;
-					Intent intent = new Intent(mService, Subscription.class);
-					intent.putExtra("from", from);
-					notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
-							+ from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
-					int id = packet.hashCode();
-					mService.sendNotification(id, notif);
-				}
-			}, filter);
-
-			mService.resetStatus();
-			mService.initJingle(mAdaptee);
-
-			final int n = mRemoteConnListeners.beginBroadcast();
+	    mService.resetStatus();
+	    mService.initJingle(mAdaptee);
 
-			for (int i = 0; i < n; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.onConnect();
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void reconnectingIn(int arg0) {
-			Log.d(TAG, "reconnectingIn");
-			final int n = mRemoteConnListeners.beginBroadcast();
+	    final int n = mRemoteConnListeners.beginBroadcast();
 
-			for (int i = 0; i < n; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.reconnectingIn(arg0);
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
+	    for (int i = 0; i < n; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.onConnect();
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
 		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void reconnectionFailed(Exception arg0) {
-			Log.d(TAG, "reconnectionFailed");
-			final int r = mRemoteConnListeners.beginBroadcast();
+	    }
+	    mRemoteConnListeners.finishBroadcast();
+	}
 
-			for (int i = 0; i < r; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.reconnectionFailed();
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void reconnectionSuccessful() {
-			Log.d(TAG, "reconnectionSuccessful");
-			PacketFilter filter = new PacketFilter() {
-
-				@Override
-				public boolean accept(Packet packet) {
-					if (packet instanceof Presence) {
-						Presence pres = (Presence) packet;
-						if (pres.getType() == Presence.Type.subscribe)
-							return true;
-					}
-					return false;
-				}
-			};
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void reconnectingIn(int arg0) {
+	    Log.d(TAG, "reconnectingIn");
+	    final int n = mRemoteConnListeners.beginBroadcast();
 
-			mAdaptee.addPacketListener(new PacketListener() {
-
-				@Override
-				public void processPacket(Packet packet) {
-					String from = packet.getFrom();
-					Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
-							.getString(R.string.AcceptContactRequest), System.currentTimeMillis());
-					notif.defaults = Notification.DEFAULT_ALL;
-					notif.flags = Notification.FLAG_AUTO_CANCEL;
-					Intent intent = new Intent(mService, Subscription.class);
-					intent.putExtra("from", from);
-					notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
-							+ from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
-					int id = packet.hashCode();
-					mService.sendNotification(id, notif);
-				}
-			}, filter);
-
-			final int n = mRemoteConnListeners.beginBroadcast();
-
-			for (int i = 0; i < n; i++) {
-				IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
-				try {
-					if (listener != null)
-						listener.reconnectionSuccessful();
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while triggering remote connection listeners", e);
-				}
-			}
-			mRemoteConnListeners.finishBroadcast();
+	    for (int i = 0; i < n; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.reconnectingIn(arg0);
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
 		}
+	    }
+	    mRemoteConnListeners.finishBroadcast();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void reconnectionFailed(Exception arg0) {
+	    Log.d(TAG, "reconnectionFailed");
+	    final int r = mRemoteConnListeners.beginBroadcast();
+
+	    for (int i = 0; i < r; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.reconnectionFailed();
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
+		}
+	    }
+	    mRemoteConnListeners.finishBroadcast();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void reconnectionSuccessful() {
+	    Log.d(TAG, "reconnectionSuccessful");
+	    PacketFilter filter = new PacketFilter() {
+
+		@Override
+		public boolean accept(Packet packet) {
+		    if (packet instanceof Presence) {
+			Presence pres = (Presence) packet;
+			if (pres.getType() == Presence.Type.subscribe)
+			    return true;
+		    }
+		    return false;
+		}
+	    };
+
+	    mAdaptee.addPacketListener(new PacketListener() {
+
+		@Override
+		public void processPacket(Packet packet) {
+		    String from = packet.getFrom();
+		    Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
+			.getString(R.string.AcceptContactRequest), System.currentTimeMillis());
+		    notif.defaults = Notification.DEFAULT_ALL;
+		    notif.flags = Notification.FLAG_AUTO_CANCEL;
+		    Intent intent = new Intent(mService, Subscription.class);
+		    intent.putExtra("from", from);
+		    notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
+			+ from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
+		    int id = packet.hashCode();
+		    mService.sendNotification(id, notif);
+		}
+	    }, filter);
+
+	    final int n = mRemoteConnListeners.beginBroadcast();
+
+	    for (int i = 0; i < n; i++) {
+		IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+		try {
+		    if (listener != null)
+			listener.reconnectionSuccessful();
+		} catch (RemoteException e) {
+		    // The RemoteCallbackList will take care of removing the
+		    // dead listeners.
+		    Log.w(TAG, "Error while triggering remote connection listeners", e);
+		}
+	    }
+	    mRemoteConnListeners.finishBroadcast();
+	}
+    }
+
 }
--- a/src/com/beem/project/beem/service/XmppFacade.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppFacade.java	Wed Nov 11 19:34:04 2009 +0100
@@ -21,133 +21,128 @@
 
 /**
  * This class is a facade for the Beem Service.
- * 
  * @author darisk
  */
 public class XmppFacade extends IXmppFacade.Stub {
 
-	private XmppConnectionAdapter mConnexion;
-	private BeemService mBeemService;
-	private JingleService mJingle;
+    private XmppConnectionAdapter mConnexion;
+    private BeemService mBeemService;
+    private JingleService mJingle;
 
-	/**
-	 * Constructor for XMPPFacade.
-	 * 
-	 * @param connection
-	 *            the connection use by the facade
-	 * @param service
-	 *            the service which holds the facade
-	 * @param jingle
-	 *            the jingle session
-	 */
-	public XmppFacade(final XmppConnectionAdapter connection, final BeemService service, final JingleService jingle) {
-		this.mConnexion = connection;
-		this.mBeemService = service;
-		this.mJingle = jingle;
-	}
+    /**
+     * Constructor for XMPPFacade.
+     * @param connection the connection use by the facade
+     * @param service the service which holds the facade
+     * @param jingle the jingle session
+     */
+    public XmppFacade(final XmppConnectionAdapter connection, final BeemService service, final JingleService jingle) {
+	this.mConnexion = connection;
+	this.mBeemService = service;
+	this.mJingle = jingle;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void changeStatus(int status, String msg) {
+	Presence pres = new Presence(Presence.Type.available);
+	if (msg != null)
+	    pres.setStatus(msg);
+	Presence.Mode mode = Status.getPresenceModeFromStatus(status);
+	if (mode != null)
+	    pres.setMode(mode);
+	mConnexion.getAdaptee().sendPacket(pres);
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void changeStatus(int status, String msg) {
-		Presence pres = new Presence(Presence.Type.available);
-		if (msg != null)
-			pres.setStatus(msg);
-		Presence.Mode mode = Status.getPresenceModeFromStatus(status);
-		if (mode != null)
-			pres.setMode(mode);
-		mConnexion.getAdaptee().sendPacket(pres);
+	Notification mStatusNotification;
+	String text = "";
+	if (msg != null)
+	    text = msg;
+	mStatusNotification = new Notification(com.beem.project.beem.R.drawable.beem_status_icon, text, System
+	    .currentTimeMillis());
+	mStatusNotification.defaults = Notification.DEFAULT_ALL;
+	mStatusNotification.flags = Notification.FLAG_NO_CLEAR;
+
+	mStatusNotification.setLatestEventInfo(mBeemService, "Beem Status", text, PendingIntent.getActivity(
+	    mBeemService, 0, new Intent(mBeemService, ChangeStatus.class), 0));
+	mBeemService.sendNotification(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
+    }
 
-		Notification mStatusNotification;
-		String text = "";
-		if (msg != null)
-			text = msg;
-		mStatusNotification = new Notification(com.beem.project.beem.R.drawable.beem_status_icon, text, System
-				.currentTimeMillis());
-		mStatusNotification.defaults = Notification.DEFAULT_ALL;
-		mStatusNotification.flags = Notification.FLAG_NO_CLEAR;
-
-		mStatusNotification.setLatestEventInfo(mBeemService, "Beem Status", text, PendingIntent.getActivity(
-				mBeemService, 0, new Intent(mBeemService, ChangeStatus.class), 0));
-		mBeemService.sendNotification(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void connectAsync() throws RemoteException {
+	mConnexion.connectAsync();
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void connectAsync() throws RemoteException {
-		mConnexion.connectAsync();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void connectSync() throws RemoteException {
-		mConnexion.connectSync();
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void connectSync() throws RemoteException {
+	mConnexion.connectSync();
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public IXmppConnection createConnection() throws RemoteException {
-		return mConnexion;
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IXmppConnection createConnection() throws RemoteException {
+	return mConnexion;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void disconnect() throws RemoteException {
+	mConnexion.disconnect();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IChatManager getChatManager() throws RemoteException {
+	return mConnexion.getChatManager();
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void disconnect() throws RemoteException {
-		mConnexion.disconnect();
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IRoster getRoster() throws RemoteException {
+	return mConnexion.getRoster();
+    }
+
+    @Override
+    public void sendPresencePacket(PresenceAdapter presence) throws RemoteException {
+	Presence presence2 = new Presence(PresenceType.getPresenceTypeFrom(presence.getType()));
+	presence2.setTo(presence.getTo());
+	mConnexion.getAdaptee().sendPacket(presence2);
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public IChatManager getChatManager() throws RemoteException {
-		return mConnexion.getChatManager();
-	}
+    @Override
+    public void blockUser(String jid) throws RemoteException {
+	mConnexion.getPrivacyList().addBlockedUser(jid);
+    }
+
+    @Override
+    public void call(String jid) throws RemoteException {
+	mJingle.call(jid);
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public IRoster getRoster() throws RemoteException {
-		return mConnexion.getRoster();
+    @Override
+    public byte[] getVcardAvatar(String jid) throws RemoteException {
+	VCard vcard = new VCard();
+
+	try {
+	    vcard.load(mConnexion.getAdaptee(), jid);
+	    return vcard.getAvatar();
+	} catch (XMPPException e) {
+	    e.printStackTrace();
 	}
-
-	@Override
-	public void sendPresencePacket(PresenceAdapter presence) throws RemoteException {
-		Presence presence2 = new Presence(PresenceType.getPresenceTypeFrom(presence.getType()));
-		presence2.setTo(presence.getTo());
-		mConnexion.getAdaptee().sendPacket(presence2);
-	}
-
-	@Override
-	public void blockUser(String jid) throws RemoteException {
-		mConnexion.getPrivacyList().addBlockedUser(jid);
-	}
-
-	@Override
-	public void call(String jid) throws RemoteException {
-		mJingle.call(jid);
-	}
-
-	@Override
-	public byte[] getVcardAvatar(String jid) throws RemoteException {
-		VCard vcard = new VCard();
-
-		try {
-			vcard.load(mConnexion.getAdaptee(), jid);
-			return vcard.getAvatar();
-		} catch (XMPPException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
+	return null;
+    }
 }
--- a/src/com/beem/project/beem/ui/AddContact.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/AddContact.java	Wed Nov 11 19:34:04 2009 +0100
@@ -26,153 +26,150 @@
 
 /**
  * This activity is used to add a contact.
- * 
  * @author nikita
  */
 public class AddContact extends Activity {
 
-	private static final Intent SERVICE_INTENT = new Intent();
-	private static final String TAG = "AddContact";
-	private final List<String> mGroup = new ArrayList<String>();
-	private IXmppFacade mXmppFacade;
-	private final ServiceConnection mServConn = new BeemServiceConnection();
-	private BeemBroadcastReceiver mReceiver;
+    private static final Intent SERVICE_INTENT = new Intent();
+    private static final String TAG = "AddContact";
+    private final List<String> mGroup = new ArrayList<String>();
+    private IXmppFacade mXmppFacade;
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private BeemBroadcastReceiver mReceiver;
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    /**
+     * Constructor.
+     */
+    public AddContact() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.addcontact);
+	Button ok = (Button) findViewById(R.id.addc_ok);
+	ok.setOnClickListener(mOkListener);
+	mReceiver = new BeemBroadcastReceiver(mServConn);
+    }
 
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    @Override
+    protected void onStart() {
+	super.onStart();
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onResume() {
+	super.onResume();
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	mReceiver.setBinded(true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onPause() {
+	super.onPause();
+	if (mReceiver.isBinded()) {
+	    unbindService(mServConn);
+	    mReceiver.setBinded(false);
 	}
+    }
+
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	this.unregisterReceiver(mReceiver);
+    }
+
+    /**
+     * The ServiceConnection used to connect to the Beem service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
 
 	/**
 	 * Constructor.
 	 */
-	public AddContact() {
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.addcontact);
-		Button ok = (Button) findViewById(R.id.addc_ok);
-		ok.setOnClickListener(mOkListener);
-		mReceiver = new BeemBroadcastReceiver(mServConn);
+	public BeemServiceConnection() {
 	}
 
 	@Override
-	protected void onStart() {
-		super.onStart();
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onResume() {
-		super.onResume();
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		mReceiver.setBinded(true);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onPause() {
-		super.onPause();
-		if (mReceiver.isBinded()) {
-			unbindService(mServConn);
-			mReceiver.setBinded(false);
-		}
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mReceiver.setBinded(true);
 	}
 
 	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		this.unregisterReceiver(mReceiver);
+	public void onServiceDisconnected(ComponentName name) {
+	    mXmppFacade = null;
 	}
-
-	/**
-	 * The ServiceConnection used to connect to the Beem service.
-	 */
-	private class BeemServiceConnection implements ServiceConnection {
-
-		/**
-		 * Constructor.
-		 */
-		public BeemServiceConnection() {
-		}
+    }
 
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-			mReceiver.setBinded(true);
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mXmppFacade = null;
-		}
-	}
+    /**
+     * Get the text of a widget.
+     * @param id the id of the widget.
+     * @return the text of the widget.
+     */
+    private String getWidgetText(int id) {
+	EditText widget = (EditText) this.findViewById(id);
+	return widget.getText().toString();
+    }
 
-	/**
-	 * Get the text of a widget.
-	 * 
-	 * @param id
-	 *            the id of the widget.
-	 * @return the text of the widget.
-	 */
-	private String getWidgetText(int id) {
-		EditText widget = (EditText) this.findViewById(id);
-		return widget.getText().toString();
-	}
-
-	private final OnClickListener mOkListener = new OnClickListener() {
+    private final OnClickListener mOkListener = new OnClickListener() {
 
-		public void onClick(View v) {
-			String login;
-			login = getWidgetText(R.id.addc_login);
-			if (login.length() == 0) {
-				Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
-				return;
-			}
-			boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login);
-			if (!isEmail) {
-				Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT)
-						.show();
-				return;
-			}
-			String alias;
-			alias = getWidgetText(R.id.addc_alias);
-			if (getWidgetText(R.id.addc_group).length() != 0)
-				mGroup.add(getWidgetText(R.id.addc_group));
-			try {
-				if (mXmppFacade != null) {
-					if (mXmppFacade.getRoster().getContact(login) != null)
-						mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups());
-					if (mXmppFacade.getRoster().getContact(login) != null) {
-						Toast.makeText(AddContact.this, getString(R.string.AddCContactAlready), Toast.LENGTH_SHORT)
-								.show();
-						return;
-					}
-					if (mXmppFacade.getRoster().addContact(login, alias, mGroup.toArray(new String[mGroup.size()])) == null) {
-						Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT)
-								.show();
-						return;
-					} else {
-						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();
-				Log.e(TAG, "Problem adding contact", e);
-			}
+	public void onClick(View v) {
+	    String login;
+	    login = getWidgetText(R.id.addc_login);
+	    if (login.length() == 0) {
+		Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
+		return;
+	    }
+	    boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login);
+	    if (!isEmail) {
+		Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT)
+		    .show();
+		return;
+	    }
+	    String alias;
+	    alias = getWidgetText(R.id.addc_alias);
+	    if (getWidgetText(R.id.addc_group).length() != 0)
+		mGroup.add(getWidgetText(R.id.addc_group));
+	    try {
+		if (mXmppFacade != null) {
+		    if (mXmppFacade.getRoster().getContact(login) != null)
+			mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups());
+		    if (mXmppFacade.getRoster().getContact(login) != null) {
+			Toast.makeText(AddContact.this, getString(R.string.AddCContactAlready), Toast.LENGTH_SHORT)
+			    .show();
+			return;
+		    }
+		    if (mXmppFacade.getRoster().addContact(login, alias, mGroup.toArray(new String[mGroup.size()])) == null) {
+			Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT)
+			    .show();
+			return;
+		    } else {
+			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();
+		Log.e(TAG, "Problem adding contact", e);
+	    }
 
-		}
-	};
+	}
+    };
 }
--- a/src/com/beem/project/beem/ui/ChangeStatus.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/ChangeStatus.java	Wed Nov 11 19:34:04 2009 +0100
@@ -28,211 +28,203 @@
 
 /**
  * This Activity is used to change the status.
- * 
  * @author nikita
  */
 public class ChangeStatus extends Activity {
 
-	private static final Intent SERVICE_INTENT = new Intent();
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
-	}
+    private static final Intent SERVICE_INTENT = new Intent();
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    private static final int AVAILABLE_FOR_CHAT_IDX = 0;
+    private static final int AVAILABLE_IDX = 1;
+    private static final int BUSY_IDX = 2;
+    private static final int AWAY_IDX = 3;
+    private static final int UNAVAILABLE_IDX = 4;
+    private static final int DISCONNECTED_IDX = 5;
+    private TextView mStatusText;
+    private Toast mToast;
+    private Button mOk;
+    private Button mClear;
+    private Spinner mSpinner;
+
+    private SharedPreferences mSettings;
+    private ArrayAdapter<CharSequence> mAdapter;
+    private IXmppFacade mXmppFacade;
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private final OnClickListener mOnClickOk = new MyOnClickListener();
+    private BeemBroadcastReceiver mReceiver;
+
+    /**
+     * Constructor.
+     */
+    public ChangeStatus() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+
+	setContentView(R.layout.changestatus);
+	mStatusText = (TextView) findViewById(R.id.ChangeStatusText);
+	mOk = (Button) findViewById(R.id.ChangeStatusOk);
+	mClear = (Button) findViewById(R.id.ChangeStatusClear);
+	mOk.setOnClickListener(mOnClickOk);
+	mClear.setOnClickListener(mOnClickOk);
+	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+
+	mSpinner = (Spinner) findViewById(R.id.ChangeStatusSpinner);
+	mAdapter = ArrayAdapter.createFromResource(this, R.array.status_types, android.R.layout.simple_spinner_item);
+	mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+	mSpinner.setAdapter(mAdapter);
+	mToast = Toast.makeText(this, R.string.ChangeStatusOk, Toast.LENGTH_LONG);
+	mReceiver = new BeemBroadcastReceiver(mServConn);
+	mStatusText.setText(getPreferenceString(R.string.PreferenceStatusText));
+	mSpinner.setSelection(getPreferenceStatusIndex());
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onResume() {
+	super.onResume();
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	mReceiver.setBinded(true);
+    }
 
-	private static final int AVAILABLE_FOR_CHAT_IDX = 0;
-	private static final int AVAILABLE_IDX = 1;
-	private static final int BUSY_IDX = 2;
-	private static final int AWAY_IDX = 3;
-	private static final int UNAVAILABLE_IDX = 4;
-	private static final int DISCONNECTED_IDX = 5;
-	private TextView mStatusText;
-	private Toast mToast;
-	private Button mOk;
-	private Button mClear;
-	private Spinner mSpinner;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onPause() {
+	super.onPause();
+	Log.d("TAG", "pause");
+	if (mReceiver.isBinded()) {
+	    unbindService(mServConn);
+	    mReceiver.setBinded(false);
+	}
+    }
+
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	this.unregisterReceiver(mReceiver);
+    }
+
+    /**
+     * Return the status index from status the settings.
+     * @return the status index from status the settings.
+     */
+    private int getPreferenceStatusIndex() {
+	return mSettings.getInt(getString(R.string.PreferenceStatus), 0);
+    }
 
-	private SharedPreferences mSettings;
-	private ArrayAdapter<CharSequence> mAdapter;
-	private IXmppFacade mXmppFacade;
-	private final ServiceConnection mServConn = new BeemServiceConnection();
-	private final OnClickListener mOnClickOk = new MyOnClickListener();
-	private BeemBroadcastReceiver mReceiver;
+    /**
+     * Return the status text from status the settings.
+     * @param id status text id.
+     * @return the status text from status the settings.
+     */
+    private String getPreferenceString(int id) {
+	return mSettings.getString(getString(id), "");
+    }
 
-	/**
-	 * Constructor.
-	 */
-	public ChangeStatus() {
+    /**
+     * convert status text to.
+     * @param item selected item text.
+     * @return item position in the array.
+     */
+    private int getStatusForService(String item) {
+	switch (mAdapter.getPosition(item)) {
+	    case ChangeStatus.DISCONNECTED_IDX:
+		return Status.CONTACT_STATUS_DISCONNECT;
+	    case ChangeStatus.AVAILABLE_FOR_CHAT_IDX:
+		return Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+	    case ChangeStatus.AVAILABLE_IDX:
+		return Status.CONTACT_STATUS_AVAILABLE;
+	    case ChangeStatus.AWAY_IDX:
+		return Status.CONTACT_STATUS_AWAY;
+	    case ChangeStatus.BUSY_IDX:
+		return Status.CONTACT_STATUS_BUSY;
+	    case ChangeStatus.UNAVAILABLE_IDX:
+		return Status.CONTACT_STATUS_UNAVAILABLE;
+	    default:
+		return Status.CONTACT_STATUS_AVAILABLE;
 	}
+    }
+
+    /**
+     * connection to service.
+     * @author nikita
+     */
+    private class BeemServiceConnection implements ServiceConnection {
 
 	/**
-	 * {@inheritDoc}
+	 * constructor.
 	 */
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-
-		setContentView(R.layout.changestatus);
-		mStatusText = (TextView) findViewById(R.id.ChangeStatusText);
-		mOk = (Button) findViewById(R.id.ChangeStatusOk);
-		mClear = (Button) findViewById(R.id.ChangeStatusClear);
-		mOk.setOnClickListener(mOnClickOk);
-		mClear.setOnClickListener(mOnClickOk);
-		mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-
-		mSpinner = (Spinner) findViewById(R.id.ChangeStatusSpinner);
-		mAdapter = ArrayAdapter.createFromResource(this, R.array.status_types, android.R.layout.simple_spinner_item);
-		mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-		mSpinner.setAdapter(mAdapter);
-		mToast = Toast.makeText(this, R.string.ChangeStatusOk, Toast.LENGTH_LONG);
-		mReceiver = new BeemBroadcastReceiver(mServConn);
-		mStatusText.setText(getPreferenceString(R.string.PreferenceStatusText));
-		mSpinner.setSelection(getPreferenceStatusIndex());
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onResume() {
-		super.onResume();
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		mReceiver.setBinded(true);
+	public BeemServiceConnection() {
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected void onPause() {
-		super.onPause();
-		Log.d("TAG", "pause");
-		if (mReceiver.isBinded()) {
-			unbindService(mServConn);
-			mReceiver.setBinded(false);
-		}
-	}
-
-	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		this.unregisterReceiver(mReceiver);
-	}
-
-	/**
-	 * Return the status index from status the settings.
-	 * 
-	 * @return the status index from status the settings.
-	 */
-	private int getPreferenceStatusIndex() {
-		return mSettings.getInt(getString(R.string.PreferenceStatus), 0);
-	}
-
-	/**
-	 * Return the status text from status the settings.
-	 * 
-	 * @param id
-	 *            status text id.
-	 * @return the status text from status the settings.
-	 */
-	private String getPreferenceString(int id) {
-		return mSettings.getString(getString(id), "");
-	}
-
-	/**
-	 * convert status text to.
-	 * 
-	 * @param item
-	 *            selected item text.
-	 * @return item position in the array.
-	 */
-	private int getStatusForService(String item) {
-		switch (mAdapter.getPosition(item)) {
-		case ChangeStatus.DISCONNECTED_IDX:
-			return Status.CONTACT_STATUS_DISCONNECT;
-		case ChangeStatus.AVAILABLE_FOR_CHAT_IDX:
-			return Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
-		case ChangeStatus.AVAILABLE_IDX:
-			return Status.CONTACT_STATUS_AVAILABLE;
-		case ChangeStatus.AWAY_IDX:
-			return Status.CONTACT_STATUS_AWAY;
-		case ChangeStatus.BUSY_IDX:
-			return Status.CONTACT_STATUS_BUSY;
-		case ChangeStatus.UNAVAILABLE_IDX:
-			return Status.CONTACT_STATUS_UNAVAILABLE;
-		default:
-			return Status.CONTACT_STATUS_AVAILABLE;
-		}
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
 	}
 
 	/**
-	 * connection to service.
-	 * 
-	 * @author nikita
+	 * {@inheritDoc}
 	 */
-	private class BeemServiceConnection implements ServiceConnection {
-
-		/**
-		 * constructor.
-		 */
-		public BeemServiceConnection() {
-		}
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    mXmppFacade = null;
+	}
+    }
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mXmppFacade = null;
-		}
-	}
+    /**
+     * User have clicked on ok.
+     * @author nikita
+     */
+    private class MyOnClickListener implements OnClickListener {
 
 	/**
-	 * User have clicked on ok.
-	 * 
-	 * @author nikita
+	 * constructor.
 	 */
-	private class MyOnClickListener implements OnClickListener {
-
-		/**
-		 * constructor.
-		 */
-		public MyOnClickListener() {
-		}
+	public MyOnClickListener() {
+	}
 
-		@Override
-		public void onClick(View v) {
-			if (v == mOk) {
-				if (!mStatusText.getText().toString().equals(getPreferenceString(R.string.PreferenceStatusText))
-						|| getPreferenceStatusIndex() != mSpinner.getSelectedItemPosition()) {
-					String msg = mStatusText.getText().toString();
-					int status = getStatusForService((String) mSpinner.getSelectedItem());
-					Editor edit = mSettings.edit();
-					edit.putString(getString(R.string.PreferenceStatusText), msg);
-					edit.putInt(getString(R.string.PreferenceStatus), mSpinner.getSelectedItemPosition());
-					edit.commit();
-					if (status == Status.CONTACT_STATUS_DISCONNECT) {
-						stopService(new Intent(ChangeStatus.this, BeemService.class));
-					} else {
-						try {
-							mXmppFacade.changeStatus(status, msg.toString());
-						} catch (RemoteException e) {
-							e.printStackTrace();
-						}
-						mToast.show();
-					}
-				}
-				ChangeStatus.this.finish();
-			} else if (v == mClear) {
-				mStatusText.setText(null);
+	@Override
+	public void onClick(View v) {
+	    if (v == mOk) {
+		if (!mStatusText.getText().toString().equals(getPreferenceString(R.string.PreferenceStatusText))
+		    || getPreferenceStatusIndex() != mSpinner.getSelectedItemPosition()) {
+		    String msg = mStatusText.getText().toString();
+		    int status = getStatusForService((String) mSpinner.getSelectedItem());
+		    Editor edit = mSettings.edit();
+		    edit.putString(getString(R.string.PreferenceStatusText), msg);
+		    edit.putInt(getString(R.string.PreferenceStatus), mSpinner.getSelectedItemPosition());
+		    edit.commit();
+		    if (status == Status.CONTACT_STATUS_DISCONNECT) {
+			stopService(new Intent(ChangeStatus.this, BeemService.class));
+		    } else {
+			try {
+			    mXmppFacade.changeStatus(status, msg.toString());
+			} catch (RemoteException e) {
+			    e.printStackTrace();
 			}
+			mToast.show();
+		    }
 		}
+		ChangeStatus.this.finish();
+	    } else if (v == mClear) {
+		mStatusText.setText(null);
+	    }
 	}
+    }
 }
--- a/src/com/beem/project/beem/ui/Chat.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/Chat.java	Wed Nov 11 19:34:04 2009 +0100
@@ -51,645 +51,632 @@
 
 public class Chat extends Activity implements OnKeyListener {
 
-	private static final String TAG = "Chat";
-	private static final Intent SERVICE_INTENT = new Intent();
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
-	}
-	private Handler mHandler = new Handler();
+    private static final String TAG = "Chat";
+    private static final Intent SERVICE_INTENT = new Intent();
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+    private Handler mHandler = new Handler();
+
+    private IRoster mRoster;
+    private Contact mContact;
+
+    private TextView mContactNameTextView;
+    private TextView mContactStatusMsgTextView;
+    private ImageView mContactStatusIcon;
+    private ListView mMessagesListView;
+    private EditText mInputField;
+    private Map<Integer, Bitmap> mStatusIconsMap = new HashMap<Integer, Bitmap>();
+
+    private List<MessageText> mListMessages = new ArrayList<MessageText>();
+
+    private IChat mChat;
+    private IChatManager mChatManager;
+    private IChatManagerListener mChatManagerListener;
+    private IMessageListener mMessageListener;
+    private MessagesListAdapter mMessagesListAdapter;
 
-	private IRoster mRoster;
-	private Contact mContact;
+    private final ServiceConnection mConn = new BeemServiceConnection();
+    private BeemBroadcastReceiver mBroadcastReceiver;
+
+    /**
+     * Constructor.
+     */
+    public Chat() {
+	super();
+    }
 
-	private TextView mContactNameTextView;
-	private TextView mContactStatusMsgTextView;
-	private ImageView mContactStatusIcon;
-	private ListView mMessagesListView;
-	private EditText mInputField;
-	private Map<Integer, Bitmap> mStatusIconsMap = new HashMap<Integer, Bitmap>();
+    /**
+     * {@inheritDoc}.
+     */
+    protected void onCreate(Bundle savedBundle) {
+	super.onCreate(savedBundle);
+
+	Log.v(TAG, "BEGIN onCreate.");
+	setContentView(R.layout.chat);
+	mMessagesListAdapter = new MessagesListAdapter(this);
+
+	mHandler = new Handler();
+
+	// Listeners
+	mMessageListener = new OnMessageListener();
+	mChatManagerListener = new OnChatManagerListener();
+
+	mBroadcastReceiver = new BeemBroadcastReceiver(mConn);
+	this.registerReceiver(mBroadcastReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
 
-	private List<MessageText> mListMessages = new ArrayList<MessageText>();
+	// UI
+	mContactNameTextView = (TextView) findViewById(R.id.chat_contact_name);
+	mContactStatusMsgTextView = (TextView) findViewById(R.id.chat_contact_status_msg);
+	mContactStatusIcon = (ImageView) findViewById(R.id.chat_contact_status_icon);
+	mMessagesListView = (ListView) findViewById(R.id.chat_messages);
+	mMessagesListView.setAdapter(mMessagesListAdapter);
+	mInputField = (EditText) findViewById(R.id.chat_input);
+	mInputField.setOnKeyListener(this);
 
-	private IChat mChat;
-	private IChatManager mChatManager;
-	private IChatManagerListener mChatManagerListener;
-	private IMessageListener mMessageListener;
-	private MessagesListAdapter mMessagesListAdapter;
+	prepareIconsStatus();
+
+	Log.v(TAG, "END onCreate.");
+    }
+
+    /**
+     * {@inheritDoc}.
+     */
+    protected void onDestroy() {
+	super.onDestroy();
 
-	private final ServiceConnection mConn = new BeemServiceConnection();
-	private BeemBroadcastReceiver mBroadcastReceiver;
+	Log.v(TAG, "BEGIN onDestroy.");
+	this.unregisterReceiver(mBroadcastReceiver);
+	if (mChatManager != null) {
+	    try {
+		mChatManager.removeChatCreationListener(mChatManagerListener);
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+	}
+	Log.v(TAG, "END onDestroy.");
+    }
+
+    /**
+     * {@inheritDoc}.
+     */
+    protected void onStart() {
+	super.onStart();
 
-	/**
-	 * Constructor.
-	 */
-	public Chat() {
-		super();
+	Log.v(TAG, "BEGIN onStart.");
+	bindService(new Intent(this, BeemService.class), mConn, BIND_AUTO_CREATE);
+	Log.v(TAG, "END onStart.");
+    }
+
+    /**
+     * {@inheritDoc}.
+     */
+    protected void onStop() {
+	super.onStop();
+
+	Log.v(TAG, "BEGIN onStop.");
+	if (mChat != null) {
+	    try {
+		mChat.setOpen(false);
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+	}
+	if (mBroadcastReceiver.isBinded()) {
+	    unbindService(mConn);
 	}
+	Log.v(TAG, "END onStop.");
+    }
 
-	/**
-	 * {@inheritDoc}.
-	 */
-	protected void onCreate(Bundle savedBundle) {
-		super.onCreate(savedBundle);
+    /**
+     * {@inheritDoc}.
+     */
+    protected void onResume() {
+	super.onResume();
+    }
+
+    /**
+     * {@inheritDoc}.
+     */
+    protected void onPause() {
+	super.onPause();
+    }
+
+    /**
+     * {@inheritDoc}.
+     */
+    protected void onNewIntent(Intent intent) {
+	super.onNewIntent(intent);
 
-		Log.v(TAG, "BEGIN onCreate.");
-		setContentView(R.layout.chat);
-		mMessagesListAdapter = new MessagesListAdapter(this);
+	Log.v(TAG, "BEGIN onNewIntent.");
+	try {
+	    changeCurrentChat((mContact = new Contact(intent.getData())));
+	} catch (RemoteException e) {
+	    Log.e(TAG, e.getMessage());
+	}
+	Log.v(TAG, "END onNewIntent.");
+    }
 
-		mHandler = new Handler();
+    /**
+     * {@inheritDoc}.
+     */
+    @Override
+    protected void onSaveInstanceState(Bundle savedInstanceState) {
+	// TODO
+	super.onSaveInstanceState(savedInstanceState);
+    }
 
-		// Listeners
-		mMessageListener = new OnMessageListener();
-		mChatManagerListener = new OnChatManagerListener();
+    /**
+     * {@inheritDoc}.
+     */
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+	super.onRestoreInstanceState(savedInstanceState);
+	// TODO
+    }
 
-		mBroadcastReceiver = new BeemBroadcastReceiver(mConn);
-		this.registerReceiver(mBroadcastReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    /**
+     * Change the displayed chat.
+     * @param contact
+     * @throws RemoteException
+     */
+    private void changeCurrentChat(Contact contact) throws RemoteException {
+	Log.v(TAG, "BEGIN changeCurrentChat.");
+	if (mChat != null)
+	    mChat.setOpen(false);
+	mChat = mChatManager.createChat(contact, mMessageListener);
+	mChat.setOpen(true);
+
+	mChatManager.deleteChatNotification(mChat);
+
+	mContact = mRoster.getContact(contact.getJID());
+	updateContactInformations();
+	updateContactStatusIcon();
+
+	playRegisteredTranscript();
+	Log.v(TAG, "END changeCurrentChat.");
+    }
+
+    /**
+     * Get all messages from the current chat and refresh the activity with them.
+     * @throws RemoteException
+     */
+    private void playRegisteredTranscript() throws RemoteException {
+	String fromBareJid = null;
+	String fromName = null;
+	List<Message> chatMessages = mChat.getMessages();
 
-		// UI
-		mContactNameTextView = (TextView) findViewById(R.id.chat_contact_name);
-		mContactStatusMsgTextView = (TextView) findViewById(R.id.chat_contact_status_msg);
-		mContactStatusIcon = (ImageView) findViewById(R.id.chat_contact_status_icon);
-		mMessagesListView = (ListView) findViewById(R.id.chat_messages);
-		mMessagesListView.setAdapter(mMessagesListAdapter);
-		mInputField = (EditText) findViewById(R.id.chat_input);
-		mInputField.setOnKeyListener(this);
+	Log.v(TAG, "BEGIN playRegisteredTranscript.");
+	mListMessages.clear();
+	if (chatMessages.size() > 0) {
+	    MessageText lastMessage = null;
+	    for (Message m : chatMessages) {
+		fromBareJid = StringUtils.parseBareAddress(m.getFrom());
+		fromName = mContact.getName();
+
+		if (fromBareJid == null) {
+		    fromBareJid = getString(R.string.chat_self);
+		    fromName = getString(R.string.chat_self);
+		}
+
+		if (lastMessage == null) {
+		    lastMessage = new MessageText(fromBareJid, fromName, m.getBody());
+		    continue;
+		}
 
-		prepareIconsStatus();
+		if (!lastMessage.getBareJid().equals(fromBareJid)) {
+		    mListMessages.add(lastMessage);
+		    lastMessage = new MessageText(fromBareJid, fromName, m.getBody());
+		} else
+		    lastMessage.setMessage(lastMessage.getMessage().concat("\n" + m.getBody()));
+	    }
+	    mListMessages.add(lastMessage);
+	}
+	mMessagesListAdapter.notifyDataSetChanged();
+	Log.v(TAG, "END playRegisteredTranscript.");
+    }
 
-		Log.v(TAG, "END onCreate.");
-	}
+    /**
+     * @author Jamu
+     */
+    private final class BeemServiceConnection implements ServiceConnection {
+
+	private IXmppFacade mXmppFacade;
+	private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
 
 	/**
 	 * {@inheritDoc}.
 	 */
-	protected void onDestroy() {
-		super.onDestroy();
-
-		Log.v(TAG, "BEGIN onDestroy.");
-		this.unregisterReceiver(mBroadcastReceiver);
-		if (mChatManager != null) {
-			try {
-				mChatManager.removeChatCreationListener(mChatManagerListener);
-			} catch (RemoteException e) {
-				Log.e(TAG, e.getMessage());
-			}
-		}
-		Log.v(TAG, "END onDestroy.");
-	}
-
-	/**
-	 * {@inheritDoc}.
-	 */
-	protected void onStart() {
-		super.onStart();
-
-		Log.v(TAG, "BEGIN onStart.");
-		bindService(new Intent(this, BeemService.class), mConn, BIND_AUTO_CREATE);
-		Log.v(TAG, "END onStart.");
-	}
-
-	/**
-	 * {@inheritDoc}.
-	 */
-	protected void onStop() {
-		super.onStop();
-
-		Log.v(TAG, "BEGIN onStop.");
-		if (mChat != null) {
-			try {
-				mChat.setOpen(false);
-			} catch (RemoteException e) {
-				Log.e(TAG, e.getMessage());
-			}
-		}
-		if (mBroadcastReceiver.isBinded()) {
-			unbindService(mConn);
-		}
-		Log.v(TAG, "END onStop.");
-	}
-
-	/**
-	 * {@inheritDoc}.
-	 */
-	protected void onResume() {
-		super.onResume();
-	}
-
-	/**
-	 * {@inheritDoc}.
-	 */
-	protected void onPause() {
-		super.onPause();
-	}
-
-	/**
-	 * {@inheritDoc}.
-	 */
-	protected void onNewIntent(Intent intent) {
-		super.onNewIntent(intent);
-
-		Log.v(TAG, "BEGIN onNewIntent.");
-		try {
-			changeCurrentChat((mContact = new Contact(intent.getData())));
-		} catch (RemoteException e) {
-			Log.e(TAG, e.getMessage());
-		}
-		Log.v(TAG, "END onNewIntent.");
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    Log.v(TAG, "BEGIN onServiceConnected.");
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mBroadcastReceiver.setBinded(true);
+	    try {
+		mChatManager = mXmppFacade.getChatManager();
+		mRoster = mXmppFacade.getRoster();
+		mRoster.addRosterListener(mBeemRosterListener);
+		changeCurrentChat((mContact = new Contact(getIntent().getData())));
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+	    Log.v(TAG, "END onServiceConnected.");
 	}
 
 	/**
 	 * {@inheritDoc}.
 	 */
 	@Override
-	protected void onSaveInstanceState(Bundle savedInstanceState) {
-		// TODO
-		super.onSaveInstanceState(savedInstanceState);
+	public void onServiceDisconnected(ComponentName name) {
+	    Log.v(TAG, "BEGIN onServiceDisconnected.");
+	    mXmppFacade = null;
+	    mBroadcastReceiver.setBinded(false);
+	    try {
+		mRoster.removeRosterListener(mBeemRosterListener);
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+	    Log.v(TAG, "END onServiceDisconnected.");
+	}
+    }
+
+    /**
+     * @author Jamu
+     */
+    private class BeemRosterListener extends IBeemRosterListener.Stub {
+
+	/**
+	 * {@inheritDoc}.
+	 */
+	@Override
+	public void onEntriesAdded(List<String> addresses) throws RemoteException {
+	    Log.v(TAG, "BEGIN onEntriesAdded.");
+	    Log.v(TAG, "END onEntriesAdded.");
+	}
+
+	/**
+	 * {@inheritDoc}.
+	 */
+	@Override
+	public void onEntriesDeleted(List<String> addresses) throws RemoteException {
+	    Log.v(TAG, "BEGIN onEntriesDeleted.");
+	    Log.v(TAG, "END onEntriesDeleted.");
+	}
+
+	/**
+	 * {@inheritDoc}.
+	 */
+	@Override
+	public void onEntriesUpdated(List<String> addresses) throws RemoteException {
+	    Log.v(TAG, "BEGIN onEntriesUpdated.");
+	    Log.v(TAG, "END onEntriesUpdated.");
+	}
+
+	/**
+	 * {@inheritDoc}.
+	 */
+	@Override
+	public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
+	    Log.v(TAG, "BEGIN onEntryDeleteFromGroup.");
+	    Log.v(TAG, "END onEntryDeleteFromGroup.");
 	}
 
 	/**
 	 * {@inheritDoc}.
 	 */
 	@Override
-	protected void onRestoreInstanceState(Bundle savedInstanceState) {
-		super.onRestoreInstanceState(savedInstanceState);
-		// TODO
-	}
+	public void onPresenceChanged(final PresenceAdapter presence) throws RemoteException {
+	    Log.v(TAG, "BEGIN onPresenceChanged.");
+	    if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
+		mHandler.post(new Runnable() {
+		    @Override
+		    public void run() {
+			mContact.setStatus(presence.getStatus());
+			mContact.setMsgState(presence.getStatusText());
 
-	/**
-	 * Change the displayed chat.
-	 * 
-	 * @param contact
-	 * @throws RemoteException
-	 */
-	private void changeCurrentChat(Contact contact) throws RemoteException {
-		Log.v(TAG, "BEGIN changeCurrentChat.");
-		if (mChat != null)
-			mChat.setOpen(false);
-		mChat = mChatManager.createChat(contact, mMessageListener);
-		mChat.setOpen(true);
+			updateContactInformations();
+			updateContactStatusIcon();
+		    }
+		});
+	    }
+	    Log.v(TAG, "END onPresenceChanged.");
+	}
+    }
 
-		mChatManager.deleteChatNotification(mChat);
-
-		mContact = mRoster.getContact(contact.getJID());
-		updateContactInformations();
-		updateContactStatusIcon();
-
-		playRegisteredTranscript();
-		Log.v(TAG, "END changeCurrentChat.");
-	}
+    /**
+     * @author Jamu
+     */
+    private class OnMessageListener extends IMessageListener.Stub {
 
 	/**
-	 * Get all messages from the current chat and refresh the activity with
-	 * them.
-	 * 
-	 * @throws RemoteException
+	 * {@inheritDoc}.
 	 */
-	private void playRegisteredTranscript() throws RemoteException {
-		String fromBareJid = null;
-		String fromName = null;
-		List<Message> chatMessages = mChat.getMessages();
+	@Override
+	public void processMessage(IChat chat, final Message msg) throws RemoteException {
+	    Log.v(TAG, "BEGIN processMessage.");
 
-		Log.v(TAG, "BEGIN playRegisteredTranscript.");
-		mListMessages.clear();
-		if (chatMessages.size() > 0) {
-			MessageText lastMessage = null;
-			for (Message m : chatMessages) {
-				fromBareJid = StringUtils.parseBareAddress(m.getFrom());
-				fromName = mContact.getName();
+	    final String fromBareJid = StringUtils.parseBareAddress(msg.getFrom());
+
+	    if (mContact.getJID().equals(fromBareJid)) {
+		mHandler.post(new Runnable() {
 
-				if (fromBareJid == null) {
-					fromBareJid = getString(R.string.chat_self);
-					fromName = getString(R.string.chat_self);
-				}
-
-				if (lastMessage == null) {
-					lastMessage = new MessageText(fromBareJid, fromName, m.getBody());
-					continue;
-				}
+		    /**
+		     * {@inheritDoc}.
+		     */
+		    @Override
+		    public void run() {
+			if (msg.getBody() != null && msg.getType() != Message.MSG_TYPE_ERROR) {
+			    MessageText lastMessage = mListMessages.size() != 0 ? mListMessages.get(mListMessages
+				.size() - 1) : null;
 
-				if (!lastMessage.getBareJid().equals(fromBareJid)) {
-					mListMessages.add(lastMessage);
-					lastMessage = new MessageText(fromBareJid, fromName, m.getBody());
-				} else
-					lastMessage.setMessage(lastMessage.getMessage().concat("\n" + m.getBody()));
+			    if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid)) {
+				lastMessage.setMessage(lastMessage.getMessage().concat("\n" + msg.getBody()));
+				mListMessages.set(mListMessages.size() - 1, lastMessage);
+			    } else
+				mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody()));
+			    mMessagesListAdapter.notifyDataSetChanged();
 			}
-			mListMessages.add(lastMessage);
-		}
-		mMessagesListAdapter.notifyDataSetChanged();
-		Log.v(TAG, "END playRegisteredTranscript.");
+		    }
+		});
+	    }
+	    Log.v(TAG, "END processMessage.");
 	}
 
 	/**
-	 * 
-	 * @author Jamu
-	 * 
-	 */
-	private final class BeemServiceConnection implements ServiceConnection {
-
-		private IXmppFacade mXmppFacade;
-		private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			Log.v(TAG, "BEGIN onServiceConnected.");
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-			mBroadcastReceiver.setBinded(true);
-			try {
-				mChatManager = mXmppFacade.getChatManager();
-				mRoster = mXmppFacade.getRoster();
-				mRoster.addRosterListener(mBeemRosterListener);
-				changeCurrentChat((mContact = new Contact(getIntent().getData())));
-			} catch (RemoteException e) {
-				Log.e(TAG, e.getMessage());
-			}
-			Log.v(TAG, "END onServiceConnected.");
-		}
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			Log.v(TAG, "BEGIN onServiceDisconnected.");
-			mXmppFacade = null;
-			mBroadcastReceiver.setBinded(false);
-			try {
-				mRoster.removeRosterListener(mBeemRosterListener);
-			} catch (RemoteException e) {
-				Log.e(TAG, e.getMessage());
-			}
-			Log.v(TAG, "END onServiceDisconnected.");
-		}
-	}
-
-	/**
-	 * 
-	 * @author Jamu
-	 * 
+	 * {@inheritDoc}.
 	 */
-	private class BeemRosterListener extends IBeemRosterListener.Stub {
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void onEntriesAdded(List<String> addresses) throws RemoteException {
-			Log.v(TAG, "BEGIN onEntriesAdded.");
-			Log.v(TAG, "END onEntriesAdded.");
-		}
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void onEntriesDeleted(List<String> addresses) throws RemoteException {
-			Log.v(TAG, "BEGIN onEntriesDeleted.");
-			Log.v(TAG, "END onEntriesDeleted.");
-		}
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void onEntriesUpdated(List<String> addresses) throws RemoteException {
-			Log.v(TAG, "BEGIN onEntriesUpdated.");
-			Log.v(TAG, "END onEntriesUpdated.");
-		}
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
-			Log.v(TAG, "BEGIN onEntryDeleteFromGroup.");
-			Log.v(TAG, "END onEntryDeleteFromGroup.");
-		}
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void onPresenceChanged(final PresenceAdapter presence) throws RemoteException {
-			Log.v(TAG, "BEGIN onPresenceChanged.");
-			if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
-				mHandler.post(new Runnable() {
-					@Override
-					public void run() {
-						mContact.setStatus(presence.getStatus());
-						mContact.setMsgState(presence.getStatusText());
-
-						updateContactInformations();
-						updateContactStatusIcon();
-					}
-				});
-			}
-			Log.v(TAG, "END onPresenceChanged.");
-		}
-	}
-
-	/**
-	 * 
-	 * @author Jamu
-	 * 
-	 */
-	private class OnMessageListener extends IMessageListener.Stub {
+	@Override
+	public void stateChanged(IChat chat) throws RemoteException {
+	    Log.v(TAG, "BEGIN stateChanged.");
+	    mHandler.post(new Runnable() {
 
 		/**
 		 * {@inheritDoc}.
 		 */
 		@Override
-		public void processMessage(IChat chat, final Message msg) throws RemoteException {
-			Log.v(TAG, "BEGIN processMessage.");
-
-			final String fromBareJid = StringUtils.parseBareAddress(msg.getFrom());
-
-			if (mContact.getJID().equals(fromBareJid)) {
-				mHandler.post(new Runnable() {
-
-					/**
-					 * {@inheritDoc}.
-					 */
-					@Override
-					public void run() {
-						if (msg.getBody() != null && msg.getType() != Message.MSG_TYPE_ERROR) {
-							MessageText lastMessage = mListMessages.size() != 0 ? mListMessages.get(mListMessages
-									.size() - 1) : null;
-
-							if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid)) {
-								lastMessage.setMessage(lastMessage.getMessage().concat("\n" + msg.getBody()));
-								mListMessages.set(mListMessages.size() - 1, lastMessage);
-							} else
-								mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody()));
-							mMessagesListAdapter.notifyDataSetChanged();
-						}
-					}
-				});
-			}
-			Log.v(TAG, "END processMessage.");
+		public void run() {
 		}
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void stateChanged(IChat chat) throws RemoteException {
-			Log.v(TAG, "BEGIN stateChanged.");
-			mHandler.post(new Runnable() {
-
-				/**
-				 * {@inheritDoc}.
-				 */
-				@Override
-				public void run() {
-				}
-			});
-			Log.v(TAG, "END stateChanged.");
-		}
+	    });
+	    Log.v(TAG, "END stateChanged.");
 	}
-
-	/**
-	 * 
-	 * @author Jamu
-	 * 
-	 */
-	private class OnChatManagerListener extends IChatManagerListener.Stub {
-		/**
-		 * Constructor.
-		 */
-		public OnChatManagerListener() {
-			Log.v(TAG, "OnChatManagerListener constructor.");
-		}
-
-		/**
-		 * {@inheritDoc}.
-		 */
-		@Override
-		public void chatCreated(IChat chat, boolean locally) throws RemoteException {
-			Log.i(TAG, "Chat has been created.");
-		}
-	}
-
-	/**
-	 * Update the contact informations.
-	 * 
-	 */
-	private void updateContactInformations() {
-		Log.v(TAG, "BEGIN updateContactInformations.");
-		// Check for a contact name update
-		if (!(mContactNameTextView.getText().toString().equals(mContact.getName())))
-			mContactNameTextView.setText(mContact.getName());
-
-		// Check for a contact status message update
-		if (!(mContactStatusMsgTextView.getText().toString().equals(mContact.getMsgState()))) {
-			Log.d(TAG, "Setting status message - " + mContact.getMsgState());
-			mContactStatusMsgTextView.setText(mContact.getMsgState());
-			Linkify.addLinks(mContactStatusMsgTextView, Linkify.WEB_URLS);
-		}
-		Log.v(TAG, "END updateContactInformations.");
-	}
-
-	/**
-	 * Update the contact status icon.
-	 */
-	private void updateContactStatusIcon() {
-		Log.v(TAG, "BEGIN updateContactStatusIcon.");
-		mContactStatusIcon.setImageBitmap(mStatusIconsMap.get(mContact.getStatus()));
-		Log.v(TAG, "END updateContactStatusIcon.");
-	}
-
-	/**
-	 * Prepare the status icons map.
-	 */
-	private void prepareIconsStatus() {
-		mStatusIconsMap.put(Status.CONTACT_STATUS_AVAILABLE, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_available));
-		mStatusIconsMap.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_available));
-		mStatusIconsMap.put(Status.CONTACT_STATUS_AWAY, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_away));
-		mStatusIconsMap.put(Status.CONTACT_STATUS_BUSY, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_dnd));
-		mStatusIconsMap.put(Status.CONTACT_STATUS_DISCONNECT, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_offline));
-		mStatusIconsMap.put(Status.CONTACT_STATUS_UNAVAILABLE, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_requested));
-	}
-
-	private class MessagesListAdapter extends BaseAdapter {
-
-		private Context mContext;
+    }
 
-		public MessagesListAdapter(Context context) {
-			mContext = context;
-		}
-
-		public int getCount() {
-			return mListMessages.size();
-		}
-
-		public Object getItem(int position) {
-			return position;
-		}
-
-		public long getItemId(int position) {
-			return position;
-		}
-
-		public View getView(int position, View convertView, ViewGroup parent) {
-			MessageView sv;
-			if (convertView == null) {
-				sv = new MessageView(mContext, mListMessages.get(position).getName(), mListMessages.get(position)
-						.getMessage());
-			} else {
-				sv = (MessageView) convertView;
-				sv.setName(mListMessages.get(position).getName());
-				sv.setMessage(mListMessages.get(position).getMessage());
-			}
-
-			sv.setPadding(2, 2, 2, 4);
-
-			sv.mName.setTextSize(16);
-			sv.mName.setTextColor(Color.WHITE);
-			sv.mName.setTypeface(Typeface.DEFAULT_BOLD);
-
-			sv.mMessage.setLinkTextColor(Color.WHITE);
-			sv.mMessage.setPadding(0, 4, 0, 4);
-			Linkify.addLinks(sv.mMessage, Linkify.WEB_URLS);
-
-			return sv;
-		}
-	}
-
-	private class MessageText {
-		private String mBareJid;
-		private String mName;
-		private String mMessage;
-
-		public MessageText(String bareJid, String name, String message) {
-			mBareJid = bareJid;
-			mName = name;
-			mMessage = message;
-		}
-
-		public String getBareJid() {
-			return mBareJid;
-		}
-
-		public String getName() {
-			return mName;
-		}
-
-		public String getMessage() {
-			return mMessage;
-		}
-
-		@SuppressWarnings("unused")
-		public void setBareJid(String bareJid) {
-			mBareJid = bareJid;
-		}
-
-		@SuppressWarnings("unused")
-		public void setName(String name) {
-			mName = name;
-		}
-
-		public void setMessage(String message) {
-			mMessage = message;
-		}
-	}
-
+    /**
+     * @author Jamu
+     */
+    private class OnChatManagerListener extends IChatManagerListener.Stub {
 	/**
-	 * We will use a MessageView to display each message.
+	 * Constructor.
 	 */
-	private class MessageView extends LinearLayout {
-		private TextView mName;
-		private TextView mMessage;
-
-		/**
-		 * Constructor.
-		 * 
-		 * @param context
-		 * @param name
-		 * @param message
-		 */
-		public MessageView(Context context, String name, String message) {
-			super(context);
-
-			this.setOrientation(VERTICAL);
-
-			mName = new TextView(context);
-			mName.setText(name);
-			addView(mName, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
-
-			mMessage = new TextView(context);
-			mMessage.setText(message);
-			addView(mMessage, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
-		}
-
-		/**
-		 * Convenience method to set the title of a MessageView
-		 */
-		public void setName(String name) {
-			mName.setText(name);
-		}
-
-		/**
-		 * Convenience method to set the dialogue of a MessageView
-		 */
-		public void setMessage(String message) {
-			mMessage.setText(message);
-		}
+	public OnChatManagerListener() {
+	    Log.v(TAG, "OnChatManagerListener constructor.");
 	}
 
 	/**
 	 * {@inheritDoc}.
 	 */
 	@Override
-	public boolean onKey(View v, int keyCode, KeyEvent event) {
-		Log.d(TAG, "KeyEvent = " + event.getAction());
-		if (event.getAction() == KeyEvent.ACTION_DOWN) {
-			switch (keyCode) {
-			case KeyEvent.KEYCODE_ENTER:
-				sendMessage();
-				return true;
-			default:
-				return false;
-			}
-		}
-		return false;
+	public void chatCreated(IChat chat, boolean locally) throws RemoteException {
+	    Log.i(TAG, "Chat has been created.");
+	}
+    }
+
+    /**
+     * Update the contact informations.
+     */
+    private void updateContactInformations() {
+	Log.v(TAG, "BEGIN updateContactInformations.");
+	// Check for a contact name update
+	if (!(mContactNameTextView.getText().toString().equals(mContact.getName())))
+	    mContactNameTextView.setText(mContact.getName());
+
+	// Check for a contact status message update
+	if (!(mContactStatusMsgTextView.getText().toString().equals(mContact.getMsgState()))) {
+	    Log.d(TAG, "Setting status message - " + mContact.getMsgState());
+	    mContactStatusMsgTextView.setText(mContact.getMsgState());
+	    Linkify.addLinks(mContactStatusMsgTextView, Linkify.WEB_URLS);
+	}
+	Log.v(TAG, "END updateContactInformations.");
+    }
+
+    /**
+     * Update the contact status icon.
+     */
+    private void updateContactStatusIcon() {
+	Log.v(TAG, "BEGIN updateContactStatusIcon.");
+	mContactStatusIcon.setImageBitmap(mStatusIconsMap.get(mContact.getStatus()));
+	Log.v(TAG, "END updateContactStatusIcon.");
+    }
+
+    /**
+     * Prepare the status icons map.
+     */
+    private void prepareIconsStatus() {
+	mStatusIconsMap.put(Status.CONTACT_STATUS_AVAILABLE, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_available));
+	mStatusIconsMap.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_available));
+	mStatusIconsMap.put(Status.CONTACT_STATUS_AWAY, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_away));
+	mStatusIconsMap.put(Status.CONTACT_STATUS_BUSY, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_dnd));
+	mStatusIconsMap.put(Status.CONTACT_STATUS_DISCONNECT, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_offline));
+	mStatusIconsMap.put(Status.CONTACT_STATUS_UNAVAILABLE, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_requested));
+    }
+
+    private class MessagesListAdapter extends BaseAdapter {
+
+	private Context mContext;
+
+	public MessagesListAdapter(Context context) {
+	    mContext = context;
+	}
+
+	public int getCount() {
+	    return mListMessages.size();
+	}
+
+	public Object getItem(int position) {
+	    return position;
+	}
+
+	public long getItemId(int position) {
+	    return position;
+	}
+
+	public View getView(int position, View convertView, ViewGroup parent) {
+	    MessageView sv;
+	    if (convertView == null) {
+		sv = new MessageView(mContext, mListMessages.get(position).getName(), mListMessages.get(position)
+		    .getMessage());
+	    } else {
+		sv = (MessageView) convertView;
+		sv.setName(mListMessages.get(position).getName());
+		sv.setMessage(mListMessages.get(position).getMessage());
+	    }
+
+	    sv.setPadding(2, 2, 2, 4);
+
+	    sv.mName.setTextSize(16);
+	    sv.mName.setTextColor(Color.WHITE);
+	    sv.mName.setTypeface(Typeface.DEFAULT_BOLD);
+
+	    sv.mMessage.setLinkTextColor(Color.WHITE);
+	    sv.mMessage.setPadding(0, 4, 0, 4);
+	    Linkify.addLinks(sv.mMessage, Linkify.WEB_URLS);
+
+	    return sv;
+	}
+    }
+
+    private class MessageText {
+	private String mBareJid;
+	private String mName;
+	private String mMessage;
+
+	public MessageText(String bareJid, String name, String message) {
+	    mBareJid = bareJid;
+	    mName = name;
+	    mMessage = message;
+	}
+
+	public String getBareJid() {
+	    return mBareJid;
+	}
+
+	public String getName() {
+	    return mName;
+	}
+
+	public String getMessage() {
+	    return mMessage;
+	}
+
+	@SuppressWarnings("unused")
+	public void setBareJid(String bareJid) {
+	    mBareJid = bareJid;
+	}
+
+	@SuppressWarnings("unused")
+	public void setName(String name) {
+	    mName = name;
+	}
+
+	public void setMessage(String message) {
+	    mMessage = message;
+	}
+    }
+
+    /**
+     * We will use a MessageView to display each message.
+     */
+    private class MessageView extends LinearLayout {
+	private TextView mName;
+	private TextView mMessage;
+
+	/**
+	 * Constructor.
+	 * @param context
+	 * @param name
+	 * @param message
+	 */
+	public MessageView(Context context, String name, String message) {
+	    super(context);
+
+	    this.setOrientation(VERTICAL);
+
+	    mName = new TextView(context);
+	    mName.setText(name);
+	    addView(mName, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
+
+	    mMessage = new TextView(context);
+	    mMessage.setText(message);
+	    addView(mMessage, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
 	}
 
 	/**
-	 * Send an xmpp message.
+	 * Convenience method to set the title of a MessageView
 	 */
-	private void sendMessage() {
-		final String inputContent = mInputField.getText().toString();
+	public void setName(String name) {
+	    mName.setText(name);
+	}
+
+	/**
+	 * Convenience method to set the dialogue of a MessageView
+	 */
+	public void setMessage(String message) {
+	    mMessage.setText(message);
+	}
+    }
 
-		Log.v(TAG, "BEGIN sendMessage.");
-		if (!inputContent.equals("")) {
-			Message msgToSend = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
-			msgToSend.setBody(inputContent);
+    /**
+     * {@inheritDoc}.
+     */
+    @Override
+    public boolean onKey(View v, int keyCode, KeyEvent event) {
+	Log.d(TAG, "KeyEvent = " + event.getAction());
+	if (event.getAction() == KeyEvent.ACTION_DOWN) {
+	    switch (keyCode) {
+		case KeyEvent.KEYCODE_ENTER:
+		    sendMessage();
+		    return true;
+		default:
+		    return false;
+	    }
+	}
+	return false;
+    }
 
-			try {
-				mChat.sendMessage(msgToSend);
-			} catch (RemoteException e) {
-				Log.e(TAG, e.getMessage());
-			}
+    /**
+     * Send an xmpp message.
+     */
+    private void sendMessage() {
+	final String inputContent = mInputField.getText().toString();
 
-			final String self = getString(R.string.chat_self);
-			MessageText lastMessage = mListMessages.size() != 0 ? mListMessages.get(mListMessages.size() - 1) : null;
+	Log.v(TAG, "BEGIN sendMessage.");
+	if (!inputContent.equals("")) {
+	    Message msgToSend = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
+	    msgToSend.setBody(inputContent);
 
-			if (lastMessage != null && lastMessage.getName().equals(self)) {
-				lastMessage.setMessage(lastMessage.getMessage().concat("\n" + inputContent));
-				mListMessages.set(mListMessages.size() - 1, lastMessage);
-			} else
-				mListMessages.add(new MessageText(self, self, inputContent));
-			mMessagesListAdapter.notifyDataSetChanged();
-			mInputField.setText(null);
-		}
-		Log.v(TAG, "END sendMessage.");
+	    try {
+		mChat.sendMessage(msgToSend);
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+
+	    final String self = getString(R.string.chat_self);
+	    MessageText lastMessage = mListMessages.size() != 0 ? mListMessages.get(mListMessages.size() - 1) : null;
+
+	    if (lastMessage != null && lastMessage.getName().equals(self)) {
+		lastMessage.setMessage(lastMessage.getMessage().concat("\n" + inputContent));
+		mListMessages.set(mListMessages.size() - 1, lastMessage);
+	    } else
+		mListMessages.add(new MessageText(self, self, inputContent));
+	    mMessagesListAdapter.notifyDataSetChanged();
+	    mInputField.setText(null);
 	}
+	Log.v(TAG, "END sendMessage.");
+    }
 }
--- a/src/com/beem/project/beem/ui/ContactDialog.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactDialog.java	Wed Nov 11 19:34:04 2009 +0100
@@ -18,142 +18,137 @@
 import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
- * This activity class provides the view to show dialog when long click on
- * contact list.
- * 
+ * This activity class provides the view to show dialog when long click on contact list.
  * @author marseille
  */
 public class ContactDialog extends Dialog {
 
-	private static final Intent SERVICE_INTENT = new Intent();
-	private final Contact mContact;
-	private final Context mContext;
-	private IXmppFacade mXmppFacade;
-	private final ServiceConnection mServConn = new BeemServiceConnection();
+    private static final Intent SERVICE_INTENT = new Intent();
+    private final Contact mContact;
+    private final Context mContext;
+    private IXmppFacade mXmppFacade;
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    /**
+     * Constructor.
+     * @param context context where is call the dialog.
+     * @param curContact current contact.
+     */
+    public ContactDialog(final Context context, final Contact curContact) {
+	super(context);
+	mContext = context;
 
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
-	}
+	setContentView(R.layout.contactdialog);
+	mContact = curContact;
+	setTitle(curContact.getJID());
+
+	Button button = (Button) findViewById(R.id.CDChat);
+	button.setOnClickListener(new ChatListener());
+	button = (Button) findViewById(R.id.CDInfos);
+	button.setOnClickListener(new InfosListener());
+	button = (Button) findViewById(R.id.CDCall);
+	button.setOnClickListener(new CallListener());
+	mContext.bindService(SERVICE_INTENT, mServConn, Service.BIND_AUTO_CREATE);
+    }
+
+    @Override
+    public void dismiss() {
+	super.dismiss();
+	mContext.unbindService(mServConn);
+    }
+
+    /**
+     * Event simple click on call button.
+     */
+    class CallListener implements View.OnClickListener {
 
 	/**
 	 * Constructor.
-	 * 
-	 * @param context
-	 *            context where is call the dialog.
-	 * @param curContact
-	 *            current contact.
 	 */
-	public ContactDialog(final Context context, final Contact curContact) {
-		super(context);
-		mContext = context;
-
-		setContentView(R.layout.contactdialog);
-		mContact = curContact;
-		setTitle(curContact.getJID());
-
-		Button button = (Button) findViewById(R.id.CDChat);
-		button.setOnClickListener(new ChatListener());
-		button = (Button) findViewById(R.id.CDInfos);
-		button.setOnClickListener(new InfosListener());
-		button = (Button) findViewById(R.id.CDCall);
-		button.setOnClickListener(new CallListener());
-		mContext.bindService(SERVICE_INTENT, mServConn, Service.BIND_AUTO_CREATE);
+	public CallListener() {
 	}
 
 	@Override
-	public void dismiss() {
-		super.dismiss();
-		mContext.unbindService(mServConn);
+	public void onClick(View v) {
+	    try {
+		// TODO permettre a l'user de choisir a quel ressource il veut
+		// faire le call.
+		mXmppFacade.call(mContact.getJID() + "/psi");
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
 	}
+    }
+
+    /**
+     * Event simple click on chat button.
+     */
+    class ChatListener implements View.OnClickListener {
 
 	/**
-	 * Event simple click on call button.
+	 * Constructor.
 	 */
-	class CallListener implements View.OnClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public CallListener() {
-		}
+	public ChatListener() {
+	}
 
-		@Override
-		public void onClick(View v) {
-			try {
-				// TODO permettre a l'user de choisir a quel ressource il veut
-				// faire le call.
-				mXmppFacade.call(mContact.getJID() + "/psi");
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-		}
+	@Override
+	public void onClick(View v) {
+	    Activity a = ContactDialog.this.getOwnerActivity();
+	    Intent i = new Intent(mContext, Chat.class);
+	    i.setData(mContact.toUri());
+	    a.startActivity(i);
+	    dismiss();
 	}
 
+    }
+
+    /**
+     * Event simple click on info button.
+     */
+    class InfosListener implements View.OnClickListener {
+
 	/**
-	 * Event simple click on chat button.
+	 * Constructor.
 	 */
-	class ChatListener implements View.OnClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public ChatListener() {
-		}
+	public InfosListener() {
+	}
 
-		@Override
-		public void onClick(View v) {
-			Activity a = ContactDialog.this.getOwnerActivity();
-			Intent i = new Intent(mContext, Chat.class);
-			i.setData(mContact.toUri());
-			a.startActivity(i);
-			dismiss();
-		}
+	@Override
+	public void onClick(View v) {
+	    Activity a = ContactDialog.this.getOwnerActivity();
+	    Intent i = new Intent(mContext, UserInfo.class);
+	    Log.i("OOO", mContact.getJID());
+	    i.putExtra("contact_contactdialog", mContact.getJID());
+	    a.startActivity(i);
+	    dismiss();
+	}
 
-	}
+    }
+
+    /**
+     * The service connection used to connect to the Beem service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
 
 	/**
-	 * Event simple click on info button.
+	 * Constructor.
 	 */
-	class InfosListener implements View.OnClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public InfosListener() {
-		}
-
-		@Override
-		public void onClick(View v) {
-			Activity a = ContactDialog.this.getOwnerActivity();
-			Intent i = new Intent(mContext, UserInfo.class);
-			Log.i("OOO", mContact.getJID());
-			i.putExtra("contact_contactdialog", mContact.getJID());
-			a.startActivity(i);
-			dismiss();
-		}
-
+	public BeemServiceConnection() {
 	}
 
-	/**
-	 * The service connection used to connect to the Beem service.
-	 */
-	private class BeemServiceConnection implements ServiceConnection {
-
-		/**
-		 * Constructor.
-		 */
-		public BeemServiceConnection() {
-		}
-
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mXmppFacade = null;
-		}
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
 	}
 
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    mXmppFacade = null;
+	}
+    }
+
 }
--- a/src/com/beem/project/beem/ui/ContactList.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java	Wed Nov 11 19:34:04 2009 +0100
@@ -52,32 +52,222 @@
  */
 public class ContactList extends Activity {
 
-	// private static final String TAG = "CONTACTLIST_ACT";
-	private static final Intent SERVICE_INTENT = new Intent();
-	private static final int REQUEST_CODE = 1;
-	private BeemContactList mAdapterContactList;
-	private BeemBanner mAdapterBanner;
-	private IRoster mRoster;
-	private List<Contact> mListContact = new ArrayList<Contact>();
-	private final List<String> mListGroup = new ArrayList<String>();
-	private final Map<String, List<Contact>> mContactOnGroup = new HashMap<String, List<Contact>>();
-	private String mCurGroup;
-	private Handler mHandler;
-	private IXmppFacade mXmppFacade;
-	private SharedPreferences mSettings;
-	private final ServiceConnection mServConn = new BeemServiceConnection();
-	private BeemBroadcastReceiver mReceiver;
-	private Map<Integer, Bitmap> mIconsMap = new HashMap<Integer, Bitmap>();
-	private LayoutInflater mInflater;
+    // private static final String TAG = "CONTACTLIST_ACT";
+    private static final Intent SERVICE_INTENT = new Intent();
+    private static final int REQUEST_CODE = 1;
+    private BeemContactList mAdapterContactList;
+    private BeemBanner mAdapterBanner;
+    private IRoster mRoster;
+    private List<Contact> mListContact = new ArrayList<Contact>();
+    private final List<String> mListGroup = new ArrayList<String>();
+    private final Map<String, List<Contact>> mContactOnGroup = new HashMap<String, List<Contact>>();
+    private String mCurGroup;
+    private Handler mHandler;
+    private IXmppFacade mXmppFacade;
+    private SharedPreferences mSettings;
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private BeemBroadcastReceiver mReceiver;
+    private Map<Integer, Bitmap> mIconsMap = new HashMap<Integer, Bitmap>();
+    private LayoutInflater mInflater;
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    /**
+     * Constructor.
+     */
+    public ContactList() {
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onCreate(Bundle saveBundle) {
+	super.onCreate(saveBundle);
+	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+	setContentView(R.layout.contactlist);
+	mAdapterContactList = new BeemContactList(this);
+	mAdapterBanner = new BeemBanner(this);
+	mHandler = new Handler();
+	mReceiver = new BeemBroadcastReceiver(mServConn);
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+	mInflater = LayoutInflater.from(this);
+	prepareIconsStatus();
+    }
+
+    /**
+     * 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;
+    }
 
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    /**
+     * 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, Settings.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 == RESULT_OK) {
+		mListContact.clear();
+		stopService(SERVICE_INTENT);
+		finish();
+		startActivity(new Intent(this, Login.class));
+	    }
+	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onStart() {
+	super.onStart();
+	bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onStop() {
+	super.onStop();
+	if (mReceiver.isBinded())
+	    unbindService(mServConn);
+	mReceiver.setBinded(false);
+    }
+
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	this.unregisterReceiver(mReceiver);
+    }
+
+    /**
+     * Comparator Contact by Name.
+     */
+    class ComparatorContactListByName<T> implements Comparator<T> {
+	/**
+	 * Constructor.
+	 */
+	public ComparatorContactListByName() {
+
 	}
 
 	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public int compare(T c1, T c2) {
+	    return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
+	}
+    }
+
+    /**
+     * Comparator Contact by status and name.
+     */
+    class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
+	/**
 	 * Constructor.
 	 */
-	public ContactList() {
+	public ComparatorContactListByStatusAndName() {
+
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@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());
+	}
+    }
+
+    /**
+     * Contact List construction.
+     */
+    private void buildContactList() {
+	if (mCurGroup != null) {
+	    mListContact = mContactOnGroup.get(mCurGroup);
+	}
+	sortBeemContactList();
+	ListView listView = (ListView) findViewById(R.id.contactlist);
+	listView.setOnItemClickListener(new BeemContactListOnClick());
+	listView.setOnItemLongClickListener(new BeemContactListOnLongClick());
+	listView.setAdapter(mAdapterContactList);
+    }
+
+    /**
+     * buildBanner.
+     */
+    private void buildBanner() {
+	Gallery g = (Gallery) findViewById(R.id.contactlist_banner);
+	g.setOnItemClickListener(new OnItemClickGroupName());
+	g.setAdapter(mAdapterBanner);
+    }
+
+    /**
+     * Event simple click on item of the contact list.
+     */
+    public class BeemContactListOnClick implements OnItemClickListener {
+	/**
+	 * Constructor.
+	 */
+	public BeemContactListOnClick() {
+
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void onItemClick(AdapterView<?> arg0, View v, int pos, long lpos) {
+	    Contact c = mListContact.get(pos);
+	    Intent i = new Intent(ContactList.this, Chat.class);
+	    i.setData(c.toUri());
+	    startActivity(i);
+	}
+    }
+
+    /**
+     * Event long click on item of the contact list.
+     */
+    public class BeemContactListOnLongClick implements OnItemLongClickListener {
+	/**
+	 * Constructor.
+	 */
+	public BeemContactListOnLongClick() {
 
 	}
 
@@ -85,625 +275,424 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected void onCreate(Bundle saveBundle) {
-		super.onCreate(saveBundle);
-		mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-		setContentView(R.layout.contactlist);
-		mAdapterContactList = new BeemContactList(this);
-		mAdapterBanner = new BeemBanner(this);
-		mHandler = new Handler();
-		mReceiver = new BeemBroadcastReceiver(mServConn);
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-		mInflater = LayoutInflater.from(this);
-		prepareIconsStatus();
+	public boolean onItemLongClick(AdapterView<?> arg0, View v, int pos, long lpos) {
+	    Contact c = mListContact.get(pos);
+	    ContactDialog dialogContact = new ContactDialog(ContactList.this, c);
+	    dialogContact.setOwnerActivity(ContactList.this);
+	    dialogContact.show();
+	    return true;
+	}
+    }
+
+    /**
+     * Event simple click on middle groupe name.
+     */
+    private class OnItemClickGroupName implements OnItemClickListener {
+
+	/**
+	 * Constructor.
+	 */
+	public OnItemClickGroupName() {
 	}
 
+	@Override
+	public void onItemClick(AdapterView<?> arg0, View v, int i, long l) {
+	    mCurGroup = mListGroup.get(i);
+	    buildContactList();
+	}
+    }
+
+    /**
+     * Prepare Bitmap Map.
+     */
+    private void prepareIconsStatus() {
+	mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_available));
+	mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_available));
+	mIconsMap.put(Status.CONTACT_STATUS_AWAY, BitmapFactory.decodeResource(getResources(), R.drawable.status_away));
+	mIconsMap.put(Status.CONTACT_STATUS_BUSY, BitmapFactory.decodeResource(getResources(), R.drawable.status_dnd));
+	mIconsMap.put(Status.CONTACT_STATUS_DISCONNECT, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_offline));
+	mIconsMap.put(Status.CONTACT_STATUS_UNAVAILABLE, BitmapFactory.decodeResource(getResources(),
+	    R.drawable.status_requested));
+    }
+
+    /**
+     * Sort the contact list.
+     */
+    private void sortBeemContactList() {
+	Collections.sort(mListContact, new ComparatorContactListByStatusAndName<Contact>());
+    }
+
+    /**
+     * Listener on service event.
+     */
+    private class BeemRosterListener extends IBeemRosterListener.Stub {
 	/**
-	 * Callback for menu creation.
-	 * 
-	 * @param menu
-	 *            the menu created
-	 * @return true on success, false otherwise
+	 * Constructor.
 	 */
-	@Override
-	public final boolean onCreateOptionsMenu(Menu menu) {
-		super.onCreateOptionsMenu(menu);
-		MenuInflater inflater = getMenuInflater();
-		inflater.inflate(R.menu.contact_list, menu);
-		return true;
+	public BeemRosterListener() {
+
 	}
 
 	/**
-	 * Callback for menu item selected.
-	 * 
-	 * @param item
-	 *            the item selected
-	 * @return true on success, false otherwise
+	 * Refresh the contact list.
 	 */
-	@Override
-	public final boolean onOptionsItemSelected(MenuItem item) {
-		switch (item.getItemId()) {
-		case R.id.contact_list_menu_settings:
-			startActivityForResult(new Intent(this, Settings.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;
-		}
-	}
+	private class RunnableChange implements Runnable {
+	    /**
+	     * Constructor.
+	     */
+	    public RunnableChange() {
+
+	    }
 
-	@Override
-	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-		super.onActivityResult(requestCode, resultCode, data);
-		if (requestCode == REQUEST_CODE) {
-			if (resultCode == RESULT_OK) {
-				mListContact.clear();
-				stopService(SERVICE_INTENT);
-				finish();
-				startActivity(new Intent(this, Login.class));
-			}
-		}
+	    /**
+	     * {@inheritDoc}
+	     */
+	    @Override
+	    public void run() {
+		sortBeemContactList();
+		mAdapterContactList.notifyDataSetChanged();
+		mAdapterBanner.notifyDataSetChanged();
+	    }
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected void onStart() {
-		super.onStart();
-		bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+	public void onEntriesAdded(List<String> addresses) throws RemoteException {
+	    for (String newName : addresses) {
+		Contact c = mRoster.getContact(newName);
+		mContactOnGroup.get(getString(R.string.contact_list_all_contact)).add(c);
+		if (c.getGroups().size() == 0)
+		    mContactOnGroup.get(getString(R.string.contact_list_no_group)).add(c);
+		else {
+		    for (String group : c.getGroups()) {
+			if (!mListGroup.contains(group)) {
+			    mListGroup.add(mListGroup.size() - 1, group);
+			    List<Contact> tmplist = new ArrayList<Contact>();
+			    mContactOnGroup.put(group, tmplist);
+			}
+			mContactOnGroup.get(group).add(c);
+			if (group.equals(mCurGroup) && !mListContact.contains(c))
+			    mListContact.add(c);
+		    }
+		}
+	    }
+	    mHandler.post(new RunnableChange());
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void onEntriesDeleted(List<String> addresses) throws RemoteException {
+	    for (String cToDelete : addresses) {
+		for (Contact c : mListContact) {
+		    if (c.getJID().equals(cToDelete)) {
+			mListContact.remove(c);
+			for (String group : mListGroup) {
+			    mContactOnGroup.get(group).remove(c);
+			    if (mContactOnGroup.get(group).size() == 0) {
+				mListGroup.remove(group);
+				mListContact = mContactOnGroup.get(getString(R.string.contact_list_all_contact));
+			    }
+			}
+			break;
+		    }
+		}
+	    }
+	    mHandler.post(new RunnableChange());
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void onEntriesUpdated(List<String> addresses) throws RemoteException {
+	    for (String adr : addresses) {
+		Contact c = mRoster.getContact(adr);
+		if (c.getGroups() != null) {
+		    if (mContactOnGroup.get(getString(R.string.contact_list_no_group)).contains(c)) {
+			mContactOnGroup.get(getString(R.string.contact_list_no_group)).remove(c);
+		    }
+		}
+	    }
+	    mHandler.post(new RunnableChange());
+	}
+
+	@Override
+	public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
+	    List<Contact> tmpContactList = mContactOnGroup.get(group);
+	    Contact curContact = null;
+	    for (Contact c : tmpContactList) {
+		if (jid.equals(c.getJID())) {
+		    curContact = c;
+		    tmpContactList.remove(c);
+		    c.getGroups().remove(group);
+		    if (mContactOnGroup.get(group).size() == 0) {
+			mContactOnGroup.remove(group);
+			mListGroup.remove(group);
+			mListContact = mContactOnGroup.get(getString(R.string.contact_list_all_contact));
+		    }
+		    break;
+		}
+	    }
+	    if (curContact != null && curContact.getGroups().size() == 0) {
+		mContactOnGroup.get(getString(R.string.contact_list_no_group)).add(curContact);
+	    }
+	    mHandler.post(new RunnableChange());
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected void onStop() {
-		super.onStop();
-		if (mReceiver.isBinded())
-			unbindService(mServConn);
-		mReceiver.setBinded(false);
+	public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
+	    String from = presence.getFrom();
+	    boolean resfound = false;
+	    for (Contact curContact : mListContact) {
+		if (curContact.getJID().equals(StringUtils.parseBareAddress(from))) {
+		    String pres = StringUtils.parseResource(from);
+		    for (String res : curContact.getMRes()) {
+			if (res.equals(pres)) {
+			    resfound = true;
+			    break;
+			}
+		    }
+		    curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
+		    int status = presence.getStatus();
+		    if (!resfound && !Status.statusOnline(status))
+			curContact.addRes(pres);
+		    else if (resfound && Status.statusOnline(status))
+			curContact.delRes(pres);
+		    mHandler.post(new RunnableChange());
+		    return;
+		}
+	    }
 	}
-
-	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		this.unregisterReceiver(mReceiver);
-	}
+    }
 
-	/**
-	 * Comparator Contact by Name.
-	 */
-	class ComparatorContactListByName<T> implements Comparator<T> {
-		/**
-		 * Constructor.
-		 */
-		public ComparatorContactListByName() {
-
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public int compare(T c1, T c2) {
-			return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
-		}
-	}
+    /**
+     * Adapter contact list.
+     */
+    private class BeemContactList extends BaseAdapter {
 
 	/**
-	 * Comparator Contact by status and name.
+	 * Constructor.
+	 * @param context context activity.
 	 */
-	class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
-		/**
-		 * Constructor.
-		 */
-		public ComparatorContactListByStatusAndName() {
-
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@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());
-		}
-	}
-
-	/**
-	 * Contact List construction.
-	 */
-	private void buildContactList() {
-		if (mCurGroup != null) {
-			mListContact = mContactOnGroup.get(mCurGroup);
-		}
-		sortBeemContactList();
-		ListView listView = (ListView) findViewById(R.id.contactlist);
-		listView.setOnItemClickListener(new BeemContactListOnClick());
-		listView.setOnItemLongClickListener(new BeemContactListOnLongClick());
-		listView.setAdapter(mAdapterContactList);
-	}
-
-	/**
-	 * buildBanner.
-	 */
-	private void buildBanner() {
-		Gallery g = (Gallery) findViewById(R.id.contactlist_banner);
-		g.setOnItemClickListener(new OnItemClickGroupName());
-		g.setAdapter(mAdapterBanner);
+	public BeemContactList(final Context context) {
 	}
 
 	/**
-	 * Event simple click on item of the contact list.
+	 * {@inheritDoc}
 	 */
-	public class BeemContactListOnClick implements OnItemClickListener {
-		/**
-		 * Constructor.
-		 */
-		public BeemContactListOnClick() {
-
+	@Override
+	public int getCount() {
+	    if (mSettings.getBoolean("settings_key_hidden_contact", false)) {
+		int res = 0;
+		for (Contact c : mListContact) {
+		    if (Status.statusOnline(c.getStatus()))
+			res++;
 		}
+		return res;
+	    } else {
+		return mListContact.size();
+	    }
+	}
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onItemClick(AdapterView<?> arg0, View v, int pos, long lpos) {
-			Contact c = mListContact.get(pos);
-			Intent i = new Intent(ContactList.this, Chat.class);
-			i.setData(c.toUri());
-			startActivity(i);
-		}
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Object getItem(int position) {
+	    return position;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public long getItemId(int position) {
+	    return position;
 	}
 
 	/**
-	 * Event long click on item of the contact list.
-	 */
-	public class BeemContactListOnLongClick implements OnItemLongClickListener {
-		/**
-		 * Constructor.
-		 */
-		public BeemContactListOnLongClick() {
-
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public boolean onItemLongClick(AdapterView<?> arg0, View v, int pos, long lpos) {
-			Contact c = mListContact.get(pos);
-			ContactDialog dialogContact = new ContactDialog(ContactList.this, c);
-			dialogContact.setOwnerActivity(ContactList.this);
-			dialogContact.show();
-			return true;
-		}
-	}
-
-	/**
-	 * Event simple click on middle groupe name.
+	 * {@inheritDoc}
 	 */
-	private class OnItemClickGroupName implements OnItemClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public OnItemClickGroupName() {
-		}
-
-		@Override
-		public void onItemClick(AdapterView<?> arg0, View v, int i, long l) {
-			mCurGroup = mListGroup.get(i);
-			buildContactList();
+	@Override
+	public View getView(int position, View convertView, ViewGroup parent) {
+	    View v = convertView;
+	    if (convertView == null) {
+		v = mInflater.inflate(R.layout.contactlistcontact, null);
+	    }
+	    Contact c = null;
+	    if (mSettings.getBoolean("settings_key_hidden_contact", false)) {
+		int res = 0;
+		for (Contact cur : mListContact) {
+		    if (res == position) {
+			c = cur;
+			break;
+		    }
+		    if (Status.statusOnline(cur.getStatus()))
+			res++;
 		}
-	}
-
-	/**
-	 * Prepare Bitmap Map.
-	 */
-	private void prepareIconsStatus() {
-		mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_available));
-		mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_available));
-		mIconsMap.put(Status.CONTACT_STATUS_AWAY, BitmapFactory.decodeResource(getResources(), R.drawable.status_away));
-		mIconsMap.put(Status.CONTACT_STATUS_BUSY, BitmapFactory.decodeResource(getResources(), R.drawable.status_dnd));
-		mIconsMap.put(Status.CONTACT_STATUS_DISCONNECT, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_offline));
-		mIconsMap.put(Status.CONTACT_STATUS_UNAVAILABLE, BitmapFactory.decodeResource(getResources(),
-				R.drawable.status_requested));
-	}
-
-	/**
-	 * Sort the contact list.
-	 */
-	private void sortBeemContactList() {
-		Collections.sort(mListContact, new ComparatorContactListByStatusAndName<Contact>());
+	    } else
+		c = mListContact.get(position);
+	    if (mRoster != null) {
+		try {
+		    c = mRoster.getContact(c.getJID());
+		} catch (RemoteException e) {
+		    e.printStackTrace();
+		}
+	    }
+	    if (mSettings.getBoolean("settings_key_hidden_contact", false) && !Status.statusOnline(c.getStatus())) {
+		v.setVisibility(View.GONE);
+	    } else {
+		bindView(v, c);
+	    }
+	    return v;
 	}
 
 	/**
-	 * Listener on service event.
+	 * Adapte curContact to the view.
+	 * @param view the row view.
+	 * @param curContact the current contact.
 	 */
-	private class BeemRosterListener extends IBeemRosterListener.Stub {
-		/**
-		 * Constructor.
-		 */
-		public BeemRosterListener() {
-
-		}
-
-		/**
-		 * Refresh the contact list.
-		 */
-		private class RunnableChange implements Runnable {
-			/**
-			 * Constructor.
-			 */
-			public RunnableChange() {
-
-			}
+	private void bindView(View view, Contact curContact) {
 
-			/**
-			 * {@inheritDoc}
-			 */
-			@Override
-			public void run() {
-				sortBeemContactList();
-				mAdapterContactList.notifyDataSetChanged();
-				mAdapterBanner.notifyDataSetChanged();
-			}
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onEntriesAdded(List<String> addresses) throws RemoteException {
-			for (String newName : addresses) {
-				Contact c = mRoster.getContact(newName);
-				mContactOnGroup.get(getString(R.string.contact_list_all_contact)).add(c);
-				if (c.getGroups().size() == 0)
-					mContactOnGroup.get(getString(R.string.contact_list_no_group)).add(c);
-				else {
-					for (String group : c.getGroups()) {
-						if (!mListGroup.contains(group)) {
-							mListGroup.add(mListGroup.size() - 1, group);
-							List<Contact> tmplist = new ArrayList<Contact>();
-							mContactOnGroup.put(group, tmplist);
-						}
-						mContactOnGroup.get(group).add(c);
-						if (group.equals(mCurGroup) && !mListContact.contains(c))
-							mListContact.add(c);
-					}
-				}
-			}
-			mHandler.post(new RunnableChange());
-		}
+	    if (curContact != null) {
+		ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
+		TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
+		imgV.setImageBitmap(mIconsMap.get(curContact.getStatus()));
+		v.setText(curContact.getName());
+		v = (TextView) view.findViewById(R.id.contactlistmsgperso);
+		v.setText(curContact.getMsgState());
+	    }
+	}
+    }
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onEntriesDeleted(List<String> addresses) throws RemoteException {
-			for (String cToDelete : addresses) {
-				for (Contact c : mListContact) {
-					if (c.getJID().equals(cToDelete)) {
-						mListContact.remove(c);
-						for (String group : mListGroup) {
-							mContactOnGroup.get(group).remove(c);
-							if (mContactOnGroup.get(group).size() == 0) {
-								mListGroup.remove(group);
-								mListContact = mContactOnGroup.get(getString(R.string.contact_list_all_contact));
-							}
-						}
-						break;
-					}
-				}
-			}
-			mHandler.post(new RunnableChange());
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onEntriesUpdated(List<String> addresses) throws RemoteException {
-			for (String adr : addresses) {
-				Contact c = mRoster.getContact(adr);
-				if (c.getGroups() != null) {
-					if (mContactOnGroup.get(getString(R.string.contact_list_no_group)).contains(c)) {
-						mContactOnGroup.get(getString(R.string.contact_list_no_group)).remove(c);
-					}
-				}
-			}
-			mHandler.post(new RunnableChange());
-		}
+    /**
+     * Adapter banner list.
+     */
+    public class BeemBanner extends BaseAdapter {
+	/**
+	 * Constructor.
+	 * @param c context activity.
+	 */
+	public BeemBanner(final Context c) {
+	}
 
-		@Override
-		public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
-			List<Contact> tmpContactList = mContactOnGroup.get(group);
-			Contact curContact = null;
-			for (Contact c : tmpContactList) {
-				if (jid.equals(c.getJID())) {
-					curContact = c;
-					tmpContactList.remove(c);
-					c.getGroups().remove(group);
-					if (mContactOnGroup.get(group).size() == 0) {
-						mContactOnGroup.remove(group);
-						mListGroup.remove(group);
-						mListContact = mContactOnGroup.get(getString(R.string.contact_list_all_contact));
-					}
-					break;
-				}
-			}
-			if (curContact != null && curContact.getGroups().size() == 0) {
-				mContactOnGroup.get(getString(R.string.contact_list_no_group)).add(curContact);
-			}
-			mHandler.post(new RunnableChange());
-		}
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public int getCount() {
+	    return mListGroup.size();
+	}
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
-			String from = presence.getFrom();
-			boolean resfound = false;
-			for (Contact curContact : mListContact) {
-				if (curContact.getJID().equals(StringUtils.parseBareAddress(from))) {
-					String pres = StringUtils.parseResource(from);
-					for (String res : curContact.getMRes()) {
-						if (res.equals(pres)) {
-							resfound = true;
-							break;
-						}
-					}
-					curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
-					int status = presence.getStatus();
-					if (!resfound && !Status.statusOnline(status))
-						curContact.addRes(pres);
-					else if (resfound && Status.statusOnline(status))
-						curContact.delRes(pres);
-					mHandler.post(new RunnableChange());
-					return;
-				}
-			}
-		}
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Object getItem(int position) {
+	    return position;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public long getItemId(int position) {
+	    return position;
 	}
 
 	/**
-	 * Adapter contact list.
+	 * {@inheritDoc}
 	 */
-	private class BeemContactList extends BaseAdapter {
-
-		/**
-		 * Constructor.
-		 * 
-		 * @param context
-		 *            context activity.
-		 */
-		public BeemContactList(final Context context) {
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public int getCount() {
-			if (mSettings.getBoolean("settings_key_hidden_contact", false)) {
-				int res = 0;
-				for (Contact c : mListContact) {
-					if (Status.statusOnline(c.getStatus()))
-						res++;
-				}
-				return res;
-			} else {
-				return mListContact.size();
-			}
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public Object getItem(int position) {
-			return position;
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public long getItemId(int position) {
-			return position;
-		}
+	@Override
+	public View getView(int position, View convertView, ViewGroup parent) {
+	    View v = convertView;
+	    if (convertView == null) {
+		v = mInflater.inflate(R.layout.contactlist_group, null);
+	    }
+	    ((TextView) v).setText(mListGroup.get(position));
+	    return v;
+	}
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public View getView(int position, View convertView, ViewGroup parent) {
-			View v = convertView;
-			if (convertView == null) {
-				v = mInflater.inflate(R.layout.contactlistcontact, null);
-			}
-			Contact c = null;
-			if (mSettings.getBoolean("settings_key_hidden_contact", false)) {
-				int res = 0;
-				for (Contact cur : mListContact) {
-					if (res == position) {
-						c = cur;
-						break;
-					}
-					if (Status.statusOnline(cur.getStatus()))
-						res++;
-				}
-			} else
-				c = mListContact.get(position);
-			if (mRoster != null) {
-				try {
-					c = mRoster.getContact(c.getJID());
-				} catch (RemoteException e) {
-					e.printStackTrace();
-				}
-			}
-			if (mSettings.getBoolean("settings_key_hidden_contact", false) && !Status.statusOnline(c.getStatus())) {
-				v.setVisibility(View.GONE);
-			} else {
-				bindView(v, c);
-			}
-			return v;
-		}
+    }
 
-		/**
-		 * Adapte curContact to the view.
-		 * 
-		 * @param view
-		 *            the row view.
-		 * @param curContact
-		 *            the current contact.
-		 */
-		private void bindView(View view, Contact curContact) {
+    /**
+     * The service connection used to connect to the Beem service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
+	private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
 
-			if (curContact != null) {
-				ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
-				TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
-				imgV.setImageBitmap(mIconsMap.get(curContact.getStatus()));
-				v.setText(curContact.getName());
-				v = (TextView) view.findViewById(R.id.contactlistmsgperso);
-				v.setText(curContact.getMsgState());
-			}
-		}
+	/**
+	 * Constructor.
+	 */
+	public BeemServiceConnection() {
 	}
 
-	/**
-	 * Adapter banner list.
-	 */
-	public class BeemBanner extends BaseAdapter {
-		/**
-		 * Constructor.
-		 * 
-		 * @param c
-		 *            context activity.
-		 */
-		public BeemBanner(final Context c) {
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public int getCount() {
-			return mListGroup.size();
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mReceiver.setBinded(true);
+	    try {
+		mRoster = mXmppFacade.getRoster();
+		if (mRoster != null) {
+		    mRoster.addRosterListener(mBeemRosterListener);
+		    List<Contact> tmpContactList = mRoster.getContactList();
+		    List<String> tmpGroupList = mRoster.getGroupsNames();
+		    Collections.sort(tmpGroupList);
+		    if (mListGroup.size() > 0)
+			mListGroup.clear();
+		    mListGroup.add(getString(R.string.contact_list_all_contact));
+		    mListGroup.addAll(tmpGroupList);
+		    mListGroup.add(getString(R.string.contact_list_no_group));
+		    if (tmpGroupList.size() > 0) {
+			List<Contact> tmpNoGroup = new ArrayList<Contact>();
+			for (String s : tmpGroupList) {
+			    List<Contact> tmpList = new ArrayList<Contact>();
+			    for (Contact c : tmpContactList) {
+				if (c.getGroups().size() == 0 && !tmpNoGroup.contains(c))
+				    tmpNoGroup.add(c);
+				else if (c.getGroups().contains(s))
+				    tmpList.add(c);
+			    }
+			    mContactOnGroup.put(s, tmpList);
+			}
+			mContactOnGroup.put(getString(R.string.contact_list_no_group), tmpNoGroup);
+		    } else {
+			mContactOnGroup.put(getString(R.string.contact_list_no_group), tmpContactList);
+		    }
+		    mContactOnGroup.put(getString(R.string.contact_list_all_contact), tmpContactList);
+		    mCurGroup = getString(R.string.contact_list_all_contact);
+		    buildBanner();
+		    buildContactList();
 		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public Object getItem(int position) {
-			return position;
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public long getItemId(int position) {
-			return position;
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public View getView(int position, View convertView, ViewGroup parent) {
-			View v = convertView;
-			if (convertView == null) {
-				v = mInflater.inflate(R.layout.contactlist_group, null);
-			}
-			((TextView) v).setText(mListGroup.get(position));
-			return v;
-		}
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
 
 	}
 
-	/**
-	 * The service connection used to connect to the Beem service.
-	 */
-	private class BeemServiceConnection implements ServiceConnection {
-		private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
-
-		/**
-		 * Constructor.
-		 */
-		public BeemServiceConnection() {
-		}
-
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-			mReceiver.setBinded(true);
-			try {
-				mRoster = mXmppFacade.getRoster();
-				if (mRoster != null) {
-					mRoster.addRosterListener(mBeemRosterListener);
-					List<Contact> tmpContactList = mRoster.getContactList();
-					List<String> tmpGroupList = mRoster.getGroupsNames();
-					Collections.sort(tmpGroupList);
-					if (mListGroup.size() > 0)
-						mListGroup.clear();
-					mListGroup.add(getString(R.string.contact_list_all_contact));
-					mListGroup.addAll(tmpGroupList);
-					mListGroup.add(getString(R.string.contact_list_no_group));
-					if (tmpGroupList.size() > 0) {
-						List<Contact> tmpNoGroup = new ArrayList<Contact>();
-						for (String s : tmpGroupList) {
-							List<Contact> tmpList = new ArrayList<Contact>();
-							for (Contact c : tmpContactList) {
-								if (c.getGroups().size() == 0 && !tmpNoGroup.contains(c))
-									tmpNoGroup.add(c);
-								else if (c.getGroups().contains(s))
-									tmpList.add(c);
-							}
-							mContactOnGroup.put(s, tmpList);
-						}
-						mContactOnGroup.put(getString(R.string.contact_list_no_group), tmpNoGroup);
-					} else {
-						mContactOnGroup.put(getString(R.string.contact_list_no_group), tmpContactList);
-					}
-					mContactOnGroup.put(getString(R.string.contact_list_all_contact), tmpContactList);
-					mCurGroup = getString(R.string.contact_list_all_contact);
-					buildBanner();
-					buildContactList();
-				}
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			try {
-				mRoster.removeRosterListener(mBeemRosterListener);
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-			mXmppFacade = null;
-			mRoster = null;
-			mListContact.clear();
-			mListGroup.clear();
-			mContactOnGroup.clear();
-			mReceiver.setBinded(false);
-		}
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    try {
+		mRoster.removeRosterListener(mBeemRosterListener);
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
+	    mXmppFacade = null;
+	    mRoster = null;
+	    mListContact.clear();
+	    mListGroup.clear();
+	    mContactOnGroup.clear();
+	    mReceiver.setBinded(false);
 	}
+    }
 }
--- a/src/com/beem/project/beem/ui/CreateAccount.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/CreateAccount.java	Wed Nov 11 19:34:04 2009 +0100
@@ -25,275 +25,255 @@
 import com.beem.project.beem.R;
 
 /**
- * This class represents an activity which allows the user to create an account
- * on the XMPP server saved in settings.
- * 
+ * This class represents an activity which allows the user to create an account on the XMPP server saved in settings.
  * @author dasilvj
  */
 public class CreateAccount extends Activity {
 
-	private static final boolean DEFAULT_BOOLEAN_VALUE = false;
-	private static final String DEFAULT_STRING_VALUE = "";
-	private static final int DEFAULT_INT_VALUE = 0;
-	private static final int DEFAULT_XMPP_PORT = 5222;
+    private static final boolean DEFAULT_BOOLEAN_VALUE = false;
+    private static final String DEFAULT_STRING_VALUE = "";
+    private static final int DEFAULT_INT_VALUE = 0;
+    private static final int DEFAULT_XMPP_PORT = 5222;
 
-	private static final int NOTIFICATION_DURATION = Toast.LENGTH_SHORT;
+    private static final int NOTIFICATION_DURATION = Toast.LENGTH_SHORT;
 
-	private SharedPreferences mSettings;
-	private Button mCreateAccountButton;
+    private SharedPreferences mSettings;
+    private Button mCreateAccountButton;
 
-	/**
-	 * Constructor.
-	 */
-	public CreateAccount() {
-	}
+    /**
+     * Constructor.
+     */
+    public CreateAccount() {
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.create_account);
-		initCreateAccountButton();
-		mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-	}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.create_account);
+	initCreateAccountButton();
+	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+    }
 
-	/**
-	 * Create an account on the XMPP server specified in settings.
-	 * 
-	 * @param username
-	 *            the username of the account.
-	 * @param password
-	 *            the password of the account.
-	 * @return true if the account was created successfully.
-	 */
-	private boolean createAccount(String username, String password) {
-		XMPPConnection xmppConnection = null;
-		ConnectionConfiguration connectionConfiguration = null;
+    /**
+     * Create an account on the XMPP server specified in settings.
+     * @param username the username of the account.
+     * @param password the password of the account.
+     * @return true if the account was created successfully.
+     */
+    private boolean createAccount(String username, String password) {
+	XMPPConnection xmppConnection = null;
+	ConnectionConfiguration connectionConfiguration = null;
 
-		if (getRegisteredProxy() != null) {
-			connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT,
-					getRegisteredProxy());
-		} else {
-			connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT);
-		}
-		if (getRegisteredXMPPTLSUse())
-			connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
+	if (getRegisteredProxy() != null) {
+	    connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT,
+		getRegisteredProxy());
+	} else {
+	    connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT);
+	}
+	if (getRegisteredXMPPTLSUse())
+	    connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
 
-		xmppConnection = new XMPPConnection(connectionConfiguration);
-		try {
-			xmppConnection.connect();
-			AccountManager accountManager = new AccountManager(xmppConnection);
-			accountManager.createAccount(username, password);
-			Toast toast = Toast.makeText(getApplicationContext(), "Account " + username + " "
-					+ getString(R.string.create_account_successfull_after), NOTIFICATION_DURATION);
-			toast.show();
-		} catch (XMPPException e) {
-			Log.e(getString(R.string.create_account_tag), e.getMessage());
-			createErrorDialog(e.getMessage());
-			return false;
-		}
-		xmppConnection.disconnect();
-		return true;
+	xmppConnection = new XMPPConnection(connectionConfiguration);
+	try {
+	    xmppConnection.connect();
+	    AccountManager accountManager = new AccountManager(xmppConnection);
+	    accountManager.createAccount(username, password);
+	    Toast toast = Toast.makeText(getApplicationContext(), "Account " + username + " "
+		+ getString(R.string.create_account_successfull_after), NOTIFICATION_DURATION);
+	    toast.show();
+	} catch (XMPPException e) {
+	    Log.e(getString(R.string.create_account_tag), e.getMessage());
+	    createErrorDialog(e.getMessage());
+	    return false;
 	}
+	xmppConnection.disconnect();
+	return true;
+    }
 
-	/**
-	 * Create a dialog containing an error message.
-	 * 
-	 * @param errMsg
-	 *            the error message
-	 */
-	private void createErrorDialog(String errMsg) {
-		Log.v(getString(R.string.create_account_tag), errMsg);
-		AlertDialog.Builder builder = new AlertDialog.Builder(this);
-		builder.setTitle(R.string.create_account_err_dialog_title).setMessage(errMsg).setCancelable(false);
-		builder.setNeutralButton(R.string.create_account_close_dialog_button, new DialogInterface.OnClickListener() {
+    /**
+     * Create a dialog containing an error message.
+     * @param errMsg the error message
+     */
+    private void createErrorDialog(String errMsg) {
+	Log.v(getString(R.string.create_account_tag), errMsg);
+	AlertDialog.Builder builder = new AlertDialog.Builder(this);
+	builder.setTitle(R.string.create_account_err_dialog_title).setMessage(errMsg).setCancelable(false);
+	builder.setNeutralButton(R.string.create_account_close_dialog_button, new DialogInterface.OnClickListener() {
 
-			@Override
-			public void onClick(DialogInterface dialog, int which) {
-				dialog.cancel();
-			}
-		});
-		AlertDialog settingsErrDialog = builder.create();
-		settingsErrDialog.show();
-	}
+	    @Override
+	    public void onClick(DialogInterface dialog, int which) {
+		dialog.cancel();
+	    }
+	});
+	AlertDialog settingsErrDialog = builder.create();
+	settingsErrDialog.show();
+    }
 
-	/**
-	 * Retrive proxy informations from the preferences.
-	 * 
-	 * @return Registered proxy informations
-	 */
-	private ProxyInfo getRegisteredProxy() {
-		if (getRegisteredProxyUse()) {
-			ProxyInfo proxyInfo = new ProxyInfo(getRegisteredProxyType(), getRegisteredProxyServer(),
-					getRegisteredProxyPort(), getRegisteredProxyUsername(), getRegisteredProxyPassword());
-			return proxyInfo;
-		}
-		return null;
+    /**
+     * Retrive proxy informations from the preferences.
+     * @return Registered proxy informations
+     */
+    private ProxyInfo getRegisteredProxy() {
+	if (getRegisteredProxyUse()) {
+	    ProxyInfo proxyInfo = new ProxyInfo(getRegisteredProxyType(), getRegisteredProxyServer(),
+		getRegisteredProxyPort(), getRegisteredProxyUsername(), getRegisteredProxyPassword());
+	    return proxyInfo;
 	}
+	return null;
+    }
 
-	/**
-	 * Retrieve proxy password from the preferences.
-	 * 
-	 * @return Registered proxy password
-	 */
-	private String getRegisteredProxyPassword() {
-		return mSettings.getString(getString(R.string.settings_key_proxy_password), DEFAULT_STRING_VALUE);
-	}
+    /**
+     * Retrieve proxy password from the preferences.
+     * @return Registered proxy password
+     */
+    private String getRegisteredProxyPassword() {
+	return mSettings.getString(getString(R.string.settings_key_proxy_password), DEFAULT_STRING_VALUE);
+    }
 
-	/**
-	 * Retrieve proxy port from the preferences.
-	 * 
-	 * @return Registered proxy port
-	 */
-	private int getRegisteredProxyPort() {
-		return Integer.parseInt(mSettings.getString(getString(R.string.settings_key_proxy_port), DEFAULT_STRING_VALUE));
-	}
+    /**
+     * Retrieve proxy port from the preferences.
+     * @return Registered proxy port
+     */
+    private int getRegisteredProxyPort() {
+	return Integer.parseInt(mSettings.getString(getString(R.string.settings_key_proxy_port), DEFAULT_STRING_VALUE));
+    }
 
-	/**
-	 * Retrieve proxy server from the preferences.
-	 * 
-	 * @return Registered proxy server
-	 */
-	private String getRegisteredProxyServer() {
-		return mSettings.getString(getString(R.string.settings_key_proxy_server), DEFAULT_STRING_VALUE);
-	}
+    /**
+     * Retrieve proxy server from the preferences.
+     * @return Registered proxy server
+     */
+    private String getRegisteredProxyServer() {
+	return mSettings.getString(getString(R.string.settings_key_proxy_server), DEFAULT_STRING_VALUE);
+    }
 
-	/**
-	 * Retrieve proxy type from the preferences.
-	 * 
-	 * @return Registered proxy type
-	 */
-	private ProxyInfo.ProxyType getRegisteredProxyType() {
-		ProxyInfo.ProxyType result;
-		switch (mSettings.getInt(getString(R.string.settings_key_proxy_type), DEFAULT_INT_VALUE)) {
-		case 0:
-			result = ProxyInfo.ProxyType.HTTP;
-			break;
-		case 1:
-			result = ProxyInfo.ProxyType.SOCKS4;
-			break;
-		case 2:
-			Log.i(getString(R.string.create_account_tag), "SOCKS5 PROXY");
-			result = ProxyInfo.ProxyType.SOCKS5;
-			break;
-		default:
-			result = ProxyInfo.ProxyType.NONE;
-			break;
-		}
-		return result;
+    /**
+     * Retrieve proxy type from the preferences.
+     * @return Registered proxy type
+     */
+    private ProxyInfo.ProxyType getRegisteredProxyType() {
+	ProxyInfo.ProxyType result;
+	switch (mSettings.getInt(getString(R.string.settings_key_proxy_type), DEFAULT_INT_VALUE)) {
+	    case 0:
+		result = ProxyInfo.ProxyType.HTTP;
+		break;
+	    case 1:
+		result = ProxyInfo.ProxyType.SOCKS4;
+		break;
+	    case 2:
+		Log.i(getString(R.string.create_account_tag), "SOCKS5 PROXY");
+		result = ProxyInfo.ProxyType.SOCKS5;
+		break;
+	    default:
+		result = ProxyInfo.ProxyType.NONE;
+		break;
 	}
+	return result;
+    }
 
-	/**
-	 * Retrieve proxy use from the preferences.
-	 * 
-	 * @return Registered proxy use
-	 */
-	private boolean getRegisteredProxyUse() {
-		return mSettings.getBoolean(getString(R.string.settings_key_proxy_use), DEFAULT_BOOLEAN_VALUE);
-	}
+    /**
+     * Retrieve proxy use from the preferences.
+     * @return Registered proxy use
+     */
+    private boolean getRegisteredProxyUse() {
+	return mSettings.getBoolean(getString(R.string.settings_key_proxy_use), DEFAULT_BOOLEAN_VALUE);
+    }
 
-	/**
-	 * Retrieve proxy username from the preferences.
-	 * 
-	 * @return Registered proxy username
-	 */
-	private String getRegisteredProxyUsername() {
-		return mSettings.getString(getString(R.string.settings_key_proxy_username), DEFAULT_STRING_VALUE);
-	}
+    /**
+     * Retrieve proxy username from the preferences.
+     * @return Registered proxy username
+     */
+    private String getRegisteredProxyUsername() {
+	return mSettings.getString(getString(R.string.settings_key_proxy_username), DEFAULT_STRING_VALUE);
+    }
 
-	/**
-	 * Retrieve xmpp server from the preferences.
-	 * 
-	 * @return Registered xmpp server
-	 */
-	private String getXMPPServer() {
-		TextView xmppServerTextView = (TextView) findViewById(R.id.create_account_username);
-		String xmppServer = StringUtils.parseServer(xmppServerTextView.getText().toString());
-		return xmppServer;
-	}
+    /**
+     * Retrieve xmpp server from the preferences.
+     * @return Registered xmpp server
+     */
+    private String getXMPPServer() {
+	TextView xmppServerTextView = (TextView) findViewById(R.id.create_account_username);
+	String xmppServer = StringUtils.parseServer(xmppServerTextView.getText().toString());
+	return xmppServer;
+    }
 
-	/**
-	 * Retrieve TLS use from the preferences.
-	 * 
-	 * @return Registered TLS use
-	 */
-	private boolean getRegisteredXMPPTLSUse() {
-		return mSettings.getBoolean(getString(R.string.settings_key_xmpp_tls_use), DEFAULT_BOOLEAN_VALUE);
-	}
+    /**
+     * Retrieve TLS use from the preferences.
+     * @return Registered TLS use
+     */
+    private boolean getRegisteredXMPPTLSUse() {
+	return mSettings.getBoolean(getString(R.string.settings_key_xmpp_tls_use), DEFAULT_BOOLEAN_VALUE);
+    }
 
-	/**
-	 * Check if the fields password and confirm password match.
-	 * 
-	 * @return return true if password & confirm password fields match, else
-	 *         false
-	 */
-	private boolean checkPasswords() {
-		final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString();
-		final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password))
-				.getText().toString();
+    /**
+     * Check if the fields password and confirm password match.
+     * @return return true if password & confirm password fields match, else false
+     */
+    private boolean checkPasswords() {
+	final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString();
+	final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password))
+	    .getText().toString();
 
-		return passwordFieldValue.equals(passwordConfirmFielddValue);
-	}
+	return passwordFieldValue.equals(passwordConfirmFielddValue);
+    }
 
-	/**
-	 * Check the format of the email.
-	 * 
-	 * @return true if the email is valid.
-	 */
-	private boolean checkEmail() {
-		String email = ((TextView) findViewById(R.id.create_account_username)).getText().toString();
-		return Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", email);
-	}
+    /**
+     * Check the format of the email.
+     * @return true if the email is valid.
+     */
+    private boolean checkEmail() {
+	String email = ((TextView) findViewById(R.id.create_account_username)).getText().toString();
+	return Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", email);
+    }
 
-	/**
-	 * Initialize the "Create this account" button which allows the user to
-	 * create an account.
-	 */
-	private void initCreateAccountButton() {
-		mCreateAccountButton = (Button) findViewById(R.id.create_account_button);
-		mCreateAccountButton.setOnClickListener(new View.OnClickListener() {
-			public void onClick(View v) {
-				String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
-						.toString();
-				String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
-						.toString();
-				String username = StringUtils.parseName(usernameFieldValue);
-				if (!checkEmail())
-					createErrorDialog(getString(R.string.create_account_err_username));
-				else if (!checkPasswords())
-					createErrorDialog(getString(R.string.create_account_err_passwords));
-				else {
-					if (createAccount(username, passwordFieldValue))
-						finish();
-				}
+    /**
+     * Initialize the "Create this account" button which allows the user to create an account.
+     */
+    private void initCreateAccountButton() {
+	mCreateAccountButton = (Button) findViewById(R.id.create_account_button);
+	mCreateAccountButton.setOnClickListener(new View.OnClickListener() {
+	    public void onClick(View v) {
+		String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
+		    .toString();
+		String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
+		    .toString();
+		String username = StringUtils.parseName(usernameFieldValue);
+		if (!checkEmail())
+		    createErrorDialog(getString(R.string.create_account_err_username));
+		else if (!checkPasswords())
+		    createErrorDialog(getString(R.string.create_account_err_passwords));
+		else {
+		    if (createAccount(username, passwordFieldValue))
+			finish();
+		}
 
-			}
-		});
-		Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button);
-		createAccountLoginButton.setOnClickListener(new View.OnClickListener() {
-			public void onClick(View v) {
-				String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
-						.toString();
-				String username = StringUtils.parseName(usernameFieldValue);
-				String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
-						.toString();
-				if (!checkEmail())
-					createErrorDialog(getString(R.string.create_account_err_username));
-				else if (!checkPasswords())
-					createErrorDialog(getString(R.string.create_account_err_passwords));
-				else {
-					if (createAccount(username, passwordFieldValue)) {
-						SharedPreferences.Editor settingsEditor = mSettings.edit();
-						settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue);
-						settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue);
-						settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), true);
-						settingsEditor.commit();
-						finish();
-					}
-				}
-			}
-		});
-	}
+	    }
+	});
+	Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button);
+	createAccountLoginButton.setOnClickListener(new View.OnClickListener() {
+	    public void onClick(View v) {
+		String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
+		    .toString();
+		String username = StringUtils.parseName(usernameFieldValue);
+		String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
+		    .toString();
+		if (!checkEmail())
+		    createErrorDialog(getString(R.string.create_account_err_username));
+		else if (!checkPasswords())
+		    createErrorDialog(getString(R.string.create_account_err_passwords));
+		else {
+		    if (createAccount(username, passwordFieldValue)) {
+			SharedPreferences.Editor settingsEditor = mSettings.edit();
+			settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue);
+			settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue);
+			settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), true);
+			settingsEditor.commit();
+			finish();
+		    }
+		}
+	    }
+	});
+    }
 }
--- a/src/com/beem/project/beem/ui/GroupList.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/GroupList.java	Wed Nov 11 19:34:04 2009 +0100
@@ -30,192 +30,191 @@
 
 /**
  * That activity permit to manage user groups.
- * 
  * @author nikita
  */
 public class GroupList extends ListActivity {
 
-	private static final Intent SERVICE_INTENT = new Intent();
+    private static final Intent SERVICE_INTENT = new Intent();
+
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private BeemBroadcastReceiver mReceiver;
+    private IXmppFacade mXmppFacade;
+    private IRoster mRoster;
+    private String mJID;
+    private ArrayAdapter<String> mGroups;
+    private Contact mContact;
+    private TextView mText;
+    private final List<String> mStrings = new ArrayList<String>();
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    /**
+     * Constructor.
+     */
+    public GroupList() {
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.group_list);
+	mReceiver = new BeemBroadcastReceiver(mServConn);
+	mContact = getIntent().getParcelableExtra("contact");
+	mJID = mContact.getJID();
+	final ListView listView = getListView();
+
+	listView.setItemsCanFocus(false);
+	listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
+	listView.setOnItemClickListener(new GroupOnItemClickListener());
+
+	mText = (TextView) findViewById(R.id.GroupListText);
+	mText.setOnKeyListener(new GroupListOnKeyListener());
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    }
 
-	private final ServiceConnection mServConn = new BeemServiceConnection();
-	private BeemBroadcastReceiver mReceiver;
-	private IXmppFacade mXmppFacade;
-	private IRoster mRoster;
-	private String mJID;
-	private ArrayAdapter<String> mGroups;
-	private Contact mContact;
-	private TextView mText;
-	private final List<String> mStrings = new ArrayList<String>();
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onResume() {
+	super.onResume();
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	mReceiver.setBinded(true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onPause() {
+	super.onPause();
+	if (mReceiver.isBinded()) {
+	    unbindService(mServConn);
+	    mReceiver.setBinded(false);
+	}
+    }
 
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	this.unregisterReceiver(mReceiver);
+    }
+
+    /**
+     * init activity list adapter.
+     */
+    private void setAdapter() {
+	try {
+	    for (String group : mRoster.getGroupsNames()) {
+		mStrings.add(group);
+	    }
+	    mGroups = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, mStrings);
+	    setListAdapter(mGroups);
+	    mContact = mRoster.getContact(mJID);
+	    for (String group : mContact.getGroups()) {
+		getListView().setItemChecked(mGroups.getPosition(group), true);
+	    }
+	} catch (RemoteException e) {
+	    e.printStackTrace();
 	}
+    }
+
+    /**
+     * Event when group is added.
+     */
+    private class GroupListOnKeyListener implements OnKeyListener {
 
 	/**
 	 * Constructor.
 	 */
-	public GroupList() {
+	public GroupListOnKeyListener() {
 	}
 
 	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.group_list);
-		mReceiver = new BeemBroadcastReceiver(mServConn);
-		mContact = getIntent().getParcelableExtra("contact");
-		mJID = mContact.getJID();
-		final ListView listView = getListView();
+	public boolean onKey(View v, int keyCode, KeyEvent event) {
+	    boolean result = false;
+	    if (event.getAction() == KeyEvent.ACTION_DOWN) {
+		switch (keyCode) {
+		    case KeyEvent.KEYCODE_DPAD_CENTER:
+		    case KeyEvent.KEYCODE_ENTER:
+			if (mText.getText().length() == 0)
+			    return false;
+			String groupname = mText.getText().toString();
+			mGroups.add(groupname);
+			mText.setText(null);
+			result = true;
+			break;
+		    default:
+			result = false;
+		}
+	    }
+	    return result;
+	}
 
-		listView.setItemsCanFocus(false);
-		listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
-		listView.setOnItemClickListener(new GroupOnItemClickListener());
+    }
 
-		mText = (TextView) findViewById(R.id.GroupListText);
-		mText.setOnKeyListener(new GroupListOnKeyListener());
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-	}
+    /**
+     * Event click on list group contact.
+     */
+    private class GroupOnItemClickListener implements OnItemClickListener {
 
 	/**
-	 * {@inheritDoc}
+	 * Constructor.
 	 */
-	@Override
-	protected void onResume() {
-		super.onResume();
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		mReceiver.setBinded(true);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onPause() {
-		super.onPause();
-		if (mReceiver.isBinded()) {
-			unbindService(mServConn);
-			mReceiver.setBinded(false);
-		}
+	public GroupOnItemClickListener() {
 	}
 
 	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		this.unregisterReceiver(mReceiver);
-	}
-
-	/**
-	 * init activity list adapter.
-	 */
-	private void setAdapter() {
+	public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
+	    CheckedTextView textView = (CheckedTextView) v;
+	    if (!textView.isChecked()) {
 		try {
-			for (String group : mRoster.getGroupsNames()) {
-				mStrings.add(group);
-			}
-			mGroups = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, mStrings);
-			setListAdapter(mGroups);
-			mContact = mRoster.getContact(mJID);
-			for (String group : mContact.getGroups()) {
-				getListView().setItemChecked(mGroups.getPosition(group), true);
-			}
+		    mRoster.addContactToGroup(textView.getText().toString(), mJID);
 		} catch (RemoteException e) {
-			e.printStackTrace();
+		    e.printStackTrace();
 		}
-	}
-
-	/**
-	 * Event when group is added.
-	 */
-	private class GroupListOnKeyListener implements OnKeyListener {
-
-		/**
-		 * Constructor.
-		 */
-		public GroupListOnKeyListener() {
+	    } else {
+		try {
+		    mRoster.removeContactFromGroup(textView.getText().toString(), mJID);
+		} catch (RemoteException e) {
+		    e.printStackTrace();
 		}
-
-		@Override
-		public boolean onKey(View v, int keyCode, KeyEvent event) {
-			boolean result = false;
-			if (event.getAction() == KeyEvent.ACTION_DOWN) {
-				switch (keyCode) {
-				case KeyEvent.KEYCODE_DPAD_CENTER:
-				case KeyEvent.KEYCODE_ENTER:
-					if (mText.getText().length() == 0)
-						return false;
-					String groupname = mText.getText().toString();
-					mGroups.add(groupname);
-					mText.setText(null);
-					result = true;
-					break;
-				default:
-					result = false;
-				}
-			}
-			return result;
-		}
+	    }
 
 	}
 
-	/**
-	 * Event click on list group contact.
-	 */
-	private class GroupOnItemClickListener implements OnItemClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public GroupOnItemClickListener() {
-		}
+    }
 
-		@Override
-		public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
-			CheckedTextView textView = (CheckedTextView) v;
-			if (!textView.isChecked()) {
-				try {
-					mRoster.addContactToGroup(textView.getText().toString(), mJID);
-				} catch (RemoteException e) {
-					e.printStackTrace();
-				}
-			} else {
-				try {
-					mRoster.removeContactFromGroup(textView.getText().toString(), mJID);
-				} catch (RemoteException e) {
-					e.printStackTrace();
-				}
-			}
+    /**
+     * The ServiceConnection used to connect to the Beem service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
 
-		}
-
+	/**
+	 * Constructor.
+	 */
+	public BeemServiceConnection() {
 	}
 
-	/**
-	 * The ServiceConnection used to connect to the Beem service.
-	 */
-	private class BeemServiceConnection implements ServiceConnection {
-
-		/**
-		 * Constructor.
-		 */
-		public BeemServiceConnection() {
-		}
-
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-			mReceiver.setBinded(true);
-			try {
-				mRoster = mXmppFacade.getRoster();
-				setAdapter();
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mXmppFacade = null;
-			mRoster = null;
-		}
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mReceiver.setBinded(true);
+	    try {
+		mRoster = mXmppFacade.getRoster();
+		setAdapter();
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
 	}
 
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    mXmppFacade = null;
+	    mRoster = null;
+	}
+    }
+
 }
--- a/src/com/beem/project/beem/ui/Login.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/Login.java	Wed Nov 11 19:34:04 2009 +0100
@@ -28,360 +28,353 @@
 import com.beem.project.beem.utils.Status;
 
 /**
- * This class represents an activity which allows the user to connect to an XMPP
- * server with his username/password.
- * 
+ * This class represents an activity which allows the user to connect to an XMPP server with his username/password.
  * @author dasilvj
  */
 public class Login extends Activity {
 
-	private static final String TAG = "LOG_AS";
-	private static final int REQUEST_CODE = 1;
-	private static final Intent SERVICE_INTENT = new Intent();
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    private static final String TAG = "LOG_AS";
+    private static final int REQUEST_CODE = 1;
+    private static final Intent SERVICE_INTENT = new Intent();
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    private final Handler mConnectionHandler = new Handler();
+    private ConnectionRunnable mConnectionRunnable = new ConnectionRunnable();
+    private ProgressDialog mProgressDialog;
+
+    private boolean mIsConnectedService;
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private IXmppFacade mXmppFacade;
+
+    private SharedPreferences mSettings;
+    private boolean mIsConfigured;
+    private int mRetry;
+    private IXmppConnection mXmppConnection;
+
+    /**
+     * Constructor.
+     */
+    public Login() {
+    }
+
+    /**
+     * Create an about "BEEM" dialog.
+     */
+    public void createAboutDialog() {
+	AlertDialog.Builder builder = new AlertDialog.Builder(this);
+	builder.setTitle(R.string.login_about_title).setMessage(R.string.login_about_msg).setCancelable(false);
+	builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() {
+
+	    public void onClick(DialogInterface dialog, int whichButton) {
+		dialog.cancel();
+	    }
+	});
+	AlertDialog aboutDialog = builder.create();
+	aboutDialog.show();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	Log.d(TAG, "onCreate");
+	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+	setContentView(R.layout.login);
+	mProgressDialog = new ProgressDialog(this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onStop() {
+	super.onStop();
+	Log.d(TAG, "onStop " + mIsConnectedService);
+	if (mIsConfigured && (mIsConnectedService || mXmppFacade != null)) {
+	    boolean isConnected = false;
+	    if (mXmppConnection != null) {
+		try {
+		    isConnected = mXmppConnection.isAuthentificated();
+		} catch (RemoteException e) {
+		    e.printStackTrace();
+		}
+	    }
+	    unbindService(mServConn);
+	    if (!isConnected) {
+		stopService(SERVICE_INTENT);
+	    }
+	    mXmppFacade = null;
 	}
+    }
 
-	private final Handler mConnectionHandler = new Handler();
-	private ConnectionRunnable mConnectionRunnable = new ConnectionRunnable();
-	private ProgressDialog mProgressDialog;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onPause() {
+	super.onPause();
+	Log.d(TAG, "onPause");
+	mConnectionHandler.removeCallbacks(mConnectionRunnable);
+	mProgressDialog.dismiss();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onResume() {
+	super.onResume();
+	Log.d(TAG, "onResume");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onStart() {
+	super.onStart();
+	Log.d(TAG, "onStart " + mIsConnectedService);
+	mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
+	if (mIsConfigured && !mIsConnectedService) {
+	    try {
+		Thread.sleep(1000); // HACK: Pour éviter de rebinder un service
+		// pas encore arreter.
+	    } catch (InterruptedException e) {
+		e.printStackTrace();
+	    }
+	    bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+	    mIsConnectedService = true;
+	}
+    }
 
-	private boolean mIsConnectedService;
-	private final ServiceConnection mServConn = new BeemServiceConnection();
-	private IXmppFacade mXmppFacade;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+	super.onActivityResult(requestCode, resultCode, data);
+	if (requestCode == REQUEST_CODE) {
+	    if (resultCode == RESULT_OK) {
+		stopService(SERVICE_INTENT);
+	    }
+	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+	super.onCreateOptionsMenu(menu);
+	MenuInflater inflater = getMenuInflater();
+	inflater.inflate(R.menu.login, menu);
+	return true;
+    }
 
-	private SharedPreferences mSettings;
-	private boolean mIsConfigured;
-	private int mRetry;
-	private IXmppConnection mXmppConnection;
+    /**
+     * 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.login_menu_settings:
+		startActivity(new Intent(Login.this, Settings.class));
+		return true;
+	    case R.id.login_menu_about:
+		createAboutDialog();
+		return true;
+	    default:
+		return false;
+	}
+    }
+
+    /**
+     * Connection runnable.
+     * @author nikita
+     */
+    private class ConnectionRunnable implements Runnable {
 
 	/**
 	 * Constructor.
 	 */
-	public Login() {
-	}
-
-	/**
-	 * Create an about "BEEM" dialog.
-	 */
-	public void createAboutDialog() {
-		AlertDialog.Builder builder = new AlertDialog.Builder(this);
-		builder.setTitle(R.string.login_about_title).setMessage(R.string.login_about_msg).setCancelable(false);
-		builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() {
-
-			public void onClick(DialogInterface dialog, int whichButton) {
-				dialog.cancel();
-			}
-		});
-		AlertDialog aboutDialog = builder.create();
-		aboutDialog.show();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		Log.d(TAG, "onCreate");
-		mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-		setContentView(R.layout.login);
-		mProgressDialog = new ProgressDialog(this);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onStop() {
-		super.onStop();
-		Log.d(TAG, "onStop " + mIsConnectedService);
-		if (mIsConfigured && (mIsConnectedService || mXmppFacade != null)) {
-			boolean isConnected = false;
-			if (mXmppConnection != null) {
-				try {
-					isConnected = mXmppConnection.isAuthentificated();
-				} catch (RemoteException e) {
-					e.printStackTrace();
-				}
-			}
-			unbindService(mServConn);
-			if (!isConnected) {
-				stopService(SERVICE_INTENT);
-			}
-			mXmppFacade = null;
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onPause() {
-		super.onPause();
-		Log.d(TAG, "onPause");
-		mConnectionHandler.removeCallbacks(mConnectionRunnable);
-		mProgressDialog.dismiss();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onResume() {
-		super.onResume();
-		Log.d(TAG, "onResume");
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onStart() {
-		super.onStart();
-		Log.d(TAG, "onStart " + mIsConnectedService);
-		mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
-		if (mIsConfigured && !mIsConnectedService) {
-			try {
-				Thread.sleep(1000); // HACK: Pour éviter de rebinder un service
-									// pas encore arreter.
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-			bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
-			mIsConnectedService = true;
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-		super.onActivityResult(requestCode, resultCode, data);
-		if (requestCode == REQUEST_CODE) {
-			if (resultCode == RESULT_OK) {
-				stopService(SERVICE_INTENT);
-			}
-		}
+	public ConnectionRunnable() {
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public boolean onCreateOptionsMenu(Menu menu) {
-		super.onCreateOptionsMenu(menu);
-		MenuInflater inflater = getMenuInflater();
-		inflater.inflate(R.menu.login, menu);
-		return true;
+	public void run() {
+	    if (mRetry++ > 3) {
+		Toast.makeText(Login.this, R.string.login_max_retry, Toast.LENGTH_LONG).show();
+		mConnectionHandler.removeCallbacks(mConnectionRunnable);
+	    } else {
+		mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
+		if (mIsConfigured) {
+		    bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+		}
+	    }
+
 	}
+    }
+
+    /**
+     * Listener use to check the state of the connection with the server.
+     */
+    private class BeemConnectionListener extends IBeemConnectionListener.Stub {
 
 	/**
-	 * Callback for menu item selected.
-	 * 
-	 * @param item
-	 *            the item selected
-	 * @return true on success, false otherwise
+	 * Constructor.
 	 */
-	@Override
-	public final boolean onOptionsItemSelected(MenuItem item) {
-		switch (item.getItemId()) {
-		case R.id.login_menu_settings:
-			startActivity(new Intent(Login.this, Settings.class));
-			return true;
-		case R.id.login_menu_about:
-			createAboutDialog();
-			return true;
-		default:
-			return false;
-		}
+	public BeemConnectionListener() {
 	}
 
 	/**
-	 * Connection runnable.
-	 * 
-	 * @author nikita
+	 * {@inheritDoc}
 	 */
-	private class ConnectionRunnable implements Runnable {
+	@Override
+	public void connectionClosed() throws RemoteException {
+	    if (mXmppFacade != null) {
+		launchReconnectionHandler();
+		mXmppFacade = null;
+	    }
+	}
 
-		/**
-		 * Constructor.
-		 */
-		public ConnectionRunnable() {
-		}
+	@Override
+	public void connectionClosedOnError() throws RemoteException {
+	    if (mXmppFacade != null) {
+		launchReconnectionHandler();
+		mXmppFacade = null;
+	    }
+	}
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void run() {
-			if (mRetry++ > 3) {
-				Toast.makeText(Login.this, R.string.login_max_retry, Toast.LENGTH_LONG).show();
-				mConnectionHandler.removeCallbacks(mConnectionRunnable);
-			} else {
-				mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
-				if (mIsConfigured) {
-					bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
-				}
-			}
+	@Override
+	public void connectionFailed(String errorMsg) throws RemoteException {
+	    Log.d(TAG, "CONNECTIONFAILLED");
+	    if (mXmppFacade != null) {
+		Login.this.unbindService(mServConn);
+		Login.this.stopService(SERVICE_INTENT);
+		mIsConnectedService = false;
+		mXmppFacade = null;
+	    }
+	    dismissProgressDialog();
+	    showToast(errorMsg);
+	    launchReconnectionHandler();
+	}
 
-		}
+	/**
+	 * launch reconnection handler.
+	 */
+	private void launchReconnectionHandler() {
+	    mConnectionHandler.postAtTime(mConnectionRunnable, Integer.parseInt(mSettings.getString(
+		"settings_key_reco_delay", "10"))
+		* 1000 + SystemClock.uptimeMillis());
 	}
 
 	/**
-	 * Listener use to check the state of the connection with the server.
+	 * Show an error message with a toast.
+	 * @param errorMsg The message to display.
 	 */
-	private class BeemConnectionListener extends IBeemConnectionListener.Stub {
-
+	private void showToast(final String errorMsg) {
+	    mConnectionHandler.post(new Runnable() {
 		/**
-		 * Constructor.
-		 */
-		public BeemConnectionListener() {
-		}
-
-		/**
-		 * {@inheritDoc}
+		 * @{inheritDoc
 		 */
 		@Override
-		public void connectionClosed() throws RemoteException {
-			if (mXmppFacade != null) {
-				launchReconnectionHandler();
-				mXmppFacade = null;
-			}
-		}
-
-		@Override
-		public void connectionClosedOnError() throws RemoteException {
-			if (mXmppFacade != null) {
-				launchReconnectionHandler();
-				mXmppFacade = null;
-			}
-		}
-
-		@Override
-		public void connectionFailed(String errorMsg) throws RemoteException {
-			Log.d(TAG, "CONNECTIONFAILLED");
-			if (mXmppFacade != null) {
-				Login.this.unbindService(mServConn);
-				Login.this.stopService(SERVICE_INTENT);
-				mIsConnectedService = false;
-				mXmppFacade = null;
-			}
-			dismissProgressDialog();
-			showToast(errorMsg);
-			launchReconnectionHandler();
-		}
-
-		/**
-		 * launch reconnection handler.
-		 */
-		private void launchReconnectionHandler() {
-			mConnectionHandler.postAtTime(mConnectionRunnable, Integer.parseInt(mSettings.getString(
-					"settings_key_reco_delay", "10"))
-					* 1000 + SystemClock.uptimeMillis());
+		public void run() {
+		    Toast.makeText(Login.this, errorMsg, Toast.LENGTH_LONG).show();
+		    TextView labelError = (TextView) findViewById(R.id.log_as_msg);
+		    labelError.setText(getString(R.string.login_error_msg, errorMsg));
 		}
-
-		/**
-		 * Show an error message with a toast.
-		 * 
-		 * @param errorMsg
-		 *            The message to display.
-		 */
-		private void showToast(final String errorMsg) {
-			mConnectionHandler.post(new Runnable() {
-				/**
-				 * @{inheritDoc
-				 */
-				@Override
-				public void run() {
-					Toast.makeText(Login.this, errorMsg, Toast.LENGTH_LONG).show();
-					TextView labelError = (TextView) findViewById(R.id.log_as_msg);
-					labelError.setText(getString(R.string.login_error_msg, errorMsg));
-				}
-			});
-		}
-
-		/**
-		 * Dismiss the progress dialog.
-		 */
-		private void dismissProgressDialog() {
-			mConnectionHandler.post(new Runnable() {
-
-				/**
-				 * @{inheritDoc
-				 */
-				@Override
-				public void run() {
-					mProgressDialog.dismiss();
-				}
-			});
-		}
-
-		@Override
-		public void onConnect() throws RemoteException {
-			dismissProgressDialog();
-			Log.i(TAG, "Connected.");
-			mXmppFacade.changeStatus(Status.CONTACT_STATUS_AVAILABLE, null);
-			mRetry = 0;
-			startActivity(new Intent(Login.this, ContactList.class));
-			finish();
-		}
-
-		@Override
-		public void reconnectingIn(int seconds) throws RemoteException {
-		}
-
-		@Override
-		public void reconnectionFailed() throws RemoteException {
-		}
-
-		@Override
-		public void reconnectionSuccessful() throws RemoteException {
-		}
+	    });
 	}
 
 	/**
-	 * ServiceConnection use to connect to the Beem Service.
+	 * Dismiss the progress dialog.
 	 */
-	private class BeemServiceConnection implements ServiceConnection {
+	private void dismissProgressDialog() {
+	    mConnectionHandler.post(new Runnable() {
+
 		/**
-		 * Constructor.
+		 * @{inheritDoc
 		 */
-		public BeemServiceConnection() {
-		}
-
 		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			Log.d(TAG, "service connected");
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-			mIsConnectedService = true;
-			try {
-				mXmppConnection = mXmppFacade.createConnection();
-				mXmppConnection.addConnectionListener(new BeemConnectionListener());
-				if (!mXmppConnection.isAuthentificated()) {
-					mConnectionHandler.post(new Runnable() {
-						@Override
-						public void run() {
-							mProgressDialog.setMessage(getString(R.string.login_login_progress));
-							mProgressDialog.show();
-						}
-					});
-					Login.this.startService(Login.SERVICE_INTENT);
-				} else {
-					startActivity(new Intent(Login.this, ContactList.class));
-					finish();
-				}
-			} catch (RemoteException e) {
-				Log.e(TAG, "REMOTE EXCEPTION $" + e.getMessage());
+		public void run() {
+		    mProgressDialog.dismiss();
+		}
+	    });
+	}
+
+	@Override
+	public void onConnect() throws RemoteException {
+	    dismissProgressDialog();
+	    Log.i(TAG, "Connected.");
+	    mXmppFacade.changeStatus(Status.CONTACT_STATUS_AVAILABLE, null);
+	    mRetry = 0;
+	    startActivity(new Intent(Login.this, ContactList.class));
+	    finish();
+	}
+
+	@Override
+	public void reconnectingIn(int seconds) throws RemoteException {
+	}
+
+	@Override
+	public void reconnectionFailed() throws RemoteException {
+	}
+
+	@Override
+	public void reconnectionSuccessful() throws RemoteException {
+	}
+    }
+
+    /**
+     * ServiceConnection use to connect to the Beem Service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
+	/**
+	 * Constructor.
+	 */
+	public BeemServiceConnection() {
+	}
+
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    Log.d(TAG, "service connected");
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mIsConnectedService = true;
+	    try {
+		mXmppConnection = mXmppFacade.createConnection();
+		mXmppConnection.addConnectionListener(new BeemConnectionListener());
+		if (!mXmppConnection.isAuthentificated()) {
+		    mConnectionHandler.post(new Runnable() {
+			@Override
+			public void run() {
+			    mProgressDialog.setMessage(getString(R.string.login_login_progress));
+			    mProgressDialog.show();
 			}
+		    });
+		    Login.this.startService(Login.SERVICE_INTENT);
+		} else {
+		    startActivity(new Intent(Login.this, ContactList.class));
+		    finish();
 		}
+	    } catch (RemoteException e) {
+		Log.e(TAG, "REMOTE EXCEPTION $" + e.getMessage());
+	    }
+	}
 
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			Log.d(TAG, "service disconnected");
-			mIsConnectedService = false;
-			mXmppFacade = null;
-		}
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    Log.d(TAG, "service disconnected");
+	    mIsConnectedService = false;
+	    mXmppFacade = null;
 	}
+    }
 }
--- a/src/com/beem/project/beem/ui/SendIM.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/SendIM.java	Wed Nov 11 19:34:04 2009 +0100
@@ -45,505 +45,495 @@
 import com.beem.project.beem.utils.Status;
 
 /**
- * This activity class provides the view for instant messaging after selecting a
- * correspondant.
- * 
+ * This activity class provides the view for instant messaging after selecting a correspondant.
  * @author barbu
  */
 
 public class SendIM extends Activity implements OnClickListener, OnKeyListener {
 
-	private static final String TAG = "SEND_IM";
-	private static final Intent SERVICE_INTENT = new Intent();
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    private static final String TAG = "SEND_IM";
+    private static final Intent SERVICE_INTENT = new Intent();
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    private IRoster mRoster;
+    private EditText mToSend;
+    private SendIMDialogSmiley mSmyDialog;
+    private SharedPreferences mSet;
+    private Handler mHandler;
+    private Contact mContact;
+    private ImageView mStatusIcon;
+    private IChatManager mChatManager;
+    private IChatManagerListener mChatManagerListener;
+    private IMessageListener mMessageListener;
+    private IChat mChat;
+    private TextView mText;
+    private TextView mLogin;
+    private ScrollView mScrolling;
+    private char mSpeak;
+
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private IXmppFacade mXmppFacade;
+    private TextView mStatusText;
+    private BeemBroadcastReceiver mReceiver;
+
+    /**
+     * Constructor.
+     */
+    public SendIM() {
+	super();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onClick(View view) {
+	sendText();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onCreate(Bundle saveBundle) {
+	super.onCreate(saveBundle);
+	// setTheme(R.style.OldTheme);
+	setContentView(R.layout.sendim);
+	mHandler = new Handler();
+	mChatManagerListener = new OnChatListener();
+	mMessageListener = new OnMessageListener();
+	mToSend = (EditText) findViewById(R.id.userText);
+	mSet = getSharedPreferences("lol", MODE_PRIVATE);
+	mSmyDialog = new SendIMDialogSmiley(this, mSet);
+	mToSend.setOnClickListener(this);
+	mToSend.setOnKeyListener(this);
+	mStatusIcon = (ImageView) findViewById(R.id.sendimstatus);
+	mLogin = (TextView) findViewById(R.id.sendimlogin);
+	mContact = new Contact(getIntent().getData());
+	mText = (TextView) findViewById(R.id.sendimlist);
+	mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
+	mStatusText = (TextView) findViewById(R.id.sendimstatusmsg);
+	mReceiver = new BeemBroadcastReceiver(mServConn);
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final boolean onCreateOptionsMenu(Menu menu) {
+	super.onCreateOptionsMenu(menu);
+	MenuInflater inflater = getMenuInflater();
+	inflater.inflate(R.menu.sendimmenu, menu);
+	return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	this.unregisterReceiver(mReceiver);
+	if (mChatManager != null) {
+	    try {
+		mChatManager.removeChatCreationListener(mChatManagerListener);
+		// TODO trouver quand detruire le chat
+		// mChatManager.destroyChat(mChat);
+	    } catch (RemoteException e) {
+		Log.e(TAG, "mchat manager and SendIM destroy", e);
+	    }
 	}
+    }
 
-	private IRoster mRoster;
-	private EditText mToSend;
-	private SendIMDialogSmiley mSmyDialog;
-	private SharedPreferences mSet;
-	private Handler mHandler;
-	private Contact mContact;
-	private ImageView mStatusIcon;
-	private IChatManager mChatManager;
-	private IChatManagerListener mChatManagerListener;
-	private IMessageListener mMessageListener;
-	private IChat mChat;
-	private TextView mText;
-	private TextView mLogin;
-	private ScrollView mScrolling;
-	private char mSpeak;
+    /**
+     * Update the status icon of our contact.
+     */
+    protected void updateStatusIcon() {
+	Drawable statusIcon = null;
+	switch (mContact.getStatus()) {
+	    case Status.CONTACT_STATUS_AVAILABLE:
+		statusIcon = getResources().getDrawable(R.drawable.status_available);
+		break;
+	    case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+		statusIcon = getResources().getDrawable(R.drawable.status_available);
+		break;
+	    case Status.CONTACT_STATUS_AWAY:
+		statusIcon = getResources().getDrawable(R.drawable.status_away);
+		break;
+	    case Status.CONTACT_STATUS_BUSY:
+		statusIcon = getResources().getDrawable(R.drawable.status_dnd);
+		break;
+	    case Status.CONTACT_STATUS_DISCONNECT:
+		statusIcon = getResources().getDrawable(R.drawable.status_offline);
+		break;
+	    case Status.CONTACT_STATUS_UNAVAILABLE:
+		statusIcon = getResources().getDrawable(R.drawable.status_requested);
+		break;
+	    default:
+		statusIcon = getResources().getDrawable(R.drawable.status_error);
+		break;
+	}
+	Log.d("SENDIM -- UPDATE STATUS ICON", "Contact current status: " + mContact.getStatus() + "");
+	mStatusIcon.setImageDrawable(statusIcon);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean onKey(View v, int keyCode, KeyEvent event) {
+	if (event.getAction() == KeyEvent.ACTION_DOWN) {
+	    switch (keyCode) {
+		case KeyEvent.KEYCODE_DPAD_CENTER:
+		case KeyEvent.KEYCODE_ENTER:
+		    sendText();
+		    return true;
+		default:
+		    return false;
+	    }
+	}
+	return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onNewIntent(Intent intent) {
+	super.onNewIntent(intent);
+	mContact = new Contact(intent.getData());
+	try {
+	    if (mRoster != null)
+		mContact = mRoster.getContact(mContact.getJID());
+	} catch (RemoteException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+    }
 
-	private final ServiceConnection mServConn = new BeemServiceConnection();
-	private IXmppFacade mXmppFacade;
-	private TextView mStatusText;
-	private BeemBroadcastReceiver mReceiver;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final boolean onOptionsItemSelected(MenuItem item) {
+	switch (item.getItemId()) {
+	    case R.id.sendim_smiley:
+		mSmyDialog.show();
+		return true;
+	    case R.id.sendim_call:
+		// TODO start the jingle call
+		// Bug a besoin du jid complet (resource compris)
+		try {
+		    mXmppFacade.call(mContact.getJID());
+		} catch (RemoteException e) {
+		    // TODO Auto-generated catch block
+		    e.printStackTrace();
+		}
+		return true;
+	    default:
+		return false;
+	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onStop() {
+	super.onStop();
+	try {
+	    if (mChat != null)
+		mChat.setOpen(false);
+	} catch (RemoteException e) {
+	    Log.d(TAG, "Error while closing chat", e);
+	}
+	if (mReceiver.isBinded()) {
+	    unbindService(mServConn);
+	    mReceiver.setBinded(false);
+	}
+	mRoster = null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onStart() {
+	super.onStart();
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+	try {
+	    if (mRoster != null)
+		mContact = mRoster.getContact(mContact.getJID());
+	} catch (RemoteException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+    }
+
+    /**
+     * The service connection used to connect with the BeemService.
+     */
+    private final class BeemServiceConnection implements ServiceConnection {
+	private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
 
 	/**
 	 * Constructor.
 	 */
-	public SendIM() {
-		super();
+	public BeemServiceConnection() {
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
 	@Override
-	public void onClick(View view) {
-		sendText();
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mReceiver.setBinded(true);
+	    try {
+		if (mChatManager == null) {
+		    mChatManager = mXmppFacade.getChatManager();
+		    mChatManager.addChatCreationListener(mChatManagerListener);
+		}
+		mRoster = mXmppFacade.getRoster();
+		if (mRoster != null) {
+		    mRoster.addRosterListener(mBeemRosterListener);
+		    // mContact.setStatus(mRoster.getPresence(mContact.getJID()));
+		    if (mRoster.getContact(mContact.getJID()) != null) {
+			mContact = mRoster.getContact(mContact.getJID());
+			mStatusText.setText(mContact.getMsgState());
+			mLogin.setText(mContact.getName());
+		    }
+		    updateStatusIcon();
+		}
+		switchChat(mContact);
+	    } catch (RemoteException e) {
+		Log.e(TAG, "Error during chat manager creation", e);
+	    }
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
 	@Override
-	protected void onCreate(Bundle saveBundle) {
-		super.onCreate(saveBundle);
-		// setTheme(R.style.OldTheme);
-		setContentView(R.layout.sendim);
-		mHandler = new Handler();
-		mChatManagerListener = new OnChatListener();
-		mMessageListener = new OnMessageListener();
-		mToSend = (EditText) findViewById(R.id.userText);
-		mSet = getSharedPreferences("lol", MODE_PRIVATE);
-		mSmyDialog = new SendIMDialogSmiley(this, mSet);
-		mToSend.setOnClickListener(this);
-		mToSend.setOnKeyListener(this);
-		mStatusIcon = (ImageView) findViewById(R.id.sendimstatus);
-		mLogin = (TextView) findViewById(R.id.sendimlogin);
-		mContact = new Contact(getIntent().getData());
-		mText = (TextView) findViewById(R.id.sendimlist);
-		mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
-		mStatusText = (TextView) findViewById(R.id.sendimstatusmsg);
-		mReceiver = new BeemBroadcastReceiver(mServConn);
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+	public void onServiceDisconnected(ComponentName name) {
+	    mReceiver.setBinded(false);
+	    mXmppFacade = null;
+	    try {
+		mRoster.removeRosterListener(mBeemRosterListener);
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
+	    mRoster = null;
 	}
+    }
+
+    /**
+     * Send a message to the contact over the XMPP connection. Also display it on activity view. TODO : Gerer
+     * l'exception si la connexion se coupe pendant la conversation
+     */
+    private void sendText() {
+	String text = mToSend.getText().toString();
+	if (!"".equals(text)) {
+	    Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
+	    msg.setBody(text);
+	    try {
+		mChat.sendMessage(msg);
+		if (mSpeak != 1)
+		    mText.append(getString(R.string.SendIMYouSay, text));
+		else
+		    mText.append(getString(R.string.SendIMSameSpeaker, text));
+		mToSend.setText(null);
+		mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+		mToSend.requestFocus();
+		mSpeak = 1;
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
+	}
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public final boolean onCreateOptionsMenu(Menu menu) {
-		super.onCreateOptionsMenu(menu);
-		MenuInflater inflater = getMenuInflater();
-		inflater.inflate(R.menu.sendimmenu, menu);
-		return true;
+    /**
+     * Show the message history.
+     * @param messages list of message to display
+     */
+    private void showMessageList(List<Message> messages) {
+	mText.setText("");
+	mSpeak = 0;
+	for (Message message : messages) {
+	    String from = message.getFrom();
+	    if (from == null) {
+		if (mSpeak != 1)
+		    mText.append(getString(R.string.SendIMYouSay, message.getBody()));
+		else
+		    mText.append(getString(R.string.SendIMYouSay, message.getBody()));
+		mSpeak = 1;
+	    } else {
+		if (mSpeak != 2)
+		    mText.append(getString(R.string.SendIMSays, mContact.getName(), message.getBody()));
+		else
+		    mText.append(getString(R.string.SendIMSameSpeaker, message.getBody()));
+		mSpeak = 2;
+	    }
 	}
+	mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		this.unregisterReceiver(mReceiver);
-		if (mChatManager != null) {
-			try {
-				mChatManager.removeChatCreationListener(mChatManagerListener);
-				// TODO trouver quand detruire le chat
-				// mChatManager.destroyChat(mChat);
-			} catch (RemoteException e) {
-				Log.e(TAG, "mchat manager and SendIM destroy", e);
-			}
-		}
-	}
+    /**
+     * Change the correspondant of the chat.
+     * @param newContact New contact to chat with
+     * @throws RemoteException if an errors occurs in the connection with the service
+     */
+    private void switchChat(Contact newContact) throws RemoteException {
+	if (mChat != null)
+	    mChat.setOpen(false);
+	mChat = mChatManager.createChat(newContact, mMessageListener);
+	showMessageList(mChat.getMessages());
+	mChat.setOpen(true);
+	mChatManager.deleteChatNotification(mChat);
+	mContact = newContact;
+	mToSend.requestFocus();
+    }
+
+    /**
+     * Listener for chat creation. (maybe not necessary).
+     * @author darisk
+     */
+    private class OnChatListener extends IChatManagerListener.Stub {
 
 	/**
-	 * Update the status icon of our contact.
-	 */
-	protected void updateStatusIcon() {
-		Drawable statusIcon = null;
-		switch (mContact.getStatus()) {
-		case Status.CONTACT_STATUS_AVAILABLE:
-			statusIcon = getResources().getDrawable(R.drawable.status_available);
-			break;
-		case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
-			statusIcon = getResources().getDrawable(R.drawable.status_available);
-			break;
-		case Status.CONTACT_STATUS_AWAY:
-			statusIcon = getResources().getDrawable(R.drawable.status_away);
-			break;
-		case Status.CONTACT_STATUS_BUSY:
-			statusIcon = getResources().getDrawable(R.drawable.status_dnd);
-			break;
-		case Status.CONTACT_STATUS_DISCONNECT:
-			statusIcon = getResources().getDrawable(R.drawable.status_offline);
-			break;
-		case Status.CONTACT_STATUS_UNAVAILABLE:
-			statusIcon = getResources().getDrawable(R.drawable.status_requested);
-			break;
-		default:
-			statusIcon = getResources().getDrawable(R.drawable.status_error);
-			break;
-		}
-		Log.d("SENDIM -- UPDATE STATUS ICON", "Contact current status: " + mContact.getStatus() + "");
-		mStatusIcon.setImageDrawable(statusIcon);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean onKey(View v, int keyCode, KeyEvent event) {
-		if (event.getAction() == KeyEvent.ACTION_DOWN) {
-			switch (keyCode) {
-			case KeyEvent.KEYCODE_DPAD_CENTER:
-			case KeyEvent.KEYCODE_ENTER:
-				sendText();
-				return true;
-			default:
-				return false;
-			}
-		}
-		return false;
-	}
-
-	/**
-	 * {@inheritDoc}
+	 * Constructor.
 	 */
-	@Override
-	protected void onNewIntent(Intent intent) {
-		super.onNewIntent(intent);
-		mContact = new Contact(intent.getData());
-		try {
-			if (mRoster != null)
-				mContact = mRoster.getContact(mContact.getJID());
-		} catch (RemoteException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public final boolean onOptionsItemSelected(MenuItem item) {
-		switch (item.getItemId()) {
-		case R.id.sendim_smiley:
-			mSmyDialog.show();
-			return true;
-		case R.id.sendim_call:
-			// TODO start the jingle call
-			// Bug a besoin du jid complet (resource compris)
-			try {
-				mXmppFacade.call(mContact.getJID());
-			} catch (RemoteException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-			return true;
-		default:
-			return false;
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onStop() {
-		super.onStop();
-		try {
-			if (mChat != null)
-				mChat.setOpen(false);
-		} catch (RemoteException e) {
-			Log.d(TAG, "Error while closing chat", e);
-		}
-		if (mReceiver.isBinded()) {
-			unbindService(mServConn);
-			mReceiver.setBinded(false);
-		}
-		mRoster = null;
+	public OnChatListener() {
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected void onStart() {
-		super.onStart();
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
-		try {
-			if (mRoster != null)
-				mContact = mRoster.getContact(mContact.getJID());
-		} catch (RemoteException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
+	public void chatCreated(IChat chat, boolean locally) throws RemoteException {
+	    Log.i("LOG", "chatCreated");
 	}
 
-	/**
-	 * The service connection used to connect with the BeemService.
-	 */
-	private final class BeemServiceConnection implements ServiceConnection {
-		private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
-
-		/**
-		 * Constructor.
-		 */
-		public BeemServiceConnection() {
-		}
+    }
 
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-			mReceiver.setBinded(true);
-			try {
-				if (mChatManager == null) {
-					mChatManager = mXmppFacade.getChatManager();
-					mChatManager.addChatCreationListener(mChatManagerListener);
-				}
-				mRoster = mXmppFacade.getRoster();
-				if (mRoster != null) {
-					mRoster.addRosterListener(mBeemRosterListener);
-					// mContact.setStatus(mRoster.getPresence(mContact.getJID()));
-					if (mRoster.getContact(mContact.getJID()) != null) {
-						mContact = mRoster.getContact(mContact.getJID());
-						mStatusText.setText(mContact.getMsgState());
-						mLogin.setText(mContact.getName());
-					}
-					updateStatusIcon();
-				}
-				switchChat(mContact);
-			} catch (RemoteException e) {
-				Log.e(TAG, "Error during chat manager creation", e);
-			}
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mReceiver.setBinded(false);
-			mXmppFacade = null;
-			try {
-				mRoster.removeRosterListener(mBeemRosterListener);
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-			mRoster = null;
-		}
-	}
+    /**
+     * Listener use to change the status displayed.
+     */
+    private class BeemRosterListener extends IBeemRosterListener.Stub {
 
 	/**
-	 * Send a message to the contact over the XMPP connection. Also display it
-	 * on activity view. TODO : Gerer l'exception si la connexion se coupe
-	 * pendant la conversation
+	 * Constructor.
 	 */
-	private void sendText() {
-		String text = mToSend.getText().toString();
-		if (!"".equals(text)) {
-			Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
-			msg.setBody(text);
-			try {
-				mChat.sendMessage(msg);
-				if (mSpeak != 1)
-					mText.append(getString(R.string.SendIMYouSay, text));
-				else
-					mText.append(getString(R.string.SendIMSameSpeaker, text));
-				mToSend.setText(null);
-				mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
-				mToSend.requestFocus();
-				mSpeak = 1;
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-		}
+	public BeemRosterListener() {
+	}
+
+	@Override
+	public void onEntriesAdded(List<String> addresses) throws RemoteException {
+	    // TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void onEntriesDeleted(List<String> addresses) throws RemoteException {
+	    // TODO Auto-generated method stub
+
 	}
 
-	/**
-	 * Show the message history.
-	 * 
-	 * @param messages
-	 *            list of message to display
-	 */
-	private void showMessageList(List<Message> messages) {
-		mText.setText("");
-		mSpeak = 0;
-		for (Message message : messages) {
-			String from = message.getFrom();
-			if (from == null) {
-				if (mSpeak != 1)
-					mText.append(getString(R.string.SendIMYouSay, message.getBody()));
-				else
-					mText.append(getString(R.string.SendIMYouSay, message.getBody()));
-				mSpeak = 1;
-			} else {
-				if (mSpeak != 2)
-					mText.append(getString(R.string.SendIMSays, mContact.getName(), message.getBody()));
-				else
-					mText.append(getString(R.string.SendIMSameSpeaker, message.getBody()));
-				mSpeak = 2;
-			}
-		}
-		mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+	@Override
+	public void onEntriesUpdated(List<String> addresses) throws RemoteException {
+	    // TODO Auto-generated method stub
+
 	}
 
-	/**
-	 * Change the correspondant of the chat.
-	 * 
-	 * @param newContact
-	 *            New contact to chat with
-	 * @throws RemoteException
-	 *             if an errors occurs in the connection with the service
-	 */
-	private void switchChat(Contact newContact) throws RemoteException {
-		if (mChat != null)
-			mChat.setOpen(false);
-		mChat = mChatManager.createChat(newContact, mMessageListener);
-		showMessageList(mChat.getMessages());
-		mChat.setOpen(true);
-		mChatManager.deleteChatNotification(mChat);
-		mContact = newContact;
-		mToSend.requestFocus();
+	@Override
+	public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
+	    // TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
+	    if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
+		mContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
+		Log.d("SENDIM -- onPresenceChanged", "Contact current status: " + mContact.getStatus() + "");
+		mHandler.post(new RunnableChange());
+	    }
 	}
 
 	/**
-	 * Listener for chat creation. (maybe not necessary).
-	 * 
-	 * @author darisk
+	 * Runnable to change the status displayed.
 	 */
-	private class OnChatListener extends IChatManagerListener.Stub {
+	private class RunnableChange implements Runnable {
+
+	    /**
+	     * Constructor.
+	     */
+	    public RunnableChange() {
+	    }
 
-		/**
-		 * Constructor.
-		 */
-		public OnChatListener() {
-		}
+	    @Override
+	    public void run() {
+		updateStatusIcon();
+		mStatusText.setText(mContact.getMsgState());
+		Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
+	    }
+	}
+    }
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void chatCreated(IChat chat, boolean locally) throws RemoteException {
-			Log.i("LOG", "chatCreated");
-		}
+    /**
+     * Listener for new chat messages.
+     * @author darisk
+     */
+    private class OnMessageListener extends IMessageListener.Stub {
 
+	/**
+	 * Constructor.
+	 */
+	public OnMessageListener() {
 	}
 
 	/**
-	 * Listener use to change the status displayed.
+	 * {@inheritDoc}
 	 */
-	private class BeemRosterListener extends IBeemRosterListener.Stub {
-
-		/**
-		 * Constructor.
-		 */
-		public BeemRosterListener() {
-		}
-
-		@Override
-		public void onEntriesAdded(List<String> addresses) throws RemoteException {
-			// TODO Auto-generated method stub
+	@Override
+	public void processMessage(IChat chat, Message msg) throws RemoteException {
 
-		}
-
-		@Override
-		public void onEntriesDeleted(List<String> addresses) throws RemoteException {
-			// TODO Auto-generated method stub
-
-		}
-
-		@Override
-		public void onEntriesUpdated(List<String> addresses) throws RemoteException {
-			// TODO Auto-generated method stub
-
-		}
+	    if (chat != mChat)
+		return;
+	    final Message m = msg;
+	    Log.d("Message Type", "Le type du message : " + m.getType());
+	    mHandler.post(new Runnable() {
 
 		@Override
-		public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
-			// TODO Auto-generated method stub
-
-		}
-
-		@Override
-		public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
-			if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
-				mContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
-				Log.d("SENDIM -- onPresenceChanged", "Contact current status: " + mContact.getStatus() + "");
-				mHandler.post(new RunnableChange());
-			}
+		public void run() {
+		    if (m.getBody() != null) {
+			if (m.getType() == Message.MSG_TYPE_ERROR) {
+			    mText.append(getString(R.string.SendIMErrorMsg, m.getBody()));
+			    mSpeak = 0;
+			} else if (mSpeak == 2)
+			    mText.append(getString(R.string.SendIMSameSpeaker, m.getBody()));
+			else
+			    mText.append(getString(R.string.SendIMSays, mContact.getName(), m.getBody()));
+			mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+			mToSend.requestFocus();
+			mSpeak = 2;
+		    }
 		}
-
-		/**
-		 * Runnable to change the status displayed.
-		 */
-		private class RunnableChange implements Runnable {
-
-			/**
-			 * Constructor.
-			 */
-			public RunnableChange() {
-			}
-
-			@Override
-			public void run() {
-				updateStatusIcon();
-				mStatusText.setText(mContact.getMsgState());
-				Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
-			}
-		}
+	    });
 	}
 
 	/**
-	 * Listener for new chat messages.
-	 * 
-	 * @author darisk
+	 * {@inheritDoc}
 	 */
-	private class OnMessageListener extends IMessageListener.Stub {
-
-		/**
-		 * Constructor.
-		 */
-		public OnMessageListener() {
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void processMessage(IChat chat, Message msg) throws RemoteException {
-
-			if (chat != mChat)
-				return;
-			final Message m = msg;
-			Log.d("Message Type", "Le type du message : " + m.getType());
-			mHandler.post(new Runnable() {
+	@Override
+	public void stateChanged(IChat chat) throws RemoteException {
+	    if (chat != mChat)
+		return;
+	    Log.d("ChatState", "Action du correspondant : <--- " + chat.getState() + " --->");
+	    mHandler.post(new Runnable() {
 
-				@Override
-				public void run() {
-					if (m.getBody() != null) {
-						if (m.getType() == Message.MSG_TYPE_ERROR) {
-							mText.append(getString(R.string.SendIMErrorMsg, m.getBody()));
-							mSpeak = 0;
-						} else if (mSpeak == 2)
-							mText.append(getString(R.string.SendIMSameSpeaker, m.getBody()));
-						else
-							mText.append(getString(R.string.SendIMSays, mContact.getName(), m.getBody()));
-						mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
-						mToSend.requestFocus();
-						mSpeak = 2;
-					}
-				}
-			});
+		@Override
+		public void run() {
 		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void stateChanged(IChat chat) throws RemoteException {
-			if (chat != mChat)
-				return;
-			Log.d("ChatState", "Action du correspondant : <--- " + chat.getState() + " --->");
-			mHandler.post(new Runnable() {
-
-				@Override
-				public void run() {
-				}
-			});
-		}
+	    });
 	}
+    }
 }
--- a/src/com/beem/project/beem/ui/SendIMDialogSmiley.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/SendIMDialogSmiley.java	Wed Nov 11 19:34:04 2009 +0100
@@ -10,29 +10,26 @@
  */
 public class SendIMDialogSmiley extends Dialog {
 
-	@SuppressWarnings("unused")
-	private SendIM mSendIM;
-	@SuppressWarnings("unused")
-	private SharedPreferences mSet;
+    @SuppressWarnings("unused")
+    private SendIM mSendIM;
+    @SuppressWarnings("unused")
+    private SharedPreferences mSet;
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param sendim
-	 *            unused
-	 * @param settings
-	 *            unused
-	 */
-	public SendIMDialogSmiley(final SendIM sendim, final SharedPreferences settings) {
-		super(sendim);
-		this.mSendIM = sendim;
-		this.mSet = settings;
-	}
+    /**
+     * Constructor.
+     * @param sendim unused
+     * @param settings unused
+     */
+    public SendIMDialogSmiley(final SendIM sendim, final SharedPreferences settings) {
+	super(sendim);
+	this.mSendIM = sendim;
+	this.mSet = settings;
+    }
 
-	@Override
-	protected void onStart() {
-		super.onStart();
-		setContentView(R.layout.sendimdialogsmiley);
-		setTitle("Select a smiley");
-	}
+    @Override
+    protected void onStart() {
+	super.onStart();
+	setContentView(R.layout.sendimdialogsmiley);
+	setTitle("Select a smiley");
+    }
 }
--- a/src/com/beem/project/beem/ui/Settings.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/Settings.java	Wed Nov 11 19:34:04 2009 +0100
@@ -16,113 +16,111 @@
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
 
 /**
- * This class represents an activity which allows the user to change his account
- * or proxy parameters.
- * 
+ * This class represents an activity which allows the user to change his account or proxy parameters.
  * @author nikita
  */
 public class Settings extends PreferenceActivity {
 
-	private static final Intent SERVICE_INTENT = new Intent();
-	private SettingsBroadcastReceiver mReceiver;
+    private static final Intent SERVICE_INTENT = new Intent();
+    private SettingsBroadcastReceiver mReceiver;
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    /**
+     * Constructor.
+     */
+    public Settings() {
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	addPreferencesFromResource(R.layout.preferences);
+	mReceiver = new SettingsBroadcastReceiver();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onPause() {
+	super.onPause();
+	this.unregisterReceiver(mReceiver);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onResume() {
+	super.onResume();
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    }
 
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onStop() {
+	super.onStop();
+	SharedPreferences settings = getPreferenceManager().getSharedPreferences();
+	settings.edit().putBoolean(
+	    "PreferenceIsConfigured",
+	    !"".equals(settings.getString("settings_key_account_username", ""))
+		|| !"".equals(settings.getString("settings_key_account_password", ""))).commit();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+	MenuInflater mInflater = getMenuInflater();
+	mInflater.inflate(R.menu.edit_settings, menu);
+	return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+	Intent i = null;
+	switch (item.getItemId()) {
+	    case R.id.settings_menu_create_account:
+		i = new Intent(this, CreateAccount.class);
+		startActivity(i);
+		return true;
+	    case R.id.settings_menu_login:
+		setResult(RESULT_OK);
+		SharedPreferences settings = getPreferenceManager().getSharedPreferences();
+		settings.edit().putBoolean(
+		    "PreferenceIsConfigured",
+		    !"".equals(settings.getString("settings_key_account_username", ""))
+			|| !"".equals(settings.getString("settings_key_account_password", ""))).commit();
+		this.stopService(SERVICE_INTENT);
+		finish();
+		return true;
+	    default:
+		return false;
 	}
+    }
 
+    /**
+     * disconnect Broadcast receiver.
+     */
+    private class SettingsBroadcastReceiver extends BroadcastReceiver {
 	/**
 	 * Constructor.
 	 */
-	public Settings() {
+	public SettingsBroadcastReceiver() {
 	}
 
 	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		addPreferencesFromResource(R.layout.preferences);
-		mReceiver = new SettingsBroadcastReceiver();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onPause() {
-		super.onPause();
-		this.unregisterReceiver(mReceiver);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onResume() {
-		super.onResume();
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onStop() {
-		super.onStop();
-		SharedPreferences settings = getPreferenceManager().getSharedPreferences();
-		settings.edit().putBoolean(
-				"PreferenceIsConfigured",
-				!"".equals(settings.getString("settings_key_account_username", ""))
-						|| !"".equals(settings.getString("settings_key_account_password", ""))).commit();
+	public void onReceive(Context context, Intent intent) {
+	    Settings.this.setResult(RESULT_CANCELED);
 	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean onCreateOptionsMenu(Menu menu) {
-		MenuInflater mInflater = getMenuInflater();
-		mInflater.inflate(R.menu.edit_settings, menu);
-		return true;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean onOptionsItemSelected(MenuItem item) {
-		Intent i = null;
-		switch (item.getItemId()) {
-		case R.id.settings_menu_create_account:
-			i = new Intent(this, CreateAccount.class);
-			startActivity(i);
-			return true;
-		case R.id.settings_menu_login:
-			setResult(RESULT_OK);
-			SharedPreferences settings = getPreferenceManager().getSharedPreferences();
-			settings.edit().putBoolean(
-					"PreferenceIsConfigured",
-					!"".equals(settings.getString("settings_key_account_username", ""))
-							|| !"".equals(settings.getString("settings_key_account_password", ""))).commit();
-			this.stopService(SERVICE_INTENT);
-			finish();
-			return true;
-		default:
-			return false;
-		}
-	}
-
-	/**
-	 * disconnect Broadcast receiver.
-	 */
-	private class SettingsBroadcastReceiver extends BroadcastReceiver {
-		/**
-		 * Constructor.
-		 */
-		public SettingsBroadcastReceiver() {
-		}
-
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			Settings.this.setResult(RESULT_CANCELED);
-		}
-	}
+    }
 }
--- a/src/com/beem/project/beem/ui/Subscription.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/Subscription.java	Wed Nov 11 19:34:04 2009 +0100
@@ -24,121 +24,122 @@
 
 /**
  * This activity is used to accept a subscription request.
- * 
  * @author nikita
  */
 public class Subscription extends Activity {
 
-	private static final Intent SERVICE_INTENT = new Intent();
-	private IXmppFacade mService;
-	private String mContact;
-	private ServiceConnection mServConn = new BeemServiceConnection();
-	private BeemBroadcastReceiver mReceiver;
-	private MyOnClickListener mClickListener = new MyOnClickListener();
+    private static final Intent SERVICE_INTENT = new Intent();
+    private IXmppFacade mService;
+    private String mContact;
+    private ServiceConnection mServConn = new BeemServiceConnection();
+    private BeemBroadcastReceiver mReceiver;
+    private MyOnClickListener mClickListener = new MyOnClickListener();
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    /**
+     * Constructor.
+     */
+    public Subscription() {
+    }
 
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.subscription);
+	mReceiver = new BeemBroadcastReceiver(mServConn);
+	findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener);
+	findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener);
+	mContact = getIntent().getStringExtra("from");
+	TextView tv = (TextView) findViewById(R.id.SubscriptionText);
+	String str = String.format(getString(R.string.SubscriptText), mContact);
+	tv.setText(str);
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    }
+
+    @Override
+    protected void onResume() {
+	super.onResume();
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	mReceiver.setBinded(true);
+    }
+
+    @Override
+    protected void onPause() {
+	super.onPause();
+	if (mReceiver.isBinded()) {
+	    unbindService(mServConn);
+	    mReceiver.setBinded(false);
 	}
+    }
+
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	this.unregisterReceiver(mReceiver);
+    }
+
+    /**
+     * Event simple click on buttons.
+     */
+    private class MyOnClickListener implements OnClickListener {
 
 	/**
 	 * Constructor.
 	 */
-	public Subscription() {
-	}
-
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.subscription);
-		mReceiver = new BeemBroadcastReceiver(mServConn);
-		findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener);
-		findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener);
-		mContact = getIntent().getStringExtra("from");
-		TextView tv = (TextView) findViewById(R.id.SubscriptionText);
-		String str = String.format(getString(R.string.SubscriptText), mContact);
-		tv.setText(str);
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-	}
-
-	@Override
-	protected void onResume() {
-		super.onResume();
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		mReceiver.setBinded(true);
-	}
-
-	@Override
-	protected void onPause() {
-		super.onPause();
-		if (mReceiver.isBinded()) {
-			unbindService(mServConn);
-			mReceiver.setBinded(false);
-		}
+	public MyOnClickListener() {
 	}
 
 	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		this.unregisterReceiver(mReceiver);
+	public void onClick(View v) {
+	    switch (v.getId()) {
+		case R.id.SubscriptionAccept:
+		    Presence presence = new Presence(Type.subscribed);
+		    presence.setTo(mContact);
+		    PresenceAdapter preAdapt = new PresenceAdapter(presence);
+		    try {
+			mService.sendPresencePacket(preAdapt);
+			Toast.makeText(Subscription.this, getString(R.string.SubscriptAccept), Toast.LENGTH_SHORT)
+			    .show();
+			finish();
+		    } catch (RemoteException e) {
+			Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT)
+			    .show();
+			e.printStackTrace();
+		    }
+		    break;
+		case R.id.SubscriptionRefuse:
+		    Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused), Toast.LENGTH_SHORT).show();
+
+		    break;
+		default:
+		    Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT).show();
+	    }
 	}
+    };
+
+    /**
+     * The ServiceConnection used to connect to the Beem service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
 
 	/**
-	 * Event simple click on buttons.
+	 * Constructor.
 	 */
-	private class MyOnClickListener implements OnClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public MyOnClickListener() {
-		}
-
-		@Override
-		public void onClick(View v) {
-			switch (v.getId()) {
-			case R.id.SubscriptionAccept:
-				Presence presence = new Presence(Type.subscribed);
-				presence.setTo(mContact);
-				PresenceAdapter preAdapt = new PresenceAdapter(presence);
-				try {
-					mService.sendPresencePacket(preAdapt);
-					Toast.makeText(Subscription.this, getString(R.string.SubscriptAccept), Toast.LENGTH_SHORT).show();
-					finish();
-				} catch (RemoteException e) {
-					Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT).show();
-					e.printStackTrace();
-				}
-				break;
-			case R.id.SubscriptionRefuse:
-				Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused), Toast.LENGTH_SHORT).show();
+	public BeemServiceConnection() {
+	}
 
-				break;
-			default:
-				Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT).show();
-			}
-		}
-	};
-
-	/**
-	 * The ServiceConnection used to connect to the Beem service.
-	 */
-	private class BeemServiceConnection implements ServiceConnection {
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mService = IXmppFacade.Stub.asInterface(service);
+	    mReceiver.setBinded(true);
+	}
 
-		/**
-		 * Constructor.
-		 */
-		public BeemServiceConnection() {
-		}
-
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mService = IXmppFacade.Stub.asInterface(service);
-			mReceiver.setBinded(true);
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mService = null;
-		}
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    mService = null;
 	}
+    }
 }
--- a/src/com/beem/project/beem/ui/UserInfo.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/ui/UserInfo.java	Wed Nov 11 19:34:04 2009 +0100
@@ -34,342 +34,337 @@
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
 
 /**
- * This activity class provides the view for user infos after long click on a
- * correspondant.
- * 
+ * This activity class provides the view for user infos after long click on a correspondant.
  * @author marseille
  */
 public class UserInfo extends Activity {
 
-	private static final Intent SERVICE_INTENT = new Intent();
-	private final ServiceConnection mServConn = new BeemServiceConnection();
-	private TextView mTextAlias;
-	private Gallery mGalleryGroups;
-	private Contact mContact;
-	private IXmppFacade mXmppFacade;
-	private BeemBroadcastReceiver mReceiver;
-	private String mJID;
-	private IRoster mRoster;
+    private static final Intent SERVICE_INTENT = new Intent();
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private TextView mTextAlias;
+    private Gallery mGalleryGroups;
+    private Contact mContact;
+    private IXmppFacade mXmppFacade;
+    private BeemBroadcastReceiver mReceiver;
+    private String mJID;
+    private IRoster mRoster;
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
+
+    /**
+     * Constructor.
+     */
+    public UserInfo() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.userinfo);
+	View v = (View) findViewById(R.id.userinfo_layout_alias);
+	v.setOnClickListener(new AliasListener());
+	v = findViewById(R.id.userinfo_layout_delete);
+	v.setOnClickListener(new DeleteListener());
+	v = findViewById(R.id.userinfo_layout_chg_group);
+	v.setOnClickListener(new GroupListener());
+	v = findViewById(R.id.userinfo_layout_re_suscription);
+	v.setOnClickListener(new ResendListener());
+	mTextAlias = (TextView) findViewById(R.id.userinfo_alias);
+	mGalleryGroups = (Gallery) findViewById(R.id.userinfo_groups);
+	mReceiver = new BeemBroadcastReceiver(mServConn);
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onResume() {
+	super.onResume();
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+    }
 
-	static {
-		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onPause() {
+	super.onPause();
+	if (mReceiver.isBinded()) {
+	    unbindService(mServConn);
+	    mReceiver.setBinded(false);
+	}
+    }
+
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	this.unregisterReceiver(mReceiver);
+    }
+
+    /**
+     * Event simple click on layout alias.
+     */
+    private class AliasListener implements View.OnClickListener {
+	/**
+	 * Constructor.
+	 */
+	public AliasListener() {
 	}
 
+	@Override
+	public void onClick(View v) {
+	    Dialog d = new DialogAlias();
+	    d.show();
+	}
+    }
+
+    /**
+     * Event simple click on layout group.
+     */
+    private class GroupListener implements View.OnClickListener {
+	/**
+	 * Constructor.
+	 */
+	public GroupListener() {
+	}
+
+	@Override
+	public void onClick(View v) {
+	    Intent i = new Intent(UserInfo.this, GroupList.class);
+	    i.putExtra("contact", mContact);
+	    startActivity(i);
+	}
+
+    }
+
+    /**
+     * Create dialog alias.
+     */
+    public class DialogAlias extends Dialog {
+
 	/**
 	 * Constructor.
 	 */
-	public UserInfo() {
+	public DialogAlias() {
+	    super(UserInfo.this);
+	    setContentView(R.layout.contactdialogaliasdialog);
+	    setTitle(mContact.getJID());
+	    EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
+	    if (mContact.getName().length() == 0)
+		nameText.setText(mContact.getJID());
+	    else
+		nameText.setText(mContact.getName());
+	    Button ok = (Button) findViewById(R.id.CDAliasDialogOk);
+	    ok.setOnClickListener(new ContactDialogAliasDialogOK());
 	}
 
 	/**
-	 * {@inheritDoc}
+	 * Event click on the button OK.
 	 */
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.userinfo);
-		View v = (View) findViewById(R.id.userinfo_layout_alias);
-		v.setOnClickListener(new AliasListener());
-		v = findViewById(R.id.userinfo_layout_delete);
-		v.setOnClickListener(new DeleteListener());
-		v = findViewById(R.id.userinfo_layout_chg_group);
-		v.setOnClickListener(new GroupListener());
-		v = findViewById(R.id.userinfo_layout_re_suscription);
-		v.setOnClickListener(new ResendListener());
-		mTextAlias = (TextView) findViewById(R.id.userinfo_alias);
-		mGalleryGroups = (Gallery) findViewById(R.id.userinfo_groups);
-		mReceiver = new BeemBroadcastReceiver(mServConn);
-		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+	private class ContactDialogAliasDialogOK implements View.OnClickListener {
+
+	    /**
+	     * Constructor.
+	     */
+	    public ContactDialogAliasDialogOK() {
+	    }
+
+	    @Override
+	    public void onClick(View v) {
+		try {
+		    EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
+		    String name = nameText.getText().toString();
+		    if (name.length() == 0)
+			name = mContact.getJID();
+		    mRoster.setContactName(mContact.getJID(), name);
+		    mContact.setName(name);
+		    mTextAlias.setText(name);
+
+		} catch (RemoteException e) {
+		    e.printStackTrace();
+		}
+		dismiss();
+	    }
 	}
+    }
+
+    /**
+     * Adapter group horizontal list.
+     */
+    public class BeemGroups extends BaseAdapter {
+	private Context mContext;
+	private List<String> mListGroup;
 
 	/**
-	 * {@inheritDoc}
+	 * Constructor.
+	 * @param c context activity.
+	 * @param listGroup the user group list.
 	 */
-	@Override
-	protected void onResume() {
-		super.onResume();
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	public BeemGroups(final Context c, final List<String> listGroup) {
+	    mContext = c;
+	    if (listGroup.size() == 0)
+		listGroup.add(getString(R.string.contact_list_no_group));
+	    mListGroup = listGroup;
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected void onPause() {
-		super.onPause();
-		if (mReceiver.isBinded()) {
-			unbindService(mServConn);
-			mReceiver.setBinded(false);
-		}
-	}
-
-	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		this.unregisterReceiver(mReceiver);
-	}
-
-	/**
-	 * Event simple click on layout alias.
-	 */
-	private class AliasListener implements View.OnClickListener {
-		/**
-		 * Constructor.
-		 */
-		public AliasListener() {
-		}
-
-		@Override
-		public void onClick(View v) {
-			Dialog d = new DialogAlias();
-			d.show();
-		}
+	public int getCount() {
+	    return mListGroup.size();
 	}
 
 	/**
-	 * Event simple click on layout group.
+	 * {@inheritDoc}
 	 */
-	private class GroupListener implements View.OnClickListener {
-		/**
-		 * Constructor.
-		 */
-		public GroupListener() {
-		}
-
-		@Override
-		public void onClick(View v) {
-			Intent i = new Intent(UserInfo.this, GroupList.class);
-			i.putExtra("contact", mContact);
-			startActivity(i);
-		}
-
+	@Override
+	public Object getItem(int position) {
+	    return position;
 	}
 
 	/**
-	 * Create dialog alias.
+	 * {@inheritDoc}
 	 */
-	public class DialogAlias extends Dialog {
-
-		/**
-		 * Constructor.
-		 */
-		public DialogAlias() {
-			super(UserInfo.this);
-			setContentView(R.layout.contactdialogaliasdialog);
-			setTitle(mContact.getJID());
-			EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
-			if (mContact.getName().length() == 0)
-				nameText.setText(mContact.getJID());
-			else
-				nameText.setText(mContact.getName());
-			Button ok = (Button) findViewById(R.id.CDAliasDialogOk);
-			ok.setOnClickListener(new ContactDialogAliasDialogOK());
-		}
-
-		/**
-		 * Event click on the button OK.
-		 */
-		private class ContactDialogAliasDialogOK implements View.OnClickListener {
-
-			/**
-			 * Constructor.
-			 */
-			public ContactDialogAliasDialogOK() {
-			}
-
-			@Override
-			public void onClick(View v) {
-				try {
-					EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
-					String name = nameText.getText().toString();
-					if (name.length() == 0)
-						name = mContact.getJID();
-					mRoster.setContactName(mContact.getJID(), name);
-					mContact.setName(name);
-					mTextAlias.setText(name);
-
-				} catch (RemoteException e) {
-					e.printStackTrace();
-				}
-				dismiss();
-			}
-		}
+	@Override
+	public long getItemId(int position) {
+	    return position;
 	}
 
 	/**
-	 * Adapter group horizontal list.
+	 * {@inheritDoc}
 	 */
-	public class BeemGroups extends BaseAdapter {
-		private Context mContext;
-		private List<String> mListGroup;
+	@Override
+	public View getView(int position, View convertView, ViewGroup parent) {
+	    TextView textView = new TextView(mContext);
+	    textView.setText(mListGroup.get(position));
+	    return textView;
+	}
+
+    }
 
-		/**
-		 * Constructor.
-		 * 
-		 * @param c
-		 *            context activity.
-		 * @param listGroup
-		 *            the user group list.
-		 */
-		public BeemGroups(final Context c, final List<String> listGroup) {
-			mContext = c;
-			if (listGroup.size() == 0)
-				listGroup.add(getString(R.string.contact_list_no_group));
-			mListGroup = listGroup;
-		}
+    /**
+     * Event simple click on layout resend suscription.
+     */
+    class ResendListener implements View.OnClickListener {
+
+	/**
+	 * Constructor.
+	 */
+	public ResendListener() {
+	}
+
+	@Override
+	public void onClick(View v) {
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public int getCount() {
-			return mListGroup.size();
-		}
+	    AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
+	    builder.setMessage(UserInfo.this.getString(R.string.userinfo_sureresend)).setCancelable(false)
+		.setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
+		    new DialogInterface.OnClickListener() {
+			public void onClick(DialogInterface dialog, int id) {
+			    Presence presencePacket = new Presence(Presence.Type.subscribe);
+			    presencePacket.setTo(mContact.getJID());
+			    try {
+				mXmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket));
+			    } catch (RemoteException e) {
+				e.printStackTrace();
+			    }
+			    Toast.makeText(UserInfo.this, getString(R.string.userinfo_resend), Toast.LENGTH_SHORT)
+				.show();
+			}
+		    }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
+		    new DialogInterface.OnClickListener() {
+			public void onClick(DialogInterface dialog, int id) {
+			    dialog.cancel();
+			}
+		    });
+	    AlertDialog alert = builder.create();
+	    alert.show();
+	}
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public Object getItem(int position) {
-			return position;
-		}
+    }
+
+    /**
+     * Event simple click on layout delete.
+     */
+    class DeleteListener implements View.OnClickListener {
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public long getItemId(int position) {
-			return position;
-		}
+	/**
+	 * Constructor.
+	 */
+	public DeleteListener() {
+	}
 
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public View getView(int position, View convertView, ViewGroup parent) {
-			TextView textView = new TextView(mContext);
-			textView.setText(mListGroup.get(position));
-			return textView;
-		}
+	@Override
+	public void onClick(View v) {
+	    AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
+	    builder.setMessage(UserInfo.this.getString(R.string.userinfo_sure2delete)).setCancelable(false)
+		.setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
+		    new DialogInterface.OnClickListener() {
+			public void onClick(DialogInterface dialog, int id) {
+			    try {
+				mRoster.deleteContact(mContact);
+			    } catch (RemoteException e) {
+				e.printStackTrace();
+			    }
+			    finish();
+			}
+		    }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
+		    new DialogInterface.OnClickListener() {
+			public void onClick(DialogInterface dialog, int id) {
+			    dialog.cancel();
+			}
+		    });
+	    AlertDialog alert = builder.create();
+	    alert.show();
+	}
+    }
 
+    /**
+     * The ServiceConnection used to connect to the Beem service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
+
+	/**
+	 * Constructor.
+	 */
+	public BeemServiceConnection() {
 	}
 
 	/**
-	 * Event simple click on layout resend suscription.
+	 * {@inheritDoc}
 	 */
-	class ResendListener implements View.OnClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public ResendListener() {
-		}
-
-		@Override
-		public void onClick(View v) {
-
-			AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
-			builder.setMessage(UserInfo.this.getString(R.string.userinfo_sureresend)).setCancelable(false)
-					.setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
-							new DialogInterface.OnClickListener() {
-								public void onClick(DialogInterface dialog, int id) {
-									Presence presencePacket = new Presence(Presence.Type.subscribe);
-									presencePacket.setTo(mContact.getJID());
-									try {
-										mXmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket));
-									} catch (RemoteException e) {
-										e.printStackTrace();
-									}
-									Toast.makeText(UserInfo.this, getString(R.string.userinfo_resend),
-											Toast.LENGTH_SHORT).show();
-								}
-							}).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
-							new DialogInterface.OnClickListener() {
-								public void onClick(DialogInterface dialog, int id) {
-									dialog.cancel();
-								}
-							});
-			AlertDialog alert = builder.create();
-			alert.show();
-		}
-
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mReceiver.setBinded(true);
+	    try {
+		mRoster = mXmppFacade.getRoster();
+		mJID = getIntent().getStringExtra("contact_contactdialog");
+		mContact = mRoster.getContact(mJID);
+		if (mContact.getName() != null)
+		    mTextAlias.setText(mContact.getName());
+		else
+		    mTextAlias.setText(mContact.getJID());
+		mGalleryGroups.setAdapter(new BeemGroups(UserInfo.this, mContact.getGroups()));
+		setTitle(mJID);
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
 	}
 
 	/**
-	 * Event simple click on layout delete.
-	 */
-	class DeleteListener implements View.OnClickListener {
-
-		/**
-		 * Constructor.
-		 */
-		public DeleteListener() {
-		}
-
-		@Override
-		public void onClick(View v) {
-			AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
-			builder.setMessage(UserInfo.this.getString(R.string.userinfo_sure2delete)).setCancelable(false)
-					.setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
-							new DialogInterface.OnClickListener() {
-								public void onClick(DialogInterface dialog, int id) {
-									try {
-										mRoster.deleteContact(mContact);
-									} catch (RemoteException e) {
-										e.printStackTrace();
-									}
-									finish();
-								}
-							}).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
-							new DialogInterface.OnClickListener() {
-								public void onClick(DialogInterface dialog, int id) {
-									dialog.cancel();
-								}
-							});
-			AlertDialog alert = builder.create();
-			alert.show();
-		}
-	}
-
-	/**
-	 * The ServiceConnection used to connect to the Beem service.
+	 * {@inheritDoc}
 	 */
-	private class BeemServiceConnection implements ServiceConnection {
-
-		/**
-		 * Constructor.
-		 */
-		public BeemServiceConnection() {
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mXmppFacade = IXmppFacade.Stub.asInterface(service);
-			mReceiver.setBinded(true);
-			try {
-				mRoster = mXmppFacade.getRoster();
-				mJID = getIntent().getStringExtra("contact_contactdialog");
-				mContact = mRoster.getContact(mJID);
-				if (mContact.getName() != null)
-					mTextAlias.setText(mContact.getName());
-				else
-					mTextAlias.setText(mContact.getJID());
-				mGalleryGroups.setAdapter(new BeemGroups(UserInfo.this, mContact.getGroups()));
-				setTitle(mJID);
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mXmppFacade = null;
-		}
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    mXmppFacade = null;
 	}
+    }
 }
--- a/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java	Wed Nov 11 19:34:04 2009 +0100
@@ -12,65 +12,59 @@
 
 /**
  * Manage broadcast disconnect intent.
- * 
  * @author nikita
  */
 public class BeemBroadcastReceiver extends BroadcastReceiver {
 
-	/**
-	 * Broadcast intent type.
-	 */
-	public static final String BEEM_CONNECTION_CLOSED = "BeemConnectionClosed";
-	private ServiceConnection mService;
-	private boolean mIsBinded;
+    /**
+     * Broadcast intent type.
+     */
+    public static final String BEEM_CONNECTION_CLOSED = "BeemConnectionClosed";
+    private ServiceConnection mService;
+    private boolean mIsBinded;
 
-	/**
-	 * constructor.
-	 * 
-	 * @param service
-	 *            service observed
-	 */
-	public BeemBroadcastReceiver(final ServiceConnection service) {
-		mService = service;
-		mIsBinded = false;
-	}
+    /**
+     * constructor.
+     * @param service service observed
+     */
+    public BeemBroadcastReceiver(final ServiceConnection service) {
+	mService = service;
+	mIsBinded = false;
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void onReceive(Context context, Intent intent) {
-		Log.d("Broadcast", "onReceive");
-		if (mIsBinded)
-			context.unbindService(mService);
-		setBinded(false);
-		// start activity if unexpected disconnection
-		if (!intent.getBooleanExtra("normally", false))
-			context.startActivity(new Intent(context, Login.class));
-		CharSequence message = intent.getCharSequenceExtra("message");
-		Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
-		if (context instanceof Activity) {
-			Activity act = (Activity) context;
-			act.finish();
-		}
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onReceive(Context context, Intent intent) {
+	Log.d("Broadcast", "onReceive");
+	if (mIsBinded)
+	    context.unbindService(mService);
+	setBinded(false);
+	// start activity if unexpected disconnection
+	if (!intent.getBooleanExtra("normally", false))
+	    context.startActivity(new Intent(context, Login.class));
+	CharSequence message = intent.getCharSequenceExtra("message");
+	Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
+	if (context instanceof Activity) {
+	    Activity act = (Activity) context;
+	    act.finish();
 	}
+    }
 
-	/**
-	 * service is binded.
-	 * 
-	 * @param binded
-	 *            the state of the bind.
-	 */
-	public void setBinded(boolean binded) {
-		mIsBinded = binded;
-	}
+    /**
+     * service is binded.
+     * @param binded the state of the bind.
+     */
+    public void setBinded(boolean binded) {
+	mIsBinded = binded;
+    }
 
-	/**
-	 * return service bind status.
-	 * 
-	 * @return service bind status.
-	 */
-	public boolean isBinded() {
-		return mIsBinded;
-	}
+    /**
+     * return service bind status.
+     * @return service bind status.
+     */
+    public boolean isBinded() {
+	return mIsBinded;
+    }
 }
--- a/src/com/beem/project/beem/utils/FreePort.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/utils/FreePort.java	Wed Nov 11 19:34:04 2009 +0100
@@ -5,47 +5,45 @@
 
 /**
  * Utility class to get a free port.
- * 
  * @author nikita
  */
 public final class FreePort {
 
-	private static final int MAGIC_10 = 10;
-	private static final int MAGIC_10000 = 10000;
-
-	/**
-	 * Private default constructor.
-	 */
-	private FreePort() {
-	}
+    private static final int MAGIC_10 = 10;
+    private static final int MAGIC_10000 = 10000;
 
-	/**
-	 * return a free port.
-	 * 
-	 * @return free socket port.
-	 */
-	public static int getFreePort() {
-		ServerSocket ss;
-		int freePort = 0;
+    /**
+     * Private default constructor.
+     */
+    private FreePort() {
+    }
+
+    /**
+     * return a free port.
+     * @return free socket port.
+     */
+    public static int getFreePort() {
+	ServerSocket ss;
+	int freePort = 0;
 
-		for (int i = 0; i < MAGIC_10; i++) {
-			freePort = (int) (MAGIC_10000 + Math.round(Math.random() * MAGIC_10000));
-			try {
-				ss = new ServerSocket(freePort);
-				freePort = ss.getLocalPort();
-				ss.close();
-				return freePort;
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-		}
-		try {
-			ss = new ServerSocket(0);
-			freePort = ss.getLocalPort();
-			ss.close();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
+	for (int i = 0; i < MAGIC_10; i++) {
+	    freePort = (int) (MAGIC_10000 + Math.round(Math.random() * MAGIC_10000));
+	    try {
+		ss = new ServerSocket(freePort);
+		freePort = ss.getLocalPort();
+		ss.close();
 		return freePort;
+	    } catch (IOException e) {
+		e.printStackTrace();
+	    }
 	}
+	try {
+	    ss = new ServerSocket(0);
+	    freePort = ss.getLocalPort();
+	    ss.close();
+	} catch (IOException e) {
+	    e.printStackTrace();
+	}
+	return freePort;
+    }
 }
--- a/src/com/beem/project/beem/utils/PresenceType.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/utils/PresenceType.java	Wed Nov 11 19:34:04 2009 +0100
@@ -7,123 +7,117 @@
 
 /**
  * Utility class to deal with Presence type.
- * 
  * @author nikita
  */
 public final class PresenceType {
 
-	/**
-	 * The user is available to receive messages (default).
-	 */
-	public static final int AVAILABLE = 100;
+    /**
+     * The user is available to receive messages (default).
+     */
+    public static final int AVAILABLE = 100;
 
-	/**
-	 * The user is unavailable to receive messages.
-	 */
-	public static final int UNAVAILABLE = 200;
+    /**
+     * The user is unavailable to receive messages.
+     */
+    public static final int UNAVAILABLE = 200;
 
-	/**
-	 * Request subscription to recipient's presence.
-	 */
+    /**
+     * Request subscription to recipient's presence.
+     */
 
-	public static final int SUBSCRIBE = 300;
+    public static final int SUBSCRIBE = 300;
 
-	/**
-	 * Grant subscription to sender's presence.
-	 */
-	public static final int SUBSCRIBED = 400;
+    /**
+     * Grant subscription to sender's presence.
+     */
+    public static final int SUBSCRIBED = 400;
 
-	/**
-	 * Request removal of subscription to sender's presence.
-	 */
-	public static final int UNSUBSCRIBE = 500;
+    /**
+     * Request removal of subscription to sender's presence.
+     */
+    public static final int UNSUBSCRIBE = 500;
 
-	/**
-	 * Grant removal of subscription to sender's presence.
-	 */
-	public static final int UNSUBSCRIBED = 600;
+    /**
+     * Grant removal of subscription to sender's presence.
+     */
+    public static final int UNSUBSCRIBED = 600;
 
-	/**
-	 * The presence packet contains an error message.
-	 */
-	public static final int ERROR = 701;
+    /**
+     * The presence packet contains an error message.
+     */
+    public static final int ERROR = 701;
 
-	/**
-	 * Private default constructor.
-	 */
-	private PresenceType() {
-	}
+    /**
+     * Private default constructor.
+     */
+    private PresenceType() {
+    }
 
-	/**
-	 * Get the presence type from a presence packet.
-	 * 
-	 * @param presence
-	 *            the presence type
-	 * @return an int representing the presence type
-	 */
-	public static int getPresenceType(Presence presence) {
-		int res = PresenceType.ERROR;
-		switch (presence.getType()) {
-		case available:
-			res = PresenceType.AVAILABLE;
-			break;
-		case unavailable:
-			res = PresenceType.UNAVAILABLE;
-			break;
-		case subscribe:
-			res = PresenceType.SUBSCRIBE;
-			break;
-		case subscribed:
-			res = PresenceType.SUBSCRIBED;
-			break;
-		case unsubscribe:
-			res = PresenceType.UNSUBSCRIBE;
-			break;
-		case unsubscribed:
-			res = PresenceType.UNSUBSCRIBED;
-			break;
-		case error:
-		default:
-			res = PresenceType.ERROR;
-		}
-		return res;
+    /**
+     * Get the presence type from a presence packet.
+     * @param presence the presence type
+     * @return an int representing the presence type
+     */
+    public static int getPresenceType(Presence presence) {
+	int res = PresenceType.ERROR;
+	switch (presence.getType()) {
+	    case available:
+		res = PresenceType.AVAILABLE;
+		break;
+	    case unavailable:
+		res = PresenceType.UNAVAILABLE;
+		break;
+	    case subscribe:
+		res = PresenceType.SUBSCRIBE;
+		break;
+	    case subscribed:
+		res = PresenceType.SUBSCRIBED;
+		break;
+	    case unsubscribe:
+		res = PresenceType.UNSUBSCRIBE;
+		break;
+	    case unsubscribed:
+		res = PresenceType.UNSUBSCRIBED;
+		break;
+	    case error:
+	    default:
+		res = PresenceType.ERROR;
 	}
+	return res;
+    }
 
-	/**
-	 * Get the smack presence mode for a status.
-	 * 
-	 * @param type
-	 *            the status type in beem
-	 * @return the presence mode to use in presence packet or null if there is
-	 *         no mode to use
-	 */
-	public static Presence.Type getPresenceTypeFrom(int type) {
-		Presence.Type res;
-		switch (type) {
-		case AVAILABLE:
-			res = Presence.Type.available;
-			break;
-		case UNAVAILABLE:
-			res = Presence.Type.unavailable;
-			break;
-		case SUBSCRIBE:
-			res = Presence.Type.subscribe;
-			break;
-		case SUBSCRIBED:
-			res = Presence.Type.subscribed;
-			break;
-		case UNSUBSCRIBE:
-			res = Presence.Type.unsubscribe;
-			break;
-		case UNSUBSCRIBED:
-			res = Presence.Type.unsubscribed;
-			break;
-		case ERROR:
-			res = Presence.Type.error;
-			break;
-		default:
-			return null;
-		}
-		return res;
+    /**
+     * Get the smack presence mode for a status.
+     * @param type the status type in beem
+     * @return the presence mode to use in presence packet or null if there is no mode to use
+     */
+    public static Presence.Type getPresenceTypeFrom(int type) {
+	Presence.Type res;
+	switch (type) {
+	    case AVAILABLE:
+		res = Presence.Type.available;
+		break;
+	    case UNAVAILABLE:
+		res = Presence.Type.unavailable;
+		break;
+	    case SUBSCRIBE:
+		res = Presence.Type.subscribe;
+		break;
+	    case SUBSCRIBED:
+		res = Presence.Type.subscribed;
+		break;
+	    case UNSUBSCRIBE:
+		res = Presence.Type.unsubscribe;
+		break;
+	    case UNSUBSCRIBED:
+		res = Presence.Type.unsubscribed;
+		break;
+	    case ERROR:
+		res = Presence.Type.error;
+		break;
+	    default:
+		return null;
 	}
+	return res;
+    }
 }
--- a/src/com/beem/project/beem/utils/Status.java	Wed Nov 11 19:21:44 2009 +0100
+++ b/src/com/beem/project/beem/utils/Status.java	Wed Nov 11 19:34:04 2009 +0100
@@ -8,129 +8,121 @@
 
 /**
  * Utility class to deal with status and presence value.
- * 
  * @author marseille
  */
 public final class Status {
 
-	/**
-	 * Status of a disconnected contact.
-	 */
-	public static final int CONTACT_STATUS_DISCONNECT = 100;
+    /**
+     * Status of a disconnected contact.
+     */
+    public static final int CONTACT_STATUS_DISCONNECT = 100;
 
-	/**
-	 * Status of a unavailable (long away) contact.
-	 */
-	public static final int CONTACT_STATUS_UNAVAILABLE = 200;
+    /**
+     * Status of a unavailable (long away) contact.
+     */
+    public static final int CONTACT_STATUS_UNAVAILABLE = 200;
+
+    /**
+     * Status of a away contact.
+     */
+    public static final int CONTACT_STATUS_AWAY = 300;
 
-	/**
-	 * Status of a away contact.
-	 */
-	public static final int CONTACT_STATUS_AWAY = 300;
+    /**
+     * Status of a busy contact.
+     */
+    public static final int CONTACT_STATUS_BUSY = 400;
+
+    /**
+     * Status of a available contact.
+     */
+    public static final int CONTACT_STATUS_AVAILABLE = 500;
 
-	/**
-	 * Status of a busy contact.
-	 */
-	public static final int CONTACT_STATUS_BUSY = 400;
+    /**
+     * Status of a available for chat contact.
+     */
+    public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
 
-	/**
-	 * Status of a available contact.
-	 */
-	public static final int CONTACT_STATUS_AVAILABLE = 500;
+    /**
+     * Default constructor masked.
+     */
+    private Status() {
+    }
 
-	/**
-	 * Status of a available for chat contact.
-	 */
-	public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
-
-	/**
-	 * Default constructor masked.
-	 */
-	private Status() {
+    /**
+     * Get the smack presence mode for a status.
+     * @param status the status in beem
+     * @return the presence mode to use in presence packet or null if there is no mode to use
+     */
+    public static Presence.Mode getPresenceModeFromStatus(int status) {
+	Presence.Mode res;
+	switch (status) {
+	    case CONTACT_STATUS_AVAILABLE:
+		res = Presence.Mode.available;
+		break;
+	    case CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+		res = Presence.Mode.chat;
+		break;
+	    case CONTACT_STATUS_AWAY:
+		res = Presence.Mode.away;
+		break;
+	    case CONTACT_STATUS_BUSY:
+		res = Presence.Mode.dnd;
+		break;
+	    case CONTACT_STATUS_UNAVAILABLE:
+		res = Presence.Mode.xa;
+		break;
+	    default:
+		return null;
 	}
+	return res;
+    }
 
-	/**
-	 * Get the smack presence mode for a status.
-	 * 
-	 * @param status
-	 *            the status in beem
-	 * @return the presence mode to use in presence packet or null if there is
-	 *         no mode to use
-	 */
-	public static Presence.Mode getPresenceModeFromStatus(int status) {
-		Presence.Mode res;
-		switch (status) {
-		case CONTACT_STATUS_AVAILABLE:
-			res = Presence.Mode.available;
-			break;
-		case CONTACT_STATUS_AVAILABLE_FOR_CHAT:
-			res = Presence.Mode.chat;
-			break;
-		case CONTACT_STATUS_AWAY:
-			res = Presence.Mode.away;
-			break;
-		case CONTACT_STATUS_BUSY:
-			res = Presence.Mode.dnd;
+    /**
+     * Get the status of from a presence packet.
+     * @param presence the presence containing status
+     * @return an int representing the status
+     */
+    public static int getStatusFromPresence(Presence presence) {
+	int res = Status.CONTACT_STATUS_DISCONNECT;
+	if (presence.getType().equals(Presence.Type.unavailable)) {
+	    res = Status.CONTACT_STATUS_DISCONNECT;
+	} else {
+	    Mode mode = presence.getMode();
+	    if (mode == null) {
+		res = Status.CONTACT_STATUS_AVAILABLE;
+	    } else {
+		switch (mode) {
+		    case available:
+			res = Status.CONTACT_STATUS_AVAILABLE;
 			break;
-		case CONTACT_STATUS_UNAVAILABLE:
-			res = Presence.Mode.xa;
+		    case away:
+			res = Status.CONTACT_STATUS_AWAY;
+			break;
+		    case chat:
+			res = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
 			break;
-		default:
-			return null;
-		}
-		return res;
-	}
-
-	/**
-	 * Get the status of from a presence packet.
-	 * 
-	 * @param presence
-	 *            the presence containing status
-	 * @return an int representing the status
-	 */
-	public static int getStatusFromPresence(Presence presence) {
-		int res = Status.CONTACT_STATUS_DISCONNECT;
-		if (presence.getType().equals(Presence.Type.unavailable)) {
+		    case dnd:
+			res = Status.CONTACT_STATUS_BUSY;
+			break;
+		    case xa:
+			res = Status.CONTACT_STATUS_UNAVAILABLE;
+			break;
+		    default:
 			res = Status.CONTACT_STATUS_DISCONNECT;
-		} else {
-			Mode mode = presence.getMode();
-			if (mode == null) {
-				res = Status.CONTACT_STATUS_AVAILABLE;
-			} else {
-				switch (mode) {
-				case available:
-					res = Status.CONTACT_STATUS_AVAILABLE;
-					break;
-				case away:
-					res = Status.CONTACT_STATUS_AWAY;
-					break;
-				case chat:
-					res = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
-					break;
-				case dnd:
-					res = Status.CONTACT_STATUS_BUSY;
-					break;
-				case xa:
-					res = Status.CONTACT_STATUS_UNAVAILABLE;
-					break;
-				default:
-					res = Status.CONTACT_STATUS_DISCONNECT;
-					break;
-				}
-			}
+			break;
 		}
-		return res;
+	    }
 	}
+	return res;
+    }
 
-	/**
-	 * Check if contact is online by his status.
-	 * 
-	 * @param status
-	 *            contact status
-	 * @return is obline
-	 */
-	public static boolean statusOnline(int status) {
-		return (status != Status.CONTACT_STATUS_DISCONNECT && status != Status.CONTACT_STATUS_UNAVAILABLE);
-	}
+    /**
+     * Check if contact is online by his status.
+     * @param status contact status
+     * @return is obline
+     */
+    public static boolean statusOnline(int status) {
+	return (status != Status.CONTACT_STATUS_DISCONNECT && status != Status.CONTACT_STATUS_UNAVAILABLE);
+    }
 
 }