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 * @brief control bar window
14 #include "CicoHSControlBarWindow.h"
15 #include "CicoHSControlBarTouch.h"
16 #include "CicoGKeyFileConfig.h"
17 #include "CicoResourceConfig.h"
18 #include "CicoHomeScreen.h"
19 #include "CicoHSSystemState.h"
20 #include "CicoSound.h"
22 /*============================================================================*/
24 /*============================================================================*/
25 /*--------------------------------------------------------------------------*/
27 * @brief CicoHSControlBarWindow::CicoHSControlBarWindow
33 /*--------------------------------------------------------------------------*/
34 CicoHSControlBarWindow::CicoHSControlBarWindow(void)
36 ICO_DBG("CicoHSControlBarWindow::CicoHSControlBarWindow: Enter");
40 CicoResourceConfig::GetImagePath(img_dir_path, ICO_HS_MAX_PATH_BUFF_LEN);
42 CicoGKeyFileConfig config;
43 config.Initialize(ICO_HOMESCREEN_CONFIG_FILE);
44 const char *value = config.ConfigGetString("switchzone", "keyname", "m");
45 if (strlen(value) > (sizeof(changeZoneKeyName) - 1)) {
46 ICO_WRN("[switchzone] keyname is strlen overflow. use default keyname(m)");
49 memset(changeZoneKeyName, 0, sizeof(changeZoneKeyName));
50 strncpy(changeZoneKeyName, value, strlen(value));
53 value = config.ConfigGetString("standardswitch", "homekeyname", "h");
54 if (strlen(value) > (sizeof(homeKeyName) - 1)) {
55 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(h)");
58 memset(homeKeyName, 0, sizeof(homeKeyName));
59 strncpy(homeKeyName, value, strlen(value));
62 value = config.ConfigGetString("standardswitch", "backkeyname", "b");
63 if (strlen(value) > (sizeof(backKeyName) - 1)) {
64 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(b)");
67 memset(backKeyName, 0, sizeof(backKeyName));
68 strncpy(backKeyName, value, strlen(value));
71 value = config.ConfigGetString("standardswitch", "menukeyname", "l");
72 menuKeyName[0] = value[0];
73 if (strlen(value) > (sizeof(menuKeyName) - 1)) {
74 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(l)");
77 memset(menuKeyName, 0, sizeof(menuKeyName));
78 strncpy(menuKeyName, value, strlen(value));
80 ICO_DBG("Assigned key config : changeZone[%s]", changeZoneKeyName);
81 ICO_DBG("Assigned key config : home[%s]", homeKeyName);
82 ICO_DBG("Assigned key config : back[%s]", backKeyName);
83 ICO_DBG("Assigned key config : menu[%s]", menuKeyName);
86 for (unsigned int ii = 0; ii < ICO_HS_CONTROL_BAR_SHORTCUT_MAX_NUM; ii++) {
87 sprintf(tmp_str, ICO_HS_CONTROL_BAR_CONFIG_SHORTCUT_APP"%d", ii);
88 value = config.ConfigGetString(ICO_HS_CONFIG_CONTROL_BAR, tmp_str, NULL);
89 if ((NULL != value) && (0 != strcmp(value, "none"))) {
90 shortcut_appid[ii] = value;
91 ICO_DBG("shortcut_appid[%d] = [%s]", ii, shortcut_appid[ii]);
94 shortcut_appid[ii] = NULL;
95 ICO_DBG("shortcut_appid[%d] = NULL", ii);
98 ICO_DBG("CicoHSControlBarWindow::CicoHSControlBarWindow: Leave");
101 /*--------------------------------------------------------------------------*/
103 * @brief CicoHSControlBarWindow::~CicoHSControlBarWindow
109 /*--------------------------------------------------------------------------*/
110 CicoHSControlBarWindow::~CicoHSControlBarWindow(void)
112 /* not somthing to do */
115 /*--------------------------------------------------------------------------*/
117 * @brief CicoHSControlBarWindow::CreateControlBarWindow
118 * crate window (control bar)
120 * @param[in] pos_x position x
121 * @param[in] pos_y position y
122 * @param[in] width width
123 * @param[in] height height
124 * @return OK or ERRROR
126 /*--------------------------------------------------------------------------*/
128 CicoHSControlBarWindow::CreateControlBarWindow(int pos_x, int pos_y,
129 int width, int height)
132 char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
134 ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow: Enter(x/y=%d/%d,w/h=%d/%d)",
135 pos_x, pos_y, width, height);
138 ret = CreateWindow(ICO_HS_CONTROL_BAR_WINDOW_TITLE,
139 pos_x, pos_y, width, height, EINA_TRUE);
141 ICO_ERR("CreateWindow failed.");
142 ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow: Leave(Error=%d)", ret);
147 evas = ecore_evas_get(window);
149 ICO_ERR("ecore_evas_get failed.");
150 ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow Leave(ERROR)");
154 // create background evas object
155 background = evas_object_rectangle_add(evas);
157 // add callback functions
158 evas_object_event_callback_add(background, EVAS_CALLBACK_KEY_DOWN,
159 CicoHSControlBarWindow::evasKeyDownCB, this);
162 evas_object_focus_set(background, EINA_FALSE);
163 Eina_Bool eret = evas_object_key_grab(background, (const char*)changeZoneKeyName,
165 if (EINA_FALSE == eret) {
166 ICO_WRN("evas_object_key_grab failed.");
168 eret = evas_object_key_grab(background, (const char*)homeKeyName,
170 if (EINA_FALSE == eret) {
171 ICO_WRN("evas_object_key_grab failed.");
173 eret = evas_object_key_grab(background, (const char*)backKeyName,
175 if (EINA_FALSE == eret) {
176 ICO_WRN("evas_object_key_grab failed.");
178 eret = evas_object_key_grab(background, (const char*)menuKeyName,
180 if (EINA_FALSE == eret) {
181 ICO_WRN("evas_object_key_grab failed.");
184 // set background coloer
185 evas_object_color_set(background,128,128,128,255);
187 // change window geometry
188 evas_object_move(background, 0, 0);
189 evas_object_resize(background, width,height);
192 evas_object_show(background);
196 snprintf(img_path, sizeof(img_path), "%s%s",
197 img_dir_path, ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
200 menu_btn = evas_object_image_filled_add(evas);
203 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
204 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
205 evas_object_image_file_set(menu_btn, img_path, NULL);
207 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
208 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
209 evas_object_image_file_set(menu_btn, img_path, NULL);
211 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
212 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
213 evas_object_image_file_set(menu_btn, img_path, NULL);
215 // load fisrt show icon image
216 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
217 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
218 evas_object_image_file_set(menu_btn, img_path, NULL);
220 evas_object_move(menu_btn,
221 (width/2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH /2),
222 ICO_HS_CONTROL_BAR_MENU_BTN_START_POS_Y);
223 evas_object_resize(menu_btn, ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH,
224 ICO_HS_CONTROL_BAR_MENU_BTN_HEIGHT);
225 evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_DOWN,
226 CicoHSControlBarTouch::TouchDownControlBar,
228 evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_UP,
229 CicoHSControlBarTouch::TouchUpControlBar,
231 evas_object_show(menu_btn);
234 AddShortcut(evas, width);
236 ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow: Leave");
240 /*--------------------------------------------------------------------------*/
242 * @brief CicoHSControlBarWindow::AddShortcut
243 * shortcut addition (control bar)
245 * @param[in] evas Evas Object
246 * @param[in] width width
249 /*--------------------------------------------------------------------------*/
251 CicoHSControlBarWindow::AddShortcut(Evas *evas, int width)
253 ICO_TRA("CicoHSControlBarWindow::AddShortcut Enter");
259 const char *tmp_appid;
260 CicoHSLifeCycleController *life_cycle_controller;
262 /* menu button x position */
263 escPosX = (width / 2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH / 2);
265 life_cycle_controller = CicoHSLifeCycleController::getInstance();
267 tmp_space = (width - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH
268 * ICO_HS_CONTROL_BAR_BTN_MAX_NUM))
269 / (ICO_HS_CONTROL_BAR_BTN_MAX_NUM + 1);
270 ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_space = [%d]",
273 for (unsigned ii = 0; ii < ICO_HS_CONTROL_BAR_BTN_MAX_NUM; ii++) {
274 x = (ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH * ii) +
275 (tmp_space * (ii + 1));
277 if ((x <= escPosX) &&
278 ((x + ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH) >= escPosX)) {
279 /* The position of a menu button is skipped */
282 ICO_DBG("CicoHSControlBarWindow::AddShortcut x = [%d]", x);
284 tmp_appid = (const char *)(shortcut_appid[s_cnt]);
285 if (tmp_appid == NULL) {
286 /* No shortcut appid */
291 /* get APP information */
292 std::vector<CicoAilItems> aillist =
293 life_cycle_controller->getAilList();
295 /* add shortcut object */
296 for (unsigned int kk = 0; kk < aillist.size(); kk++ ) {
297 if (strncmp(aillist[kk].m_appid.c_str(), tmp_appid,
298 ICO_HS_MAX_PROCESS_NAME) == 0) {
299 ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_appid = [%s]",
301 shortcut[s_cnt] = evas_object_image_filled_add(evas);
302 evas_object_image_file_set(shortcut[s_cnt],
303 aillist[kk].m_icon.c_str(), NULL);
304 evas_object_move(shortcut[s_cnt], x,
305 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_START_POS_Y);
306 evas_object_resize(shortcut[s_cnt],
307 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH,
308 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_HEIGHT);
309 evas_object_event_callback_add(shortcut[s_cnt],
310 EVAS_CALLBACK_MOUSE_UP,
311 CicoHSControlBarTouch::TouchUpControlBar,
313 evas_object_show(shortcut[s_cnt]);
319 ICO_TRA("CicoHSControlBarWindow::AddShortcut Leave");
323 /*--------------------------------------------------------------------------*/
325 * @brief CicoHSControlBarWindow::FreeControlBarWindow
326 * free window (control bar)
331 /*--------------------------------------------------------------------------*/
333 CicoHSControlBarWindow::FreeControlBarWindow(void)
335 evas_object_del(background);
336 evas_object_del(menu_btn);
340 /*--------------------------------------------------------------------------*/
342 * @brief CicoHSControlBarWindow::TouchHome
348 /*--------------------------------------------------------------------------*/
350 CicoHSControlBarWindow::TouchHome(void)
353 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
354 CicoSound::GetInstance()->PlayFailureSound();
357 CicoSound::GetInstance()->PlayOperationSound();
359 CicoHomeScreen::ChangeMode(ICO_HS_SHOW_HIDE_PATTERN_SLIDE);
362 /*--------------------------------------------------------------------------*/
364 * @brief CicoHSControlBarWindow::SetNightMode
365 * set night mode color theme chagne
370 /*--------------------------------------------------------------------------*/
372 CicoHSControlBarWindow::SetNightMode(void)
374 ICO_TRA("CicoHSControlBarWindow::SetNightMode Enter");
376 bool state = CicoHSSystemState::getInstance()->getNightMode();
378 char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
380 ICO_DBG("ICO_SYC_STATE_ON");
381 evas_object_color_set(background,0,0,0,255);
382 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
383 ICO_DBG("Regulation=ON");
384 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
385 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
388 ICO_DBG("Regulation=OFF");
389 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
390 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
392 evas_object_image_file_set(menu_btn, img_path, NULL);
395 ICO_DBG("ICO_SYC_STATE_OFF");
396 evas_object_color_set(background,128,128,128,255);
397 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
398 ICO_DBG("Regulation=ON");
399 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
400 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
403 ICO_DBG("Regulation=OFF");
404 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
405 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
407 evas_object_image_file_set(menu_btn, img_path, NULL);
410 ICO_TRA("CicoHSControlBarWindow::SetNightMode Leave");
413 /*--------------------------------------------------------------------------*/
415 * @brief CicoHSControlBarWindow::SetRegulation
416 * set regulation color theme chagne
421 /*--------------------------------------------------------------------------*/
423 CicoHSControlBarWindow::SetRegulation(void)
425 ICO_TRA("CicoHSControlBarWindow::SetRegulation Enter");
427 char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
428 if (true == CicoHSSystemState::getInstance()->getNightMode()) {
429 ICO_DBG("NightMode=ON");
430 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
431 ICO_DBG("Regulation=ON");
432 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
433 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
436 ICO_DBG("Regulation=OFF");
437 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
438 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
442 ICO_DBG("NightMode=OFF");
443 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
444 ICO_DBG("Regulation=ON");
445 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
446 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
449 ICO_DBG("Regulation=OFF");
450 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
451 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
454 evas_object_image_file_set(menu_btn, img_path, NULL);
456 ICO_TRA("CicoHSControlBarWindow::SetRegulation Leave");
459 /*--------------------------------------------------------------------------*/
461 * @brief CicoHSControlBarWindow::SetWindowID
462 * set appid and surface
467 /*--------------------------------------------------------------------------*/
469 CicoHSControlBarWindow::SetWindowID(const char *appid,int surface)
471 strncpy(this->appid,appid,ICO_HS_MAX_PROCESS_NAME);
472 this->surface = surface;
475 /*--------------------------------------------------------------------------*/
477 * @brief CicoHSControlBarWindow::GetSurfaceId
478 * get surface id of control bar window
482 /*--------------------------------------------------------------------------*/
484 CicoHSControlBarWindow::GetSurfaceId(void)
486 return this->surface;
489 /*--------------------------------------------------------------------------*/
491 * @brief CicoHSControlBarWindow::GetAppId
492 * get application id of control bar
494 * @return application id
496 /*--------------------------------------------------------------------------*/
498 CicoHSControlBarWindow::GetAppId(void)
503 /*--------------------------------------------------------------------------*/
505 * @brief CicoHSControlBarWindow::TouchShortcut
506 * touch shortcut button
511 /*--------------------------------------------------------------------------*/
513 CicoHSControlBarWindow::TouchShortcut(const char *appid)
515 ICO_TRA("CicoHSControlBarWindow::TouchShortcut Enter");
518 CicoSound::GetInstance()->PlayOperationSound();
521 ICO_DBG("CicoHSControlBarWindow::TouchShortcut appid = [%s]", appid);
522 CicoHomeScreen::ExecuteApp(appid);
524 ICO_TRA("CicoHSControlBarWindow::TouchShortcut Leave");
527 //--------------------------------------------------------------------------
529 * @brief key up event callback function
531 * @pamam [in] data user data
532 * @param [in] evas evas instcance
533 * @param [in] obj evas object instcance
534 * @param [in] info event information(Evas_Event_Key_Down)
536 //--------------------------------------------------------------------------
538 CicoHSControlBarWindow::onKeyDown(void *data, Evas *evas,
539 Evas_Object *obj, void *info)
541 Evas_Event_Key_Down *evinfo = NULL;
542 evinfo = (Evas_Event_Key_Down*)info;
544 CicoSound::GetInstance()->PlayOperationSound();
546 ICO_PRF("TOUCH_EVENT Key Down keyname=%s, key=%d",
547 evinfo->keyname, (char)*evinfo->key);
549 if (0 == strcmp(evinfo->keyname, changeZoneKeyName)) {
550 CicoHomeScreen::ChangeZone();
552 else if (0 == strcmp(evinfo->keyname, homeKeyName)) {
555 else if (0 == strcmp(evinfo->keyname, backKeyName)) {
556 // TODO not assinded funciton
558 else if (0 == strcmp(evinfo->keyname, menuKeyName)) {
559 // TODO not assinded funciton
563 //--------------------------------------------------------------------------
565 * @brief key up event callback function
567 * @pamam [in] data user data
568 * @param [in] evas evas instcance
569 * @param [in] obj evas object instcance
570 * @param [in] info event information(Evas_Event_Key_Down)
572 //--------------------------------------------------------------------------
574 CicoHSControlBarWindow::evasKeyDownCB(void *data, Evas *evas,
575 Evas_Object *obj, void *info)
577 CicoHSControlBarWindow *ctrlbarwin = (CicoHSControlBarWindow*)(data);
578 ctrlbarwin->onKeyDown(data, evas, obj, info);
581 //--------------------------------------------------------------------------
583 * @brief Activation update swipe app
586 * @retval true update
587 * @retval false no update
589 //--------------------------------------------------------------------------
591 CicoHSControlBarWindow::ActivationUpdate(void)
593 return CicoHomeScreen::ActivationUpdate();
595 // vim: set expandtab ts=4 sw=4: