author | Nikita Kozlov <nikita@beem-project.com> |
Wed, 25 May 2011 01:31:07 +0200 | |
changeset 912 | 5441ea00c4f1 |
parent 902 | c2eb19cd7032 |
child 916 | 211f45e7bbd3 |
permissions | -rwxr-xr-x |
577 | 1 |
/* |
567 | 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, |
|
577 | 9 |
Vincent Veronis. |
567 | 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 |
||
577 | 29 |
Epitech, hereby disclaims all copyright interest in the program "Beem" |
567 | 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 |
||
897 | 43 |
*/ |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
44 |
package com.beem.project.beem.service; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
45 |
|
842 | 46 |
import java.io.File; |
47 |
import java.io.FileWriter; |
|
48 |
import java.io.IOException; |
|
219
79ccbe331695
Les conversations sont retenues dans les chats du service.
Da Risk <darisk972@gmail.com>
parents:
186
diff
changeset
|
49 |
import java.util.Collections; |
79ccbe331695
Les conversations sont retenues dans les chats du service.
Da Risk <darisk972@gmail.com>
parents:
186
diff
changeset
|
50 |
import java.util.LinkedList; |
79ccbe331695
Les conversations sont retenues dans les chats du service.
Da Risk <darisk972@gmail.com>
parents:
186
diff
changeset
|
51 |
import java.util.List; |
79ccbe331695
Les conversations sont retenues dans les chats du service.
Da Risk <darisk972@gmail.com>
parents:
186
diff
changeset
|
52 |
|
815
ca323cff3ac9
I have reimplemented the BeemOtrService in a more "centralized" way.
Nikita Kozlov <nikita@mbdsys.com>
parents:
813
diff
changeset
|
53 |
import net.java.otr4j.OtrException; |
813
bcafceecd837
adding otr status listener
Nikita Kozlov <nikita@mbdsys.com>
parents:
810
diff
changeset
|
54 |
import net.java.otr4j.session.SessionID; |
bcafceecd837
adding otr status listener
Nikita Kozlov <nikita@mbdsys.com>
parents:
810
diff
changeset
|
55 |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
56 |
import org.jivesoftware.smack.Chat; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
57 |
import org.jivesoftware.smack.XMPPException; |
842 | 58 |
import org.jivesoftware.smack.util.StringUtils; |
810
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
714
diff
changeset
|
59 |
import org.jivesoftware.smackx.ChatState; |
584
72d9d76900af
Fix many bugs and memory leak
Da Risk <darisk972@gmail.com>
parents:
583
diff
changeset
|
60 |
import org.jivesoftware.smackx.ChatStateListener; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
61 |
|
842 | 62 |
import android.os.Environment; |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
63 |
import android.os.RemoteCallbackList; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
64 |
import android.os.RemoteException; |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
65 |
import android.util.Log; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
66 |
|
815
ca323cff3ac9
I have reimplemented the BeemOtrService in a more "centralized" way.
Nikita Kozlov <nikita@mbdsys.com>
parents:
813
diff
changeset
|
67 |
import com.beem.project.beem.otr.BeemOtrManager; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
68 |
import com.beem.project.beem.service.aidl.IChat; |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
69 |
import com.beem.project.beem.service.aidl.IMessageListener; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
70 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
71 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
72 |
* An adapter for smack's Chat class. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
73 |
* @author darisk |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
74 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
75 |
public class ChatAdapter extends IChat.Stub { |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
76 |
private static final int HISTORY_MAX_SIZE = 50; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
77 |
private static final String TAG = "ChatAdapter"; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
78 |
private static final String PROTOCOL = "XMPP"; |
819 | 79 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
80 |
private final Chat mAdaptee; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
81 |
private final Contact mParticipant; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
82 |
private String mState; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
83 |
private boolean mIsOpen; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
84 |
private final List<Message> mMessages; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
85 |
private final RemoteCallbackList<IMessageListener> mRemoteListeners = new RemoteCallbackList<IMessageListener>(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
86 |
private final MsgListener mMsgListener = new MsgListener(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
87 |
private SessionID mOtrSessionId; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
88 |
private boolean mIsHistory; |
870 | 89 |
private File mHistoryPath; |
842 | 90 |
private String mAccountUser; |
474 | 91 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
92 |
/** |
897 | 93 |
* Constructor. |
94 |
* @param chat The chat to adapt |
|
95 |
*/ |
|
96 |
public ChatAdapter(final Chat chat) { |
|
97 |
mAdaptee = chat; |
|
98 |
mParticipant = new Contact(chat.getParticipant()); |
|
99 |
mMessages = new LinkedList<Message>(); |
|
100 |
mAdaptee.addMessageListener(mMsgListener); |
|
101 |
} |
|
451 | 102 |
|
897 | 103 |
/** |
104 |
* {@inheritDoc} |
|
105 |
*/ |
|
106 |
@Override |
|
107 |
public Contact getParticipant() throws RemoteException { |
|
108 |
return mParticipant; |
|
109 |
} |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
110 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
111 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
112 |
* {@inheritDoc} |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
113 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
114 |
@Override |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
115 |
public void sendMessage(com.beem.project.beem.service.Message message) throws RemoteException { |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
116 |
sendMessage(message, true); |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
117 |
} |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
118 |
|
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
119 |
/** |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
120 |
* private method for sending message. |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
121 |
* @param message the message to send |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
122 |
* @param log do we want to log (in memory and history) the message? |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
123 |
*/ |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
124 |
private void sendMessage(com.beem.project.beem.service.Message message, boolean log) { |
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
125 |
org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message(); |
895 | 126 |
String msgBody = message.getBody(); |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
127 |
String otrBody = null; |
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
128 |
send.setTo(message.getTo()); |
895 | 129 |
Log.w(TAG, "message to " + message.getTo()); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
130 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
131 |
if (mOtrSessionId != null) { |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
132 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
133 |
try { |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
134 |
otrBody = BeemOtrManager.getInstance().getOtrManager().transformSending(mOtrSessionId, msgBody); |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
135 |
send.setBody(otrBody); |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
136 |
} catch (OtrException e) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
137 |
e.printStackTrace(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
138 |
} |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
139 |
} else { |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
140 |
send.setBody(msgBody); |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
141 |
otrBody = msgBody; |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
142 |
} |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
143 |
|
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
144 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
145 |
send.setThread(message.getThread()); |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
146 |
send.setSubject(message.getSubject()); |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
147 |
send.setType(org.jivesoftware.smack.packet.Message.Type.chat); |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
148 |
// TODO gerer les messages contenant des XMPPError |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
149 |
// send.set |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
150 |
try { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
151 |
mAdaptee.sendMessage(send); |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
152 |
if (log && otrBody != null) |
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
153 |
mMessages.add(message); |
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
154 |
} catch (XMPPException e) { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
155 |
e.printStackTrace(); |
810
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
714
diff
changeset
|
156 |
} |
870 | 157 |
String state = Environment.getExternalStorageState(); |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
158 |
if (log && mIsHistory && Environment.MEDIA_MOUNTED.equals(state)) |
870 | 159 |
saveHistory(message, mAccountUser); |
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
160 |
} |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
161 |
|
898 | 162 |
/** |
163 |
* send message. |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
164 |
* @param msg to send. |
898 | 165 |
*/ |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
166 |
public void sendMessage(String msg) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
167 |
Message msgToSend = new Message(mParticipant.getJIDWithRes(), Message.MSG_TYPE_CHAT); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
168 |
msgToSend.setBody(msg); |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
169 |
sendMessage(msgToSend, false); |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
170 |
} |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
171 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
172 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
173 |
* {@inheritDoc} |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
174 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
175 |
@Override |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
176 |
public void addMessageListener(IMessageListener listen) { |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
177 |
if (listen != null) |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
178 |
mRemoteListeners.register(listen); |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
179 |
} |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
180 |
|
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
181 |
/** |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
182 |
* {@inheritDoc} |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
183 |
*/ |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
184 |
@Override |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
185 |
public void removeMessageListener(IMessageListener listen) { |
584
72d9d76900af
Fix many bugs and memory leak
Da Risk <darisk972@gmail.com>
parents:
583
diff
changeset
|
186 |
if (listen != null) { |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
187 |
mRemoteListeners.unregister(listen); |
819 | 188 |
} |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
189 |
} |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
190 |
|
895 | 191 |
|
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
192 |
/** |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
193 |
* {@inheritDoc} |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
194 |
*/ |
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
195 |
@Override |
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
196 |
public String getState() throws RemoteException { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
197 |
return mState; |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
198 |
} |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
199 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
200 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
201 |
* {@inheritDoc} |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
202 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
203 |
@Override |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
204 |
public void setState(String state) throws RemoteException { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
205 |
mState = state; |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
206 |
} |
99 | 207 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
208 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
209 |
* Get the adaptee for the Chat. |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
210 |
* @return The real chat object |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
211 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
212 |
public Chat getAdaptee() { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
213 |
return mAdaptee; |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
214 |
} |
186 | 215 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
216 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
217 |
* {@inheritDoc} |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
218 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
219 |
@Override |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
220 |
public void setOpen(boolean isOpen) { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
221 |
this.mIsOpen = isOpen; |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
222 |
} |
219
79ccbe331695
Les conversations sont retenues dans les chats du service.
Da Risk <darisk972@gmail.com>
parents:
186
diff
changeset
|
223 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
224 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
225 |
* {@inheritDoc} |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
226 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
227 |
@Override |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
228 |
public boolean isOpen() { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
229 |
return mIsOpen; |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
230 |
} |
186 | 231 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
232 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
233 |
* {@inheritDoc} |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
234 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
235 |
@Override |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
236 |
public List<Message> getMessages() throws RemoteException { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
237 |
return Collections.unmodifiableList(mMessages); |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
238 |
} |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
239 |
|
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
240 |
/** |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
241 |
* Add a message in the chat history. |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
242 |
* @param msg the message to add |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
243 |
*/ |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
244 |
void addMessage(Message msg) { |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
245 |
if (mMessages.size() == HISTORY_MAX_SIZE) |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
246 |
mMessages.remove(0); |
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
247 |
mMessages.add(msg); |
842 | 248 |
if (!"".equals(msg.getBody()) && msg.getBody() != null) { |
870 | 249 |
String state = Environment.getExternalStorageState(); |
250 |
if (mIsHistory && Environment.MEDIA_MOUNTED.equals(state)) |
|
251 |
saveHistory(msg, msg.getFrom()); |
|
842 | 252 |
} |
503
93e5d2d9953f
Le formatter a encore frappé.
Jean-Manuel ¨dasilvj¨ Da Silva
parents:
501
diff
changeset
|
253 |
} |
219
79ccbe331695
Les conversations sont retenues dans les chats du service.
Da Risk <darisk972@gmail.com>
parents:
186
diff
changeset
|
254 |
|
588 | 255 |
/** |
843 | 256 |
* Save message in SDCard. |
842 | 257 |
* @param msg the message receive |
843 | 258 |
* @param contactName the name of the contact |
844 | 259 |
*/ |
842 | 260 |
public void saveHistory(Message msg, String contactName) { |
870 | 261 |
File path = getHistoryPath(); |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
262 |
File filepath; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
263 |
if (contactName.equals(msg.getFrom())) |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
264 |
filepath = new File(path, StringUtils.parseBareAddress(contactName)); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
265 |
else |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
266 |
filepath = new File(path, StringUtils.parseBareAddress(msg.getTo())); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
267 |
path.mkdirs(); |
870 | 268 |
try { |
269 |
FileWriter file = new FileWriter(filepath, true); |
|
270 |
String log = msg.getTimestamp() + " " + contactName + " " + msg.getBody() |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
271 |
+ System.getProperty("line.separator"); |
870 | 272 |
file.write(log); |
273 |
file.close(); |
|
274 |
} catch (IOException e) { |
|
275 |
Log.e(TAG, "Error writing chat history", e); |
|
819 | 276 |
} |
842 | 277 |
} |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
278 |
|
842 | 279 |
/** |
870 | 280 |
* set History enable/disable. |
844 | 281 |
* @param isHisory history state |
842 | 282 |
*/ |
870 | 283 |
public void setHistory(boolean isHisory) { |
284 |
this.mIsHistory = isHisory; |
|
842 | 285 |
} |
286 |
||
287 |
/** |
|
843 | 288 |
* get History state. |
289 |
* @return mIsHistory |
|
842 | 290 |
*/ |
870 | 291 |
public boolean getHistory() { |
292 |
return mIsHistory; |
|
842 | 293 |
} |
294 |
||
843 | 295 |
/** |
296 |
* Set Account user name. |
|
297 |
* @param accountUser user name |
|
298 |
*/ |
|
842 | 299 |
public void setAccountUser(String accountUser) { |
300 |
mAccountUser = accountUser; |
|
301 |
} |
|
843 | 302 |
|
303 |
/** |
|
304 |
* get Account user name. |
|
305 |
* @return mAccountUser |
|
306 |
*/ |
|
842 | 307 |
public String getAccountUser() { |
308 |
return mAccountUser; |
|
309 |
} |
|
843 | 310 |
|
842 | 311 |
/** |
872 | 312 |
* set History path. |
313 |
* @param historyPath history path |
|
870 | 314 |
*/ |
872 | 315 |
public void setHistoryPath(File historyPath) { |
316 |
this.mHistoryPath = historyPath; |
|
870 | 317 |
} |
318 |
||
319 |
/** |
|
872 | 320 |
* get History path. |
870 | 321 |
* @return mHistoryPath; |
322 |
*/ |
|
323 |
public File getHistoryPath() { |
|
324 |
return mHistoryPath; |
|
325 |
} |
|
326 |
||
327 |
/** |
|
588 | 328 |
* Listener. |
329 |
*/ |
|
704
e310d3275d5d
Finish reception of Chat State message.
Da Risk <darisk972@gmail.com>
parents:
622
diff
changeset
|
330 |
private class MsgListener implements ChatStateListener { |
819 | 331 |
/** |
599 | 332 |
* Constructor. |
584
72d9d76900af
Fix many bugs and memory leak
Da Risk <darisk972@gmail.com>
parents:
583
diff
changeset
|
333 |
*/ |
895 | 334 |
public MsgListener() { } |
819 | 335 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
336 |
@Override |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
337 |
public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message message) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
338 |
Message msg = new Message(message); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
339 |
Log.d(TAG, "new msg " + msg.getBody()); |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
340 |
String body; |
819 | 341 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
342 |
if (mOtrSessionId != null) { |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
343 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
344 |
try { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
345 |
body = BeemOtrManager.getInstance().getOtrManager().transformReceiving(mOtrSessionId, msg.getBody()); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
346 |
msg.setBody(body); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
347 |
} catch (OtrException e) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
348 |
e.printStackTrace(); |
819 | 349 |
} |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
350 |
} |
819 | 351 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
352 |
//TODO add que les message pas de type errors |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
353 |
ChatAdapter.this.addMessage(msg); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
354 |
final int n = mRemoteListeners.beginBroadcast(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
355 |
for (int i = 0; i < n; i++) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
356 |
IMessageListener listener = mRemoteListeners.getBroadcastItem(i); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
357 |
try { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
358 |
if (listener != null) |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
359 |
listener.processMessage(ChatAdapter.this, msg); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
360 |
} catch (RemoteException e) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
361 |
Log.w(TAG, "Error while diffusing message to listener", e); |
819 | 362 |
} |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
363 |
} |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
364 |
mRemoteListeners.finishBroadcast(); |
819 | 365 |
} |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
366 |
|
819 | 367 |
/** |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
368 |
* {@inheritDoc} |
813
bcafceecd837
adding otr status listener
Nikita Kozlov <nikita@mbdsys.com>
parents:
810
diff
changeset
|
369 |
*/ |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
370 |
@Override |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
371 |
public void stateChanged(Chat chat, ChatState state) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
372 |
mState = state.name(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
373 |
final int n = mRemoteListeners.beginBroadcast(); |
813
bcafceecd837
adding otr status listener
Nikita Kozlov <nikita@mbdsys.com>
parents:
810
diff
changeset
|
374 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
375 |
for (int i = 0; i < n; i++) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
376 |
IMessageListener listener = mRemoteListeners.getBroadcastItem(i); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
377 |
try { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
378 |
listener.stateChanged(ChatAdapter.this); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
379 |
} catch (RemoteException e) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
380 |
Log.w(TAG, e.getMessage()); |
813
bcafceecd837
adding otr status listener
Nikita Kozlov <nikita@mbdsys.com>
parents:
810
diff
changeset
|
381 |
} |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
382 |
} |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
383 |
mRemoteListeners.finishBroadcast(); |
810
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
714
diff
changeset
|
384 |
} |
819 | 385 |
|
386 |
||
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
387 |
} |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
388 |
/** |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
389 |
* This method is executed when the otr session status change. |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
390 |
* @param otrState the new state of otr session. |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
391 |
*/ |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
392 |
public void otrStateChanged(final String otrState) { |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
393 |
final int n = mRemoteListeners.beginBroadcast(); |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
394 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
395 |
for (int i = 0; i < n; i++) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
396 |
IMessageListener listener = mRemoteListeners.getBroadcastItem(i); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
397 |
try { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
398 |
listener.otrStateChanged(otrState); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
399 |
} catch (RemoteException e) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
400 |
Log.w(TAG, e.getMessage()); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
401 |
} |
810
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
714
diff
changeset
|
402 |
} |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
403 |
mRemoteListeners.finishBroadcast(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
404 |
} |
819 | 405 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
406 |
|
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
407 |
@Override |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
408 |
public void startOtrSession() throws RemoteException { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
409 |
if (mOtrSessionId != null) |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
410 |
return; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
411 |
|
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
412 |
mOtrSessionId = new SessionID(mParticipant.getJIDWithRes(), mParticipant.getJID(), PROTOCOL); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
413 |
try { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
414 |
BeemOtrManager.getInstance().addChat(mOtrSessionId, this); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
415 |
BeemOtrManager.getInstance().getOtrManager().startSession(mOtrSessionId); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
416 |
} catch (OtrException e) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
417 |
mOtrSessionId = null; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
418 |
e.printStackTrace(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
419 |
throw new RemoteException(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
420 |
} |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
421 |
} |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
422 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
423 |
@Override |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
424 |
public void endOtrSession() throws RemoteException { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
425 |
try { |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
426 |
localEndOtrSession(); |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
427 |
} catch (OtrException e) { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
428 |
e.printStackTrace(); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
429 |
throw new RemoteException(); |
819 | 430 |
} |
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
431 |
} |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
432 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
433 |
/** |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
434 |
* end an Otr session. |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
435 |
* @return false if something bad happened. |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
436 |
*/ |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
437 |
public boolean localEndOtrSession() throws OtrException { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
438 |
if (mOtrSessionId == null) |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
439 |
return true; |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
440 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
441 |
BeemOtrManager.getInstance().getOtrManager().endSession(mOtrSessionId); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
442 |
BeemOtrManager.getInstance().removeChat(mOtrSessionId); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
443 |
mOtrSessionId = null; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
444 |
return true; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
445 |
} |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
446 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
447 |
@Override |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
448 |
public void listenOtrSession() throws RemoteException { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
449 |
if (mOtrSessionId != null) |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
450 |
return; |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
451 |
|
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
452 |
mOtrSessionId = new SessionID(mParticipant.getJIDWithRes(), mParticipant.getJID(), PROTOCOL); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
453 |
BeemOtrManager.getInstance().addChat(mOtrSessionId, this); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
454 |
//OtrEngineImpl will make a call to "this.getSession(sessionID)" which will instantiate our session. |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
455 |
BeemOtrManager.getInstance().getOtrManager().getSessionStatus(mOtrSessionId); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
456 |
|
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
457 |
} |
816
bf953743f5a1
rewrite BeemOtrManager as a singleton and merge it with BeemOtrEngineHostImpl
Nikita Kozlov <nikita@mbdsys.com>
parents:
815
diff
changeset
|
458 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
459 |
@Override |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
460 |
public String getLocalOtrFingerprint() throws RemoteException { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
461 |
if (mOtrSessionId == null) |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
462 |
return null; |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
463 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
464 |
return BeemOtrManager.getInstance().getLocalFingerprint(mOtrSessionId); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
465 |
} |
819 | 466 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
467 |
@Override |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
468 |
public String getRemoteOtrFingerprint() throws RemoteException { |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
469 |
if (mOtrSessionId == null) |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
470 |
return null; |
902
c2eb19cd7032
fix otr message in history
Nikita Kozlov <nikita@beem-project.com>
parents:
900
diff
changeset
|
471 |
|
900
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
472 |
return BeemOtrManager.getInstance().getRemoteFingerprint(mOtrSessionId); |
ab30d289a86c
adding a keystore for otr, adding buttons which display fingerprints
Nikita Kozlov <nikita@beem-project.com>
parents:
899
diff
changeset
|
473 |
} |
912
5441ea00c4f1
check otr status when openning a new chat
Nikita Kozlov <nikita@beem-project.com>
parents:
902
diff
changeset
|
474 |
|
5441ea00c4f1
check otr status when openning a new chat
Nikita Kozlov <nikita@beem-project.com>
parents:
902
diff
changeset
|
475 |
@Override |
5441ea00c4f1
check otr status when openning a new chat
Nikita Kozlov <nikita@beem-project.com>
parents:
902
diff
changeset
|
476 |
public String getOtrStatus() throws RemoteException { |
5441ea00c4f1
check otr status when openning a new chat
Nikita Kozlov <nikita@beem-project.com>
parents:
902
diff
changeset
|
477 |
if (mOtrSessionId == null) |
5441ea00c4f1
check otr status when openning a new chat
Nikita Kozlov <nikita@beem-project.com>
parents:
902
diff
changeset
|
478 |
return null; |
5441ea00c4f1
check otr status when openning a new chat
Nikita Kozlov <nikita@beem-project.com>
parents:
902
diff
changeset
|
479 |
return BeemOtrManager.getInstance().getOtrManager().getSessionStatus(mOtrSessionId).toString(); |
5441ea00c4f1
check otr status when openning a new chat
Nikita Kozlov <nikita@beem-project.com>
parents:
902
diff
changeset
|
480 |
} |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
481 |
} |
583
ca7bec1b5754
Add methods for managing MessageListeners in the Chat adapter.
Da Risk <darisk972@gmail.com>
parents:
577
diff
changeset
|
482 |