author | nikita@nikita-lab |
Sat, 16 May 2009 22:59:02 +0200 | |
changeset 186 | 7aec70b9ca79 |
parent 178 | 393009fc8265 |
child 187 | ce342bfa7bdb |
permissions | -rw-r--r-- |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
1 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
2 |
* |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
3 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
4 |
package com.beem.project.beem.service; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
5 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
6 |
import java.util.HashMap; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
7 |
import java.util.Map; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
8 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
9 |
import org.jivesoftware.smack.Chat; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
10 |
import org.jivesoftware.smack.ChatManager; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
11 |
import org.jivesoftware.smack.ChatManagerListener; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
12 |
import org.jivesoftware.smack.MessageListener; |
75 | 13 |
import org.jivesoftware.smack.packet.Message; |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
14 |
import org.jivesoftware.smack.util.StringUtils; |
99 | 15 |
import org.jivesoftware.smackx.ChatState; |
16 |
import org.jivesoftware.smackx.ChatStateListener; |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
17 |
|
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
18 |
import android.app.Notification; |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
19 |
import android.app.PendingIntent; |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
20 |
import android.content.Intent; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
21 |
import android.os.RemoteCallbackList; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
22 |
import android.os.RemoteException; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
23 |
import android.util.Log; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
24 |
|
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
25 |
import com.beem.project.beem.BeemService; |
178 | 26 |
import com.beem.project.beem.R; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
27 |
import com.beem.project.beem.service.aidl.IChat; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
28 |
import com.beem.project.beem.service.aidl.IChatManager; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
29 |
import com.beem.project.beem.service.aidl.IChatManagerListener; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
30 |
import com.beem.project.beem.service.aidl.IMessageListener; |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
31 |
import com.beem.project.beem.ui.SendIM; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
32 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
33 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
34 |
* An adapter for smack's ChatManager. This class provides functionnality to handle chats. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
35 |
* @author darisk |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
36 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
37 |
public class BeemChatManager extends IChatManager.Stub { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
38 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
39 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
40 |
* Tag to use with log methods. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
41 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
42 |
public static final String TAG = "BeemChatManager"; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
43 |
private ChatManager mAdaptee; |
186 | 44 |
private Map<String, ChatAdapter> mChats = new HashMap<String, ChatAdapter>(); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
45 |
private ChatListener mChatListener = new ChatListener(); |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
46 |
private RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners = new RemoteCallbackList<IChatManagerListener>(); |
75 | 47 |
private RemoteCallbackList<IMessageListener> mRemoteMessageListeners = new RemoteCallbackList<IMessageListener>(); |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
48 |
private BeemService mService; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
49 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
50 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
51 |
* Constructor. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
52 |
* @param chatManager the smack ChatManager to adapt |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
53 |
*/ |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
54 |
public BeemChatManager(final ChatManager chatManager, BeemService service) { |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
55 |
mService = service; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
56 |
mAdaptee = chatManager; |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
57 |
mAdaptee.addChatListener(mChatListener); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
58 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
59 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
60 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
61 |
* Create a chat session. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
62 |
* @param jid the jid of the contact you want to chat with |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
63 |
* @param listener listener to use for chat events on this chat session |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
64 |
* @return the chat session |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
65 |
*/ |
75 | 66 |
public IChat createChat(String jid, IMessageListener listener) { |
67 |
mRemoteMessageListeners.register(listener); |
|
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
68 |
String key = StringUtils.parseBareAddress(jid); |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
69 |
if (mChats.containsKey(key)) { |
186 | 70 |
return (mChats.get(key)); |
75 | 71 |
} |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
72 |
// create the chat. the adaptee will be add automatically in the map |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
73 |
mAdaptee.createChat(key, mChatListener); |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
74 |
return mChats.get(key); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
75 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
76 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
77 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
78 |
* Create a chat session. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
79 |
* @param contact the contact you want to chat with |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
80 |
* @param listener listener to use for chat events on this chat session |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
81 |
* @return the chat session |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
82 |
*/ |
75 | 83 |
public IChat createChat(Contact contact, IMessageListener listener) { |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
84 |
String jid = contact.getJID(); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
85 |
return createChat(jid, listener); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
86 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
87 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
88 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
89 |
* {@inheritDoc} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
90 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
91 |
@Override |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
92 |
public void addChatCreationListener(IChatManagerListener listener) throws RemoteException { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
93 |
mRemoteChatCreationListeners.register(listener); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
94 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
95 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
96 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
97 |
* {@inheritDoc} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
98 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
99 |
@Override |
75 | 100 |
public void removeChatCreationListener(IChatManagerListener listener) throws RemoteException { |
101 |
mRemoteChatCreationListeners.unregister(listener); |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
102 |
} |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
103 |
|
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
104 |
/** |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
105 |
* {@inheritDoc} |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
106 |
*/ |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
107 |
@Override |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
108 |
public void destroyChat(IChat chat) throws RemoteException { |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
109 |
// TODO gerer les resources egalement |
186 | 110 |
Log.d(TAG, "destroy chat jid "+ chat.getParticipant().getJID()); |
111 |
ChatAdapter res = mChats.get(chat.getParticipant().getJID()); |
|
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
112 |
IChat c = mChats.remove(chat.getParticipant().getJID()); |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
113 |
if (c == null) |
186 | 114 |
Log.w(TAG, "CA devrait pas 1!!" + chat.getParticipant().getJID()); |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
115 |
} |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
116 |
|
75 | 117 |
private IChat getChat(Chat chat) { |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
118 |
String key = StringUtils.parseBareAddress(chat.getParticipant()); |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
119 |
if (mChats.containsKey(key)) { |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
120 |
return mChats.get(key); |
75 | 121 |
} |
186 | 122 |
ChatAdapter res = new ChatAdapter(chat); |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
123 |
mChats.put(key, res); |
75 | 124 |
return res; |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
125 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
126 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
127 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
128 |
* A listener for all the chat creation event that happens on the connection. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
129 |
* @author darisk |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
130 |
*/ |
99 | 131 |
private class ChatListener implements ChatStateListener, ChatManagerListener, MessageListener { |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
132 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
133 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
134 |
* Constructor. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
135 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
136 |
public ChatListener() { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
137 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
138 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
139 |
/** |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
140 |
* {@inheritDoc} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
141 |
*/ |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
142 |
@Override |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
143 |
public void chatCreated(Chat chat, boolean locally) { |
186 | 144 |
Log.d(TAG,"new chat"); |
75 | 145 |
IChat newchat = getChat(chat); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
146 |
if (!locally) { |
178 | 147 |
// chat.addMessageListener(mChatListener); |
186 | 148 |
Log.d(TAG, "new local chat"); |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
149 |
notifyNewChat(newchat); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
150 |
} |
186 | 151 |
else |
152 |
Log.d(TAG, "reuse local chat"); |
|
131 | 153 |
chat.addMessageListener(mChatListener); |
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
154 |
final int n = mRemoteChatCreationListeners.beginBroadcast(); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
155 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
156 |
for (int i = 0; i < n; i++) { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
157 |
IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
158 |
try { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
159 |
listener.chatCreated(newchat, locally); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
160 |
} catch (RemoteException e) { |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
161 |
// The RemoteCallbackList will take care of removing the |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
162 |
// dead listeners. |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
163 |
Log.w(TAG, "Error while triggering remote connection listeners", e); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
164 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
165 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
166 |
mRemoteChatCreationListeners.finishBroadcast(); |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
167 |
} |
75 | 168 |
|
186 | 169 |
/* |
170 |
* |
|
171 |
*/ |
|
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
172 |
private void notifyNewChat(IChat chat) { |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
173 |
try { |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
174 |
String text = chat.getParticipant().getJID(); |
178 | 175 |
Notification notif = new Notification(com.beem.project.beem.R.drawable.notify_message, text, System |
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
176 |
.currentTimeMillis()); |
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
177 |
notif.defaults = Notification.DEFAULT_ALL; |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
178 |
notif.flags = Notification.FLAG_AUTO_CANCEL; |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
179 |
Intent intent = new Intent(mService, SendIM.class); |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
180 |
// TODO use prefix for name |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
181 |
intent.putExtra("contact", chat.getParticipant()); |
178 | 182 |
notif.setLatestEventInfo(mService, text, mService.getString(R.string.BeemChatManagerNewMessage), |
183 |
PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT)); |
|
118
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
184 |
int id = chat.hashCode(); |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
185 |
mService.sendNotification(id, notif); |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
186 |
} catch (RemoteException e) { |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
187 |
// TODO Auto-generated catch block |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
188 |
e.printStackTrace(); |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
189 |
} |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
190 |
} |
8bbe46055004
fix some bugs. When you receive a new chat, a notification appears.
Da Risk <darisk972@gmail.com>
parents:
108
diff
changeset
|
191 |
|
75 | 192 |
@Override |
193 |
public void processMessage(Chat chat, Message message) { |
|
194 |
IChat newchat = getChat(chat); |
|
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
195 |
try { |
132 | 196 |
if (message.getBody() != null) |
197 |
newchat.addToLastMessages(message.getBody()); |
|
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
198 |
final int n = mRemoteMessageListeners.beginBroadcast(); |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
199 |
for (int i = 0; i < n; i++) { |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
200 |
IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i); |
75 | 201 |
listener.processMessage(newchat, new com.beem.project.beem.service.Message(message)); |
202 |
} |
|
119
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
203 |
mRemoteMessageListeners.finishBroadcast(); |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
204 |
} catch (RemoteException e) { |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
205 |
// The RemoteCallbackList will take care of removing the |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
206 |
// dead listeners. |
c93e4b69f031
Correction de bug sur la reception de messages
Da Risk <darisk972@gmail.com>
parents:
118
diff
changeset
|
207 |
Log.w(TAG, "Error while triggering remote connection listeners", e); |
75 | 208 |
} |
209 |
} |
|
99 | 210 |
|
211 |
@Override |
|
212 |
public void stateChanged(Chat chat, ChatState state) { |
|
213 |
try { |
|
123 | 214 |
Log.d(TAG, "state changed"); |
99 | 215 |
mChats.get(chat.getParticipant()).setState(state.name()); |
216 |
} catch (RemoteException e) { |
|
217 |
e.printStackTrace(); |
|
218 |
} |
|
219 |
} |
|
55
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
220 |
} |
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
221 |
|
66732dd2cb77
Add an interface for sending im message.
Da Risk <darisk972@gmail.com>
parents:
diff
changeset
|
222 |
} |