# HG changeset patch # User Philippe Lago # Date 1239142344 -7200 # Node ID 7d0e36aa1be5049158a66bbd625d0330c9801ab0 # Parent 9a4dbd7fe5460ce8f23d78a92969a23d42e9f0c6# Parent 2e6e98e9f8efdae62104e7220d2539d7626a2cd3 le commit apres le merge j'apprends diff -r 2e6e98e9f8ef -r 7d0e36aa1be5 res/layout/messagelist.xml --- a/res/layout/messagelist.xml Tue Apr 07 21:50:45 2009 +0200 +++ b/res/layout/messagelist.xml Wed Apr 08 00:12:24 2009 +0200 @@ -1,7 +1,6 @@ \ No newline at end of file diff -r 2e6e98e9f8ef -r 7d0e36aa1be5 res/layout/sendim.xml --- a/res/layout/sendim.xml Tue Apr 07 21:50:45 2009 +0200 +++ b/res/layout/sendim.xml Wed Apr 08 00:12:24 2009 +0200 @@ -2,8 +2,7 @@ + android:layout_height="fill_parent"> SOCKS5 - says :\n + says :\n Tip text here Is : and is speaking from : diff -r 2e6e98e9f8ef -r 7d0e36aa1be5 src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Tue Apr 07 21:50:45 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Wed Apr 08 00:12:24 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 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(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()); + } + + } }