Java 类org.jivesoftware.smack.Roster 实例源码

项目:jmeter-bzm-plugins    文件:RosterAction.java   
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    Action action = Action.valueOf(sampler.getPropertyAsString(ACTION, Action.get_roster.toString()));
    Roster roster = sampler.getXMPPConnection().getRoster();
    String entry = sampler.getPropertyAsString(ENTRY);
    res.setSamplerData(action.toString() + ": " + entry);
    if (action == Action.get_roster) {
        res.setResponseData(rosterToString(roster).getBytes());
    } else if (action == Action.add_item) {
        roster.createEntry(entry, entry, new String[0]);
    } else if (action == Action.delete_item) {
        RosterEntry rosterEntry = roster.getEntry(entry);
        if (rosterEntry != null) {
            roster.removeEntry(rosterEntry);
        }
    }

    return res;
}
项目:xmpp    文件:XmppTool.java   
/**
 * 添加到分组
 *
 * @param
 * @param userName
 * @param groupName
 */
public void addUserToGroup(String userName, String groupName) {
    Roster roster = con.getRoster();
    RosterGroup group = roster.getGroup(groupName);
    if (null == group) {
        group = roster.createGroup(groupName);
    }
    RosterEntry entry = roster.getEntry(userName);
    if (entry != null) {
        try {
            group.addEntry(entry);
        } catch (XMPPException e) {
            SLog.e(tag, Log.getStackTraceString(e));
        }
    }

}
项目:xmpp    文件:XmppTool.java   
/**
 * 获取某一个分组的成员
 *
 * @param
 * @param groupName
 * @return
 */
public List<RosterEntry> getEntrysByGroup(String groupName) {

    Roster roster = getCon().getRoster();
    List<RosterEntry> list = new ArrayList<RosterEntry>();
    RosterGroup group = roster.getGroup(groupName);
    Collection<RosterEntry> rosterEntiry = group.getEntries();
    Iterator<RosterEntry> iter = rosterEntiry.iterator();
    while (iter.hasNext()) {
        RosterEntry entry = iter.next();
        SLog.i("xmpptool", entry.getUser() + "\t" + entry.getName() + entry.getType().toString());
        if (entry.getType().toString().equals("both")) {
            list.add(entry);
        }

    }
    return list;

}
项目:xmpp    文件:XmppTool.java   
/**
 * 判断是否是好友
 *
 * @param
 * @param user
 * @return
 */
public boolean isFriendly(String user) {


    Roster roster = getCon().getRoster();
    List<RosterEntry> list = new ArrayList<RosterEntry>();
    list.addAll(roster.getEntries());
    for (int i = 0; i < list.size(); i++) {
        Log.i("xmppttttttttt", list.get(i).getUser().toUpperCase() + "\t" + user);
        if (list.get(i).getUser().contains(user.toLowerCase())) {
            if (list.get(i).getType().toString().equals("both")) {
                return true;
            } else {
                return false;
            }
        }
    }
    return false;

}
项目:communote-server    文件:XMPPConnector.java   
/**
 * This method sends a friend request to the user if he isn't already in the bots {@link Roster}
 * . {@inheritDoc}
 */
@Override
public void enableUser(String username) {
    if (!connection.isConnected()) {
        return;
    }
    Roster roster = connection.getRoster();
    if (roster != null && roster.getEntry(username) != null) {
        return;
    }
    try {
        String clientId = ClientAndChannelContextHolder.getClient().getClientId();
        Presence subscribe = new Presence(Presence.Type.subscribe);
        subscribe.setFrom(sender);
        subscribe.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
        connection.sendPacket(subscribe);
        Presence subscribed = new Presence(Presence.Type.subscribed);
        subscribed.setFrom(sender);
        subscribed.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
        connection.sendPacket(subscribed);
    } catch (NotConnectedException e) {
        LOG.debug("Could not send friendship request because XMPP connector is disconnected");
    }
}
项目:communote-server    文件:XMPPConnector.java   
/**
 * {@inheritDoc}
 *
 * @param username
 *            Has to be in the messagers format.
 */
@Override
public boolean isAvailable(String username) {
    if (connection.isConnected()) {
        Roster roster = connection.getRoster();
        if (roster != null) {
            Presence presence = roster.getPresence(username + XMPPPatternUtils.getUserSuffix());
            return presence.isAvailable();
        } else {
            LOG.debug("XMPP connection did not return a roster for communote bot");
        }
    } else {
        LOG.debug("Cannot check availability of user because XMPP connector is disconnected");
    }
    return false;
}
项目:AyoSunny    文件:ConstactFragment.java   
public void findFriends() {
    try {
        listGroup=new ArrayList<Group>();
        XMPPConnection conn = QQApplication.xmppConnection;
        Roster roster = conn.getRoster();
        Collection<RosterGroup> groups = roster.getGroups();
        for (RosterGroup group : groups) {
            Group mygroup=new Group();
            mygroup.setGroupName(group.getName());
            Collection<RosterEntry> entries = group.getEntries();
            List<Child> childList=new ArrayList<Child>();
            for (RosterEntry entry : entries) {
                if(entry.getType().name().equals("both")){
                    Child child=new Child();
                    child.setUsername(entry.getUser().split("@")[0]);
                    childList.add(child);
                }
            }
            mygroup.setChildList(childList);
            listGroup.add(mygroup);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:AyoSunny    文件:AddFriendActivity.java   
void showDialog(final String toUser){
    Builder bd=new Builder(AddFriendActivity.this);
    bd.setItems(new String[] {"添加为好友"}, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Roster roster=QQApplication.xmppConnection.getRoster();
                        XmppUtil.addGroup(roster, "我的好友");//先默认创建一个分组
                        XmppUtil.addUsers(roster,toUser+"@"+QQApplication.xmppConnection.getServiceName(), toUser,"我的好友");
                        //注意消息的协议格式 =》接收者卍发送者卍消息类型卍消息内容卍发送时间
                        String message=toUser+Const.SPLIT+I+Const.SPLIT+Const.MSG_TYPE_ADD_FRIEND+Const.SPLIT+"你好"+Const.SPLIT+new SimpleDateFormat("MM-dd HH:mm").format(new Date());
                        XmppUtil.sendMessage(QQApplication.xmppConnection, message,toUser);
                        sendInviteUser=toUser;
                        mHandler.sendEmptyMessage(2);
                    } catch (XMPPException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    });
    bd.create().show();
}
项目:AyoSunny    文件:XmppConnectionManager.java   
public XMPPConnection init() {
    Connection.DEBUG_ENABLED = false;
    ProviderManager pm = ProviderManager.getInstance();
    configure(pm);
    ConnectionConfiguration connectionConfig = new ConnectionConfiguration(Const.XMPP_HOST, Const.XMPP_PORT);
    // connectionConfig.setSASLAuthenticationEnabled(false);//
    // 不使用SASL验证,设置为false
    // connectionConfig
    // .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
    // 允许自动连接
    connectionConfig.setReconnectionAllowed(true);
    // 允许登陆成功后更新在线状态
    connectionConfig.setSendPresence(true);

    // 收到好友邀请后manual表示需要经过同意,accept_all表示不经同意自动为好友
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
    XMPPConnection connection = new XMPPConnection(connectionConfig);
    return connection;
}
项目:EIM    文件:ContacterManager.java   
/**
 * ������з�����ϵ��
 * 
 * @return
 */
public static List<MRosterGroup> getGroups(Roster roster) {
    if (contacters == null)
        throw new RuntimeException("contacters is null");

    List<MRosterGroup> groups = new ArrayList<ContacterManager.MRosterGroup>();
    groups.add(new MRosterGroup(Constant.ALL_FRIEND, getContacterList()));
    for (RosterGroup group : roster.getGroups()) {
        List<User> groupUsers = new ArrayList<User>();
        for (RosterEntry entry : group.getEntries()) {
            groupUsers.add(contacters.get(entry.getUser()));
        }
        groups.add(new MRosterGroup(group.getName(), groupUsers));
    }
    groups.add(new MRosterGroup(Constant.NO_GROUP_FRIEND,
            getNoGroupUserList(roster)));
    return groups;
}
项目:EIM    文件:ContacterManager.java   
/**
 * ����RosterEntry����һ��User
 * 
 * @param entry
 * @return
 */
public static User transEntryToUser(RosterEntry entry, Roster roster) {
    User user = new User();
    if (entry.getName() == null) {
        user.setName(StringUtil.getUserNameByJid(entry.getUser()));
    } else {
        user.setName(entry.getName());
    }
    user.setJID(entry.getUser());
    System.out.println(entry.getUser());
    Presence presence = roster.getPresence(entry.getUser());
    user.setFrom(presence.getFrom());
    user.setStatus(presence.getStatus());
    user.setSize(entry.getGroups().size());
    user.setAvailable(presence.isAvailable());
    user.setType(entry.getType());
    return user;
}
项目:EIM    文件:ContacterManager.java   
/**
 * �����û�jid�õ��û�
 * 
 * @param userJid
 * @param nickname
 */
public static User getByUserJid(String userJId, XMPPConnection connection) {
    Roster roster = connection.getRoster();
    RosterEntry entry = connection.getRoster().getEntry(userJId);
    if (null == entry) {
        return null;
    }
    User user = new User();
    if (entry.getName() == null) {
        user.setName(StringUtil.getUserNameByJid(entry.getUser()));
    } else {
        user.setName(entry.getName());
    }
    user.setJID(entry.getUser());
    System.out.println(entry.getUser());
    Presence presence = roster.getPresence(entry.getUser());
    user.setFrom(presence.getFrom());
    user.setStatus(presence.getStatus());
    user.setSize(entry.getGroups().size());
    user.setAvailable(presence.isAvailable());
    user.setType(entry.getType());
    return user;

}
项目:Gmail-Plugin    文件:GtalkConsole.java   
public void displayfrndslist()
{
    Roster rster = conn.getRoster();
    Collection<RosterEntry> records = rster.getEntries();
    System.out.println("\nTotal friends: "+records.size());
    int i = 1;
    String status = null;
    for(RosterEntry r:records)
    {
    Presence presence = rster.getPresence(r.getUser());
    if ((presence != null)){
    if(rster.getPresence(r.getUser()).toString().contains("away"))
    status = "idle";
    else if (rster.getPresence(r.getUser()).toString().contains("unavailable"))
    status = "offline";
    else if (rster.getPresence(r.getUser()).toString().contains("dnd"))
    status = "busy";
    else
    status = "available";
    System.out.println("(#" + i + ")"+r.getUser()+"---"+status);
    i++;
    }
    }
}
项目:androidsummary    文件:XmppConnectionManager.java   
/**
 * 初始化连接
 * @param loginConfig
 * @return
 */
public XMPPConnection init(IMConfig loginConfig) {
    Connection.DEBUG_ENABLED = false;
    ProviderManager pm = ProviderManager.getInstance();
    configure(pm);

    connectionConfig = new ConnectionConfiguration(
            loginConfig.getXmppHost(), loginConfig.getXmppPort(),
            loginConfig.getXmppServiceName());
    //connectionConfig.setSASLAuthenticationEnabled(false);// 不使用SASL验证,设置为false
    connectionConfig
            .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
    // 允许自动连接
    connectionConfig.setReconnectionAllowed(false);
    // 允许登陆成功后更新在线状态
    connectionConfig.setSendPresence(true);
    // 收到好友邀请后manual表示需要经过同意,accept_all表示不经同意自动为好友
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
    connection = new XMPPConnection(connectionConfig);
    return connection;
}
项目:androidsummary    文件:ContacterFragment.java   
public void initContacter(){
    mGroupNames.clear();
    mIMRosterGroups.clear();
    //增加分组
    try {
        Roster mRoster = IMUtil.getRoster();
        mGroupNames.addAll(IMUtil.getGroupNames(mRoster));
        mIMRosterGroups.addAll(IMUtil.getRosterGroups(mRoster));
    } catch (Exception e) {
        e.printStackTrace();
        mGroupNames.clear();
        mIMRosterGroups.clear();
    }
    mContacterListAdapter.notifyDataSetChanged();
    if(mGroupNames.size()>0){
        mListView.expandGroup(0);
    }

}
项目:androidsummary    文件:IMUtil.java   
/**
 * 获得花名册包含的分组列表
 */
public static List<IMRosterGroup> getRosterGroups(Roster roster) {

    List<IMRosterGroup> groups = new ArrayList<IMRosterGroup>();
    groups.add(new IMRosterGroup(IMConstant.ALL_FRIEND, getContacterList()));
    for (RosterGroup group : roster.getGroups()) {
        List<IMUser> users = new ArrayList<IMUser>();
        for (RosterEntry entry : group.getEntries()) {
            users.add(contacters.get(entry.getUser()));
        }
        groups.add(new IMRosterGroup(group.getName(), users));
    }
    groups.add(new IMRosterGroup(IMConstant.NO_GROUP_FRIEND,
            getNoGroupUserList(roster)));
    return groups;
}
项目:android_chat    文件:ThreadHelper.java   
public void updateUserList(Activity act) {
    if (!ThreadHelper.xmppConnection.isAuthenticated()) {
        if (D) Log.d(TAG, "XMPP connection is not authenticated!");
        return;
    }
    ArrayList<User> list = new ArrayList<User>();
    Roster roster = ThreadHelper.xmppConnection.getRoster();
    Iterator<RosterEntry> cit = roster.getEntries().iterator();
    while(cit.hasNext()) {
        RosterEntry entry = cit.next();
        VCard vCard = new VCard();
        try {
            vCard.load(ThreadHelper.xmppConnection, entry.getUser());
        } catch (XMPPException e) {
            Log.e(TAG, e.getMessage(), e);
        }
        list.add(new User(entry.getUser(), vCard.getNickName(),
                roster.getPresence(entry.getUser()).isAvailable()));
    }
    updateUserList(act, list);
}
项目:android_chat    文件:ListenerHandler.java   
@Override
public void handleMessage(Message message) {
    Bundle data = message.getData();
    String request = (String)message.obj;

    if (request.equals(Listener.MESSAGE) && data != null) {
        Roster roster = ThreadHelper.xmppConnection.getRoster();
        String user = data.getString(Listener.ID);
        String msg = data.getString(Listener.MESSAGE);

        if (th.D) Log.d(TAG, "Received user message!");
        if (!roster.contains(user)) {
            //TODO: request new user 
        } else {
            th.addDiscussionEntry(act, user, msg, false);
        }
    }
}
项目:League-of-Legends-XMPP-Chat-Library    文件:LolChat.java   
/**
 * Represents a single connection to a League of Legends chatserver.
 * 
 * @param server
 *            The chatserver of the region you want to connect to
 * @param friendRequestPolicy
 *            Determines how new Friend requests are treated.
 * @param riotApiKey
 *            Your apiKey used to convert summonerId's to name. You can get
 *            your key here <a
 *            href="https://developer.riotgames.com/">developer
 *            .riotgames.com</a>
 * 
 * @see LolChat#setFriendRequestPolicy(FriendRequestPolicy)
 * @see LolChat#setFriendRequestListener(FriendRequestListener)
 */
public LolChat(ChatServer server, FriendRequestPolicy friendRequestPolicy,
        RiotApiKey riotApiKey) {
    this.friendRequestPolicy = friendRequestPolicy;
    this.server = server;
    if (riotApiKey != null && server.api != null) {
        this.riotApi = RiotApi.build(riotApiKey, server);
    }
    Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
    final ConnectionConfiguration config = new ConnectionConfiguration(
            server.host, 5223, "pvp.net");
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
    config.setSocketFactory(SSLSocketFactory.getDefault());
    config.setCompressionEnabled(true);
    connection = new XMPPTCPConnection(config);

    addListeners();
}
项目:aceim    文件:XMPPRosterListener.java   
List<BuddyGroup> getContactList() {
    Roster roster = getInternalService().getConnection().getRoster();

    Collection<RosterEntry> entries = roster.getEntries();
    for (RosterEntry entry : entries) {
        if (entry.getName() == null) {
            try {
                VCard vc = new VCard();
                vc.load(getInternalService().getConnection(), entry.getUser());
                String nick = getNicknameFromVCard(vc);

                if (nick != null) {
                    entry.setName(nick);
                }
            } catch (XMPPException e) {
                Logger.log(e);
            }
        }
    }

    List<BuddyGroup> groups = getInternalService().getService().getEntityAdapter().rosterGroupCollection2BuddyGroupList(roster.getGroups(), entries, getInternalService().getOnlineInfo().getProtocolUid(), getInternalService().getService().getContext(), getInternalService().getService().getServiceId());
    return groups;
}
项目:aceim    文件:XMPPRosterListener.java   
void moveBuddy(final Buddy buddy) {
    new Thread() {
        @Override
        public void run() {
            try {
                Roster roster = getInternalService().getConnection().getRoster();
                roster.createEntry(buddy.getProtocolUid(), buddy.getName(), (buddy.getGroupId() != null && buddy.getGroupId().equals(ApiConstants.NO_GROUP_ID)) ? new String[] { buddy.getGroupId() } : new String[0]);
                buddy.setGroupId(buddy.getGroupId());
                getInternalService().getService().getCoreService().buddyAction(ItemAction.MODIFIED, buddy);
            } catch (XMPPException e) {
                Logger.log(e);
                getInternalService().getService().getCoreService().notification( e.getLocalizedMessage());
            }
        }
    }.start();
}
项目:aceim    文件:XMPPRosterListener.java   
void addBuddy(final Buddy buddy) {
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                XMPPCommonService service = getInternalService().getService();
                Roster roster = getInternalService().getConnection().getRoster();
                roster.createEntry(buddy.getProtocolUid(), buddy.getName(), (buddy.getGroupId() != null && !buddy.getGroupId().equals(ApiConstants.NO_GROUP_ID)) ? new String[] { buddy.getGroupId() } : new String[0]);
                service.getCoreService().buddyAction(
                        ItemAction.ADDED, 
                        service.getEntityAdapter().rosterEntry2Buddy(
                                roster.getEntry(buddy.getProtocolUid()), 
                                service.getProtocolUid(), 
                                service.getContext(), 
                                service.getServiceId()));
            } catch (XMPPException e) {
                Logger.log(e);
                getInternalService().getService().getCoreService().notification( e.getLocalizedMessage());
            }
        }
    };

    Executors.defaultThreadFactory().newThread(r).start();
}
项目:prive-android    文件:XmppConnectionTest.java   
@Before
public void setUp() throws Exception {
    app = new ImApp();
    con = new XmppConnection(app);
    roster = createMock(Roster.class);
    smackCon = createMock(MyXMPPConnection.class);
    expect(smackCon.getRoster()).andStubReturn(roster);
    Contact user = new Contact(new XmppAddress(TEST_CONTACT), TEST_CONTACT_NAME);
    con.initConnection(smackCon, user, XmppConnection.LOGGED_IN);
    contactListManager = con.getContactListManager();
    subscriptionRequestListener = createMock(SubscriptionRequestListener.class);
    contactListManager.setSubscriptionRequestListener(subscriptionRequestListener);
    listener = createMock(ContactListListener.class);
    contactListManager.addContactListListener(listener);
    expect(smackCon.isConnected()).andStubReturn(true);
}
项目:prive-android    文件:XmppConnection.java   
@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);
    }
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Returns the correct JID based on the number of resources signed in.
 *
 * @param jid the users jid.
 * @return the valid jid to use.
 */
public static String getValidJID(String jid) {
    Roster roster = SparkManager.getConnection().getRoster();
    Iterator<Presence> presences = roster.getPresences(jid);
    int count = 0;
    Presence p = null;
    if (presences.hasNext()) {
        p = presences.next();
        count++;
    }

    if (count == 1 && p != null) {
        return p.getFrom();
    }
    else {
        return jid;
    }
}
项目:spark-svn-mirror    文件:ContactList.java   
/**
 * Removes a contact item from the group.
 *
 * @param item the ContactItem to remove.
 */
private void removeContactFromGroup(ContactItem item) {
    String groupName = item.getGroupName();
    ContactGroup contactGroup = getContactGroup(groupName);
    Roster roster = SparkManager.getConnection().getRoster();
    RosterEntry entry = roster.getEntry(item.getJID());
    if (entry != null && contactGroup != offlineGroup) {
        try {
            RosterGroup rosterGroup = roster.getGroup(groupName);
            if (rosterGroup != null) {
                RosterEntry rosterEntry = rosterGroup.getEntry(entry.getUser());
                if (rosterEntry != null) {
                    rosterGroup.removeEntry(rosterEntry);
                }
            }
            contactGroup.removeContactItem(contactGroup.getContactItemByJID(item.getJID()));
            checkGroup(contactGroup);
        }
        catch (Exception e) {
            Log.error("Error removing user from contact list.", e);
        }
    }
}
项目:spark-svn-mirror    文件:TransferGroupUI.java   
public TransferGroupUI(String groupName) {
    setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
    setBackground(Color.white);

    final Roster roster = SparkManager.getConnection().getRoster();
    final RosterGroup rosterGroup = roster.getGroup(groupName);

    final List<RosterEntry> entries = new ArrayList<RosterEntry>(rosterGroup.getEntries());

    Collections.sort(entries, entryComparator);

    for (RosterEntry entry : entries) {
        final UserEntry userEntry = new UserEntry(entry);
        userEntries.add(userEntry);
        add(userEntry);
    }
}
项目:jmeter-bzm-plugins    文件:RosterAction.java   
private String rosterToString(Roster roster) {
    StringBuilder res = new StringBuilder();
    for (RosterEntry entry : roster.getEntries()) {
        res.append(entry.toString());
        res.append(':');
        res.append(roster.getPresence(entry.getUser()).toString());
        res.append('\n');
    }
    return res.toString();
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 获取所有好友
 * @param xmppConnection
 * @return
 */
public static List<RosterEntry> getAllRosterEntry(XMPPConnection xmppConnection){
    //获取花名册对象
    Roster roster=xmppConnection.getRoster();
    //获取所有好友
    Collection<RosterEntry> rosterEntries=roster.getEntries();
    return rosterEntries.stream().collect(Collectors.toList());
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 获取某个分组下的所有好友
 * @param xmppConnection
 * @param groupName
 * @return
 */
public static List<RosterEntry> getRosterEntrysForGroup(XMPPConnection xmppConnection,String groupName){
    // 获取花名册对象
    Roster roster = xmppConnection.getRoster();
    // 获取所有好友
    RosterGroup rosterGroup = roster.getGroup(groupName);
    Collection<RosterEntry> rosterEntries = rosterGroup.getEntries();
    return rosterEntries.stream().collect(Collectors.toList());
}
项目:xmpp    文件:XmppTool.java   
/** * ���һ���� */
public static boolean addGroup(Roster roster, String groupName) {
    try {
        roster.createGroup(groupName);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
项目:xmpp    文件:XmppTool.java   
/**
 * 添加好友
 *
 * @param
 * @param userName
 * @param name
 * @param groupName 是否有分组
 * @return
 */
public boolean addUser(String userName, String name, String groupName) {
    Roster roster = con.getRoster();
    try {
        roster.createEntry(userName, name, null == groupName ? null
                : new String[]{groupName});
        return true;
    } catch (XMPPException e) {
        SLog.e(tag, Log.getStackTraceString(e));
    }
    return false;
}
项目:xmpp    文件:XmppTool.java   
/**
 * 删除好友
 *
 * @param userName
 * @return
 */
public boolean removeUser(String userName) {
    Roster roster = con.getRoster();
    try {
        RosterEntry entry = roster.getEntry(userName);
        if (null != entry) {
            roster.removeEntry(entry);
        }
        return true;
    } catch (XMPPException e) {
        SLog.e(tag, Log.getStackTraceString(e));
    }
    return false;
}
项目:xmpp    文件:XmppTool.java   
/**
 * 获取所有分组
 *
 * @param
 * @return
 */
public List<RosterGroup> getGroups() {
    Roster roster = getCon().getRoster();
    List<RosterGroup> list = new ArrayList<RosterGroup>();
    list.addAll(roster.getGroups());
    return list;
}
项目:AyoSunny    文件:XmppUtil.java   
/**
 * 返回所有组信息 <RosterGroup>
 * @return List(RosterGroup)
 */
public static List<RosterGroup> getGroups(Roster roster) {
    List<RosterGroup> groupsList = new ArrayList<RosterGroup>();
    Collection<RosterGroup> rosterGroup = roster.getGroups();
    Iterator<RosterGroup> i = rosterGroup.iterator();
    while (i.hasNext())
        groupsList.add(i.next());
    return groupsList;
}
项目:AyoSunny    文件:XmppUtil.java   
/**
 * 返回相应(groupName)组里的所有用户<RosterEntry>
 * @return List(RosterEntry)
 */
public static List<RosterEntry> getEntriesByGroup(Roster roster,
        String groupName) {
    List<RosterEntry> EntriesList = new ArrayList<RosterEntry>();
    RosterGroup rosterGroup = roster.getGroup(groupName);
    Collection<RosterEntry> rosterEntry = rosterGroup.getEntries();
    Iterator<RosterEntry> i = rosterEntry.iterator();
    while (i.hasNext())
        EntriesList.add(i.next());
    return EntriesList;
}
项目:AyoSunny    文件:XmppUtil.java   
/**
 * 返回所有用户信息 <RosterEntry>
 * @return List(RosterEntry)
 */
public static List<RosterEntry> getAllEntries(Roster roster) {
    List<RosterEntry> EntriesList = new ArrayList<RosterEntry>();
    Collection<RosterEntry> rosterEntry = roster.getEntries();
    Iterator<RosterEntry> i = rosterEntry.iterator();
    while (i.hasNext()){
        RosterEntry rosterentry=  (RosterEntry) i.next();
        Log.e("jj", "好友:"+rosterentry.getUser()+","+rosterentry.getName()+","+rosterentry.getType().name());
        EntriesList.add(rosterentry);
    }
    return EntriesList;
}
项目:AyoSunny    文件:XmppUtil.java   
/** 
    * 创建一个组 
    */ 
public static boolean addGroup(Roster roster,String groupName)  
   {  
       try {  
           roster.createGroup(groupName);  
           return true;  
       } catch (Exception e) {  
           e.printStackTrace();  
           Log.e("jj", "创建分组异常:"+e.getMessage());
           return false;  
       }  
   }
项目:AyoSunny    文件:XmppUtil.java   
/**
 * 添加一个好友  无分组
 */
public static boolean addUser(Roster roster,String userName,String name)
{
    try {
        roster.createEntry(userName, name, null);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

}
项目:AyoSunny    文件:XmppUtil.java   
/**
 * 添加一个好友到分组
 * @param roster
 * @param userName
 * @param name
 * @return
 */
public static boolean addUsers(Roster roster,String userName,String name,String groupName)
{
    try {
        roster.createEntry(userName, name,new String[]{ groupName});
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("jj", "添加好友异常:"+e.getMessage());
        return false;
    }

}