(Circle) Dialer / src /

main.c

  1. /*
  2. * Copyright (c) 2015 Samsung Electronics Co., Ltd
  3. *
  4. * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
  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 <app.h>
  18. #include <Elementary.h>
  19. #include <system_settings.h>
  20. #include <efl_extension.h>
  21. #include <dlog.h>
  22.  
  23. #include "$(appName).h"
  24. #include "view.h"
  25. #include "data.h"
  26.  
  27. static void _btn_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
  28. static void _btn_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
  29.  
  30. /*
  31. * @brief Hook to take necessary actions before main event loop starts
  32. * @param[in] user_data The user data to be passed to the callback function
  33. * Initialize UI resources and application's data
  34. * If this function returns true, the main loop of application starts
  35. * If this function returns false, the application is terminated
  36. */
  37. static bool app_create(void *user_data)
  38. {
  39. /* Hook to take necessary actions before main event loop starts
  40. Initialize UI resources and application's data
  41. If this function returns true, the main loop of application starts
  42. If this function returns false, the application is terminated */
  43.  
  44. char *image = NULL;
  45. char full_path[PATH_MAX] = { 0, };
  46.  
  47. /* Create main view */
  48. view_create();
  49. data_get_full_path(EDJ_FILE, full_path, (int)PATH_MAX);
  50. view_dialer_create(full_path);
  51.  
  52. /* Set background image to "sw.button.bg" part of EDC */
  53. image = data_get_image_path("sw.button.bg");
  54. view_set_image(view_dialer_get_layout_object(), "sw.button.bg", image);
  55. view_set_color(view_dialer_get_layout_object(), "sw.button.bg", 8, 36, 61, 255);
  56. free(image);
  57.  
  58. /* Set Call button effect image to "sw.button.call.ef" part of EDC */
  59. image = data_get_image_path("sw.button.call.ef");
  60. view_set_image(view_dialer_get_layout_object(), "sw.button.call.ef", image);
  61. view_set_color(view_dialer_get_layout_object(), "sw.button.call.ef", 0, 0, 0, 255);
  62. free(image);
  63.  
  64. /* Set Call button image to "sw.button.call" part of EDC */
  65. image = data_get_image_path("sw.button.call");
  66. view_set_image(view_dialer_get_layout_object(), "sw.button.call", image);
  67. view_set_color(view_dialer_get_layout_object(), "sw.button.call", 0, 214, 46, 255);
  68. free(image);
  69.  
  70. /* Set Delete button to "sw.button.delete" part of EDC */
  71. image = data_get_image_path("sw.button.delete");
  72. view_set_button(view_dialer_get_layout_object(), "sw.button.delete", "focus", image, NULL, _btn_down_cb, _btn_up_cb, NULL, NULL);
  73. view_set_color(view_dialer_get_layout_object(), "sw.button.delete", 250, 250, 250, 255);
  74. free(image);
  75.  
  76. /* Set Entry widget to "sw.entry.dial" part of EDC to display input dial number */
  77. view_dialer_set_entry("sw.entry.dial");
  78. view_set_color(view_dialer_get_layout_object(), "sw.entry.dial", 250, 250, 250, 255);
  79.  
  80. /* Set full size Rectangle to catch circular dial button touch */
  81. view_dialer_create_rectangle();
  82.  
  83. return true;
  84. }
  85.  
  86. /*
  87. * @brief This callback function is called when another application
  88. * @param[in] app_control The handle to the app_control
  89. * @param[in] user_data The user data to be passed to the callback function
  90. * sends the launch request to the application
  91. */
  92. static void app_control(app_control_h app_control, void *user_data)
  93. {
  94. /* Handle the launch request. */
  95. }
  96.  
  97. /*
  98. * @brief This callback function is called each time
  99. * @param[in] user_data The user data to be passed to the callback function
  100. * the application is completely obscured by another application
  101. * and becomes invisible to the user
  102. */
  103. static void app_pause(void *user_data)
  104. {
  105. /* Take necessary actions when application becomes invisible. */
  106. }
  107.  
  108. /*
  109. * @brief This callback function is called each time
  110. * @param[in] user_data The user data to be passed to the callback function
  111. * the application becomes visible to the user
  112. */
  113. static void app_resume(void *user_data)
  114. {
  115. /* Take necessary actions when application becomes visible. */
  116. }
  117.  
  118. /*
  119. * @brief This callback function is called once after the main loop of the application exits
  120. * @param[in] user_data The user data to be passed to the callback function
  121. */
  122. static void app_terminate(void *user_data)
  123. {
  124. /*
  125. * Destroy window component.
  126. */
  127. view_destroy();
  128. }
  129.  
  130. /*
  131. * @brief This function will be called when the language is changed
  132. * @param[in] event_info The system event information
  133. * @param[in] user_data The user data to be passed to the callback function
  134. */
  135. static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  136. {
  137. /*APP_EVENT_LANGUAGE_CHANGED*/
  138. char *locale = NULL;
  139.  
  140. system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
  141.  
  142. if (locale != NULL) {
  143. elm_language_set(locale);
  144. free(locale);
  145. }
  146. return;
  147. }
  148.  
  149. /*
  150. * @brief Main function of the application
  151. * @param[in] argc The argument count
  152. * @param[in] argv The argument vector
  153. */
  154. int main(int argc, char *argv[])
  155. {
  156. int ret;
  157.  
  158. ui_app_lifecycle_callback_s event_callback = {0, };
  159. app_event_handler_h handlers[5] = {NULL, };
  160.  
  161. event_callback.create = app_create;
  162. event_callback.terminate = app_terminate;
  163. event_callback.pause = app_pause;
  164. event_callback.resume = app_resume;
  165. event_callback.app_control = app_control;
  166.  
  167. /*
  168. * If you want to handling more events,
  169. * Please check the application lifecycle guide
  170. */
  171. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
  172.  
  173. ret = ui_app_main(argc, argv, &event_callback, NULL);
  174. if (ret != APP_ERROR_NONE) {
  175. dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
  176. }
  177.  
  178. return ret;
  179. }
  180.  
  181.  
  182. /*
  183. * @brief Function will be operated when registered event is triggered.
  184. * @param[in] data The data to be passed to the callback function
  185. * @param[in] e The handle to an Evas canvas to be passed to the callback function
  186. * @param[in] obj The Evas object handle to be passed to the callback function
  187. * @param[in] event_info The system event information
  188. */
  189. static void _btn_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
  190. {
  191. dlog_print(DLOG_DEBUG, LOG_TAG, "button is pressed.");
  192.  
  193. /* Delete One Character of Entry */
  194. view_dialer_set_entry_text(ENTRY_TEXT_BACKSPACE, NULL);
  195.  
  196. /* Change Delete button color */
  197. evas_object_color_set(obj, 250, 250, 250, 102);
  198. }
  199.  
  200. /*
  201. * @brief Function will be operated when registered event is triggered.
  202. * @param[in] data The data to be passed to the callback function
  203. * @param[in] e The handle to an Evas canvas to be passed to the callback function
  204. * @param[in] obj The Evas object handle to be passed to the callback function
  205. * @param[in] event_info The system event information
  206. */
  207. static void _btn_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
  208. {
  209. dlog_print(DLOG_DEBUG, LOG_TAG, "button is released.");
  210.  
  211. /* Change Delete button color */
  212. evas_object_color_set(obj, 250, 250, 250, 255);
  213. }