fix UC popup as wearable style
[platform/core/location/maps-plugin-here.git] / heremaps-uc / src / heremaps-uc.c
1 /*
2  * heremaps-uc
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jongmun Woo <jongmun.woo@samsung.com>, Seechan Kim <cbible.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include "heremaps-uc-common.h"
23
24 #define EDJE_PATH "/usr/apps/org.tizen.heremaps-uc/res/edje/heremaps-uc.edj"
25
26 static Evas_Object *create_conformant(Evas_Object * parent)
27 {
28         LS_FUNC_ENTER
29         Evas_Object *conformant = NULL;
30
31         conformant = elm_conformant_add(parent);
32         elm_win_conformant_set(parent, EINA_TRUE);
33         elm_win_resize_object_add(parent, conformant);
34         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
35         evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
36         evas_object_show(conformant);
37
38         LS_FUNC_EXIT
39         return conformant;
40 }
41
42 static Evas_Object *create_layout(Evas_Object * parent)
43 {
44         LS_FUNC_ENTER
45         Evas_Object *layout = NULL;
46
47         if (parent != NULL) {
48                 layout = elm_layout_add(parent);
49                 elm_object_content_set(parent, layout);
50                 evas_object_show(layout);
51         }
52
53         LS_FUNC_EXIT
54         return layout;
55 }
56
57 static void win_del(void *data, Evas_Object * obj, void *event)
58 {
59         LS_FUNC_ENTER
60         elm_exit();
61 }
62
63 static void save_vconf(int value, heremaps_uc_app_data *ad)
64 {
65         int enabled = 0;
66         int ret = 0;
67
68         ret = vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled);
69         if (ret != 0)
70                 LS_LOGE("Fail to get vconf value");
71         else if (enabled != value) {
72                 ret = vconf_set_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, value);
73                 if (ret != 0)
74                         LS_LOGE("Fail to set vconf value");
75         }
76 }
77
78 static void disagree_btn_cb(void *data, Evas_Object * obj, void *event)
79 {
80         LS_FUNC_ENTER
81         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
82
83         save_vconf(0, ad);
84
85         elm_exit();
86 }
87
88 static void agree_btn_cb(void *data, Evas_Object * obj, void *event)
89 {
90         LS_FUNC_ENTER
91         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
92
93         save_vconf(1, ad);
94
95         elm_exit();
96 }
97
98 static void back_btn_cb(void *data, Evas_Object * obj, void *event)
99 {
100         LS_FUNC_ENTER
101         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
102
103         save_vconf(0, ad);
104         elm_exit();
105 }
106
107 static Evas_Object *create_win(const char *name)
108 {
109         LS_FUNC_ENTER
110         Evas_Object *eo;
111
112         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
113         if (eo) {
114                 elm_win_title_set(eo, name);
115                 elm_win_borderless_set(eo, EINA_TRUE);
116                 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
117                 elm_win_alpha_set(eo, EINA_TRUE);
118                 if (elm_win_wm_rotation_supported_get(eo)) {
119                         int rots[4] = { 0, 90, 180, 270 };
120                         elm_win_wm_rotation_available_rotations_set(eo, (const int *)(&rots), 4);
121                 }
122         }
123         return eo;
124 }
125
126 #ifdef TIZEN_WEARABLE
127 static Evas_Object *create_popup_wearable(Evas_Object *layout, heremaps_uc_app_data *ad)
128 {
129         LS_FUNC_ENTER
130         Evas_Object *popup;
131         Evas_Object *disagree_btn, *agree_btn;
132
133         /* popup */
134         popup = elm_popup_add(layout);
135         elm_object_style_set(popup, "circle");
136         evas_object_size_hint_weight_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
137         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, back_btn_cb, ad);
138
139         Evas_Object *popupLayout = elm_layout_add(popup);
140         elm_layout_theme_set(popupLayout, "layout", "popup", "content/circle/buttons2");
141         evas_object_size_hint_align_set(popupLayout, EVAS_HINT_FILL, EVAS_HINT_FILL);
142         evas_object_size_hint_weight_set(popupLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
143         elm_object_part_text_set(popupLayout, "elm.text.title", P_("IDS_POSITIONING_CONSENT_TITLE"));
144         elm_object_content_set(popup, popupLayout);
145
146         Evas_Object *box = elm_box_add(popupLayout);
147         elm_box_align_set(box, 0.5, 0);
148         elm_object_part_content_set(popupLayout, "elm.swallow.content", box);
149         evas_object_show(box);
150
151         char buf[4096] = {0};
152         char *str1 = P_("IDS_POSITIONING_CONSENT_BODY");
153         char *str2 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/terms/service-terms>http://here.com/terms/service-terms</a></color>";
154         char *str3 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/privacy/privacy-policy>http://here.com/privacy/privacy-policy</a></color>";
155         snprintf(buf, 4096, str1, str2, str3);
156         char *text = strdup(buf);
157
158         Evas_Object *entry1 = elm_entry_add(box);
159         evas_object_size_hint_weight_set(entry1, EVAS_HINT_EXPAND, 0.0);
160         evas_object_size_hint_align_set(entry1, EVAS_HINT_FILL, EVAS_HINT_FILL);
161         elm_entry_editable_set(entry1, EINA_FALSE);
162         elm_entry_line_wrap_set(entry1, ELM_WRAP_CHAR);
163         elm_object_part_text_set(entry1, "elm.text", text);
164         elm_box_pack_end(box, entry1);
165         evas_object_show(entry1);
166
167         /* Disagree button */
168         disagree_btn = elm_button_add(popup);
169         elm_object_style_set(disagree_btn, "popup/circle/left");
170         evas_object_size_hint_weight_set(disagree_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
171         evas_object_smart_callback_add(disagree_btn, "clicked", disagree_btn_cb, ad);
172         elm_object_part_content_set(popup, "button1", disagree_btn);
173
174         Evas_Object *icon = elm_image_add(disagree_btn);
175         elm_image_file_set(icon, EDJE_PATH, "tw_ic_popup_btn_delete.png");
176         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177         elm_object_part_content_set(disagree_btn, "elm.swallow.content", icon);
178         evas_object_show(icon);
179
180         /* Agree button */
181         agree_btn = elm_button_add(popup);
182         elm_object_style_set(agree_btn, "popup/circle/right");
183         evas_object_size_hint_weight_set(agree_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
184
185         icon = elm_image_add(agree_btn);
186         elm_image_file_set(icon, EDJE_PATH, "tw_ic_popup_btn_check.png");
187         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
188         elm_object_part_content_set(agree_btn, "elm.swallow.content", icon);
189         evas_object_show(icon);
190
191         evas_object_smart_callback_add(agree_btn, "clicked", agree_btn_cb, ad);
192         elm_object_part_content_set(popup, "button2", agree_btn);
193
194         evas_object_show(popup);
195         LS_FUNC_EXIT
196         return popup;
197 }
198
199 #else
200 static Evas_Object *create_popup(Evas_Object *layout, heremaps_uc_app_data *ad)
201 {
202         LS_FUNC_ENTER
203         Evas_Object *popup;
204         Evas_Object *disagree_btn, *agree_btn;
205
206         /* popup */
207         popup = elm_popup_add(layout);
208         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
209         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, back_btn_cb, ad);
210         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
211         elm_object_part_text_set(popup, "title,text", P_("IDS_POSITIONING_CONSENT_TITLE"));
212
213         char buf[4096] = {0};
214         char *str1 = P_("IDS_POSITIONING_CONSENT_BODY");
215         char *str2 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/terms/service-    terms>http://here.com/terms/service-terms</a></color>";
216         char *str3 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/privacy/privac    y-policy>http://here.com/privacy/privacy-policy</a></color>";
217         snprintf(buf, 4096, str1, str2, str3);
218         char *text = strdup(buf);
219         elm_object_text_set(popup, text);
220
221         /* Disagree button */
222         disagree_btn = elm_button_add(popup);
223         elm_object_style_set(disagree_btn, "popup");
224         elm_object_text_set(disagree_btn, P_("IDS_ST_BUTTON_DISAGREE"));
225         elm_object_part_content_set(popup, "button1", disagree_btn);
226         evas_object_smart_callback_add(disagree_btn, "clicked", disagree_btn_cb, ad);
227
228         /* Agree button */
229         agree_btn = elm_button_add(popup);
230         elm_object_style_set(agree_btn, "popup");
231         elm_object_text_set(agree_btn, P_("IDS_ST_BUTTON_AGREE"));
232         elm_object_part_content_set(popup, "button2", agree_btn);
233         evas_object_smart_callback_add(agree_btn, "clicked", agree_btn_cb, ad);
234
235         evas_object_show(popup);
236         LS_FUNC_EXIT
237         return popup;
238 }
239 #endif
240
241 static bool _app_create_cb(void *user_data)
242 {
243         LS_FUNC_ENTER
244
245         return true;
246 }
247
248 static void _app_terminate_cb(void *user_data)
249 {
250         LS_FUNC_ENTER
251 }
252
253 static void _app_pause_cb(void *user_data)
254 {
255         LS_FUNC_ENTER
256 }
257
258 static void _app_resume_cb(void *user_data)
259 {
260         LS_FUNC_ENTER
261 }
262
263 static void _app_control_cb(app_control_h app_control, void *user_data)
264 {
265         LS_FUNC_ENTER
266
267         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) user_data;
268         LS_RETURN_IF_FAILED(ad);
269
270         if (ad->win_main) {
271                 evas_object_del(ad->win_main);
272                 ad->win_main = NULL;
273         }
274
275         elm_app_base_scale_set(2.6);
276         elm_config_accel_preference_set("3d");
277
278         bindtextdomain(HEREMAPS_UC_PKG, LOCALE_DIR);
279
280         save_vconf(-1, ad);
281
282         ad->win_main = create_win(HEREMAPS_UC_PKG);
283         ad->conformant = create_conformant(ad->win_main);
284         ad->layout_main = create_layout(ad->conformant);
285
286 #ifdef TIZEN_WEARABLE
287         ad->popup = create_popup_wearable(ad->layout_main, ad);
288 #else
289         ad->popup = create_popup(ad->layout_main, ad);
290 #endif
291
292         evas_object_show(ad->win_main);
293         LS_FUNC_EXIT
294 }
295
296 /*
297 static void _app_low_memory_cb(void *user_data)
298 {
299         LS_FUNC_ENTER
300 }
301
302 static void _app_low_battery_cb(void *user_data)
303 {
304         LS_FUNC_ENTER
305 }
306
307 static void _app_device_orientation_cb(app_event_info_h event_info, void *user_data)
308 {
309         LS_FUNC_ENTER
310         LS_RETURN_IF_FAILED(event_info);
311         LS_RETURN_IF_FAILED(user_data);
312
313         heremaps_uc_app_data *ad = (heremaps_uc_app_data *)user_data;
314         app_device_orientation_e orientation;
315         app_event_get_device_orientation(event_info, &orientation);
316         elm_win_rotation_with_resize_set(ad->win_main, orientation);
317 }
318 */
319
320 static void _app_language_changed_cb(app_event_info_h event_info, void *user_data)
321 {
322         LS_FUNC_ENTER
323
324         char *locale = vconf_get_str(VCONFKEY_LANGSET);
325         if (locale) elm_language_set(locale);
326 }
327
328 int main(int argc, char *argv[])
329 {
330         LS_FUNC_ENTER
331
332         int ret = 0;
333         heremaps_uc_app_data ad = {0,};
334
335         ui_app_lifecycle_callback_s event_callback = {0,};
336         app_event_handler_h handlers[5] = {NULL, };
337
338         event_callback.create = _app_create_cb;
339         event_callback.terminate = _app_terminate_cb;
340         event_callback.app_control = _app_control_cb;
341         event_callback.pause = _app_pause_cb;
342         event_callback.resume = _app_resume_cb;
343
344         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed_cb, NULL);
345
346         ret = APP_ERROR_NONE;
347         ret = ui_app_main(argc, argv, &event_callback, &ad);
348
349         if (ret != APP_ERROR_NONE)
350                 LS_LOGE("ui_app_main() is failed. err=%d", ret);
351
352         return ret;
353
354         LS_FUNC_EXIT
355 }