本文整理汇总了Java中org.jivesoftware.smack.roster.RosterEntry类的典型用法代码示例。如果您正苦于以下问题:Java RosterEntry类的具体用法?Java RosterEntry怎么用?Java RosterEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RosterEntry类属于org.jivesoftware.smack.roster包,在下文中一共展示了RosterEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listRoster
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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];
}
示例2: run
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的package包/类
@Override
public void run(){
Roster roster = xmppManager.getRoster();
if (roster != null && !roster.isLoaded())
try{
roster.reloadAndWait();
Log.d("SERVICE_DEBUG", "reloaded roster");
}catch (Exception e){
Log.e("SERVICE_ERROR", "Couldn't load the roster");
e.printStackTrace();
}
if (roster != null){
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries)
presenceReceived(roster.getPresence(entry.getUser()));
roster.addRosterListener(rosterListener);
}
}
示例3: rebuildRoster
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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();
}
示例4: getRosterEntryFor
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的package包/类
private XmppRosterEntry getRosterEntryFor(Roster roster, RosterEntry entry) {
XmppRosterEntry newEntry = new XmppRosterEntry();
newEntry.setXmppJID(entry.getUser())
.setAlias(entry.getName())
.setAvatar(getCachedAvatar(entry.getUser()));
if (newEntry.getAvatar() == null) {
newEntry.setAvatar(getAvatarFor(entry.getUser()));
}
Presence presence = roster.getPresence(entry.getUser());
newEntry.setAvailable(presence.isAvailable())
.setPresenceMode(presence.getMode().ordinal())
.setPersonalMessage(presence.getStatus());
newEntry.setUnreadMessages(mMessagesProvider.countUnreadMessages(mAccount.getXmppJid(), entry.getUser()));
return newEntry;
}
示例5: addRosterEntry
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的package包/类
/**
* Adds a roster entry to the packet.
*
* @param rosterEntry a roster entry to add.
*/
public void addRosterEntry(RosterEntry rosterEntry) {
// Obtain a String[] from the roster entry groups name
List<String> groupNamesList = new ArrayList<String>();
String[] groupNames;
for (RosterGroup group : rosterEntry.getGroups()) {
groupNamesList.add(group.getName());
}
groupNames = groupNamesList.toArray(new String[groupNamesList.size()]);
// Create a new Entry based on the rosterEntry and add it to the packet
RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getUser(),
rosterEntry.getName(), groupNames);
addRosterEntry(remoteRosterEntry);
}
示例6: doSetContactName
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的package包/类
@Override
protected void doSetContactName(String address, String name) throws ImException {
Contact contact = getContact(address);
contact.setName(name);
Contact[] contacts = {contact};
notifyContactsPresenceUpdated(contacts);
// set name
try {
RosterEntry entry = mRoster.getEntry(JidCreate.bareFrom(address));
// confirm entry still exists
if (entry == null) {
return;
}
entry.setName(name);
}
catch (Exception e)
{
throw new ImException(e.toString());
}
}
示例7: entriesUpdated
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的package包/类
@Override
public void entriesUpdated(Collection<Jid> addresses) {
final MessageCenterService service = mService.get();
final PresenceListener presenceListener = mPresenceListener.get();
if (service == null || presenceListener == null)
return;
// we got an updated roster entry
// check if it's a subscription "both"
for (Jid jid : addresses) {
RosterEntry e = service.getRosterEntry(jid.asBareJid());
if (e != null && e.canSeeHisPresence()) {
userSubscribed(service, presenceListener, jid);
}
}
}
示例8: broadcastPresence
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的package包/类
private void broadcastPresence(Roster roster, RosterEntry entry, BareJid jid, String id) {
// this method might be called async
final LocalBroadcastManager lbm = mLocalBroadcastManager;
if (lbm == null)
return;
Intent i;
// entry present and not pending subscription
if (isRosterEntrySubscribed(entry) || Authenticator.isSelfJID(this, jid)) {
// roster entry found, look for presence
Presence presence = roster.getPresence(jid);
i = PresenceListener.createIntent(this, presence, entry);
}
else {
// null type indicates no roster entry found or not authorized
i = new Intent(ACTION_PRESENCE);
i.putExtra(EXTRA_FROM, jid.toString());
}
// to keep track of request-reply
i.putExtra(EXTRA_PACKET_ID, id);
lbm.sendBroadcast(i);
}
示例9: getContact
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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;
}
示例10: entriesAdded
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的package包/类
/**
* NOTE: on every (re-)connect all entries are added again (loaded),
* one method call for all contacts.
*/
@Override
public void entriesAdded(Collection<Jid> addresses) {
if (mRoster == null || !mLoaded)
return;
for (Jid jid: addresses) {
RosterEntry entry = mRoster.getEntry(jid.asBareJid());
if (entry == null) {
LOGGER.warning("jid not in roster: "+jid);
return;
}
LOGGER.config("entry: "+entry.toString());
mHandler.onEntryAdded(clientToModel(entry));
}
}
示例11: removeFromRoster
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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;
}
示例12: updateRosterEntry
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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);
}
}
示例13: removeAllContacts
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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);
}
}
示例14: getContacts
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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;
}
示例15: getContactsWithSubscriptionPending
import org.jivesoftware.smack.roster.RosterEntry; //导入依赖的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;
}