Project

General

Profile

Feature #216 » patch_beem_muc_015.patch

Alexandre Chataignon, 02/28/2011 05:03 PM

View differences:

default.properties Mon Jan 31 20:01:33 2011 +0100 → default.properties Sun Feb 27 23:38:33 2011 +0100
8 8
# project structure.
9 9

  
10 10
# Project target.
11
target=android-7
11
target=android-10
/dev/null Thu Jan 01 00:00:00 1970 +0000 → res/layout/joinmucdialog.xml Sun Feb 27 23:38:33 2011 +0100
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>
res/layout/preferences.xml Mon Jan 31 20:01:33 2011 +0100 → res/layout/preferences.xml Sun Feb 27 23:38:33 2011 +0100
37 37
			<RingtonePreference android:title="@string/notification_snd_title"
38 38
				android:key="notification_sound" android:summary="@string/notification_snd_sum"
39 39
				android:ringtoneType="notification" android:showDefault="true" />
40
			<CheckBoxPreference android:title="@string/notification_hl_title"
41
				android:defaultValue="false" android:summary="@string/notification_hl_sum"
42
				android:key="notification_hls" />
40 43
		</PreferenceScreen>
41 44
	</PreferenceCategory>
42 45
	<PreferenceCategory android:title="@string/user_preferences">
......
56 59
			android:title="@string/SettingsPriorityTitle" android:summary="@string/SettingsPrioritySummary"
57 60
			android:numeric="signed" android:defaultValue="0" />
58 61
	</PreferenceCategory>
62
	<PreferenceCategory android:title="@string/muc_preferences">
63
		<EditTextPreference android:key="settings_key_nickname"
64
			android:title="@string/SettingsNicknameTitle" android:summary="@string/SettingsNicknameSummary"
65
			android:defaultValue="BeemGuest" />
66
		<EditTextPreference android:key="settings_key_hls" android:title="@string/SettingsHLSTitle" android:summary="@string/SettingsHLSSummary" />
67
	</PreferenceCategory>
59 68
	<PreferenceCategory android:title="@string/network_preferences">
60 69
		<PreferenceScreen android:key="proxy" android:title="@string/SettingsProxy"
61 70
			android:summary="@string/settings_proxy_sum">
res/menu/contact_list.xml Mon Jan 31 20:01:33 2011 +0100 → res/menu/contact_list.xml Sun Feb 27 23:38:33 2011 +0100
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>
res/menu/contactlist_context.xml Mon Jan 31 20:01:33 2011 +0100 → res/menu/contactlist_context.xml Sun Feb 27 23:38:33 2011 +0100
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>
res/values-fr/strings.xml Mon Jan 31 20:01:33 2011 +0100 → res/values-fr/strings.xml Sun Feb 27 23:38:33 2011 +0100
300 300

  
301 301
	<string name="UpdateButton">Mettre à jour</string>
302 302
	
303
	<string name="Room">Salon</string>
304
	<string name="Nick">Pseudo</string>
305
	
303 306
	<!-- Error messages -->
304 307
	<string name="error_login_authentication">Erreur lors de l\'authenfitication, mauvais login ou password</string>
305 308
	<string name="interna_server_error">Erreur survenu sur le serveur</string>
res/values/strings.xml Mon Jan 31 20:01:33 2011 +0100 → res/values/strings.xml Sun Feb 27 23:38:33 2011 +0100
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>
81
    <string name="SettingsHLSTitle">Highlights</string>
79 82
	<string name="SettingsResourceSummary">Set the XMPP resource of your client </string>
80 83
	<string name="SettingsPrioritySummary">Set the priority of your client</string>
84
	<string name="SettingsNicknameSummary">Set the default nickname when joining MUC</string>
85
    <string name="SettingsHLSSummary">Comma-separated list of words (other than your nickname) that will highlight you</string>
86

  
81 87
	<string name="contact_list_preferences">Buddy list</string>
82 88
	<string name="contact_list_preferences_sum">A set of display options for your buddy list
83 89
	</string>
......
117 123
	<string name="notification_enable_vibrate_sum">Enable vibrate on incoming messages</string>
118 124
	<string name="notification_snd_title">Message ringtone</string>
119 125
	<string name="notification_snd_sum">Set your incoming message ringtone</string>
126
    <string name="notification_hl_title">Notify only highlights</string>
127
    <string name="notification_hl_sum">Check if you want to be notified only when you are highlited in MUC</string>
120 128
	<string name="settings_chat_compact">Chat compact</string>
121 129
	<string name="settings_chat_compact_sum">Set the chat windows compact</string>
122 130
	<string name="history">History</string>
......
197 205
	<string name="general_preferences">General preferences</string>
198 206
	<string name="user_preferences">User settings (required)</string>
199 207
	<string name="user_preferences_advanced">User settings advanced (optional)</string>
208
    <string name="muc_preferences">MUC settings (optional)</string>
200 209
	<string name="network_preferences">Network options</string>
201 210
	<string name="proxy_proxy_settings">Proxy settings</string>
202 211
	<string name="proxy_user_settings">Proxy settings</string>
......
285 294
	<string name="privacy_list_delete_dialog_no">No</string>
286 295

  
287 296
	<string name="UpdateButton">Update</string>
288
	
297
	<string name="Room">Room</string>
298
	<string name="Nick">Nickname</string>
289 299
	<!-- Error messages -->
290 300
	
291 301
	<string name="error_login_authentication">Error during authentication, bad login or password.</string>
src/com/beem/project/beem/BeemService.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/BeemService.java Sun Feb 27 23:38:33 2011 +0100
299 299
    public IXmppFacade getBind() {
300 300
	return mBind;
301 301
    }
302
    
303
    public XmppConnectionAdapter getmConnection() {
304
		return mConnection;
305
	}
302 306

  
303 307
    /**
304 308
     * Get the preference of the service.
src/com/beem/project/beem/service/BeemChatManager.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/service/BeemChatManager.java Sun Feb 27 23:38:33 2011 +0100
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.BeemApplication;
65 68
import com.beem.project.beem.BeemService;
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
		String nick = StringUtils.parseResource(jid);
161
		ChatMUCAdapter result;
162
		Log.d(TAG, "Get chat key2 = "+jid);
163
		if (mMUCChats.containsKey(key)) {
164
		    result = mMUCChats.get(key);
165
		    result.addMessageListener(listener);
166
		    return result;
167
		}
168
		MultiUserChat c = new MultiUserChat(mService.getmConnection().getAdaptee(),key);
169
		result = new ChatMUCAdapter(c, mService, nick);
170
		mMUCChats.put(key, result);
171
		result.addMessageListener(listener);
172
		result.addMessageListener(mChatListener);
173
		return result;
174
    }
175

  
139 176

  
140 177
    /**
141 178
     * {@inheritDoc}
......
150 187
	mChats.remove(chat.getParticipant().getJID());
151 188
    }
152 189

  
190
    @Override
191
    public void destroyMUCChat(IChatMUC chat) throws RemoteException {
192
		if (chat == null)
193
		    return;
194
		((ChatMUCAdapter)chat).getAdaptee().leave() ;
195
		mMUCChats.remove(chat.getRoom().getJID());
196
		
197
    }
198
    
153 199
    /**
154 200
     * {@inheritDoc}
155 201
     */
......
185 231
    }
186 232

  
187 233
    @Override
188
    public ChatAdapter getChat(Contact contact) {
189
	String key = contact.getJIDWithRes();
190
	return mChats.get(key);
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);
191 242
    }
243
    
192 244

  
193
    /**
245
     /**
194 246
     * This methods permits to retrieve the list of contacts who have an opened chat session with us.
195 247
     * @return An List containing Contact instances.
196 248
     * @throws RemoteException If a Binder remote-invocation error occurred.
......
198 250
    public List<Contact> getOpenedChatList() throws RemoteException {
199 251
	List<Contact> openedChats = new ArrayList<Contact>();
200 252
	IRoster mRoster = mService.getBind().getRoster();
201

  
202 253
	for (ChatAdapter chat : mChats.values()) {
203 254
	    if (chat.getMessages().size() > 0) {
204
		Contact t = mRoster.getContact(chat.getParticipant().getJID());
255
		Contact t = mRoster.getContact(chat.getParticipant().getJIDWithRes());
205 256
		if (t == null)
206
		    t = new Contact(chat.getParticipant().getJID());
257
		    t = new Contact(chat.getParticipant().getJIDWithRes());
207 258
		openedChats.add(t);
208 259
	    }
209 260
	}
261
	for (ChatMUCAdapter chat : mMUCChats.values()) {
262
		Contact t = new Contact(chat.getRoom().getJID(), true);
263
		openedChats.add(t);
264
	}
265

  
210 266
	return openedChats;
211 267
    }
212 268

  
......
259 315
	 * @param chat A ChatAdapter instance
260 316
	 * @return A Chat activity PendingIntent
261 317
	 */
262
	private PendingIntent makeChatIntent(IChat chat) {
318
	private PendingIntent makeChatIntent(Contact c) {
263 319
	    Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class);
264 320
	    chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP
265 321
		| Intent.FLAG_ACTIVITY_NEW_TASK);
266
	    try {
267
		chatIntent.setData(chat.getParticipant().toUri());
268
	    } catch (RemoteException e) {
269
		Log.e(TAG, e.getMessage());
270
	    }
322
        chatIntent.setData(c.toUri());
271 323
	    PendingIntent contentIntent = PendingIntent.getActivity(mService, 0, chatIntent,
272 324
		PendingIntent.FLAG_UPDATE_CURRENT);
273 325
	    return contentIntent;
......
278 330
	 * @param chat The chat to access by the notification
279 331
	 * @param msgBody the body of the new message
280 332
	 */
281
	private void notifyNewChat(IChat chat, String msgBody) {
282
	    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mService);
283
	    try {
284
		CharSequence tickerText = mService.getBind().getRoster().getContact(chat.getParticipant().getJID())
285
		    .getName();
333
	private void notifyNewChat(Contact c, String msgBody) {
334
        CharSequence tickerText = c.getName();
286 335
		Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System
287 336
		    .currentTimeMillis());
288 337
		notification.flags = Notification.FLAG_AUTO_CANCEL;
289
		notification.setLatestEventInfo(mService, tickerText, msgBody, makeChatIntent(chat));
290
		mService.sendNotification(chat.getParticipant().getJID().hashCode(), notification);
291
	    } catch (RemoteException e) {
292
		Log.e(TAG, e.getMessage());
293
	    }
338
		notification.setLatestEventInfo(mService, tickerText, msgBody, makeChatIntent(c));
339
		mService.sendNotification(c.getJID().hashCode(), notification);
294 340
	}
295 341

  
342

  
343
    /**
344
     * Set a notification of a new chat.
345
     * @param chat The chat to access by the notification
346
     */
347
    private void notifyNewChat(IChat chat, String msgBody) {
348
        try {
349
            notifyNewChat(chat.getParticipant(), msgBody);
350
        } catch (RemoteException e) {
351
            // TODO Auto-generated catch block
352
            e.printStackTrace();
353
        }
354
    }
355
   /**
356
    * Set a notification of a MUC chat.
357
    * @param chat The chat to access by the notification
358
    */
359
   private void notifyMUCChat(IChatMUC chat, String msgBody) {
360
       Log.d(TAG,"poeuet") ;
361
       try {
362
               notifyNewChat(chat.getRoom(), msgBody) ;
363
           } catch (RemoteException e) {
364
               // TODO Auto-generated catch block
365
               e.printStackTrace();
366
           }
367
    }
368

  
296 369
	/**
297 370
	 * {@inheritDoc}
298 371
	 */
......
311 384
	    }
312 385
	}
313 386

  
387
    @Override
388
    public void processMUCMessage(IChatMUC chat, Message message)
389
        throws RemoteException {
390
        String body = message.getBody();
391
		boolean onlyhl = PreferenceManager.getDefaultSharedPreferences(mService).getBoolean("notification_hls", false) ;
392
		if (!chat.isOpen() && message.getBody() != null && ( message.isHL() || !onlyhl)) {
393
             notifyMUCChat(chat, body) ;
394
        }
395
    }
396

  
314 397
	@Override
315 398
	public void stateChanged(final IChat chat) {
316 399
	}
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/service/ChatMUCAdapter.java Sun Feb 27 23:38:33 2011 +0100
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.smack.util.StringUtils;
55
import org.jivesoftware.smackx.ChatStateListener;
56
import org.jivesoftware.smackx.ChatState;
57

  
58
import android.os.RemoteCallbackList;
59
import android.os.RemoteException;
60
import android.preference.PreferenceManager;
61
import android.util.Log;
62

  
63
import com.beem.project.beem.BeemService;
64
import com.beem.project.beem.service.aidl.IChatMUC;
65
import com.beem.project.beem.service.aidl.IMessageListener;
66

  
67
/**
68
 * An adapter for smack's Chat class.
69
 * @author darisk
70
 */
71
public class ChatMUCAdapter extends IChatMUC.Stub {
72
    private static final int HISTORY_MAX_SIZE = 50;
73
    private static final String TAG = "ChatMUCAdapter";
74
    private final  MultiUserChat mAdaptee;
75
    private final Contact mParticipant;
76
    private String mState;
77
    private boolean mIsOpen;
78
    private String mNick ;
79
    private final BeemService mService;
80
    private final List<Message> mMessages;
81
    private final RemoteCallbackList<IMessageListener> mRemoteListeners = new RemoteCallbackList<IMessageListener>();
82
    private final MsgMUCListener mMsgListener = new MsgMUCListener();
83
    
84
   /**
85
     * Constructor.
86
     * @param chat The chat to adapt
87
     */
88
    public ChatMUCAdapter(final MultiUserChat chat, final BeemService service, String nick) {
89
    	mAdaptee = chat;
90
    	mParticipant = new Contact(chat.getRoom(),true);
91
    	mMessages = new LinkedList<Message>();
92
    	mAdaptee.addMessageListener(mMsgListener);
93
    	mNick = nick ;
94
    	mService = service;
95
    	// Join the MUC
96
		try {
97
			chat.join(nick) ;
98
		} catch (XMPPException e) {
99
			// TODO Auto-generated catch block
100
			e.printStackTrace();
101
		}
102
    }
103

  
104
    /**
105
     * {@inheritDoc}
106
     */
107
    @Override
108
    public Contact getRoom() throws RemoteException {
109
	return mParticipant;
110
    }
111
    
112
    /**
113
     * {@inheritDoc}
114
     */
115
    @Override
116
    public void sendMessage(com.beem.project.beem.service.Message message) throws RemoteException {
117
	org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message();
118
	send.setTo(message.getTo());
119
	Log.w(TAG, "message to " + message.getTo());
120
	send.setBody(message.getBody());
121
	send.setType(org.jivesoftware.smack.packet.Message.Type.groupchat);
122
	// TODO gerer les messages contenant des XMPPError
123
	// send.set
124
	try {
125
	    mAdaptee.sendMessage(send);
126
	} catch (XMPPException e) {
127
	    // TODO Auto-generated catch block
128
	    e.printStackTrace();
129
	}
130
    }
131

  
132
    /**
133
     * {@inheritDoc}
134
     */
135
    @Override
136
    public void addMessageListener(IMessageListener listen) {
137
    	Log.d(TAG, "Un ecouteur de plus");
138
	if (listen != null)
139
	    mRemoteListeners.register(listen);
140
    }
141

  
142
    /**
143
     * {@inheritDoc}
144
     */
145
    @Override
146
    public void removeMessageListener(IMessageListener listen) {
147
    	Log.d(TAG, "Un ecouteur de moins");
148
	if (listen != null) {
149
	    mRemoteListeners.unregister(listen);
150
	}
151
    }
152

  
153
    /**
154
     * {@inheritDoc}
155
     */
156
    @Override
157
    public String getState() throws RemoteException {
158
	return mState;
159
    }
160

  
161
    /**
162
     * {@inheritDoc}
163
     */
164
    @Override
165
    public void setState(String state) throws RemoteException {
166
	mState = state;
167
    }
168

  
169
    /**
170
     * Get the adaptee for the Chat.
171
     * @return The real chat object
172
     */
173
    public MultiUserChat getAdaptee() {
174
	return mAdaptee;
175
    }
176

  
177
    /**
178
     * {@inheritDoc}
179
     */
180
    @Override
181
    public void setOpen(boolean isOpen) {
182
	this.mIsOpen = isOpen;
183
    }
184

  
185
    /**
186
     * {@inheritDoc}
187
     */
188
    @Override
189
    public boolean isOpen() {
190
	return mIsOpen;
191
    }
192

  
193
    /**
194
     * {@inheritDoc}
195
     */
196
    @Override
197
    public List<Message> getMessages() throws RemoteException {
198
	return Collections.unmodifiableList(mMessages);
199
    }
200

  
201
    /**
202
     * Add a message in the chat history.
203
     * @param msg the message to add
204
     */
205
    void addMessage(Message msg) {
206
	if (mMessages.size() == HISTORY_MAX_SIZE)
207
	    mMessages.remove(0);
208
	mMessages.add(msg);
209
    }
210

  
211
    /**
212
     * Listener.
213
     */
214
    private class MsgMUCListener implements PacketListener {
215
	/**
216
	 * Constructor.
217
	 */
218
	public MsgMUCListener() { }
219

  
220
	public void processPacket(Packet p) {
221
		org.jivesoftware.smack.packet.Message message = (org.jivesoftware.smack.packet.Message) p ;
222
	    Message  msg = new Message(message);
223
	    //TODO add que les message pas de type errors
224
	    ChatMUCAdapter.this.addMessage(msg);
225
	    final int n = mRemoteListeners.beginBroadcast();
226
	    for (int i = 0; i < n; i++) {
227
		IMessageListener listener = mRemoteListeners.getBroadcastItem(i);
228
		try {
229
		    if (listener != null) {
230
		    	//HL detection
231
		    	//If the pseudo
232
		    	String bodylow = msg.getBody().toLowerCase() ;
233
		    	if (bodylow.contains(mNick.toLowerCase())) {
234
		    		msg.setHL(true) ; 
235
		    	}
236
		    	//If in the hl list
237
		    	String hls = PreferenceManager.getDefaultSharedPreferences(mService).getString("settings_key_hls", "") ;
238
		    	if (! hls.equalsIgnoreCase("")) {
239
			    	for (String hl : hls.split(",")) {
240
			    		if (bodylow.contains(hl.toLowerCase())) {
241
				    		msg.setHL(true) ; 
242
				    	}
243
			    	}
244
		    	}
245
		    	listener.processMUCMessage(ChatMUCAdapter.this, msg);
246
		    }
247
		} catch (RemoteException e) {
248
		    Log.w(TAG, "Error while diffusing message to listener", e);
249
		}
250
	    }
251
	    mRemoteListeners.finishBroadcast();
252
	}
253

  
254
    }
255

  
256
	@Override
257
	public List<Contact> getMembers() throws RemoteException {
258
		// TODO Auto-generated method stub
259
		return null;
260
	}
261

  
262
}
263

  
src/com/beem/project/beem/service/Contact.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/service/Contact.java Sun Feb 27 23:38:33 2011 +0100
86 86
    private final List<String> mGroups = new ArrayList<String>();
87 87
    private String mName;
88 88
    private String mAvatarId;
89
    private boolean mIsMUC;
89 90

  
90 91
    /**
91 92
     * Construct a contact from a parcel.
......
129 130
	if (!"xmpp".equals(uri.getScheme()))
130 131
	    throw new IllegalArgumentException();
131 132
	String enduri = uri.getEncodedSchemeSpecificPart();
132
	mJID = StringUtils.parseBareAddress(enduri);
133
    String fjid = StringUtils.parseBareAddress(enduri);
134
	if (fjid.charAt(0) == '$') {
135
		mJID = fjid.substring(1) ;
136
		mIsMUC = true ;
137
	} else {
138
        mJID = fjid ;
139
		mIsMUC = false ;
140
	}
133 141
	mName = mJID;
134 142
	mStatus = Status.CONTACT_STATUS_DISCONNECT;
135 143
	mMsgState = null;
......
138 146
	mSelectedRes = res;
139 147
	mRes.add(res);
140 148
    }
149
    
150
    public Contact(final String jid, boolean isMuc) {
151
    	this(jid) ;
152
    	this.mIsMUC = true ;
153
    }
141 154

  
142 155
    /**
143 156
     * Make an xmpp uri for a spcific jid.
......
282 295
    public int getStatus() {
283 296
	return mStatus;
284 297
    }
298
    
299
    /**
300
     * Return whether the contact is a MUC room or not
301
     */
302
    public boolean isMUC() {
303
    	return mIsMUC ;
304
    }
285 305

  
286 306
    /**
287 307
     * Get the avatar id of the contact.
......
419 439
     */
420 440
    public Uri toUri(String resource) {
421 441
	StringBuilder build = new StringBuilder("xmpp:");
442
	if (this.isMUC()) {
443
		build.append("$") ;
444
	}
422 445
	String name = StringUtils.parseName(mJID);
423 446
	build.append(name);
424 447
	if (!"".equals(name))
src/com/beem/project/beem/service/Message.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/service/Message.java Sun Feb 27 23:38:33 2011 +0100
90 90
    private String mFrom;
91 91
    private String mThread;
92 92
    private Date mTimestamp;
93
    private boolean mHL ;
93 94

  
94 95
    // TODO ajouter l'erreur
95 96

  
......
106 107
	mThread = "";
107 108
	mFrom = null;
108 109
	mTimestamp = new Date();
110
	mHL = false;
109 111
    }
110 112

  
111 113
    /**
......
143 145
		break;
144 146
	}
145 147
	this.mFrom = smackMsg.getFrom();
148
	mHL = false;
146 149
	//TODO better handling of error messages
147 150
	if (mType == MSG_TYPE_ERROR) {
148 151
	    XMPPError er = smackMsg.getError();
......
176 179
	mThread = in.readString();
177 180
	mFrom = in.readString();
178 181
	mTimestamp = new Date(in.readLong());
182
	mHL = false;
179 183
    }
180 184

  
181 185
    /**
......
316 320
	return 0;
317 321
    }
318 322

  
323
	public void setHL(boolean mHL) {
324
		this.mHL = mHL;
325
	}
326

  
327
	public boolean isHL() {
328
		return mHL;
329
	}
330

  
319 331
}
src/com/beem/project/beem/service/XmppConnectionAdapter.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun Feb 27 23:38:33 2011 +0100
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
import org.jivesoftware.smackx.packet.DiscoverInfo;
59 60

  
60 61
import android.app.Notification;
......
104 105
    private final String mLogin;
105 106
    private final String mPassword;
106 107
    private String mResource;
108
    private String mDefaultNickname;
107 109
    private String mErrorMsg;
108 110
    private RosterAdapter mRoster;
109 111
    private int mPreviousPriority;
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/service/aidl/IChatMUC.aidl Sun Feb 27 23:38:33 2011 +0100
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
}
src/com/beem/project/beem/service/aidl/IChatManager.aidl Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/service/aidl/IChatManager.aidl Sun Feb 27 23:38:33 2011 +0100
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.
src/com/beem/project/beem/service/aidl/IMessageListener.aidl Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/service/aidl/IMessageListener.aidl Sun Feb 27 23:38:33 2011 +0100
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.
src/com/beem/project/beem/ui/Chat.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/ui/Chat.java Sun Feb 27 23:38:33 2011 +0100
65 65
import android.graphics.Bitmap;
66 66
import android.graphics.BitmapFactory;
67 67
import android.graphics.Color;
68
import android.net.Uri;
68 69
import android.os.Bundle;
69 70
import android.os.Handler;
70 71
import android.os.IBinder;
......
96 97
import com.beem.project.beem.service.PresenceAdapter;
97 98
import com.beem.project.beem.service.aidl.IBeemRosterListener;
98 99
import com.beem.project.beem.service.aidl.IChat;
100
import com.beem.project.beem.service.aidl.IChatMUC;
99 101
import com.beem.project.beem.service.aidl.IChatManager;
100 102
import com.beem.project.beem.service.aidl.IChatManagerListener;
101 103
import com.beem.project.beem.service.aidl.IMessageListener;
......
133 135

  
134 136
    private final List<MessageText> mListMessages = new ArrayList<MessageText>();
135 137

  
136
    private IChat mChat;
137 138
    private IChatManager mChatManager;
138 139
    private final IMessageListener mMessageListener = new OnMessageListener();
139 140
    private final IChatManagerListener mChatManagerListener = new ChatManagerListener();
......
215 216
    protected void onPause() {
216 217
	super.onPause();
217 218
	try {
219
		IChat mChat = mChatManager.getChat(mContact) ;
218 220
	    if (mChat != null) {
219 221
		mChat.setOpen(false);
220 222
		mChat.removeMessageListener(mMessageListener);
221 223
	    }
224
	    IChatMUC mChatMUC = mChatManager.getMUCChat(mContact) ;
225
	    if (mChatMUC != null) {
226
		mChatMUC.setOpen(false);
227
		mChatMUC.removeMessageListener(mMessageListener);
228
	    }
222 229
	    if (mRoster != null)
223 230
		mRoster.removeRosterListener(mBeemRosterListener);
224 231
	    if (mChatManager != null)
......
232 239
	}
233 240
	mXmppFacade = null;
234 241
	mRoster = null;
235
	mChat = null;
236 242
	mChatManager = null;
237 243
    }
238 244

  
......
295 301
		break;
296 302
	    case R.id.chat_menu_close_chat:
297 303
		try {
304
			IChat mChat = mChatManager.getChat(mContact) ;
298 305
		    mChatManager.destroyChat(mChat);
306
		    IChatMUC mMUCChat = mChatManager.getMUCChat(mContact) ;
307
		    mChatManager.destroyMUCChat(mMUCChat);
308
		    
299 309
		} catch (RemoteException e) {
300 310
		    Log.e(TAG, e.getMessage());
301 311
		}
......
313 323
     * @throws RemoteException If a Binder remote-invocation error occurred.
314 324
     */
315 325
    private void changeCurrentChat(Contact contact) throws RemoteException {
316
	if (mChat != null) {
317
	    mChat.setOpen(false);
318
	    mChat.removeMessageListener(mMessageListener);
319
	}
320
	mChat = mChatManager.getChat(contact);
321
	if (mChat != null) {
322
	    mChat.setOpen(true);
323
	    mChat.addMessageListener(mMessageListener);
324
	    mChatManager.deleteChatNotification(mChat);
325
	}
326
	mContact = mRoster.getContact(contact.getJID());
327
	String res = contact.getSelectedRes();
328
	if (mContact == null)
329
	    mContact = contact;
330
	if (!"".equals(res)) {
331
	    mContact.setSelectedRes(res);
332
	}
333
	updateContactInformations();
334
	updateContactStatusIcon();
326
	    if (mContact.isMUC()) {
327
	    	IChatMUC mChat = mChatManager.getMUCChat(mContact) ;
328
		    if (mChat != null) {
329
			    mChat.setOpen(false);
330
			    mChat.removeMessageListener(mMessageListener);
331
			}
332
	    } else {
333
	    	IChat mChat = mChatManager.getChat(mContact) ;
334
		    if (mChat != null) {
335
			    mChat.setOpen(false);
336
			    mChat.removeMessageListener(mMessageListener);
337
			}
338
	    }
339
	    
340
	    if (contact.isMUC()) {
341
			IChatMUC newChat = mChatManager.getMUCChat(contact);
342
			if (newChat != null) {
343
			    newChat.setOpen(true);
344
			    newChat.addMessageListener(mMessageListener);
345
			}
346
			mContact = contact;
347
	    } else {
348
			IChat newChat = mChatManager.getChat(contact);
349
			if (newChat != null) {
350
			    newChat.setOpen(true);
351
			    newChat.addMessageListener(mMessageListener);
352
			    mChatManager.deleteChatNotification(newChat);
353
			}
354
			mContact = mRoster.getContact(contact.getJID());
355
	    }
335 356

  
336
	playRegisteredTranscript();
357
		String res = contact.getSelectedRes();
358
		if (mContact == null)
359
		    mContact = contact;
360
		if (!"".equals(res)) {
361
		    mContact.setSelectedRes(res);
362
		}
363
		updateContactInformations();
364
		updateContactStatusIcon();
365
	
366
		playRegisteredTranscript();
337 367
    }
338 368

  
339 369
    /**
......
341 371
     * @throws RemoteException If a Binder remote-invocation error occurred.
342 372
     */
343 373
    private void playRegisteredTranscript() throws RemoteException {
344
	mListMessages.clear();
345
	if (mChat != null) {
346
	    List<MessageText> msgList = convertMessagesList(mChat.getMessages());
347
	    mListMessages.addAll(msgList);
348
	    mMessagesListAdapter.notifyDataSetChanged();
349
	}
374
    	mListMessages.clear();
375
    	List<MessageText> msgList = null ;
376
		if (mContact.isMUC()) {
377
			IChatMUC mChat = mChatManager.getMUCChat(mContact) ;
378
			if (mChat != null) {
379
				msgList = convertMessagesList(mChat.getMessages());
380
			}
381
		} else {
382
			IChat mChat = mChatManager.getChat(mContact) ;
383
			if (mChat != null) {
384
				msgList = convertMessagesList(mChat.getMessages());
385
			}
386

  
387
		}
388
		
389
		if (msgList != null) {
390
		    mListMessages.addAll(msgList);
391
		    mMessagesListAdapter.notifyDataSetChanged();
392
		}
350 393
    }
351 394

  
352 395
    /**
......
365 408
	    String fromBareJid = StringUtils.parseBareAddress(m.getFrom());
366 409
	    if (m.getType() == Message.MSG_TYPE_ERROR) {
367 410
		lastMessage = null;
368
		result.add(new MessageText(fromBareJid, name, m.getBody(), true, m.getTimestamp()));
369
	    } else if (m.getType() == Message.MSG_TYPE_CHAT) {
370
		if (fromBareJid == null) { //nofrom or from == yours
411
		result.add(new MessageText(fromBareJid, name, m.getBody(), true, false, m.getTimestamp()));
412
	    } else if (m.getType() == Message.MSG_TYPE_CHAT || m.getType() == Message.MSG_TYPE_GROUP_CHAT) {
413
		if (m.getType() == Message.MSG_TYPE_GROUP_CHAT) {
414
			name = StringUtils.parseResource(m.getFrom());
415
		}
416
	    	
417
	    if (fromBareJid == null) { //nofrom or from == yours
371 418
		    name = localName;
372 419
		    fromBareJid = "";
373 420
		}
374 421

  
375 422
		if (m.getBody() != null) {
376
		    if (lastMessage == null || !fromBareJid.equals(lastMessage.getBareJid())) {
377
			lastMessage = new MessageText(fromBareJid, name, m.getBody(), false, m.getTimestamp());
378
			result.add(lastMessage);
379
		    } else {
380
			lastMessage.setMessage(lastMessage.getMessage().concat("\n" + m.getBody()));
423
			if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid) && lastMessage.getName().equals(name)) {
424
		    	if (m.isHL()) {
425
		    		lastMessage.setHL(true) ;
426
		    	}
427
				lastMessage.setMessage(lastMessage.getMessage().concat("\n" + m.getBody()));
428
			} else {
429
				lastMessage = new MessageText(fromBareJid, name, m.getBody(), false, m.isHL(), m.getTimestamp());
430
				result.add(lastMessage);
381 431
		    }
382 432
		}
383 433
	    }
......
411 461
		    mChatManager.addChatCreationListener(mChatManagerListener);
412 462
		    changeCurrentChat(mContact);
413 463
		}
464
		if (mContact!= null && mContact.isMUC()) {
465
			IChatMUC muc = mChatManager.getMUCChat(mContact) ;
466
			if (muc == null) {
467
				Log.d(TAG,"Service connected : "+mContact.getJIDWithRes()) ;
468
				IChatMUC mChatMUC = mChatManager.createMUCChat(mContact, mMessageListener) ;
469
				mChatMUC.addMessageListener(mMessageListener) ;
470
				mChatMUC.setOpen(true);
471
			}
472
		}
473

  
414 474
	    } catch (RemoteException e) {
415
		Log.e(TAG, e.getMessage());
475
	    	Log.e(TAG, e.getMessage());
416 476
	    }
477
	    
417 478
	}
418 479

  
419 480
	/**
......
507 568
		    public void run() {
508 569
			if (msg.getType() == Message.MSG_TYPE_ERROR) {
509 570
			    mListMessages.add(new MessageText(fromBareJid, mContact.getName(),
510
				msg.getBody(), true, msg.getTimestamp()));
571
				msg.getBody(), true, false, msg.getTimestamp()));
511 572
			    mMessagesListAdapter.notifyDataSetChanged();
512 573
			} else if (msg.getBody() != null) {
513 574
			    MessageText lastMessage = null;
514 575
			    if (mListMessages.size() != 0)
515 576
				lastMessage = mListMessages.get(mListMessages.size() - 1);
516 577

  
517
			    if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid)) {
518
				lastMessage.setMessage(lastMessage.getMessage().concat("\n" + msg.getBody()));
519
				lastMessage.setTimestamp(msg.getTimestamp());
520
				mListMessages.set(mListMessages.size() - 1, lastMessage);
521
			    } else if (msg.getBody() != null)
522
				mListMessages.add(new MessageText(fromBareJid, mContact.getName(),
523
				    msg.getBody(), false, msg.getTimestamp()));
524
			    mMessagesListAdapter.notifyDataSetChanged();
525
			}
578
               String name ;
579
               if (mContact.isMUC()) {
580
                   name = StringUtils.parseResource(msg.getFrom());
581
               } else {
582
                   name = mContact.getName();
583
               }
584

  
585
               if (lastMessage != null && lastMessage.getBareJid().equals(fromBareJid) && lastMessage.getName().equals(name)) {
586
			    	if (msg.isHL()) {
587
			    		lastMessage.setHL(true) ;
588
			    	}
589
					lastMessage.setMessage(lastMessage.getMessage().concat("\n" + msg.getBody()));
590
                    lastMessage.setTimestamp(msg.getTimestamp());
591
                    mListMessages.set(mListMessages.size() - 1, lastMessage);
592
                } else if (msg.getBody() != null) {
593
			    	mListMessages.add(new MessageText(fromBareJid, name, msg.getBody(), false, msg.isHL(), msg.getTimestamp()));
594
                    mMessagesListAdapter.notifyDataSetChanged();
595
                }
526 596
		    }
527
		});
597
		}
598
	    });
528 599
	    }
529
	}
600
    }
601

  
602
    @Override
603
    public void processMUCMessage(IChatMUC chat, final Message msg) throws RemoteException {
604
        processMessage(null, msg) ;
605
    }
606

  
530 607

  
531 608
	/**
532 609
	 * {@inheritDoc}.
......
697 774
		TextView msgName = (TextView) sv.findViewById(R.id.chatmessagename);
698 775
		msgName.setText(msg.getName());
699 776
		msgName.setTextColor(Color.WHITE);
777
	    if (msg.isHL()) {
778
	    	msgName.setTextColor(Color.RED);
779
	    } else {
780
	    	msgName.setTextColor(Color.WHITE);
781
	    }
700 782
		msgName.setError(null);
701 783
		TextView msgText = (TextView) sv.findViewById(R.id.chatmessagetext);
702 784
		msgText.setText(msg.getMessage());
......
727 809
	private String mName;
728 810
	private String mMessage;
729 811
	private boolean mIsError;
812
	private boolean mHL;
730 813
	private Date mTimestamp;
731 814

  
732 815
	/**
......
765 848
	 * @param isError if the message is an error message.
766 849
	 * @param date the time of the message.
767 850
	 */
768
	public MessageText(final String bareJid, final String name, final String message,
769
	    final boolean isError, Date date) {
851
	public MessageText(final String bareJid, final String name, final String message, final boolean isError, final boolean isHL, Date date) {
770 852
	    mBareJid = bareJid;
771 853
	    mName = name;
772 854
	    mMessage = message;
773 855
	    mIsError = isError;
856
	    mHL = isHL ;
774 857
	    mTimestamp = date;
775 858
	}
776 859

  
......
831 914
	public boolean isError() {
832 915
	    return mIsError;
833 916
	}
917
	
918
	public boolean isHL() {
919
		return mHL; 
920
	}
921
	
922
	public void setHL(boolean hl) {
923
		mHL = hl ;
924
	}
834 925

  
835 926
	/**
836 927
	 * Set the Date of the message.
......
874 965
	final String inputContent = mInputField.getText().toString();
875 966

  
876 967
	if (!"".equals(inputContent)) {
877
	    Message msgToSend = new Message(mContact.getJIDWithRes(), Message.MSG_TYPE_CHAT);
968
		Message msgToSend ;
969
		if (mContact.isMUC()) {
970
			msgToSend = new Message(mContact.getJID(), Message.MSG_TYPE_GROUP_CHAT);	
971
		} else {
972
			msgToSend = new Message(mContact.getJIDWithRes(), Message.MSG_TYPE_CHAT);
973
		}
974
	    
878 975
	    msgToSend.setBody(inputContent);
879 976

  
880 977
	    try {
881
		if (mChat == null) {
882
		    mChat = mChatManager.createChat(mContact, mMessageListener);
883
		    mChat.setOpen(true);
884
		}
885
		mChat.sendMessage(msgToSend);
978
	    	if (mContact.isMUC()) {
979
	    		IChatMUC mChatMUC = mChatManager.getMUCChat(mContact) ;
980
				mChatMUC.sendMessage(msgToSend);
981
	    	} else {
982
	    		IChat mChat = mChatManager.getChat(mContact) ;
983
				if (mChat == null) {
984
				    mChat = mChatManager.createChat(mContact, mMessageListener);
985
				    mChat.setOpen(true);
986
				}
987
				mChat.sendMessage(msgToSend);
988
			    final String self = getString(R.string.chat_self);
989
			    MessageText lastMessage = null;
990
			    if (mListMessages.size() != 0)
991
				lastMessage = mListMessages.get(mListMessages.size() - 1);
992
	
993
			    if (lastMessage != null && lastMessage.getName().equals(self)) {
994
			    	lastMessage.setMessage(lastMessage.getMessage().concat("\n" + inputContent));
995
			    	lastMessage.setTimestamp(new Date());
996
			    } else {
997
			    	mListMessages.add(new MessageText(self, self, inputContent, false, false, new Date()));
998
			    }
999
	    	}
886 1000
	    } catch (RemoteException e) {
887 1001
		Log.e(TAG, e.getMessage());
888 1002
	    }
889 1003

  
890
	    final String self = getString(R.string.chat_self);
891
	    MessageText lastMessage = null;
892
	    if (mListMessages.size() != 0)
893
		lastMessage = mListMessages.get(mListMessages.size() - 1);
894 1004

  
895
	    if (lastMessage != null && lastMessage.getName().equals(self)) {
896
		lastMessage.setMessage(lastMessage.getMessage().concat("\n" + inputContent));
897
		lastMessage.setTimestamp(new Date());
898
	    } else
899
		mListMessages.add(new MessageText(self, self, inputContent, false, new Date()));
900 1005
	    mMessagesListAdapter.notifyDataSetChanged();
901 1006
	    mInputField.setText(null);
902 1007
	}
......
922 1027
		String chatJid = chat.getParticipant().getJIDWithRes();
923 1028
		if (chatJid.equals(contactJid)) {
924 1029
		    // This should not be happened but to be sure
1030
			IChat mChat = mChatManager.getChat(mContact) ;
925 1031
		    if (mChat != null) {
926 1032
			mChat.setOpen(false);
927 1033
			mChat.removeMessageListener(mMessageListener);
src/com/beem/project/beem/ui/ContactList.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/ui/ContactList.java Sun Feb 27 23:38:33 2011 +0100
98 98
import com.beem.project.beem.ui.dialogs.builders.Alias;
99 99
import com.beem.project.beem.ui.dialogs.builders.ChatList;
100 100
import com.beem.project.beem.ui.dialogs.builders.DeleteContact;
101
import com.beem.project.beem.ui.dialogs.builders.JoinMUC;
101 102
import com.beem.project.beem.ui.dialogs.builders.ResendSubscription;
102 103
import com.beem.project.beem.utils.BeemBroadcastReceiver;
103 104
import com.beem.project.beem.utils.SortedList;
......
185 186
	    case R.id.menu_disconnect:
186 187
		stopService(SERVICE_INTENT);
187 188
		finish();
189
	    case R.id.muc:
190
	    	Dialog joinmuc = new JoinMUC(ContactList.this).create() ;
191
	    	joinmuc.show() ;
192
		    return true;
188 193
	    default:
189 194
		return false;
190 195
	}
......
262 267
		    delete.show();
263 268
		    result = true;
264 269
		    break;
270
		case R.id.contact_list_context_menu_joinasmuc_item :
271
		    Contact c = new Contact(mSelectedContact.getJID(), true);
272
		    Intent i = new Intent(ContactList.this, Chat.class);
273
		    i.setData(c.toUri(mSettings.getString("settings_key_nickname", "BeemGuest")));
274
		    startActivity(i);
275
			result=true;
276
			break;
265 277
		default:
266 278
		    result = super.onContextItemSelected(item);
267 279
		    break;
src/com/beem/project/beem/ui/dialogs/builders/ChatList.java Mon Jan 31 20:01:33 2011 +0100 → src/com/beem/project/beem/ui/dialogs/builders/ChatList.java Sun Feb 27 23:38:33 2011 +0100
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() {
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/ui/dialogs/builders/JoinMUC.java Sun Feb 27 23:38:33 2011 +0100
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);
... This diff was truncated because it exceeds the maximum size that can be displayed.
(3-3/5)