本文整理汇总了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();
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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());
}
示例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");
}
}
示例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();
}
}
示例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);
}