Alarm / src /

view.c

  1. /*
  2. * Copyright (c) 2016 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 <tizen.h>
  18. #include <Elementary.h>
  19.  
  20. #include "$(appName).h"
  21. #include "view.h"
  22. #include "view_defines.h"
  23.  
  24. static struct view_info {
  25. Evas_Object *win;
  26. Evas_Object *conform;
  27. Evas_Object *layout;
  28. } s_info = {
  29. .win = NULL,
  30. .conform = NULL,
  31. .layout = NULL,
  32. };
  33.  
  34. #define ALARM_MESSAGE_TIMEOUT 1.0
  35.  
  36. static void _delete_win_request_cb(void *data, Evas_Object *obj, void *event_info);
  37. static void _win_back_cb(void *data, Evas_Object *obj, void *event_info);
  38. static void _get_app_resource(const char *edj_file_in, char *edj_path_out);
  39. static Eina_Bool _hide_recurring_alarm_message_cb(void *data);
  40.  
  41. /**
  42. * Function is invoked by controller when ontime alarm fires
  43. */
  44. void view_handle_ontime_alarm(void)
  45. {
  46. elm_object_signal_emit(s_info.layout, SIGNAL_ALARM_ON, PART_ONTIME_ALARM_STATE_TEXT);
  47. elm_object_signal_emit(s_info.layout, SIGNAL_ALARM_ON, PART_ALARM_IMAGE);
  48. }
  49.  
  50. /**
  51. * Function is invoked by controller when recurring alarm fires
  52. */
  53. void view_handle_recurring_alarm(void)
  54. {
  55. elm_object_signal_emit(s_info.layout, SIGNAL_ALARM_ON, PART_RECURRING_ALARM_STATE_TEXT);
  56. elm_object_signal_emit(s_info.layout, SIGNAL_ALARM_ON, PART_ALARM_IMAGE);
  57. /*
  58. * Timer is created to hide displayed alarm image and text message
  59. */
  60. ecore_timer_add(ALARM_MESSAGE_TIMEOUT, _hide_recurring_alarm_message_cb, NULL);
  61. }
  62.  
  63. /**
  64. * @brief Creates essential objects: window, conformant and layout.
  65. */
  66. Eina_Bool view_create(void)
  67. {
  68. char edj_path[PATH_MAX] = {0, };
  69.  
  70. /* Create the window */
  71. s_info.win = view_create_win(PACKAGE);
  72. if (s_info.win == NULL) {
  73. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a window.");
  74. return EINA_FALSE;
  75. }
  76.  
  77. /* Create the conformant */
  78. s_info.conform = view_create_conformant(s_info.win);
  79. if (s_info.conform == NULL) {
  80. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a conformant");
  81. return EINA_FALSE;
  82. }
  83.  
  84. /* Create Layout */
  85. _get_app_resource(MAIN_EDJ, edj_path);
  86. s_info.layout = view_create_layout(s_info.win, edj_path, MAIN_GRP);
  87. if (s_info.layout == NULL) {
  88. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a layout");
  89. return EINA_FALSE;
  90. }
  91.  
  92. elm_object_content_set(s_info.conform, s_info.layout);
  93.  
  94. /* Show the window after main view is set up */
  95. evas_object_show(s_info.win);
  96.  
  97. return EINA_TRUE;
  98. }
  99.  
  100. /**
  101. * @brief Creates a basic window named package.
  102. * @param[in] pkg_name Name of the window
  103. */
  104. Evas_Object *view_create_win(const char *pkg_name)
  105. {
  106. Evas_Object *win = NULL;
  107.  
  108. /*
  109. * Window
  110. * Create and initialize elm_win.
  111. * elm_win is mandatory to manipulate the window.
  112. */
  113. win = elm_win_util_standard_add(pkg_name, pkg_name);
  114. elm_win_conformant_set(win, EINA_TRUE);
  115. elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
  116. elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_OPAQUE);
  117. elm_win_autodel_set(win, EINA_TRUE);
  118.  
  119. evas_object_smart_callback_add(win, "delete,request", _delete_win_request_cb, NULL);
  120.  
  121. return win;
  122. }
  123.  
  124. /**
  125. * @brief Creates a layout to target parent object with edje file
  126. * @param[in] parent The object to which you want to add this layout
  127. * @param[in] file_path File path of EDJ file will be used
  128. * @param[in] group_name Name of group in EDJ you want to set to
  129. * @param[in] cb_function The function will be called when back event is detected
  130. * @param[in] user_data The user data to be passed to the callback functions
  131. */
  132. Evas_Object *view_create_layout(Evas_Object *parent, const char *file_path, const char *group_name)
  133. {
  134. Evas_Object *layout = NULL;
  135.  
  136. if (parent == NULL) {
  137. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  138. return NULL;
  139. }
  140.  
  141. /* Create layout using EDC(an edje file) */
  142. layout = elm_layout_add(parent);
  143. if (!elm_layout_file_set(layout, file_path, group_name)) {
  144. dlog_print(DLOG_ERROR, LOG_TAG, "Couldn't load layout from: %s", file_path);
  145. return NULL;
  146. }
  147.  
  148. /* Layout size setting */
  149. evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  150.  
  151. eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, _win_back_cb, NULL);
  152.  
  153. evas_object_show(layout);
  154.  
  155. return layout;
  156. }
  157.  
  158. /**
  159. * @brief Creates a conformant object.
  160. * @param[in] win The object to which you want to set this conformant
  161. * Conformant is mandatory for base GUI to have proper size
  162. */
  163. Evas_Object *view_create_conformant(Evas_Object *win)
  164. {
  165. /*
  166. * Conformant
  167. * Create and initialize elm_conformant.
  168. * elm_conformant is mandatory for base GUI to have proper size
  169. * when indicator or virtual keypad is visible.
  170. */
  171. Evas_Object *conform = NULL;
  172.  
  173. conform = elm_conformant_add(win);
  174. evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  175. elm_win_resize_object_add(win, conform);
  176.  
  177. evas_object_show(conform);
  178.  
  179. return conform;
  180. }
  181.  
  182. /**
  183. * @brief Displays the information message about the next alarm scheduled.
  184. * @param[in] info The text message to be displayd.
  185. */
  186. void view_display_alarm_info(const char *info)
  187. {
  188. elm_object_part_text_set(s_info.layout, PART_ALARM_INFO_LABEL, info);
  189. }
  190.  
  191. /**
  192. * @brief Destroys window and frees its resources.
  193. */
  194. void view_destroy(void)
  195. {
  196. if (s_info.win == NULL)
  197. return;
  198.  
  199. evas_object_del(s_info.win);
  200. }
  201.  
  202. /**
  203. * @brief Function will be operated when registered event is triggered.
  204. * @param[in] data The data to be passed to the callback function
  205. * @param[in] obj The Evas object handle to be passed to the callback function
  206. * @param[in] event_info The system event information
  207. */
  208. static void _delete_win_request_cb(void *data, Evas_Object *obj, void *event_info)
  209. {
  210. /*
  211. * Write your code here for smart callback.
  212. */
  213. ui_app_exit();
  214. }
  215.  
  216. /**
  217. * Key back click puts window in background
  218. */
  219. static void _win_back_cb(void *data, Evas_Object *obj, void *event_info)
  220. {
  221. elm_win_lower(s_info.win);
  222. }
  223.  
  224. /**
  225. * Conveniently return absolute edje path
  226. */
  227. static void _get_app_resource(const char *edj_file_in, char *edj_path_out)
  228. {
  229. char *res_path = app_get_resource_path();
  230. if (res_path) {
  231. snprintf(edj_path_out, PATH_MAX, "%s%s", res_path, edj_file_in);
  232. free(res_path);
  233. }
  234. }
  235. /*
  236. * Callback function called by elapsing timer. In result, the text message
  237. * and an image hides.
  238. */
  239. static Eina_Bool _hide_recurring_alarm_message_cb(void *data)
  240. {
  241. elm_object_signal_emit(s_info.layout, SIGNAL_ALARM_OFF, PART_RECURRING_ALARM_STATE_TEXT);
  242. elm_object_signal_emit(s_info.layout, SIGNAL_ALARM_OFF, PART_ALARM_IMAGE);
  243.  
  244. return ECORE_CALLBACK_CANCEL;
  245. }