--- 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