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 "../../events/SDL_events_c.h"
30 #include <app_internal.h>
31 #include <app_extension.h>
32 #include <system_settings.h>
34 static int tizen_appcore_initialized = 0;
35 static appcore_context_h appcore_handle = NULL;
36 static ui_app_lifecycle_callback_s event_callback = {0,};
37 static app_event_handler_h handlers[5] = {NULL, };
40 * Impplementation of serveral app core callback function for SDL Application and App Core
44 _tizen_sdl_create(void *data)
46 SDL_Log("App Create");
51 _tizen_sdl_terminate(void *data)
53 SDL_Log("App Termincate");
55 SDL_SendAppEvent(SDL_APP_TERMINATING);
60 _tizen_sdl_pause (void *data)
63 SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
64 SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
69 _tizen_sdl_resume(void *data)
71 SDL_Log("App Resume");
72 SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
73 SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
78 _tizen_sdl_control(app_control_h app_control, void *data)
80 SDL_Log("App Control");
83 SDL_memset(&event, 0, sizeof(event));
84 event.type = SDL_APP_CONTROL;
86 event.user.data1 = (void*)app_control;
87 event.user.data2 = (void*)data;
89 SDL_PushEvent(&event);
94 _tizen_app_lang_changed(app_event_info_h event_info, void *user_data)
96 /*APP_EVENT_LANGUAGE_CHANGED*/
98 SDL_Log("Language changed");
99 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
105 _tizen_app_orient_changed(app_event_info_h event_info, void *user_data)
107 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
108 app_device_orientation_e orientation;
109 app_event_get_device_orientation(event_info, &orientation);
110 SDL_Log("Orientation Changed, Rotation Degree : %d", orientation);
112 SDL_memset(&event, 0, sizeof(event));
113 event.type = SDL_ROTATEEVENT;
115 event.user.data1 = (void*)orientation;
116 event.user.data2 = (void*)-1;
118 SDL_PushEvent(&event);
123 _tizen_app_region_changed(app_event_info_h event_info, void *user_data)
125 /*APP_EVENT_REGION_FORMAT_CHANGED*/
126 SDL_Log("region changed");
130 _tizen_app_low_battery(app_event_info_h event_info, void *user_data)
132 /*APP_EVENT_LOW_BATTERY*/
133 SDL_Log("low battery");
137 _tizen_app_low_memory(app_event_info_h event_info, void *user_data)
139 /*APP_EVENT_LOW_MEMORY*/
140 SDL_Log("low memory");
141 SDL_SendAppEvent(SDL_APP_LOWMEMORY);
145 SDL_tizen_app_init(int argc, char *argv[])
147 SDL_Log( "SDL Tizen App initialize");
148 if (tizen_appcore_initialized) {
149 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Already initialized!");
152 tizen_appcore_initialized = 1;
153 if (argc < 1 || argv == NULL) {
154 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"APP_ERROR_INVALID_PARAMETER");
158 event_callback.create = _tizen_sdl_create;
159 event_callback.terminate = _tizen_sdl_terminate;
160 event_callback.pause = _tizen_sdl_pause;
161 event_callback.resume = _tizen_sdl_resume;
162 event_callback.app_control = _tizen_sdl_control;
164 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, _tizen_app_low_battery, NULL);
165 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, _tizen_app_low_memory, NULL);
166 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, _tizen_app_orient_changed, NULL);
167 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _tizen_app_lang_changed, NULL);
168 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, _tizen_app_region_changed, NULL);
170 return ui_app_init(argc, argv, &event_callback, NULL, &appcore_handle);
174 SDL_tizen_app_exit(void)
176 ui_app_fini(appcore_handle);