本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.Type方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.Type方法的具體用法?Java Presence.Type怎麽用?Java Presence.Type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.Presence
的用法示例。
在下文中一共展示了Presence.Type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: perform
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
Presence.Type typeVal = Presence.Type.valueOf(sampler.getPropertyAsString(TYPE, Presence.Type.available.toString()));
Presence.Mode modeVal = Presence.Mode.valueOf(sampler.getPropertyAsString(MODE, Presence.Mode.available.toString()));
Presence presence = new Presence(typeVal);
presence.setMode(modeVal);
String to = sampler.getPropertyAsString(RECIPIENT);
if (!to.isEmpty()) {
presence.setTo(to);
}
String text = sampler.getPropertyAsString(STATUS_TEXT);
if (!text.isEmpty()) {
presence.setStatus(text);
}
sampler.getXMPPConnection().sendPacket(presence);
res.setSamplerData(presence.toXML().toString());
return res;
}
示例2: getStatusFromContact
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public Presence.Type getStatusFromContact(String name) {
try {
HashMap<Jid, Presence.Type> buddies = getContacts();
for (Map.Entry<Jid, Presence.Type> pair : buddies.entrySet()) {
if (XMPPUtils.fromJIDToUserName(pair.getKey().toString()).equals(name)) {
return pair.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return Presence.Type.unavailable;
}
示例3: onPresenceUpdate
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void onPresenceUpdate(JID jid, Presence.Type type, Optional<String> optStatus) {
JID myJID = mClient.getOwnJID().orElse(null);
if (myJID != null && myJID.equals(jid))
// don't wanna see myself
return;
Contact contact = mModel.contacts().get(jid).orElse(null);
if (contact == null) {
LOGGER.info("can't find contact with jid: "+jid);
return;
}
if (type == Presence.Type.available) {
contact.setOnlineStatus(Contact.Online.YES);
} else if (type == Presence.Type.unavailable) {
contact.setOnlineStatus(Contact.Online.NO);
}
if (optStatus.isPresent())
contact.setStatusText(optStatus.get());
}
示例4: setPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* 設置用戶狀態
* @param xmppConnection
* @param type 狀態
* @param status 狀態描述
* @return
*/
public static boolean setPresence(XMPPConnection xmppConnection,Presence.Type type,String status){
Presence presence=new Presence(type);
presence.setStatus(status);
try{
xmppConnection.sendPacket(presence);
return true;
}catch (Exception e){
return false;
}
}
示例5: setPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* 設置用戶狀態
* @param xmppConnection
* @param type
* @param status
* @return
*/
public static boolean setPresence(XMPPConnection xmppConnection, Presence.Type type, String status) {
Presence presence = new Presence(type);
presence.setStatus(status);
try {
xmppConnection.sendPacket(presence);
return true;
} catch (Exception e) {
Log.e("setPresence", e.getMessage());
return false;
}
}
示例6: isChatWithContact
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private boolean isChatWithContact() {
try {
HashMap<Jid, Presence.Type> buddies = RosterManager.getInstance().getContacts();
for (Map.Entry pair : buddies.entrySet()) {
if (mChat.getJid().equals(pair.getKey().toString())) {
return true;
}
}
} catch (SmackException.NotLoggedInException | InterruptedException | SmackException.NotConnectedException e) {
e.printStackTrace();
}
return false;
}
示例7: loadRosterContactsChats
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void loadRosterContactsChats() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException {
try {
HashMap<Jid, Presence.Type> buddies = RosterManager.getInstance().getContacts();
for (Map.Entry pair : buddies.entrySet()) {
String userJid = pair.getKey().toString();
RoomsListManager.getInstance().createChatIfNotExists(userJid, true);
}
} finally {
mListener.onRoomsLoaded();
}
}
示例8: getContacts
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public HashMap<Jid, Presence.Type> getContacts()
throws SmackException.NotLoggedInException, InterruptedException,
SmackException.NotConnectedException {
Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
if (!roster.isLoaded()) {
roster.reloadAndWait();
}
String groupName = "Buddies";
RosterGroup group = roster.getGroup(groupName);
if (group == null) {
roster.createGroup(groupName);
group = roster.getGroup(groupName);
}
HashMap<Jid, Presence.Type> buddies = new HashMap<>();
List<RosterEntry> entries = group.getEntries();
for (RosterEntry entry : entries) {
BareJid jid = entry.getJid();
Presence.Type status = roster.getPresence(jid).getType();
buddies.put(jid, status);
}
return buddies;
}
示例9: getContactsWithSubscriptionPending
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public HashMap<Jid, Presence.Type> getContactsWithSubscriptionPending()
throws SmackException.NotLoggedInException, InterruptedException,
SmackException.NotConnectedException {
Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
if (!roster.isLoaded()) {
roster.reloadAndWait();
}
String groupName = "Buddies";
RosterGroup group = roster.getGroup(groupName);
if (group == null) {
roster.createGroup(groupName);
group = roster.getGroup(groupName);
}
HashMap<Jid, Presence.Type> buddiesPending = new HashMap<>();
List<RosterEntry> entries = group.getEntries();
for (RosterEntry entry : entries) {
if (entry.isSubscriptionPending()) {
BareJid jid = entry.getJid();
Presence.Type status = roster.getPresence(jid).getType();
buddiesPending.put(jid, status);
}
}
return buddiesPending;
}
示例10: hasContactSubscriptionPending
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public boolean hasContactSubscriptionPending(Jid jid)
throws SmackException.NotLoggedInException, InterruptedException,
SmackException.NotConnectedException {
HashMap<Jid, Presence.Type> buddies = getContactsWithSubscriptionPending();
return buddies.containsKey(jid);
}
示例11: setStatus
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void setStatus(boolean available, String status) {
connect();
if (connection != null && connection.isConnected()) {
Presence.Type type = available ? Type.available : Type.unavailable;
Presence presence = new Presence(type);
presence.setStatus(status);
connection.sendPacket(presence);
} else {
log.error("setStatus not connected");
}
}
示例12: sendSubscribe
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* �ظ�һ��presence��Ϣ���û������û��ǽ��ջ��Ǿܾ�
*
* @param type
* @param to
*/
protected void sendSubscribe(Presence.Type type, String to)
{
Presence presence = new Presence(type);
presence.setTo(to);
XmppConnectionManager.getInstance().getConnection().sendPacket(presence);
}
示例13: sendSubscribe
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* �ظ�һ��presence��Ϣ���û�
*
* @param type
* @param to
*/
protected void sendSubscribe(Presence.Type type, String to) {
Presence presence = new Presence(type);
presence.setTo(to);
XmppConnectionManager.getInstance().getConnection()
.sendPacket(presence);
}
示例14: sendPresenceEvent
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* helper method to trigger a presence update even if the server does not send a presence packet itself (e.g. entering a test but no other buddies are online)
*
* @param username
*/
@Override
public void sendPresenceEvent(final Presence.Type type, final String username) {
final Presence presence = new Presence(type);
presence.setTo(username);
final GenericEventListener listener = listeners.get(username);
if (listener != null) {
listener.event(new InstantMessagingEvent(presence, "presence"));
}
}
示例15: setStatus
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void setStatus(boolean available, String status) {
if (connection != null && connection.isConnected()) {
Presence.Type type = available ? Type.available : Type.unavailable;
Presence presence = new Presence(type);
presence.setStatus(status);
// connection.sendPacket(presence);
} else {
log.error("setStatus not connected");
}
}