当前位置: 首页>>代码示例>>Java>>正文


Java Type类代码示例

本文整理汇总了Java中org.jivesoftware.smack.packet.Presence.Type的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Type类属于org.jivesoftware.smack.packet.Presence包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessage

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
/**
 * Send provided message to provided JID. Message type is always NORMAL.
 * 
 * @param message
 * @param jid
 * @throws NotConnectedException
 */
public void sendMessage(String message, String jid) throws NotConnectedException {
	
	try{
	String jidFinal = getFullJid(jid);
	logger.debug("Sending message: {} to user: {}", new Object[] { message, jidFinal });
	Message msg = new Message(jidFinal, Message.Type.normal);
	msg.setBody(message);
	connection.sendStanza(msg);
	logger.debug("Successfully sent message to user: {}", jidFinal);}
	catch(NotConnectedException ex){
		ex.printStackTrace();
		
		try {
			logger.debug("Tring again to connect..");
			init();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
开发者ID:Pardus-LiderAhenk,项目名称:lider,代码行数:29,代码来源:XMPPClientImpl.java

示例2: sendMessage

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Override
public SendResponse sendMessage(Message message)
{
    org.jivesoftware.smack.packet.Message.Type type = org.jivesoftware.smack.packet.Message.Type.chat;
    org.jivesoftware.smack.packet.Message msg = new org.jivesoftware.smack.packet.Message();
    msg.setFrom(message.getFromJid().getId());
    msg.setBody(message.getBody());
    msg.setType(type);
    
    for (JID to : message.getRecipientJids())
    {
        msg.setTo(to.getId());
        session_.getConnection().sendPacket(msg);
    }
    
    return null;
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:18,代码来源:XMPPServiceImpl.java

示例3: constructCurrentLegacyPresencePacket

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
/**
 * Returns a (legacy/Smack-based) Presence stanza that represents the
 * current presence of this session. The Presence includes relevant Mode,
 * Status and VCardUpdate information.
 * 
 * This method uses the fields {@link TransportSession#presence} and
 * {@link TransportSession#verboseStatus} to generate the result.
 * 
 * @return A Presence packet representing the current presence state of this
 *         session.
 */
public Presence constructCurrentLegacyPresencePacket() {
    final org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(
            org.jivesoftware.smack.packet.Presence.Type.available);
    final Presence.Mode pMode = ((XMPPTransport) getTransport())
            .convertGatewayStatusToXMPP(this.presence);
    if (pMode != null) {
        presence.setMode(pMode);
    }
    if (verboseStatus != null && verboseStatus.trim().length() > 0) {
        presence.setStatus(verboseStatus);
    }
    final Avatar avatar = getAvatar();
    if (avatar != null) {
        final VCardUpdateExtension ext = new VCardUpdateExtension();
        ext.setPhotoHash(avatar.getLegacyIdentifier());
        presence.addExtension(ext);
    }
    return presence;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:31,代码来源:XMPPSession.java

示例4: getContact

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
public Contact getContact(RosterEntry r) {
  Contact contact = new Contact();
  contact.name = r.getName();
  contact.user = r.getUser();
  contact.type = r.getType().toString();

  Type presenceType = roster.getPresence(r.getUser()).getType();
  if (presenceType != null) {
    contact.presence = presenceType.toString();
  }

  ItemStatus status = r.getStatus();
  if (status != null) {
    contact.status = status.toString();
  }

  // ItemStatus status = r.getStatus(); // null
  // log.info("roster entry {}", r.toString());
  // contact.na= r.getUser();
  log.info("getContact {}", contact.toString());

  return contact;
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:24,代码来源:Xmpp.java

示例5: updatePresence

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
public void updatePresence() {
	try {
		Connection connection = XmppConnectionUtils.getInstance()
				.getConnection();
		if (connection != null && connection.isConnected()
				&& connection.isAuthenticated()) {
			// 在线状态获取
			Presence presence = connection.getRoster().getPresence(mUserId);
			if (presence.getType() != Type.unavailable) {
				setPresence("online");
			} else {
				setPresence("unavailable");
			}
			saveToDatabase();
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
}
 
开发者ID:ikantech,项目名称:yiim_v2,代码行数:20,代码来源:XmppVcard.java

示例6: xmppPresence2UserStatus

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
public byte xmppPresence2UserStatus(Presence presence) {
	if (presence == null || presence.getType() != Type.available){
		return -1;
	}
	
	if (presence.getMode() == null || presence.getMode() == Mode.available){
		return 0;
	}
	
	for (byte i=0; i<presenceModes.length; i++) {
		Mode m = presenceModes[i];
		if (m == presence.getMode()){
			return i;
		}
	}
	
	return -1;
}
 
开发者ID:snuk182,项目名称:aceim,代码行数:19,代码来源:XMPPEntityAdapter.java

示例7: userStatus2XMPPPresence

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Override
public Presence userStatus2XMPPPresence(Byte status) {
	Presence presence;
	
	if (status < 0 || status >= presenceModes.length) {
		presence = new Presence(Type.unavailable);
	} else {
		presence = new Presence(Type.available);
		presence.setMode(presenceModes[status]);
	}
	
	if (edProvider != null){
		SignedPresence spr = new SignedPresence();
		try {
			spr.signAndSet(presence.getStatus(), edProvider.getMyKey(), edProvider.getMyKeyPw());
			presence.addExtension(spr);
		} catch (XMPPException e) {
			Logger.log(e);
		}
	}
	
	return presence;
}
 
开发者ID:snuk182,项目名称:aceim,代码行数:24,代码来源:XMPPCryptoEntityAdapter.java

示例8: textMessage2XMPPMessage

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Override
public Message textMessage2XMPPMessage(TextMessage textMessage, String thread, String to, Message.Type messageType) throws Exception {
	Message message = new Message(to, messageType);
	message.setThread(thread);
	message.setPacketID(textMessage.getMessageId() + "");
	MessageEventManager.addNotificationsRequests(message, true, true, true, true);
	
	String buddyKey = null;
	if (edProvider != null && (buddyKey = edProvider.getKeyStorage().get(textMessage.getContactUid())) != null){
		EncryptedMessage ems = new EncryptedMessage();
		ems.setAndEncrypt(textMessage.getText(), buddyKey);
		//TODO
		message.setBody("Encrypted message");			
		message.addExtension(ems);
	} else {
		message.setBody(textMessage.getText());			
	}
	
	return message;
}
 
开发者ID:snuk182,项目名称:aceim,代码行数:21,代码来源:XMPPCryptoEntityAdapter.java

示例9: doAddContactToListAsync

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Override
protected void doAddContactToListAsync(String address, ContactList list) throws ImException {
    debug(TAG, "add contact to " + list.getName());
    org.jivesoftware.smack.packet.Presence response = new org.jivesoftware.smack.packet.Presence(
            org.jivesoftware.smack.packet.Presence.Type.subscribed);
    response.setTo(address);

    sendPacket(response);

    Roster roster = mConnection.getRoster();
    String[] groups = new String[] { list.getName() };
    try {
        Contact contact = makeContact(address);
        roster.createEntry(address, contact.getName(), groups);

        // If contact exists locally, don't create another copy
        
        if (!list.containsContact(contact))
            notifyContactListUpdated(list, ContactListListener.LIST_CONTACT_ADDED, contact);
        else
            debug(TAG, "skip adding existing contact locally " + contact.getName());
    } catch (XMPPException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:prive,项目名称:prive-android,代码行数:26,代码来源:XmppConnection.java

示例10: onClick

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Override
public void onClick(View v) {
    Presence presence = null;
    switch (v.getId()) {
	case R.id.SubscriptionAccept:
	    presence = new Presence(Type.subscribed);
	    Toast.makeText(Subscription.this, getString(R.string.SubscriptAccept), Toast.LENGTH_SHORT)
		    .show();
	    break;
	case R.id.SubscriptionRefuse:
	    presence = new Presence(Type.unsubscribed);
	    Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused), Toast.LENGTH_SHORT).show();
	    break;
	default:
	    Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT).show();
    }
    if (presence != null) {
	presence.setTo(mContact);
	sendPresence(presence);
    }
    finish();
}
 
开发者ID:BoogieMAN2K,项目名称:Beem,代码行数:23,代码来源:Subscription.java

示例11: testSetPresence

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Test
public void testSetPresence() {
	XMPPConnection xmppConnection = providerConnection();
	assertTrue(XMPPUtil.login(xmppConnection, "ranrandemo", "admin123"));
	assertTrue(XMPPUtil.setPresence(xmppConnection, Type.error, "I am bad"));
	XMPPUtil.relaseXMPPConnection(xmppConnection);
}
 
开发者ID:FanHuaRan,项目名称:SmackStudy,代码行数:8,代码来源:XMPPUtilTest.java

示例12: getInitialOnlineUsers

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
/**
 * Get online users from roster and store in onlineUsers
 */
private void getInitialOnlineUsers() {
	Roster roster = Roster.getInstanceFor(connection);
	Collection<RosterEntry> entries = roster.getEntries();
	if (entries != null && !entries.isEmpty()) {
		for (RosterEntry entry : entries) {
			String jid = entry.getUser();
			Presence presence = roster.getPresence(jid);
			if (presence != null) {
				XMPPError xmppError = presence.getError();
				if (xmppError != null) {
					logger.error(xmppError.getDescriptiveText());
				} else {
					try {
						if (presence.getType() == Type.available) {
							onlineUsers.add(jid.substring(0, jid.indexOf('@')));
						} else if (presence.getType() == Type.unavailable) {
							onlineUsers.remove(jid.substring(0, jid.indexOf('@')));
						}
					} catch (Exception e) {
						logger.error(e.getMessage(), e);
					}
				}
			}
		}
	}
	logger.debug("Online users: {}", onlineUsers.toString());
}
 
开发者ID:Pardus-LiderAhenk,项目名称:lider,代码行数:31,代码来源:OnlineRosterListener.java

示例13: setStatus

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的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");
	}
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:12,代码来源:XMPP.java

示例14: disconnect

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Override
public void disconnect()
{
    if (this.isConnected())
    {
        org.jivesoftware.smack.packet.Presence unavailable = new org.jivesoftware.smack.packet.Presence(Type.unavailable);
        unavailable.setFrom(this.session_.getUser().getId().getId());
        
        this.session_.getConnection().disconnect(unavailable);
        this.eventManager_.stop();
    }
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:13,代码来源:XMPPServiceImpl.java

示例15: sendPresence

import org.jivesoftware.smack.packet.Presence.Type; //导入依赖的package包/类
@Override
public void sendPresence(JID jabberId, PresenceType type, PresenceShow show, String status, JID fromJid)
{
    checkNotNull(jabberId);
    
    final Type presenceType = type == null ? Type.available : Type.valueOf(type.name().toLowerCase());
    final Mode presenceMode = show == null ? null : Mode.valueOf(show.name().toLowerCase());
    
    org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(presenceType, status, 1, presenceMode);
    presence.setFrom(fromJid == null ? null : fromJid.getId());
    presence.setTo(jabberId.getId());
    this.session_.getConnection().sendPacket(presence);
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:14,代码来源:XMPPServiceImpl.java


注:本文中的org.jivesoftware.smack.packet.Presence.Type类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。