# HG changeset patch # User Da Risk # Date 1243105167 -7200 # Node ID bb656974bab15b1a69dd29d64cb8d65bad93ee5c # Parent f72be51936d5022402e7782508d15c20a92dbf61 Some javadocs diff -r f72be51936d5 -r bb656974bab1 src/com/beem/project/beem/service/BeemChatManager.java --- a/src/com/beem/project/beem/service/BeemChatManager.java Sat May 23 20:15:18 2009 +0200 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Sat May 23 20:59:27 2009 +0200 @@ -50,8 +50,9 @@ /** * Constructor. * @param chatManager the smack ChatManager to adapt + * @param service the service which runs the chat manager */ - public BeemChatManager(final ChatManager chatManager, BeemService service) { + public BeemChatManager(final ChatManager chatManager, final BeemService service) { mService = service; mAdaptee = chatManager; mAdaptee.addChatListener(mChatListener); @@ -67,7 +68,7 @@ mRemoteMessageListeners.register(listener); String key = StringUtils.parseBareAddress(jid); if (mChats.containsKey(key)) { - return (mChats.get(key)); + return mChats.get(key); } // create the chat. the adaptee will be add automatically in the map mAdaptee.createChat(key, mChatListener); @@ -107,12 +108,17 @@ @Override public void destroyChat(IChat chat) throws RemoteException { // TODO gerer les resources egalement - Log.d(TAG, "destroy chat jid "+ chat.getParticipant().getJID()); + Log.d(TAG, "destroy chat jid " + chat.getParticipant().getJID()); IChat c = mChats.remove(chat.getParticipant().getJID()); if (c == null) Log.w(TAG, "CA devrait pas 1!!" + chat.getParticipant().getJID()); } + /** + * Get an existing ChatAdapter or create it if necessary. + * @param chat The real instance of smack chat + * @return a chat adapter register in the manager + */ private ChatAdapter getChat(Chat chat) { String key = StringUtils.parseBareAddress(chat.getParticipant()); if (mChats.containsKey(key)) { @@ -141,10 +147,6 @@ @Override public void chatCreated(Chat chat, boolean locally) { IChat newchat = getChat(chat); - if (!locally) { - // Pas necessaire vu qu'on recoit l'event processMessage juste apres - // notifyNewChat(newchat); - } chat.addMessageListener(mChatListener); final int n = mRemoteChatCreationListeners.beginBroadcast(); @@ -161,8 +163,9 @@ mRemoteChatCreationListeners.finishBroadcast(); } - /* - * + /** + * Set a notification of a new chat in android. + * @param chat The chat to access by the notification */ private void notifyNewChat(IChat chat) { try { @@ -172,7 +175,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); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setData(chat.getParticipant().toUri()); notif.setLatestEventInfo(mService, text, mService.getString(R.string.BeemChatManagerNewMessage), PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); @@ -183,6 +186,9 @@ } } + /** + * {@inheritDoc} + */ @Override public void processMessage(Chat chat, Message message) { ChatAdapter newchat = getChat(chat); @@ -196,7 +202,7 @@ listener.processMessage(newchat, new com.beem.project.beem.service.Message(message)); } mRemoteMessageListeners.finishBroadcast(); - if (! newchat.isOpen()) { + if (!newchat.isOpen()) { notifyNewChat(newchat); } } catch (RemoteException e) { @@ -206,6 +212,9 @@ } } + /** + * {@inheritDoc} + */ @Override public void stateChanged(Chat chat, ChatState state) { IChat newchat = getChat(chat); diff -r f72be51936d5 -r bb656974bab1 src/com/beem/project/beem/service/ChatAdapter.java --- a/src/com/beem/project/beem/service/ChatAdapter.java Sat May 23 20:15:18 2009 +0200 +++ b/src/com/beem/project/beem/service/ChatAdapter.java Sat May 23 20:59:27 2009 +0200 @@ -22,8 +22,7 @@ private Chat mAdaptee; private Contact mParticipant; private String mState; - private StringBuffer mLastMessages; - private boolean isOpen; + private boolean mIsOpen; private List mMessages; /** @@ -31,7 +30,6 @@ * @param chat The chat to adapt */ public ChatAdapter(final Chat chat) { - mLastMessages = new StringBuffer(); mAdaptee = chat; mParticipant = new Contact(chat.getParticipant()); mMessages = new LinkedList(); @@ -67,41 +65,58 @@ } } + /** + * {@inheritDoc} + */ @Override public String getState() throws RemoteException { return mState; } + /** + * {@inheritDoc} + */ @Override public void setState(String state) throws RemoteException { mState = state; } + /** + * Get the adaptee for the Chat. + * @return The real chat object + */ public Chat getAdaptee() { return mAdaptee; } /** - * @param isOpen the isOpen to set + * {@inheritDoc} */ @Override public void setOpen(boolean isOpen) { - this.isOpen = isOpen; + this.mIsOpen = isOpen; } /** - * @return the isOpen + * {@inheritDoc} */ @Override public boolean isOpen() { - return isOpen; + return mIsOpen; } + /** + * {@inheritDoc} + */ @Override public List getMessages() throws RemoteException { return Collections.unmodifiableList(mMessages); } + /** + * Add a message in the chat history. + * @param msg the message to add + */ void addMessage(Message msg) { if (mMessages.size() == 50) mMessages.remove(0); diff -r f72be51936d5 -r bb656974bab1 src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Sat May 23 20:15:18 2009 +0200 +++ b/src/com/beem/project/beem/service/Contact.java Sat May 23 20:59:27 2009 +0200 @@ -23,15 +23,6 @@ */ public class Contact implements Parcelable { - private static final String TAG = "Contact"; - - private int mID; - private int mStatus; - private String mJID; - private String mMsgState; - private List mRes; - private List mGroups; - /** * Parcelable.Creator needs by Android. */ @@ -48,18 +39,30 @@ } }; + private int mID; + private int mStatus; + private String mJID; + private String mMsgState; + private List mRes; + private List mGroups; + /** * Constructor. */ public Contact() { } + /** + * Create a contact from a 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")) + if (!uri.getScheme().equals("xmpp")) throw new IllegalArgumentException(); mJID = uri.getSchemeSpecificPart(); } - + /** * Constructor. * @param jid JID of the contact @@ -150,6 +153,10 @@ mMsgState = presence.getStatus(); } + /** + * Set status for the contact. + * @param presence The presence packet which contains the status + */ public void setStatus(PresenceAdapter presence) { mStatus = presence.getStatus(); mMsgState = presence.getStatusText(); @@ -189,7 +196,8 @@ } /** - * @param res + * Add a resource for this contact. + * @param res the resource to add */ public void addRes(String res) { if (!mRes.contains(res)) @@ -197,13 +205,15 @@ } /** - * @param res + * Delete a resource for this contact. + * @param res the resource de delete */ public void delRes(String res) { mRes.remove(res); } /** + * Set a list of resource for the contact. * @param mRes the mRes to set */ public void setMRes(List mRes) { @@ -211,12 +221,16 @@ } /** + * Get the list of resource for the contact. * @return the mRes */ public List getMRes() { return mRes; } + /** + * {@inheritDoc} + */ @Override public String toString() { if (mJID != null) @@ -224,17 +238,27 @@ return super.toString(); } + /** + * Set the groups the contact is in. + * @param groups list of groups + */ public void setGroups(Collection groups) { + this.mGroups.clear(); for (RosterGroup rosterGroup : groups) { mGroups.add(rosterGroup.getName()); } } + /** + * Add a group for the contact. + * @param group the group + */ public void addGroup(String group) { mGroups.add(group); } /** + * Set the groups the contact is in. * @param mGroups the mGroups to set */ public void setGroups(List mGroups) { @@ -242,20 +266,22 @@ } /** + * Get the groups the contact is in. * @return the mGroups */ public List getGroups() { return mGroups; } + /** + * Get a URI to access the contact. + * @return the URI + */ 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 f72be51936d5 -r bb656974bab1 src/com/beem/project/beem/service/Message.java --- a/src/com/beem/project/beem/service/Message.java Sat May 23 20:15:18 2009 +0200 +++ b/src/com/beem/project/beem/service/Message.java Sat May 23 20:59:27 2009 +0200 @@ -81,6 +81,10 @@ this(to, MSG_TYPE_CHAT); } + /** + * Construct a message from a smack message packet. + * @param smackMsg Smack message packet + */ public Message(org.jivesoftware.smack.packet.Message smackMsg) { this(smackMsg.getTo()); switch (smackMsg.getType()) { @@ -209,6 +213,7 @@ } /** + * Set the from field of the message. * @param mFrom the mFrom to set */ public void setFrom(String mFrom) { @@ -216,6 +221,7 @@ } /** + * Get the from field of the message. * @return the mFrom */ public String getFrom() { diff -r f72be51936d5 -r bb656974bab1 src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Sat May 23 20:15:18 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Sat May 23 20:59:27 2009 +0200 @@ -44,7 +44,7 @@ private SharedPreferences mSet; private BeemApplication mBeemApplication; private Handler mHandler; - private IXmppFacade mService = null; + private IXmppFacade mService; private Contact mContact; private IChatManager mChatManager; private IChatManagerListener mChatManagerListener; @@ -63,7 +63,7 @@ } /** - * Overload of onCreate() Activity inherited function + * {@inheritDoc} */ @Override public void onCreate(Bundle saveBundle) { @@ -86,6 +86,9 @@ mScrolling = (ScrollView) findViewById(R.id.sendimscroll); } + /** + * {@inheritDoc} + */ @Override protected void onStart() { super.onStart(); @@ -97,6 +100,9 @@ } + /** + * {@inheritDoc} + */ @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); @@ -104,6 +110,9 @@ setViewHeader(); } + /** + * {@inheritDoc} + */ @Override protected void onResume() { super.onResume(); @@ -128,16 +137,22 @@ }); } + /** + * {@inheritDoc} + */ @Override protected void onPause() { super.onPause(); try { mChat.setOpen(false); } catch (RemoteException e) { - Log.d(TAG, "mchat open false", e); + Log.d(TAG, "Error while closing chat", e); } } + /** + * {@inheritDoc} + */ @Override protected void onStop() { super.onStop(); @@ -149,6 +164,9 @@ mBeemApplication.unbindBeemService(); } + /** + * {@inheritDoc} + */ @Override protected void onDestroy() { super.onDestroy(); @@ -164,15 +182,17 @@ } /** - * Abstract method inherited from OnClickListener + * {@inheritDoc} */ + @Override public void onClick(View view) { sendText(); } /** - * Abstract method inherited from OnKeyListener + * {@inheritDoc} */ + @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { @@ -180,15 +200,15 @@ case KeyEvent.KEYCODE_ENTER: sendText(); return true; + default: + return false; } } return false; } /** - * Callback for menu creation. - * @param The created menu - * @return true on success, false otherwise + * {@inheritDoc} */ @Override public final boolean onCreateOptionsMenu(Menu menu) { @@ -198,6 +218,9 @@ return true; } + /** + * {@inheritDoc} + */ @Override public final boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -210,8 +233,8 @@ } /** - * 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 + * 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(); @@ -220,21 +243,26 @@ msg.setBody(text); try { 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(); } - 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; } } + /** + * 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); @@ -242,8 +270,12 @@ showMessageList(mChat.getMessages()); mChat.setOpen(true); mContact = newContact; + mToSend.requestFocus(); } + /** + * Set the header information in the window. + */ private void setViewHeader() { Drawable avatar = (Drawable) getResources().getDrawable(R.drawable.avatar); ImageView imgV = (ImageView) findViewById(R.id.sendimavatar); @@ -258,6 +290,10 @@ status.setText(statmsg); } + /** + * Show the message history. + * @param messages list of message to display + */ private void showMessageList(List messages) { mText.setText(""); mSpeak = 0; @@ -279,8 +315,15 @@ mScrolling.fullScroll(ScrollView.FOCUS_DOWN); } + /** + * 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"); @@ -288,8 +331,15 @@ } + /** + * Listener for new chat messages. + * @author darisk + */ private class OnMessageListener extends IMessageListener.Stub { + /** + * {@inheritDoc} + */ @Override public void processMessage(IChat chat, Message msg) throws RemoteException { @@ -316,6 +366,9 @@ }); } + /** + * {@inheritDoc} + */ @Override public void stateChanged(IChat chat) throws RemoteException { // TODO: a integrer dans l'ui