merge avec marseille
authorPhilippe Lago <lago_p@epitech.net>
Tue, 23 Jun 2009 18:36:28 +0200
changeset 281 3178dcbd170a
parent 280 f34b1da1c668 (diff)
parent 275 5a07bf00b2f8 (current diff)
child 285 1b87dbca7ea2
merge avec marseille
src/com/beem/project/beem/BeemApplication.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/ui/ContactList.java
--- a/res/layout/sendim.xml	Tue Jun 23 15:43:49 2009 +0200
+++ b/res/layout/sendim.xml	Tue Jun 23 18:36:28 2009 +0200
@@ -50,7 +50,6 @@
 
 	<ScrollView android:id="@+id/sendimscroll"
 		android:layout_width="fill_parent" android:layout_height="fill_parent"
-		android:background="@drawable/beem_sendim_textview"
 		android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
 		android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
 		android:scrollbarSize="12dip" android:layout_weight="1">
@@ -58,7 +57,7 @@
 		<TextView android:id="@+id/sendimlist" android:paddingLeft="10px"
 			android:paddingRight="10px" android:paddingTop="10px"
 			android:layout_width="fill_parent" android:layout_height="fill_parent"
-			android:singleLine="false" />
+			android:singleLine="false"/>
 
 	</ScrollView>
 
--- a/res/values/colors.xml	Tue Jun 23 15:43:49 2009 +0200
+++ b/res/values/colors.xml	Tue Jun 23 18:36:28 2009 +0200
@@ -2,5 +2,5 @@
 <resources>
 	<color name="blue_sky">#A0C8FF</color>
 	<color name="black">#000000</color>
-<color name="white">#FFFFFF</color>
+	<color name="white">#FFFFFF</color>
 </resources>
\ No newline at end of file
--- a/res/values/styles.xml	Tue Jun 23 15:43:49 2009 +0200
+++ b/res/values/styles.xml	Tue Jun 23 18:36:28 2009 +0200
@@ -14,4 +14,19 @@
 	<style name="Theme.BEEM.Default" parent="@android:style/Theme">
 		<item name="android:windowBackground">@drawable/background</item>
 	</style>
+	
+
+<!-- Old PC style -->
+
+	<style name="OldTheme">
+		<item name="android:textViewStyle" >@style/OldThemeTextView</item>
+	</style>
+	<style name="OldThemeTextView" parent="@android:style/Widget.TextView">
+		<item name="android:textColor">#ff009900</item>
+		<item name="android:background">@color/black</item>
+	</style>
+	
+	
+<!-- Other style -->
+
 </resources>
--- a/src/com/beem/project/beem/service/Contact.java	Tue Jun 23 15:43:49 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java	Tue Jun 23 18:36:28 2009 +0200
@@ -7,6 +7,7 @@
 import java.util.Collection;
 import java.util.List;
 
+import org.jivesoftware.smack.RosterEntry;
 import org.jivesoftware.smack.RosterGroup;
 import org.jivesoftware.smack.packet.Presence;
 import org.jivesoftware.smack.util.StringUtils;
@@ -22,6 +23,14 @@
  * @author darisk
  */
 public class Contact implements Parcelable {
+   
+    private int mID;
+    private int mStatus;
+    private String mJID;
+    private String mMsgState;
+    private List<String> mRes;
+    private List<String> mGroups;
+    private String mName;
 
     /**
      * Parcelable.Creator needs by Android.
@@ -39,14 +48,6 @@
 	}
     };
 
-    private int mID;
-    private int mStatus;
-    private String mJID;
-    private String mMsgState;
-    private List<String> mRes;
-    private List<String> mGroups;
-    private String mName;
-
     /**
      * Constructor.
      */
@@ -55,7 +56,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();
@@ -71,7 +73,8 @@
 
     /**
      * Constructor.
-     * @param jid JID of the contact
+     * @param jid
+     *            JID of the contact
      */
     public Contact(final String jid) {
 	mJID = jid;
@@ -84,8 +87,10 @@
 
     /**
      * Create a contact from a Uri.
-     * @param uri an uri for the contact
-     * @throws IllegalArgumentException if it is not a xmpp uri
+     * @param uri
+     *            an uri for the contact
+     * @throws IllegalArgumentException
+     *             if it is not a xmpp uri
      */
     public Contact(Uri uri) {
 	if (!uri.getScheme().equals("xmpp"))
@@ -95,7 +100,8 @@
 
     /**
      * Add a group for the contact.
-     * @param group the group
+     * @param group
+     *            the group
      */
     public void addGroup(String group) {
 	if (!mGroups.contains(group))
@@ -108,7 +114,8 @@
 
     /**
      * Add a resource for this contact.
-     * @param res the resource to add
+     * @param res
+     *            the resource to add
      */
     public void addRes(String res) {
 	if (!mRes.contains(res))
@@ -117,7 +124,8 @@
 
     /**
      * Delete a resource for this contact.
-     * @param res the resource de delete
+     * @param res
+     *            the resource de delete
      */
     public void delRes(String res) {
 	mRes.remove(res);
@@ -189,7 +197,8 @@
 
     /**
      * Set the groups the contact is in.
-     * @param groups list of groups
+     * @param groups
+     *            list of groups
      */
     public void setGroups(Collection<RosterGroup> groups) {
 	this.mGroups.clear();
@@ -200,7 +209,8 @@
 
     /**
      * Set the groups the contact is in.
-     * @param mGroups the mGroups to set
+     * @param mGroups
+     *            the mGroups to set
      */
     public void setGroups(List<String> mGroups) {
 	this.mGroups = mGroups;
@@ -208,7 +218,8 @@
 
     /**
      * set the id of te contact on the phone contact list.
-     * @param mid the mID to set
+     * @param mid
+     *            the mID to set
      */
     public void setID(int mid) {
 	mID = mid;
@@ -216,7 +227,8 @@
 
     /**
      * Set the Jabber ID of the contact.
-     * @param jid the jabber ID to set
+     * @param jid
+     *            the jabber ID to set
      */
     public void setJID(String jid) {
 	mJID = jid;
@@ -224,7 +236,8 @@
 
     /**
      * Set a list of resource for the contact.
-     * @param mRes the mRes to set
+     * @param mRes
+     *            the mRes to set
      */
     public void setMRes(List<String> mRes) {
 	this.mRes = mRes;
@@ -232,14 +245,16 @@
 
     /**
      * Set the message status of the contact.
-     * @param msgState the message status of the contact to set
+     * @param msgState
+     *            the message status of the contact to set
      */
     public void setMsgState(String msgState) {
 	mMsgState = msgState;
     }
 
     /**
-     * @param mName the mName to set
+     * @param mName
+     *            the mName to set
      */
     public void setName(String mName) {
 	if (mName != null)
@@ -248,7 +263,8 @@
 
     /**
      * Set the status of the contact.
-     * @param status the mStatus to set
+     * @param status
+     *            the mStatus to set
      */
     public void setStatus(int status) {
 	mStatus = status;
@@ -256,7 +272,8 @@
 
     /**
      * Set the status of the contact using a presence packet.
-     * @param presence the presence containing status
+     * @param presence
+     *            the presence containing status
      */
     public void setStatus(Presence presence) {
 	mStatus = Status.getStatusFromPresence(presence);
@@ -265,7 +282,8 @@
 
     /**
      * Set status for the contact.
-     * @param presence The presence packet which contains the status
+     * @param presence
+     *            The presence packet which contains the status
      */
     public void setStatus(PresenceAdapter presence) {
 	mStatus = presence.getStatus();
@@ -289,7 +307,8 @@
      */
     public Uri toUri() {
 	StringBuilder build = new StringBuilder("xmpp:");
-	build.append(StringUtils.parseName(mJID)).append('@').append(StringUtils.parseServer(mJID));
+	build.append(StringUtils.parseName(mJID)).append('@').append(
+		StringUtils.parseServer(mJID));
 	Uri u = Uri.parse(build.toString());
 	return u;
     }
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Tue Jun 23 15:43:49 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Tue Jun 23 18:36:28 2009 +0200
@@ -27,7 +27,8 @@
  * This class implement a Roster adapter for BEEM.
  * @author darisk
  */
-public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
+public class RosterAdapter extends
+	com.beem.project.beem.service.aidl.IRoster.Stub {
 
     private static final String TAG = "RosterAdapter";
     private Roster mAdaptee;
@@ -39,7 +40,8 @@
 
     /**
      * Constructor.
-     * @param roster the roster to adapt
+     * @param roster
+     *            the roster to adapt
      */
     public RosterAdapter(final Roster roster) {
 	mAdaptee = roster;
@@ -47,10 +49,7 @@
 	for (RosterEntry entry : roster.getEntries()) {
 	    String user = StringUtils.parseBareAddress(entry.getUser());
 	    if (!mContacts.containsKey(user)) {
-		Contact c = new Contact(user);
-		c.setStatus(roster.getPresence(user));
-		c.setGroups(entry.getGroups());
-		c.setName(entry.getName());
+		Contact c = getContactFromRosterEntry(entry);
 		mContacts.put(user, c);
 	    }
 	}
@@ -60,7 +59,8 @@
      * {@inheritDoc}
      */
     @Override
-    public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
+    public void addRosterListener(IBeemRosterListener listen)
+	    throws RemoteException {
 	if (listen != null)
 	    mRemoteRosListeners.register(listen);
     }
@@ -69,7 +69,8 @@
      * {@inheritDoc}
      */
     @Override
-    public Contact addContact(String user, String name, String[] groups) throws RemoteException {
+    public Contact addContact(String user, String name, String[] groups)
+	    throws RemoteException {
 	Contact res = null;
 	RosterEntry contact = mAdaptee.getEntry(user);
 	if (contact != null) {
@@ -78,7 +79,8 @@
 		for (String groupStr : groups) {
 		    boolean found = false;
 		    for (RosterGroup group : mAdaptee.getGroups()) {
-			if (group.getName().equals(groupStr) && !group.contains(contact)) {
+			if (group.getName().equals(groupStr)
+				&& !group.contains(contact)) {
 			    try {
 				group.addEntry(contact);
 				res.addGroup(groupStr);
@@ -126,10 +128,12 @@
      * {@inheritDoc}
      */
     @Override
-    public void deleteContact(Contact contact, String group) throws RemoteException {
+    public void deleteContact(Contact contact, String group)
+	    throws RemoteException {
 	mContacts.get(contact.getJID()).delGroup(group);
 	try {
-	    mAdaptee.getGroup(group).removeEntry(mAdaptee.getEntry(contact.getJID()));
+	    mAdaptee.getGroup(group).removeEntry(
+		    mAdaptee.getEntry(contact.getJID()));
 	} catch (XMPPException e) {
 	    e.printStackTrace();
 	}
@@ -178,7 +182,8 @@
      * {@inheritDoc}
      */
     @Override
-    public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
+    public void removeRosterListener(IBeemRosterListener listen)
+	    throws RemoteException {
 	if (listen != null)
 	    mRemoteRosListeners.unregister(listen);
     }
@@ -197,8 +202,18 @@
 	return new PresenceAdapter(mAdaptee.getPresence(jid));
     }
 
+    private Contact getContactFromRosterEntry(RosterEntry entry) {
+	String user = StringUtils.parseBareAddress(entry.getUser());
+	Contact c = new Contact(user);
+	c.setStatus(mAdaptee.getPresence(user));
+	c.setGroups(entry.getGroups());
+	c.setName(entry.getName());
+	return c;
+    }
+
     /**
-     * Listener for the roster events. It will call the remote listeners registered.
+     * Listener for the roster events. It will call the remote listeners
+     * registered.
      * @author darisk
      */
     private class RosterListenerAdapter implements RosterListener {
@@ -220,7 +235,8 @@
 	    List<String> tab = new ArrayList<String>();
 	    tab.addAll(addresses);
 	    for (int i = 0; i < n; i++) {
-		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		IBeemRosterListener listener = mRemoteRosListeners
+			.getBroadcastItem(i);
 		try {
 		    listener.onEntriesAdded(tab);
 		} catch (RemoteException e) {
@@ -241,7 +257,8 @@
 	    List<String> tab = new ArrayList<String>();
 	    tab.addAll(addresses);
 	    for (int i = 0; i < n; i++) {
-		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		IBeemRosterListener listener = mRemoteRosListeners
+			.getBroadcastItem(i);
 		try {
 		    listener.onEntriesDeleted(tab);
 		} catch (RemoteException e) {
@@ -262,7 +279,8 @@
 	    List<String> tab = new ArrayList<String>();
 	    tab.addAll(addresses);
 	    for (int i = 0; i < n; i++) {
-		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		IBeemRosterListener listener = mRemoteRosListeners
+			.getBroadcastItem(i);
 		try {
 		    listener.onEntriesUpdated(tab);
 		} catch (RemoteException e) {
@@ -291,7 +309,8 @@
 	    final int n = mRemoteRosListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
-		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		IBeemRosterListener listener = mRemoteRosListeners
+			.getBroadcastItem(i);
 		try {
 		    listener.onPresenceChanged(new PresenceAdapter(presence));
 		} catch (RemoteException e) {
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Jun 23 15:43:49 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Tue Jun 23 18:36:28 2009 +0200
@@ -311,10 +311,12 @@
 
 	    if (curContact != null) {
 		ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
+		TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
 		Drawable imageDrawable = null;
 		switch (curContact.getStatus()) {
 		    case Status.CONTACT_STATUS_AVAILABLE:
 			imageDrawable = getResources().getDrawable(R.drawable.online);
+			v.setTextColor(getResources().getColor(R.color.white));
 			break;
 		    case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
 			imageDrawable = getResources().getDrawable(R.drawable.chat);
@@ -337,7 +339,6 @@
 		}
 		imgV.setImageDrawable(imageDrawable);
 
-		TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
 		if (v != null) {
 		    v.setText(curContact.getName());
 		}
--- a/src/com/beem/project/beem/ui/SendIM.java	Tue Jun 23 15:43:49 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java	Tue Jun 23 18:36:28 2009 +0200
@@ -42,388 +42,429 @@
 import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
- * 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 EditText mToSend;
-	private SendIMDialogSmiley mSmyDialog;
-	private SharedPreferences mSet;
-	private Handler mHandler;
-	private Contact mContact;
-	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 static final String TAG = "SEND_IM";
+    private EditText mToSend;
+    private SendIMDialogSmiley mSmyDialog;
+    private SharedPreferences mSet;
+    private Handler mHandler;
+    private Contact mContact;
+    private String mContactName;
+    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 xmppFacade;
+    public IRoster mRoster;
+    private TextView mStatusText;
+
+    /**
+     * 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);
+	mLogin = (TextView) findViewById(R.id.sendimlogin);
+	try {
+	    mContact = new Contact(getIntent().getData());
+	    if (mRoster != null)
+		mContact = mRoster.getContact(mContact.getJID());
+	} catch (RemoteException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+	mText = (TextView) findViewById(R.id.sendimlist);
+	mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
+	mStatusText = (TextView) findViewById(R.id.sendimstatus);
+	setViewHeader();
+    }
+
+    /**
+     * Set the header information in the window.
+     */
+    private void setViewHeader() {
+	Drawable avatar = getResources().getDrawable(R.drawable.avatar);
+	ImageView imgV = (ImageView) findViewById(R.id.sendimavatar);
+	imgV.setImageDrawable(avatar);
+	mStatusText.setTextSize(12);
+	mContactName = mContact.getName();
+	if (mContactName == null || "".equals(mContactName)) {
+	    mContactName = mContact.getJID();
+	    mContactName = StringUtils.parseName(mContactName);
+	}
+	mLogin.setText(mContactName);
+    }
+
+    /**
+     * {@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();
+	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 final ServiceConnection mServConn = new BeemServiceConnection();
-	private IXmppFacade xmppFacade;
-	public IRoster mRoster;
-	private TextView mStatusText;
+    /**
+     * {@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();
+	}
+	setViewHeader();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final boolean onOptionsItemSelected(MenuItem item) {
+	switch (item.getItemId()) {
+	    case R.id.sendim_smiley:
+		mSmyDialog.show();
+		return true;
+	    default:
+		return false;
+	}
+    }
 
-	/**
-	 * Constructor.
-	 */
-	public SendIM() {
-		super();
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onPause() {
+	super.onPause();
+	try {
+	    mChat.setOpen(false);
+	} catch (RemoteException e) {
+	    Log.d(TAG, "Error while closing chat", e);
+	}
+	unbindService(mServConn);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onResume() {
+	super.onResume();
+	bindService(new Intent(this, BeemService.class), mServConn,
+		BIND_AUTO_CREATE);
+	mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void onStart() {
+	super.onStart();
+	// TODO cancel the notification if any
+	if (mContact == null)
+	    mContact = getIntent().getParcelableExtra("contact");
+	try {
+	    if (mRoster != null)
+		mContact = mRoster.getContact(mContact.getJID());
+	} catch (RemoteException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+	setViewHeader();
+
+    }
+
+    private class BeemServiceConnection implements ServiceConnection {
+
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    xmppFacade = IXmppFacade.Stub.asInterface(service);
+	    try {
+		if (mChatManager == null) {
+		    mChatManager = xmppFacade.getChatManager();
+		    mChatManager.addChatCreationListener(mChatManagerListener);
+		}
+		mRoster = xmppFacade.getRoster();
+		if (mRoster != null) {
+		    mRoster.addRosterListener(new BeemRosterListener());
+		    // mContact.setStatus(mRoster.getPresence(mContact.getJID()));
+		    mContact = mRoster.getContact(mContact.getJID());
+		    mStatusText.setText(mContact.getMsgState());
+		    Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
+		}
+		switchChat(mContact);
+	    } catch (RemoteException e) {
+		Log.e(TAG, "Error during chat manager creation", e);
+	    }
 	}
 
+	@Override
+	public void onServiceDisconnected(ComponentName name) {
+	    xmppFacade = 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 (!text.equals("")) {
+	    Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
+	    msg.setBody(text);
+	    try {
+		// TODO: PAs connecter au serveur BING grosse Error !
+		// INTERDICTION !
+		mChat.sendMessage(msg);
+		if (mSpeak != 1)
+		    mText
+			    .append(getString(R.string.SendIMYouSay) + text
+				    + '\n');
+		else
+		    mText.append(text + "\n");
+		mToSend.setText(null);
+		mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+		mToSend.requestFocus();
+		mSpeak = 1;
+	    } catch (RemoteException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	    }
+	}
+    }
+
+    /**
+     * 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));
+		mSpeak = 1;
+	    } else {
+		if (mSpeak != 2) {
+		    String str = String.format(getString(R.string.SendIMSays),
+			    mContactName);
+		    mText.append(str);
+		}
+		mSpeak = 2;
+	    }
+	    mText.append(message.getBody() + '\n');
+	}
+	mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+    }
+
+    /**
+     * 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);
+	mContact = newContact;
+	mToSend.requestFocus();
+    }
+
+    /**
+     * Listener for chat creation. (maybe not necessary)
+     * @author darisk
+     */
+    private class OnChatListener extends IChatManagerListener.Stub {
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void onClick(View view) {
-		sendText();
+	public void chatCreated(IChat chat, boolean locally)
+		throws RemoteException {
+	    Log.i("LOG", "chatCreated");
+	}
+
+    }
+
+    private class BeemRosterListener extends IBeemRosterListener.Stub {
+
+	@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
+
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
 	@Override
-	protected void onCreate(Bundle saveBundle) {
-		super.onCreate(saveBundle);
-		mHandler = new Handler();
-		mChatManagerListener = new OnChatListener();
-		mMessageListener = new OnMessageListener();
-		setContentView(R.layout.sendim);
-		mToSend = (EditText) findViewById(R.id.userText);
-		mSet = getSharedPreferences("lol", MODE_PRIVATE);
-		mSmyDialog = new SendIMDialogSmiley(this, mSet);
-		mToSend.setOnClickListener(this);
-		mToSend.setOnKeyListener(this);
-		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.sendimstatus);
-		setViewHeader();
+	public void onEntriesUpdated(List<String> addresses)
+		throws RemoteException {
+	    // TODO Auto-generated method stub
+
 	}
 
-	/**
-	 * Set the header information in the window.
-	 */
-	private void setViewHeader() {
-		Drawable avatar = getResources().getDrawable(R.drawable.avatar);
-		ImageView imgV = (ImageView) findViewById(R.id.sendimavatar);
-		imgV.setImageDrawable(avatar);		
-		mStatusText.setTextSize(12);
-		mLogin.setText(mContact.getJID());
-		mLogin.setTextColor(getResources().getColor(R.color.white));
+	@Override
+	public void onPresenceChanged(PresenceAdapter presence)
+		throws RemoteException {
+	    if (mContact.getJID().equals(
+		    StringUtils.parseBareAddress(presence.getFrom()))) {
+		mContact.setStatus(mRoster.getPresence(StringUtils
+			.parseBareAddress(presence.getFrom())));
+		mHandler.post(new RunnableChange());
+	    }
 	}
 
+	private class RunnableChange implements Runnable {
+	    @Override
+	    public void run() {
+		mStatusText.setText(mContact.getMsgState());
+		Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
+	    }
+	}
+
+    }
+
+    /**
+     * Listener for new chat messages.
+     * @author darisk
+     */
+    private class OnMessageListener extends IMessageListener.Stub {
+
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public final boolean onCreateOptionsMenu(Menu menu) {
-		super.onCreateOptionsMenu(menu);
-		MenuInflater inflater = getMenuInflater();
-		inflater.inflate(R.menu.sendimmenu, menu);
-		return true;
-	}
+	public void processMessage(IChat chat, Message msg)
+		throws RemoteException {
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		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);
-			}
-		}
-	}
-
-	/**
-	 * {@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;
-	}
+	    if (chat != mChat)
+		return;
+	    final Message m = msg;
+	    mHandler.post(new Runnable() {
 
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onNewIntent(Intent intent) {
-		super.onNewIntent(intent);
-		mContact = new Contact(intent.getData());
-		setViewHeader();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public final boolean onOptionsItemSelected(MenuItem item) {
-		switch (item.getItemId()) {
-		case R.id.sendim_smiley:
-			mSmyDialog.show();
-			return true;
-		default:
-			return false;
+		@Override
+		public void run() {
+		    if (m.getBody() != null) {
+			if (mSpeak == 2)
+			    mText.append(m.getBody() + "\n");
+			else {
+			    
+			    String str = String
+				    .format(getString(R.string.SendIMSays), mContactName);
+			    mText.append(str);
+			    mText.append(m.getBody() + "\n");
+			}
+			mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+			mToSend.requestFocus();
+			mSpeak = 2;
+		    }
 		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onPause() {
-		super.onPause();
-		try {
-			mChat.setOpen(false);
-		} catch (RemoteException e) {
-			Log.d(TAG, "Error while closing chat", e);
-		}
-		unbindService(mServConn);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	protected void onResume() {
-		super.onResume();
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+	    });
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected void onStart() {
-		super.onStart();
-		// TODO cancel the notification if any
-		if (mContact == null)
-			mContact = getIntent().getParcelableExtra("contact");
-		setViewHeader();
-
-	}
-
-	private class BeemServiceConnection implements ServiceConnection {
-
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			xmppFacade = IXmppFacade.Stub.asInterface(service);
-			try {
-				if (mChatManager == null) {
-					mChatManager = xmppFacade.getChatManager();
-					mChatManager.addChatCreationListener(mChatManagerListener);
-				}
-				switchChat(mContact);
-			} catch (RemoteException e) {
-				Log.e(TAG, "Error during chat manager creation", e);
-			}
-			try {
-				mRoster = xmppFacade.getRoster();
-				if (mRoster != null) {
-					mRoster.addRosterListener(new BeemRosterListener());
-					mContact.setStatus(mRoster.getPresence(mContact.getJID()));
-					mStatusText.setText(mContact.getMsgState());
-					Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
-				}
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			xmppFacade = 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 (!text.equals("")) {
-			Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
-			msg.setBody(text);
-			try {
-				// TODO: PAs connecter au serveur BING grosse Error ! INTERDICTION !
-				mChat.sendMessage(msg);
-				if (mSpeak != 1)
-					mText.append(getString(R.string.SendIMYouSay) + text + '\n');
-				else
-					mText.append(text + "\n");
-				mToSend.setText(null);
-				mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
-				mToSend.requestFocus();
-				mSpeak = 1;
-			} catch (RemoteException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}	
-
-	/**
-	 * 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));
-				mSpeak = 1;
-			} else {
-				if (mSpeak != 2) {
-					String str = String.format(getString(R.string.SendIMSays), from);
-					mText.append(str);
-				}
-				mSpeak = 2;
-			}
-			mText.append(message.getBody() + '\n');
-		}
-		mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+	public void stateChanged(IChat chat) throws RemoteException {
+	    // TODO: a integrer dans l'ui
+	    // Log.d(TAG, "state changed");
 	}
-
-	/**
-	 * 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);
-		mContact = newContact;
-		mToSend.requestFocus();
-	}
-
-	/**
-	 * Listener for chat creation. (maybe not necessary)
-	 * @author darisk
-	 */
-	private class OnChatListener extends IChatManagerListener.Stub {
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void chatCreated(IChat chat, boolean locally) throws RemoteException {
-			Log.i("LOG", "chatCreated");
-		}
-
-	}
-	private class BeemRosterListener extends IBeemRosterListener.Stub {
-
-		@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
-
-		}
-
-		@Override
-		public void onEntriesUpdated(List<String> addresses)
-		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())));
-				mHandler.post(new RunnableChange());
-			}
-		}
-
-		private class RunnableChange implements Runnable {
-			@Override
-			public void run() {
-				mStatusText.setText(mContact.getMsgState());
-				Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
-			}
-		}
-
-	}
-
-	/**
-	 * Listener for new chat messages.
-	 * @author darisk
-	 */
-	private class OnMessageListener extends IMessageListener.Stub {
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void processMessage(IChat chat, Message msg) throws RemoteException {
-
-			if (chat != mChat)
-				return;
-			final Message m = msg;
-			mHandler.post(new Runnable() {
-
-				@Override
-				public void run() {
-					if (m.getBody() != null) {
-						if (mSpeak == 2)
-							mText.append(m.getBody() + "\n");
-						else {
-							String str = String.format(getString(R.string.SendIMSays), m.getFrom());
-							mText.append(str);
-							mText.append(m.getBody() + "\n");
-						}
-						mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
-						mToSend.requestFocus();
-						mSpeak = 2;
-					}
-				}
-			});
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void stateChanged(IChat chat) throws RemoteException {
-			// TODO: a integrer dans l'ui
-			// Log.d(TAG, "state changed");
-		}
-	}
+    }
 
 }