The app_time_tick() function is called at least once per second. The watch applications can get the current time from the watch_time_h handle.
/*
@brief Called at each second. This callback is not called while the app is paused or the device is in ambient mode
@param[in] watch_time The watch time handle. watch_time is not available after returning this callback. It is freed by the framework
@param[in] user_data The user data to be passed to the callback functions
*/
void
app_time_tick(watch_time_h watch_time, void* user_data)
{
int hour = 0;
int min = 0;
int sec = 0;
int year = 0;
int month = 0;
int day = 0;
int day_of_week = 0;
watch_time_get_hour(watch_time, &hour);
watch_time_get_minute(watch_time, &min);
watch_time_get_second(watch_time, &sec);
watch_time_get_day(watch_time, &day);
watch_time_get_month(watch_time, &month);
watch_time_get_year(watch_time, &year);
watch_time_get_day_of_week(watch_time, &day_of_week);
_set_time(hour, min, sec);
_set_date(day, month, day_of_week);
_set_moonphase(day, month, year);
}
The _set_time() and _set_date() functions calculate the position of each hand and finally redraw the hands to the calculated positions:
/*
@brief Set time in the watch
@pram[in] hour The hour number
@pram[in] min The min number
@pram[in] sec The sec number
*/
static void
_set_time(int hour, int min, int sec)
{
Evas_Object *bg = NULL;
Evas_Object *hands = NULL;
Evas_Object *hands_shadow = NULL;
double degree = 0.0f;
bg = view_get_bg();
if (bg == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get bg");
return;
}
/* Rotate hands in the watch */
degree = sec * SEC_ANGLE;
hands = evas_object_data_get(bg, "__HANDS_SEC__");
view_rotate_hand(hands, degree, (BASE_WIDTH / 2), (BASE_HEIGHT / 2));
hands_shadow = evas_object_data_get(bg, "__HANDS_SEC_SHADOW__");
view_rotate_hand(hands_shadow, degree, (BASE_WIDTH / 2), (BASE_HEIGHT / 2) + HANDS_SEC_SHADOW_PADDING);
if (s_info.cur_min != min) {
degree = min * MIN_ANGLE;
hands = evas_object_data_get(bg, "__HANDS_MIN__");
view_rotate_hand(hands, degree, (BASE_WIDTH / 2), (BASE_HEIGHT / 2));
hands_shadow = evas_object_data_get(bg, "__HANDS_MIN_SHADOW__");
view_rotate_hand(hands_shadow, degree, (BASE_WIDTH / 2), (BASE_HEIGHT / 2) + HANDS_MIN_SHADOW_PADDING);
s_info.cur_min = min;
}
if (s_info.cur_hour != hour) {
degree = (hour * HOUR_ANGLE) + data_get_plus_angle(min);
hands = evas_object_data_get(bg, "__HANDS_HOUR__");
view_rotate_hand(hands, degree, (BASE_WIDTH / 2), (BASE_HEIGHT / 2));
hands_shadow = evas_object_data_get(bg, "__HANDS_HOUR_SHADOW__");
view_rotate_hand(hands_shadow, degree, (BASE_WIDTH / 2), (BASE_HEIGHT / 2) + HANDS_HOUR_SHADOW_PADDING);
s_info.cur_hour = hour;
}
}
/*
@brief Set date in the watch
@pram[in] day The day number
@pram[in] month The month number
@pram[in] day_of_week The day of week number
*/
static void
_set_date(int day, int month, int day_of_week)
{
Evas_Object *bg = NULL;
Evas_Object *module_day_layout = NULL;
Evas_Object *hands = NULL;
Evas_Object *hands_shadow = NULL;
double degree = 0.0f;
char txt_day_num[32] = {0,};
/* Set day in the watch */
if (s_info.cur_day != day) {
module_day_layout = view_get_module_day_layout();
snprintf(txt_day_num, sizeof(txt_day_num), "%d", day);
view_set_text(module_day_layout, "txt.day.num", txt_day_num);
s_info.cur_day = day;
}
bg = view_get_bg();
if (bg == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get bg");
return;
}
/* Rotate hands in the watch */
if (s_info.cur_month != month) {
degree = month * MONTH_ANGLE;
hands = evas_object_data_get(bg, "__HANDS_MODULE_MONTH__");
view_rotate_hand(hands, degree, (BASE_WIDTH / 2) - (HANDS_MODULE_CALENDAR_WIDTH / 2) - 54,
175 + (HANDS_MODULE_CALENDAR_HEIGHT / 2));
hands_shadow = evas_object_data_get(bg, "__HANDS_MODULE_MONTH_SHADOW__");
view_rotate_hand(hands_shadow, degree, (BASE_WIDTH / 2) - (HANDS_MODULE_CALENDAR_WIDTH / 2) - 54,
175 + (HANDS_MODULE_CALENDAR_HEIGHT / 2) + HANDS_MODULE_CALENDAR_PADDING);
s_info.cur_month = month;
}
if (s_info.cur_weekday != day_of_week) {
degree = (day_of_week - 1) * WEEKDAY_ANGLE;
hands = evas_object_data_get(bg, "__HANDS_MODULE_WEEKDAY__");
view_rotate_hand(hands, degree, (BASE_WIDTH / 2) + (HANDS_MODULE_CALENDAR_WIDTH / 2) + 54,
175 + (HANDS_MODULE_CALENDAR_HEIGHT / 2));
hands_shadow = evas_object_data_get(bg, "__HANDS_MODULE_WEEKDAY_SHADOW__");
view_rotate_hand(hands_shadow, degree, (BASE_WIDTH / 2) + (HANDS_MODULE_CALENDAR_WIDTH / 2) + 54,
175 + (HANDS_MODULE_CALENDAR_HEIGHT / 2) + HANDS_MODULE_CALENDAR_PADDING);
s_info.cur_weekday = day_of_week;
}
}