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


Java Roster.getInstanceFor方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.roster.Roster.getInstanceFor方法的典型用法代码示例。如果您正苦于以下问题:Java Roster.getInstanceFor方法的具体用法?Java Roster.getInstanceFor怎么用?Java Roster.getInstanceFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.roster.Roster的用法示例。


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

示例1: removeContact

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public void removeContact(String jidString)
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException, XmppStringprepException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }

    BareJid jid = JidCreate.bareFrom(jidString);
    roster.removeEntry(roster.getEntry(jid));

    Presence presence = new Presence(Presence.Type.unsubscribe);
    presence.setTo(JidCreate.from(jidString));
    XMPPSession.getInstance().sendStanza(presence);
}
 
开发者ID:esl,项目名称:mangosta-android,代码行数:17,代码来源:RosterManager.java

示例2: addContact

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public void addContact(String jidString)
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException, XmppStringprepException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }

    BareJid jid = JidCreate.bareFrom(jidString);
    String name = XMPPUtils.fromJIDToUserName(jidString);
    String[] groups = new String[]{"Buddies"};

    roster.createEntry(jid, name, groups);
    roster.sendSubscriptionRequest(jid);
}
 
开发者ID:esl,项目名称:mangosta-android,代码行数:17,代码来源:RosterManager.java

示例3: listRoster

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
/**
 * creates a list of all RosterEntries
 * @return the rosterEntryArray
 */
public RosterEntry[] listRoster(){
  try{
    // get the roster and if it is not loaded reload it
    Roster roster = Roster.getInstanceFor(connection);
    if (!roster.isLoaded())
      roster.reloadAndWait();
    RosterEntry[] result = new RosterEntry[roster.getEntries().size()];
    int i = 0;
    // loop through all roster entries and append them to the array
    for (RosterEntry entry: roster.getEntries()){
      result[i++] = entry;
    }
    return result;
  }catch (Exception e){
    e.printStackTrace();
  }
  return new RosterEntry[0];
}
 
开发者ID:Nik-Sch,项目名称:ChatApp-Android,代码行数:23,代码来源:XmppManager.java

示例4: rebuildRoster

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
private void rebuildRoster() {
    Roster roster = Roster.getInstanceFor(mConnection);
    if (roster == null) {
        Logger.info(TAG, "no roster, skipping rebuild roster");
        return;
    }

    Set<RosterEntry> entries = roster.getEntries();
    ArrayList<XmppRosterEntry> newRoster = new ArrayList<>(entries.size());

    for (RosterEntry entry : entries) {
        XmppRosterEntry newEntry = getRosterEntryFor(roster, entry);
        newRoster.add(newEntry);
    }

    Collections.sort(newRoster);
    XmppService.setRosterEntries(newRoster);
    XmppServiceBroadcastEventEmitter.broadcastRosterChanged();
}
 
开发者ID:VoiSmart,项目名称:xmpp-service,代码行数:20,代码来源:XmppServiceConnection.java

示例5: connect

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public void connect(String hostname, int port, String username, String password) throws Exception {

    purgeTask("reconnect");

    this.hostname = hostname;
    this.serviceName = hostname;
    this.port = port;
    this.username = username;
    this.password = password;

    Builder builder = XMPPTCPConnectionConfiguration.builder();
    builder.setUsernameAndPassword(username, password);
    builder.setServiceName(serviceName);
    builder.setServiceName(hostname);
    builder.setPort(port);
    builder.setSecurityMode(SecurityMode.disabled);
    builder.setDebuggerEnabled(true);

    XMPPTCPConnectionConfiguration config = builder.build();

    connection = new XMPPTCPConnection(config);
    connection.connect().login();

    roster = Roster.getInstanceFor(connection);
    chatManager = ChatManager.getInstanceFor(connection);

    roster.addRosterListener(this);

    isConnected = true;

    // not worth it - always empty right after connect
    // getContactList();

    broadcastState();
  }
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:36,代码来源:Xmpp.java

示例6: removeFromRoster

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public boolean removeFromRoster(JID jid) {
    if (!this.isConnected()) {
        LOGGER.info("not connected");
        return false;
    }
    Roster roster = Roster.getInstanceFor(mConn);
    RosterEntry entry = roster.getEntry(jid.toBareSmack());
    if (entry == null) {
        LOGGER.info("can't find roster entry for jid: "+jid);
        return true;
    }
    try {
        // blocking
        roster.removeEntry(entry);
    } catch (SmackException.NotLoggedInException |
            SmackException.NoResponseException |
            XMPPException.XMPPErrorException |
            SmackException.NotConnectedException |
            InterruptedException ex) {
        LOGGER.log(Level.WARNING, "can't remove contact from roster", ex);
        return false;
    }
    return true;
}
 
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:25,代码来源:Client.java

示例7: updateRosterEntry

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public void updateRosterEntry(JID jid, String newName) {
    if (!this.isConnected()) {
        LOGGER.info("not connected");
        return;
    }
    Roster roster = Roster.getInstanceFor(mConn);
    RosterEntry entry = roster.getEntry(jid.toBareSmack());
    if (entry == null) {
        LOGGER.warning("can't find roster entry for jid: "+jid);
        return;
    }
    try {
        entry.setName(newName);
    } catch (SmackException.NotConnectedException |
            SmackException.NoResponseException |
            XMPPException.XMPPErrorException |
            InterruptedException ex) {
        LOGGER.log(Level.WARNING, "can't set name for entry", ex);
    }
}
 
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:21,代码来源:Client.java

示例8: newConnection

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
@Override
public void newConnection(XMPPConnection connection) {
	mConnection = connection;
	mRoster = Roster.getInstanceFor(connection);
	mRoster.addRosterListener(this);

	mRoster.addSubscribeListener(new SubscribeListener() {
		@Override
		public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
			Set<EntityBareJid> masterJids = mSettings.getMasterJids();
			for (EntityBareJid masterJid : masterJids) {
				if (masterJid.equals(from)) {
					return SubscribeAnswer.Approve;
				}
			}
			return SubscribeAnswer.Deny;
		}
	});
}
 
开发者ID:ProjectMAXS,项目名称:maxs,代码行数:20,代码来源:XMPPRoster.java

示例9: notifyAboutNewMasterAddress

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public void notifyAboutNewMasterAddress(final EntityBareJid newMasterAddress) {
	final XMPPConnection connection = getConnection();
	if (connection == null || !connection.isAuthenticated()) {
		return;
	}

	final Roster roster = Roster.getInstanceFor(connection);

	Async.go(new ThrowingRunnable() {
		@Override
		public void runOrThrow() throws NotLoggedInException, NotConnectedException,
				FeatureNotSupportedException, InterruptedException {
			if (roster.isSubscriptionPreApprovalSupported()) {
				roster.preApprove(newMasterAddress);
			}
			RosterUtil.askForSubscriptionIfRequired(roster, newMasterAddress);
		}
	});
}
 
开发者ID:ProjectMAXS,项目名称:maxs,代码行数:20,代码来源:XMPPService.java

示例10: removeAllContacts

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public void removeAllContacts()
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }
    for (RosterEntry entry : roster.getEntries()) {
        roster.removeEntry(entry);
        Presence presence = new Presence(Presence.Type.unsubscribe);
        presence.setTo(entry.getJid());
        XMPPSession.getInstance().sendStanza(presence);
    }
}
 
开发者ID:esl,项目名称:mangosta-android,代码行数:16,代码来源:RosterManager.java

示例11: getContacts

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的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;
}
 
开发者ID:esl,项目名称:mangosta-android,代码行数:29,代码来源:RosterManager.java

示例12: getContactsWithSubscriptionPending

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的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;
}
 
开发者ID:esl,项目名称:mangosta-android,代码行数:31,代码来源:RosterManager.java

示例13: getRoster

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
/**
 * returns the roster for the current connection
 *
 * @return the roster and null if the roster cannot be accessed
 */
public Roster getRoster(){
  if (connection != null && connection.isConnected()){
    Log.d("DEBUG", "Success: returning roster.");
    return Roster.getInstanceFor(connection);
  }else{
    Log.d("DEBUG", "Couldn't get the roster: No connection.");
    return null;
  }
}
 
开发者ID:Nik-Sch,项目名称:ChatApp-Android,代码行数:15,代码来源:XmppManager.java

示例14: getInitialOnlineUsers

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的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

示例15: connect

import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
public void connect() throws IOException, XMPPException, SmackException {
    if (mConnection == null) {
        createConnection();
    }

    if (!mConnection.isConnected()) {
        Logger.info(TAG, "Connecting to " + mAccount.getHost() + ":" + mAccount.getPort());
        mConnection.connect();

        Roster roster = Roster.getInstanceFor(mConnection);
        roster.removeRosterListener(this);
        roster.addRosterListener(this);
        roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
        roster.setRosterLoadedAtLogin(true);
    }

    if (!mConnection.isAuthenticated()) {
        Logger.info(TAG, "Authenticating " + mAccount.getXmppJid());
        mConnection.login();

        PingManager.setDefaultPingInterval(XmppService.DEFAULT_PING_INTERVAL);
        PingManager pingManager = PingManager.getInstanceFor(mConnection);
        pingManager.registerPingFailedListener(this);

        ChatManager chatManager = ChatManager.getInstanceFor(mConnection);
        chatManager.removeChatListener(this);
        chatManager.addChatListener(this);

        DeliveryReceiptManager receipts = DeliveryReceiptManager.getInstanceFor(mConnection);
        receipts.setAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.always);
        receipts.autoAddDeliveryReceiptRequests();
    }

    mOwnAvatar = getAvatarFor("");
}
 
开发者ID:VoiSmart,项目名称:xmpp-service,代码行数:36,代码来源:XmppServiceConnection.java


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