3 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <Elementary.h>
20 #include "adventure.h"
27 win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
32 static Evas_Object *_create_adventure(Evas_Object *parent)
34 Evas_Object *adventure = NULL;
36 char full_path[PATH_LEN] = {0, };
38 adventure = elm_layout_add(parent);
39 retv_if(!adventure, NULL);
41 path = app_get_resource_path();
44 snprintf(full_path, sizeof(full_path), "%s/edje/adventure.edj", path);
46 elm_layout_file_set(adventure, full_path, "main");
47 evas_object_size_hint_weight_set(adventure, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
48 evas_object_size_hint_align_set(adventure, EVAS_HINT_FILL, EVAS_HINT_FILL);
49 evas_object_show(adventure);
54 static void _destroy_adventure(Evas_Object *adventure)
57 evas_object_del(adventure);
60 Eina_Bool _destroy_initial_cb(void *data)
62 adventure_info_s *adventure_info = data;
64 retv_if(!adventure_info, ECORE_CALLBACK_CANCEL);
66 elm_object_part_content_unset(adventure_info->adventure, "initial");
67 initial_destroy(adventure_info->initial);
68 adventure_info->initial_timer = NULL;
70 adventure_info->ui_manager = ui_manager_create(adventure_info->conformant, adventure_info);
71 retv_if(!adventure_info->ui_manager, ECORE_CALLBACK_CANCEL);
74 adventure_info->loading = loading_create(adventure_info->adventure, adventure_info->width, adventure_info->height);
75 retv_if(!adventure_info->loading, ECORE_CALLBACK_CANCEL);
76 elm_object_part_content_set(adventure_info->adventure, "loading", adventure_info->loading);
79 return ECORE_CALLBACK_CANCEL;
83 app_create(void *data)
85 adventure_info_s *adventure_info = data;
86 adventure_info->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
87 elm_win_conformant_set(adventure_info->win, EINA_TRUE);
88 elm_win_autodel_set(adventure_info->win, EINA_TRUE);
89 if (elm_win_wm_rotation_supported_get(adventure_info->win)) {
91 elm_win_wm_rotation_available_rotations_set(adventure_info->win, (const int *)(&rots), 1);
93 evas_object_smart_callback_add(adventure_info->win, "delete,request", win_delete_request_cb, NULL);
94 elm_win_screen_size_get(adventure_info->win, NULL, NULL, &adventure_info->width, &adventure_info->height);
95 evas_object_show(adventure_info->win);
97 adventure_info->conform = elm_conformant_add(adventure_info->win);
98 elm_win_indicator_mode_set(adventure_info->win, ELM_WIN_INDICATOR_HIDE);
99 evas_object_size_hint_weight_set(adventure_info->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100 elm_win_resize_object_add(adventure_info->win, adventure_info->conform);
101 evas_object_show(adventure_info->conform);
103 _D("Window size (%d:%d)", adventure_info->width, adventure_info->height);
105 adventure_info->adventure = _create_adventure(adventure_info->conform);
106 if (adventure_info->adventure)
107 elm_object_content_set(adventure_info->conform, adventure_info->adventure);
109 _E("cannot create the adventure ui");
111 adventure_info->initial = initial_create(adventure_info->conform, adventure_info->width, adventure_info->height);
112 if (adventure_info->initial)
113 elm_object_part_content_set(adventure_info->adventure, "initial", adventure_info->initial);
115 _E("cannot create the initial ui");
117 adventure_info->initial_timer = ecore_timer_add(3.0f, _destroy_initial_cb, adventure_info);
118 retv_if(!adventure_info->initial_timer, false);
124 app_control(app_control_h app_control, void *data)
126 adventure_info_s *adventure_info = data;
127 ret_if(!adventure_info);
131 app_pause(void *data)
133 /* Take necessary actions when application becomes invisible. */
137 app_resume(void *data)
139 /* Take necessary actions when application becomes visible. */
143 app_terminate(void *data)
145 adventure_info_s *adventure_info = data;
147 if (adventure_info->ui_manager)
148 ui_manager_destroy(adventure_info->ui_manager);
150 if (adventure_info->adventure)
151 _destroy_adventure(adventure_info->adventure);
153 if (adventure_info->initial_timer) {
154 ecore_timer_del(adventure_info->initial_timer);
155 initial_destroy(adventure_info->initial);
158 if (adventure_info->conform)
159 evas_object_del(adventure_info->conform);
161 if (adventure_info->win)
162 evas_object_del(adventure_info->win);
166 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
168 /*APP_EVENT_LANGUAGE_CHANGED*/
170 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
171 elm_language_set(locale);
177 ui_app_orient_changed(app_event_info_h event_info, void *user_data)
179 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
184 ui_app_region_changed(app_event_info_h event_info, void *user_data)
186 /*APP_EVENT_REGION_FORMAT_CHANGED*/
190 ui_app_low_battery(app_event_info_h event_info, void *user_data)
192 /*APP_EVENT_LOW_BATTERY*/
196 ui_app_low_memory(app_event_info_h event_info, void *user_data)
198 /*APP_EVENT_LOW_MEMORY*/
202 main(int argc, char *argv[])
204 adventure_info_s adventure_info = {0,};
207 ui_app_lifecycle_callback_s event_callback = {0,};
208 app_event_handler_h handlers[5] = {NULL, };
210 event_callback.create = app_create;
211 event_callback.terminate = app_terminate;
212 event_callback.pause = app_pause;
213 event_callback.resume = app_resume;
214 event_callback.app_control = app_control;
216 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &adventure_info);
217 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &adventure_info);
218 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &adventure_info);
219 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &adventure_info);
220 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &adventure_info);
221 ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
223 ret = ui_app_main(argc, argv, &event_callback, &adventure_info);
224 if (ret != APP_ERROR_NONE) {
225 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);