# HG changeset patch # User Marseille # Date 1245777766 -7200 # Node ID 1b87dbca7ea2644ed6b0c0ceb760227def29478e # Parent 5b0ad39e0046ddca99b281811d623b98a09cee25# Parent 3178dcbd170a43439f2e8e34188da8cbe1a48e1f Merge. diff -r 5b0ad39e0046 -r 1b87dbca7ea2 res/layout/sendim.xml --- a/res/layout/sendim.xml Tue Jun 23 19:06:57 2009 +0200 +++ b/res/layout/sendim.xml Tue Jun 23 19:22:46 2009 +0200 @@ -50,7 +50,6 @@ @@ -58,7 +57,7 @@ + android:singleLine="false"/> diff -r 5b0ad39e0046 -r 1b87dbca7ea2 res/values/colors.xml --- a/res/values/colors.xml Tue Jun 23 19:06:57 2009 +0200 +++ b/res/values/colors.xml Tue Jun 23 19:22:46 2009 +0200 @@ -2,5 +2,5 @@ #A0C8FF #000000 -#FFFFFF + #FFFFFF \ No newline at end of file diff -r 5b0ad39e0046 -r 1b87dbca7ea2 res/values/styles.xml --- a/res/values/styles.xml Tue Jun 23 19:06:57 2009 +0200 +++ b/res/values/styles.xml Tue Jun 23 19:22:46 2009 +0200 @@ -14,4 +14,19 @@ + + + + + + + + + + diff -r 5b0ad39e0046 -r 1b87dbca7ea2 src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Tue Jun 23 19:06:57 2009 +0200 +++ b/src/com/beem/project/beem/service/Contact.java Tue Jun 23 19:22:46 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 mRes; + private List 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 mRes; - private List 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 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 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 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; } diff -r 5b0ad39e0046 -r 1b87dbca7ea2 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Tue Jun 23 19:06:57 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Tue Jun 23 19:22:46 2009 +0200 @@ -47,10 +47,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); } } @@ -201,6 +198,16 @@ 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. * @author darisk diff -r 5b0ad39e0046 -r 1b87dbca7ea2 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Tue Jun 23 19:06:57 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue Jun 23 19:22:46 2009 +0200 @@ -312,10 +312,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); @@ -338,7 +340,6 @@ } imgV.setImageDrawable(imageDrawable); - TextView v = (TextView) view.findViewById(R.id.contactlistpseudo); if (v != null) { v.setText(curContact.getName()); } diff -r 5b0ad39e0046 -r 1b87dbca7ea2 src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Tue Jun 23 19:06:57 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Tue Jun 23 19:22:46 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 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 addresses) + throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void onEntriesDeleted(List 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 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 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 addresses) - throws RemoteException { - // TODO Auto-generated method stub - - } - - @Override - public void onEntriesDeleted(List addresses) - throws RemoteException { - // TODO Auto-generated method stub - - } - - @Override - public void onEntriesUpdated(List 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"); - } - } + } }