@Override public void setStatusFromConfig() {// 设置自己的当前状态,供外部服务调用 boolean messageCarbons = PreferenceUtils.getPrefBoolean(mService, PreferenceConstants.MESSAGE_CARBONS, true); String statusMode = PreferenceUtils.getPrefString(mService, PreferenceConstants.STATUS_MODE, PreferenceConstants.AVAILABLE); String statusMessage = PreferenceUtils.getPrefString(mService, PreferenceConstants.STATUS_MESSAGE, mService.getString(R.string.status_online)); int priority = PreferenceUtils.getPrefInt(mService, PreferenceConstants.PRIORITY, 0); if (messageCarbons) CarbonManager.getInstanceFor(mXMPPConnection).sendCarbonsEnabled( true); Presence presence = new Presence(Presence.Type.available); Mode mode = Mode.valueOf(statusMode); presence.setMode(mode); presence.setStatus(statusMessage); presence.setPriority(priority); mXMPPConnection.sendPacket(presence); }
public byte xmppPresence2UserStatus(Presence presence) { if (presence == null || presence.getType() != Type.available){ return -1; } if (presence.getMode() == null || presence.getMode() == Mode.available){ return 0; } for (byte i=0; i<presenceModes.length; i++) { Mode m = presenceModes[i]; if (m == presence.getMode()){ return i; } } return -1; }
/** * Get the smack presence mode for a status. * @param status the status in beem * @return the presence mode to use in presence packet or null if there is no mode to use */ public static Presence.Mode getPresenceModeFromStatus(final int status) { Presence.Mode res; switch (status) { case CONTACT_STATUS_AVAILABLE: res = Presence.Mode.available; break; case CONTACT_STATUS_AVAILABLE_FOR_CHAT: res = Presence.Mode.chat; break; case CONTACT_STATUS_AWAY: res = Presence.Mode.away; break; case CONTACT_STATUS_BUSY: res = Presence.Mode.dnd; break; case CONTACT_STATUS_UNAVAILABLE: res = Presence.Mode.xa; break; default: return null; } return res; }
/** * Update the contact informations. */ private void updateContactInformations() { // Check for a contact name update String name = mContact.getName(); String res = mContact.getSelectedRes(); if (!"".equals(res)) name += "(" + res + ")"; if (!mCompact) { if (!(mContactNameTextView.getText().toString().equals(name))) mContactNameTextView.setText(name); //Check for a contact status message update if (!(mContactStatusMsgTextView.getText().toString().equals(mContact.getMsgState()))) { mContactStatusMsgTextView.setText(mContact.getMsgState()); Linkify.addLinks(mContactStatusMsgTextView, Linkify.WEB_URLS); } } else { Mode m = Status.getPresenceModeFromStatus(mContact.getStatus()); if (m == null) setTitle(getString(R.string.chat_name) + " " + name + " (" + getString(R.string.contact_status_msg_offline) + ")"); else setTitle(getString(R.string.chat_name) + " " + name + " (" + m.name() + ")"); } }
@Override public void sendPresence(JID jabberId, PresenceType type, PresenceShow show, String status, JID fromJid) { checkNotNull(jabberId); final Type presenceType = type == null ? Type.available : Type.valueOf(type.name().toLowerCase()); final Mode presenceMode = show == null ? null : Mode.valueOf(show.name().toLowerCase()); org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(presenceType, status, 1, presenceMode); presence.setFrom(fromJid == null ? null : fromJid.getId()); presence.setTo(jabberId.getId()); this.session_.getConnection().sendPacket(presence); }
public void setStatusFromConfig() { // TODO: only call this when carbons changed, not on every presence change CarbonManager.getInstanceFor(mXMPPConnection).sendCarbonsEnabled(mConfig.messageCarbons); Presence presence = new Presence(Presence.Type.available); Mode mode = Mode.valueOf(mConfig.statusMode); presence.setMode(mode); presence.setStatus(mConfig.statusMessage); presence.setPriority(mConfig.priority); mXMPPConnection.sendPacket(presence); mConfig.presence_required = false; }
protected static int parsePresence(org.jivesoftware.smack.packet.Presence presence) { int type = Presence.AVAILABLE; Mode rmode = presence.getMode(); Type rtype = presence.getType(); if (rmode == Mode.away || rmode == Mode.xa) type = Presence.AWAY; else if (rmode == Mode.dnd) type = Presence.DO_NOT_DISTURB; else if (rtype == Type.unavailable || rtype == Type.error) type = Presence.OFFLINE; return type; }
/** * Get the status of from a presence packet. * @param presence the presence containing status * @return an int representing the status */ public static int getStatusFromPresence(final Presence presence) { int res = Status.CONTACT_STATUS_DISCONNECT; if (presence.getType().equals(Presence.Type.unavailable)) { res = Status.CONTACT_STATUS_DISCONNECT; } else { Mode mode = presence.getMode(); if (mode == null) { res = Status.CONTACT_STATUS_AVAILABLE; } else { switch (mode) { case available: res = Status.CONTACT_STATUS_AVAILABLE; break; case away: res = Status.CONTACT_STATUS_AWAY; break; case chat: res = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT; break; case dnd: res = Status.CONTACT_STATUS_BUSY; break; case xa: res = Status.CONTACT_STATUS_UNAVAILABLE; break; default: res = Status.CONTACT_STATUS_DISCONNECT; break; } } } return res; }
public XmppLoginRunnable(XmppListener listener) { super(listener); mType = Type.available; mMode = Mode.available; mStatus = null; }
public void setMode(Mode mode) { this.mMode = mode; }
/** * @param type * @param status * @param priority * @param mode */ public void sendPresence(final Type type, final String status, final int priority, final Mode mode) { imc.sendPresence(type, status, priority, mode); }
/** * send a presence packet "available" with a certain mode e.g. "away" to all buddies * * @param mode */ public void sendPresenceAvailable(final Presence.Mode mode) { imc.sendPresence(Presence.Type.available, null, 0, mode); }