Feature #216 » beem-muc.patch
beem-muc/res/layout/joinmucdialog.xml 2010-08-11 18:01:43.825148247 +0200 | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:orientation="vertical" android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent"> |
|
5 |
<TextView android:id="@+id/CDRoomDialogLabel" |
|
6 |
android:layout_height="wrap_content" android:layout_width="wrap_content" |
|
7 |
android:layout_marginLeft="20dip" android:layout_marginRight="20dip" |
|
8 |
android:text="@string/Room" |
|
9 |
android:gravity="left" style="@style/Label" /> |
|
10 |
<EditText android:id="@+id/CDRoomDialogName" |
|
11 |
android:layout_height="wrap_content" android:layout_width="fill_parent" |
|
12 |
android:layout_marginLeft="20dip" android:layout_marginRight="20dip" |
|
13 |
android:scrollHorizontally="true" android:autoText="false" |
|
14 |
android:capitalize="none" android:gravity="fill_horizontal" |
|
15 |
android:contentDescription="@string/Room" android:text="room@server"/> |
|
16 |
<TextView android:id="@+id/CDNickDialogLabel" |
|
17 |
android:layout_height="wrap_content" android:layout_width="wrap_content" |
|
18 |
android:layout_marginLeft="20dip" android:layout_marginRight="20dip" |
|
19 |
android:text="@string/Nick" |
|
20 |
android:gravity="left" style="@style/Label" /> |
|
21 |
<EditText android:id="@+id/CDNickDialogName" |
|
22 |
android:layout_height="wrap_content" android:layout_width="fill_parent" |
|
23 |
android:layout_marginLeft="20dip" android:layout_marginRight="20dip" |
|
24 |
android:scrollHorizontally="true" android:autoText="false" |
|
25 |
android:capitalize="none" android:gravity="fill_horizontal" |
|
26 |
android:contentDescription="@string/Nick"/> |
|
27 | ||
28 |
</LinearLayout> |
beem-muc/res/layout/preferences.xml 2010-08-26 21:22:22.461304744 +0200 | ||
---|---|---|
50 | 50 |
<EditTextPreference android:key="settings_key_priority" |
51 | 51 |
android:title="@string/SettingsPriorityTitle" android:summary="@string/SettingsPrioritySummary" |
52 | 52 |
android:numeric="signed" android:defaultValue="0" /> |
53 |
<EditTextPreference android:key="settings_key_nickname" |
|
54 |
android:title="@string/SettingsNicknameTitle" android:summary="@string/SettingsNicknameSummary" |
|
55 |
android:defaultValue="BeemGuest" /> |
|
53 | 56 |
</PreferenceCategory> |
54 | 57 |
<PreferenceCategory android:title="@string/network_preferences"> |
55 | 58 |
<PreferenceScreen android:key="proxy" android:title="@string/SettingsProxy" |
beem-muc/res/menu/contactlist_context.xml 2010-08-26 21:09:34.409180747 +0200 | ||
---|---|---|
4 | 4 |
<menu> |
5 | 5 |
</menu> |
6 | 6 |
</item> |
7 |
<item android:id="@+id/contact_list_context_menu_joinasmuc_item" android:title="@string/CDJoinMUC"></item> |
|
7 | 8 |
<item android:id="@+id/contact_list_context_menu_call_item" |
8 | 9 |
android:title="@string/CDCall" android:visible="false" /> |
9 | 10 |
<item android:id="@+id/contact_list_context_menu_user_info" |
... | ... | |
21 | 22 |
android:title="@string/userinfo_label_delete" /> |
22 | 23 |
</menu> |
23 | 24 |
</item> |
25 | ||
24 | 26 |
</menu> |
beem-muc/res/menu/contact_list.xml 2010-08-11 16:36:14.588740833 +0200 | ||
---|---|---|
6 | 6 |
<item android:id="@+id/menu_change_status" |
7 | 7 |
android:visible="true" |
8 | 8 |
android:title="@string/contact_list_menu_status"/> |
9 |
<item android:id="@+id/contact_list_menu_chatlist" |
|
9 |
<item android:visible="true" android:title="MUC" android:id="@+id/muc"></item><item android:id="@+id/contact_list_menu_chatlist"
|
|
10 | 10 |
android:visible="true" android:icon="@drawable/ic_menu_chat_dashboard" |
11 |
android:title="@string/chat_menu_change_chat"/>
|
|
11 |
android:title="@string/chat_menu_change_chat"></item>
|
|
12 | 12 |
<item android:id="@+id/contact_list_menu_settings" |
13 | 13 |
android:visible="true" |
14 | 14 |
android:title="@string/contact_list_menu_settings" |
15 |
android:icon="@drawable/ic_menu_manage" />
|
|
15 |
android:icon="@drawable/ic_menu_manage" ></item>
|
|
16 | 16 |
<item android:id="@+id/menu_disconnect" |
17 | 17 |
android:visible="true" |
18 | 18 |
android:title="@string/contact_list_menu_disconnect" |
19 |
android:icon="@drawable/ic_menu_close_clear_cancel" /> |
|
19 |
android:icon="@drawable/ic_menu_close_clear_cancel" ></item> |
|
20 | ||
20 | 21 |
</menu> |
beem-muc/res/values/strings.xml 2010-08-26 21:21:45.045143447 +0200 | ||
---|---|---|
27 | 27 | |
28 | 28 |
<!-- ContactDialog class --> |
29 | 29 |
<string name="CDChat">Chat</string> |
30 |
<string name="CDJoinMUC">Join MUC</string> |
|
30 | 31 |
<string name="CDCall">Call</string> |
31 | 32 |
<string name="CDInfos">Manage User</string> |
32 | 33 | |
... | ... | |
76 | 77 |
<string name="SettingsAdvancedPortOpt">Edit the server port</string> |
77 | 78 |
<string name="SettingsResourceTitle">Resource</string> |
78 | 79 |
<string name="SettingsPriorityTitle">Priority</string> |
80 |
<string name="SettingsNicknameTitle">Default nickname for MUC</string> |
|
79 | 81 |
<string name="SettingsResourceSummary">Set the XMPP resource of your client </string> |
80 | 82 |
<string name="SettingsPrioritySummary">Set the priority of your client</string> |
83 |
<string name="SettingsNicknameSummary">Set the default nickname when joining MUC</string> |
|
81 | 84 |
<string name="contact_list_preferences">Buddy list</string> |
82 | 85 |
<string name="contact_list_preferences_sum">A set of display options for your buddy list |
83 | 86 |
</string> |
... | ... | |
278 | 281 |
<string name="privacy_list_delete_dialog_no">No</string> |
279 | 282 | |
280 | 283 |
<string name="UpdateButton">Update</string> |
281 |
|
|
284 |
<string name="Room">Room</string> |
|
285 |
<string name="Nick">Nickname</string> |
|
282 | 286 |
<!-- Error messages --> |
283 | 287 |
|
284 | 288 |
<string name="error_login_authentication">Error during authentication, bad login or password.</string> |
beem-muc/res/values-fr/strings.xml 2010-08-11 18:00:07.047657886 +0200 | ||
---|---|---|
292 | 292 | |
293 | 293 |
<string name="UpdateButton">Mettre à jour</string> |
294 | 294 |
|
295 |
<string name="Room">Salon</string> |
|
296 |
<string name="Nick">Pseudo</string> |
|
297 |
|
|
295 | 298 |
<!-- Error messages --> |
296 | 299 |
<string name="error_login_authentication">Erreur lors de l\'authenfitication, mauvais login ou password</string> |
297 | 300 |
<string name="interna_server_error">Erreur survenu sur le serveur</string> |
beem-muc/src/com/beem/project/beem/BeemService.java 2010-08-11 00:03:28.341052301 +0200 | ||
---|---|---|
293 | 293 |
public IXmppFacade getBind() { |
294 | 294 |
return mBind; |
295 | 295 |
} |
296 |
|
|
297 |
public XmppConnectionAdapter getmConnection() { |
|
298 |
return mConnection; |
|
299 |
} |
|
296 | 300 | |
297 | 301 |
/** |
298 | 302 |
* Get the preference of the service. |
beem-muc/src/com/beem/project/beem/service/aidl/IChatManager.aidl 2010-08-11 23:14:33.076637792 +0200 | ||
---|---|---|
45 | 45 | |
46 | 46 |
import com.beem.project.beem.service.Contact; |
47 | 47 |
import com.beem.project.beem.service.aidl.IChat; |
48 |
import com.beem.project.beem.service.aidl.IChatMUC; |
|
48 | 49 |
import com.beem.project.beem.service.aidl.IMessageListener; |
49 | 50 |
import com.beem.project.beem.service.aidl.IChatManagerListener; |
50 | 51 | |
... | ... | |
61 | 62 |
* @return the chat session |
62 | 63 |
*/ |
63 | 64 |
IChat createChat(in Contact contact, in IMessageListener listener); |
65 |
IChatMUC createMUCChat(in Contact contact, in IMessageListener listener); |
|
64 | 66 | |
65 | 67 |
/** |
66 | 68 |
* Get an existing Chat session with a contact. |
67 | 69 |
* @return null if the chat session does not exist. |
68 | 70 |
*/ |
69 | 71 |
IChat getChat(in Contact contact); |
72 |
IChatMUC getMUCChat(in Contact contact); |
|
70 | 73 | |
71 | 74 |
/** |
72 | 75 |
* Destroy a chat session with a contact. |
73 | 76 |
* @param chat the chat session |
74 | 77 |
*/ |
75 | 78 |
void destroyChat(in IChat chat); |
79 |
void destroyMUCChat(in IChatMUC chat); |
|
76 | 80 | |
77 | 81 |
/** |
78 | 82 |
* @param chat the chat. |
beem-muc/src/com/beem/project/beem/service/aidl/IChatMUC.aidl 2010-08-10 14:09:05.000000000 +0200 | ||
---|---|---|
1 |
/* |
|
2 |
BEEM is a videoconference application on the Android Platform. |
|
3 | ||
4 |
Copyright (C) 2009 by Frederic-Charles Barthelery, |
|
5 |
Jean-Manuel Da Silva, |
|
6 |
Nikita Kozlov, |
|
7 |
Philippe Lago, |
|
8 |
Jean Baptiste Vergely, |
|
9 |
Vincent Veronis. |
|
10 | ||
11 |
This file is part of BEEM. |
|
12 | ||
13 |
BEEM is free software: you can redistribute it and/or modify |
|
14 |
it under the terms of the GNU General Public License as published by |
|
15 |
the Free Software Foundation, either version 3 of the License, or |
|
16 |
(at your option) any later version. |
|
17 | ||
18 |
BEEM is distributed in the hope that it will be useful, |
|
19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
GNU General Public License for more details. |
|
22 | ||
23 |
You should have received a copy of the GNU General Public License |
|
24 |
along with BEEM. If not, see <http://www.gnu.org/licenses/>. |
|
25 | ||
26 |
Please send bug reports with examples or suggestions to |
|
27 |
contact@beem-project.com or http://dev.beem-project.com/ |
|
28 | ||
29 |
Epitech, hereby disclaims all copyright interest in the program "Beem" |
|
30 |
written by Frederic-Charles Barthelery, |
|
31 |
Jean-Manuel Da Silva, |
|
32 |
Nikita Kozlov, |
|
33 |
Philippe Lago, |
|
34 |
Jean Baptiste Vergely, |
|
35 |
Vincent Veronis. |
|
36 | ||
37 |
Nicolas Sadirac, November 26, 2009 |
|
38 |
President of Epitech. |
|
39 | ||
40 |
Flavien Astraud, November 26, 2009 |
|
41 |
Head of the EIP Laboratory. |
|
42 | ||
43 |
*/ |
|
44 |
package com.beem.project.beem.service.aidl; |
|
45 | ||
46 |
import com.beem.project.beem.service.Contact; |
|
47 |
import com.beem.project.beem.service.Message; |
|
48 |
import com.beem.project.beem.service.aidl.IMessageListener; |
|
49 | ||
50 |
/** |
|
51 |
* An aidl interface for ChatMUC session. |
|
52 |
*/ |
|
53 |
interface IChatMUC { |
|
54 |
/** |
|
55 |
* Send a message. |
|
56 |
* @param message the message to send |
|
57 |
*/ |
|
58 |
void sendMessage(in Message message); |
|
59 |
|
|
60 |
Contact getRoom() ; |
|
61 |
/** |
|
62 |
* Add a message listener. |
|
63 |
* @param listener the listener to add. |
|
64 |
*/ |
|
65 |
void addMessageListener(in IMessageListener listener); |
|
66 | ||
67 |
/** |
|
68 |
* Remove a message listener. |
|
69 |
* @param listener the listener to remove. |
|
70 |
*/ |
|
71 |
void removeMessageListener(in IMessageListener listener); |
|
72 | ||
73 |
String getState(); |
|
74 | ||
75 |
void setOpen(in boolean isOpen); |
|
76 | ||
77 |
boolean isOpen(); |
|
78 | ||
79 |
void setState(in String state); |
|
80 | ||
81 |
List<Message> getMessages(); |
|
82 | ||
83 |
List<Contact> getMembers(); |
|
84 | ||
85 |
} |
beem-muc/src/com/beem/project/beem/service/aidl/IMessageListener.aidl 2010-08-10 14:05:27.821323591 +0200 | ||
---|---|---|
45 | 45 | |
46 | 46 |
import com.beem.project.beem.service.Message; |
47 | 47 |
import com.beem.project.beem.service.aidl.IChat; |
48 |
import com.beem.project.beem.service.aidl.IChatMUC; |
|
48 | 49 | |
49 | 50 |
interface IMessageListener { |
50 | 51 | |
... | ... | |
54 | 55 |
* @param msg the message received in the chat. |
55 | 56 |
*/ |
56 | 57 |
void processMessage(in IChat chat, in Message msg); |
58 |
void processMUCMessage(in IChatMUC chat, in Message msg); |
|
57 | 59 | |
58 | 60 |
/** |
59 | 61 |
* This method is executed when a new ChatState is received by the chat. |
beem-muc/src/com/beem/project/beem/service/BeemChatManager.java 2010-08-26 19:30:33.405403050 +0200 | ||
---|---|---|
51 | 51 |
import org.jivesoftware.smack.Chat; |
52 | 52 |
import org.jivesoftware.smack.ChatManager; |
53 | 53 |
import org.jivesoftware.smack.ChatManagerListener; |
54 |
import org.jivesoftware.smack.XMPPException; |
|
55 |
import org.jivesoftware.smack.util.StringUtils; |
|
56 |
import org.jivesoftware.smackx.muc.MultiUserChat; |
|
54 | 57 | |
55 | 58 |
import android.app.Notification; |
56 | 59 |
import android.app.PendingIntent; |
... | ... | |
64 | 67 |
import com.beem.project.beem.BeemService; |
65 | 68 |
import com.beem.project.beem.R; |
66 | 69 |
import com.beem.project.beem.service.aidl.IChat; |
70 |
import com.beem.project.beem.service.aidl.IChatMUC; |
|
67 | 71 |
import com.beem.project.beem.service.aidl.IChatManager; |
68 | 72 |
import com.beem.project.beem.service.aidl.IChatManagerListener; |
69 | 73 |
import com.beem.project.beem.service.aidl.IMessageListener; |
... | ... | |
78 | 82 |
private static final String TAG = "BeemChatManager"; |
79 | 83 |
private final ChatManager mAdaptee; |
80 | 84 |
private final Map<String, ChatAdapter> mChats = new HashMap<String, ChatAdapter>(); |
85 |
private final Map<String, ChatMUCAdapter> mMUCChats = new HashMap<String, ChatMUCAdapter>(); |
|
81 | 86 |
private final ChatListener mChatListener = new ChatListener(); |
82 | 87 |
private final RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners = |
83 | 88 |
new RemoteCallbackList<IChatManagerListener>(); |
... | ... | |
136 | 141 |
result.addMessageListener(listener); |
137 | 142 |
return result; |
138 | 143 |
} |
144 |
|
|
145 |
/** |
|
146 |
* Create a MUC chat session. |
|
147 |
* @param jid the jid of the MUC |
|
148 |
* @param listener listener to use for chat events on this chat session |
|
149 |
* @return the chat session |
|
150 |
*/ |
|
151 |
public IChatMUC createMUCChat(Contact contact, IMessageListener listener) { |
|
152 |
String jid = contact.getJIDWithRes(); |
|
153 |
Log.d(TAG, "Get chat key1 = "); |
|
154 | ||
155 |
return createMUCChat(jid, listener); |
|
156 |
} |
|
157 |
|
|
158 |
public IChatMUC createMUCChat(String jid, IMessageListener listener) { |
|
159 |
String key = StringUtils.parseBareAddress(jid); |
|
160 |
ChatMUCAdapter result; |
|
161 |
Log.d(TAG, "Get chat key2 = "+jid); |
|
162 |
if (mMUCChats.containsKey(key)) { |
|
163 |
result = mMUCChats.get(key); |
|
164 |
result.addMessageListener(listener); |
|
165 |
return result; |
|
166 |
} |
|
167 |
MultiUserChat c = new MultiUserChat(mService.getmConnection().getAdaptee(),key); |
|
168 |
// maybe a little probleme of thread synchronization |
|
169 |
// if so use an HashTable instead of a HashMap for mChats |
|
170 |
result = getMUCChat(c); |
|
171 |
result.addMessageListener(listener); |
|
172 |
try { |
|
173 |
c.join(StringUtils.parseResource(jid)) ; |
|
174 |
result.addMessageListener(mChatListener); |
|
175 |
} catch (XMPPException e) { |
|
176 |
// TODO Auto-generated catch block |
|
177 |
e.printStackTrace(); |
|
178 |
} |
|
179 |
return result; |
|
180 |
} |
|
181 | ||
139 | 182 | |
140 | 183 |
/** |
141 | 184 |
* {@inheritDoc} |
... | ... | |
150 | 193 |
mChats.remove(chat.getParticipant().getJID()); |
151 | 194 |
} |
152 | 195 | |
196 |
@Override |
|
197 |
public void destroyMUCChat(IChatMUC chat) throws RemoteException { |
|
198 |
if (chat == null) |
|
199 |
return; |
|
200 |
((ChatMUCAdapter)chat).getAdaptee().leave() ; |
|
201 |
mMUCChats.remove(chat.getRoom().getJID()); |
|
202 |
|
|
203 |
} |
|
204 |
|
|
153 | 205 |
/** |
154 | 206 |
* {@inheritDoc} |
155 | 207 |
*/ |
... | ... | |
179 | 231 |
} |
180 | 232 | |
181 | 233 |
@Override |
182 |
public ChatAdapter getChat(Contact contact) { |
|
183 |
String key = contact.getJIDWithRes(); |
|
184 |
return mChats.get(key); |
|
185 |
} |
|
234 |
public ChatAdapter getChat(Contact contact) { |
|
235 |
String key = contact.getJIDWithRes(); |
|
236 |
return mChats.get(key); |
|
237 |
} |
|
238 | ||
239 |
public ChatMUCAdapter getMUCChat(Contact contact) { |
|
240 |
String key = contact.getJID(); |
|
241 |
return mMUCChats.get(key); |
|
242 |
} |
|
243 |
|
|
244 |
private ChatMUCAdapter getMUCChat(MultiUserChat chat) { |
|
245 |
String key = chat.getRoom(); |
|
246 |
if (mMUCChats.containsKey(key)) { |
|
247 |
return mMUCChats.get(key); |
|
248 |
} |
|
249 |
ChatMUCAdapter res = new ChatMUCAdapter(chat); |
|
250 |
Log.d(TAG, "getMUCChat put " + key); |
|
251 |
mMUCChats.put(key, res); |
|
252 |
return res; |
|
253 |
} |
|
186 | 254 | |
187 |
/** |
|
255 |
/**
|
|
188 | 256 |
* This methods permits to retrieve the list of contacts who have an opened chat session with us. |
189 | 257 |
* @return An List containing Contact instances. |
190 | 258 |
* @throws RemoteException If a Binder remote-invocation error occurred. |
... | ... | |
192 | 260 |
public List<Contact> getOpenedChatList() throws RemoteException { |
193 | 261 |
List<Contact> openedChats = new ArrayList<Contact>(); |
194 | 262 |
IRoster mRoster = mService.getBind().getRoster(); |
195 | ||
196 | 263 |
for (ChatAdapter chat : mChats.values()) { |
197 | 264 |
if (chat.getMessages().size() > 0) { |
198 |
Contact t = mRoster.getContact(chat.getParticipant().getJID()); |
|
265 |
Contact t = mRoster.getContact(chat.getParticipant().getJIDWithRes());
|
|
199 | 266 |
if (t == null) |
200 |
t = new Contact(chat.getParticipant().getJID()); |
|
267 |
t = new Contact(chat.getParticipant().getJIDWithRes());
|
|
201 | 268 |
openedChats.add(t); |
202 | 269 |
} |
203 | 270 |
} |
271 |
for (ChatMUCAdapter chat : mMUCChats.values()) { |
|
272 |
Contact t = new Contact(chat.getRoom().getJID(), true); |
|
273 |
openedChats.add(t); |
|
274 |
} |
|
275 | ||
204 | 276 |
return openedChats; |
205 | 277 |
} |
206 | 278 | |
... | ... | |
253 | 325 |
* @param chat A ChatAdapter instance |
254 | 326 |
* @return A Chat activity PendingIntent |
255 | 327 |
*/ |
256 |
private PendingIntent makeChatIntent(IChat chat) {
|
|
328 |
private PendingIntent makeChatIntent(Contact c) {
|
|
257 | 329 |
Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class); |
258 | 330 |
chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP |
259 | 331 |
| Intent.FLAG_ACTIVITY_NEW_TASK); |
260 |
try { |
|
261 |
chatIntent.setData(chat.getParticipant().toUri()); |
|
262 |
} catch (RemoteException e) { |
|
263 |
Log.e(TAG, e.getMessage()); |
|
264 |
} |
|
332 |
chatIntent.setData(c.toUri()); |
|
265 | 333 |
PendingIntent contentIntent = PendingIntent.getActivity(mService, 0, chatIntent, |
266 | 334 |
PendingIntent.FLAG_UPDATE_CURRENT); |
267 | 335 |
return contentIntent; |
... | ... | |
271 | 339 |
* Set a notification of a new chat. |
272 | 340 |
* @param chat The chat to access by the notification |
273 | 341 |
*/ |
274 |
private void notifyNewChat(IChat chat) { |
|
275 |
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mService); |
|
276 |
try { |
|
277 |
CharSequence tickerText = mService.getBind().getRoster().getContact(chat.getParticipant().getJID()) |
|
278 |
.getName(); |
|
342 |
private void notifyNewChat(Contact c) { |
|
343 | ||
344 |
CharSequence tickerText = c.getName(); |
|
279 | 345 |
Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System |
280 | 346 |
.currentTimeMillis()); |
281 | 347 |
notification.flags = Notification.FLAG_AUTO_CANCEL; |
282 | 348 |
notification.setLatestEventInfo(mService, tickerText, mService |
283 |
.getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat)); |
|
284 |
mService.sendNotification(chat.getParticipant().getJID().hashCode(), notification); |
|
285 |
} catch (RemoteException e) { |
|
286 |
Log.e(TAG, e.getMessage()); |
|
287 |
} |
|
349 |
.getString(R.string.BeemChatManagerNewMessage), makeChatIntent(c)); |
|
350 |
mService.sendNotification(c.getJID().hashCode(), notification); |
|
351 |
} |
|
352 |
|
|
353 |
/** |
|
354 |
* Set a notification of a new chat. |
|
355 |
* @param chat The chat to access by the notification |
|
356 |
*/ |
|
357 |
private void notifyNewChat(IChat chat) { |
|
358 |
try { |
|
359 |
notifyNewChat(chat.getParticipant()) ; |
|
360 |
} catch (RemoteException e) { |
|
361 |
// TODO Auto-generated catch block |
|
362 |
e.printStackTrace(); |
|
363 |
} |
|
364 |
} |
|
365 |
/** |
|
366 |
* Set a notification of a MUC chat. |
|
367 |
* @param chat The chat to access by the notification |
|
368 |
*/ |
|
369 |
private void notifyMUCChat(IChatMUC chat) { |
|
370 |
Log.d(TAG,"poeuet") ; |
|
371 |
try { |
|
372 |
notifyNewChat(chat.getRoom()) ; |
|
373 |
} catch (RemoteException e) { |
|
374 |
// TODO Auto-generated catch block |
|
375 |
e.printStackTrace(); |
|
376 |
} |
|
288 | 377 |
} |
289 | 378 | |
290 | 379 |
/** |
... | ... | |
303 | 392 |
Log.e(TAG, e.getMessage()); |
304 | 393 |
} |
305 | 394 |
} |
306 | ||
395 |
|
|
307 | 396 |
@Override |
308 | 397 |
public void stateChanged(final IChat chat) { } |
398 | ||
399 |
@Override |
|
400 |
public void processMUCMessage(IChatMUC chat, Message message) |
|
401 |
throws RemoteException { |
|
402 |
if (!chat.isOpen() && message.getBody() != null) { |
|
403 |
notifyMUCChat(chat) ; |
|
404 |
} |
|
405 |
} |
|
309 | 406 |
} |
310 | 407 |
} |
beem-muc/src/com/beem/project/beem/service/ChatMUCAdapter.java 2010-08-13 00:01:37.978214445 +0200 | ||
---|---|---|
1 |
/* |
|
2 |
BEEM is a videoconference application on the Android Platform. |
|
3 | ||
4 |
Copyright (C) 2009 by Frederic-Charles Barthelery, |
|
5 |
Jean-Manuel Da Silva, |
|
6 |
Nikita Kozlov, |
|
7 |
Philippe Lago, |
|
8 |
Jean Baptiste Vergely, |
|
9 |
Vincent Veronis. |
|
10 | ||
11 |
This file is part of BEEM. |
|
12 | ||
13 |
BEEM is free software: you can redistribute it and/or modify |
|
14 |
it under the terms of the GNU General Public License as published by |
|
15 |
the Free Software Foundation, either version 3 of the License, or |
|
16 |
(at your option) any later version. |
|
17 | ||
18 |
BEEM is distributed in the hope that it will be useful, |
|
19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
GNU General Public License for more details. |
|
22 | ||
23 |
You should have received a copy of the GNU General Public License |
|
24 |
along with BEEM. If not, see <http://www.gnu.org/licenses/>. |
|
25 | ||
26 |
Please send bug reports with examples or suggestions to |
|
27 |
contact@beem-project.com or http://dev.beem-project.com/ |
|
28 | ||
29 |
Epitech, hereby disclaims all copyright interest in the program "Beem" |
|
30 |
written by Frederic-Charles Barthelery, |
|
31 |
Jean-Manuel Da Silva, |
|
32 |
Nikita Kozlov, |
|
33 |
Philippe Lago, |
|
34 |
Jean Baptiste Vergely, |
|
35 |
Vincent Veronis. |
|
36 | ||
37 |
Nicolas Sadirac, November 26, 2009 |
|
38 |
President of Epitech. |
|
39 | ||
40 |
Flavien Astraud, November 26, 2009 |
|
41 |
Head of the EIP Laboratory. |
|
42 | ||
43 |
*/ |
|
44 |
package com.beem.project.beem.service; |
|
45 | ||
46 |
import java.util.Collections; |
|
47 |
import java.util.LinkedList; |
|
48 |
import java.util.List; |
|
49 | ||
50 |
import org.jivesoftware.smackx.muc.MultiUserChat; |
|
51 |
import org.jivesoftware.smack.PacketListener; |
|
52 |
import org.jivesoftware.smack.XMPPException; |
|
53 |
import org.jivesoftware.smack.packet.Packet; |
|
54 |
import org.jivesoftware.smackx.ChatStateListener; |
|
55 |
import org.jivesoftware.smackx.ChatState; |
|
56 | ||
57 |
import android.os.RemoteCallbackList; |
|
58 |
import android.os.RemoteException; |
|
59 |
import android.util.Log; |
|
60 | ||
61 |
import com.beem.project.beem.service.aidl.IChatMUC; |
|
62 |
import com.beem.project.beem.service.aidl.IMessageListener; |
|
63 | ||
64 |
/** |
|
65 |
* An adapter for smack's Chat class. |
|
66 |
* @author darisk |
|
67 |
*/ |
|
68 |
public class ChatMUCAdapter extends IChatMUC.Stub { |
|
69 |
private static final int HISTORY_MAX_SIZE = 50; |
|
70 |
private static final String TAG = "ChatMUCAdapter"; |
|
71 |
private final MultiUserChat mAdaptee; |
|
72 |
private final Contact mParticipant; |
|
73 |
private String mState; |
|
74 |
private boolean mIsOpen; |
|
75 |
private final List<Message> mMessages; |
|
76 |
private final RemoteCallbackList<IMessageListener> mRemoteListeners = new RemoteCallbackList<IMessageListener>(); |
|
77 |
private final MsgMUCListener mMsgListener = new MsgMUCListener(); |
|
78 |
|
|
79 |
/** |
|
80 |
* Constructor. |
|
81 |
* @param chat The chat to adapt |
|
82 |
*/ |
|
83 |
public ChatMUCAdapter(final MultiUserChat chat) { |
|
84 |
mAdaptee = chat; |
|
85 |
mParticipant = new Contact(chat.getRoom(),true); |
|
86 |
mMessages = new LinkedList<Message>(); |
|
87 |
mAdaptee.addMessageListener(mMsgListener); |
|
88 |
} |
|
89 | ||
90 |
/** |
|
91 |
* {@inheritDoc} |
|
92 |
*/ |
|
93 |
@Override |
|
94 |
public Contact getRoom() throws RemoteException { |
|
95 |
return mParticipant; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* {@inheritDoc} |
|
100 |
*/ |
|
101 |
@Override |
|
102 |
public void sendMessage(com.beem.project.beem.service.Message message) throws RemoteException { |
|
103 |
org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message(); |
|
104 |
send.setTo(message.getTo()); |
|
105 |
Log.w(TAG, "message to " + message.getTo()); |
|
106 |
send.setBody(message.getBody()); |
|
107 |
send.setType(org.jivesoftware.smack.packet.Message.Type.groupchat); |
|
108 |
// TODO gerer les messages contenant des XMPPError |
|
109 |
// send.set |
|
110 |
try { |
|
111 |
mAdaptee.sendMessage(send); |
|
112 |
} catch (XMPPException e) { |
|
113 |
// TODO Auto-generated catch block |
|
114 |
e.printStackTrace(); |
|
115 |
} |
|
116 |
} |
|
117 | ||
118 |
/** |
|
119 |
* {@inheritDoc} |
|
120 |
*/ |
|
121 |
@Override |
|
122 |
public void addMessageListener(IMessageListener listen) { |
|
123 |
Log.d(TAG, "Un ecouteur de plus"); |
|
124 |
if (listen != null) |
|
125 |
mRemoteListeners.register(listen); |
|
126 |
} |
|
127 | ||
128 |
/** |
|
129 |
* {@inheritDoc} |
|
130 |
*/ |
|
131 |
@Override |
|
132 |
public void removeMessageListener(IMessageListener listen) { |
|
133 |
Log.d(TAG, "Un ecouteur de moins"); |
|
134 |
if (listen != null) { |
|
135 |
mRemoteListeners.unregister(listen); |
|
136 |
} |
|
137 |
} |
|
138 | ||
139 |
/** |
|
140 |
* {@inheritDoc} |
|
141 |
*/ |
|
142 |
@Override |
|
143 |
public String getState() throws RemoteException { |
|
144 |
return mState; |
|
145 |
} |
|
146 | ||
147 |
/** |
|
148 |
* {@inheritDoc} |
|
149 |
*/ |
|
150 |
@Override |
|
151 |
public void setState(String state) throws RemoteException { |
|
152 |
mState = state; |
|
153 |
} |
|
154 | ||
155 |
/** |
|
156 |
* Get the adaptee for the Chat. |
|
157 |
* @return The real chat object |
|
158 |
*/ |
|
159 |
public MultiUserChat getAdaptee() { |
|
160 |
return mAdaptee; |
|
161 |
} |
|
162 | ||
163 |
/** |
|
164 |
* {@inheritDoc} |
|
165 |
*/ |
|
166 |
@Override |
|
167 |
public void setOpen(boolean isOpen) { |
|
168 |
this.mIsOpen = isOpen; |
|
169 |
} |
|
170 | ||
171 |
/** |
|
172 |
* {@inheritDoc} |
|
173 |
*/ |
|
174 |
@Override |
|
175 |
public boolean isOpen() { |
|
176 |
return mIsOpen; |
|
177 |
} |
|
178 | ||
179 |
/** |
|
180 |
* {@inheritDoc} |
|
181 |
*/ |
|
182 |
@Override |
|
183 |
public List<Message> getMessages() throws RemoteException { |
|
184 |
return Collections.unmodifiableList(mMessages); |
|
185 |
} |
|
186 | ||
187 |
/** |
|
188 |
* Add a message in the chat history. |
|
189 |
* @param msg the message to add |
|
190 |
*/ |
|
191 |
void addMessage(Message msg) { |
|
192 |
if (mMessages.size() == HISTORY_MAX_SIZE) |
|
193 |
mMessages.remove(0); |
|
194 |
mMessages.add(msg); |
|
195 |
} |
|
196 | ||
197 |
/** |
|
198 |
* Listener. |
|
199 |
*/ |
|
200 |
private class MsgMUCListener implements PacketListener { |
|
201 |
/** |
|
202 |
* Constructor. |
|
203 |
*/ |
|
204 |
public MsgMUCListener() { } |
|
205 | ||
206 |
public void processPacket(Packet p) { |
|
207 |
org.jivesoftware.smack.packet.Message message = (org.jivesoftware.smack.packet.Message) p ; |
|
208 |
Message msg = new Message(message); |
|
209 |
Log.d(TAG, "Message arrive"); |
|
210 |
//TODO add que les message pas de type errors |
|
211 |
ChatMUCAdapter.this.addMessage(msg); |
|
212 |
final int n = mRemoteListeners.beginBroadcast(); |
|
213 |
Log.d(TAG, "Nb ecouteurs : "+((Integer)n).toString()); |
|
214 |
for (int i = 0; i < n; i++) { |
|
215 |
IMessageListener listener = mRemoteListeners.getBroadcastItem(i); |
|
216 |
try { |
|
217 |
if (listener != null) |
|
218 |
listener.processMUCMessage(ChatMUCAdapter.this, msg); |
|
219 |
} catch (RemoteException e) { |
|
220 |
Log.w(TAG, "Error while diffusing message to listener", e); |
|
221 |
} |
|
222 |
} |
|
223 |
mRemoteListeners.finishBroadcast(); |
|
224 |
} |
|
225 | ||
226 |
} |
|
227 | ||
228 |
@Override |
|
229 |
public List<Contact> getMembers() throws RemoteException { |
|
230 |
// TODO Auto-generated method stub |
|
231 |
return null; |
|
232 |
} |
|
233 | ||
234 |
} |
|
235 |
beem-muc/src/com/beem/project/beem/service/Contact.java 2010-08-13 11:52:07.688085444 +0200 | ||
---|---|---|
85 | 85 |
private List<String> mRes; |
86 | 86 |
private final List<String> mGroups = new ArrayList<String>(); |
87 | 87 |
private String mName; |
88 |
private boolean mIsMUC; |
|
88 | 89 | |
89 | 90 |
/** |
90 | 91 |
* Construct a contact from a parcel. |
... | ... | |
127 | 128 |
if (!"xmpp".equals(uri.getScheme())) |
128 | 129 |
throw new IllegalArgumentException(); |
129 | 130 |
String enduri = uri.getEncodedSchemeSpecificPart(); |
130 |
mJID = StringUtils.parseBareAddress(enduri); |
|
131 |
String fjid = StringUtils.parseBareAddress(enduri); |
|
132 |
if (fjid.charAt(0) == '$') { |
|
133 |
mJID = fjid.substring(1) ; |
|
134 |
mIsMUC = true ; |
|
135 |
} else { |
|
136 |
mJID = fjid ; |
|
137 |
mIsMUC = false ; |
|
138 |
} |
|
131 | 139 |
mName = mJID; |
132 | 140 |
mStatus = Status.CONTACT_STATUS_DISCONNECT; |
133 | 141 |
mMsgState = null; |
... | ... | |
136 | 144 |
mSelectedRes = res; |
137 | 145 |
mRes.add(res); |
138 | 146 |
} |
147 |
|
|
148 |
public Contact(final String jid, boolean isMuc) { |
|
149 |
this(jid) ; |
|
150 |
this.mIsMUC = true ; |
|
151 |
} |
|
139 | 152 | |
140 | 153 |
/** |
141 | 154 |
* {@inheritDoc} |
... | ... | |
257 | 270 |
public int getStatus() { |
258 | 271 |
return mStatus; |
259 | 272 |
} |
273 |
|
|
274 |
/** |
|
275 |
* Return whether the contact is a MUC room or not |
|
276 |
*/ |
|
277 |
public boolean isMUC() { |
|
278 |
return mIsMUC ; |
|
279 |
} |
|
260 | 280 | |
261 | 281 |
/** |
262 | 282 |
* Set the groups the contact is in. |
... | ... | |
367 | 387 |
*/ |
368 | 388 |
public Uri toUri() { |
369 | 389 |
StringBuilder build = new StringBuilder("xmpp:"); |
390 |
if (this.isMUC()) { |
|
391 |
build.append("$") ; |
|
392 |
} |
|
370 | 393 |
String name = StringUtils.parseName(mJID); |
371 | 394 |
build.append(name); |
372 | 395 |
if (!"".equals(name)) |
... | ... | |
383 | 406 |
*/ |
384 | 407 |
public Uri toUri(String resource) { |
385 | 408 |
StringBuilder build = new StringBuilder("xmpp:"); |
409 |
if (this.isMUC()) { |
|
410 |
build.append("$") ; |
|
411 |
} |
|
386 | 412 |
String name = StringUtils.parseName(mJID); |
387 | 413 |
build.append(name); |
388 | 414 |
if (!"".equals(name)) |
beem-muc/src/com/beem/project/beem/service/XmppConnectionAdapter.java 2010-08-26 21:35:04.618371494 +0200 | ||
---|---|---|
55 | 55 |
import org.jivesoftware.smack.packet.Presence; |
56 | 56 |
import org.jivesoftware.smackx.ChatStateManager; |
57 | 57 |
import org.jivesoftware.smackx.ServiceDiscoveryManager; |
58 |
import org.jivesoftware.smackx.bookmark.BookmarkManager; |
|
58 | 59 | |
59 | 60 |
import android.app.Notification; |
60 | 61 |
import android.app.PendingIntent; |
... | ... | |
95 | 96 |
private final String mLogin; |
96 | 97 |
private final String mPassword; |
97 | 98 |
private String mResource; |
99 |
private String mDefaultNickname; |
|
98 | 100 |
private String mErrorMsg; |
99 | 101 |
private RosterAdapter mRoster; |
100 | 102 |
private int mPreviousPriority; |
beem-muc/src/com/beem/project/beem/ui/Chat.java 2010-08-13 00:14:39.194793588 +0200 | ||
---|---|---|
61 | 61 |
import android.graphics.Bitmap; |
62 | 62 |
import android.graphics.BitmapFactory; |
63 | 63 |
import android.graphics.Color; |
64 |
import android.net.Uri; |
|
64 | 65 |
import android.os.Bundle; |
65 | 66 |
import android.os.Handler; |
66 | 67 |
import android.os.IBinder; |
... | ... | |
89 | 90 |
import com.beem.project.beem.service.PresenceAdapter; |
90 | 91 |
import com.beem.project.beem.service.aidl.IBeemRosterListener; |
91 | 92 |
import com.beem.project.beem.service.aidl.IChat; |
93 |
import com.beem.project.beem.service.aidl.IChatMUC; |
|
92 | 94 |
import com.beem.project.beem.service.aidl.IChatManager; |
93 | 95 |
import com.beem.project.beem.service.aidl.IChatManagerListener; |
94 | 96 |
import com.beem.project.beem.service.aidl.IMessageListener; |
... | ... | |
125 | 127 |
|
126 | 128 |
private final List<MessageText> mListMessages = new ArrayList<MessageText>(); |
127 | 129 |
|
128 |
private IChat mChat; |
|
129 | 130 |
private IChatManager mChatManager; |
130 | 131 |
private final IMessageListener mMessageListener = new OnMessageListener(); |
131 | 132 |
private final IChatManagerListener mChatManagerListener = new ChatManagerListener(); |
... | ... | |
200 | 201 |
protected void onPause() { |
201 | 202 |
super.onPause(); |
202 | 203 |
try { |
204 |
IChat mChat = mChatManager.getChat(mContact) ; |
|
203 | 205 |
if (mChat != null) { |
204 | 206 |
mChat.setOpen(false); |
205 | 207 |
mChat.removeMessageListener(mMessageListener); |
206 | 208 |
} |
209 |
IChatMUC mChatMUC = mChatManager.getMUCChat(mContact) ; |
|
210 |
if (mChatMUC != null) { |
|
211 |
mChatMUC.setOpen(false); |
|
212 |
mChatMUC.removeMessageListener(mMessageListener); |
|
213 |
} |
|
207 | 214 |
if (mRoster != null) |
208 | 215 |
mRoster.removeRosterListener(mBeemRosterListener); |
209 | 216 |
if (mChatManager != null) |
... | ... | |
217 | 224 |
} |
218 | 225 |
mXmppFacade = null; |
219 | 226 |
mRoster = null; |
220 |
mChat = null; |
|
221 | 227 |
mChatManager = null; |
222 | 228 |
} |
223 | 229 |
|
... | ... | |
280 | 286 |
break; |
281 | 287 |
case R.id.chat_menu_close_chat: |
282 | 288 |
try { |
289 |
IChat mChat = mChatManager.getChat(mContact) ; |
|
283 | 290 |
mChatManager.destroyChat(mChat); |
291 |
IChatMUC mMUCChat = mChatManager.getMUCChat(mContact) ; |
|
292 |
mChatManager.destroyMUCChat(mMUCChat); |
|
293 |
|
|
284 | 294 |
} catch (RemoteException e) { |
285 | 295 |
Log.e(TAG, e.getMessage()); |
286 | 296 |
} |
... | ... | |
298 | 308 |
* @throws RemoteException If a Binder remote-invocation error occurred. |
299 | 309 |
*/ |
300 | 310 |
private void changeCurrentChat(Contact contact) throws RemoteException { |
301 |
if (mChat != null) { |
|
302 |
mChat.setOpen(false); |
|
303 |
mChat.removeMessageListener(mMessageListener); |
|
304 |
} |
|
305 |
mChat = mChatManager.getChat(contact); |
|
306 |
if (mChat != null) { |
|
307 |
mChat.setOpen(true); |
|
308 |
mChat.addMessageListener(mMessageListener); |
|
309 |
mChatManager.deleteChatNotification(mChat); |
|
310 |
} |
|
311 |
mContact = mRoster.getContact(contact.getJID()); |
|
312 |
String res = contact.getSelectedRes(); |
|
313 |
if (mContact == null) |
|
314 |
mContact = contact; |
|
315 |
if (!"".equals(res)) { |
|
316 |
mContact.setSelectedRes(res); |
|
317 |
} |
|
318 |
updateContactInformations(); |
|
319 |
updateContactStatusIcon(); |
|
311 |
if (mContact.isMUC()) { |
|
312 |
IChatMUC mChat = mChatManager.getMUCChat(mContact) ; |
|
313 |
if (mChat != null) { |
|
314 |
mChat.setOpen(false); |
|
315 |
mChat.removeMessageListener(mMessageListener); |
|
316 |
} |
|
317 |
} else { |
|
318 |
IChat mChat = mChatManager.getChat(mContact) ; |
|
319 |
if (mChat != null) { |
|
320 |
mChat.setOpen(false); |
|
321 |
mChat.removeMessageListener(mMessageListener); |
|
322 |
} |
|
323 |
} |
|
324 |
|
|
325 |
if (contact.isMUC()) { |
|
326 |
IChatMUC newChat = mChatManager.getMUCChat(contact); |
|
327 |
if (newChat != null) { |
|
328 |
newChat.setOpen(true); |
|
329 |
newChat.addMessageListener(mMessageListener); |
|
330 |
} |
|
331 |
mContact = contact; |
|
332 |
} else { |
|
333 |
IChat newChat = mChatManager.getChat(contact); |
|
334 |
if (newChat != null) { |
|
335 |
newChat.setOpen(true); |
|
336 |
newChat.addMessageListener(mMessageListener); |
|
337 |
mChatManager.deleteChatNotification(newChat); |
|
338 |
} |
|
339 |
mContact = mRoster.getContact(contact.getJID()); |
|
340 |
} |
|
320 | 341 |
|
321 |
playRegisteredTranscript(); |
|
342 |
String res = contact.getSelectedRes(); |
|
343 |
if (mContact == null) |
|
344 |
mContact = contact; |
|
345 |
if (!"".equals(res)) { |
|
346 |
mContact.setSelectedRes(res); |
|
347 |
} |
|
348 |
updateContactInformations(); |
|
349 |
updateContactStatusIcon(); |
|
350 |
|
|
351 |
playRegisteredTranscript(); |
|
322 | 352 |
} |
323 | 353 |
|
324 | 354 |
/** |
... | ... | |
326 | 356 |
* @throws RemoteException If a Binder remote-invocation error occurred. |
327 | 357 |
*/ |
328 | 358 |
private void playRegisteredTranscript() throws RemoteException { |
329 |
mListMessages.clear(); |
|
330 |
if (mChat != null) { |
|
331 |
List<MessageText> msgList = convertMessagesList(mChat.getMessages()); |
|
332 |
mListMessages.addAll(msgList); |
|
333 |
mMessagesListAdapter.notifyDataSetChanged(); |
|
334 |
} |
|
359 |
mListMessages.clear(); |
|
360 |
List<MessageText> msgList = null ; |
|
361 |
if (mContact.isMUC()) { |
|
362 |
IChatMUC mChat = mChatManager.getMUCChat(mContact) ; |
|
363 |
if (mChat != null) { |
|
364 |
msgList = convertMessagesList(mChat.getMessages()); |
|
365 |
} |
|
366 |
} else { |
|
367 |
IChat mChat = mChatManager.getChat(mContact) ; |
|
368 |
if (mChat != null) { |
|
369 |
msgList = convertMessagesList(mChat.getMessages()); |
|
370 |
} |
|
371 |
|
|
372 |
} |
|
373 |
|
|
374 |
if (msgList != null) { |
|
375 |
mListMessages.addAll(msgList); |
|
376 |
mMessagesListAdapter.notifyDataSetChanged(); |
|
377 |
} |
|
335 | 378 |
} |
336 | 379 |
|
337 | 380 |
/** |
... | ... | |
351 | 394 |
if (m.getType() == Message.MSG_TYPE_ERROR) { |
352 | 395 |
lastMessage = null; |
353 | 396 |
result.add(new MessageText(fromBareJid, name, m.getBody(), true, m.getTimestamp())); |
354 |
} else if (m.getType() == Message.MSG_TYPE_CHAT) { |
|
355 |
if (fromBareJid == null) { //nofrom or from == yours |
|
397 |
} else if (m.getType() == Message.MSG_TYPE_CHAT || m.getType() == Message.MSG_TYPE_GROUP_CHAT) { |
|
398 |
if (m.getType() == Message.MSG_TYPE_GROUP_CHAT) { |
|
399 |
name = StringUtils.parseResource(m.getFrom()); |
|
400 |
} |
|
401 |
|
|
402 |
if (fromBareJid == null) { //nofrom or from == yours |
|
356 | 403 |
name = localName; |
357 | 404 |
fromBareJid = ""; |
358 | 405 |
} |
359 | 406 |
|
360 | 407 |
if (m.getBody() != null) { |
361 |
if (lastMessage == null || !fromBareJid.equals(lastMessage.getBareJid())) {
|
|
362 |
lastMessage = new MessageText(fromBareJid, name, m.getBody(), false, m.getTimestamp());
|
|
363 |
result.add(lastMessage);
|
|
364 |
} else {
|
|
365 |
lastMessage.setMessage(lastMessage.getMessage().concat("\n" + m.getBody()));
|
|
408 |
if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid) && lastMessage.getName().equals(name)) {
|
|
409 |
lastMessage.setMessage(lastMessage.getMessage().concat("\n" + m.getBody()));
|
|
410 |
} else {
|
|
411 |
lastMessage = new MessageText(fromBareJid, name, m.getBody(), false, m.getTimestamp());
|
|
412 |
result.add(lastMessage);
|
|
366 | 413 |
} |
367 | 414 |
} |
368 | 415 |
} |
... | ... | |
396 | 443 |
mChatManager.addChatCreationListener(mChatManagerListener); |
397 | 444 |
changeCurrentChat(mContact); |
398 | 445 |
} |
446 |
if (mContact!= null && mContact.isMUC()) { |
|
447 |
IChatMUC muc = mChatManager.getMUCChat(mContact) ; |
|
448 |
if (muc == null) { |
|
449 |
Log.d(TAG,"Service connected : "+mContact.getJIDWithRes()) ; |
|
450 |
IChatMUC mChatMUC = mChatManager.createMUCChat(mContact, mMessageListener) ; |
|
451 |
mChatMUC.addMessageListener(mMessageListener) ; |
|
452 |
mChatMUC.setOpen(true); |
|
453 |
} |
|
454 |
} |
|
455 |
|
|
399 | 456 |
} catch (RemoteException e) { |
400 |
Log.e(TAG, e.getMessage()); |
|
457 |
Log.e(TAG, e.getMessage());
|
|
401 | 458 |
} |
459 |
|
|
402 | 460 |
} |
403 | 461 |
|
404 | 462 |
/** |
... | ... | |
497 | 555 |
MessageText lastMessage = null; |
498 | 556 |
if (mListMessages.size() != 0) |
499 | 557 |
lastMessage = mListMessages.get(mListMessages.size() - 1); |
500 |
|
|
501 |
if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid)) { |
|
502 |
lastMessage.setMessage(lastMessage.getMessage().concat("\n" + msg.getBody())); |
|
503 |
lastMessage.setTimestamp(msg.getTimestamp()); |
|
504 |
mListMessages.set(mListMessages.size() - 1, lastMessage); |
|
558 |
String name ; |
|
559 |
if (mContact.isMUC()) { |
|
560 |
name = StringUtils.parseResource(msg.getFrom()); |
|
561 |
} else { |
|
562 |
name = mContact.getName() ; |
|
563 |
} |
|
564 |
|
|
565 |
if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid) && lastMessage.getName().equals(name)) { |
|
566 |
lastMessage.setMessage(lastMessage.getMessage().concat("\n" + msg.getBody())); |
|
567 |
lastMessage.setTimestamp(msg.getTimestamp()); |
|
568 |
mListMessages.set(mListMessages.size() - 1, lastMessage); |
|
505 | 569 |
} else if (msg.getBody() != null) |
506 |
mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody(), false, msg.getTimestamp()));
|
|
507 |
mMessagesListAdapter.notifyDataSetChanged(); |
|
508 |
} |
|
570 |
mListMessages.add(new MessageText(fromBareJid, name, msg.getBody(), false, msg.getTimestamp()));
|
|
571 |
mMessagesListAdapter.notifyDataSetChanged();
|
|
572 |
}
|
|
509 | 573 |
} |
510 | 574 |
}); |
511 | 575 |
} |
512 | 576 |
} |
513 | 577 |
|
578 |
@Override |
|
579 |
public void processMUCMessage(IChatMUC chat, final Message msg) throws RemoteException { |
|
580 |
processMessage(null, msg) ; |
|
581 |
} |
|
582 |
|
|
514 | 583 |
/** |
515 | 584 |
* {@inheritDoc}. |
516 | 585 |
*/ |
... | ... | |
815 | 884 |
final String inputContent = mInputField.getText().toString(); |
816 | 885 |
|
817 | 886 |
if (!"".equals(inputContent)) { |
818 |
Message msgToSend = new Message(mContact.getJIDWithRes(), Message.MSG_TYPE_CHAT); |
|
887 |
Message msgToSend ; |
|
888 |
if (mContact.isMUC()) { |
|
889 |
msgToSend = new Message(mContact.getJID(), Message.MSG_TYPE_GROUP_CHAT); |
|
890 |
} else { |
|
891 |
msgToSend = new Message(mContact.getJIDWithRes(), Message.MSG_TYPE_CHAT); |
|
892 |
} |
|
893 |
|
|
819 | 894 |
msgToSend.setBody(inputContent); |
820 | 895 |
|
821 | 896 |
try { |
822 |
if (mChat == null) { |
|
823 |
mChat = mChatManager.createChat(mContact, mMessageListener); |
|
824 |
mChat.setOpen(true); |
|
825 |
} |
|
826 |
mChat.sendMessage(msgToSend); |
|
897 |
if (mContact.isMUC()) { |
|
898 |
IChatMUC mChatMUC = mChatManager.getMUCChat(mContact) ; |
|
899 |
mChatMUC.sendMessage(msgToSend); |
|
900 |
} else { |
|
901 |
IChat mChat = mChatManager.getChat(mContact) ; |
|
902 |
if (mChat == null) { |
|
903 |
mChat = mChatManager.createChat(mContact, mMessageListener); |
|
904 |
mChat.setOpen(true); |
|
905 |
} |
|
906 |
mChat.sendMessage(msgToSend); |
|
907 |
final String self = getString(R.string.chat_self); |
|
908 |
MessageText lastMessage = null; |
|
909 |
if (mListMessages.size() != 0) |
|
910 |
lastMessage = mListMessages.get(mListMessages.size() - 1); |
|
911 |
|
|
912 |
if (lastMessage != null && lastMessage.getName().equals(self)) { |
|
913 |
lastMessage.setMessage(lastMessage.getMessage().concat("\n" + inputContent)); |
|
914 |
lastMessage.setTimestamp(new Date()); |
|
915 |
} else { |
|
916 |
mListMessages.add(new MessageText(self, self, inputContent, false, new Date())); |
|
917 |
} |
|
918 |
} |
|
827 | 919 |
} catch (RemoteException e) { |
828 | 920 |
Log.e(TAG, e.getMessage()); |
829 | 921 |
} |
830 | 922 |
|
831 |
final String self = getString(R.string.chat_self); |
|
832 |
MessageText lastMessage = null; |
|
833 |
if (mListMessages.size() != 0) |
|
834 |
lastMessage = mListMessages.get(mListMessages.size() - 1); |
|
835 |
|
|
836 |
if (lastMessage != null && lastMessage.getName().equals(self)) { |
|
837 |
lastMessage.setMessage(lastMessage.getMessage().concat("\n" + inputContent)); |
|
838 |
lastMessage.setTimestamp(new Date()); |
|
839 |
} else |
|
840 |
mListMessages.add(new MessageText(self, self, inputContent, false, new Date())); |
|
923 |
|
|
841 | 924 |
mMessagesListAdapter.notifyDataSetChanged(); |
842 | 925 |
mInputField.setText(null); |
843 | 926 |
} |
... | ... | |
863 | 946 |
String chatJid = chat.getParticipant().getJIDWithRes(); |
864 | 947 |
if (chatJid.equals(contactJid)) { |
865 | 948 |
// This should not be happened but to be sure |
949 |
IChat mChat = mChatManager.getChat(mContact) ; |
|
866 | 950 |
if (mChat != null) { |
867 | 951 |
mChat.setOpen(false); |
868 | 952 |
mChat.removeMessageListener(mMessageListener); |
beem-muc/src/com/beem/project/beem/ui/ContactList.java 2010-08-26 21:39:20.477398335 +0200 | ||
---|---|---|
95 | 95 |
import com.beem.project.beem.ui.dialogs.builders.Alias; |
96 | 96 |
import com.beem.project.beem.ui.dialogs.builders.ChatList; |
97 | 97 |
import com.beem.project.beem.ui.dialogs.builders.DeleteContact; |
98 |
import com.beem.project.beem.ui.dialogs.builders.JoinMUC; |
|
98 | 99 |
import com.beem.project.beem.ui.dialogs.builders.ResendSubscription; |
99 | 100 |
import com.beem.project.beem.utils.BeemBroadcastReceiver; |
100 | 101 |
import com.beem.project.beem.utils.SortedList; |
... | ... | |
182 | 183 |
case R.id.menu_disconnect: |
183 | 184 |
stopService(SERVICE_INTENT); |
184 | 185 |
finish(); |
186 |
case R.id.muc: |
|
187 |
Dialog joinmuc = new JoinMUC(ContactList.this).create() ; |
|
188 |
joinmuc.show() ; |
|
189 |
return true; |
|
185 | 190 |
default: |
186 | 191 |
return false; |
187 | 192 |
} |
... | ... | |
259 | 264 |
delete.show(); |
260 | 265 |
result = true; |
261 | 266 |
break; |
267 |
case R.id.contact_list_context_menu_joinasmuc_item : |
|
268 |
Contact c = new Contact(mSelectedContact.getJID(), true); |
|
269 |
Intent i = new Intent(ContactList.this, Chat.class); |
|
270 |
i.setData(c.toUri(mSettings.getString("settings_key_nickname", "BeemGuest"))); |
|
271 |
startActivity(i); |
|
272 |
result=true; |
|
273 |
break; |
|
262 | 274 |
default: |
263 | 275 |
result = super.onContextItemSelected(item); |
264 | 276 |
break; |
beem-muc/src/com/beem/project/beem/ui/dialogs/builders/ChatList.java 2010-08-13 11:35:44.400684883 +0200 | ||
---|---|---|
73 | 73 | |
74 | 74 |
int i = 0; |
75 | 75 |
for (Contact c : openedChats) { |
76 |
items[i++] = c.getName(); |
|
76 |
if (c.isMUC()) { |
|
77 |
items[i++] = "[C] "+c.getJID(); |
|
78 |
} else { |
|
79 |
items[i++] = c.getJIDWithRes(); |
|
80 |
} |
|
77 | 81 |
} |
78 | 82 |
setTitle(R.string.chat_dialog_change_chat_title); |
79 | 83 |
setItems(items, new DialogInterface.OnClickListener() { |
beem-muc/src/com/beem/project/beem/ui/dialogs/builders/JoinMUC.java 2010-08-26 21:11:29.289598545 +0200 | ||
---|---|---|
1 |
/* |
|
2 |
BEEM is a videoconference application on the Android Platform. |
|
3 | ||
4 |
Copyright (C) 2009 by Frederic-Charles Barthelery, |
|
5 |
Jean-Manuel Da Silva, |
|
6 |
Nikita Kozlov, |
|
7 |
Philippe Lago, |
|
8 |
Jean Baptiste Vergely, |
|
9 |
Vincent Veronis. |
|
10 | ||
11 |
This file is part of BEEM. |
|
12 | ||
13 |
BEEM is free software: you can redistribute it and/or modify |
|
14 |
it under the terms of the GNU General Public License as published by |
|
15 |
the Free Software Foundation, either version 3 of the License, or |
|
16 |
(at your option) any later version. |
|
17 | ||
18 |
BEEM is distributed in the hope that it will be useful, |
|
19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
GNU General Public License for more details. |
|
22 | ||
23 |
You should have received a copy of the GNU General Public License |
|
24 |
along with BEEM. If not, see <http://www.gnu.org/licenses/>. |
|
25 | ||
26 |
Please send bug reports with examples or suggestions to |
|
27 |
contact@beem-project.com or http://dev.beem-project.com/ |
|
28 | ||
29 |
Epitech, hereby disclaims all copyright interest in the program "Beem" |
|
30 |
written by Frederic-Charles Barthelery, |
|
31 |
Jean-Manuel Da Silva, |
|
32 |
Nikita Kozlov, |
|
33 |
Philippe Lago, |
|
34 |
Jean Baptiste Vergely, |
|
35 |
Vincent Veronis. |
|
36 | ||
37 |
Nicolas Sadirac, November 26, 2009 |
|
38 |
President of Epitech. |
|
39 | ||
40 |
Flavien Astraud, November 26, 2009 |
|
41 |
Head of the EIP Laboratory. |
|
42 | ||
43 |
*/ |
|
44 |
package com.beem.project.beem.ui.dialogs.builders; |
|
45 | ||
46 |
import android.app.AlertDialog; |
|
47 |
import android.content.Context; |
|
48 |
import android.content.DialogInterface; |
|
49 |
import android.content.Intent; |
|
50 |
import android.view.LayoutInflater; |
|
51 |
import android.view.View; |
|
52 |
import android.widget.EditText; |
|
53 | ||
54 |
import com.beem.project.beem.R; |
|
55 |
import com.beem.project.beem.service.Contact; |
|
56 |
import com.beem.project.beem.ui.Chat; |
|
57 | ||
58 |
/** |
|
59 |
* Create dialog alias. |
|
60 |
*/ |
|
61 |
public class JoinMUC extends AlertDialog.Builder { |
|
62 | ||
63 |
private static final String TAG = "Dialogs.Builders > JoinMUC"; |
|
64 | ||
65 |
private Context context ; |
|
66 |
private EditText mEditTextRoom; |
|
67 |
private EditText mEditTextPseudo; |
|
68 | ||
69 |
/** |
|
70 |
* Constructor. |
|
71 |
* @param context context activity. |
|
72 |
* @param roster Beem roster. |
|
73 |
* @param contact the contact to modify. |
|
74 |
*/ |
|
75 |
public JoinMUC(final Context context) { |
|
76 |
super(context); |
|
77 |
this.context = context ; |
|
78 |
LayoutInflater factory = LayoutInflater.from(context); |
|
79 |
final View textEntryView = factory.inflate( |
|
80 |
R.layout.joinmucdialog, null); |
|
81 |
setTitle("Join MUC"); |
|
82 |
setView(textEntryView); |
|
83 |
mEditTextRoom = (EditText) textEntryView.findViewById(R.id.CDRoomDialogName); |
|
84 |
mEditTextPseudo = (EditText) textEntryView.findViewById(R.id.CDNickDialogName); |
|
85 |
setPositiveButton(R.string.OkButton, new DialogClickListener()); |
|
86 |
setNegativeButton(R.string.CancelButton, new DialogClickListener()); |
|
87 |
} |
|
88 | ||
89 |
/** |
|
90 |
* Event click listener. |
|
91 |
*/ |
|
92 |
class DialogClickListener implements DialogInterface.OnClickListener { |
|
93 | ||
94 |
/** |
|
95 |
* Constructor. |
|
96 |
*/ |
|
97 |
public DialogClickListener() { |
|
98 |
} |
|
99 | ||
100 | ||
101 |
@Override |
|
102 |
public void onClick(final DialogInterface dialog, final int which) { |
|
103 |
if (which == DialogInterface.BUTTON_POSITIVE) { |
|
104 |
String room = mEditTextRoom.getText().toString(); |
|
105 |
String pseudo = mEditTextPseudo.getText().toString(); |
|
106 |
Contact c = new Contact(room, true); |
|
107 |
Intent i = new Intent(context, Chat.class); |
|
108 |
i.setData(c.toUri(pseudo)); |
|
109 |
context.startActivity(i); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
} |