# HG changeset patch # User Jean-Manuel Da Silva # Date 1258077405 -3600 # Node ID 7d8da3df290738a1fb2afb81c620397a7833aad3 # Parent 71cf79d83c71b8a46785e1ec40ff646f3505f44e Ajout d'un chat switcher dans l'activite Chat. diff -r 71cf79d83c71 -r 7d8da3df2907 res/values-fr/strings.xml --- a/res/values-fr/strings.xml Thu Nov 12 03:11:22 2009 +0100 +++ b/res/values-fr/strings.xml Fri Nov 13 02:56:45 2009 +0100 @@ -277,4 +277,7 @@ Indisponible Hors ligne Mettre à jour +Liste d'amis +Changer de chat +Conversations en cours diff -r 71cf79d83c71 -r 7d8da3df2907 res/values/strings.xml --- a/res/values/strings.xml Thu Nov 12 03:11:22 2009 +0100 +++ b/res/values/strings.xml Fri Nov 13 02:56:45 2009 +0100 @@ -259,4 +259,7 @@ Update +Contacts list +Switch chat +Opened chats diff -r 71cf79d83c71 -r 7d8da3df2907 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Thu Nov 12 03:11:22 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Fri Nov 13 02:56:45 2009 +0100 @@ -202,4 +202,8 @@ public void initJingle(XMPPConnection adaptee) { mJingle.initWhenConntected(adaptee); } + + public IXmppFacade getBind() { + return mBind; + } } diff -r 71cf79d83c71 -r 7d8da3df2907 src/com/beem/project/beem/service/BeemChatManager.java --- a/src/com/beem/project/beem/service/BeemChatManager.java Thu Nov 12 03:11:22 2009 +0100 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Fri Nov 13 02:56:45 2009 +0100 @@ -1,6 +1,8 @@ package com.beem.project.beem.service; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.jivesoftware.smack.Chat; @@ -25,6 +27,7 @@ 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.IRoster; /** * An adapter for smack's ChatManager. This class provides functionnality to handle chats. @@ -160,7 +163,6 @@ private final ChatListener mChatListener = new ChatListener(); private final RemoteCallbackList mRemoteChatCreationListeners = new RemoteCallbackList(); private final RemoteCallbackList mRemoteMessageListeners = new RemoteCallbackList(); - private final BeemService mService; /** @@ -214,10 +216,11 @@ */ @Override public void destroyChat(IChat chat) throws RemoteException { - Log.d(TAG, "destroyChat - jid = " + chat.getParticipant().getJID()); + Log.d(TAG, "BEGIN destroyChat - jid = " + chat.getParticipant().getJID()); IChat c = mChats.remove(chat.getParticipant().getJID()); if (c == null) Log.w(TAG, "destroyChat - chat = null, jid = " + chat.getParticipant().getJID()); + Log.d(TAG, "END destroyChat - jid = " + chat.getParticipant().getJID()); } @Override @@ -240,6 +243,17 @@ return res; } + public List getOpenedChatList() throws RemoteException { + List openedChats = new ArrayList(); + IRoster mRoster = mService.getBind().getRoster(); + + for (ChatAdapter chat : mChats.values()) { + if (!chat.isOpen()) + openedChats.add(mRoster.getContact(chat.getParticipant().getJID())); + } + return (openedChats); + } + /** * {@inheritDoc} */ diff -r 71cf79d83c71 -r 7d8da3df2907 src/com/beem/project/beem/service/aidl/IChatManager.aidl --- a/src/com/beem/project/beem/service/aidl/IChatManager.aidl Thu Nov 12 03:11:22 2009 +0100 +++ b/src/com/beem/project/beem/service/aidl/IChatManager.aidl Fri Nov 13 02:56:45 2009 +0100 @@ -43,4 +43,6 @@ * @param listener the callback to remove. */ void removeChatCreationListener(in IChatManagerListener listener); + + List getOpenedChatList(); } diff -r 71cf79d83c71 -r 7d8da3df2907 src/com/beem/project/beem/ui/Chat.java --- a/src/com/beem/project/beem/ui/Chat.java Thu Nov 12 03:11:22 2009 +0100 +++ b/src/com/beem/project/beem/ui/Chat.java Fri Nov 13 02:56:45 2009 +0100 @@ -8,8 +8,10 @@ import org.jivesoftware.smack.util.StringUtils; import android.app.Activity; +import android.app.AlertDialog; import android.content.ComponentName; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; @@ -24,6 +26,9 @@ import android.text.util.Linkify; import android.util.Log; import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.View.OnKeyListener; @@ -216,6 +221,71 @@ } /** + * {@inheritDoc}. + */ + @Override + public final boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.chat, menu); + return true; + } + + /** + * {@inheritDoc}. + */ + @Override + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.chat_menu_contacts_list: + Intent contactListIntent = new Intent(this, ContactList.class); + contactListIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); + startActivity(contactListIntent); + return true; + case R.id.chat_menu_change_chat: + try { + final List openedChats = mChatManager.getOpenedChatList(); + createChangeChatDialog(openedChats); + } catch (RemoteException e) { + Log.e(TAG, e.getMessage()); + } + return true; + default: + return false; + } + } + + /** + * Create the change chat dialog. + * @param openedChats A list containing the JID of participants of the opened chats. + */ + private void createChangeChatDialog(final List openedChats) { + CharSequence[] items = new CharSequence[openedChats.size()]; + + int i = 0; + for (Contact c : openedChats) { + items[i++] = c.getName(); + } + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.chat_dialog_change_chat_title)); + builder.setItems(items, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int item) { + Intent chatIntent = new Intent(getApplicationContext(), com.beem.project.beem.ui.Chat.class); + try { + chatIntent.setData(mRoster.getContact(openedChats.get(item).getJID()).toUri()); + } catch (RemoteException e) { + Log.e(TAG, e.getMessage()); + } + Chat.this.onNewIntent(chatIntent); + } + }); + AlertDialog changeChatDialog = builder.create(); + changeChatDialog.show(); + } + + /** * Change the displayed chat. * @param contact * @throws RemoteException diff -r 71cf79d83c71 -r 7d8da3df2907 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu Nov 12 03:11:22 2009 +0100 +++ b/src/com/beem/project/beem/ui/ContactList.java Fri Nov 13 02:56:45 2009 +0100 @@ -130,6 +130,7 @@ } } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);