@Override public String getElementName() { return state.name(); }
@After public void cleanup() { ChatStateManager manTwo = ChatStateManager.getInstance(conTwo); manTwo.removeChatStateListener(composingListener); manTwo.removeChatStateListener(activeListener); } }
@Override public ChatStateExtension parse(XmlPullParser parser, int initialDepth) throws Exception { String chatStateString = parser.getName(); ChatState state = ChatState.valueOf(chatStateString); return new ChatStateExtension(state); }
/** * Create a new instance of ChatManager. */ private ChatManager() { chatContainer = UIComponentRegistry.createChatContainer(); // Add Default Chat Room Decorator addSparkTabHandler(new DefaultTabHandler()); // Add a Message Handler ChatStateManager chatStateManager = ChatStateManager.getInstance(SparkManager.getConnection()); chatStateManager.addChatStateListener(smackChatStateListener); }
@SmackIntegrationTest public void testChatStateListeners() throws Exception { ChatStateManager manOne = ChatStateManager.getInstance(conOne); ChatStateManager manTwo = ChatStateManager.getInstance(conTwo); // Add chatState listeners. manTwo.addChatStateListener(composingListener); manTwo.addChatStateListener(activeListener); Chat chatOne = ChatManager.getInstanceFor(conOne) .chatWith(conTwo.getUser().asEntityBareJid()); // Test, if setCurrentState works and the chatState arrives manOne.setCurrentState(ChatState.composing, chatOne); composingSyncPoint.waitForResult(timeout); // Test, if the OutgoingMessageInterceptor successfully adds a chatStateExtension of "active" to // an outgoing chat message and if it arrives at the other side. Chat chat = ChatManager.getInstanceFor(conOne) .chatWith(conTwo.getUser().asEntityBareJid()); chat.send("Hi!"); activeSyncPoint.waitForResult(timeout); }
@Override public void stateChanged(Chat chat, ChatState state, Message message) { if (state.equals(ChatState.composing)) { composingSyncPoint.signal(); } } };
/** * Sets the current state of the provided chat. This method will send an empty bodied Message * stanza with the state attached as a {@link org.jivesoftware.smack.packet.ExtensionElement}, if * and only if the new chat state is different than the last state. * * @param newState the new state of the chat * @param chat the chat. * @throws NotConnectedException * @throws InterruptedException */ public void setCurrentState(ChatState newState, Chat chat) throws NotConnectedException, InterruptedException { if (chat == null || newState == null) { throw new IllegalArgumentException("Arguments cannot be null."); } if (!updateChatState(chat, newState)) { return; } Message message = new Message(); ChatStateExtension extension = new ChatStateExtension(newState); message.addExtension(extension); chat.send(message); }
state = ChatState.valueOf(chatStateElementName); return (state == ChatState.active);
ChatStateManager.getInstance( SparkManager.getConnection() );
@Override public int hashCode() { return connection().hashCode(); }
/** * Returns the ChatStateManager related to the XMPPConnection and it will create one if it does * not yet exist. * * @param connection the connection to return the ChatStateManager * @return the ChatStateManager related the the connection. */ public static synchronized ChatStateManager getInstance(final XMPPConnection connection) { ChatStateManager manager = INSTANCES.get(connection); if (manager == null) { manager = new ChatStateManager(connection); INSTANCES.put(connection, manager); } return manager; }
ChatManager.getInstance().addChatMessageHandler(chatMessageHandler); ChatStateManager.getInstance(SparkManager.getConnection()).addChatStateListener(this);
@Override public void stateChanged(Chat chat, ChatState state, Message message) { if (state.equals(ChatState.active)) { activeSyncPoint.signal(); } } };
public ChatStatePanel(ChatState state, CharSequence nickname) { setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1)); JLabel label = new JLabel( Res.getString( state.name(), nickname.toString() ) ); label.setFont(new Font("Courier New", Font.PLAIN, 9)); label.setForeground(Color.gray); label.setHorizontalTextPosition(JLabel.LEFT); label.setVerticalTextPosition(JLabel.BOTTOM); add( label ); } }
state = ChatState.valueOf(chatStateElementName);
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ChatStateManager that = (ChatStateManager) o; return connection().equals(that.connection()); }
/** * 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, Message message) { Jid participant = chat.getXmppAddressOfChatPartner(); if (ChatState.composing.equals(state)) { composingNotification(participant); } else { cancelledNotification(participant, state); } } }
@Override public void stateChanged(Chat chat, ChatState state, Message message) { presence = Workspace.getInstance().getStatusBar().getPresence(); if (ChatState.composing.equals(state)) { changeSysTrayIcon(); } else { if (!newMessage) { if (presence.getMode() == Presence.Mode.available) { trayIcon.setImage(availableIcon.getImage()); } else if (presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa) { trayIcon.setImage(awayIcon.getImage()); } else if (presence.getMode() == Presence.Mode.dnd) { trayIcon.setImage(dndIcon.getImage()); } else { trayIcon.setImage(newMessageIcon.getImage()); } } } }