How to post a countdown through gmail status?

Is it possible to post a countdown in my gmail status? Like "01: 44: 15: 23" and its contraction is constant.

+5
source share
2 answers

Good article found to share :

Google Talk uses XMPP, and then if you can connect using XMPP clientyours Google account, you can use the client instead of Google conversations.

The whole mechanism is too simple (Smack uses XMPP Libraryit because it is simple and serves me well):

  • To come in.
  • Calculate the difference between the current and the target date.
  • Submit Availability

To come in

import org.jivesoftware.smack.XMPPConnection;

public void connect() {
    XMPPConnection connection = new XMPPConnection(server); //Server is gmail.com for Google Talk.
    connection.connect();
    connection.login(username, password); //Username and password.
}

Calculate difference between current and target date

Java Calendar Date:

import java.util.Calendar;
import java.util.Date;

{
        Calendar calendar1 = Calendar.getInstance();
        Date d = new Date();
        calendar1.setTime(d);

        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(endLine); //End line is the date we're counting to.

        long milliseconds1 = calendar1.getTimeInMillis();
        long milliseconds2 = calendar2.getTimeInMillis();
        long diff = milliseconds2 - milliseconds1;

        long diffDays = diff / (24 * 60 * 60 * 1000);
        diff = diff % (24 * 60 * 60 * 1000);

        long diffHours = diff / (60 * 60 * 1000);
        diff = diff % (60 * 60 * 1000);

        long diffMinutes = diff / (60 * 1000);
        diff = diff % (60 * 1000);
}

, .

, , :

import org.jivesoftware.smack.packet.Presence;

{
         String remaining = Long.toString(diffDays) + " day(s), " + Long.toString(diffHours) + " hour(s), " + Long.toString(diffMinutes) + " minute(s) " + message; //Message is usually: Until "something".

        Presence presence = new Presence(Presence.Type.available);
        presence.setStatus(remaining);
        presence.setPriority(24); //Highest priority in Google Talk
        presence.setMode(presenceMode); //This is one of XMPP modes (Available, Chat, DND, Away, XA).
        connection.sendPacket(presence);
}

, , Google Talk. ( , Google Talk, , . , , ).

+4

status-counter.jar script

java -jar /root/status-counter.jar -status SF -username username@gmail.com -password XXXXXX -datetime 2013-03-21T16:00:00+02:00 -type hours -decimals 0

cron,

*/5 * * * * /path/script.sh > /dev/null

5 . .

+2

All Articles