org.jivesoftware.smack.RosterGroup Java Examples
The following examples show how to use
org.jivesoftware.smack.RosterGroup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FriendFragment.java From xmpp with Apache License 2.0 | 6 votes |
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { GroupHolder holder; if (convertView == null) { holder = new GroupHolder(); convertView = LayoutInflater.from(getActivity()).inflate(R.layout.friend_group_layout, parent, false); holder.tv = (TextView) convertView.findViewById(R.id.textView); holder.iv = (ImageView) convertView.findViewById(R.id.imageView); convertView.setTag(holder); } else { holder = (GroupHolder) convertView.getTag(); } if (isExpanded) { holder.iv.setImageResource(R.mipmap.friend_group_point_xia); } else { holder.iv.setImageResource(R.mipmap.friend_group_point); } RosterGroup group = (RosterGroup) getGroup(groupPosition); holder.tv.setText(group.getName() + "[" + childs.get(groups.get(groupPosition)).size() + "]"); return convertView; }
Example #2
Source File: XmppTool.java From xmpp with Apache License 2.0 | 6 votes |
/** * 添加到分组 * * @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)); } } }
Example #3
Source File: XmppTool.java From xmpp with Apache License 2.0 | 6 votes |
/** * 获取某一个分组的成员 * * @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; }
Example #4
Source File: InstantMessagingClient.java From olat with Apache License 2.0 | 6 votes |
/** * Used by Velocity renderer * * @param groupname * @return a String representing the online buddies out of the number of total buddies for a single group like (3/5) */ protected String buddyCountOnlineForGroup(final String groupname) { final RosterGroup rosterGroup = connection.getRoster().getGroup(groupname); int buddyEntries = rosterGroup.getEntryCount(); final int allBuddies = buddyEntries; for (final Iterator I = rosterGroup.getEntries().iterator(); I.hasNext();) { final RosterEntry entry = (RosterEntry) I.next(); final Presence presence = connection.getRoster().getPresence(entry.getUser()); if (presence.getType() == Presence.Type.unavailable) { buddyEntries--; } } // final string looks like e.g. "(3/5)" final StringBuilder sb = new StringBuilder(10); sb.append("("); sb.append(buddyEntries); sb.append("/"); sb.append(allBuddies); sb.append(")"); return sb.toString(); }
Example #5
Source File: InstantMessagingClient.java From olat with Apache License 2.0 | 6 votes |
/** * Used by Velocity renderer * * @param groupname * @return a String representing the online buddies out of the number of total buddies for a single group like (3/5) */ protected String buddyCountOnlineForGroup(final String groupname) { final RosterGroup rosterGroup = connection.getRoster().getGroup(groupname); int buddyEntries = rosterGroup.getEntryCount(); final int allBuddies = buddyEntries; for (final Iterator I = rosterGroup.getEntries().iterator(); I.hasNext();) { final RosterEntry entry = (RosterEntry) I.next(); final Presence presence = connection.getRoster().getPresence(entry.getUser()); if (presence.getType() == Presence.Type.unavailable) { buddyEntries--; } } // final string looks like e.g. "(3/5)" final StringBuilder sb = new StringBuilder(10); sb.append("("); sb.append(buddyEntries); sb.append("/"); sb.append(allBuddies); sb.append(")"); return sb.toString(); }
Example #6
Source File: ContactStore.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Removes old mappings and set new Group mapping. * * @param contact * @param groups if list is empty added to default group * @return true if group mapping was changed */ boolean setContactGroups(XMPPContact contact, Collection<RosterGroup> groups) { List<String> groupNames; if (groups.isEmpty()) { groupNames = Collections.singletonList(NO_GROUP); } else { groupNames = groups.stream().map(RosterGroup::getName).collect(Collectors.toList()); } boolean removeChanged = removeContactFromGroupsExcluding(contact, groupNames); boolean addChanged = addContactToGroups(contact, groupNames); return removeChanged || addChanged; }
Example #7
Source File: ContactStore.java From saros with GNU General Public License v2.0 | 5 votes |
/** * This method asks the roster for contacts and fill its store. * * @param roster current Roster */ void init(Roster roster) { addContacts(NO_GROUP, rosterEntriesToXMPPContacts(roster.getUnfiledEntries())); for (RosterGroup group : roster.getGroups()) { addContacts(group.getName(), rosterEntriesToXMPPContacts(group.getEntries())); } }
Example #8
Source File: Friend.java From League-of-Legends-XMPP-Chat-Library with MIT License | 5 votes |
/** * Gets the FriendGroup that contains this friend. * * @return the FriendGroup that currently contains this Friend or null if * this Friend is not in a FriendGroup. */ public FriendGroup getGroup() { final Collection<RosterGroup> groups = get().getGroups(); if (groups.size() > 0) { return new FriendGroup(api, con, get().getGroups().iterator() .next()); } return null; }
Example #9
Source File: LolChat.java From League-of-Legends-XMPP-Chat-Library with MIT License | 5 votes |
/** * Get a list of all your FriendGroups. * * @return A List of all your FriendGroups */ public List<FriendGroup> getFriendGroups() { final ArrayList<FriendGroup> groups = new ArrayList<>(); for (final RosterGroup g : connection.getRoster().getGroups()) { groups.add(new FriendGroup(this, connection, g)); } return groups; }
Example #10
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 获得某个组里面的所有好友 * * @param roster * @param groupName 组名 * @return */ public List<RosterEntry> getEntriesByGroup(Roster roster, String groupName) { List<RosterEntry> entriesList = new ArrayList<RosterEntry>(); RosterGroup rosterGroup = roster.getGroup(groupName); Collection<RosterEntry> rosterEntries = rosterGroup.getEntries(); Iterator<RosterEntry> i = rosterEntries.iterator(); while (i.hasNext()) { entriesList.add(i.next()); } return entriesList; }
Example #11
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 获得所有组 * * @param roster * @return 所有组集合 */ public List<RosterGroup> getGroups(Roster roster) { List<RosterGroup> groupList = new ArrayList<RosterGroup>(); Collection<RosterGroup> rosterGroups = roster.getGroups(); Iterator<RosterGroup> i = rosterGroups.iterator(); while (i.hasNext()) { groupList.add(i.next()); } return groupList; }
Example #12
Source File: XmppConnection.java From weixin with Apache License 2.0 | 5 votes |
/** * 获取某个组里面的所有好友 * * @param roster * @param groupName 组名 * @return */ public List<RosterEntry> getEntriesByGroup(String groupName) { if (getConnection() == null) return null; List<RosterEntry> Entrieslist = new ArrayList<RosterEntry>(); RosterGroup rosterGroup = getConnection().getRoster().getGroup(groupName); Collection<RosterEntry> rosterEntry = rosterGroup.getEntries(); Iterator<RosterEntry> i = rosterEntry.iterator(); while (i.hasNext()) { Entrieslist.add(i.next()); } return Entrieslist; }
Example #13
Source File: XmppConnection.java From weixin with Apache License 2.0 | 5 votes |
/** * 获取所有组 * * @return 所有组集合 */ public List<RosterGroup> getGroups() { if (getConnection() == null) return null; List<RosterGroup> grouplist = new ArrayList<RosterGroup>(); Collection<RosterGroup> rosterGroup = getConnection().getRoster().getGroups(); Iterator<RosterGroup> i = rosterGroup.iterator(); while (i.hasNext()) { grouplist.add(i.next()); } return grouplist; }
Example #14
Source File: ClientHelper.java From olat with Apache License 2.0 | 5 votes |
/** * @return a List */ public List<RosterGroup> getRoster() { if (imc.isConnected()) { final List<RosterGroup> groups = new ArrayList<RosterGroup>(); for (final Iterator<RosterGroup> i = imc.getRoster().getGroups().iterator(); i.hasNext();) { groups.add(i.next()); } return groups; } return new ArrayList<RosterGroup>(0); }
Example #15
Source File: ClientHelper.java From olat with Apache License 2.0 | 5 votes |
/** * @return a List */ public List<RosterGroup> getRoster() { if (imc.isConnected()) { final List<RosterGroup> groups = new ArrayList<RosterGroup>(); for (final Iterator<RosterGroup> i = imc.getRoster().getGroups().iterator(); i.hasNext();) { groups.add(i.next()); } return groups; } return new ArrayList<RosterGroup>(0); }
Example #16
Source File: XmppTool.java From xmpp with Apache License 2.0 | 5 votes |
/** * 获取所有分组 * * @param * @return */ public List<RosterGroup> getGroups() { Roster roster = getCon().getRoster(); List<RosterGroup> list = new ArrayList<RosterGroup>(); list.addAll(roster.getGroups()); return list; }
Example #17
Source File: YiIMUtils.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
public static int deleteGroup(Context context, long groupId) { String owner = UserInfo.getUserInfo(context).getUser(); Cursor groupCursor = null; Cursor entriesCursor = null; Cursor defaultGroupCursor = null; try { groupCursor = context.getContentResolver().query( ContentUris.withAppendedId(RosterGroupColumns.CONTENT_URI, groupId), new String[] { RosterGroupColumns.NAME }, null, null, null); if (groupCursor == null || groupCursor.getCount() != 1) { return -1; } groupCursor.moveToFirst(); String groupName = groupCursor.getString(0); if ("unfiled".equals(groupName)) { return -2; } defaultGroupCursor = context.getContentResolver().query( RosterGroupColumns.CONTENT_URI, new String[] { RosterGroupColumns._ID }, RosterGroupColumns.NAME + "='unfiled' and " + RosterGroupColumns.OWNER + "='" + owner + "'", null, null); if (defaultGroupCursor == null || defaultGroupCursor.getCount() != 1) { return -1; } defaultGroupCursor.moveToFirst(); int defaultGroupId = defaultGroupCursor.getInt(0); XMPPConnection connection = XmppConnectionUtils.getInstance() .getConnection(); if (connection == null || !connection.isConnected() || !connection.isAuthenticated()) { return -1; } RosterGroup rosterGroup = connection.getRoster() .getGroup(groupName); if (rosterGroup == null) { return -1; } Collection<RosterEntry> entries = rosterGroup.getEntries(); if (entries != null && entries.size() > 0) { for (RosterEntry rosterEntry : entries) { rosterGroup.removeEntry(rosterEntry); } } entriesCursor = context.getContentResolver().query( RosterColumns.CONTENT_URI, new String[] { RosterColumns._ID }, RosterColumns.GROUP_ID + "=" + groupId, null, null); List<Integer> mIntegers = new ArrayList<Integer>(); if (entriesCursor != null && entriesCursor.getCount() > 0) { entriesCursor.moveToFirst(); do { mIntegers.add(entriesCursor.getInt(0)); } while (entriesCursor.moveToNext()); } for (Integer integer : mIntegers) { ContentValues values = new ContentValues(); values.put(RosterColumns.GROUP_ID, defaultGroupId); context.getContentResolver().update( ContentUris.withAppendedId(RosterColumns.CONTENT_URI, integer), values, null, null); } context.getContentResolver().delete( ContentUris.withAppendedId(RosterGroupColumns.CONTENT_URI, groupId), null, null); return 0; } catch (Exception e) { return -1; } finally { if (groupCursor != null) { groupCursor.close(); groupCursor = null; } if (entriesCursor != null) { entriesCursor.close(); entriesCursor = null; } if (defaultGroupCursor != null) { defaultGroupCursor.close(); defaultGroupCursor = null; } } }
Example #18
Source File: FriendGroup.java From League-of-Legends-XMPP-Chat-Library with MIT License | 4 votes |
public FriendGroup(LolChat api, XMPPConnection con, RosterGroup group) { super(api, con, group); }
Example #19
Source File: FriendFragment.java From xmpp with Apache License 2.0 | 4 votes |
public void getData() { if (XmppTool.getInstance().isConnection() == false) { ToastUtil.show(getActivity(), "已断开,正在重连中...."); return; } new Thread() { @Override public void run() { // TODO Auto-generated method stub super.run(); groups = XmppTool.getInstance().getGroups(); childs = new HashMap<RosterGroup, List<XmppFriend>>(); HashMap<String, Object> map = XmppService.map; for (int i = 0; i < groups.size(); i++) { List<RosterEntry> child = XmppTool.getInstance().getEntrysByGroup(groups.get(i).getName()); List<XmppFriend> lists = new ArrayList<XmppFriend>(); list_is_open.add(groups.get(i).getName()); for (int j = 0; j < child.size(); j++) { List<XmppUser> list = XmppTool.getInstance().searchUsers(child.get(j).getUser().split("@")[0]); // String str[] = list.get(0).getName().split(";"); User users = new Gson().fromJson(list.get(0).getName(), User.class); int status = 6; if (map.containsKey(users.getUser())) { status = (int) map.get(users.getUser()); } XmppFriend xf = new XmppFriend(users, status); lists.add(xf); } Collections.sort(lists, COMPARATOR); childs.put(groups.get(i), lists); } handler.sendEmptyMessage(1); } }.start(); }
Example #20
Source File: LolChat.java From League-of-Legends-XMPP-Chat-Library with MIT License | 3 votes |
/** * Creates a new FriendGroup. If this FriendGroup contains no Friends when * you logout it will be erased from the server. * * @param name * The name of this FriendGroup * @return The new FriendGroup or null if a FriendGroup with this name * already exists. */ public FriendGroup addFriendGroup(String name) { final RosterGroup g = connection.getRoster().createGroup(name); if (g != null) { return new FriendGroup(this, connection, g); } return null; }
Example #21
Source File: LolChat.java From League-of-Legends-XMPP-Chat-Library with MIT License | 3 votes |
/** * Gets a FriendGroup by name, for example "Duo Partners". The name is case * sensitive! The FriendGroup will be created if it didn't exist yet. * * @param name * The name of your group (case-sensitive) * @return The corresponding FriendGroup */ public FriendGroup getFriendGroupByName(String name) { final RosterGroup g = connection.getRoster().getGroup(name); if (g != null) { return new FriendGroup(this, connection, g); } return addFriendGroup(name); }