Search in sources :

Example 1 with Time

use of com.xabber.xmpp.time.Time in project xabber-android by redsolution.

the class TimeManager method onServerInfoReceived.

@Override
public void onServerInfoReceived(ConnectionItem connection) {
    if (!(connection instanceof AccountItem)) {
        onAvailable(connection);
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE) && offsets.get(account) == null) {
        sents.put(account, new Date());
        Time packet = new Time();
        packet.setTo(Jid.getServer(account));
        packet.setType(Type.get);
        try {
            ConnectionManager.getInstance().sendRequest(account, packet, this);
        } catch (NetworkException e) {
        }
        return;
    }
    onAvailable(connection);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Time(com.xabber.xmpp.time.Time) NetworkException(com.xabber.android.data.NetworkException) Date(java.util.Date)

Example 2 with Time

use of com.xabber.xmpp.time.Time in project xabber-android by redsolution.

the class TimeManager method onReceived.

@Override
public void onReceived(String account, String packetId, IQ iq) {
    if (!(iq instanceof Time) || !((Time) iq).isValid()) {
        onError(account, packetId, iq);
        return;
    }
    Date t1 = sents.remove(account);
    Date t2_3 = ((Time) iq).getUtc();
    Date t4 = ((Time) iq).getCreated();
    long offset = ((t2_3.getTime() - t1.getTime()) + (t2_3.getTime() - t4.getTime())) / 2;
    offsets.put(account, offset);
    onAvailable(AccountManager.getInstance().getAccount(account));
}
Also used : Time(com.xabber.xmpp.time.Time) Date(java.util.Date)

Example 3 with Time

use of com.xabber.xmpp.time.Time in project xabber-android by redsolution.

the class TimeManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    String account = ((AccountItem) connection).getAccount();
    if (!(packet instanceof Time))
        return;
    Time time = (Time) packet;
    if (time.getType() == Type.get) {
        Time result = new Time();
        result.setType(Type.result);
        result.setPacketID(time.getPacketID());
        result.setFrom(time.getTo());
        result.setTo(time.getFrom());
        Calendar calendar = Calendar.getInstance();
        result.setTzo((calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000);
        result.setUtc(calendar.getTime());
        try {
            ConnectionManager.getInstance().sendStanza(account, result);
        } catch (NetworkException e) {
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Calendar(java.util.Calendar) Time(com.xabber.xmpp.time.Time) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

Time (com.xabber.xmpp.time.Time)3 NetworkException (com.xabber.android.data.NetworkException)2 AccountItem (com.xabber.android.data.account.AccountItem)2 Date (java.util.Date)2 Calendar (java.util.Calendar)1