Merge.
authormarseille@KungFuh
Tue, 07 Apr 2009 19:07:41 +0200
changeset 79 eb9112a00b02
parent 78 a02d227ac5a6 (diff)
parent 71 fb3e3ed4bafc (current diff)
child 82 ff92a9c95c78
child 86 23a0dfdff589
Merge.
--- a/res/layout/contactlistcontact.xml	Tue Apr 07 15:20:28 2009 +0200
+++ b/res/layout/contactlistcontact.xml	Tue Apr 07 19:07:41 2009 +0200
@@ -6,7 +6,7 @@
         android:gravity="center_vertical" >
 
         <ImageView android:id="@+id/contactliststatus"
-        android:layout_weight="5"
+        	android:layout_weight="5"
         	android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:gravity="center_vertical" />
--- a/src/com/beem/project/beem/BeemApplication.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/BeemApplication.java	Tue Apr 07 19:07:41 2009 +0200
@@ -8,6 +8,7 @@
 
 import android.app.Activity;
 import android.app.Application;
+import android.app.ProgressDialog;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -17,22 +18,32 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
+import android.os.RemoteException;
 
+import com.beem.project.beem.service.aidl.IBeemConnectionListener;
+import com.beem.project.beem.service.aidl.IXmppConnection;
 import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
- * The Beem application.
- * This class has some methods utiliy needs by the activities.
+ * The Beem application. This class has some methods utiliy needs by the activities.
  * @author darisk
  */
 public class BeemApplication extends Application {
 
     private static BeemApplication mBeemApp;
+    private static final Intent SERVICE_INTENT = new Intent();
     private IXmppFacade mFacade;
     private Context mApplicationContext;
     private Resources mPrivateResources;
     private List<Message> mQueue = new LinkedList<Message>();
     private boolean mIsConnected;
+    private IXmppConnection mConnection;
+    private ProgressDialog mProgressDialog;
+    private ConnectionListener mConnectionListener = new ConnectionListener();
+
+    static {
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+    }
 
     private ServiceConnection mServConn = new ServiceConnection() {
 
@@ -44,13 +55,18 @@
 
 	@Override
 	public void onServiceConnected(ComponentName name, IBinder service) {
-	    // TODO Auto-generated method stub
+	    mIsConnected = true;
 	    mFacade = IXmppFacade.Stub.asInterface(service);
-	    synchronized (mQueue) {
-		for (Message msg : mQueue) {
-		    msg.sendToTarget();
+	    try {
+		mConnection = mFacade.createConnection();
+		if (!mConnection.isAuthentificated()) {
+		    mProgressDialog.show();
+		    mConnection.addConnectionListener(mConnectionListener);
+		    mApplicationContext.startService(BeemApplication.SERVICE_INTENT);
 		}
-		mQueue.clear();
+	    } catch (RemoteException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
 	    }
 	}
     };
@@ -59,72 +75,35 @@
      * Constructor.
      */
     public BeemApplication() {
-	// TODO Auto-generated constructor stub
+	mIsConnected = false;
     }
 
     /**
      * Get the Beem application for an activity.
-     * @param activity	the activity which want the Beem application
-     * @return		the Beem application
+     * @param activity the activity which want the Beem application
+     * @return the Beem application
      */
     public static BeemApplication getApplication(Activity activity) {
 	if (mBeemApp == null) {
 	    mBeemApp = new BeemApplication();
-	    mBeemApp.mApplicationContext = activity.getApplication();
-	    mBeemApp.mPrivateResources = activity.getResources();
-	    mBeemApp.onCreate();
 	}
+	mBeemApp.mProgressDialog = new ProgressDialog(activity);
+	mBeemApp.mProgressDialog.setTitle("Beem");
+	mBeemApp.mProgressDialog.setIcon(R.drawable.logo);
+	mBeemApp.mProgressDialog.setMessage("Connexion en cours");
+	mBeemApp.mApplicationContext = activity.getApplication();
+	mBeemApp.mPrivateResources = activity.getResources();
+	mBeemApp.onCreate();
 	return mBeemApp;
     }
 
     /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onConfigurationChanged(Configuration newConfig) {
-	// TODO Auto-generated method stub
-	super.onConfigurationChanged(newConfig);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onCreate() {
-	// TODO Auto-generated method stub
-	super.onCreate();
-	mFacade = null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onLowMemory() {
-	// TODO Auto-generated method stub
-	super.onLowMemory();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onTerminate() {
-	// TODO Auto-generated method stub
-	super.onTerminate();
-    }
-
-    /**
      * Start the beem service.
      */
     public synchronized void startBeemService() {
 	if (!mIsConnected) {
-	    // Intent intent = new Intent(this, BeemService.class);
-	    Intent intent = new Intent();
-	    intent.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
-	    mApplicationContext.startService(intent);
-	    mApplicationContext.bindService(intent, mServConn, BIND_AUTO_CREATE);
-	    mIsConnected = true;
+	    // the connection will be made on service connect
+	    mApplicationContext.bindService(BeemApplication.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
 	}
     }
 
@@ -134,8 +113,7 @@
     public synchronized void stopBeemService() {
 	if (mIsConnected) {
 	    Intent intent = new Intent();
-	    intent.setComponent(new ComponentName("com.beem.project.beem",
-		    "com.beem.project.beem.BeemService"));
+	    intent.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
 	    mApplicationContext.unbindService(mServConn);
 	    mApplicationContext.stopService(intent);
 	    mIsConnected = false;
@@ -144,21 +122,20 @@
 
     /**
      * Get the facade to use to access the Beem service.
-     * @return	the facade or null if the application is not connected to the beem service.
+     * @return the facade or null if the application is not connected to the beem service.
      */
     public IXmppFacade getXmppFacade() {
 	return mFacade;
     }
 
-
     /**
-     * Add a methode to execute when the application is connected to the Beem service.
-     * @param target	the handler which will execute the callback
-     * @param callback	the callback to execute
+     * Add a methode to execute when the application is connected to the server.
+     * @param target the handler which will execute the callback
+     * @param callback the callback to execute
      */
-    public void callWhenServiceConnected(Handler target, Runnable callback) {
+    public void callWhenConnectedToServer(Handler target, Runnable callback) {
 	Message msg = Message.obtain(target, callback);
-	if (!mIsConnected) {
+	if (mIsConnected) {
 	    msg.sendToTarget();
 	} else {
 	    startBeemService();
@@ -169,10 +146,87 @@
     }
 
     /**
-     * Indique si on est connecte au service.
+     * Tell if we are connected with the Beem Service.
+     * @return true if connected false otherwise
      */
     public boolean isConnected() {
 	return mIsConnected;
     }
 
+    /**
+     * Connection listener use to hide the progress dialog.
+     * @author darisk
+     */
+    private class ConnectionListener extends IBeemConnectionListener.Stub {
+
+	/**
+	 * Constructor.
+	 */
+	public ConnectionListener() {
+
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void connectionClosed() throws RemoteException {
+	    // TODO Auto-generated method stub
+
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void connectionClosedOnError() throws RemoteException {
+	    // TODO Auto-generated method stub
+	    // afficher une notification et reafficher le progress dialog
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void onConnect() throws RemoteException {
+	    // TODO Auto-generated method stub
+	    mProgressDialog.dismiss();
+	    mFacade.changeStatus();
+	    synchronized (mQueue) {
+		for (Message msg : mQueue) {
+		    msg.sendToTarget();
+		}
+		mQueue.clear();
+	    }
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void reconnectingIn(int seconds) throws RemoteException {
+	    // TODO Auto-generated method stub
+	    mProgressDialog.show();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void reconnectionFailed() throws RemoteException {
+	    // TODO Auto-generated method stub
+
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void reconnectionSuccessful() throws RemoteException {
+	    // TODO Auto-generated method stub
+
+	}
+
+    }
+
 }
--- a/src/com/beem/project/beem/BeemService.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Tue Apr 07 19:07:41 2009 +0200
@@ -12,31 +12,44 @@
 
 import com.beem.project.beem.service.XmppConnectionAdapter;
 import com.beem.project.beem.service.XmppFacade;
+import com.beem.project.beem.service.aidl.IBeemConnectionListener;
 import com.beem.project.beem.service.aidl.IXmppFacade;
 import com.beem.project.beem.service.aidl.IXmppConnection;
+
 /**
  * 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 = 1;
+
     private NotificationManager mNotificationManager;
-
     private IXmppConnection mConnection;
     private SharedPreferences mSettings;
     private String mLogin;
     private String mPassword;
     private String mHost;
 
+
     private IXmppFacade.Stub mBind;
 
     /**
+     * Constructor.
+     */
+    public BeemService() {
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override
     public IBinder onBind(Intent intent) {
-	showBasicNotification(R.string.BeemServiceCreated);
 	return mBind;
 	// to forbid a client to bind
 	// return null;
@@ -48,15 +61,13 @@
     @Override
     public void onCreate() {
 	super.onCreate();
-	mSettings = getSharedPreferences(getString(R.string.PreferenceFileName),
-		MODE_PRIVATE);
+	mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
 	mLogin = mSettings.getString(getString(R.string.PreferenceLoginKey), "");
-	mPassword = mSettings.getString(
-		getString(R.string.PreferencePasswordKey), "");
+	mPassword = mSettings.getString(getString(R.string.PreferencePasswordKey), "");
 	mHost = mSettings.getString(getString(R.string.PreferenceHostKey), "");
 	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 	mConnection = new XmppConnectionAdapter("10.0.2.2", mLogin, mPassword); // address
-	mBind = new XmppFacade((XmppConnectionAdapter) mConnection);
+	mBind = new XmppFacade(mConnection, this);
     }
 
     /**
@@ -65,7 +76,7 @@
     @Override
     public void onStart(Intent intent, int startId) {
 	try {
-	    mConnection.connectSync();
+	    mConnection.connectAsync();
 	} catch (RemoteException e) {
 	    // TODO Auto-generated catch block
 	    e.printStackTrace();
@@ -78,7 +89,7 @@
     @Override
     public void onDestroy() {
 	closeConnection();
-	showBasicNotification(R.string.BeemServiceDestroyed);
+	mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
     }
 
     /**
@@ -95,21 +106,11 @@
     }
 
     /**
-     * Add a notification in the notification status bar.
-     * @param stringResource	the ressource of the text to show
+     * Show a notification.
+     * @param id 	the id of the notification.
+     * @param notif	the notification to show
      */
-    private void showBasicNotification(int stringResource) {
-        String text = (String) getText(stringResource);
-        Notification notif = new Notification(R.drawable.logo, text, System
-                .currentTimeMillis());
-        notif.defaults = Notification.DEFAULT_ALL;
-        notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity(
-                this, 0, new Intent(), 0));
-        mNotificationManager.notify(stringResource, notif);
-        Toast toast = Toast.makeText(this, R.string.BeemServiceCreated,
-                Toast.LENGTH_LONG);
-        toast.show();
+    public void sendNotification(int id, Notification notif) {
+	mNotificationManager.notify(id, notif);
     }
-
-
 }
--- a/src/com/beem/project/beem/service/BeemChatManager.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/service/BeemChatManager.java	Tue Apr 07 19:07:41 2009 +0200
@@ -10,6 +10,7 @@
 import org.jivesoftware.smack.ChatManager;
 import org.jivesoftware.smack.ChatManagerListener;
 import org.jivesoftware.smack.MessageListener;
+import org.jivesoftware.smack.packet.Message;
 
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
@@ -31,10 +32,11 @@
      */
     public static final String TAG = "BeemChatManager";
     private ChatManager mAdaptee;
-    private Map<String, Chat> mChats = new HashMap<String, Chat>();
+    private Map<String, IChat> mChats = new HashMap<String, IChat>();
     private ChatListener mChatListener = new ChatListener();
     private RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners =
 	new RemoteCallbackList<IChatManagerListener>();
+    private RemoteCallbackList<IMessageListener> mRemoteMessageListeners = new RemoteCallbackList<IMessageListener>();
 
     /**
      * Constructor.
@@ -52,8 +54,12 @@
      * @param listener listener to use for chat events on this chat session
      * @return the chat session
      */
-    public Chat createChat(String jid, MessageListener listener) {
-	return mAdaptee.createChat(jid, listener);
+    public IChat createChat(String jid, IMessageListener listener) {
+	mRemoteMessageListeners.register(listener);
+	if (mChats.containsKey(jid)) {
+	    return mChats.get(jid);
+	}
+	return new ChatAdapter( mAdaptee.createChat(jid, mChatListener));
     }
 
     /**
@@ -62,7 +68,7 @@
      * @param listener listener to use for chat events on this chat session
      * @return the chat session
      */
-    public Chat createChat(Contact contact, MessageListener listener) {
+    public IChat createChat(Contact contact, IMessageListener listener) {
 	String jid = contact.getJID();
 	return createChat(jid, listener);
     }
@@ -72,7 +78,6 @@
      */
     @Override
     public void addChatCreationListener(IChatManagerListener listener) throws RemoteException {
-	// TODO Auto-generated method stub
 	mRemoteChatCreationListeners.register(listener);
     }
 
@@ -80,25 +85,24 @@
      * {@inheritDoc}
      */
     @Override
-    public IChat createChat(Contact contact, IMessageListener listener) throws RemoteException {
-	// TODO Auto-generated method stub
-	return null;
+    public void removeChatCreationListener(IChatManagerListener listener) throws RemoteException {
+	mRemoteChatCreationListeners.unregister(listener);
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void removeChatCreationListener(IChatManagerListener listener) throws RemoteException {
-	// TODO Auto-generated method stub
-	mRemoteChatCreationListeners.unregister(listener);
+    
+    private IChat getChat(Chat chat) {
+	if (mChats.containsKey(chat.getParticipant())) {
+	    return mChats.get(chat.getParticipant());
+	}
+	IChat res = new ChatAdapter(chat);
+	mChats.put(chat.getParticipant(), res);
+	return res;
     }
 
     /**
      * A listener for all the chat creation event that happens on the connection.
      * @author darisk
      */
-    private class ChatListener implements ChatManagerListener {
+    private class ChatListener implements ChatManagerListener, MessageListener {
 
 	/**
 	 * Constructor.
@@ -112,15 +116,15 @@
 	 */
 	@Override
 	public void chatCreated(Chat chat, boolean locally) {
+	    IChat newchat = getChat(chat);
 	    if (!locally) {
-		mChats.put(chat.getParticipant(), chat);
+		mChats.put(chat.getParticipant(), newchat);
 	    }
 	    final int n = mRemoteChatCreationListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
 		IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i);
 		try {
-		    IChat newchat = new ChatAdapter(chat);
 		    listener.chatCreated(newchat, locally);
 		} catch (RemoteException e) {
 		    // The RemoteCallbackList will take care of removing the
@@ -130,6 +134,24 @@
 	    }
 	    mRemoteChatCreationListeners.finishBroadcast();
 	}
+
+	@Override
+	public void processMessage(Chat chat, Message message) {
+	    IChat newchat = getChat(chat);
+	   final int n = mRemoteMessageListeners.beginBroadcast();
+	   for (int i = 0; i < n; i++) {
+		IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
+		try {
+		    listener.processMessage(newchat, new com.beem.project.beem.service.Message(message));
+		    //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", e);
+		}
+	    }
+	    mRemoteMessageListeners.finishBroadcast();
+	}
     }
 
 }
--- a/src/com/beem/project/beem/service/Contact.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java	Tue Apr 07 19:07:41 2009 +0200
@@ -52,7 +52,8 @@
 
     /**
      * Construct a contact from a parcel.
-     * @param in parcel to use for construction
+     * @param in
+     *            parcel to use for construction
      */
     private Contact(final Parcel in) {
 	mID = in.readInt();
@@ -60,7 +61,7 @@
 	mJID = in.readString();
 	mMsgState = in.readString();
 	mRes = new ArrayList<String>();
-	in.readStringList(mRes); 
+	in.readStringList(mRes);
     }
 
     /**
@@ -93,7 +94,8 @@
 
     /**
      * Constructor.
-     * @param jid JID of the contact
+     * @param jid
+     *            JID of the contact
      */
     public Contact(final String jid) {
 	mJID = jid;
@@ -110,7 +112,8 @@
     }
 
     /**
-     * @param mid the mID to set
+     * @param mid
+     *            the mID to set
      */
     public void setID(int mid) {
 	mID = mid;
@@ -124,21 +127,23 @@
     }
 
     /**
-     * @param status the mStatus to set
+     * @param status
+     *            the mStatus to set
      */
     public void setStatus(int status) {
 	mStatus = status;
     }
 
     /**
-     * @param presence the presence containing status
+     * @param presence
+     *            the presence containing status
      */
     public void setStatus(Presence presence) {
-	if (presence.getType().equals(Presence.Type.unavailable)) {
-	    Log.d(TAG, "Presence pas dispo");
-	    mStatus = Contact.CONTACT_STATUS_DISCONNECT;
-	} else {
-	    Log.d(TAG,"Presence OK");
+	Log.i(TAG, "NIKITAAAA");
+	/* presence.isAvailable() !?!? */
+	if (presence.getType().equals(Presence.Type.available)) {
+	    mStatus = Contact.CONTACT_STATUS_AVAILABLE;
+	    Log.d(TAG, "Presence OK");
 	    Mode mode = presence.getMode();
 	    switch (mode) {
 		case available:
@@ -158,9 +163,12 @@
 		    break;
 		default:
 		    Log.e("RosterAdapter", "Status mode non gere");
-		mStatus = Contact.CONTACT_STATUS_DISCONNECT;
-		break;
+		    mStatus = Contact.CONTACT_STATUS_AVAILABLE;
+		    break;
 	    }
+	} else {
+	    Log.d(TAG, "Presence pas dispo");
+	    mStatus = Contact.CONTACT_STATUS_DISCONNECT;
 	}
     }
 
@@ -172,7 +180,8 @@
     }
 
     /**
-     * @param msgState the mMsgState to set
+     * @param msgState
+     *            the mMsgState to set
      */
     public void setMMsgState(String msgState) {
 	mMsgState = msgState;
@@ -188,7 +197,8 @@
 
     /**
      * Set the Jabber ID of the contact.
-     * @param mjid	the jabber ID to set
+     * @param mjid
+     *            the jabber ID to set
      */
     public void setJID(String mjid) {
 	mJID = mjid;
@@ -204,7 +214,8 @@
     }
 
     /**
-     * @param mRes the mRes to set
+     * @param mRes
+     *            the mRes to set
      */
     public void setMRes(List<String> mRes) {
 	this.mRes = mRes;
--- a/src/com/beem/project/beem/service/Message.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/service/Message.java	Tue Apr 07 19:07:41 2009 +0200
@@ -5,6 +5,7 @@
 
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.util.Log;
 
 /**
  * This class represents a instant message.
@@ -71,6 +72,27 @@
 	this(to, MSG_TYPE_CHAT);
     }
 
+    public Message(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;
+	    default:
+		Log.w("BEEM_MESSAGE", "type de message non gerer" + smackMsg.getType());
+		break;
+	}
+	mBody = smackMsg.getBody();
+	mSubject = smackMsg.getSubject();
+	mThread = smackMsg.getThread();
+    }
+    
     /**
      * Construct a message from a parcel.
      * @param in parcel to use for construction
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Apr 07 19:07:41 2009 +0200
@@ -73,20 +73,20 @@
      */
     @Override
     public boolean connectSync() throws RemoteException {
-	try {
-	    mAdaptee.connect();
-	    mAdaptee.addConnectionListener(mConListener);
-	    mAdaptee.login(mLogin, mPassword, "BEEM");
-	    mChatManager = new BeemChatManager(mAdaptee.getChatManager());
-	    // TODO find why this cause a null pointer exception
-	    // this.initFeatures(); // pour declarer les features xmpp qu'on supporte
-	    mLastException = null;
-	    triggerAsynchronousConnectEvent();
-	    return true;
-	} catch (XMPPException e) {
-	    mLastException = new BeemException(e);
-	}
-	return false;
+	    try {
+		mAdaptee.connect();
+		mAdaptee.addConnectionListener(mConListener);
+		mAdaptee.login(mLogin, mPassword, "BEEM");
+		mChatManager = new BeemChatManager(mAdaptee.getChatManager());
+		// TODO find why this cause a null pointer exception
+		// this.initFeatures(); // pour declarer les features xmpp qu'on supporte
+		mLastException = null;
+		triggerAsynchronousConnectEvent();
+		return true;
+	    } catch (XMPPException e) {
+		mLastException = new BeemException(e);
+	    }
+	    return false;
     }
 
     /**
@@ -106,10 +106,10 @@
     public IRoster getRoster() throws RemoteException {
 	if (mRoster != null)
 	    return mRoster;
-	Roster adap = mAdaptee.getRoster();
-	if (adap == null)
-	    return null;
-	mRoster = new RosterAdapter(adap);
+	    Roster adap = mAdaptee.getRoster();
+	    if (adap == null)
+		return null;
+	    mRoster = new RosterAdapter(adap);
 	return mRoster;
     }
 
@@ -213,6 +213,7 @@
 	 */
 	@Override
 	public void connectionClosed() {
+	    mRoster = null;
 	    final int n = mRemoteConnListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
@@ -233,6 +234,7 @@
 	 */
 	@Override
 	public void connectionClosedOnError(Exception arg0) {
+	    mRoster = null;
 	    final int n = mRemoteConnListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
--- a/src/com/beem/project/beem/service/XmppFacade.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppFacade.java	Tue Apr 07 19:07:41 2009 +0200
@@ -1,10 +1,14 @@
 package com.beem.project.beem.service;
+
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.Intent;
 import android.os.RemoteException;
-
+import com.beem.project.beem.BeemService;
 import com.beem.project.beem.service.aidl.IChatManager;
 import com.beem.project.beem.service.aidl.IRoster;
 import com.beem.project.beem.service.aidl.IXmppConnection;
-import com.beem.project.beem.service.aidl.IXmppFacade;;
+import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
  * This class is a facade for the Beem Service.
@@ -12,14 +16,17 @@
  */
 public class XmppFacade extends IXmppFacade.Stub {
 
-    private XmppConnectionAdapter mConnexion;
+    private IXmppConnection mConnexion;
+    private BeemService mBeemService;
 
     /**
      * Constructor for XMPPFacade.
      * @param connection the connection use by the facade
+     * @param service the service which holds the facade
      */
-    public XmppFacade(final XmppConnectionAdapter connection) {
+    public XmppFacade(final IXmppConnection connection, final BeemService service) {
 	this.mConnexion = connection;
+	this.mBeemService = service;
     }
 
     /**
@@ -70,4 +77,20 @@
 	return mConnexion.getChatManager();
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public void changeStatus() {
+	Notification mStatusNotification;
+	String text = "Salut les amirs !!!!";
+	mStatusNotification = new Notification(com.beem.project.beem.R.drawable.logo, text, System.currentTimeMillis());
+	mStatusNotification.defaults = Notification.DEFAULT_ALL;
+	mStatusNotification.flags = Notification.FLAG_NO_CLEAR;
+
+	// TODO
+	// mStatusNotification.contentView = ;
+	mStatusNotification.setLatestEventInfo(mBeemService, "Beem Status", text, PendingIntent.getActivity(
+	    mBeemService, 0, new Intent(), 0));
+	mBeemService.sendNotification(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
+    }
 }
--- a/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl	Tue Apr 07 19:07:41 2009 +0200
@@ -18,4 +18,7 @@
 
     IChatManager getChatManager();
     
+    // to ameliore
+    void changeStatus();
+    
 }
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 07 19:07:41 2009 +0200
@@ -13,6 +13,7 @@
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.IBinder;
 import android.os.RemoteException;
 import android.util.Log;
 import android.view.Menu;
@@ -29,6 +30,8 @@
 import com.beem.project.beem.BeemApplication;
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.Contact;
+import com.beem.project.beem.service.PresenceAdapter;
+import com.beem.project.beem.service.aidl.IBeemRosterListener;
 import com.beem.project.beem.service.aidl.IXmppFacade;
 import com.beem.project.beem.service.aidl.IRoster;
 
@@ -40,6 +43,8 @@
     private Handler mHandler;
     private BeemApplication mBeemApplication;
     private ContactListDialogSettings mDialog;
+    private BeemRosterListener mRosterListener;
+    private IRoster mRoster;
 
     @SuppressWarnings("unchecked")
     @Override
@@ -62,6 +67,7 @@
 	mSettings = getSharedPreferences(
 		getString(R.string.PreferenceFileName), MODE_PRIVATE);
 	mDialog = new ContactListDialogSettings(this, mSettings);
+	mRosterListener = new BeemRosterListener();
 
 	mSettings
 		.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
@@ -81,13 +87,13 @@
 			 */
 		    }
 		});
-
     }
 
     @Override
     protected void onStart() {
 	super.onStart();
 	Log.i(TAG, "onStart");
+	mBeemApplication.startBeemService();
     }
 
     @Override
@@ -97,14 +103,18 @@
 	 * @TODO: A ameliorer apres listener de nikita
 	 */
 	Log.i(TAG, "onResume");
-	if (!mBeemApplication.isConnected())
-	    mBeemApplication.startBeemService();
-	else {
-	    callbackShowContactList();
-	}
-	mBeemApplication.callWhenServiceConnected(mHandler, new Runnable() {
+	mBeemApplication.startBeemService();
+	mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable() {
 	    @Override
 	    public void run() {
+		mService = mBeemApplication.getXmppFacade();
+		try {
+		    mRoster = mService.getRoster();
+		    mRoster.addConnectionListener(mRosterListener);
+		    Log.i(TAG, "ROSTERLISTENER OK");
+		} catch (RemoteException e) {
+		    e.printStackTrace();
+		}		
 		callbackShowContactList();
 	    }
 	});
@@ -114,17 +124,12 @@
 	/*
 	 * @TODO: A ameliorer apres listener de nikita
 	 */
-	mService = mBeemApplication.getXmppFacade();
-	if (mService != null) {
+	if (mRoster != null)
 	    try {
-		IRoster r = mService.getRoster();
-		if (r != null)
-		    showContactList(r.getGroupsNames(), r.getContactList());
+		showContactList(mRoster.getGroupsNames(), mRoster.getContactList());
 	    } catch (RemoteException e) {
-		// TODO Auto-generated catch block
 		e.printStackTrace();
-	    }
-	}
+	    }	
     }
 
     /**
@@ -248,25 +253,32 @@
 		switch (c.getStatus()) {
 		    case Contact.CONTACT_STATUS_AVAILABLE:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.avatar);
+				R.drawable.online);
+			break;
 		    case Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
 			imageDrawable = (Drawable) getResources().getDrawable(
 				R.drawable.chat);
+			break;
 		    case Contact.CONTACT_STATUS_AWAY:
 			imageDrawable = (Drawable) getResources().getDrawable(
 				R.drawable.away);
+			break;
 		    case Contact.CONTACT_STATUS_BUSY:
 			imageDrawable = (Drawable) getResources().getDrawable(
 				R.drawable.dnd);
+			break;
 		    case Contact.CONTACT_STATUS_DISCONNECT:
 			imageDrawable = (Drawable) getResources().getDrawable(
 				R.drawable.offline);
+			break;
 		    case Contact.CONTACT_STATUS_UNAVAILABLE:
 			imageDrawable = (Drawable) getResources().getDrawable(
 				R.drawable.requested);
+			break;
 		    default:
 			imageDrawable = (Drawable) getResources().getDrawable(
 				R.drawable.error);
+		    	break;
 		}
 		imgV.setImageDrawable(imageDrawable);
 
@@ -295,4 +307,33 @@
 	    }
 	}
     }
+
+    private class BeemRosterListener extends IBeemRosterListener.Stub {
+
+	@Override
+	public void onEntriesAdded(List<String> addresses)
+		throws RemoteException {
+	    Log.i(TAG, "ENTRIES ADDED");
+	    
+	}
+	@Override
+	public void onEntriesDeleted(List<String> addresses)
+		throws RemoteException {
+	    Log.i(TAG, "ENTRIES DEL");
+	    
+	}
+	@Override
+	public void onEntriesUpdated(List<String> addresses)
+		throws RemoteException {
+	    Log.i(TAG, "ENTRIES UPD");
+	    
+	}
+	@Override
+	public void onPresenceChanged(PresenceAdapter presence)
+		throws RemoteException {
+	    Log.i(TAG, "PRESENCE CHANGED");
+	    
+	}
+	
+    }
 }
\ No newline at end of file
--- a/src/com/beem/project/beem/ui/ContactListDialogSettings.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactListDialogSettings.java	Tue Apr 07 19:07:41 2009 +0200
@@ -1,5 +1,6 @@
 package com.beem.project.beem.ui;
 
+import android.app.Activity;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -19,12 +20,10 @@
 	android.view.View.OnClickListener {
 
     private SharedPreferences mSettings;
-    private ContactList mContactList;
 
-    public ContactListDialogSettings(ContactList contactList,
+    public ContactListDialogSettings(Activity activity,
 	    SharedPreferences settings) {
-	super(contactList);
-	this.mContactList = contactList;
+	super(activity);
 	this.mSettings = settings;
     }
 
@@ -54,6 +53,7 @@
 	String JID = ctx.getString(R.string.PreferenceLoginKey) + "@"
 		+ ctx.getString(R.string.PreferenceHostKey);
 	editor.putString(ctx.getString(R.string.PreferenceJID), JID);
+	editor.putBoolean("ACCOUNT_CONFIGURED", true);
 	editor.commit();
 	dismiss();
     }