# HG changeset patch # User Da Risk # Date 1243024228 -7200 # Node ID 2b8bebb95bbded51c63243c77ea06ad9913aa269 # Parent e707f2adc40a525d25d1c59155dea6668f99f9ef# Parent 79ccbe331695efcb6d478003b0ad6641089a477e Merge diff -r e707f2adc40a -r 2b8bebb95bbd .hgtags --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgtags Fri May 22 22:30:28 2009 +0200 @@ -0,0 +1,1 @@ +16373c4cd73330fa568960a11a6ee7aea6886a4d sfr-release diff -r e707f2adc40a -r 2b8bebb95bbd AndroidManifest.xml --- a/AndroidManifest.xml Fri May 22 15:55:08 2009 +0200 +++ b/AndroidManifest.xml Fri May 22 22:30:28 2009 +0200 @@ -13,7 +13,7 @@ - + diff -r e707f2adc40a -r 2b8bebb95bbd res/layout/subscription.xml --- a/res/layout/subscription.xml Fri May 22 15:55:08 2009 +0200 +++ b/res/layout/subscription.xml Fri May 22 22:30:28 2009 +0200 @@ -3,6 +3,10 @@ + + + @@ -14,4 +18,5 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="@string/RefuseButton" /> + \ No newline at end of file diff -r e707f2adc40a -r 2b8bebb95bbd res/values/strings.xml --- a/res/values/strings.xml Fri May 22 15:55:08 2009 +0200 +++ b/res/values/strings.xml Fri May 22 22:30:28 2009 +0200 @@ -71,7 +71,7 @@ - says :\n + %s says :\n You say :\n Tip text here Is : @@ -96,6 +96,7 @@ Subscription accepted Subscription error Subscription refused + You have received a request for add by %s. Do you want to accept it ? Not connected diff -r e707f2adc40a -r 2b8bebb95bbd src/com/beem/project/beem/service/BeemChatManager.java --- a/src/com/beem/project/beem/service/BeemChatManager.java Fri May 22 15:55:08 2009 +0200 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Fri May 22 22:30:28 2009 +0200 @@ -113,7 +113,7 @@ Log.w(TAG, "CA devrait pas 1!!" + chat.getParticipant().getJID()); } - private IChat getChat(Chat chat) { + private ChatAdapter getChat(Chat chat) { String key = StringUtils.parseBareAddress(chat.getParticipant()); if (mChats.containsKey(key)) { return mChats.get(key); @@ -172,6 +172,7 @@ notif.defaults = Notification.DEFAULT_ALL; notif.flags = Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(mService, SendIM.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT| Intent.FLAG_ACTIVITY_SINGLE_TOP); // TODO use prefix for name intent.putExtra("contact", chat.getParticipant()); notif.setLatestEventInfo(mService, text, mService.getString(R.string.BeemChatManagerNewMessage), @@ -185,18 +186,18 @@ @Override public void processMessage(Chat chat, Message message) { - IChat newchat = getChat(chat); + ChatAdapter newchat = getChat(chat); try { if (message.getBody() != null) - newchat.addToLastMessages(message.getBody()); + newchat.addMessage(new com.beem.project.beem.service.Message(message)); final int n = mRemoteMessageListeners.beginBroadcast(); for (int i = 0; i < n; i++) { IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i); listener.processMessage(newchat, new com.beem.project.beem.service.Message(message)); } mRemoteMessageListeners.finishBroadcast(); - if (newchat.isOpen() == false) { + if (! newchat.isOpen()) { notifyNewChat(newchat); } } catch (RemoteException e) { diff -r e707f2adc40a -r 2b8bebb95bbd src/com/beem/project/beem/service/ChatAdapter.java --- a/src/com/beem/project/beem/service/ChatAdapter.java Fri May 22 15:55:08 2009 +0200 +++ b/src/com/beem/project/beem/service/ChatAdapter.java Fri May 22 22:30:28 2009 +0200 @@ -3,6 +3,10 @@ */ package com.beem.project.beem.service; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + import org.jivesoftware.smack.Chat; import org.jivesoftware.smack.XMPPException; @@ -20,7 +24,8 @@ private String mState; private StringBuffer mLastMessages; private boolean isOpen; - + private List mMessages; + /** * Constructor. * @param chat The chat to adapt @@ -29,6 +34,7 @@ mLastMessages = new StringBuffer(); mAdaptee = chat; mParticipant = new Contact(chat.getParticipant()); + mMessages = new LinkedList(); } /** @@ -54,6 +60,7 @@ // send.set try { mAdaptee.sendMessage(send); + mMessages.add(message); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -64,7 +71,7 @@ public String getState() throws RemoteException { return mState; } - + @Override public void setState(String state) throws RemoteException { mState = state; @@ -74,24 +81,10 @@ return mAdaptee; } - @Override - public String getLastMessages() throws RemoteException { - return mLastMessages.toString(); - } - - @Override - public void addToLastMessages(String msg) throws RemoteException { - mLastMessages.append(msg).append('\n'); - } - - @Override - public void clearLastMessages() throws RemoteException { - mLastMessages.delete(0, mLastMessages.length()); - } - /** * @param isOpen the isOpen to set */ + @Override public void setOpen(boolean isOpen) { this.isOpen = isOpen; } @@ -99,8 +92,20 @@ /** * @return the isOpen */ + @Override public boolean isOpen() { return isOpen; } + @Override + public List getMessages() throws RemoteException { + return Collections.unmodifiableList(mMessages); + } + + void addMessage(Message msg) { + if (mMessages.size() == 50) + mMessages.remove(0); + mMessages.add(msg); + } + } diff -r e707f2adc40a -r 2b8bebb95bbd src/com/beem/project/beem/service/Message.java --- a/src/com/beem/project/beem/service/Message.java Fri May 22 15:55:08 2009 +0200 +++ b/src/com/beem/project/beem/service/Message.java Fri May 22 22:30:28 2009 +0200 @@ -39,6 +39,7 @@ private String mBody; private String mSubject; private String mTo; + private String mFrom; private String mThread; // TODO ajouter l'erreur @@ -69,6 +70,7 @@ mBody = ""; mSubject = ""; mThread = ""; + mFrom = null; } /** @@ -100,6 +102,7 @@ Log.w("BEEM_MESSAGE", "type de message non gerer" + smackMsg.getType()); break; } + this.mFrom = smackMsg.getFrom(); if (mType == MSG_TYPE_ERROR) { XMPPError er = smackMsg.getError(); String msg = er.getMessage(); @@ -124,6 +127,7 @@ mBody = in.readString(); mSubject = in.readString(); mThread = in.readString(); + mFrom = in.readString(); } /** @@ -137,6 +141,7 @@ dest.writeString(mBody); dest.writeString(mSubject); dest.writeString(mThread); + dest.writeString(mFrom); } /** @@ -204,6 +209,20 @@ } /** + * @param mFrom the mFrom to set + */ + public void setFrom(String mFrom) { + this.mFrom = mFrom; + } + + /** + * @return the mFrom + */ + public String getFrom() { + return mFrom; + } + + /** * Get the thread of the message. * @return the thread */ diff -r e707f2adc40a -r 2b8bebb95bbd src/com/beem/project/beem/service/aidl/IChat.aidl --- a/src/com/beem/project/beem/service/aidl/IChat.aidl Fri May 22 15:55:08 2009 +0200 +++ b/src/com/beem/project/beem/service/aidl/IChat.aidl Fri May 22 22:30:28 2009 +0200 @@ -29,14 +29,6 @@ void setState(in String state); - String getLastMessages(); - - void addToLastMessages(in String msg); - - void clearLastMessages(); -/* - void addMessageListener(in IMessageListener listener); - - void removeMessageListener(in IMessageListener listener); -*/ + List getMessages(); + } \ No newline at end of file diff -r e707f2adc40a -r 2b8bebb95bbd src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Fri May 22 15:55:08 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Fri May 22 22:30:28 2009 +0200 @@ -1,6 +1,9 @@ package com.beem.project.beem.ui; +import java.util.List; + import android.app.Activity; +import android.content.Intent; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -50,7 +53,7 @@ private TextView mText; private TextView mLogin; private ScrollView mScrolling; - private boolean mSpeak; + private char mSpeak; /** * Constructor. @@ -82,31 +85,29 @@ mScrolling = (ScrollView) findViewById(R.id.sendimscroll); } - private void setViewHeader() { - Drawable avatar = (Drawable) getResources().getDrawable(R.drawable.avatar); - ImageView imgV = (ImageView) findViewById(R.id.sendimavatar); - imgV.setImageDrawable(avatar); - mLogin = (TextView) findViewById(R.id.sendimlogin); - mLogin.setText(mContact.getJID()); - TextView status = (TextView) findViewById(R.id.sendimstatus); - status.setTextSize(12); - mLogin.setTextColor(getResources().getColor(R.color.white)); - String statmsg = mContact.getMsgState(); - if (statmsg != null) - status.setText(statmsg);; - } - @Override - public void onStart() { + protected void onStart() { super.onStart(); // TODO cancel the notification if any if (mContact == null) - mContact = getIntent().getParcelableExtra("contact"); + mContact = getIntent().getParcelableExtra("contact"); mService = mBeemApplication.getXmppFacade(); setViewHeader(); } + @Override + protected void onNewIntent(Intent intent) { + // TODO Auto-generated method stub + super.onNewIntent(intent); + Contact c = intent.getParcelableExtra("contact"); + try { + switchChat(c); + } catch (RemoteException e) { + Log.e(TAG, "Error durring switch chat", e); + } + setViewHeader(); + } @Override protected void onResume() { @@ -122,21 +123,14 @@ try { mChatManager = mService.getChatManager(); mChatManager.addChatCreationListener(mChatManagerListener); - mChat = mChatManager.createChat(mContact, mMessageListener); - String text = mChat.getLastMessages(); - if (!"".equals(text)) { - mText.append(mContact.getJID() + " " + getString(R.string.SendIMSays)); - mText.append(text); - //mChat.clearLastMessages(); - } - mChat.setOpen(true); + switchChat(mContact); } catch (RemoteException e) { Log.e(TAG, "Error during chat manager creation", e); } } }); + } - } @Override protected void onPause() { Log.d(TAG, "onPause"); @@ -168,7 +162,8 @@ if (mChatManager != null) { try { mChatManager.removeChatCreationListener(mChatManagerListener); - mChatManager.destroyChat(mChat); + // TODO trouver quand detruire le chat + // mChatManager.destroyChat(mChat); } catch (RemoteException e) { Log.e(TAG, "mchat manager and SendIM destroy", e); } @@ -184,34 +179,6 @@ } /** - * This method send a message to the server over the XMPP connection and display it on activity view TODO : - * Exception si la connexion se coupe pendant la conversation - */ - private void sendText() { - if (mSpeak) - mSpeak = false; - String text = mToSend.getText().toString(); - if (!text.equals("")) { - 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(); - } - if (!mSpeak) - mText.append(getString(R.string.SendIMYouSay) + text + "\n"); - else - mText.append(text + "\n"); - mToSend.setText(null); - mScrolling.fullScroll(ScrollView.FOCUS_DOWN); - mToSend.requestFocus(); - mSpeak = true; - } - } - - /** * Abstract method inherited from OnKeyListener */ public boolean onKey(View v, int keyCode, KeyEvent event) { @@ -250,6 +217,76 @@ } } + /** + * This method send a message to the server over the XMPP connection and display it on activity view TODO : + * 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 { + mChat.sendMessage(msg); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + 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; + } + } + + 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; + } + + private void setViewHeader() { + Drawable avatar = (Drawable) getResources().getDrawable(R.drawable.avatar); + ImageView imgV = (ImageView) findViewById(R.id.sendimavatar); + imgV.setImageDrawable(avatar); + mLogin = (TextView) findViewById(R.id.sendimlogin); + mLogin.setText(mContact.getJID()); + TextView status = (TextView) findViewById(R.id.sendimstatus); + status.setTextSize(12); + mLogin.setTextColor(getResources().getColor(R.color.white)); + String statmsg = mContact.getMsgState(); + if (statmsg != null) + status.setText(statmsg); + } + + 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); + } + private class OnChatListener extends IChatManagerListener.Stub { @Override @@ -272,22 +309,26 @@ @Override public void run() { if (m.getBody() != null) { - if (!mSpeak) + if (mSpeak == 2) mText.append(m.getBody() + "\n"); - else - mText.append(mContact.getJID() + " " + getString(R.string.SendIMSays) + m.getBody() + "\n"); - mSpeak = false; + 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; } + } }); } @Override public void stateChanged(IChat chat) throws RemoteException { - //TODO: a integrer dans l'ui - //Log.d(TAG, "state changed"); + // TODO: a integrer dans l'ui + // Log.d(TAG, "state changed"); } } } diff -r e707f2adc40a -r 2b8bebb95bbd src/com/beem/project/beem/ui/Subscription.java --- a/src/com/beem/project/beem/ui/Subscription.java Fri May 22 15:55:08 2009 +0200 +++ b/src/com/beem/project/beem/ui/Subscription.java Fri May 22 22:30:28 2009 +0200 @@ -16,6 +16,7 @@ import android.os.RemoteException; import android.view.View; import android.view.View.OnClickListener; +import android.widget.TextView; import android.widget.Toast; /** @@ -34,6 +35,9 @@ findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener); findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener); mContact = getIntent().getStringExtra("from"); + TextView tv = (TextView) findViewById(R.id.SubscriptionText); + String str = String.format(getString(R.string.SubscriptText), mContact); + tv.setText(str); mService = BeemApplication.getApplication(this).getXmppFacade(); }