63 import android.preference.PreferenceManager; |
63 import android.preference.PreferenceManager; |
64 import android.util.Log; |
64 import android.util.Log; |
65 |
65 |
66 import com.beem.project.beem.BeemApplication; |
66 import com.beem.project.beem.BeemApplication; |
67 import com.beem.project.beem.BeemService; |
67 import com.beem.project.beem.BeemService; |
|
68 import com.beem.project.beem.R; |
68 import com.beem.project.beem.service.aidl.IChat; |
69 import com.beem.project.beem.service.aidl.IChat; |
69 import com.beem.project.beem.service.aidl.IChatManager; |
70 import com.beem.project.beem.service.aidl.IChatManager; |
70 import com.beem.project.beem.service.aidl.IChatManagerListener; |
71 import com.beem.project.beem.service.aidl.IChatManagerListener; |
71 import com.beem.project.beem.service.aidl.IMessageListener; |
72 import com.beem.project.beem.service.aidl.IMessageListener; |
72 import com.beem.project.beem.service.aidl.IRoster; |
73 import com.beem.project.beem.service.aidl.IRoster; |
266 * @return A Chat activity PendingIntent |
267 * @return A Chat activity PendingIntent |
267 */ |
268 */ |
268 private PendingIntent makeChatIntent(IChat chat) { |
269 private PendingIntent makeChatIntent(IChat chat) { |
269 Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class); |
270 Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class); |
270 chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP |
271 chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP |
271 | Intent.FLAG_ACTIVITY_NEW_TASK); |
272 | Intent.FLAG_ACTIVITY_NEW_TASK); |
272 try { |
273 try { |
273 chatIntent.setData(chat.getParticipant().toUri()); |
274 chatIntent.setData(chat.getParticipant().toUri()); |
274 } catch (RemoteException e) { |
275 } catch (RemoteException e) { |
275 Log.e(TAG, e.getMessage()); |
276 Log.e(TAG, e.getMessage()); |
276 } |
277 } |
280 } |
281 } |
281 |
282 |
282 /** |
283 /** |
283 * Set a notification of a new chat. |
284 * Set a notification of a new chat. |
284 * @param chat The chat to access by the notification |
285 * @param chat The chat to access by the notification |
285 * @param msgBody the body of the new message |
286 */ |
286 */ |
287 private void notifyNewChat(IChat chat) { |
287 private void notifyNewChat(IChat chat, String msgBody) { |
|
288 SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mService); |
288 SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mService); |
289 try { |
289 try { |
290 CharSequence tickerText = mService.getBind().getRoster().getContact(chat.getParticipant().getJID()) |
290 CharSequence tickerText = mService.getBind().getRoster().getContact(chat.getParticipant().getJID()) |
291 .getName(); |
291 .getName(); |
292 Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System |
292 Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System |
293 .currentTimeMillis()); |
293 .currentTimeMillis()); |
294 notification.flags = Notification.FLAG_AUTO_CANCEL; |
294 notification.flags = Notification.FLAG_AUTO_CANCEL; |
295 notification.setLatestEventInfo(mService, tickerText, msgBody, makeChatIntent(chat)); |
295 notification.setLatestEventInfo(mService, tickerText, mService |
|
296 .getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat)); |
296 mService.sendNotification(chat.getParticipant().getJID().hashCode(), notification); |
297 mService.sendNotification(chat.getParticipant().getJID().hashCode(), notification); |
297 } catch (RemoteException e) { |
298 } catch (RemoteException e) { |
298 Log.e(TAG, e.getMessage()); |
299 Log.e(TAG, e.getMessage()); |
299 } |
300 } |
300 } |
301 } |
303 * {@inheritDoc} |
304 * {@inheritDoc} |
304 */ |
305 */ |
305 @Override |
306 @Override |
306 public void processMessage(final IChat chat, Message message) { |
307 public void processMessage(final IChat chat, Message message) { |
307 try { |
308 try { |
308 String body = message.getBody(); |
309 if (!chat.isOpen() && message.getBody() != null) { |
309 if (!chat.isOpen() && body != null) { |
|
310 if (chat instanceof ChatAdapter) { |
310 if (chat instanceof ChatAdapter) { |
311 mChats.put(chat.getParticipant().getJID(), (ChatAdapter) chat); |
311 mChats.put(chat.getParticipant().getJID(), (ChatAdapter) chat); |
312 } |
312 } |
313 notifyNewChat(chat, body); |
313 notifyNewChat(chat); |
314 } |
314 } |
315 } catch (RemoteException e) { |
315 } catch (RemoteException e) { |
316 Log.e(TAG, e.getMessage()); |
316 Log.e(TAG, e.getMessage()); |
317 } |
317 } |
318 } |
318 } |
319 |
319 |
320 @Override |
320 @Override |
321 public void stateChanged(final IChat chat) { |
321 public void stateChanged(final IChat chat) { } |
|
322 |
|
323 @Override |
|
324 public void otrStateChanged(String otrState) throws RemoteException { |
|
325 // TODO Auto-generated method stub |
|
326 |
322 } |
327 } |
323 } |
328 } |
324 } |
329 } |