(Circle) Dialer / src /

view.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 <tizen.h>
  18. #include <dlog.h>
  19. #include <app.h>
  20. #include <efl_extension.h>
  21. #include <Elementary.h>
  22. #include "$(appName).h"
  23. #include "view.h"
  24.  
  25. static struct view_info {
  26. Evas_Object *win;
  27. Evas_Object *conform;
  28. Evas_Object *layout;
  29.  
  30. Evas_Object *entry;
  31. Ecore_Timer *timer;
  32.  
  33. int mouse_down_dial_num;
  34. } s_info = {
  35. .win = NULL,
  36. .conform = NULL,
  37. .layout = NULL,
  38.  
  39. .entry = NULL,
  40. .timer = NULL,
  41. .mouse_down_dial_num = -1
  42. };
  43.  
  44. static void _win_delete_request_cb(void *data, Evas_Object *obj, void *event_info);
  45. static void _rectangle_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
  46. static void _rectangle_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
  47. static void _rectangle_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
  48. static void _dialer_text_resize(Evas_Object *entry);
  49. static void _dialer_layout_cb(void *data, Evas_Object *obj, void *event_info);
  50.  
  51. /*
  52. * @brief Create Essential Object window, conformant and layout
  53. */
  54. void view_create(void)
  55. {
  56. /* Create window */
  57. s_info.win = view_create_win(PACKAGE);
  58. if (s_info.win == NULL) {
  59. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a window.");
  60. return;
  61. }
  62.  
  63. /* Create conformant */
  64. s_info.conform = view_create_conformant_without_indicator(s_info.win);
  65. if (s_info.conform == NULL) {
  66. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a conformant");
  67. return;
  68. }
  69.  
  70. /* Show window after main view is set up */
  71. evas_object_show(s_info.win);
  72. }
  73.  
  74. /*
  75. * @brief Make a basic window named package
  76. * @param[in] pkg_name Name of the window
  77. */
  78. Evas_Object *view_create_win(const char *pkg_name)
  79. {
  80. Evas_Object *win = NULL;
  81.  
  82. /*
  83. * Window
  84. * Create and initialize elm_win.
  85. * elm_win is mandatory to manipulate window
  86. */
  87. win = elm_win_util_standard_add(pkg_name, pkg_name);
  88. elm_win_conformant_set(win, EINA_TRUE);
  89. elm_win_autodel_set(win, EINA_TRUE);
  90.  
  91. /* Rotation setting */
  92. if (elm_win_wm_rotation_supported_get(win)) {
  93. int rots[4] = { 0, 90, 180, 270 };
  94. elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
  95. }
  96.  
  97. evas_object_smart_callback_add(win, "delete,request", _win_delete_request_cb, NULL);
  98.  
  99. return win;
  100. }
  101.  
  102. /*
  103. * @brief Make a conformant without indicator for wearable app
  104. * @param[in] win The object to which you want to set this conformant
  105. * Conformant is mandatory for base GUI to have proper size
  106. */
  107. Evas_Object *view_create_conformant_without_indicator(Evas_Object *win)
  108. {
  109. /*
  110. * Conformant
  111. * Create and initialize elm_conformant.
  112. * elm_conformant is mandatory for base GUI to have proper size
  113. * when indicator or virtual keypad is visible.
  114. */
  115. Evas_Object *conform = NULL;
  116.  
  117. if (win == NULL) {
  118. dlog_print(DLOG_ERROR, LOG_TAG, "window is NULL.");
  119. return NULL;
  120. }
  121.  
  122. conform = elm_conformant_add(win);
  123. evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  124. elm_win_resize_object_add(win, conform);
  125.  
  126. evas_object_show(conform);
  127.  
  128. return conform;
  129. }
  130.  
  131. /*
  132. * @brief Make essential object for the this app, like conformant and layout
  133. * @param[in] file_path File path of EDJ file will be used
  134. */
  135. void view_dialer_create(const char *file_path)
  136. {
  137. s_info.layout = view_create_layout_for_conformant(s_info.conform, file_path, GRP_MAIN, _dialer_layout_cb, NULL);
  138. if (s_info.layout == NULL) {
  139. evas_object_del(s_info.win);
  140. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a content.");
  141. return;
  142. }
  143. }
  144.  
  145. /*
  146. * @brief Function will be operated when window is deleted
  147. * @param[in] data The data to be passed to the callback function
  148. * @param[in] obj The Evas object handle to be passed to the callback function
  149. * @param[in] event_info The system event information
  150. */
  151. static void _win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
  152. {
  153. ui_app_exit();
  154. }
  155.  
  156. /*
  157. * @brief Make a layout to target parent object with edje file
  158. * @param[in] parent The object to which you want to add this layout
  159. * @param[in] file_path File path of EDJ file will be used
  160. * @param[in] group_name Name of group in EDJ you want to set to
  161. * @param[in] cb_function The function will be called when back event is detected
  162. * @param[in] user_data The user data to be passed to the callback functions
  163. */
  164. Evas_Object *view_create_layout(Evas_Object *parent, const char *file_path, const char *group_name, Eext_Event_Cb cb_function, void *user_data)
  165. {
  166. Evas_Object *layout = NULL;
  167.  
  168. if (parent == NULL) {
  169. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  170. return NULL;
  171. }
  172.  
  173. /* Create layout by EDC(edje file) */
  174. layout = elm_layout_add(parent);
  175. elm_layout_file_set(layout, file_path, group_name);
  176.  
  177. /* Layout size setting */
  178. evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  179.  
  180. if (cb_function)
  181. eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, cb_function, user_data);
  182.  
  183. evas_object_show(layout);
  184.  
  185. return layout;
  186. }
  187.  
  188. /*
  189. * @brief Make and set a layout to conformant
  190. * @param[in] parent Target conformant object
  191. * @param[in] file_path File path of EDJ will be used
  192. * @param[in] group_name Group name in EDJ you want to set to layout
  193. * @param[in] cb_function The function will be called when the back event is detected
  194. * @param[in] user_data The user data to be passed to the callback functions
  195. */
  196. Evas_Object *view_create_layout_for_conformant(Evas_Object *parent, const char *file_path, const char *group_name, Eext_Event_Cb cb_function, void *user_data)
  197. {
  198. Evas_Object *layout = NULL;
  199.  
  200. if (parent == NULL) {
  201. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  202. return NULL;
  203. }
  204.  
  205. /* Create layout for conformant */
  206. if (file_path == NULL) {
  207. layout = view_create_layout_by_theme(parent, "layout", "application", "default");
  208. } else {
  209. layout = view_create_layout(parent, file_path, group_name, cb_function, user_data);
  210. }
  211.  
  212. if (layout == NULL) {
  213. dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL.");
  214. return NULL;
  215. }
  216.  
  217. elm_object_content_set(parent, layout);
  218.  
  219. return layout;
  220. }
  221.  
  222. /*
  223. * @brief Make a layout with theme.
  224. * @param[in] parent Object to which you want to add this layout
  225. * @param[in] class_name The class of the group
  226. * @param[in] group_name Group name in EDJ that you want to set to layout
  227. * @param[in] style The style to use
  228. */
  229. Evas_Object *view_create_layout_by_theme(Evas_Object *parent, const char *class_name, const char *group_name, const char *style)
  230. {
  231. /*
  232. * Layout
  233. * Create and initialize elm_layout.
  234. * view_create_layout_by_theme() is used to create layout by using premade edje file.
  235. */
  236. Evas_Object *layout = NULL;
  237.  
  238. if (parent == NULL) {
  239. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  240. return NULL;
  241. }
  242.  
  243. layout = elm_layout_add(parent);
  244. elm_layout_theme_set(layout, class_name, group_name, style);
  245. evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  246.  
  247. evas_object_show(layout);
  248.  
  249. return layout;
  250. }
  251.  
  252. /*
  253. * @brief Destroy window and free important data to finish this application
  254. */
  255. void view_destroy(void)
  256. {
  257. if (s_info.win == NULL) {
  258. return;
  259. }
  260.  
  261. evas_object_del(s_info.win);
  262. }
  263.  
  264. /*
  265. * @brief Set image to given part
  266. * @param[in] parent Object has part to which you want to set this image
  267. * @param[in] part_name Part name to which you want to set this image
  268. * @param[in] image_path Path of the image file
  269. */
  270. void view_set_image(Evas_Object *parent, const char *part_name, const char *image_path)
  271. {
  272. Evas_Object *image = NULL;
  273.  
  274. if (parent == NULL) {
  275. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  276. return;
  277. }
  278.  
  279. image = elm_object_part_content_get(parent, part_name);
  280. if (image == NULL) {
  281. image = elm_image_add(parent);
  282. if (image == NULL) {
  283. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create an image object.");
  284. return;
  285. }
  286.  
  287. elm_object_part_content_set(parent, part_name, image);
  288. }
  289.  
  290. if (EINA_FALSE == elm_image_file_set(image, image_path, NULL)) {
  291. dlog_print(DLOG_ERROR, LOG_TAG, "failed to set image.");
  292. return;
  293. }
  294.  
  295. evas_object_show(image);
  296.  
  297. return;
  298. }
  299.  
  300. /*
  301. * @brief Set text to the part
  302. * @param[in] parent Object has part to which you want to set text
  303. * @param[in] part_name Part name to which you want to set the text
  304. * @param[in] text Text you want to set to the part
  305. */
  306. void view_set_text(Evas_Object *parent, const char *part_name, const char *text)
  307. {
  308. if (parent == NULL) {
  309. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  310. return;
  311. }
  312.  
  313. /* Set text of target part object */
  314. elm_object_part_text_set(parent, part_name, text);
  315. }
  316.  
  317. /*
  318. * @brief Set color of the part
  319. * @param[in] parent Object has part to which you want to set color
  320. * @param[in] part_name Name of part to which you want to set color
  321. * @param[in] r R of RGBA you want to set to the part
  322. * @param[in] g G of RGBA you want to set to the part
  323. * @param[in] b B of RGBA you want to set to the part
  324. * @param[in] a A of RGBA you want to set to the part
  325. */
  326. void view_set_color(Evas_Object *parent, const char *part_name, int r, int g, int b, int a)
  327. {
  328. Evas_Object *obj = NULL;
  329.  
  330. if (parent == NULL) {
  331. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  332. return;
  333. }
  334.  
  335. obj = elm_object_part_content_get(parent, part_name);
  336. if (obj == NULL) {
  337. dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
  338. return;
  339. }
  340.  
  341. /* Set color of target part object */
  342. evas_object_color_set(obj, r, g, b, a);
  343. }
  344.  
  345. /*
  346. * @brief Make and set button.
  347. * @param[in] parent Object to which you want to set the button
  348. * @param[in] part_name Name of part to which you want to set the button
  349. * @param[in] style Style of the button
  350. * @param[in] image_path Path of image file will be used as button icon
  351. * @param[in] text The text will be written on the button
  352. * @param[in] down_cb Function will be operated when the button is pressed
  353. * @param[in] up_cb Function will be operated when the button is released
  354. * @param[in] clicked_cb Function will be operated when the button is clicked
  355. * @param[in] user_data Data passed to the 'clicked_cb' function
  356. */
  357. void view_set_button(Evas_Object *parent, const char *part_name, const char *style, const char *image_path, const char *text,
  358. Evas_Object_Event_Cb down_cb, Evas_Object_Event_Cb up_cb, Evas_Smart_Cb clicked_cb, void *user_data)
  359. {
  360. Evas_Object *btn = NULL;
  361.  
  362. if (parent == NULL) {
  363. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  364. return;
  365. }
  366.  
  367. btn = elm_button_add(parent);
  368. if (btn == NULL) {
  369. dlog_print(DLOG_ERROR, LOG_TAG, "failed to create button.");
  370. return;
  371. }
  372.  
  373. if (style)
  374. elm_object_style_set(btn, style);
  375.  
  376. evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  377. elm_object_part_content_set(parent, part_name, btn);
  378.  
  379. if (text)
  380. elm_object_text_set(btn, text);
  381.  
  382. if (image_path)
  383. view_set_image(btn, NULL, image_path);
  384.  
  385. if (down_cb)
  386. evas_object_event_callback_add(btn , EVAS_CALLBACK_MOUSE_DOWN, down_cb, user_data);
  387. if (up_cb)
  388. evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_UP, up_cb, user_data);
  389. if (clicked_cb)
  390. evas_object_smart_callback_add(btn, "clicked", clicked_cb, user_data);
  391.  
  392. evas_object_show(btn);
  393. }
  394.  
  395. /*
  396. * @brief Make Rectangle Object to target window for hijacking touch event
  397. * @Add callback function will be operated when mouse down/up event is triggered
  398. */
  399. Evas_Object *view_dialer_create_rectangle()
  400. {
  401. Evas_Object *rect = NULL;
  402.  
  403. if (s_info.win == NULL) {
  404. dlog_print(DLOG_ERROR, LOG_TAG, "window is NULL.");
  405. return NULL;
  406. }
  407.  
  408. if (s_info.layout == NULL) {
  409. dlog_print(DLOG_ERROR, LOG_TAG, "parent layout is NULL.");
  410. return NULL;
  411. }
  412.  
  413. /* Add Rectangle object to parent */
  414. rect = evas_object_rectangle_add(evas_object_evas_get(s_info.layout));
  415. if (rect == NULL) {
  416. dlog_print(DLOG_ERROR, LOG_TAG, "failed to add a rectangle");
  417. return NULL;
  418. }
  419.  
  420. /* Set Rectangle color to transparent because this rectangle is just in charge of touch event hooking
  421. * You can change color for other purpose e.g. color filter layer */
  422. evas_object_color_set(rect, 255, 255, 255, 0);
  423.  
  424. /* Set event repeat mode */
  425. evas_object_repeat_events_set(rect, EINA_TRUE);
  426.  
  427. /* Set size of Rectangle object */
  428. evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  429. elm_win_resize_object_add(s_info.win, rect);
  430.  
  431. evas_object_show(rect);
  432.  
  433. /* Set callback for event about Rectangle */
  434. evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN, _rectangle_mouse_down_cb, NULL);
  435. evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_UP, _rectangle_mouse_up_cb, NULL);
  436. evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_MOVE, _rectangle_mouse_move_cb, NULL);
  437.  
  438. return rect;
  439. }
  440.  
  441. /*
  442. * @brief Create entry object and keep the object for handling.
  443. * @param[in] part_name Part of the layout which you want to locate Entry
  444. */
  445. void view_dialer_set_entry(const char *part_name)
  446. {
  447.  
  448. if (s_info.layout == NULL) {
  449. dlog_print(DLOG_ERROR, LOG_TAG, "parent layout is NULL.");
  450. return;
  451. }
  452.  
  453. if (part_name == NULL) {
  454. dlog_print(DLOG_ERROR, LOG_TAG, "part name is NULL.");
  455. return;
  456. }
  457.  
  458. s_info.entry = view_create_entry(s_info.layout, part_name, NULL, NULL);
  459. }
  460.  
  461. /*
  462. * @brief Make a Entry Object to target window
  463. * @param[in] parent Object to which you want to set Entry
  464. * @param[in] part_name Part of the layout which you want to locate Entry
  465. * @param[in] clicked_cb The function will be called when the entry is clicked
  466. * @param[in] user_data The user data passed to the callback function
  467. * @Add callback function will be operated when mouse clicked event is triggered
  468. */
  469. Evas_Object *view_create_entry(Evas_Object *parent, const char *part_name, Evas_Smart_Cb clicked_cb, void *user_data)
  470. {
  471. Evas_Object *entry = NULL;
  472.  
  473. if (parent == NULL) {
  474. dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
  475. return NULL;
  476. }
  477.  
  478. /* Add Entry object to parent */
  479. entry = elm_entry_add(parent);
  480. if (entry == NULL) {
  481. dlog_print(DLOG_ERROR, LOG_TAG, "failed to add a entry");
  482. return NULL;
  483. }
  484.  
  485. /* Set Entry size option */
  486. evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  487.  
  488. /* Set Entry option for display and functionalities */
  489. elm_entry_single_line_set(entry, EINA_TRUE);
  490. elm_entry_scrollable_set(entry, EINA_TRUE);
  491. elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
  492. elm_entry_editable_set(entry, EINA_FALSE);
  493. elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
  494.  
  495. /* Set Entry text style using predefined style description */
  496. elm_entry_text_style_user_push(entry, DIAL_TEXT_STYLE_NORMAL);
  497.  
  498. elm_object_part_content_set(parent, part_name, entry);
  499.  
  500. /* Set callback for event about Entry */
  501. if (clicked_cb) {
  502. evas_object_smart_callback_add(entry, "clicked", clicked_cb, user_data);
  503. }
  504.  
  505. return entry;
  506. }
  507.  
  508. /*
  509. * @brief Modify entry text of Entry object
  510. * @param[in] operation ENTRY_TEXT_CLEAR_ALL - clear all text, ENTRY_TEXT_ADD_TEXT - add specific text to current text, ENTRY_TEXT_BACKSPACE - delete one character by backspace
  511. * @param[in] text target text which will be added to current entry text
  512. */
  513. int view_dialer_set_entry_text(int operation, const char *text)
  514. {
  515. if (s_info.entry == NULL) {
  516. dlog_print(DLOG_ERROR, LOG_TAG, "Entry object is NULL.");
  517. return -1;
  518. }
  519.  
  520. if (operation == ENTRY_TEXT_CLEAR_ALL)
  521. elm_object_text_set(s_info.entry, "");
  522. else if (operation == ENTRY_TEXT_ADD_TEXT) {
  523. const char* old_entry_text = elm_entry_entry_get(s_info.entry);
  524.  
  525. if (strlen(old_entry_text) < ENTRY_TEXT_MAX)
  526. elm_entry_entry_append(s_info.entry, text);
  527.  
  528. } else if (operation == ENTRY_TEXT_BACKSPACE) {
  529. const char* old_entry_text = elm_entry_entry_get(s_info.entry);
  530.  
  531. if (strlen(old_entry_text)) {
  532. char *new_entry_text;
  533. new_entry_text = strdup(old_entry_text);
  534. if (new_entry_text) {
  535. new_entry_text[strlen(old_entry_text) - 1] = '\0';
  536. elm_entry_entry_set(s_info.entry, new_entry_text);
  537. free(new_entry_text);
  538. }
  539. }
  540. } else {
  541. dlog_print(DLOG_ERROR, LOG_TAG, "view_set_entry_text text operation is invalid!");
  542. return -1;
  543. }
  544.  
  545. /* Resize Dialer entry text */
  546. _dialer_text_resize(s_info.entry);
  547. return 1;
  548. }
  549.  
  550. /*
  551. * @brief Get dial number of user's touch event position by calculating distance and slope from center
  552. * @param[in] evt_x X-coordinate value of event position
  553. * @param[in] evt_y Y-coordinate value of event position
  554. */
  555. static int _get_btn_dial_number(int evt_x, int evt_y)
  556. {
  557. int result = -1;
  558.  
  559. /* Calculation x and y from CENTER_REF point */
  560. int x = evt_x - CENTER_REF_X;
  561. int y = CENTER_REF_Y - evt_y;
  562.  
  563. /* Calculation the slope and radius from CENTER_REF point */
  564. float slope = (float)y / (float)x;
  565. float radius = sqrt(x*x + y*y);
  566.  
  567. if (radius > RADIUS_MIN) {
  568. if (x == 0) {
  569. if (y >= 0)
  570. result = 0;
  571. else
  572. result = 5;
  573. } else if (y == 0) {
  574. if (x >= 0)
  575. result = 2;
  576. else
  577. result = 8;
  578. } else {
  579. if (slope > SLOPE_72_DEGREE) {
  580. if (y > 0)
  581. result = 0;
  582. else
  583. result = 5;
  584. } else if (slope > SLOPE_36_DEGREE) {
  585. if (y > 0)
  586. result = 1;
  587. else
  588. result = 6;
  589. } else if (slope > SLOPE_180_DEGREE) {
  590. if (y > 0)
  591. result = 2;
  592. else
  593. result = 7;
  594. } else if (slope > SLOPE_144_DEGREE) {
  595. if (y > 0)
  596. result = 8;
  597. else
  598. result = 3;
  599. } else if (slope > SLOPE_108_DEGREE) {
  600. if (y > 0)
  601. result = 9;
  602. else
  603. result = 4;
  604. } else {
  605. if (y > 0)
  606. result = 0;
  607. else
  608. result = 5;
  609. }
  610. }
  611. } else {
  612. dlog_print(DLOG_DEBUG, LOG_TAG, "Ignore touch event under min radius");
  613. }
  614.  
  615. return result;
  616. }
  617.  
  618. /*
  619. * @brief Function will be operated when mouse move event is triggered
  620. * @param[in] data The data to be passed to the callback function
  621. * @param[in] e The handle to an Evas canvas to be passed to the callback function
  622. * @param[in] obj The Evas object handle to be passed to the callback function
  623. * @param[in] event_info The system event information
  624. */
  625. static void _rectangle_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
  626. {
  627. Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down*) event_info;
  628.  
  629. /* Ignore unmatched touch event with mouse down event */
  630. if (s_info.mouse_down_dial_num == -1)
  631. return;
  632.  
  633. int temp_move_dial = _get_btn_dial_number(ev->output.x, ev->output.y);
  634.  
  635. if (s_info.mouse_down_dial_num != temp_move_dial)
  636. s_info.mouse_down_dial_num = -1;
  637.  
  638. dlog_print(DLOG_DEBUG, LOG_TAG, "_mouse_move_cb is called down[%d]", s_info.mouse_down_dial_num);
  639. }
  640.  
  641. /*
  642. * @brief Function will be operated when registered event is triggered
  643. * @param[in] data The data to be passed to the callback function
  644. */
  645. static Eina_Bool _longpress_timer_cb(void *data)
  646. {
  647. char *new_dial = NULL;
  648.  
  649. /* Clear Timer */
  650. if (s_info.timer != NULL) {
  651. dlog_print(DLOG_DEBUG, LOG_TAG, "Timer DELETE 0x%x - longpress", s_info.timer);
  652. ecore_timer_del(s_info.timer);
  653. s_info.timer = NULL;
  654. }
  655.  
  656. /* Ignore unmatched touch event with mouse down event */
  657. if (s_info.mouse_down_dial_num == -1)
  658. return EINA_FALSE;
  659.  
  660. if (s_info.mouse_down_dial_num == 3)
  661. new_dial = strdup("#");
  662. else if (s_info.mouse_down_dial_num == 5)
  663. new_dial = strdup("+");
  664. else if (s_info.mouse_down_dial_num == 7)
  665. new_dial = strdup("*");
  666. else
  667. return ECORE_CALLBACK_CANCEL;
  668.  
  669. s_info.mouse_down_dial_num = -1;
  670.  
  671. if (new_dial) {
  672. /* Set new Entry text for long-press */
  673. view_dialer_set_entry_text(ENTRY_TEXT_ADD_TEXT, new_dial);
  674. free(new_dial);
  675. }
  676.  
  677. return ECORE_CALLBACK_CANCEL;
  678. }
  679.  
  680. /*
  681. * @brief Function will be operated when mouse down event is triggered
  682. * @param[in] data The data to be passed to the callback function
  683. * @param[in] e The handle to an Evas canvas to be passed to the callback function
  684. * @param[in] obj The Evas object handle to be passed to the callback function
  685. * @param[in] event_info The system event information
  686. */
  687. static void _rectangle_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
  688. {
  689. Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down*) event_info;
  690. s_info.mouse_down_dial_num = _get_btn_dial_number(ev->output.x, ev->output.y);
  691.  
  692. if (s_info.mouse_down_dial_num != -1) {
  693. char signal[9] = {0, };
  694.  
  695. /* Trigger touch animation */
  696. snprintf(signal, sizeof(signal), "%s%d", "button.", s_info.mouse_down_dial_num);
  697. elm_layout_signal_emit(s_info.layout, "button.dial.touch", signal);
  698.  
  699. if (s_info.mouse_down_dial_num == 3
  700. || s_info.mouse_down_dial_num == 5
  701. || s_info.mouse_down_dial_num == 7) {
  702. s_info.timer = ecore_timer_add(LONGPRESS_TIME, _longpress_timer_cb, NULL);
  703. dlog_print(DLOG_DEBUG, LOG_TAG, "Timer SET 0x%x", s_info.timer);
  704. }
  705. }
  706. }
  707.  
  708. /*
  709. * @brief Function will be operated when mouse up event is triggered
  710. * @param[in] data The data to be passed to the callback function
  711. * @param[in] e The handle to an Evas canvas to be passed to the callback function
  712. * @param[in] obj The Evas object handle to be passed to the callback function
  713. * @param[in] event_info The system event information
  714. */
  715. static void _rectangle_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
  716. {
  717. /* Clear Timer */
  718. if (s_info.timer != NULL) {
  719. dlog_print(DLOG_DEBUG, LOG_TAG, "Timer DELETE 0x%x - mouse up", s_info.timer);
  720. ecore_timer_del(s_info.timer);
  721. s_info.timer = NULL;
  722. }
  723.  
  724. /* Ignore unmatched touch event with mouse down event */
  725. if (s_info.mouse_down_dial_num == -1)
  726. return;
  727.  
  728. /* Set new Entry text */
  729. char new_dial[2] = { 0, };
  730. snprintf(new_dial, sizeof(new_dial), "%d", s_info.mouse_down_dial_num);
  731. view_dialer_set_entry_text(ENTRY_TEXT_ADD_TEXT, new_dial);
  732.  
  733. /* Initialize event records */
  734. s_info.mouse_down_dial_num = -1;
  735. }
  736.  
  737. /*
  738. * @brief Layout back key event callback function
  739. * @param[in] data The data to be passed to the callback function
  740. * @param[in] obj The Evas object handle to be passed to the callback function
  741. * @param[in] event_info The system event information
  742. */
  743. static void _dialer_layout_cb(void *data, Evas_Object *obj, void *event_info)
  744. {
  745. dlog_print(DLOG_DEBUG, LOG_TAG, "_dialer_layout_cb is called");
  746. ui_app_exit();
  747. }
  748.  
  749. /*
  750. * @brief Resize dialer entry text for long text
  751. * @param[in] entry Entry object to be modified by this function
  752. */
  753. static void _dialer_text_resize(Evas_Object *entry)
  754. {
  755. const char *dial_entry = elm_entry_entry_get(entry);
  756. int text_length = strlen(dial_entry);
  757.  
  758. /* Change Entry text style and size according to length */
  759. if (text_length < 12)
  760. elm_entry_text_style_user_push(entry, DIAL_TEXT_STYLE_NORMAL);
  761. else if (text_length < 15)
  762. elm_entry_text_style_user_push(entry, DIAL_TEXT_STYLE_SMALL);
  763. else
  764. elm_entry_text_style_user_push(entry, DIAL_TEXT_STYLE_SMALLER);
  765.  
  766. /* Set entry cursor to end for displaying last updated entry text*/
  767. elm_entry_cursor_end_set(entry);
  768. }
  769.  
  770. /*
  771. * @brief This function just return static layout object.
  772. */
  773. Evas_Object *view_dialer_get_layout_object(void)
  774. {
  775. return s_info.layout;
  776. }