/** * {@inheritDoc} */ @Override public void stateChanged(Chat chat, ChatState state) { mState = state.name(); final int n = mRemoteListeners.beginBroadcast(); for (int i = 0; i < n; i++) { IMessageListener listener = mRemoteListeners.getBroadcastItem(i); try { listener.stateChanged(ChatAdapter.this); } catch (RemoteException e) { Log.w(TAG, e.getMessage()); } } mRemoteListeners.finishBroadcast(); }
public void closeChatRoom() { // If already closed, don't bother. if (!active) { return; } super.closeChatRoom(); removeListeners(); sendChatState(ChatState.gone); sendGoneNotification = false; SparkManager.getChatManager().removeChat(this); SparkManager.getConnection().removePacketListener(this); if (typingTimerTask != null) { TaskEngine.getInstance().cancelScheduledTask(typingTimerTask); typingTimerTask = null; } active = false; vcardPanel = null; this.removeAll(); }
/** * The current SendField has been updated somehow. * * @param e - the DocumentEvent to respond to. */ public void insertUpdate(DocumentEvent e) { checkForText(e); if (!sendChatStateNotification) { return; } startNotificationSendingTime = System.currentTimeMillis(); // If the user pauses for more than two seconds, send out a new notice. if (sendComposingNotification) { try { //SparkManager.getMessageEventManager().sendComposingNotification(getParticipantJID(), threadID); sendChatState(ChatState.composing); sendPausingNotification = true; sendInactiveNotification = true; sendGoneNotification = true; sendComposingNotification = false; } catch (Exception exception) { Log.error("Error updating", exception); } } }
/** * Filters all incoming messages. * * @param room the room the message belongs to. * @param message the message to filter. */ public void filterIncomingMessage(ChatRoom room, Message message) { // Fire Message Filters final ChatManager chatManager = SparkManager.getChatManager(); Iterator<MessageFilter> filters = chatManager.getMessageFilters().iterator(); try { cancelledNotification(message.getFrom(), ChatState.paused); } catch (Exception e) { Log.error(e); } // Notify MessageFilters. while (filters.hasNext()) { (filters.next()).filterIncoming(room, message); } }
public void composingNotification(final String from) { SwingUtilities.invokeLater(new Runnable() { public void run() { final ContactList contactList = SparkManager.getWorkspace().getContactList(); ChatRoom chatRoom; try { chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from)); if (chatRoom != null && chatRoom instanceof ChatRoomImpl) { typingNotificationList.add(chatRoom); // Notify Decorators notifySparkTabHandlers(chatRoom); ((ChatRoomImpl)chatRoom).notifyChatStateChange(ChatState.composing); } } catch (ChatRoomNotFoundException e) { // Do nothing } contactList.setIconFor(from, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE)); } }); }
public void cancelledNotification(final String from, final ChatState state) { SwingUtilities.invokeLater(new Runnable() { public void run() { ContactList contactList = SparkManager.getWorkspace().getContactList(); ChatRoom chatRoom; try { chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from)); if (chatRoom != null && chatRoom instanceof ChatRoomImpl) { typingNotificationList.remove(chatRoom); // Notify Decorators notifySparkTabHandlers(chatRoom); ((ChatRoomImpl)chatRoom).notifyChatStateChange(state); } } catch (ChatRoomNotFoundException e) { // Do nothing } contactList.useDefaults(from); } }); }
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { ChatState state; try { state = ChatState.valueOf(parser.getName()); } catch (Exception ex) { state = ChatState.active; } return new ChatStateExtension(state); }
/** * @see net.sf.kraken.session.TransportSession#sendChatState(org.xmpp.packet.JID, net.sf.kraken.type.ChatStateType) */ @Override public void sendChatState(JID jid, ChatStateType chatState) { final Presence presence = conn.getRoster().getPresence(jid.toString()); if (presence == null || presence.getType().equals(Presence.Type.unavailable)) { // don't send chat state to contacts that are offline. return; } Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener); try { ChatState state = ChatState.active; switch (chatState) { case active: state = ChatState.active; break; case composing: state = ChatState.composing; break; case paused: state = ChatState.paused; break; case inactive: state = ChatState.inactive; break; case gone: state = ChatState.gone; break; } Message message = new Message(); message.addExtension(new ChatStateExtension(state)); chat.sendMessage(message); } catch (XMPPException e) { // Ignore } }
protected void createChatStateTimerTask() { typingTimerTask = new TimerTask() { public void run() { if (!sendChatStateNotification) { return; } long now = System.currentTimeMillis(); long time = now - startNotificationSendingTime; if (inBetween(time, pauseTimePeriod, inactiveTimePeriod)) { if (sendPausingNotification) { // send cancel //SparkManager.getMessageEventManager().sendCancelledNotification(getParticipantJID(), threadID); sendChatState(ChatState.paused); sendPausingNotification = false; sendComposingNotification = true; } } else if (inBetween(time, inactiveTimePeriod, goneTimePeriod)) { if(sendInactiveNotification) { sendChatState(ChatState.inactive); sendInactiveNotification = false; } } else if (time > goneTimePeriod) { if (sendGoneNotification) { sendChatState(ChatState.gone); sendGoneNotification = false; } } } }; TaskEngine.getInstance().scheduleAtFixedRate(typingTimerTask, pauseTimePeriod, pauseTimePeriod); }
public void activateChatStateNotificationSystem() { startNotificationSendingTime = System.currentTimeMillis(); sendInactiveNotification = true; sendGoneNotification = true; sendPausingNotification = false; sendComposingNotification = true; if (lastNotificationSent == null || !lastNotificationSent.equals(ChatState.active)) { sendChatState(ChatState.active); } }
public void inactivateChatStateNotificationSystem() { startNotificationSendingTime = System.currentTimeMillis(); sendInactiveNotification = false; sendGoneNotification = true; sendPausingNotification = false; sendComposingNotification = false; if (lastNotificationSent != null && !lastNotificationSent.equals(ChatState.inactive) && !lastNotificationSent.equals(ChatState.gone)) { sendChatState(ChatState.inactive); } }
private void sendChatState(ChatState state) { Connection connection = SparkManager.getConnection(); boolean connected = connection.isConnected(); if (connected) { Chat chat = connection.getChatManager().createChat(getParticipantJID(), null); try { ChatStateManager.getInstance(connection).setCurrentState(state, chat); lastNotificationSent = state; } catch (XMPPException e) { Log.error("Cannot send " + state + " chat notification"); } } }
public void notifyChatStateChange(ChatState state) { if (chatStatePanel != null) { getEditorWrapperBar().remove(chatStatePanel); } chatStatePanel = new ChatStatePanel(state, getParticipantNickname()); getEditorWrapperBar().add(chatStatePanel, BorderLayout.SOUTH); getEditorWrapperBar().revalidate(); getEditorWrapperBar().repaint(); }
public ChatStatePanel(ChatState state, String nickname) { setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1)); label = new JLabel(Res.getString(state.name(), nickname)); label.setFont(new Font("Courier New", Font.PLAIN, 9)); label.setForeground(Color.gray); label.setHorizontalTextPosition(JLabel.LEFT); label.setVerticalTextPosition(JLabel.BOTTOM); add(label); }
/** * Called by smack when the state of a chat changes. * * @param chat the chat that is concerned by this event. * @param state the new state of the chat. */ @Override public void stateChanged(Chat chat, ChatState state) { String participant = chat.getParticipant(); if (ChatState.composing.equals(state)) { composingNotification(participant); } else { cancelledNotification(participant, state); } }
@Override public void stateChanged(Chat chat, ChatState state) { if (ChatState.composing.equals(state)) { changeSysTrayIcon(); } else { if (!newMessage) trayIcon.setImage(availableIcon.getImage()); else { trayIcon.setImage(newMessageIcon.getImage()); } } }
@Override public void stateChanged(Chat chat, ChatState state) { if (state == ChatState.composing) { getInternalService().getService().getCoreService().typingNotification(getInternalService().getService().getEntityAdapter().normalizeJID(chat.getParticipant())); } }
/** * Default constructor. The argument provided is the state that the extension will represent. * * @param state the state that the extension represents. */ public ChatStateExtension(ChatState state) { this.state = state; }
/** * Default constructor. The argument provided is the state that the * extension will represent. * * @param state * the state that the extension represents. */ public ChatStateExtension(ChatState state) { this.state = state; }