Ajout d'un chat switcher dans l'activite Chat.
--- 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 @@
<string name="contact_status_msg_xa">Indisponible</string>
<string name="contact_status_msg_offline">Hors ligne</string>
<string name="UpdateButton">Mettre à jour</string>
+<string name="chat_menu_contacts_list">Liste d'amis</string>
+<string name="chat_menu_change_chat">Changer de chat</string>
+<string name="chat_dialog_change_chat_title">Conversations en cours</string>
</resources>
--- 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 @@
<string name="UpdateButton">Update</string>
+<string name="chat_menu_contacts_list">Contacts list</string>
+<string name="chat_menu_change_chat">Switch chat</string>
+<string name="chat_dialog_change_chat_title">Opened chats</string>
</resources>
--- 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;
+ }
}
--- 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<IChatManagerListener> mRemoteChatCreationListeners = new RemoteCallbackList<IChatManagerListener>();
private final RemoteCallbackList<IMessageListener> mRemoteMessageListeners = new RemoteCallbackList<IMessageListener>();
-
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<Contact> getOpenedChatList() throws RemoteException {
+ List<Contact> openedChats = new ArrayList<Contact>();
+ IRoster mRoster = mService.getBind().getRoster();
+
+ for (ChatAdapter chat : mChats.values()) {
+ if (!chat.isOpen())
+ openedChats.add(mRoster.getContact(chat.getParticipant().getJID()));
+ }
+ return (openedChats);
+ }
+
/**
* {@inheritDoc}
*/
--- 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<Contact> getOpenedChatList();
}
--- 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<Contact> 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<Contact> 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
--- 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);