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)
38 CicoResourceConfig::GetImagePath(img_dir_path, ICO_HS_MAX_PATH_BUFF_LEN);
40 CicoGKeyFileConfig config;
41 config.Initialize(ICO_HOMESCREEN_CONFIG_FILE, ICO_SYC_PACKAGE_HOMESCREEN);
43 const char *value = config.ConfigGetString("switchzone", "keyname", "m");
44 if (strlen(value) > (sizeof(changeZoneKeyName) - 1)) {
45 ICO_WRN("[switchzone] keyname is strlen overflow. use default keyname(m)");
48 memset(changeZoneKeyName, 0, sizeof(changeZoneKeyName));
49 strncpy(changeZoneKeyName, value, strlen(value));
52 value = config.ConfigGetString("standardswitch", "homekeyname", "h");
53 if (strlen(value) > (sizeof(homeKeyName) - 1)) {
54 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(h)");
57 memset(homeKeyName, 0, sizeof(homeKeyName));
58 strncpy(homeKeyName, value, strlen(value));
61 value = config.ConfigGetString("standardswitch", "backkeyname", "b");
62 if (strlen(value) > (sizeof(backKeyName) - 1)) {
63 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(b)");
66 memset(backKeyName, 0, sizeof(backKeyName));
67 strncpy(backKeyName, value, strlen(value));
70 value = config.ConfigGetString("standardswitch", "menukeyname", "l");
71 menuKeyName[0] = value[0];
72 if (strlen(value) > (sizeof(menuKeyName) - 1)) {
73 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(l)");
76 memset(menuKeyName, 0, sizeof(menuKeyName));
77 strncpy(menuKeyName, value, strlen(value));
79 ICO_DBG("Assigned key config : changeZone[%s]", changeZoneKeyName);
80 ICO_DBG("Assigned key config : home[%s]", homeKeyName);
81 ICO_DBG("Assigned key config : back[%s]", backKeyName);
82 ICO_DBG("Assigned key config : menu[%s]", menuKeyName);
85 for (unsigned int ii = 0; ii < ICO_HS_CONTROL_BAR_SHORTCUT_MAX_NUM; ii++) {
86 sprintf(tmp_str, ICO_HS_CONTROL_BAR_CONFIG_SHORTCUT_APP"%d", ii);
87 value = config.ConfigGetString(ICO_HS_CONFIG_CONTROL_BAR, tmp_str, NULL);
88 if ((NULL != value) && (0 != strcmp(value, "none"))) {
89 shortcut_appid[ii] = value;
90 ICO_DBG("shortcut_appid[%d] = [%s]", ii, shortcut_appid[ii]);
93 shortcut_appid[ii] = NULL;
94 ICO_DBG("shortcut_appid[%d] = NULL", ii);
99 /*--------------------------------------------------------------------------*/
101 * @brief CicoHSControlBarWindow::~CicoHSControlBarWindow
107 /*--------------------------------------------------------------------------*/
108 CicoHSControlBarWindow::~CicoHSControlBarWindow(void)
110 /* not somthing to do */
113 /*--------------------------------------------------------------------------*/
115 * @brief CicoHSControlBarWindow::CreateControlBarWindow
116 * crate window (control bar)
118 * @param[in] pos_x position x
119 * @param[in] pos_y position y
120 * @param[in] width width
121 * @param[in] height height
122 * @return OK or ERRROR
124 /*--------------------------------------------------------------------------*/
126 CicoHSControlBarWindow::CreateControlBarWindow(int pos_x, int pos_y,
127 int width, int height)
130 char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
133 ret = CreateWindow(ICO_HS_CONTROL_BAR_WINDOW_TITLE,
134 pos_x, pos_y, width, height, EINA_TRUE);
140 evas = ecore_evas_get(window);
142 ICO_ERR("ecore_evas_get failed.");
143 ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow Leave(ERROR)");
147 // create background evas object
148 background = evas_object_rectangle_add(evas);
150 // add callback functions
151 evas_object_event_callback_add(background, EVAS_CALLBACK_KEY_DOWN,
152 CicoHSControlBarWindow::evasKeyDownCB, this);
155 evas_object_focus_set(background, EINA_FALSE);
156 Eina_Bool eret = evas_object_key_grab(background, (const char*)changeZoneKeyName,
158 if (EINA_FALSE == eret) {
159 ICO_WRN("evas_object_key_grab failed.");
161 eret = evas_object_key_grab(background, (const char*)homeKeyName,
163 if (EINA_FALSE == eret) {
164 ICO_WRN("evas_object_key_grab failed.");
166 eret = evas_object_key_grab(background, (const char*)backKeyName,
168 if (EINA_FALSE == eret) {
169 ICO_WRN("evas_object_key_grab failed.");
171 eret = evas_object_key_grab(background, (const char*)menuKeyName,
173 if (EINA_FALSE == eret) {
174 ICO_WRN("evas_object_key_grab failed.");
177 // set background coloer
178 evas_object_color_set(background,128,128,128,255);
180 // change window geometry
181 evas_object_move(background, 0, 0);
182 evas_object_resize(background, width,height);
185 evas_object_show(background);
189 snprintf(img_path, sizeof(img_path), "%s%s",
190 img_dir_path, ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
193 menu_btn = evas_object_image_filled_add(evas);
196 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
197 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
198 evas_object_image_file_set(menu_btn, img_path, NULL);
200 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
201 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
202 evas_object_image_file_set(menu_btn, img_path, NULL);
204 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
205 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
206 evas_object_image_file_set(menu_btn, img_path, NULL);
208 // load fisrt show icon image
209 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
210 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
211 evas_object_image_file_set(menu_btn, img_path, NULL);
213 evas_object_move(menu_btn,
214 (width/2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH /2),
215 ICO_HS_CONTROL_BAR_MENU_BTN_START_POS_Y);
216 evas_object_resize(menu_btn, ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH,
217 ICO_HS_CONTROL_BAR_MENU_BTN_HEIGHT);
218 evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_DOWN,
219 CicoHSControlBarTouch::TouchDownControlBar,
221 evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_UP,
222 CicoHSControlBarTouch::TouchUpControlBar,
224 evas_object_show(menu_btn);
227 AddShortcut(evas, width);
232 /*--------------------------------------------------------------------------*/
234 * @brief CicoHSControlBarWindow::AddShortcut
235 * shortcut addition (control bar)
237 * @param[in] evas Evas Object
238 * @param[in] width width
241 /*--------------------------------------------------------------------------*/
243 CicoHSControlBarWindow::AddShortcut(Evas *evas, int width)
245 ICO_TRA("CicoHSControlBarWindow::AddShortcut Enter");
251 const char *tmp_appid;
252 CicoHSLifeCycleController *life_cycle_controller;
254 /* menu button x position */
255 escPosX = (width / 2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH / 2);
257 life_cycle_controller = CicoHSLifeCycleController::getInstance();
259 tmp_space = (width - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH
260 * ICO_HS_CONTROL_BAR_BTN_MAX_NUM))
261 / (ICO_HS_CONTROL_BAR_BTN_MAX_NUM + 1);
262 ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_space = [%d]",
265 for (unsigned ii = 0; ii < ICO_HS_CONTROL_BAR_BTN_MAX_NUM; ii++) {
266 x = (ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH * ii) +
267 (tmp_space * (ii + 1));
269 if ((x <= escPosX) &&
270 ((x + ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH) >= escPosX)) {
271 /* The position of a menu button is skipped */
274 ICO_DBG("CicoHSControlBarWindow::AddShortcut x = [%d]", x);
276 tmp_appid = (const char *)(shortcut_appid[s_cnt]);
277 if (tmp_appid == NULL) {
278 /* No shortcut appid */
283 /* get APP information */
284 std::vector<CicoAilItems> aillist =
285 life_cycle_controller->getAilList();
287 /* add shortcut object */
288 for (unsigned int kk = 0; kk < aillist.size(); kk++ ) {
289 if (strncmp(aillist[kk].m_appid.c_str(), tmp_appid,
290 ICO_HS_MAX_PROCESS_NAME) == 0) {
291 ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_appid = [%s]",
293 shortcut[s_cnt] = evas_object_image_filled_add(evas);
294 evas_object_image_file_set(shortcut[s_cnt],
295 aillist[kk].m_icon.c_str(), NULL);
296 evas_object_move(shortcut[s_cnt], x,
297 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_START_POS_Y);
298 evas_object_resize(shortcut[s_cnt],
299 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH,
300 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_HEIGHT);
301 evas_object_event_callback_add(shortcut[s_cnt],
302 EVAS_CALLBACK_MOUSE_UP,
303 CicoHSControlBarTouch::TouchUpControlBar,
305 evas_object_show(shortcut[s_cnt]);
311 ICO_TRA("CicoHSControlBarWindow::AddShortcut Leave");
315 /*--------------------------------------------------------------------------*/
317 * @brief CicoHSControlBarWindow::FreeControlBarWindow
318 * free window (control bar)
323 /*--------------------------------------------------------------------------*/
325 CicoHSControlBarWindow::FreeControlBarWindow(void)
327 evas_object_del(background);
328 evas_object_del(menu_btn);
332 /*--------------------------------------------------------------------------*/
334 * @brief CicoHSControlBarWindow::TouchHome
340 /*--------------------------------------------------------------------------*/
342 CicoHSControlBarWindow::TouchHome(void)
345 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
346 CicoSound::GetInstance()->PlayFailureSound();
349 CicoSound::GetInstance()->PlayOperationSound();
351 CicoHomeScreen::ChangeMode(ICO_HS_SHOW_HIDE_PATTERN_SLIDE);
354 /*--------------------------------------------------------------------------*/
356 * @brief CicoHSControlBarWindow::SetNightMode
357 * set night mode color theme chagne
362 /*--------------------------------------------------------------------------*/
364 CicoHSControlBarWindow::SetNightMode(void)
366 ICO_TRA("CicoHSControlBarWindow::SetNightMode Enter");
368 bool state = CicoHSSystemState::getInstance()->getNightMode();
370 char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
372 ICO_DBG("ICO_SYC_STATE_ON");
373 evas_object_color_set(background,0,0,0,255);
374 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
375 ICO_DBG("Regulation=ON");
376 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
377 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
380 ICO_DBG("Regulation=OFF");
381 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
382 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
384 evas_object_image_file_set(menu_btn, img_path, NULL);
387 ICO_DBG("ICO_SYC_STATE_OFF");
388 evas_object_color_set(background,128,128,128,255);
389 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
390 ICO_DBG("Regulation=ON");
391 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
392 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
395 ICO_DBG("Regulation=OFF");
396 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
397 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
399 evas_object_image_file_set(menu_btn, img_path, NULL);
402 ICO_TRA("CicoHSControlBarWindow::SetNightMode Leave");
405 /*--------------------------------------------------------------------------*/
407 * @brief CicoHSControlBarWindow::SetRegulation
408 * set regulation color theme chagne
413 /*--------------------------------------------------------------------------*/
415 CicoHSControlBarWindow::SetRegulation(void)
417 ICO_TRA("CicoHSControlBarWindow::SetRegulation Enter");
419 char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
420 if (true == CicoHSSystemState::getInstance()->getNightMode()) {
421 ICO_DBG("NightMode=ON");
422 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
423 ICO_DBG("Regulation=ON");
424 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
425 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
428 ICO_DBG("Regulation=OFF");
429 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
430 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
434 ICO_DBG("NightMode=OFF");
435 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
436 ICO_DBG("Regulation=ON");
437 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
438 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
441 ICO_DBG("Regulation=OFF");
442 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
443 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
446 evas_object_image_file_set(menu_btn, img_path, NULL);
448 ICO_TRA("CicoHSControlBarWindow::SetRegulation Leave");
451 /*--------------------------------------------------------------------------*/
453 * @brief CicoHSControlBarWindow::SetWindowID
454 * set appid and surface
459 /*--------------------------------------------------------------------------*/
461 CicoHSControlBarWindow::SetWindowID(const char *appid,int surface)
463 strncpy(this->appid,appid,ICO_HS_MAX_PROCESS_NAME);
464 this->surface = surface;
467 /*--------------------------------------------------------------------------*/
469 * @brief CicoHSControlBarWindow::GetSurfaceId
470 * get surface id of control bar window
474 /*--------------------------------------------------------------------------*/
476 CicoHSControlBarWindow::GetSurfaceId(void)
478 return this->surface;
481 /*--------------------------------------------------------------------------*/
483 * @brief CicoHSControlBarWindow::GetAppId
484 * get application id of control bar
486 * @return application id
488 /*--------------------------------------------------------------------------*/
490 CicoHSControlBarWindow::GetAppId(void)
495 /*--------------------------------------------------------------------------*/
497 * @brief CicoHSControlBarWindow::TouchShortcut
498 * touch shortcut button
503 /*--------------------------------------------------------------------------*/
505 CicoHSControlBarWindow::TouchShortcut(const char *appid)
507 ICO_TRA("CicoHSControlBarWindow::TouchShortcut Enter");
510 CicoSound::GetInstance()->PlayOperationSound();
513 ICO_DBG("CicoHSControlBarWindow::TouchShortcut appid = [%s]", appid);
514 CicoHomeScreen::ExecuteApp(appid);
517 ICO_TRA("CicoHSControlBarWindow::TouchShortcut Leave");
520 //--------------------------------------------------------------------------
522 * @brief key up event callback function
524 * @pamam [in] data user data
525 * @param [in] evas evas instcance
526 * @param [in] obj evas object instcance
527 * @param [in] info event information(Evas_Event_Key_Down)
529 //--------------------------------------------------------------------------
531 CicoHSControlBarWindow::onKeyDown(void *data, Evas *evas,
532 Evas_Object *obj, void *info)
534 Evas_Event_Key_Down *evinfo = NULL;
535 evinfo = (Evas_Event_Key_Down*)info;
537 CicoSound::GetInstance()->PlayOperationSound();
539 ICO_PRF("TOUCH_EVENT Key Down keyname=%s, key=%d",
540 evinfo->keyname, (char)*evinfo->key);
542 if (0 == strcmp(evinfo->keyname, changeZoneKeyName)) {
543 CicoHomeScreen::ChangeZone();
545 else if (0 == strcmp(evinfo->keyname, homeKeyName)) {
548 else if (0 == strcmp(evinfo->keyname, backKeyName)) {
549 // TODO not assinded funciton
551 else if (0 == strcmp(evinfo->keyname, menuKeyName)) {
552 // TODO not assinded funciton
556 //--------------------------------------------------------------------------
558 * @brief key up event callback function
560 * @pamam [in] data user data
561 * @param [in] evas evas instcance
562 * @param [in] obj evas object instcance
563 * @param [in] info event information(Evas_Event_Key_Down)
565 //--------------------------------------------------------------------------
567 CicoHSControlBarWindow::evasKeyDownCB(void *data, Evas *evas,
568 Evas_Object *obj, void *info)
570 CicoHSControlBarWindow *ctrlbarwin = (CicoHSControlBarWindow*)(data);
571 ctrlbarwin->onKeyDown(data, evas, obj, info);
574 //--------------------------------------------------------------------------
576 * @brief Activation update swipe app
579 * @retval true update
580 * @retval false no update
582 //--------------------------------------------------------------------------
584 CicoHSControlBarWindow::ActivationUpdate(void)
586 return CicoHomeScreen::ActivationUpdate();
588 // vim: set expandtab ts=4 sw=4: