Java 类org.jivesoftware.smackx.iqlast.packet.LastActivity 实例源码

项目:Zom-Android    文件:XmppConnection.java   
private void getLastSeen (Contact contact)
{
    if (getState() == ImConnection.LOGGED_IN) {
        try {
            LastActivity activity = mLastActivityManager.getLastActivity(JidCreate.bareFrom(contact.getAddress().getBareAddress()));

            if (activity != null) {
                Presence presence = new Presence();
                Date now = new Date();
                presence.setLastSeen(new Date(now.getTime() - (activity.getIdleTime() * 1000)));
                contact.setPresence(presence);
            }

        } catch (Exception e) {
            debug("LastActivity", "error getting last activity for: " + contact.getAddress().getAddress());
        }
    }
}
项目:desktopclient-java    文件:LastActivityListener.java   
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException {
    LOGGER.config("last activity: " + packet);

    LastActivity lastActivity = (LastActivity) packet;

    long lastActivityTime = lastActivity.getIdleTime();
    if (lastActivityTime < 0) {
        // error message or parsing error, not important here (logged by Client class)
        return;
    }

    mControl.onLastActivity(JID.fromSmack(lastActivity.getFrom()),
            lastActivity.getIdleTime(),
            StringUtils.defaultString(lastActivity.getStatusMessage()));
}
项目:X-Messenger    文件:XMPPManager.java   
public String getLastSeenMessage(String jid) {
    if (!isConnected() || !connection.isAuthenticated()) {
        return LocaleController.getString("Offline", R.string.Offline);
    }
    try {
        LastActivityManager lastActivityManager = LastActivityManager.getInstanceFor(connection);
        LastActivity activity = lastActivityManager.getLastActivity(JidCreate.bareFrom(jid));

        int lastSeenBySeconds = Utilities.parseInt(activity.lastActivity + "");

        String lastSeenMessage = "";
        lastSeenMessage = LocaleController.getString("Offline", R.string.Offline);
        if (lastSeenBySeconds >= 1) {
            PrettyTime p = new PrettyTime();
            Date date = new Date();
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.SECOND, -1 * lastSeenBySeconds);

            lastSeenMessage = LocaleController.formatDateOnline(cal.getTime()); //p.format(cal.getTime());
        } else {
            lastSeenMessage = LocaleController.getString("Offline", R.string.Offline);
        }
        //FileLog.e("LAST ACTIVITY","" + ""+ "" + lastSeenBySeconds +"  "+jid);
        return lastSeenMessage;

    } catch (Exception e) {
        e.printStackTrace();
        return LocaleController.getString("Offline", R.string.Offline);
    }
    //return "Offline";
}
项目:androidclient    文件:LastActivityListener.java   
@Override
public void processStanza(Stanza packet) {
    Intent i = prepareIntent(packet, ACTION_LAST_ACTIVITY);

    LastActivity p = (LastActivity) packet;
    i.putExtra(EXTRA_SECONDS, p.getIdleTime());
    i.putExtra(EXTRA_TYPE, p.getType().toString());

    sendBroadcast(i);
}
项目:androidclient    文件:MessageCenterService.java   
@CommandHandler(name = ACTION_LAST_ACTIVITY)
private boolean handleLastActivity(Intent intent, boolean canConnect) {
    if (canConnect && isConnected()) {
        LastActivity p = new LastActivity();

        p.setStanzaId(intent.getStringExtra(EXTRA_PACKET_ID));
        p.setTo(intent.getStringExtra(EXTRA_TO));

        sendIqWithReply(p, true, mLastActivityListener, mLastActivityListener);
    }
    return false;
}
项目:Chatting-App-    文件:LastActivityListener.java   
@Override
public void processPacket(Packet packet) {
    LastActivity p = (LastActivity) packet;
    Intent i = new Intent(ACTION_LAST_ACTIVITY);
    i.putExtra(EXTRA_PACKET_ID, p.getPacketID());

    String from = p.getFrom();
    String network = StringUtils.parseServer(from);
    // our network - convert to userId
    if (network.equalsIgnoreCase(getServer().getNetwork())) {
        StringBuilder b = new StringBuilder();
        b.append(StringUtils.parseName(from));
        b.append(StringUtils.parseResource(from));
        i.putExtra(EXTRA_FROM_USERID, b.toString());
    }

    i.putExtra(EXTRA_FROM, from);
    i.putExtra(EXTRA_TO, p.getTo());
    i.putExtra(EXTRA_SECONDS, p.lastActivity);

    // non-standard stanza group extension
    PacketExtension ext = p.getExtension(StanzaGroupExtension.ELEMENT_NAME, StanzaGroupExtension.NAMESPACE);
    if (ext != null && ext instanceof StanzaGroupExtension) {
        StanzaGroupExtension g = (StanzaGroupExtension) ext;
        i.putExtra(EXTRA_GROUP_ID, g.getId());
        i.putExtra(EXTRA_GROUP_COUNT, g.getCount());
    }

    Log.v(MessageCenterService.TAG, "broadcasting presence: " + i);
    sendBroadcast(i);
}
项目:desktopclient-java    文件:Client.java   
private void sendLastActivityRequestAsync(JID jid) {
    if (mFeatureDiscovery == null) {
        LOGGER.warning("no feature discovery");
        return;
    }

    // blocking
    if (!mFeatureDiscovery.getFeaturesFor(jid.toDomain())
            .containsKey(FeatureDiscovery.Feature.LAST_ACTIVITY))
        // not supported by server
        return;

    LastActivity request = new LastActivity(jid.toBareSmack());
    this.sendPacket(request);
}
项目:Smack    文件:LastActivityManager.java   
public synchronized void enable() {
    ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(LastActivity.NAMESPACE);
    enabled = true;
}
项目:Smack    文件:LastActivityManager.java   
public synchronized void disable() {
    ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(LastActivity.NAMESPACE);
    enabled = false;
}
项目:Smack    文件:LastActivityManager.java   
/**
 * Returns true if Last Activity (XEP-0012) is supported by a given JID
 * 
 * @param jid a JID to be tested for Last Activity support
 * @return true if Last Activity is supported, otherwise false
 * @throws NotConnectedException 
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 */
public boolean isLastActivitySupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException {
    return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, LastActivity.NAMESPACE);
}