summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrince Kumar Dubey <prince.dubey@samsung.com>2017-10-24 15:29:22 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-10-24 15:44:16 +0900
commit9d2dcd92f795a89513883cf42bbe85be7cf562cf (patch)
tree916e565ca508583e6873809992160332a3f58fa1
parent880dd63a0c884642a0f87aa3a08338a7b244e37a (diff)
example: improve location example, fix crash
Summary: Printing Address detail with Position. Label added to show the detail of address. Test Plan: Compiled with cmd: gcc -o location_example_01 \ location_example_01.c -g `pkg-config --cflags --libs elementary \ elocation` Reviewers: raster, cedric Subscribers: rajeshps, jpeg Differential Revision: https://phab.enlightenment.org/D5356
-rw-r--r--src/examples/elementary/location_example_01.c78
1 files changed, 68 insertions, 10 deletions
diff --git a/src/examples/elementary/location_example_01.c b/src/examples/elementary/location_example_01.c
index a46bf75fc5..96ca818069 100644
--- a/src/examples/elementary/location_example_01.c
+++ b/src/examples/elementary/location_example_01.c
@@ -1,12 +1,13 @@
1//Compile with: 1//Compile with:
2//gcc -o location_example_01 location_example_01.c -g `pkg-config --cflags --libs elementary elocation` 2//gcc -o location_example_01 location_example_01.c -g `pkg-config --cflags --libs elementary elocation`
3 3
4#define EFL_BETA_API_SUPPORT
4#include <Elementary.h> 5#include <Elementary.h>
5#ifdef ELM_ELOCATION 6#ifdef ELM_ELOCATION
6#include <Elocation.h> 7#include <Elocation.h>
7#endif 8#endif
8 9
9static Evas_Object *label, *win; 10static Evas_Object *pos_label, *addr_label, *box, *win;
10 11
11#ifdef ELM_ELOCATION 12#ifdef ELM_ELOCATION
12static void 13static void
@@ -16,6 +17,7 @@ _print_position(Elocation_Position *position)
16 17
17 if (!position) return; 18 if (!position) return;
18 snprintf(buffer, sizeof(buffer), 19 snprintf(buffer, sizeof(buffer),
20 "<b>### Position Detail ###</b><br/>"
19 "<b>GeoClue position reply with data from timestamp</b> %i<br/>" 21 "<b>GeoClue position reply with data from timestamp</b> %i<br/>"
20 "<b>Latitude:</b> %f<br/>" 22 "<b>Latitude:</b> %f<br/>"
21 "<b>Longitude:</b> %f<br/>" 23 "<b>Longitude:</b> %f<br/>"
@@ -26,7 +28,32 @@ _print_position(Elocation_Position *position)
26 position->timestamp, position->latitude, position->longitude, 28 position->timestamp, position->latitude, position->longitude,
27 position->altitude, position->accur->level, 29 position->altitude, position->accur->level,
28 position->accur->horizontal, position->accur->vertical); 30 position->accur->horizontal, position->accur->vertical);
29 elm_object_text_set(label, buffer); 31 elm_object_text_set(pos_label, buffer);
32}
33
34static void
35_print_address(Elocation_Address *address)
36{
37 char buffer[1024];
38
39 if (!address) return;
40 snprintf(buffer, sizeof(buffer),
41 "<b>### Address Detail ###</b><br/>"
42 "<b>Address update with data from timestamp:</b> %i<br/>"
43 "<b>Country:</b> %s<br/>"
44 "<b>Countrycode:</b> %s<br/>"
45 "<b>Locality:</b> %s<br/>"
46 "<b>Postalcode:</b> %s<br/>"
47 "<b>Region:</b> %s<br/>"
48 "<b>Timezone:</b> %s<br/>"
49 "<b>Accuracy level:</b> %i<br/>"
50 "<b>Accuracy horizontal:</b> %f<br/>"
51 "<b>Accuracy vertical:</b> %f",
52 address->timestamp, address->country, address->countrycode,
53 address->locality, address->postalcode, address->region,
54 address->timezone, address->accur->level, address->accur->horizontal,
55 address->accur->vertical);
56 elm_object_text_set(addr_label, buffer);
30} 57}
31 58
32static Eina_Bool 59static Eina_Bool
@@ -38,6 +65,17 @@ _position_changed(void *data, int ev_type, void *event)
38 _print_position(position); 65 _print_position(position);
39 return ECORE_CALLBACK_DONE; 66 return ECORE_CALLBACK_DONE;
40} 67}
68
69static Eina_Bool
70_address_changed(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
71{
72 Elocation_Address *address;
73
74 address = event;
75 _print_address(address);
76
77 return ECORE_CALLBACK_DONE;
78}
41#endif 79#endif
42 80
43EAPI_MAIN int 81EAPI_MAIN int
@@ -57,25 +95,45 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
57 win = elm_win_util_standard_add("elocation", "Elocation example"); 95 win = elm_win_util_standard_add("elocation", "Elocation example");
58 elm_win_autodel_set(win, EINA_TRUE); 96 elm_win_autodel_set(win, EINA_TRUE);
59 97
60 label = elm_label_add(win); 98 box = elm_box_add(win);
61 elm_label_line_wrap_set(label, ELM_WRAP_CHAR); 99 elm_win_resize_object_add(win, box);
62 elm_object_text_set(label, "Getting location ..."); 100 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
63 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0); 101 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
64 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL); 102
65 elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_ALWAYS); 103 pos_label = elm_label_add(box);
66 evas_object_resize(label, 600, 480); 104 elm_label_line_wrap_set(pos_label, ELM_WRAP_CHAR);
67 evas_object_show(label); 105 elm_object_text_set(pos_label, "Getting location ...");
106 evas_object_size_hint_weight_set(pos_label, EVAS_HINT_EXPAND, 0.0);
107 evas_object_size_hint_align_set(pos_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
108 elm_label_slide_mode_set(pos_label, ELM_LABEL_SLIDE_MODE_ALWAYS);
109 elm_box_pack_end(box, pos_label);
110 evas_object_show(pos_label);
111 elm_box_padding_set(box, 0, 50);
112
113 addr_label = elm_label_add(box);
114 elm_label_line_wrap_set(addr_label, ELM_WRAP_CHAR);
115 elm_object_text_set(addr_label, "Getting location ...");
116 evas_object_size_hint_weight_set(addr_label, EVAS_HINT_EXPAND, 0.0);
117 evas_object_size_hint_align_set(addr_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
118 elm_label_slide_mode_set(addr_label, ELM_LABEL_SLIDE_MODE_ALWAYS);
119 elm_box_pack_end(box, addr_label);
120 evas_object_show(addr_label);
68 121
69#ifdef ELM_ELOCATION 122#ifdef ELM_ELOCATION
70 address = elocation_address_new(); 123 address = elocation_address_new();
71 position = elocation_position_new(); 124 position = elocation_position_new();
72 125
73 ecore_event_handler_add(ELOCATION_EVENT_POSITION, _position_changed, NULL); 126 ecore_event_handler_add(ELOCATION_EVENT_POSITION, _position_changed, NULL);
127 ecore_event_handler_add(ELOCATION_EVENT_ADDRESS, _address_changed, NULL);
74 128
75 elocation_position_get(position); 129 elocation_position_get(position);
76 _print_position(position); 130 _print_position(position);
131
132 elocation_address_get(address);
133 _print_address(address);
77#endif 134#endif
78 135
136 evas_object_show(box);
79 evas_object_resize(win, 600, 480); 137 evas_object_resize(win, 600, 480);
80 evas_object_show(win); 138 evas_object_show(win);
81 139