本文整理汇总了Java中org.jivesoftware.smack.roster.Roster类的典型用法代码示例。如果您正苦于以下问题:Java Roster类的具体用法?Java Roster怎么用?Java Roster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Roster类属于org.jivesoftware.smack.roster包,在下文中一共展示了Roster类的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);
}
示例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);
}
示例3: onDestroy
import org.jivesoftware.smack.roster.Roster; //导入依赖的package包/类
@SuppressLint("NewApi")
@Override
protected void onDestroy() {
// XMPP.getInstance().getConnection(acitiviy).getRoster()
// .removeRosterListener(rosterListener);
Roster.getInstanceFor(XMPP.getInstance().getConnection(acitiviy)).removeRosterListener(rosterListener);
ChatManager.getInstanceFor(XMPP.getInstance().getConnection(acitiviy))
.removeChatListener(chatListener);
if (chat != null && messageListener != null) {
chat.removeMessageListener(messageListener);
}
if (popupWindow != null) {
popupWindow.dismiss();
}
if (emoticonsCover != null) {
emoticonsCover.setVisibility(View.GONE);
}
// actionBar.setIcon(R.drawable.ic_launcher);
super.onDestroy();
}
示例4: 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];
}
示例5: run
import org.jivesoftware.smack.roster.Roster; //导入依赖的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);
}
}
示例6: disconnect
import org.jivesoftware.smack.roster.Roster; //导入依赖的package包/类
/**
* Remove all connection & packet listeners and disconnect XMPP connection.
*/
public void disconnect() {
if (null != connection && connection.isConnected()) {
// Remove listeners
Roster.getInstanceFor(connection).removeRosterListener(onlineRosterListener);
connection.removeAsyncStanzaListener(packetListener);
connection.removeAsyncStanzaListener(taskStatusListener);
connection.removeAsyncStanzaListener(policyStatusListener);
connection.removeAsyncStanzaListener(registrationListener);
connection.removeAsyncStanzaListener(userSessionListener);
connection.removeAsyncStanzaListener(missingPluginListener);
connection.removeAsyncStanzaListener(policyListener);
connection.removeAsyncStanzaListener(connectionListener);
connection.removeAsyncStanzaListener(reqAggrementListener);
connection.removeAsyncStanzaListener(aggrementStatusListener);
connection.removeAsyncStanzaListener(scriptResultListener);
connection.removeConnectionListener(connectionListener);
logger.debug("Listeners are removed.");
PingManager.getInstanceFor(connection).setPingInterval(-1);
logger.debug("Disabled ping manager");
connection.disconnect();
logger.info("Successfully closed XMPP connection.");
}
}
示例7: authenticated
import org.jivesoftware.smack.roster.Roster; //导入依赖的package包/类
@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
if (resumed) {
Logger.debug(TAG, "authenticated after resumption");
} else {
Logger.debug(TAG, "authenticated");
}
XmppService.setConnected(true);
try {
sendPendingMessages();
Roster.getInstanceFor(mConnection).reload();
} catch (Exception exc) {
Logger.info(TAG, "Failed to automatically send pending messages on authentication");
}
}
示例8: 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();
}
示例9: getRosterEntryFor
import org.jivesoftware.smack.roster.Roster; //导入依赖的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;
}
示例10: onRosterLoaded
import org.jivesoftware.smack.roster.Roster; //导入依赖的package包/类
@Override
public void onRosterLoaded(Roster roster) {
final MessageCenterService service = mService.get();
if (service == null)
return;
final Handler handler = service.mHandler;
if (handler != null) {
handler.post(new Runnable() {
@Override
public void run() {
// send pending subscription replies
service.sendPendingSubscriptionReplies();
// resend failed and pending messages
service.resendPendingMessages(false, false);
// resend failed and pending received receipts
service.resendPendingReceipts();
// roster has been loaded
service.broadcast(MessageCenterService.ACTION_ROSTER_LOADED);
}
});
}
}
示例11: broadcastPresence
import org.jivesoftware.smack.roster.Roster; //导入依赖的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);
}
示例12: initialize
import org.jivesoftware.smack.roster.Roster; //导入依赖的package包/类
public static void initialize(Context context) {
if (!sInitialized) {
disableSmackDefault();
InputStream is = context.getResources().openRawResource(R.raw.service);
ProviderManager.addLoader(new ProviderFileLoader(is));
try {
is.close();
}
catch (IOException ignored) {
}
// FIXME these got to be fixed somehow (VCard4 is not even used anymore)
ProviderManager.addIQProvider(VCard4.ELEMENT_NAME, VCard4.NAMESPACE, new VCard4.Provider());
ProviderManager.addIQProvider(ServerlistCommand.ELEMENT_NAME, ServerlistCommand.NAMESPACE, new ServerlistCommand.ResultProvider());
// do not append Smack version
VersionManager.setAutoAppendSmackVersion(false);
// we want to manually handle roster stuff
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
sInitialized = true;
}
}
示例13: 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();
}
示例14: addToRoster
import org.jivesoftware.smack.roster.Roster; //导入依赖的package包/类
public boolean addToRoster(JID jid, String name) {
if (!this.isConnected()) {
LOGGER.info("not connected");
return false;
}
if (!jid.isValid()) {
LOGGER.warning("invalid JID: " + jid);
return false;
}
try {
// also sends presence subscription request
Roster.getInstanceFor(mConn).createEntry(jid.toBareSmack(), name,
null);
} catch (SmackException.NotLoggedInException |
SmackException.NoResponseException |
XMPPException.XMPPErrorException |
SmackException.NotConnectedException |
InterruptedException ex) {
LOGGER.log(Level.WARNING, "can't add contact to roster", ex);
return false;
}
return true;
}
示例15: 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;
}