2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
23 #include "../../SDL_internal.h"
26 #include "SDL_tizen.h"
28 #include "SDL_events.h"
29 #include <app_internal.h>
30 #include <app_extension.h>
31 #include <system_settings.h>
33 static int tizen_appcore_initialized = 0;
34 static appcore_context_h appcore_handle = NULL;
35 static ui_app_lifecycle_callback_s event_callback = {0,};
36 static app_event_handler_h handlers[5] = {NULL, };
39 * Impplementation of serveral app core callback function for SDL Application and App Core
43 _tizen_sdl_create(void *data)
45 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "SDL_AppCore CreateCB");
50 _tizen_sdl_terminate(void *data)
52 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "SDL_AppCore TermincateCB");
54 SDL_SendAppEvent(SDL_APP_TERMINATING);
59 _tizen_sdl_pause (void *data)
61 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "SDL_AppCore PauseCB");
62 SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
63 SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
68 _tizen_sdl_resume(void *data)
70 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "SDL_AppCore ResumeCB");
71 SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
72 SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
77 _tizen_sdl_control(app_control_h app_control, void *data)
79 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "SDL_AppCore ControlCB");
84 _tizen_app_lang_changed(app_event_info_h event_info, void *user_data)
86 /*APP_EVENT_LANGUAGE_CHANGED*/
88 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Language changedCB");
89 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
95 _tizen_app_orient_changed(app_event_info_h event_info, void *user_data)
97 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
98 app_device_orientation_e orientation;
99 app_event_get_device_orientation(event_info, &orientation);
100 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION," Orientation Changed CB, Rotation Degree : %d", orientation);
102 SDL_memset(&event, 0, sizeof(event));
103 event.type = SDL_ROTATEEVENT;
104 event.user.code = NULL;
105 event.window.data1 = (void*)orientation;
106 event.user.data2 = -1;
108 SDL_PushEvent(&event);
113 _tizen_app_region_changed(app_event_info_h event_info, void *user_data)
115 /*APP_EVENT_REGION_FORMAT_CHANGED*/
116 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "region changedCB");
120 _tizen_app_low_battery(app_event_info_h event_info, void *user_data)
122 /*APP_EVENT_LOW_BATTERY*/
123 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "low battery CB");
127 _tizen_app_low_memory(app_event_info_h event_info, void *user_data)
129 /*APP_EVENT_LOW_MEMORY*/
130 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "low memory CB");
131 SDL_SendAppEvent(SDL_APP_LOWMEMORY);
135 SDL_tizen_app_init(int argc, char *argv[])
137 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "SDL Tizen App initialize");
138 if (tizen_appcore_initialized)
140 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Already initialized!");
143 tizen_appcore_initialized = 1;
144 if (argc < 1 || argv == NULL)
146 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "APP_ERROR_INVALID_PARAMETER");
150 event_callback.create = _tizen_sdl_create;
151 event_callback.terminate = _tizen_sdl_terminate;
152 event_callback.pause = _tizen_sdl_pause;
153 event_callback.resume = _tizen_sdl_resume;
154 event_callback.app_control = _tizen_sdl_control;
156 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, _tizen_app_low_battery, NULL);
157 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, _tizen_app_low_memory, NULL);
158 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, _tizen_app_orient_changed, NULL);
159 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _tizen_app_lang_changed, NULL);
160 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, _tizen_app_region_changed, NULL);
162 return ui_app_init(argc, argv, &event_callback, NULL, &appcore_handle);
166 SDL_tizen_app_exit(void)
168 ui_app_fini(appcore_handle);