Sticker Consumer / src /

main.c

  1. /*
  2. * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16.  
  17. #include "main.h"
  18.  
  19. typedef struct appdata {
  20. Evas_Object *win;
  21. Evas_Object *conform;
  22. Evas_Object *nf;
  23. sticker_consumer_h sticker_h;
  24. char *sticker_path[STICKER_MAX];
  25. int idx;
  26. } appdata_s;
  27.  
  28. typedef struct itemdata {
  29. int index;
  30. const char *path;
  31. appdata_s *ad;
  32. } itemdata_s;
  33.  
  34. typedef enum {
  35. FOREACH_ALL = 0,
  36. FOREACH_BY_KEYWORD,
  37. FOREACH_BY_GROUP,
  38. FOREACH_BY_TYPE
  39. } api_type;
  40.  
  41. /*
  42. * @brief Function will be operated when window deletion is requested
  43. * @param[in] data The data to be passed to the callback function
  44. * @param[in] obj The Evas object handle to be passed to the callback function
  45. * @param[in] event_info The system event information
  46. */
  47. static void
  48. win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
  49. {
  50. ui_app_exit();
  51. }
  52.  
  53. /*
  54. * @brief Function to get object on gengrid item's swallow part
  55. * @param[in] data The data to be passed to the callback function
  56. * @param[in] obj The Evas object handle to be passed to the callback function
  57. * @param[in] part The name of swallow part
  58. * @param[out] Evas_Object An image to use as genlist item's swallow part
  59. */
  60. static Evas_Object*
  61. gengrid_content_get_cb(void *data, Evas_Object *obj, const char *part)
  62. {
  63. itemdata_s *id = data;
  64.  
  65. if (!strcmp(part, "elm.swallow.icon")) {
  66. Evas_Object *img = elm_image_add(obj);
  67.  
  68. elm_image_file_set(img, id->path, NULL);
  69. elm_image_aspect_fixed_set(img, EINA_FALSE);
  70. elm_image_preload_disabled_set(img, EINA_FALSE);
  71. evas_object_show(img);
  72.  
  73. return img;
  74. }
  75.  
  76. return NULL;
  77. }
  78.  
  79. /*
  80. * @brief Function to retrieve all sticker data
  81. * @param[in] data_handle The sticker data handle
  82. * @param[in] user_data The data to be passed to the callback function
  83. */
  84. static void
  85. sticker_info_cb(sticker_data_h data_handle, void *user_data)
  86. {
  87. appdata_s *ad = user_data;
  88. int ret;
  89. sticker_data_uri_type_e type;
  90. /* Get sticker URI and URI type */
  91. ret = sticker_data_get_uri(data_handle, &type, &ad->sticker_path[ad->idx]);
  92. /* Check sticker error code */
  93. if (ret != STICKER_ERROR_NONE) {
  94. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get sticker path");
  95. return;
  96. }
  97.  
  98. ad->idx++;
  99. }
  100.  
  101. /*
  102. * @brief Function to retrieve all keywords
  103. * @param[in] keyword The keyword of the sticker
  104. * @param[in] user_data The data to be passed to the callback function
  105. */
  106. static void
  107. keyword_list_cb(const char *keyword, void *user_data)
  108. {
  109. dlog_print(DLOG_INFO, LOG_TAG, "keyword : %s", keyword);
  110. }
  111.  
  112. /*
  113. * @brief Function to retrieve all group names
  114. * @param[in] group The group name of the sticker
  115. * @param[in] user_data The data to be passed to the callback function
  116. */
  117. static void
  118. group_list_cb(const char *group, void *user_data)
  119. {
  120. dlog_print(DLOG_INFO, LOG_TAG, "group name : %s", group);
  121. }
  122.  
  123. /*
  124. * @brief Function will be called when gengrid is deleted
  125. * @param[in] data The data to be passed to the callback function
  126. * @param[in] obj The Evas object handle to be passed to the callback function
  127. */
  128. void
  129. gengrid_uri_del(void *data, Evas_Object *obj EINA_UNUSED)
  130. {
  131. itemdata_s *id = data;
  132. eina_stringshare_del(id->path);
  133. free(id);
  134. }
  135.  
  136. /*
  137. * @brief Function to create gengrid
  138. * @param[in] ad The data structure to manage gui object
  139. * @param[out] Evas_Object The layout object which is created
  140. */
  141. static Evas_Object*
  142. create_gengrid(appdata_s *ad, api_type type)
  143. {
  144. int ret, result = 0;
  145. Elm_Gengrid_Item_Class *gic;
  146. Evas_Object *gengrid;
  147. int i;
  148.  
  149. gengrid = elm_gengrid_add(ad->nf);
  150. evas_object_size_hint_weight_set(gengrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  151. evas_object_size_hint_align_set(gengrid, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
  152. elm_gengrid_item_size_set(gengrid, ELM_SCALE_SIZE(110), ELM_SCALE_SIZE(110));
  153. elm_gengrid_align_set(gengrid, 0.5, 0.1);
  154.  
  155. gic = elm_gengrid_item_class_new();
  156. gic->item_style = "default";
  157. gic->func.text_get = NULL;
  158. gic->func.content_get = gengrid_content_get_cb;
  159. gic->func.state_get = NULL;
  160. gic->func.del = gengrid_uri_del;
  161.  
  162. ad->idx = 0;
  163. switch (type) {
  164. case FOREACH_ALL:
  165. /* Retrieve all sticker data */
  166. ret = sticker_consumer_data_foreach_all(ad->sticker_h, 0, STICKER_MAX, &result, sticker_info_cb, ad);
  167. /* Check sticker error code */
  168. if (ret != STICKER_ERROR_NONE)
  169. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call sticker_consumer_data_foreach_all()");
  170.  
  171. break;
  172. case FOREACH_BY_KEYWORD:
  173. /* Retrieve all keywords */
  174. ret = sticker_consumer_keyword_list_foreach_all(ad->sticker_h, keyword_list_cb, NULL);
  175. /* Check sticker error code */
  176. if (ret != STICKER_ERROR_NONE)
  177. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call sticker_consumer_keyword_list_foreach_all()");
  178.  
  179. /* Retrieve all sticker data by keyword */
  180. ret = sticker_consumer_data_foreach_by_keyword(ad->sticker_h, 0, STICKER_MAX, &result, "face", sticker_info_cb, ad);
  181. /* Check sticker error code */
  182. if (ret != STICKER_ERROR_NONE)
  183. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call sticker_consumer_data_foreach_by_keyword()");
  184.  
  185. break;
  186. case FOREACH_BY_GROUP:
  187. /* Retrieve all group names */
  188. ret = sticker_consumer_group_list_foreach_all(ad->sticker_h, group_list_cb, NULL);
  189. /* Check sticker error code */
  190. if (ret != STICKER_ERROR_NONE)
  191. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call sticker_consumer_group_list_foreach_all()");
  192.  
  193. /* Retrieve all sticker data by group name */
  194. ret = sticker_consumer_data_foreach_by_group(ad->sticker_h, 0, STICKER_MAX, &result, "animal", sticker_info_cb, ad);
  195. /* Check sticker error code */
  196. if (ret != STICKER_ERROR_NONE)
  197. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call sticker_consumer_data_foreach_by_group()");
  198.  
  199. break;
  200. case FOREACH_BY_TYPE:
  201. /* Retrieve all sticker data by URI type */
  202. ret = sticker_consumer_data_foreach_by_type(ad->sticker_h, 0, STICKER_MAX, &result, STICKER_DATA_URI_LOCAL_PATH, sticker_info_cb, ad);
  203. /* Check sticker error code */
  204. if (ret != STICKER_ERROR_NONE)
  205. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call sticker_consumer_data_foreach_by_type()");
  206.  
  207. break;
  208. default:
  209. break;
  210. }
  211.  
  212. for (i = 0; i < result; i++) {
  213. itemdata_s *id = calloc(sizeof(itemdata_s), 1);
  214. id->index = i;
  215. id->path = eina_stringshare_add(ad->sticker_path[i]);
  216. id->ad = ad;
  217. elm_gengrid_item_append(gengrid, gic, id, NULL, NULL);
  218. }
  219.  
  220. evas_object_show(gengrid);
  221.  
  222. return gengrid;
  223. }
  224.  
  225. /*
  226. * @brief Function to create sticker image view layout
  227. * @param[in] ad The data structure to manage gui object
  228. * @param[out] Evas_Object The layout object which is created
  229. */
  230. static Evas_Object *
  231. create_sticker_view(appdata_s *ad, char *subject, api_type type)
  232. {
  233. Elm_Object_Item *nf_it;
  234. Evas_Object *gengrid;
  235.  
  236. gengrid = create_gengrid(ad, type);
  237. nf_it = elm_naviframe_item_push(ad->nf, subject, NULL, NULL, gengrid, NULL);
  238.  
  239. return gengrid;
  240. }
  241.  
  242. /*
  243. * @brief Function will be called when "Retrieves all sticker data" item is selected
  244. * @param[in] data The data to be passed to the callback function
  245. * @param[in] obj The Evas object handle to be passed to the callback function
  246. * @param[in] event_info The system event information
  247. */
  248. void
  249. foreach_all_cb(void *data, Evas_Object *obj, void *event_info)
  250. {
  251. appdata_s *ad = (appdata_s *)data;
  252. Evas_Object *sticker_view;
  253. sticker_view = create_sticker_view(ad, "Retrieves all sticker data", FOREACH_ALL);
  254. }
  255.  
  256. /*
  257. * @brief Function will be called when "Retrieves sticker data using keyword" item is selected
  258. * @param[in] data The data to be passed to the callback function
  259. * @param[in] obj The Evas object handle to be passed to the callback function
  260. * @param[in] event_info The system event information
  261. */
  262. void
  263. foreach_by_keyword_cb(void *data, Evas_Object *obj, void *event_info)
  264. {
  265. appdata_s *ad = (appdata_s *)data;
  266. Evas_Object *sticker_view;
  267. sticker_view = create_sticker_view(ad, "Retrieves sticker data using keyword", FOREACH_BY_KEYWORD);
  268. }
  269.  
  270. /*
  271. * @brief Function will be called when "Retrieves sticker data using group" item is selected
  272. * @param[in] data The data to be passed to the callback function
  273. * @param[in] obj The Evas object handle to be passed to the callback function
  274. * @param[in] event_info The system event information
  275. */
  276. void
  277. foreach_by_group_cb(void *data, Evas_Object *obj, void *event_info)
  278. {
  279. appdata_s *ad = (appdata_s *)data;
  280. Evas_Object *sticker_view;
  281. sticker_view = create_sticker_view(ad, "Retrieves sticker data using group", FOREACH_BY_GROUP);
  282. }
  283.  
  284. /*
  285. * @brief Function will be called when "Retrieves sticker data using URI type" item is selected
  286. * @param[in] data The data to be passed to the callback function
  287. * @param[in] obj The Evas object handle to be passed to the callback function
  288. * @param[in] event_info The system event information
  289. */
  290. void
  291. foreach_by_type_cb(void *data, Evas_Object *obj, void *event_info)
  292. {
  293. appdata_s *ad = (appdata_s *)data;
  294. Evas_Object *sticker_view;
  295. sticker_view = create_sticker_view(ad, "Retrieves sticker data using URI type", FOREACH_BY_TYPE);
  296. }
  297.  
  298. /*
  299. * @brief Function will be called when list item is selected
  300. * @param[in] data The data to be passed to the callback function
  301. * @param[in] obj The Evas object handle to be passed to the callback function
  302. * @param[in] event_info The system event information
  303. */
  304. static void
  305. list_selected_cb(void *data, Evas_Object *obj, void *event_info)
  306. {
  307. Elm_Object_Item *it = event_info;
  308. elm_list_item_selected_set(it, EINA_FALSE);
  309. }
  310.  
  311. /*
  312. * @brief Function to create main view layout
  313. * @param[in] ad The data structure to manage gui object
  314. * @param[out] Evas_Object The layout object which is created
  315. */
  316. static Evas_Object *
  317. create_main_list(appdata_s *ad)
  318. {
  319. Evas_Object *list;
  320.  
  321. /* List */
  322. list = elm_list_add(ad->nf);
  323. elm_list_mode_set(list, ELM_LIST_COMPRESS);
  324. evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
  325.  
  326. /* Main Menu Items Here */
  327. elm_list_item_append(list, "Retrieves all sticker data", NULL, NULL, foreach_all_cb, ad);
  328. elm_list_item_append(list, "Retrieves sticker data using keyword", NULL, NULL, foreach_by_keyword_cb, ad);
  329. elm_list_item_append(list, "Retrieves sticker data using group", NULL, NULL, foreach_by_group_cb, ad);
  330. elm_list_item_append(list, "Retrieves sticker data using URI type", NULL, NULL, foreach_by_type_cb, ad);
  331.  
  332. elm_list_go(list);
  333.  
  334. return list;
  335. }
  336.  
  337. /*
  338. * @brief Function will be operated when naviframe pop its own item
  339. * @param[in] data The data to be passed to the callback function
  340. * @param[in] it The item to be popped from naviframe
  341. */
  342. static Eina_Bool
  343. naviframe_pop_cb(void *data, Elm_Object_Item *it)
  344. {
  345. appdata_s *ad = data;
  346.  
  347. /* Let window go to hide state. */
  348. elm_win_lower(ad->win);
  349.  
  350. return EINA_FALSE;
  351. }
  352.  
  353. /*
  354. * @brief Function to create base gui structure
  355. * @param[in] ad The data structure to manage gui object
  356. */
  357. static void
  358. create_base_gui(appdata_s *ad)
  359. {
  360. Evas_Object *main_list;
  361. Elm_Object_Item *nf_it;
  362.  
  363. /* Window */
  364. /* Create and initialize elm_win.
  365. elm_win is mandatory to manipulate window. */
  366. ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
  367. elm_win_conformant_set(ad->win, EINA_TRUE);
  368. elm_win_autodel_set(ad->win, EINA_TRUE);
  369.  
  370. if (elm_win_wm_rotation_supported_get(ad->win)) {
  371. int rots[4] = { 0, 90, 180, 270 };
  372. elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
  373. }
  374.  
  375. evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
  376.  
  377. /* Conformant */
  378. /* Create and initialize elm_conformant.
  379. elm_conformant is mandatory for base gui to have proper size
  380. when indicator or virtual keypad is visible. */
  381. ad->conform = elm_conformant_add(ad->win);
  382. elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
  383. evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  384. elm_win_resize_object_add(ad->win, ad->conform);
  385. evas_object_show(ad->conform);
  386.  
  387. /* Naviframe */
  388. ad->nf = elm_naviframe_add(ad->conform);
  389. eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, ad);
  390. evas_object_size_hint_weight_set(ad->nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  391. elm_object_content_set(ad->conform, ad->nf);
  392. evas_object_show(ad->nf);
  393.  
  394. /* Main list */
  395. main_list = create_main_list(ad);
  396. nf_it = elm_naviframe_item_push(ad->nf, "Sticker Consumer Sample", NULL, NULL, main_list, NULL);
  397. elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, ad);
  398.  
  399. /* Show window after base gui is set up */
  400. evas_object_show(ad->win);
  401. }
  402.  
  403. /*
  404. * @brief Hook to take necessary actions before main event loop starts
  405. * Initialize UI resources and application's data
  406. * If this function return true, the main loop of application starts
  407. * If this function return false, the application is terminated
  408. * @param[in] user_data The data to be passed to the callback function
  409. */
  410. static bool
  411. app_create(void *data)
  412. {
  413. appdata_s *ad = data;
  414.  
  415. elm_app_base_scale_set(1.8);
  416. create_base_gui(ad);
  417.  
  418. return true;
  419. }
  420.  
  421. /*
  422. * @brief Function will be called when permission is selected
  423. * @param[in] cause The value representing a reason why this callback has been called
  424. * @param[in] result The result of a response triggered by calling ppm_request_permission()
  425. * @param[in] privilege The privilege that has been checked
  426. * @param[in] user_data The data to be passed to the callback function
  427. */
  428. void ppm_popup_response_cb(ppm_call_cause_e cause, ppm_request_result_e result, const char *privilege, void *user_data)
  429. {
  430. if (cause == PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR) {
  431. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get ppm_request_result");
  432. return;
  433. }
  434.  
  435. appdata_s *ad = user_data;
  436.  
  437. switch (result) {
  438. case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER:
  439. if (ad->sticker_h == NULL) {
  440. /* Create sticker consumer handle */
  441. int ret = sticker_consumer_create(&ad->sticker_h);
  442. /* Check sticker error code*/
  443. if (ret != STICKER_ERROR_NONE)
  444. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create sticker consumer handle");
  445. }
  446. break;
  447. case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_FOREVER:
  448. dlog_print(DLOG_INFO, LOG_TAG, "PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_FOREVER");
  449. notification_status_message_post("The mediastorage privilege is required to use the Sticker Consumer");
  450. ui_app_exit();
  451. break;
  452. case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_ONCE:
  453. dlog_print(DLOG_INFO, LOG_TAG, "PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_ONCE");
  454. notification_status_message_post("The mediastorage privilege is required to use the Sticker Consumer");
  455. ui_app_exit();
  456. break;
  457. default:
  458. break;
  459. }
  460. }
  461.  
  462. /*
  463. * @brief Checks if the Sticker Consumer has privilege
  464. * @param[in] ad The data structure to manage gui object
  465. * @param[in] privilege The privilege that is to be checked
  466. */
  467. void check_privilege(appdata_s *ad, const char* privilege)
  468. {
  469. ppm_check_result_e result;
  470.  
  471. /* Checks if an application, which calls this function, has permission to use the given privilege */
  472. int ret = ppm_check_permission(privilege, &result);
  473.  
  474. /* If there is an error, print log */
  475. if (ret != PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) {
  476. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call ppm_check_permission()");
  477. return;
  478. }
  479.  
  480. /* Allow, deny or ask */
  481. switch (result) {
  482. case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
  483. dlog_print(DLOG_INFO, LOG_TAG, "An application has permission to use the %s privilege", privilege);
  484. if (ad->sticker_h == NULL) {
  485. /* Create sticker consumer handle */
  486. int ret = sticker_consumer_create(&ad->sticker_h);
  487. /* Check sticker error code*/
  488. if (ret != STICKER_ERROR_NONE)
  489. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create sticker consumer handle");
  490. }
  491. break;
  492. case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
  493. notification_status_message_post("Sticker Consumer doesn't have permission to use the mediastorage privilege");
  494. ui_app_exit();
  495. break;
  496. case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
  497. dlog_print(DLOG_INFO, LOG_TAG, "Ask to user whether to grant permission to use the %s privilege", privilege);
  498. /* Requests a user's response to obtain permission for using the given privilege */
  499. int ret_popup = ppm_request_permission(privilege, ppm_popup_response_cb, ad);
  500. if (ret_popup != PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) {
  501. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to call ppm_request_permission()");
  502. return;
  503. }
  504. break;
  505. default:
  506. dlog_print(DLOG_ERROR, LOG_TAG, "Unknown result (%d) for the %s privilege", result, privilege);
  507. break;
  508. }
  509. }
  510.  
  511. /*
  512. * @brief This callback function is called when another application
  513. * sends the launch request to the application
  514. * @param[in] app_control The handle to the app_control
  515. * @param[in] user_data The data to be passed to the callback function
  516. */
  517. static void
  518. app_control(app_control_h app_control, void *data)
  519. {
  520. /* Handle the launch request. */
  521. }
  522.  
  523. /*
  524. * @brief This callback function is called each time
  525. * the application is completely obscured by another application
  526. * and becomes invisible to the user
  527. * @param[in] user_data The data to be passed to the callback function
  528. */
  529. static void
  530. app_pause(void *data)
  531. {
  532. /* Take necessary actions when application becomes invisible. */
  533. }
  534.  
  535. /*
  536. * @brief This callback function is called each time
  537. * the application becomes visible to the user
  538. * @param[in] user_data The data to be passed to the callback function
  539. */
  540. static void
  541. app_resume(void *data)
  542. {
  543. /* Take necessary actions when application becomes visible. */
  544. const char* sticker_privilege = "http://tizen.org/privilege/mediastorage";
  545. check_privilege(data, sticker_privilege);
  546. }
  547.  
  548. /*
  549. * @brief This callback function is called once after the main loop of the application exits
  550. * @param[in] user_data The data to be passed to the callback function
  551. */
  552. static void
  553. app_terminate(void *data)
  554. {
  555. appdata_s *ad = data;
  556. /* Release all resources. */
  557. if (ad->sticker_h != NULL) {
  558. /* Destroy sticker consumer handle */
  559. int ret = sticker_consumer_destroy(ad->sticker_h);
  560. /* Check sticker error code */
  561. if (ret != STICKER_ERROR_NONE)
  562. dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy sticker consumer handle");
  563. }
  564. }
  565.  
  566. /*
  567. * @brief This function will be called when the language is changed
  568. * @param[in] event_info The system event information
  569. * @param[in] user_data The user data to be passed to the callback function
  570. */
  571. static void
  572. ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  573. {
  574. /*APP_EVENT_LANGUAGE_CHANGED*/
  575.  
  576. int ret;
  577. char *language;
  578.  
  579. /* Get locale */
  580. ret = app_event_get_language(event_info, &language);
  581. if (ret != APP_ERROR_NONE) {
  582. dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
  583. return;
  584. }
  585.  
  586. if (language != NULL) {
  587. elm_language_set(language);
  588. free(language);
  589. }
  590. }
  591.  
  592. /*
  593. * @brief This function will be called when the orientation is changed
  594. * @param[in] event_info The system event information
  595. * @param[in] user_data The user data to be passed to the callback function
  596. */
  597. static void
  598. ui_app_orient_changed(app_event_info_h event_info, void *user_data)
  599. {
  600. /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
  601. return;
  602. }
  603.  
  604. /*
  605. * @brief This function will be called when the region is changed
  606. * @param[in] event_info The system event information
  607. * @param[in] user_data The user data to be passed to the callback function
  608. */
  609. static void
  610. ui_app_region_changed(app_event_info_h event_info, void *user_data)
  611. {
  612. /*APP_EVENT_REGION_FORMAT_CHANGED*/
  613. }
  614.  
  615. /*
  616. * @brief This function will be called when the battery is low
  617. * @param[in] event_info The system event information
  618. * @param[in] user_data The user data to be passed to the callback function
  619. */
  620. static void
  621. ui_app_low_battery(app_event_info_h event_info, void *user_data)
  622. {
  623. /*APP_EVENT_LOW_BATTERY*/
  624. }
  625.  
  626. /*
  627. * @brief This function will be called when the memory is low
  628. * @param[in] event_info The system event information
  629. * @param[in] user_data The user data to be passed to the callback function
  630. */
  631. static void
  632. ui_app_low_memory(app_event_info_h event_info, void *user_data)
  633. {
  634. /*APP_EVENT_LOW_MEMORY*/
  635. }
  636.  
  637. /*
  638. * @brief Main function of the application
  639. * @param[in] argc The argument count
  640. * @param[in] argv The argument vector
  641. */
  642. int
  643. main(int argc, char *argv[])
  644. {
  645. appdata_s ad = {0,};
  646. int ret = 0;
  647.  
  648. ui_app_lifecycle_callback_s event_callback = {0,};
  649. app_event_handler_h handlers[5] = {NULL, };
  650.  
  651. event_callback.create = app_create;
  652. event_callback.terminate = app_terminate;
  653. event_callback.pause = app_pause;
  654. event_callback.resume = app_resume;
  655. event_callback.app_control = app_control;
  656.  
  657. /* Register for low battery event handler */
  658. ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
  659.  
  660. /* Register for low memory event handler */
  661. ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
  662.  
  663. /* Register for device operation changed event handler */
  664. ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
  665.  
  666. /* Register for language changed event handler */
  667. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
  668.  
  669. /* Register for region format changed event handler */
  670. ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
  671.  
  672. ret = ui_app_main(argc, argv, &event_callback, &ad);
  673. if (ret != APP_ERROR_NONE)
  674. dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
  675.  
  676. return ret;
  677. }