타이젠 BasicUI 템플릿 소스코드 주석
#include "basicui.h" // 헤더파일을 링크
typedef struct appdata {
Evas_Object *win;
Evas_Object *conform;
Evas_Object *label;
} appdata_s; // 앱에서 사용하는 데이터를 저장하는 구조체
static void // 종료버튼을 눌렀을때 일어나는 이벤트
win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
{
ui_app_exit();
}
static void // 뒤로가기 버튼을 눌렀을때 일어나는 이벤트
win_back_cb(void *data, Evas_Object *obj, void *event_info)
{
appdata_s *ad = data;
/* Let window go to hide state. */
elm_win_lower(ad->win);
}
static void // UI의 기본틀을 만드는 부분 화면을 구성하는 각종 윈도우와 위젯 컴포넌트의 초기화를 하는 함수
create_base_gui(appdata_s *ad)
{
/* Window */
/* Create and initialize elm_win.
elm_win is mandatory to manipulate window. */
ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE); //앱의 최상위 객체인 윈도우를 생성
elm_win_autodel_set(ad->win, EINA_TRUE);
if (elm_win_wm_rotation_supported_get(ad->win)) {
int rots[4] = { 0, 90, 180, 270 }; // 0도 90도 180도 270도
elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
} // 화면 회전 각도를 설정하는 부분
evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
//evas_object_smart_callback_add(오브젝트,이벤트의 종류,콜백함수의 이름,사용자데이터)
//null = 사용자 데이터가 없음.
//스마트 오브젝트의 이벤트 콜백을 지정하는 함수
eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);
//모든 오브젝트의 이벤트 콜백을 지정하는 함수
/* Conformant */
/* Create and initialize elm_conformant.
elm_conformant is mandatory for base gui to have proper size
when indicator or virtual keypad is visible. */
ad->conform = elm_conformant_add(ad->win); //
elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW); //화면 위쪽 Indicator를 보이게 함.
elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);//화면 위쪽 Indicator의 투명도
evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(ad->win, ad->conform);
evas_object_show(ad->conform); //오브젝트를 화면에 표시하도록 설정. 모든 오브젝트는
생성시 기본적으로 Hide 상태
/* Label */
/* Create an actual view of the base gui.
Modify this part to change the view. */
/* 타이젠에서 라벨은 텍스트를 의미합니다.
이 부분을 수정하면 타이젠 앱에서 보여지는 텍스트 즉 GUI가 변합니다. */
/* GUI = Graphic User Interface */
ad->label = elm_label_add(ad->conform);
elm_object_text_set(ad->label, "<align=center>Hello Tizen</align>"); //오브젝트의 텍스트를 변경
evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_content_set(ad->conform, ad->label);
/* Show window after base gui is set up */
evas_object_show(ad->win);
}
static bool
app_create(void *data)
{
/* Hook to take necessary actions before main event loop starts
Initialize UI resources and application's data
If this function returns true, the main loop of application starts
If this function returns false, the application is terminated */
appdata_s *ad = data;
create_base_gui(ad);
return true;
}
static void
app_control(app_control_h app_control, void *data)
{
/* Handle the launch request. */
}
static void
app_pause(void *data)
{
/* Take necessary actions when application becomes invisible. */
}
static void
app_resume(void *data)
{
/* Take necessary actions when application becomes visible. */
}
static void
app_terminate(void *data)
{
/* Release all resources. */
}
static void
ui_app_lang_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LANGUAGE_CHANGED*/
int ret;
char *language;
ret = app_event_get_language(event_info, &language);
if (ret != APP_ERROR_NONE) {
dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
return;
}
if (language != NULL) {
elm_language_set(language);
free(language);
}
}
static void
ui_app_orient_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
return;
}
static void
ui_app_region_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_REGION_FORMAT_CHANGED*/
}
static void
ui_app_low_battery(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_BATTERY*/
}
static void
ui_app_low_memory(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_MEMORY*/
}
int
main(int argc, char *argv[])
{
appdata_s ad = {0,};
int ret = 0;
ui_app_lifecycle_callback_s event_callback = {0,};
app_event_handler_h handlers[5] = {NULL, };
event_callback.create = app_create;
event_callback.terminate = app_terminate;
event_callback.pause = app_pause;
event_callback.resume = app_resume;
event_callback.app_control = app_control;
ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
ret = ui_app_main(argc, argv, &event_callback, &ad);
if (ret != APP_ERROR_NONE) {
dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
}
return ret;
}
typedef struct appdata {
Evas_Object *win;
Evas_Object *conform;
Evas_Object *label;
} appdata_s; // 앱에서 사용하는 데이터를 저장하는 구조체
static void // 종료버튼을 눌렀을때 일어나는 이벤트
win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
{
ui_app_exit();
}
static void // 뒤로가기 버튼을 눌렀을때 일어나는 이벤트
win_back_cb(void *data, Evas_Object *obj, void *event_info)
{
appdata_s *ad = data;
/* Let window go to hide state. */
elm_win_lower(ad->win);
}
static void // UI의 기본틀을 만드는 부분 화면을 구성하는 각종 윈도우와 위젯 컴포넌트의 초기화를 하는 함수
create_base_gui(appdata_s *ad)
{
/* Window */
/* Create and initialize elm_win.
elm_win is mandatory to manipulate window. */
ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE); //앱의 최상위 객체인 윈도우를 생성
elm_win_autodel_set(ad->win, EINA_TRUE);
if (elm_win_wm_rotation_supported_get(ad->win)) {
int rots[4] = { 0, 90, 180, 270 }; // 0도 90도 180도 270도
elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
} // 화면 회전 각도를 설정하는 부분
evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
//evas_object_smart_callback_add(오브젝트,이벤트의 종류,콜백함수의 이름,사용자데이터)
//null = 사용자 데이터가 없음.
//스마트 오브젝트의 이벤트 콜백을 지정하는 함수
eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);
//모든 오브젝트의 이벤트 콜백을 지정하는 함수
/* Conformant */
/* Create and initialize elm_conformant.
elm_conformant is mandatory for base gui to have proper size
when indicator or virtual keypad is visible. */
ad->conform = elm_conformant_add(ad->win); //
elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW); //화면 위쪽 Indicator를 보이게 함.
elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);//화면 위쪽 Indicator의 투명도
evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(ad->win, ad->conform);
evas_object_show(ad->conform); //오브젝트를 화면에 표시하도록 설정. 모든 오브젝트는
생성시 기본적으로 Hide 상태
/* Label */
/* Create an actual view of the base gui.
Modify this part to change the view. */
/* 타이젠에서 라벨은 텍스트를 의미합니다.
이 부분을 수정하면 타이젠 앱에서 보여지는 텍스트 즉 GUI가 변합니다. */
/* GUI = Graphic User Interface */
ad->label = elm_label_add(ad->conform);
elm_object_text_set(ad->label, "<align=center>Hello Tizen</align>"); //오브젝트의 텍스트를 변경
evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_content_set(ad->conform, ad->label);
/* Show window after base gui is set up */
evas_object_show(ad->win);
}
static bool
app_create(void *data)
{
/* Hook to take necessary actions before main event loop starts
Initialize UI resources and application's data
If this function returns true, the main loop of application starts
If this function returns false, the application is terminated */
appdata_s *ad = data;
create_base_gui(ad);
return true;
}
static void
app_control(app_control_h app_control, void *data)
{
/* Handle the launch request. */
}
static void
app_pause(void *data)
{
/* Take necessary actions when application becomes invisible. */
}
static void
app_resume(void *data)
{
/* Take necessary actions when application becomes visible. */
}
static void
app_terminate(void *data)
{
/* Release all resources. */
}
static void
ui_app_lang_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LANGUAGE_CHANGED*/
int ret;
char *language;
ret = app_event_get_language(event_info, &language);
if (ret != APP_ERROR_NONE) {
dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
return;
}
if (language != NULL) {
elm_language_set(language);
free(language);
}
}
static void
ui_app_orient_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
return;
}
static void
ui_app_region_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_REGION_FORMAT_CHANGED*/
}
static void
ui_app_low_battery(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_BATTERY*/
}
static void
ui_app_low_memory(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_MEMORY*/
}
int
main(int argc, char *argv[])
{
appdata_s ad = {0,};
int ret = 0;
ui_app_lifecycle_callback_s event_callback = {0,};
app_event_handler_h handlers[5] = {NULL, };
event_callback.create = app_create;
event_callback.terminate = app_terminate;
event_callback.pause = app_pause;
event_callback.resume = app_resume;
event_callback.app_control = app_control;
ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
ret = ui_app_main(argc, argv, &event_callback, &ad);
if (ret != APP_ERROR_NONE) {
dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
}
return ret;
}
댓글
댓글 쓰기