creating a timer in a Moblet


#include <MAUtil/Moblet.h>
#include <conprint.h>
#include <matime.h>
#include <MAUtil/Environment.h>

using namespace MAUtil;

class MyTimer : public MAUtil::TimerListener
{
public:
 void runTimerEvent ()
 {
 lprintfln("Timer expired");
 }
};
MyTimer timer;

/**
 * A Moblet is a high-level class that defines the
 * behaviour of a MoSync program.
 */
class MyMoblet : public Moblet
{
public:
 /**
 * Initialize the application in the constructor.
 */
 MyMoblet()
 {
 printf("Press zero or back to exit\n");
 printf("%d",maLocalTime());
 MAUtil::Environment::getEnvironment().addTimer(&timer, 1000,0);

}

/**
 * Called when a key is pressed.
 */
 void keyPressEvent(int keyCode, int nativeCode)
 {
 if (MAK_BACK == keyCode || MAK_0 == keyCode)
 {
 // Call close to exit the application.
 close();
 }

// Print the key character.
 printf("You typed: %c\n", keyCode);
 }

/**
 * Called when a key is released.
 */
 void keyReleaseEvent(int keyCode, int nativeCode)
 {
 }

/**
 * Called when the screen is touched.
 */
 void pointerPressEvent(MAPoint2d point)
 {
 // Print the x and y coordinate.
 printf("You touched: %i %i\n", point.x, point.y);
 printf("%d",maLocalTime());
 }
};

/**
 * Entry point of the program. The MAMain function
 * needs to be declared as extern "C".
 */
extern "C" int MAMain()
{
 Moblet::run(new MyMoblet());
 return 0;
}

 

source: http://www.mosync.com/content/looking-timercountdown-timer

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s