2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 //==========================================================================
12 * @file CicoComponentimplementation.cpp
14 * @brief This file is implimentation of CicoStatusBarClockComponent class
15 * and CicoNotificationPanelComponent class
17 //==========================================================================
23 #include <tzplatform_config.h>
26 #include "ico_syc_private.h"
27 #include "CicoComponentImplementation.h"
30 #define IMG_DIR ICO_SYC_PACKAGE_STATUSBAR "/res/images"
31 #define THEME_PATH ICO_SYC_PACKAGE_STATUSBAR "/res/themes/statusbar.edj"
33 /* Theme group name */
34 #define THEME_CLOCK_NAME "ClockImage"
35 #define THEME_NOTIFICATION_NAME "Notification"
37 // set image file path of clock
38 static const char *clock_image_path[] = {
55 /* define of special image index */
56 #define TIME_IMAGE_AM (10)
57 #define TIME_IMAGE_PM (11)
58 #define TIME_IMAGE_SP (12)
60 /* array of clock object name */
61 static const char *clock_image_object[] = {
71 /*--------------------------------------------------------------------------*/
73 * @brief default constructor
78 /*--------------------------------------------------------------------------*/
79 CicoStatusBarClockComponent::CicoStatusBarClockComponent()
83 /*--------------------------------------------------------------------------*/
90 /*--------------------------------------------------------------------------*/
91 CicoStatusBarClockComponent::~CicoStatusBarClockComponent()
95 /*--------------------------------------------------------------------------*/
97 * @brief initialize of clock component
99 * @param[in] windowobj
102 * @return true: success false: failed
104 /*--------------------------------------------------------------------------*/
106 CicoStatusBarClockComponent::Initialize(Evas_Object *windowobj, Evas *evas)
108 ICO_TRA("CicoStatusBarClockComponent::Initialize Enter");
110 /* initialize display clock image */
112 for(i=0; i<CLOCK_OBJECT_COUNT; i++ ){
113 last_clock_image[i] = -1;
116 /* make TimeImage object */
117 evasobj_=edje_object_add(evas);
119 snprintf(wrk_path, sizeof(wrk_path), "%s/" THEME_PATH,
120 tzplatform_getenv(TZ_SYS_RO_APP));
121 if (!edje_object_file_set(evasobj_, wrk_path, THEME_CLOCK_NAME )) {
122 Edje_Load_Error err = edje_object_load_error_get(evasobj_);
123 const char *errmsg = edje_load_error_str(err);
124 ICO_ERR("could not load 'main' from statusbar.edj: %s",
129 /* move TimeImage to UpRight of window */
130 /* Do not need this process , if positiong of UpRight enabled with .EDC file */
132 Evas_Coord w_width=0;
133 Evas_Object* obj = NULL;
134 evas_object_geometry_get( windowobj, &x, &y, &w_width, &h );
135 evas_object_resize( evasobj_, w_width, h );
136 obj = (Evas_Object*)edje_object_part_object_get(evasobj_,"MIN1_img" );
137 evas_object_geometry_get( obj, &x, &y, &w, &h );
138 Evas_Coord offset = w_width - x - w -18;
140 for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
141 obj = (Evas_Object*)edje_object_part_object_get(
142 evasobj_, clock_image_object[i] );
144 evas_object_geometry_get( obj, &x, &y, &w, &h );
145 evas_object_move( obj, x+offset , y);
146 evas_object_show(obj);
150 /* initial display */
155 ICO_TRA("CicoStatusBarClockComponent::Initialize Leave");
159 /*--------------------------------------------------------------------------*/
161 * @brief update of clock component
164 * @return true: success false: failed
166 /*--------------------------------------------------------------------------*/
168 CicoStatusBarClockComponent::Update()
170 //ICO_TRA("CicoStatusBarClockComponent::Update Enter");
171 if (evasobj_ == NULL) {
176 nowtime = std::time(NULL);
177 std::tm *tm = std::localtime(&nowtime);
178 int min = tm->tm_min;
179 int hour = tm->tm_hour;
181 /* Make now clock image tabel */
182 int now_clock_image[CLOCK_OBJECT_COUNT];
184 now_clock_image[0]=TIME_IMAGE_PM;
187 now_clock_image[0]=TIME_IMAGE_AM;
189 time_t hour_m = hour % 12;
190 now_clock_image[1]=hour_m / 10;
191 now_clock_image[2]=hour_m % 10;
192 now_clock_image[3]=TIME_IMAGE_SP;
193 now_clock_image[4]=min / 10;
194 now_clock_image[5]=min % 10;
196 /* Set now clock image */
198 for ( i=0; i<CLOCK_OBJECT_COUNT; i++ ) {
200 /* if now clock image different last clock */
201 if ( now_clock_image[i] != last_clock_image[i] ) {
203 Evas_Object* obj = NULL;
204 obj = (Evas_Object*)edje_object_part_object_get(
205 evasobj_,clock_image_object[i] );
207 ICO_DBG("CicoStatusBarClockComponent image set[%s][%s]",
208 clock_image_object[i], clock_image_path[now_clock_image[i]]);
210 snprintf(wrk_path, sizeof(wrk_path), "%s/" IMG_DIR "/%s",
211 tzplatform_getenv(TZ_SYS_RO_APP),
212 clock_image_path[now_clock_image[i]]);
213 evas_object_image_file_set(obj, wrk_path, NULL);
214 // add update view area
215 // (Omitted update area is set so that evas_object_image_file_set())
216 //Evas_Coord x,y,w,h;
217 //evas_object_geometry_get( obj, &x, &y, &w, &h );
218 //evas_object_image_data_update_add( obj, x, y, w, h );
222 ICO_DBG("CicoStatusBarClockComponent image set error[object not found]" );
224 last_clock_image[i] = now_clock_image[i];
228 //ICO_TRA("CicoStatusBarClockComponent::Update Leave(true)");
232 /*--------------------------------------------------------------------------*/
234 * @brief get clock start position
236 * @param[out] x X axis
237 * @param[out] y Y axis
238 * @return true: success false: failed
240 /*--------------------------------------------------------------------------*/
242 CicoStatusBarClockComponent::GetClockStart( Evas_Coord *x_ret, Evas_Coord *y_ret)
244 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Enter");
245 if (evasobj_ == NULL) {
246 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
250 Evas_Object* obj = NULL;
251 obj = (Evas_Object*)edje_object_part_object_get(
252 evasobj_, clock_image_object[0] );
254 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(false)");
259 evas_object_geometry_get( obj, &x, &y, &w, &h );
263 ICO_TRA("CicoStatusBarClockComponent::GetClockStart Leave(true)");
267 /*--------------------------------------------------------------------------*/
269 * @brief default constructor
274 /*--------------------------------------------------------------------------*/
275 CicoNotificationPanelComponent::CicoNotificationPanelComponent()
280 /*--------------------------------------------------------------------------*/
287 /*--------------------------------------------------------------------------*/
288 CicoNotificationPanelComponent::~CicoNotificationPanelComponent()
292 /*--------------------------------------------------------------------------*/
294 * @brief initialize of notification component
297 * @return true: success false: failed
299 /*--------------------------------------------------------------------------*/
301 CicoNotificationPanelComponent::Initialize(Evas_Object *window, Evas *evas)
303 ICO_TRA("CicoNotificationPanelComponent::Initialize Enter");
305 if (evasobj_ != NULL) {
306 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
310 if (window == NULL) {
311 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(false)");
315 /* create Notification object */
316 ICO_DBG("Create Text Module end");
317 evasobj_=edje_object_add(evas);
319 snprintf(wrk_path, sizeof(wrk_path), "%s/" THEME_PATH,
320 tzplatform_getenv(TZ_SYS_RO_APP));
321 if (!edje_object_file_set(evasobj_, wrk_path, THEME_NOTIFICATION_NAME)) {
322 Edje_Load_Error err = edje_object_load_error_get(evasobj_);
323 const char *errmsg = edje_load_error_str(err);
324 ICO_ERR("could not load 'main' from statusbar.edj: %s",
329 evas_object_geometry_get( window, &x, &y, &w, &h );
330 evas_object_resize( evasobj_, w, h );
332 /* initial display */
336 ICO_TRA("CicoNotificationPanelComponent::Initialize Levae(true)");
340 /*--------------------------------------------------------------------------*/
342 * @brief set notification panel
345 * @param[in] iconpaht
346 * @param[in] soundpath
347 * @return true: success false: failed
349 /*--------------------------------------------------------------------------*/
351 CicoNotificationPanelComponent::SetNotification(const char *text,
352 const char *iconpath,
353 const char *soundpath)
355 ICO_TRA("CicoNotificationPanelComponent::SetNotification Enter"
356 "(text=%s icon=%s sound=%s)", text, iconpath, soundpath);
359 if (iconpath != NULL) {
360 Evas_Object* obj = NULL;
361 obj = (Evas_Object*)edje_object_part_object_get(
362 evasobj_, "noti_image");
364 ICO_DBG("SetNotification image set[%s]",iconpath);
365 evas_object_image_file_set(obj, iconpath, NULL);
368 ICO_DBG("SetNotification image set error[object not found]" );
379 ICO_TRA("CicoNotificationPanelComponent::SetNotification Leave");
382 //--------------------------------------------------------------------------
384 * @brief set text to Content_text
386 * @return true: success
388 //--------------------------------------------------------------------------
390 CicoNotificationPanelComponent::SetText(const char *text)
392 ICO_TRA("CicoNotificationPanelComponent::SetText Enter(text=%s)",
394 if ( text == NULL ) {
395 edje_object_part_text_set(evasobj_, "content_text", "");
398 edje_object_part_text_set(evasobj_, "content_text", text);
400 ICO_TRA("CicoNotificationPanelComponent::SetText Leave");
404 //--------------------------------------------------------------------------
406 * @brief set text to Content_text
408 * @return true: success
410 //--------------------------------------------------------------------------
412 CicoNotificationPanelComponent::SetTextEndPosition( Evas_Coord x_end, Evas_Coord y_end)
414 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Enter(%d,%d)",
417 if (evasobj_ == NULL) {
418 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
422 Evas_Object* obj = NULL;
423 obj = (Evas_Object*)edje_object_part_object_get(
424 evasobj_, "content_text" );
426 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave(false)");
431 evas_object_geometry_get( obj, &x, &y, &w, &h );
432 evas_object_resize( evasobj_, x_end, h );
433 ICO_TRA("CicoNotificationPanelComponent::text width %d -> %d",w, x_end - x -1);
434 evas_object_resize( obj, x_end - x -1, h );
435 edje_object_calc_force( obj );
437 ICO_TRA("CicoNotificationPanelComponent::SetTextEndPosition Leave" );
440 // vim: set expandtab ts=4 sw=4: