Super mercurial le retour du commit oubliƩ apres le merge du pull -f -r19
authorPhilippe Lago <lago_p@epitech.net>
Wed, 08 Apr 2009 00:02:09 +0200
changeset 84 9a4dbd7fe546
parent 71 fb3e3ed4bafc (current diff)
parent 80 29f0d6a23321 (diff)
child 85 7d0e36aa1be5
Super mercurial le retour du commit oubliƩ apres le merge du pull -f -r19
res/layout/messagelist.xml
res/layout/sendim.xml
res/values/strings.xml
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/ui/SendIM.java
--- a/res/layout/messagelist.xml	Tue Apr 07 15:20:28 2009 +0200
+++ b/res/layout/messagelist.xml	Wed Apr 08 00:02:09 2009 +0200
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:android="http://schemas.android.com/apk/res/android" id="text1"
           android:textSize="2mm"
-          android:textColor="@color/black"
           android:singleLine="false"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"/>
\ No newline at end of file
--- a/res/layout/sendim.xml	Tue Apr 07 15:20:28 2009 +0200
+++ b/res/layout/sendim.xml	Wed Apr 08 00:02:09 2009 +0200
@@ -2,8 +2,7 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent" 
-    android:layout_height="fill_parent"
-    android:background="@color/blue_sky">
+    android:layout_height="fill_parent">
 
     <ListView android:id="@android:id/list"
         android:layout_width="fill_parent" 
--- a/res/values/strings.xml	Tue Apr 07 15:20:28 2009 +0200
+++ b/res/values/strings.xml	Wed Apr 08 00:02:09 2009 +0200
@@ -17,9 +17,18 @@
 	<string name="PreferenceHostKey">host</string>
 	<string name="PreferenceJID">Jabber ID</string><string name="PreferenceLoginKey">login</string><string name="PreferencePasswordKey">password</string>
 	<string name="PreferencePortKey">port</string>
+	<string name="PreferenceProxyHost">proxy_host</string>
+	<string name="PreferenceProxyPort">proxy_port</string>
+	<string name="PreferenceUseProxy">use_proxy</string>
+	<string name="PreferenceProxyType">proxy_type</string>
+	<string name="PreferenceProxyUser">proxy_user</string>
+	<string name="PreferenceProxyPassword">proxy_password</string>
+	<string name="PreferenceProxyTypeHttp">HTTP</string>
+	<string name="PreferenceProxyTypeSocks4">SOCKS4</string>
+	<string name="PreferenceProxyTypeSocks5">SOCKS5</string>
 
 	<!--  SendIM class -->
-	<string name="SendIMSays">says :\n</string>
+	<string name="SendIMSays"> says :\n</string>
 	<string name="SendIMHint">Tip text here</string>
 	<string name="SendIMState">Is : </string>
 	<string name="SendIMFrom">and is speaking from : </string>
--- a/src/com/beem/project/beem/BeemApplication.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/BeemApplication.java	Wed Apr 08 00:02:09 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	Wed Apr 08 00:02:09 2009 +0200
@@ -1,42 +1,55 @@
 package com.beem.project.beem;
 
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.proxy.ProxyInfo;
+import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
 import android.app.Notification;
 import android.app.NotificationManager;
-import android.app.PendingIntent;
 import android.app.Service;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.IBinder;
 import android.os.RemoteException;
-import android.widget.Toast;
-
 import com.beem.project.beem.service.XmppConnectionAdapter;
 import com.beem.project.beem.service.XmppFacade;
+import com.beem.project.beem.service.aidl.IXmppConnection;
 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 ConnectionConfiguration mConnectionConfiguration;
+    private ProxyInfo mProxyInfo;
+    private boolean mUseProxy;
+    private IXmppFacade.Stub mBind;
 
-    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,37 @@
     @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), "");
+	mHost = "10.0.2.2";
+	initConnectionConfig();
 	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-	mConnection = new XmppConnectionAdapter("10.0.2.2", mLogin, mPassword); // address
-	mBind = new XmppFacade((XmppConnectionAdapter) mConnection);
+	mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword);
+	mBind = new XmppFacade(mConnection, this);
+    }
+
+    /**
+     * Initialise la configuration de la connexion.
+     */
+    private void initConnectionConfig() {
+	//TODO mettre a false par defaut et remplacer les valeurs par defaut
+	mUseProxy = mSettings.getBoolean(getString(R.string.PreferenceUseProxy), false);
+	if (mUseProxy) {
+	    String stype = mSettings.getString(getString(R.string.PreferenceProxyType),
+		getString(R.string.PreferenceProxyTypeHttp));
+	    String phost = mSettings.getString(getString(R.string.PreferenceProxyHost), "");
+	    String puser = mSettings.getString(getString(R.string.PreferenceProxyUser), "");
+	    String ppass = mSettings.getString(getString(R.string.PreferenceProxyPassword), "");
+	    int pport =  mSettings.getInt(getString(R.string.PreferenceProxyPort), 3128);
+	    ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
+	    mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
+	    mConnectionConfiguration = new ConnectionConfiguration(mHost, mProxyInfo);
+	} else {
+	    mConnectionConfiguration = new ConnectionConfiguration(mHost);
+	}
+	mConnectionConfiguration.setSendPresence(true);
     }
 
     /**
@@ -65,7 +100,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 +113,7 @@
     @Override
     public void onDestroy() {
 	closeConnection();
-	showBasicNotification(R.string.BeemServiceDestroyed);
+	mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
     }
 
     /**
@@ -95,21 +130,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	Wed Apr 08 00:02:09 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	Wed Apr 08 00:02:09 2009 +0200
@@ -20,12 +20,36 @@
  */
 public class Contact implements Parcelable {
 
+    /**
+     * 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 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 available for chat contact.
+     */
     public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
+
     private static final String TAG = "Contact";
 
     private int mID;
@@ -51,6 +75,24 @@
     };
 
     /**
+     * Constructor.
+     */
+    public Contact() {
+	// TODO Auto-generated constructor stub
+    }
+
+    /**
+     * Constructor.
+     * @param jid JID of the contact
+     */
+    public Contact(final String jid) {
+	mJID = jid;
+	mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+	mRes = new ArrayList<String>();
+	mRes.add("none");
+    }
+
+    /**
      * Construct a contact from a parcel.
      * @param in parcel to use for construction
      */
@@ -60,7 +102,7 @@
 	mJID = in.readString();
 	mMsgState = in.readString();
 	mRes = new ArrayList<String>();
-	in.readStringList(mRes); 
+	in.readStringList(mRes);
     }
 
     /**
@@ -85,24 +127,7 @@
     }
 
     /**
-     * Constructor.
-     */
-    public Contact() {
-	// TODO Auto-generated constructor stub
-    }
-
-    /**
-     * Constructor.
-     * @param jid JID of the contact
-     */
-    public Contact(final String jid) {
-	mJID = jid;
-	mStatus = Contact.CONTACT_STATUS_DISCONNECT;
-	mRes = new ArrayList<String>();
-	mRes.add("none");
-    }
-
-    /**
+     * Get the id of the contact on the phone contact list.
      * @return the mID
      */
     public int getID() {
@@ -110,6 +135,7 @@
     }
 
     /**
+     * set the id of te contact on the phone contact list.
      * @param mid the mID to set
      */
     public void setID(int mid) {
@@ -117,6 +143,7 @@
     }
 
     /**
+     * Get the status of the contact.
      * @return the mStatus
      */
     public int getStatus() {
@@ -124,6 +151,7 @@
     }
 
     /**
+     * Set the status of the contact.
      * @param status the mStatus to set
      */
     public void setStatus(int status) {
@@ -131,6 +159,7 @@
     }
 
     /**
+     * Set the status of the contact using a presence packet.
      * @param presence the presence containing status
      */
     public void setStatus(Presence presence) {
@@ -138,7 +167,7 @@
 	    Log.d(TAG, "Presence pas dispo");
 	    mStatus = Contact.CONTACT_STATUS_DISCONNECT;
 	} else {
-	    Log.d(TAG,"Presence OK");
+	    Log.d(TAG, "Presence OK");
 	    Mode mode = presence.getMode();
 	    switch (mode) {
 		case available:
@@ -158,23 +187,25 @@
 		    break;
 		default:
 		    Log.e("RosterAdapter", "Status mode non gere");
-		mStatus = Contact.CONTACT_STATUS_DISCONNECT;
-		break;
+		    mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+		    break;
 	    }
 	}
     }
 
     /**
-     * @return the mMsgState
+     * Get the message status of the contact.
+     * @return the message status of the contact.
      */
-    public String getMMsgState() {
+    public String getMsgState() {
 	return mMsgState;
     }
 
     /**
-     * @param msgState the mMsgState to set
+     * Set the message status of the contact.
+     * @param msgState the message status of the contact to set
      */
-    public void setMMsgState(String msgState) {
+    public void setMsgState(String msgState) {
 	mMsgState = msgState;
     }
 
@@ -188,17 +219,25 @@
 
     /**
      * 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;
     }
 
+    /**
+     * 
+     * @param res
+     */
     public void addRes(String res) {
 	if (!mRes.contains(res))
 	    mRes.add(res);
     }
 
+    /**
+     * 
+     * @param res
+     */
     public void delRes(String res) {
 	mRes.remove(res);
     }
--- 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	Wed Apr 08 00:02:09 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/RosterAdapter.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Wed Apr 08 00:02:09 2009 +0200
@@ -46,16 +46,22 @@
 	roster.addRosterListener(mRosterListener);
 	for (RosterEntry entry : roster.getEntries()) {
 	    String user = StringUtils.parseBareAddress(entry.getUser());
-	    if ( !mContacts.containsKey(user))
+	    if (!mContacts.containsKey(user))
 		mContacts.put(user, new Contact(user));
 	}
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void createGroup(String groupname) throws RemoteException {
 	mAdaptee.createGroup(groupname);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Contact addContact(String user, String name, String[] groups) throws RemoteException {
 	try {
@@ -76,18 +82,27 @@
 	mContacts.remove(contact.getJID());
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void addConnectionListener(IBeemRosterListener listen) throws RemoteException {
 	if (listen != null)
 	    mRemoteRosListeners.register(listen);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException {
 	if (listen != null)
 	    mRemoteRosListeners.unregister(listen);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Contact getContact(String jid) throws RemoteException {
 	return mContacts.get(jid);
@@ -103,8 +118,24 @@
 	return res;
     }
 
+    /**
+     * Listener for the roster events.
+     * It will call the remote listeners registered.
+     * @author darisk
+     *
+     */
     private class RosterListenerAdapter implements RosterListener {
 
+	/**
+	 * Constructor.
+	 */
+	public RosterListenerAdapter() {
+	    // TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void entriesAdded(Collection<String> addresses) {
 	    Log.i(TAG, "Ajout de l'entry");
@@ -125,6 +156,9 @@
 	    mRemoteRosListeners.finishBroadcast();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void entriesDeleted(Collection<String> addresses) {
 	    Log.i(TAG, "Suppression de l'entry");
@@ -142,9 +176,12 @@
 		    Log.w(TAG, "Error while deleting roster entries", e);
 		}
 	    }
-	    mRemoteRosListeners.finishBroadcast();			
+	    mRemoteRosListeners.finishBroadcast();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void entriesUpdated(Collection<String> addresses) {
 	    Log.i(TAG, "Update de l'entry");
@@ -162,15 +199,18 @@
 		    Log.w(TAG, "Error while updating roster entries", e);
 		}
 	    }
-	    mRemoteRosListeners.finishBroadcast();			
+	    mRemoteRosListeners.finishBroadcast();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public void presenceChanged(Presence presence) {
 	    Log.i(TAG, "Changement de Presence");
 	    /* gestion du roster coter sedirvice */
 	    String user = StringUtils.parseBareAddress(presence.getFrom());
-	    Log.d(TAG, "User : "+user);
+	    Log.d(TAG, "User : " + user);
 	    Contact c = mContacts.get(StringUtils.parseBareAddress(user));
 	    if (c == null) {
 		c = new Contact(user);
@@ -191,7 +231,7 @@
 		    Log.w(TAG, "Error while updating roster entries", e);
 		}
 	    }
-	    mRemoteRosListeners.finishBroadcast();			
+	    mRemoteRosListeners.finishBroadcast();
 	}
     }
 
--- 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	Wed Apr 08 00:02:09 2009 +0200
@@ -84,6 +84,7 @@
 	    triggerAsynchronousConnectEvent();
 	    return true;
 	} catch (XMPPException e) {
+	    Log.e(TAG, "Error while connecting", e);
 	    mLastException = new BeemException(e);
 	}
 	return false;
@@ -213,6 +214,7 @@
 	 */
 	@Override
 	public void connectionClosed() {
+	    mRoster = null;
 	    final int n = mRemoteConnListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
@@ -233,6 +235,7 @@
 	 */
 	@Override
 	public void connectionClosedOnError(Exception arg0) {
+	    mRoster = null;
 	    final int n = mRemoteConnListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
@@ -262,6 +265,7 @@
 		} 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();
@@ -309,7 +313,11 @@
 
     }
 
-    public boolean isAuthentificated() throws RemoteException {
+    /**
+     * Returns true if currently authenticated by successfully calling the login method.
+     * @return true when successfully authenticated
+     */
+    public boolean isAuthentificated() {
 	return mAdaptee.isAuthenticated();
     }
 
--- 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	Wed Apr 08 00:02:09 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	Wed Apr 08 00:02:09 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	Wed Apr 08 00:02:09 2009 +0200
@@ -88,6 +88,7 @@
     protected void onStart() {
 	super.onStart();
 	Log.i(TAG, "onStart");
+	mBeemApplication.startBeemService();
     }
 
     @Override
@@ -97,12 +98,8 @@
 	 * @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() {
 		callbackShowContactList();
@@ -279,7 +276,7 @@
 		 */
 		v = (TextView) view.findViewById(to[2]);
 		if (v != null) {
-		    v.setText(c.getMMsgState());
+		    v.setText(c.getMsgState());
 		}
 
 		/*
--- 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	Wed Apr 08 00:02:09 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();
     }
--- a/src/com/beem/project/beem/ui/SendIM.java	Tue Apr 07 15:20:28 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java	Wed Apr 08 00:02:09 2009 +0200
@@ -4,7 +4,10 @@
 
 import android.app.ListActivity;
 import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.RemoteException;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.Menu;
@@ -16,8 +19,15 @@
 import android.widget.ArrayAdapter;
 import android.widget.EditText;
 
+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.Message;
+import com.beem.project.beem.service.aidl.IChat;
+import com.beem.project.beem.service.aidl.IChatManager;
+import com.beem.project.beem.service.aidl.IChatManagerListener;
+import com.beem.project.beem.service.aidl.IMessageListener;
+import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
  * @author barbu This activity class provide the view for instant messaging
@@ -31,7 +41,15 @@
     private ArrayAdapter<String> mAdapter;
     private SendIMDialogSmiley mSmyDialog;
     private SharedPreferences mSet;
+    private SharedPreferences mGlobalSettings;
+    private BeemApplication mBeemApplication;
+    private Handler mHandler;
+    private IXmppFacade mService = null;
     private Contact mContact;
+    private IChatManager mChatManager;
+    private IChatManagerListener mChatManagerListener;
+    private IMessageListener mMessageListener;
+    private IChat mChat;
 
     /**
      * Constructor.
@@ -46,11 +64,15 @@
     @Override
     public void onCreate(Bundle saveBundle) {
 	super.onCreate(saveBundle);
-
+	mHandler = new Handler();
+	mChatManagerListener = new OnChatListener();
+	mMessageListener = new OnMessageListener();
+	mBeemApplication = BeemApplication.getApplication(this);
 	setContentView(R.layout.sendim);
 	mToSend = (EditText) findViewById(R.id.userText);
 	mSet = getSharedPreferences("lol", MODE_PRIVATE);
 	mSmyDialog = new SendIMDialogSmiley(this, mSet);
+	mGlobalSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
 
 	mAdapter = new ArrayAdapter<String>(this, R.layout.messagelist,
 		mMessages);
@@ -65,7 +87,16 @@
     @Override
     public void onStart() {
 	super.onStart();
-
+	mBeemApplication.startBeemService();
+	mService = mBeemApplication.getXmppFacade();
+	try {
+	    mChatManager = mService.getChatManager();
+	    mChatManager.addChatCreationListener(mChatManagerListener);
+	    mChat = mChatManager.createChat(mContact, mMessageListener);
+	} catch (RemoteException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
     }
 
     /**
@@ -82,19 +113,17 @@
      */
     private void sendText() {
 	String text = mToSend.getText().toString();
+	String from = mGlobalSettings.getString(getString(R.string.PreferenceJID), "You");
 	if (!text.equals("")) {
-	    /*
-	     * Prepare the message to be send
-	     */
-	    /* Message msg = new Message("barbu", Message.Type.chat); */
-	    /* msg.setBody(text); */
-	    /*
-	     * Rien a voir il faut changer le mContact.getJID() et remplacer
-	     * avec son pseudo cetait juste un test pour savoir qu'on recupere
-	     * bien le contact a qui envoyer les infos
-	     */
-	    mAdapter.add(mContact.getJID() + " "
-		    + getString(R.string.SendIMSays) + text);
+	    Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
+	    msg.setBody(text);
+	    try {
+		mChat.sendMessage(msg);
+	    } catch (RemoteException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	    }
+	    mAdapter.add(from + getString(R.string.SendIMSays) + text);
 	    mToSend.setText(null);
 	}
     }
@@ -139,4 +168,27 @@
 		return false;
 	}
     }
+    
+    private class OnChatListener extends IChatManagerListener.Stub {
+
+	@Override
+	public void chatCreated(IChat chat, boolean locally)
+		throws RemoteException {
+	    Log.i("LOG", "chatCreated");
+	    
+	}
+	
+    }
+    
+    private class OnMessageListener extends IMessageListener.Stub {
+
+	@Override
+	public void processMessage(IChat chat, Message msg)
+		throws RemoteException {
+	    Log.i("LOG", "processMessage");
+	    mAdapter.add(mContact.getJID() + " "
+		    + getString(R.string.SendIMSays) + msg.getBody());
+	}
+	
+    }
 }