# HG changeset patch # User Nikita Kozlov # Date 1279884720 -7200 # Node ID 236c54f9145dcc24ff46f0a855b9cf4d31c80c9e # Parent 0e0af155292ef893da0b68b73cae4456ce293b9e Feature #255: adding a chat list button in contact list menu diff -r 0e0af155292e -r 236c54f9145d res/menu/contact_list.xml --- a/res/menu/contact_list.xml Fri Jul 23 11:12:14 2010 +0200 +++ b/res/menu/contact_list.xml Fri Jul 23 13:32:00 2010 +0200 @@ -6,6 +6,9 @@ + openedChats = mChatManager.getOpenedChatList(); Log.d(TAG, "opened chats = " + openedChats); - if (openedChats.size() > 0) - createChatSwitcherDialog(openedChats); - else - createNoActiveChatsDialog(); + Dialog chatList = new ChatList(Chat.this, openedChats).create(); + chatList.show(); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } @@ -295,41 +293,6 @@ } /** - * Create the change chat dialog. - * @param openedChats A list containing the JID of participants of the opened chats. - */ - private void createChatSwitcherDialog(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); - chatIntent.setData((openedChats.get(item)).toUri()); - startActivity(chatIntent); - } - }); - AlertDialog chatSwitcherDialog = builder.create(); - chatSwitcherDialog.show(); - } - - /** - * Create a dialog which notify the user that there're not another one active chat. - */ - private void createNoActiveChatsDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(getString(R.string.chat_no_more_chats)); - AlertDialog noActiveChatsDialog = builder.create(); - noActiveChatsDialog.show(); - } - - /** * Change the displayed chat. * @param contact the targeted contact of the new chat * @throws RemoteException If a Binder remote-invocation error occurred. diff -r 0e0af155292e -r 236c54f9145d src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Fri Jul 23 11:12:14 2010 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Fri Jul 23 13:32:00 2010 +0200 @@ -43,13 +43,12 @@ package com.beem.project.beem.ui; import java.util.ArrayList; -import java.util.LinkedList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import org.jivesoftware.smack.util.StringUtils; @@ -76,6 +75,8 @@ import android.view.ViewGroup; import android.view.ViewStub; import android.widget.AdapterView; +import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.Filter; import android.widget.Filterable; @@ -83,21 +84,21 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; -import android.widget.AdapterView.AdapterContextMenuInfo; -import android.widget.AdapterView.OnItemClickListener; import com.beem.project.beem.R; import com.beem.project.beem.service.Contact; import com.beem.project.beem.service.PresenceAdapter; import com.beem.project.beem.service.aidl.IBeemRosterListener; +import com.beem.project.beem.service.aidl.IChatManager; import com.beem.project.beem.service.aidl.IRoster; import com.beem.project.beem.service.aidl.IXmppFacade; import com.beem.project.beem.ui.dialogs.builders.Alias; +import com.beem.project.beem.ui.dialogs.builders.ChatList; import com.beem.project.beem.ui.dialogs.builders.DeleteContact; import com.beem.project.beem.ui.dialogs.builders.ResendSubscription; import com.beem.project.beem.utils.BeemBroadcastReceiver; +import com.beem.project.beem.utils.SortedList; import com.beem.project.beem.utils.Status; -import com.beem.project.beem.utils.SortedList; /** * The contact list activity displays the roster of the user. @@ -130,6 +131,7 @@ private IRoster mRoster; private Contact mSelectedContact; private IXmppFacade mXmppFacade; + private IChatManager mChatManager; private SharedPreferences mSettings; private LayoutInflater mInflater; private BeemBanner mAdapterBanner; @@ -169,6 +171,16 @@ case R.id.menu_disconnect: stopService(SERVICE_INTENT); finish(); + case R.id.contact_list_menu_chatlist: + List openedChats; + try { + openedChats = mChatManager.getOpenedChatList(); + Log.d(TAG, "opened chats = " + openedChats); + Dialog chatList = new ChatList(ContactList.this, openedChats).create(); + chatList.show(); + } catch (RemoteException e) { + e.printStackTrace(); + } return true; default: return false; @@ -235,7 +247,7 @@ break; case R.id.contact_list_context_menu_userinfo_subscription: Dialog subscription = new ResendSubscription(ContactList.this, - mXmppFacade, mSelectedContact).create(); + mXmppFacade, mSelectedContact).create(); subscription.show(); result = true; break; @@ -456,7 +468,7 @@ if (!mListGroup.contains(group)) { mListGroup.add(mListGroup.size() - 1, group); List tmplist = new SortedList( - new LinkedList(), mComparator); + new LinkedList(), mComparator); mContactOnGroup.put(group, tmplist); } mContactOnGroup.get(group).remove(contact); @@ -539,11 +551,11 @@ String noGroup = getString(R.string.contact_list_no_group); String allGroup = getString(R.string.contact_list_all_contact); final boolean add = ((!hideDisconnected || Status.statusOnline(contact.getStatus())) && // must show and - ( - (listName.equals(noGroup) && groups.isEmpty()) || // in no group - groups.contains(listName) || // or in current - listName.equals(allGroup) // or in all - )); + ( + (listName.equals(noGroup) && groups.isEmpty()) || // in no group + groups.contains(listName) || // or in current + listName.equals(allGroup) // or in all + )); mHandler.post(new Runnable() { public void run() { mListContact.remove(contact); @@ -642,7 +654,7 @@ if (curContact != null) { TextView v = (TextView) view.findViewById(R.id.contactlistpseudo); LevelListDrawable mStatusDrawable = (LevelListDrawable) getResources() - .getDrawable(R.drawable.status_icon); + .getDrawable(R.drawable.status_icon); mStatusDrawable.setLevel(curContact.getStatus()); v.setCompoundDrawablesWithIntrinsicBounds(mStatusDrawable, null, null, null); v.setText(curContact.getName()); @@ -748,7 +760,6 @@ try { mRoster = mXmppFacade.getRoster(); if (mRoster != null) { - List tmpContactList = mRoster.getContactList(); List tmpGroupList = mRoster.getGroupsNames(); Collections.sort(tmpGroupList); mListGroup.clear(); @@ -764,7 +775,8 @@ String group = getString(R.string.contact_list_all_contact); buildContactList(group); mRoster.addRosterListener(mBeemRosterListener); - Log.d(TAG, "add rester listneer"); + Log.d(TAG, "add roster listener"); + mChatManager = mXmppFacade.getChatManager(); } } catch (RemoteException e) { e.printStackTrace(); @@ -779,6 +791,7 @@ e.printStackTrace(); } mXmppFacade = null; + mChatManager = null; mRoster = null; mListContact.clear(); mListGroup.clear(); diff -r 0e0af155292e -r 236c54f9145d src/com/beem/project/beem/ui/dialogs/builders/ChatList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/dialogs/builders/ChatList.java Fri Jul 23 13:32:00 2010 +0200 @@ -0,0 +1,90 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.ui.dialogs.builders; + +import java.util.List; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; + +import com.beem.project.beem.R; +import com.beem.project.beem.service.Contact; + +/** + * Create the change chat dialog. + */ +public class ChatList extends AlertDialog.Builder { + + //private static final String TAG = "Dialogs.Builders > Chat list"; + + /** + * Constructor. + * @param context context activity. + * @param openedChats A list containing the JID of participants of the opened chats. + */ + public ChatList(final Context context, final List openedChats) { + super(context); + + if (openedChats.size() > 0) { + CharSequence[] items = new CharSequence[openedChats.size()]; + + int i = 0; + for (Contact c : openedChats) { + items[i++] = c.getName(); + } + setTitle(R.string.chat_dialog_change_chat_title); + setItems(items, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int item) { + Intent chatIntent = new Intent(context, com.beem.project.beem.ui.Chat.class); + chatIntent.setData((openedChats.get(item)).toUri()); + context.startActivity(chatIntent); + } + }); + } else { + setMessage(R.string.chat_no_more_chats); + } + } +}