DALi Watch Application
PUBLISHED
You can create a watch application with DALi to retrieve the current date and time and display it accurately on the screen.
This feature is supported in wearable applications only.
To create a DALi watch application, you must:
- Use the Dali::WatchApplication class.
Note A DALi watch application is implemented similarly to a DALi basic UI application [1], since the Dali::WatchApplication [2] class inherits from the Dali::Application [3] class. Consequently, make sure you are familiar with the basic UI application details before tackling a watch application.
- Make sure you start the event loop.
- React to application events with callbacks.
- Manage the time handle and display the time with the DALi 3D UI.
The
TimeTickSignal()
andAmbientTickSignal()
functions trigger callback functions to update the display with the new accurate time. TheWatchTime
handle is provided with the callback function to help you to update the current time properly.
Figure: DALi watch application
For the steps of creating the basic parts of a simple DALi watch application, see Basics of Creating a DALi Watch Application.
Main Application Classes
If you want to use DALi for your watch application, you must create the application with the Dali::WatchApplication
class. This class provides the means for initializing the resources required by DALi.
The following table lists the main functions you need in your application to retrieve the current time. They are all provided by the Dali::WatchTime [4] class.
Table: Main functions
Function | Description |
---|---|
GetHour() |
Get the hour from the WatchTime handle. |
GetHour24() |
Get the hour from the WatchTime handle in 24-hour format. |
GetMinute() |
Get the minute from the WatchTime handle. |
GetSecond() |
Get the second from the WatchTime handle. |
Event Loop
Like all ordinary Tizen applications, the DALi watch application must start the main event loop. Afterwards, it can receive usual platform events and dedicated watch events from the platform.
The mainloop()
function is used to start the event loop. If you do not call the function and start the event loop, DALi cannot call any callback functions for application events.
Event Callbacks
The Dali::WatchApplication
class emits several signals which you can connect to.
The following table lists the callbacks for the watch application signals provided by the Dali::WatchApplication
class. These signals originally occur in the Tizen application framework, and you can use the callbacks to react to them.
Table: Callbacks for watch application event signals
Callback | Description |
---|---|
TimeTickSignal() |
Called every second. You can use the signal to update the time on the screen. |
AmbientTickSignal() |
Called every minute when the device is in the ambient mode. You can use the signal to update the time on the screen. |
AmbientChangedSignal() |
Called when the device enters or exits the ambient mode. |
Basics of Creating a DALi Watch Application
To create a DALi watch application, set the time, and draw the UI:
- Initialize the application:
- To use the functions and data types of the DALi watch application, include the
<dali/public-api/dali-wearable.h>
header file in your application:#include <dali/public-api/dali-wearable.h>
- Like in a basic UI application, use the following 2
using
directives for convenience, because all DALi APIs are contained in eitherDali
orDali::Toolkit
namespace:
using namespace Dali; using namespace Dali::Toolkit;
- To use the functions and data types of the DALi watch application, include the
- Create the
Dali::WatchApplication
class instance to initialize and set up DALi for a watch application:
WatchApplication application = WatchApplication::New( &argc, &argv );
- Connect signals to keep yourself informed when certain system events occur.
- To manage signal connection safely, DALi provides the Dali::ConnectionTracker [5] class. A typical way to start a DALi application is to create a class derived from the
Dali::ConnectionTracker
class and use its member functions as callback functions for DALi signals.When the application receives the
InitSignal()
, it can create UI components. Connect theWatchExample::Create()
callback to theDali::WatchApplication::InitSignal()
function:class WatchExample : public ConnectionTracker { public: WatchExample( WatchApplication& application ) : mApplication( application ) { mApplication.InitSignal().Connect( this, &WatchExample::Create ); } void Create( Application& application ) { // Create a DALi UI component } private: WatchApplication& mApplication; }
- Handle the tick signals.
The
TimeTickSignal()
callback is triggered once per second. Retrieve the current time from theWatchTime
time handle to draw the updated time.You can get the current hour, minute, and second from the
WatchTime
time handle by using thetime.GetHour()
,time.GetMinute()
, andtime.GetSecond()
functions.mApplication.TimeTickSignal().Connect( this, &WatchExample::OnTimeTick ); // Update clock hands on the tick event void OnTimeTick( Application& application, const WatchTime& time ) { UpdateClockHands(time.GetHour(), time.GetMinute(), time.GetSecond()); } void UpdateClockHands(int hour, int min, int sec) { // Update the angle of each hand }
- To manage signal connection safely, DALi provides the Dali::ConnectionTracker [5] class. A typical way to start a DALi application is to create a class derived from the