C Interface design has not been confirmed. but finally we did.
This was for the pre/post event callbacks for life-cycle and common events.
Change-Id: I2f632ca3de5149b8ac24b383e70730c30a675ff5
Conflicts:
src/include/efl/mobile/c/ui_application.h
Change-Id: Ia9bda8a64e8c7a3bffb1b303053fc5b4c355e5d9
#include "main.h"
static bool
-app_create(void *data)
+app_create(void *user_data, void *event_info)
{
/* Hook to take necessary actions before main event loop starts.
Initialize Application base resources and application's data
}
static bool
-app_control(app_control_h app_control, void *user_data)
+app_control(void *user_data, void *event_info)
{
+ //app_control_h app_control = (app_control_h) event_info;
+
/* Handle the launch request. */
return true;
int
main(int argc, char *argv[])
{
- ui_application_lifecycle_cb_s app_lifecycle_cb = {0, };
+ ui_application_event_s events[]= {
+ {UI_APPLICATION_EVENT_CREATE, app_create},
+ {UI_APPLICATION_EVENT_CONTROL, app_control},
+ {UI_APPLICATION_EVENT_LAST, NULL}
+ };
//Initialize ui_app. ui_app initializes basic resources including ui_viewmgr internally.
if (!ui_application_init(PACKAGE, LOCALE_DIR))
return 0;
}
- //Register life cycle callback functions.
- app_lifecycle_cb.create = app_create;
- app_lifecycle_cb.control = app_control;
-
//Run ui_app. Now it requests to run an application mainloop.
- if (!ui_application_run(argc, argv, &app_lifecycle_cb, NULL))
+ if (!ui_application_run(argc, argv, events, NULL))
{
dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_run() is failed");
return 0;
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page1");
return;
}
- //Set View Life-Cycle callbacks.
- lifecycle_cb.load = view1_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view1_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page10");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view10_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view10_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
- //Set Rotation Event callbacks.
+ //Set Rotation callback.
if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_ROTATE, view10_rotate_cb, NULL)))
{
dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page11");
return;
}
- //Set View Life-Cycle callback.
- view_lifecycle_cb.load = view11_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view11_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
- //Set Menu Event callback.
+ //Set Menu callback.
if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_MENU, view11_menu_cb, NULL)))
{
dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view
view = ui_standard_view_create("page12");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view12_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view12_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page13");
//Set Fade Transition Effect.
ui_view_set_transition_style(view, "fade");
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view13_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view13_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page14");
//Turn off Transition Effect.
ui_view_set_transition_style(view, "none");
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view14_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view14_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
view = ui_standard_view_create("page15");
if (!view)
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view15_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view15_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page16");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view16_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view16_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page2");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view2_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view2_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page3");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view3_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view3_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page4");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view4_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view4_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_view_create("page5");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view5_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view5_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page6");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view6_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view6_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page7");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view7_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view7_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
{
int ret = 0;
ui_standard_view *view = NULL;
- ui_view_lifecycle_cb_s view_lifecycle_cb = {0, };
//Create a view.
view = ui_standard_view_create("page9");
return;
}
- //Set View Life-Cycle callbacks.
- view_lifecycle_cb.load = view9_load_cb;
- if (!(ret = ui_view_set_lifecycle_cb(view, &view_lifecycle_cb, NULL)))
+ //Set View Load callback.
+ if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view9_load_cb, NULL)))
{
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_lifecycle_cb() is failed. err = %d", ret);
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
ui_view_destroy(view);
return;
}
- //Set Portrait Event callback.
+ //Set Portrait callback.
if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_PORTRAIT, view9_portrait_cb, NULL)))
{
dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
}
- //Set Landscape Event callback.
+ //Set Landscape callback.
if (!(ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LANDSCAPE, view9_landscape_cb, NULL)))
{
dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret);
class ui_common_view_capi
{
public:
- ui_view_lifecycle_cb_s lifecycle_cb = {nullptr, };
- void *lifecycle_data = nullptr;
-
//TODO: Optimize memory? We don't need all slots.
ui_view_event_cb event_cb[UI_VIEW_EVENT_LAST] = {nullptr, };
void* event_data[UI_VIEW_EVENT_LAST] = {nullptr, };
const char *type = nullptr;
- ui_common_view_capi(const char *type) : lifecycle_data(NULL), type(type)
+ ui_common_view_capi(const char *type) : type(type)
{
}
extern "C" {
#endif
-typedef bool (*ui_application_create_cb)(void *user_data);
-typedef bool (*ui_application_terminate_cb)(void *user_data);
-typedef bool (*ui_application_pause_cb)(void *user_data);
-typedef bool (*ui_application_resume_cb)(void *user_data);
-typedef bool (*ui_application_control_cb)(app_control_h app_control, void *user_data);
+typedef bool (*ui_application_event_cb)(void *user_data, void *event_info);
+
+typedef enum {
+ UI_APPLICATION_EVENT_CREATE = 0,
+ UI_APPLICATION_EVENT_TERMINATE,
+ UI_APPLICATION_EVENT_PAUSE ,
+ UI_APPLICATION_EVENT_RESUME,
+ UI_APPLICATION_EVENT_CONTROL,
+
+ UI_APPLICATION_EVENT_CREATE_PRE,
+ UI_APPLICATION_EVENT_TERMINATE_PRE,
+ UI_APPLICATION_EVENT_PAUSE_PRE,
+ UI_APPLICATION_EVENT_RESUME_PRE,
+ UI_APPLICATION_EVENT_CONTROL_PRE,
+
+ UI_APPLICATION_EVENT_LAST
+} ui_application_event_type_e;
typedef struct
{
- ui_application_create_cb create;
- ui_application_terminate_cb terminate;
- ui_application_pause_cb pause;
- ui_application_resume_cb resume;
- ui_application_control_cb control;
-
-} ui_application_lifecycle_cb_s;
+ ui_application_event_type_e event_type;
+ ui_application_event_cb event_cb;
+} ui_application_event_s;
/**
* @defgroup CAPI_UI_APPLICATION UI Application
*
* @param argc The argument count.
* @param argv The argument vector.
- * @param lifecycle_callback The set of callback functions to handle application lifecycle events.
- * @param user_data The user data to be passed to the given @a life_cycle_callback functions.
+ * @param events event callback list.
+ * @param user_data user data for event callbacks
*
* @return @c true if it succeeds, @c false otherwise.
*
* @since_tizen 3.0
*/
-EAPI bool ui_application_run(int argc, char **argv, ui_application_lifecycle_cb_s *app_lifecycle_cb, void *user_data);
+EAPI bool ui_application_run(int argc, char **argv, ui_application_event_s *events, void *user_data);
/**
* @brief This is ui_application destructor.
* @{
*/
-/**
- * @brief ui_view's lifecycle callback function signature.
- *
- * @since_tizen 3.0
- */
-typedef bool (*ui_view_lifecycle_cb)(ui_view *view, void *user_data);
-
/**
* @brief ui_view's rotate event callback function signature.
*
*/
typedef bool (*ui_view_event_cb)(ui_view *view, void *user_data);
-/**
- * @brief The structure type containing the set of callback functions for handling view's lifecycle events.
- *
- * @since_tizen 3.0
- */
-typedef struct
-{
- ui_view_lifecycle_cb load;
- ui_view_lifecycle_cb unload;
- ui_view_lifecycle_cb pause;
- ui_view_lifecycle_cb resume;
- ui_view_lifecycle_cb activate;
- ui_view_lifecycle_cb deactivate;
- ui_view_lifecycle_cb destroy;
-} ui_view_lifecycle_cb_s;
-
-
/**
* @brief The Enumeration for view events.
*
* @since_tizen 3.0
*/
typedef enum {
- UI_VIEW_EVENT_ROTATE = 0,
+ UI_VIEW_EVENT_LOAD = 0,
+ UI_VIEW_EVENT_UNLOAD,
+ UI_VIEW_EVENT_PAUSE,
+ UI_VIEW_EVENT_RESUME,
+ UI_VIEW_EVENT_ACTIVATE,
+ UI_VIEW_EVENT_DEACTIVATE,
+ UI_VIEW_EVENT_DESTROY,
+
+ UI_VIEW_EVENT_LOAD_POST,
+ UI_VIEW_EVENT_UNLOAD_POST,
+ UI_VIEW_EVENT_PAUSE_POST,
+ UI_VIEW_EVENT_RESUME_POST,
+ UI_VIEW_EVENT_ACTIVATE_POST,
+ UI_VIEW_EVENT_DEACTIVATE_POST,
+ UI_VIEW_EVENT_DESTROY_POST,
+
+ UI_VIEW_EVENT_ROTATE,
UI_VIEW_EVENT_PORTRAIT,
UI_VIEW_EVENT_LANDSCAPE,
UI_VIEW_EVENT_BACK,
UI_VIEW_EVENT_MENU,
+
+ UI_VIEW_EVENT_ROTATE_POST,
+ UI_VIEW_EVENT_PORTRAIT_POST,
+ UI_VIEW_EVENT_LANDSCAPE_POST,
+ UI_VIEW_EVENT_BACK_POST,
+ UI_VIEW_EVENT_MENU_POST,
+
UI_VIEW_EVENT_LAST
} ui_view_event_type_e;
*/
EAPI bool ui_view_set_content(ui_view *view, Eo *content);
-/**
- * @brief Set callback functions for handling view's lifecycle events.
- *
- * @param view An ui_view instance.
- * @param lifecycle_cb The set of callback functions to handle application lifecycle events.
- * @param user_data The user data to be passed to the given @a lifecycle_callback functions.
- *
- * @return @c true if it succeeds, @c false otherwise.
- *
- * @since_tizen 3.0
- */
-EAPI bool ui_view_set_lifecycle_cb(ui_view *view, ui_view_lifecycle_cb_s *lifecycle_cb, void *user_data);
-
/**
* @brief Set callback functions for handling view events.
*
class ui_app_capi : public UiApp
{
public:
- ui_application_lifecycle_cb_s app_lifecycle_cb;
- void *user_data;
+
+ ui_application_event_cb event_cb[UI_APPLICATION_EVENT_LAST] = {nullptr, };
+ void *user_data[UI_APPLICATION_EVENT_LAST] = {nullptr, };
bool onCreate()
{
+ if (this->event_cb[UI_APPLICATION_EVENT_CREATE_PRE])
+ {
+ if (!this->event_cb[UI_APPLICATION_EVENT_CREATE_PRE](this->user_data[UI_APPLICATION_EVENT_CREATE_PRE], nullptr)) return true;
+ }
+
if (!UiApp::onCreate()) return false;
- if (this->app_lifecycle_cb.create)
+ if (this->event_cb[UI_APPLICATION_EVENT_CREATE])
{
- return this->app_lifecycle_cb.create(this->user_data);
+ return this->event_cb[UI_APPLICATION_EVENT_CREATE](this->user_data[UI_APPLICATION_EVENT_CREATE], nullptr);
}
return true;
void onTerminate()
{
+ if (this->event_cb[UI_APPLICATION_EVENT_TERMINATE_PRE])
+ {
+ if (!this->event_cb[UI_APPLICATION_EVENT_TERMINATE_PRE](this->user_data[UI_APPLICATION_EVENT_TERMINATE_PRE], nullptr)) return;
+ }
+
UiApp::onTerminate();
- if (this->app_lifecycle_cb.terminate)
+ if (this->event_cb[UI_APPLICATION_EVENT_TERMINATE])
{
- this->app_lifecycle_cb.terminate(this->user_data);
+ this->event_cb[UI_APPLICATION_EVENT_TERMINATE](this->user_data[UI_APPLICATION_EVENT_TERMINATE], nullptr);
}
}
void onPause()
{
+ if (this->event_cb[UI_APPLICATION_EVENT_PAUSE_PRE])
+ {
+ if (!this->event_cb[UI_APPLICATION_EVENT_PAUSE_PRE](this->user_data[UI_APPLICATION_EVENT_PAUSE_PRE], nullptr)) return;
+ }
+
UiApp::onPause();
- if (this->app_lifecycle_cb.pause)
+ if (this->event_cb[UI_APPLICATION_EVENT_PAUSE])
{
- this->app_lifecycle_cb.pause(this->user_data);
+ this->event_cb[UI_APPLICATION_EVENT_PAUSE](this->user_data[UI_APPLICATION_EVENT_PAUSE], nullptr);
}
-
}
void onResume()
{
+ if (this->event_cb[UI_APPLICATION_EVENT_RESUME_PRE])
+ {
+ if (!this->event_cb[UI_APPLICATION_EVENT_RESUME_PRE](this->user_data[UI_APPLICATION_EVENT_RESUME_PRE], nullptr)) return;
+ }
+
UiApp::onResume();
- if (this->app_lifecycle_cb.resume)
+ if (this->event_cb[UI_APPLICATION_EVENT_RESUME])
{
- this->app_lifecycle_cb.resume(this->user_data);
+ this->event_cb[UI_APPLICATION_EVENT_RESUME](this->user_data[UI_APPLICATION_EVENT_RESUME], nullptr);
}
}
void onControl(app_control_h app_control)
{
+ if (this->event_cb[UI_APPLICATION_EVENT_CONTROL_PRE])
+ {
+ if (!this->event_cb[UI_APPLICATION_EVENT_CONTROL_PRE](this->user_data[UI_APPLICATION_EVENT_CONTROL_PRE], static_cast<void*>(app_control))) return;
+ }
+
UiApp::onControl(app_control);
- if (this->app_lifecycle_cb.control)
+ if (this->event_cb[UI_APPLICATION_EVENT_CONTROL])
{
- this->app_lifecycle_cb.control(app_control, this->user_data);
+ this->event_cb[UI_APPLICATION_EVENT_CONTROL](this->user_data[UI_APPLICATION_EVENT_CONTROL], static_cast<void*>(app_control));
}
}
ui_app_capi(const char *pkg, const char *locale_dir)
- : UiApp(pkg, locale_dir), user_data(nullptr)
+ : UiApp(pkg, locale_dir)
{
}
{
}
- bool run(int argc, char **argv, ui_application_lifecycle_cb_s* app_lifecycle_cb, void* user_data)
+ bool set_event_cb(ui_application_event_type_e event_type, ui_application_event_cb event_cb, void *user_data)
{
- if (app_lifecycle_cb)
- {
- this->app_lifecycle_cb = *app_lifecycle_cb;
- }
- else
- {
- memset(&this->app_lifecycle_cb, 0x0, sizeof(this->app_lifecycle_cb));
- }
+ this->event_cb[event_type] = event_cb;
+ this->user_data[event_type] = user_data;
- this->user_data = user_data;
+ return true;
+ }
+ bool run(int argc, char **argv)
+ {
return UiApp::run(argc, argv);
}
};
return true;
}
-EAPI bool ui_application_run(int argc, char **argv, ui_application_lifecycle_cb_s* app_lifecycle_cb, void* user_data)
+EAPI bool ui_application_run(int argc, char **argv, ui_application_event_s *events, void *user_data)
{
ui_app_capi *app = g_app;
if (!app)
return false;
}
- return app->run(argc, argv, app_lifecycle_cb, user_data);
+ bool ret = true;
+
+ int i = 0;
+
+ while (true)
+ {
+ if (events[i].event_type == UI_APPLICATION_EVENT_LAST) break;
+
+ if (events[i].event_type < UI_APPLICATION_EVENT_CREATE)
+ {
+ LOGE("events[%d] is invalid(%d)", i, events[i].event_type);
+ ret = false;
+ }
+ else
+ {
+ app->set_event_cb(events[i].event_type, events[i].event_cb, user_data);
+ }
+
+ ++i;
+ }
+
+ if (!ret) return false;
+
+ return app->run(argc, argv);
}
EAPI bool ui_application_term(void)
public:
void onLoad()
{
- if (this->lifecycle_cb.load)
+ if (this->event_cb[UI_VIEW_EVENT_LOAD])
{
- if (!this->lifecycle_cb.load(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_LOAD](this, this->event_data[UI_VIEW_EVENT_LOAD])) return;
}
+
ui_standard_view::onLoad();
+
+ if (this->event_cb[UI_VIEW_EVENT_LOAD_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_LOAD_POST](this, this->event_data[UI_VIEW_EVENT_LOAD_POST])) return;
+ }
}
void onUnload()
{
- if (this->lifecycle_cb.unload)
+ if (this->event_cb[UI_VIEW_EVENT_UNLOAD])
{
- if (!this->lifecycle_cb.unload(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_UNLOAD](this, this->event_data[UI_VIEW_EVENT_UNLOAD])) return;
}
+
ui_standard_view::onUnload();
+
+ if (this->event_cb[UI_VIEW_EVENT_UNLOAD_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_UNLOAD_POST](this, this->event_data[UI_VIEW_EVENT_UNLOAD_POST])) return;
+ }
}
void onPause()
{
- if (this->lifecycle_cb.pause)
+ if (this->event_cb[UI_VIEW_EVENT_PAUSE])
{
- if (!this->lifecycle_cb.pause(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_PAUSE](this, this->event_data[UI_VIEW_EVENT_PAUSE])) return;
}
+
ui_standard_view::onPause();
+
+ if (this->event_cb[UI_VIEW_EVENT_PAUSE_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_PAUSE_POST](this, this->event_data[UI_VIEW_EVENT_PAUSE_POST])) return;
+ }
}
void onResume()
{
- if (this->lifecycle_cb.resume)
+ if (this->event_cb[UI_VIEW_EVENT_RESUME])
{
- if (!this->lifecycle_cb.resume(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_RESUME](this, this->event_data[UI_VIEW_EVENT_RESUME])) return;
}
+
ui_standard_view::onResume();
+
+ if (this->event_cb[UI_VIEW_EVENT_RESUME_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_RESUME_POST](this, this->event_data[UI_VIEW_EVENT_RESUME_POST])) return;
+ }
}
void onActivate()
{
- if (this->lifecycle_cb.activate)
+ if (this->event_cb[UI_VIEW_EVENT_ACTIVATE])
{
- if (!this->lifecycle_cb.activate(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_ACTIVATE](this, this->event_data[UI_VIEW_EVENT_ACTIVATE])) return;
}
+
ui_standard_view::onActivate();
+
+ if (this->event_cb[UI_VIEW_EVENT_ACTIVATE_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_ACTIVATE_POST](this, this->event_data[UI_VIEW_EVENT_ACTIVATE_POST])) return;
+ }
}
void onDeactivate()
{
- if (this->lifecycle_cb.deactivate)
+ if (this->event_cb[UI_VIEW_EVENT_DEACTIVATE])
{
- if (!this->lifecycle_cb.deactivate(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_DEACTIVATE](this, this->event_data[UI_VIEW_EVENT_DEACTIVATE])) return;
}
+
ui_standard_view::onDeactivate();
+
+ if (this->event_cb[UI_VIEW_EVENT_DEACTIVATE_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_DEACTIVATE_POST](this, this->event_data[UI_VIEW_EVENT_DEACTIVATE_POST])) return;
+ }
}
void onDestroy()
{
- if (this->lifecycle_cb.destroy)
+ if (this->event_cb[UI_VIEW_EVENT_DESTROY])
{
- if (!this->lifecycle_cb.destroy(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_DESTROY](this, this->event_data[UI_VIEW_EVENT_DESTROY])) return;
}
+
ui_standard_view::onDestroy();
+
+ if (this->event_cb[UI_VIEW_EVENT_DESTROY_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_DESTROY_POST](this, this->event_data[UI_VIEW_EVENT_DESTROY_POST])) return;
+ }
}
void onPortrait()
{
if (!(*this->event_cb[UI_VIEW_EVENT_PORTRAIT])(this, this->event_data[UI_VIEW_EVENT_PORTRAIT])) return;
}
+
ui_standard_view::onPortrait();
+
+ if (this->event_cb[UI_VIEW_EVENT_PORTRAIT_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_PORTRAIT_POST])(this, this->event_data[UI_VIEW_EVENT_PORTRAIT_POST])) return;
+ }
}
void onLandscape()
{
if (!(*this->event_cb[UI_VIEW_EVENT_LANDSCAPE])(this, this->event_data[UI_VIEW_EVENT_LANDSCAPE])) return;
}
+
ui_standard_view::onLandscape();
+
+ if (this->event_cb[UI_VIEW_EVENT_LANDSCAPE_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_LANDSCAPE_POST])(this, this->event_data[UI_VIEW_EVENT_LANDSCAPE_POST])) return;
+ }
}
void onRotate(int degree)
{
if (!(*this->event_cb[UI_VIEW_EVENT_ROTATE])(this, this->event_data[UI_VIEW_EVENT_ROTATE])) return;
}
+
ui_standard_view::onRotate(degree);
+
+ if (this->event_cb[UI_VIEW_EVENT_ROTATE_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_ROTATE_POST])(this, this->event_data[UI_VIEW_EVENT_ROTATE_POST])) return;
+ }
}
void onBack()
{
if (!(*this->event_cb[UI_VIEW_EVENT_BACK])(this, this->event_data[UI_VIEW_EVENT_BACK])) return;
}
+
ui_standard_view::onBack();
+
+ if (this->event_cb[UI_VIEW_EVENT_BACK_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_BACK_POST])(this, this->event_data[UI_VIEW_EVENT_BACK_POST])) return;
+ }
}
void onMenu(ui_menu *menu)
{
if (!(*this->event_cb[UI_VIEW_EVENT_MENU])(this, this->event_data[UI_VIEW_EVENT_MENU])) return;
}
+
ui_standard_view::onMenu(menu);
+
+ if (this->event_cb[UI_VIEW_EVENT_MENU_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_MENU_POST])(this, this->event_data[UI_VIEW_EVENT_MENU_POST])) return;
+ }
}
ui_standard_view_capi(const char *name)
public:
void onLoad()
{
- if (this->lifecycle_cb.load)
+ if (this->event_cb[UI_VIEW_EVENT_LOAD])
{
- if (!this->lifecycle_cb.load(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_LOAD](this, this->event_data[UI_VIEW_EVENT_LOAD])) return;
}
+
ui_view::onLoad();
+
+ if (this->event_cb[UI_VIEW_EVENT_LOAD_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_LOAD_POST](this, this->event_data[UI_VIEW_EVENT_LOAD_POST])) return;
+ }
}
void onUnload()
{
- if (this->lifecycle_cb.unload)
+ if (this->event_cb[UI_VIEW_EVENT_UNLOAD])
{
- if (!this->lifecycle_cb.unload(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_UNLOAD](this, this->event_data[UI_VIEW_EVENT_UNLOAD])) return;
}
+
ui_view::onUnload();
+
+ if (this->event_cb[UI_VIEW_EVENT_UNLOAD_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_UNLOAD_POST](this, this->event_data[UI_VIEW_EVENT_UNLOAD_POST])) return;
+ }
}
void onPause()
{
- if (this->lifecycle_cb.pause)
+ if (this->event_cb[UI_VIEW_EVENT_PAUSE])
{
- if (!this->lifecycle_cb.pause(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_PAUSE](this, this->event_data[UI_VIEW_EVENT_PAUSE])) return;
}
+
ui_view::onPause();
+
+ if (this->event_cb[UI_VIEW_EVENT_PAUSE_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_PAUSE_POST](this, this->event_data[UI_VIEW_EVENT_PAUSE_POST])) return;
+ }
}
void onResume()
{
- if (this->lifecycle_cb.resume)
+ if (this->event_cb[UI_VIEW_EVENT_RESUME])
{
- if (!this->lifecycle_cb.resume(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_RESUME](this, this->event_data[UI_VIEW_EVENT_RESUME])) return;
}
+
ui_view::onResume();
+
+ if (this->event_cb[UI_VIEW_EVENT_RESUME_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_RESUME_POST](this, this->event_data[UI_VIEW_EVENT_RESUME_POST])) return;
+ }
}
void onActivate()
{
- if (this->lifecycle_cb.activate)
+ if (this->event_cb[UI_VIEW_EVENT_ACTIVATE])
{
- if (!this->lifecycle_cb.activate(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_ACTIVATE](this, this->event_data[UI_VIEW_EVENT_ACTIVATE])) return;
}
+
ui_view::onActivate();
+
+ if (this->event_cb[UI_VIEW_EVENT_ACTIVATE_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_ACTIVATE_POST](this, this->event_data[UI_VIEW_EVENT_ACTIVATE_POST])) return;
+ }
}
void onDeactivate()
{
- if (this->lifecycle_cb.deactivate)
+ if (this->event_cb[UI_VIEW_EVENT_DEACTIVATE])
{
- if (!this->lifecycle_cb.deactivate(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_DEACTIVATE](this, this->event_data[UI_VIEW_EVENT_DEACTIVATE])) return;
}
+
ui_view::onDeactivate();
+
+ if (this->event_cb[UI_VIEW_EVENT_DEACTIVATE_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_DEACTIVATE_POST](this, this->event_data[UI_VIEW_EVENT_DEACTIVATE_POST])) return;
+ }
}
void onDestroy()
{
- if (this->lifecycle_cb.destroy)
+ if (this->event_cb[UI_VIEW_EVENT_DESTROY])
{
- if (!this->lifecycle_cb.destroy(this, this->lifecycle_data)) return;
+ if (!this->event_cb[UI_VIEW_EVENT_DESTROY](this, this->event_data[UI_VIEW_EVENT_DESTROY])) return;
}
+
ui_view::onDestroy();
+
+ if (this->event_cb[UI_VIEW_EVENT_DESTROY_POST])
+ {
+ if (!this->event_cb[UI_VIEW_EVENT_DESTROY_POST](this, this->event_data[UI_VIEW_EVENT_DESTROY_POST])) return;
+ }
}
void onPortrait()
{
if (!(*this->event_cb[UI_VIEW_EVENT_PORTRAIT])(this, this->event_data[UI_VIEW_EVENT_PORTRAIT])) return;
}
+
ui_view::onPortrait();
+
+ if (this->event_cb[UI_VIEW_EVENT_PORTRAIT_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_PORTRAIT_POST])(this, this->event_data[UI_VIEW_EVENT_PORTRAIT_POST])) return;
+ }
}
void onLandscape()
{
if (!(*this->event_cb[UI_VIEW_EVENT_LANDSCAPE])(this, this->event_data[UI_VIEW_EVENT_LANDSCAPE])) return;
}
+
ui_view::onLandscape();
+
+ if (this->event_cb[UI_VIEW_EVENT_LANDSCAPE_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_LANDSCAPE_POST])(this, this->event_data[UI_VIEW_EVENT_LANDSCAPE_POST])) return;
+ }
}
void onRotate(int degree)
{
if (!(*this->event_cb[UI_VIEW_EVENT_ROTATE])(this, this->event_data[UI_VIEW_EVENT_ROTATE])) return;
}
+
ui_view::onRotate(degree);
+
+ if (this->event_cb[UI_VIEW_EVENT_ROTATE_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_ROTATE_POST])(this, this->event_data[UI_VIEW_EVENT_ROTATE_POST])) return;
+ }
}
void onBack()
{
if (!(*this->event_cb[UI_VIEW_EVENT_BACK])(this, this->event_data[UI_VIEW_EVENT_BACK])) return;
}
+
ui_view::onBack();
+
+ if (this->event_cb[UI_VIEW_EVENT_BACK_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_BACK_POST])(this, this->event_data[UI_VIEW_EVENT_BACK_POST])) return;
+ }
}
void onMenu(ui_menu *menu)
{
if (!(*this->event_cb[UI_VIEW_EVENT_MENU])(this, this->event_data[UI_VIEW_EVENT_MENU])) return;
}
+
ui_view::onMenu(menu);
+
+ if (this->event_cb[UI_VIEW_EVENT_MENU_POST])
+ {
+ if (!(*this->event_cb[UI_VIEW_EVENT_MENU_POST])(this, this->event_data[UI_VIEW_EVENT_MENU_POST])) return;
+ }
}
ui_view_capi(const char *name)
return new ui_view_capi(name);
}
-EAPI bool ui_view_set_lifecycle_cb(ui_view *view, ui_view_lifecycle_cb_s *lifecycle_cb, void *user_data)
-{
- if (!validate_view(view)) return false;
-
- auto event_attr = dynamic_cast<ui_common_view_capi *>(view);
- if (!event_attr)
- {
- LOGE("This view(%p) doesn't allow lifecycle callback?!");
- return false;
- }
-
- if (lifecycle_cb)
- {
- event_attr->lifecycle_cb = *lifecycle_cb;
- }
- event_attr->lifecycle_data = user_data;
-
- return true;
-}
-
EAPI bool ui_view_set_event_cb(ui_view *view, ui_view_event_type_e event_type, ui_view_event_cb event_cb, void *user_data)
{
if (!validate_view(view)) return false;
- if (event_type < UI_VIEW_EVENT_ROTATE || event_type >= UI_VIEW_EVENT_LAST)
+
+ if (event_type < UI_VIEW_EVENT_LOAD || event_type >= UI_VIEW_EVENT_LAST)
{
LOGE("This view(%p) event_type is invalid(%d)", view, event_type);
return false;