2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "timer_motion.h"
18 #include "timer_utils.h"
19 //#include "timer_resource.h"
21 /**********************************************************************
22 ******************define, struct ,typedef, union, enum, global val *************************************
23 ***********************************************************************/
25 static Edje_Color_Class g_color_class_lbtn_hl = {
26 .name = STRING_TIMER_MOTION_LBTN_TXT_COLOR,
27 .r = 249,.g = 249,.b = 249,.a = 255,
28 .r2 = 0,.g2 = 0,.b2 = 0,.a2 = 102,
29 .r3 = 0,.g3 = 0,.b3 = 0,.a3 = 0,
32 static Edje_Color_Class g_color_class_rbtn_hl = {
33 .name = STRING_TIMER_MOTION_RBTN_TXT_COLOR,
34 .r = 249,.g = 249,.b = 249,.a = 255,
35 .r2 = 0,.g2 = 0,.b2 = 0,.a2 = 102,
36 .r3 = 0,.g3 = 0,.b3 = 0,.a3 = 0,
39 /**********************************************************************
40 ******************Local function declear, extern function declear*************************************
41 ***********************************************************************/
44 static void _timer_view_motion_btn_set(motion_view * view);
45 static Eina_Bool _timer_view_motion_timer_cb(void *data);
46 static int _timer_view_motion_btn_stop_cb(struct appdata *ad);
47 static int _timer_view_motion_btn_restart_cb(struct appdata *ad);
48 static int _timer_view_motion_btn_reset_cb(struct appdata *ad);
49 static int _timer_view_motion_create_clock(struct appdata *ad);
51 //static void _timer_view_motion_effect_cb (void *data, Elm_Transit * transit);
53 static int _timer_view_motion_create(void *data);
54 static int _timer_view_motion_destroy(void *data);
55 static int _timer_view_motion_update(void *data);
56 static int _timer_view_motion_cleanup(void *data);
58 static int _timer_view_motion_create_layout(void *data);
59 static int _timer_view_motion_update_layout(void *data);
60 /**********************************************************************
61 ******************Global val , static global val*************************************
62 ***********************************************************************/
63 static int mutex_reset, mutex_stop_restart; // to control button clicking logic
65 clk_view timer_view_motion = {
66 .create = _timer_view_motion_create,
67 .destroy = _timer_view_motion_destroy,
68 .update = _timer_view_motion_update,
69 .cleanup = _timer_view_motion_cleanup,
70 .is_create = EINA_FALSE,
71 .layer = MAX_CLK_FWK_VIEW_LAYER,
74 /**********************************************************************
75 ******************Local function ref*************************************
76 ***********************************************************************/
78 static void _timer_view_motion_btn_set(motion_view * view)
80 retm_if(NULL_CHECK(view), "view null");
81 switch (view->type_state) {
82 case TIMER_VIEW_MOTION_STATE_RUN:
83 edje_object_part_text_set(_EDJ(view->eo_btn_lft),
85 STRING_TIMER_IDS_COM_SK_STOP_S_);
86 edje_object_color_class_set(_EDJ(view->eo_btn_lft),
87 STRING_TIMER_MOTION_LBTN_TXT_COLOR,
88 255, 255, 255, 255, 0, 0, 0, 102, 0,
90 edje_object_part_text_set(_EDJ(view->eo_btn_rht),
92 STRING_TIMER_IDS_COM_BODY_RESET_S_);
93 edje_object_color_class_set(_EDJ(view->eo_btn_rht),
94 STRING_TIMER_MOTION_RBTN_TXT_COLOR,
95 255, 255, 255, 255, 0, 0, 0, 102, 0,
98 case TIMER_VIEW_MOTION_STATE_STOP:
99 edje_object_part_text_set(_EDJ(view->eo_btn_lft),
101 STRING_TIMER_IDS_TMR_SK3_RESTART_);
102 edje_object_color_class_set(_EDJ(view->eo_btn_lft),
103 STRING_TIMER_MOTION_LBTN_TXT_COLOR,
104 255, 255, 255, 255, 0, 0, 0, 102, 0,
106 edje_object_part_text_set(_EDJ(view->eo_btn_rht),
108 STRING_TIMER_IDS_COM_BODY_RESET_S_);
109 edje_object_color_class_set(_EDJ(view->eo_btn_rht),
110 STRING_TIMER_MOTION_RBTN_TXT_COLOR,
111 255, 255, 255, 255, 0, 0, 102, 0, 0,
120 * Debug function: to update time and interval in each timer intervals
121 * This function requires data as parameters
123 * _timer_view_motion_timer_cb()
124 * @param[in] data Pointer to user data, which contains the data of application
126 * @return int, which indicates the result state of operation
128 static Eina_Bool _timer_view_motion_timer_cb(void *data)
130 retvm_if(NULL_CHECK(data), ECORE_CALLBACK_CANCEL, "data null");
131 struct appdata *ad = (struct appdata *)data;
132 motion_view *view = ad->view_motion;
133 retvm_if(NULL_CHECK(view), ECORE_CALLBACK_CANCEL, "view null");
134 struct timeval time_past = { 0, };
135 //read the system time
136 gettimeofday(&ad->current_systime, NULL);
139 ad->current_systime.tv_sec - ad->start_systime.tv_sec;
141 ad->current_systime.tv_usec - ad->start_systime.tv_usec;
142 if ((time_past.tv_sec) && (time_past.tv_usec < 0)) {
143 time_past.tv_sec -= 1;
144 time_past.tv_usec += 1000000;
146 //reduce due-time according to time passed
147 ad->due_time.tv_sec -= time_past.tv_sec;
148 ad->due_time.tv_usec -= time_past.tv_usec;
149 if ((ad->due_time.tv_sec) && (ad->due_time.tv_usec < 0)) {
150 ad->due_time.tv_sec -= 1;
151 ad->due_time.tv_usec += 1000000;
153 if ((ad->due_time.tv_sec < 0)
154 || ((ad->due_time.tv_sec == 0) && (ad->due_time.tv_usec <= 0))) {
155 edje_color_class_set(STRING_TIMER_MOTION_TITLE_COLOR, 246, 105,
156 50, 255, 0, 0, 0, 0, 0, 0, 0, 0);
157 timer_utils_view_change(ad);
158 return ECORE_CALLBACK_CANCEL;
159 } else if (ad->due_time.tv_sec >= 46800) {
160 ecore_timer_freeze(ad->timer);
161 timer_utils_unregister_alarm(ad);
162 clk_view_change(&timer_view_motion, &timer_view_setting, ad);
163 elm_object_part_content_set(ad->eo_effect,
164 STRING_TIMER_ELM_SWALLOW_CENTER,
165 ad->view_setting->eo_navibar);
166 return ECORE_CALLBACK_CANCEL;
168 if (!ad->isTimerView) {
169 // let start system time equals current system time
170 ad->start_systime.tv_sec = ad->current_systime.tv_sec;
171 ad->start_systime.tv_usec = ad->current_systime.tv_usec;
172 return ECORE_CALLBACK_RENEW;
174 char time_str[BUF_SIZE] = { 0, };
176 gmtime_r(&ad->due_time.tv_sec, &show_time);
179 snprintf(time_str, sizeof(time_str), "%d", show_time.tm_hour/10);
180 edje_object_signal_emit(_EDJ(view->eo_content), time_str, "time/image/hour/1");
181 snprintf(time_str, sizeof(time_str), "%d", show_time.tm_hour%10);
182 edje_object_signal_emit(_EDJ(view->eo_content), time_str, "time/image/hour/2");
183 snprintf(time_str, sizeof(time_str), "%d", show_time.tm_min/10);
184 edje_object_signal_emit(_EDJ(view->eo_content), time_str, "time/image/min/1");
185 snprintf(time_str, sizeof(time_str), "%d", show_time.tm_min%10);
186 edje_object_signal_emit(_EDJ(view->eo_content), time_str, "time/image/min/2");
187 snprintf(time_str, sizeof(time_str), "%d", show_time.tm_sec/10);
188 edje_object_signal_emit(_EDJ(view->eo_content), time_str, "time/image/sec/1");
189 snprintf(time_str, sizeof(time_str), "%d", show_time.tm_sec%10);
190 edje_object_signal_emit(_EDJ(view->eo_content), time_str, "time/image/sec/2");
192 // let start system time equals current system time
193 ad->start_systime.tv_sec = ad->current_systime.tv_sec;
194 ad->start_systime.tv_usec = ad->current_systime.tv_usec;
195 return ECORE_CALLBACK_RENEW;
200 static int _timer_view_motion_btn_stop_cb(struct appdata *ad)
202 retvm_if(NULL_CHECK(ad), FAILED, "ad null");
203 motion_view *view = ad->view_motion;
204 if ((ad->due_time.tv_sec > 1)
205 || (ad->due_time.tv_sec == 1 && ad->due_time.tv_usec > 2100)) {
206 ECORE_TIMER_DELIF(ad->timer);
207 timer_utils_unregister_alarm(ad);
208 view->type_state = TIMER_VIEW_MOTION_STATE_STOP;
209 _timer_view_motion_btn_set(view);
215 static int _timer_view_motion_btn_restart_cb(struct appdata *ad)
217 retvm_if(NULL_CHECK(ad), FAILED, "ad null");
218 motion_view *view = ad->view_motion;
219 timer_utils_register_alarm(ad);
220 gettimeofday(&ad->start_systime, NULL);
221 edje_color_class_set(STRING_TIMER_MOTION_TITLE_COLOR, 223, 180, 152,
222 255, 0, 0, 0, 0, 0, 0, 0, 0);
223 ECORE_TIMER_DELIF(ad->timer);
224 _timer_view_motion_timer_cb(ad);
226 ecore_timer_add(ad->timer_interval, _timer_view_motion_timer_cb,
229 view->type_state = TIMER_VIEW_MOTION_STATE_RUN;
230 _timer_view_motion_btn_set(view);
235 static int _timer_view_motion_btn_reset_cb(struct appdata *ad)
237 retvm_if(NULL_CHECK(ad), FAILED, "ad null");
238 if ((ad->due_time.tv_sec > 1)
239 || (ad->due_time.tv_sec == 1 && ad->due_time.tv_usec > 2100)) {
240 timer_utils_unregister_alarm(ad);
241 timer_utils_view_change(ad);
247 static int _timer_view_motion_create(void *data)
250 struct appdata *ad = NULL;
252 ad = (struct appdata *)data;
254 ad->page = TIMER_VIEW_PAGE_MOTION;
255 ret = _timer_view_motion_create_layout(data);
256 ret |= _timer_view_motion_update_layout(data);
257 timer_show_view(ad, EINA_TRUE);
258 timer_view_motion.is_create = EINA_TRUE;
259 timer_view_motion.layer = 1;
265 static int __timer_view_motion_destroy_cb(void *data)
267 struct appdata *ad = NULL;
268 motion_view *view = NULL;
269 ad = (struct appdata *)data;
270 view = ad->view_motion;
272 ECORE_TIMER_DELIF(ad->timer);
273 EVAS_OBJECT_DELIF(view->eo_icon_hour);
274 EVAS_OBJECT_DELIF(view->eo_clock);
275 EVAS_OBJECT_DELIF(view->eo_content);
276 EVAS_OBJECT_DELIF(view->eo_content);
277 timer_view_motion.is_create = EINA_FALSE;
282 static int _timer_view_motion_destroy(void *data)
287 __timer_view_motion_destroy_cb(data);
293 static int _timer_view_motion_update(void *data)
296 struct appdata *ad = NULL;
298 ad = (struct appdata *)data;
300 ad->page = TIMER_VIEW_PAGE_MOTION;
301 ret = _timer_view_motion_update_layout(data);
302 timer_show_view(ad, EINA_TRUE);
308 static int _timer_view_motion_cleanup(void *data)
310 return _timer_view_motion_destroy(data);
314 static int _timer_view_motion_create_layout(void *data)
316 retvm_if(!data, FAILED, "data null");
317 struct appdata *ad = (struct appdata *)data;
318 motion_view *view = ad->view_motion;
319 retvm_if(NULL_CHECK(view), FAILED, "view null");
321 view->eo_parent = ad->parent;
322 view->eo_layout = ad->layout;
323 view->eo_content = load_edj(view->eo_layout, EDJ_NAME, CONTENT_MOTION);
324 // elm_object_part_content_set(ad->eo_effect, STRING_TIMER_ELM_SWALLOW_CENTER, view->eo_content);
327 clk_widget_create_button(view->eo_content, EDJ_NAME,
328 STRING_TIMER_MOTION_LBTN,
329 &g_color_class_lbtn_hl,
330 timer_motion_lbtn_cb, ad);
331 elm_object_part_content_set(view->eo_content, STRING_TIMER_SW_LBTN,
334 clk_widget_create_button(view->eo_content, EDJ_NAME,
335 STRING_TIMER_MOTION_RBTN,
336 &g_color_class_rbtn_hl,
337 timer_motion_rbtn_cb, ad);
338 elm_object_part_content_set(view->eo_content, STRING_TIMER_SW_RBTN,
341 edje_object_part_text_set(_EDJ(view->eo_content),
342 STRING_TIMER_TIME_LABEL_HOUR,
343 STRING_TIMER_IDS_TMR_BODY_HOUR_);
344 edje_object_part_text_set(_EDJ(view->eo_content),
345 STRING_TIMER_TIME_LABEL_MINUTE,
346 STRING_TIMER_IDS_TMR_BODY_MIN_);
347 edje_object_part_text_set(_EDJ(view->eo_content),
348 STRING_TIMER_TIME_LABEL_SECOND,
349 STRING_TIMER_IDS_TMR_BODY_SEC_);
351 //_timer_view_motion_create_clock(ad);
353 mutex_reset = mutex_stop_restart = 0;
355 gettimeofday(&ad->start_systime, NULL);
356 _timer_view_motion_timer_cb(ad);
358 ecore_timer_add(ad->timer_interval, _timer_view_motion_timer_cb,
364 static int _timer_view_motion_update_layout(void *data)
366 retvm_if(!data, FAILED, "data null");
367 struct appdata *ad = (struct appdata *)data;
368 motion_view *view = ad->view_motion;
369 retvm_if(!view, FAILED, "view null");
370 edje_object_part_text_set(_EDJ(view->eo_content),
371 STRING_TIMER_TIME_LABEL_HOUR,
372 STRING_TIMER_IDS_TMR_BODY_HOUR_);
373 edje_object_part_text_set(_EDJ(view->eo_content),
374 STRING_TIMER_TIME_LABEL_MINUTE,
375 STRING_TIMER_IDS_TMR_BODY_MIN_);
376 edje_object_part_text_set(_EDJ(view->eo_content),
377 STRING_TIMER_TIME_LABEL_SECOND,
378 STRING_TIMER_IDS_TMR_BODY_SEC_);
381 view->type_state = TIMER_VIEW_MOTION_STATE_RUN;
382 _timer_view_motion_btn_set(view);
386 /**********************************************************************
387 ******************Global function ref*************************************
388 ***********************************************************************/
391 * Debug function: to handle button clicking logic
392 * This function requires data, obj, emission, source as parameters
394 * timer_motion_lbtn_cb()
395 * @param[in] data Pointer to user data, which contains the data of application
396 * @param[in] obj Pointer to button object
397 * @param[in] emission Pointer to signal
398 * @param[in] source Pointer to the source from which signal is emitted
402 void timer_motion_lbtn_cb(void *data, Evas_Object * obj, const char *emission,
405 retm_if(NULL_CHECK(data), "data null");
406 struct appdata *ad = (struct appdata *)data;
407 const char *str = NULL;
408 str = edje_object_part_text_get(obj, STRING_TIMER_TXT);
409 if (IS_STR_EQUAL(STRING_TIMER_IDS_COM_SK_STOP_S_, str)) {
410 _timer_view_motion_btn_stop_cb(ad);
411 } else if (IS_STR_EQUAL(STRING_TIMER_IDS_TMR_SK3_RESTART_, str)) {
412 _timer_view_motion_btn_restart_cb(ad);
417 void timer_motion_rbtn_cb(void *data, Evas_Object * obj, const char *emission,
420 retm_if(NULL_CHECK(data), "data null");
421 struct appdata *ad = (struct appdata *)data;
422 _timer_view_motion_btn_reset_cb(ad);