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);
42 const char *value = config.ConfigGetString("switchzone", "keyname", "m");
43 if (strlen(value) > (sizeof(changeZoneKeyName) - 1)) {
44 ICO_WRN("[switchzone] keyname is strlen overflow. use default keyname(m)");
47 memset(changeZoneKeyName, 0, sizeof(changeZoneKeyName));
48 strncpy(changeZoneKeyName, value, strlen(value));
51 value = config.ConfigGetString("standardswitch", "homekeyname", "h");
52 if (strlen(value) > (sizeof(homeKeyName) - 1)) {
53 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(h)");
56 memset(homeKeyName, 0, sizeof(homeKeyName));
57 strncpy(homeKeyName, value, strlen(value));
60 value = config.ConfigGetString("standardswitch", "backkeyname", "b");
61 if (strlen(value) > (sizeof(backKeyName) - 1)) {
62 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(b)");
65 memset(backKeyName, 0, sizeof(backKeyName));
66 strncpy(backKeyName, value, strlen(value));
69 value = config.ConfigGetString("standardswitch", "menukeyname", "l");
70 menuKeyName[0] = value[0];
71 if (strlen(value) > (sizeof(menuKeyName) - 1)) {
72 ICO_WRN("[standardswitch] keyname is strlen overflow. use default keyname(l)");
75 memset(menuKeyName, 0, sizeof(menuKeyName));
76 strncpy(menuKeyName, value, strlen(value));
78 ICO_DBG("Assigned key config : changeZone[%s]", changeZoneKeyName);
79 ICO_DBG("Assigned key config : home[%s]", homeKeyName);
80 ICO_DBG("Assigned key config : back[%s]", backKeyName);
81 ICO_DBG("Assigned key config : menu[%s]", menuKeyName);
84 for (unsigned int ii = 0; ii < ICO_HS_CONTROL_BAR_SHORTCUT_MAX_NUM; ii++) {
85 sprintf(tmp_str, ICO_HS_CONTROL_BAR_CONFIG_SHORTCUT_APP"%d", ii);
86 value = config.ConfigGetString(ICO_HS_CONFIG_CONTROL_BAR, tmp_str, NULL);
87 if ((NULL != value) && (0 != strcmp(value, "none"))) {
88 shortcut_appid[ii] = value;
89 ICO_DBG("shortcut_appid[%d] = [%s]", ii, shortcut_appid[ii]);
92 shortcut_appid[ii] = NULL;
93 ICO_DBG("shortcut_appid[%d] = NULL", ii);
98 /*--------------------------------------------------------------------------*/
100 * @brief CicoHSControlBarWindow::~CicoHSControlBarWindow
106 /*--------------------------------------------------------------------------*/
107 CicoHSControlBarWindow::~CicoHSControlBarWindow(void)
109 /* not somthing to do */
112 /*--------------------------------------------------------------------------*/
114 * @brief CicoHSControlBarWindow::CreateControlBarWindow
115 * crate window (control bar)
117 * @param[in] pos_x position x
118 * @param[in] pos_y position y
119 * @param[in] width width
120 * @param[in] height height
121 * @return OK or ERRROR
123 /*--------------------------------------------------------------------------*/
125 CicoHSControlBarWindow::CreateControlBarWindow(int pos_x, int pos_y,
126 int width, int height)
129 char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
132 ret = CreateWindow(ICO_HS_CONTROL_BAR_WINDOW_TITLE,
133 pos_x, pos_y, width, height, EINA_TRUE);
139 evas = ecore_evas_get(window);
141 ICO_ERR("ecore_evas_get failed.");
142 ICO_DBG("CicoHSControlBarWindow::CreateControlBarWindow Leave(ERROR)");
146 // create background evas object
147 background = evas_object_rectangle_add(evas);
149 // add callback functions
150 evas_object_event_callback_add(background, EVAS_CALLBACK_KEY_DOWN,
151 CicoHSControlBarWindow::evasKeyDownCB, this);
154 evas_object_focus_set(background, EINA_FALSE);
155 Eina_Bool eret = evas_object_key_grab(background, (const char*)changeZoneKeyName,
157 if (EINA_FALSE == eret) {
158 ICO_WRN("evas_object_key_grab failed.");
160 eret = evas_object_key_grab(background, (const char*)homeKeyName,
162 if (EINA_FALSE == eret) {
163 ICO_WRN("evas_object_key_grab failed.");
165 eret = evas_object_key_grab(background, (const char*)backKeyName,
167 if (EINA_FALSE == eret) {
168 ICO_WRN("evas_object_key_grab failed.");
170 eret = evas_object_key_grab(background, (const char*)menuKeyName,
172 if (EINA_FALSE == eret) {
173 ICO_WRN("evas_object_key_grab failed.");
176 // set background coloer
177 evas_object_color_set(background,128,128,128,255);
179 // change window geometry
180 evas_object_move(background, 0, 0);
181 evas_object_resize(background, width,height);
184 evas_object_show(background);
188 snprintf(img_path, sizeof(img_path), "%s%s",
189 img_dir_path, ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
192 menu_btn = evas_object_image_filled_add(evas);
195 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
196 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY2);
197 evas_object_image_file_set(menu_btn, img_path, NULL);
199 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
200 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT);
201 evas_object_image_file_set(menu_btn, img_path, NULL);
203 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
204 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_NIHGT2);
205 evas_object_image_file_set(menu_btn, img_path, NULL);
207 // load fisrt show icon image
208 snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,
209 ICO_HS_IMAGE_FILE_CONTROL_BAR_BUTTON_DAY);
210 evas_object_image_file_set(menu_btn, img_path, NULL);
212 evas_object_move(menu_btn,
213 (width/2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH /2),
214 ICO_HS_CONTROL_BAR_MENU_BTN_START_POS_Y);
215 evas_object_resize(menu_btn, ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH,
216 ICO_HS_CONTROL_BAR_MENU_BTN_HEIGHT);
217 evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_DOWN,
218 CicoHSControlBarTouch::TouchDownControlBar,
220 evas_object_event_callback_add(menu_btn, EVAS_CALLBACK_MOUSE_UP,
221 CicoHSControlBarTouch::TouchUpControlBar,
223 evas_object_show(menu_btn);
226 AddShortcut(evas, width);
231 /*--------------------------------------------------------------------------*/
233 * @brief CicoHSControlBarWindow::AddShortcut
234 * shortcut addition (control bar)
236 * @param[in] evas Evas Object
237 * @param[in] width width
240 /*--------------------------------------------------------------------------*/
242 CicoHSControlBarWindow::AddShortcut(Evas *evas, int width)
244 ICO_TRA("CicoHSControlBarWindow::AddShortcut Enter");
250 const char *tmp_appid;
251 CicoHSLifeCycleController *life_cycle_controller;
253 /* menu button x position */
254 escPosX = (width / 2) - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH / 2);
256 life_cycle_controller = CicoHSLifeCycleController::getInstance();
258 tmp_space = (width - (ICO_HS_CONTROL_BAR_MENU_BTN_WIDTH
259 * ICO_HS_CONTROL_BAR_BTN_MAX_NUM))
260 / (ICO_HS_CONTROL_BAR_BTN_MAX_NUM + 1);
261 ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_space = [%d]",
264 for (unsigned ii = 0; ii < ICO_HS_CONTROL_BAR_BTN_MAX_NUM; ii++) {
265 x = (ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH * ii) +
266 (tmp_space * (ii + 1));
268 if ((x <= escPosX) &&
269 ((x + ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH) >= escPosX)) {
270 /* The position of a menu button is skipped */
273 ICO_DBG("CicoHSControlBarWindow::AddShortcut x = [%d]", x);
275 tmp_appid = (const char *)(shortcut_appid[s_cnt]);
276 if (tmp_appid == NULL) {
277 /* No shortcut appid */
282 /* get APP information */
283 std::vector<CicoAilItems> aillist =
284 life_cycle_controller->getAilList();
286 /* add shortcut object */
287 for (unsigned int kk = 0; kk < aillist.size(); kk++ ) {
288 if (strncmp(aillist[kk].m_appid.c_str(), tmp_appid,
289 ICO_HS_MAX_PROCESS_NAME) == 0) {
290 ICO_DBG("CicoHSControlBarWindow::AddShortcut tmp_appid = [%s]",
292 shortcut[s_cnt] = evas_object_image_filled_add(evas);
293 evas_object_image_file_set(shortcut[s_cnt],
294 aillist[kk].m_icon.c_str(), NULL);
295 evas_object_move(shortcut[s_cnt], x,
296 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_START_POS_Y);
297 evas_object_resize(shortcut[s_cnt],
298 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_WIDTH,
299 ICO_HS_CONTROL_BAR_SHORTCUT_BTN_HEIGHT);
300 evas_object_event_callback_add(shortcut[s_cnt],
301 EVAS_CALLBACK_MOUSE_UP,
302 CicoHSControlBarTouch::TouchUpControlBar,
304 evas_object_show(shortcut[s_cnt]);
310 ICO_TRA("CicoHSControlBarWindow::AddShortcut Leave");
314 /*--------------------------------------------------------------------------*/
316 * @brief CicoHSControlBarWindow::FreeControlBarWindow
317 * free window (control bar)
322 /*--------------------------------------------------------------------------*/
324 CicoHSControlBarWindow::FreeControlBarWindow(void)
326 evas_object_del(background);
327 evas_object_del(menu_btn);
331 /*--------------------------------------------------------------------------*/
333 * @brief CicoHSControlBarWindow::TouchHome
339 /*--------------------------------------------------------------------------*/
341 CicoHSControlBarWindow::TouchHome(void)
344 if (true == CicoHSSystemState::getInstance()->getRegulation()) {
345 CicoSound::GetInstance()->PlayFailureSound();
348 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: