From 8b51320499e30f93d1e711ff29a358d037e27fa0 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 26 Apr 2016 13:50:27 +0900 Subject: [PATCH] Introduce ui_app class. This class is designed for application framework abstractor. Change-Id: I5edfdd56f957d105b5234b04993c57656aec3ff2 --- src/examples/efl/main.cpp | 137 +++++------------ src/examples/efl/main.h | 5 - src/include/efl/mobile/ui_app.h | 54 +++++++ src/include/efl/mobile/ui_viewmanager.h | 2 + src/include/efl/mobile/ui_viewmgr.h | 1 - src/lib/CMakeLists.txt | 1 + src/lib/efl/mobile/ui_app.cpp | 189 ++++++++++++++++++++++++ 7 files changed, 279 insertions(+), 110 deletions(-) create mode 100644 src/include/efl/mobile/ui_app.h create mode 100644 src/lib/efl/mobile/ui_app.cpp diff --git a/src/examples/efl/main.cpp b/src/examples/efl/main.cpp index ffeb835..157f739 100644 --- a/src/examples/efl/main.cpp +++ b/src/examples/efl/main.cpp @@ -32,6 +32,37 @@ #include "page2.h" #include "page1.h" +class sample_app : public ui_app +{ +public: + sample_app(const char*pkg, const char *locale_dir); + ~sample_app(); + + bool on_create(); +}; + +sample_app::sample_app(const char *pkg, const char *locale_dir) + : ui_app(pkg, locale_dir) +{ +} + +sample_app::~sample_app() +{ +} + +bool sample_app::on_create() +{ + if (!ui_app::on_create()) + { + return false; + } + + create_page1(); + + return true; +} + + Elm_Toolbar* create_toolbar(Evas_Object *parent, const char *style) { @@ -295,110 +326,8 @@ create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_cli return scroller; } -static void create_base_gui(void) -{ - create_page1(); - UI_VIEWMGR->activate(); -} - -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 */ - - elm_app_base_scale_set(2.6); - - /* Bind package locale file */ - bindtextdomain(PACKAGE, LOCALE_DIR); - textdomain(PACKAGE); - - //FIXME: Hide this creation. - ui_viewmgr *viewmgr = new ui_viewmgr(PACKAGE); - - create_base_gui(); - - return true; -} - -static void app_control(app_control_h app_control, void *data) -{ - /* Handle the launch request. */ -} - -static void app_pause(void *data) -{ -} - -static void app_resume(void *data) -{ - UI_VIEWMGR->activate(); -} - -static void app_terminate(void *data) -{ -} - -static void ui_app_lang_changed(app_event_info_h event_info, void *user_data) -{ - /*APP_EVENT_LANGUAGE_CHANGED*/ - char *locale = NULL; - system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); - elm_language_set(locale); - free(locale); - return; -} - -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; - 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); - ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]); - - 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; + sample_app app(PACKAGE, LOCALE_DIR); + return app.start(argc, argv); } diff --git a/src/examples/efl/main.h b/src/examples/efl/main.h index 6364456..8b8b45c 100644 --- a/src/examples/efl/main.h +++ b/src/examples/efl/main.h @@ -14,8 +14,6 @@ * limitations under the License. * */ -#include -#include #include #include "ui_viewmanager.h" @@ -35,9 +33,6 @@ using namespace efl_viewmgr; -typedef struct appdata { -} appdata_s; - Evas_Object *create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb); Evas_Object *create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb); Evas_Object *create_scrolling_content(Evas_Object *parent); diff --git a/src/include/efl/mobile/ui_app.h b/src/include/efl/mobile/ui_app.h new file mode 100644 index 0000000..f81dc89 --- /dev/null +++ b/src/include/efl/mobile/ui_app.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef UI_APP_H +#define UI_APP_H + +#include "../ui_base_viewmanager.h" + +namespace efl_viewmgr +{ + +class ui_viewmgr; + +class ui_app +{ +private: + ui_viewmgr *viewmgr; + Eina_Stringshare *pkg; + Eina_Stringshare *locale_dir; + +public: + ui_app(const char *pkg, const char *locale_dir); + virtual ~ui_app(); + + virtual int start(int argc, char **argv); + virtual bool on_create(); + virtual void on_terminate(); + virtual void on_pause(); + virtual void on_resume(); + virtual void on_control(app_control_h app_control); + + virtual void on_low_battery(app_event_info_h event_info); + virtual void on_low_memory(app_event_info_h event_info); + virtual void on_region_changed(app_event_info_h event_info); + virtual void on_orient_changed(app_event_info_h event_info); + virtual void on_lang_changed(app_event_info_h event_info); +}; + +} + +#endif /* UI_APP_H */ diff --git a/src/include/efl/mobile/ui_viewmanager.h b/src/include/efl/mobile/ui_viewmanager.h index bebbadc..5a692a7 100644 --- a/src/include/efl/mobile/ui_viewmanager.h +++ b/src/include/efl/mobile/ui_viewmanager.h @@ -15,6 +15,7 @@ * */ #include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -26,5 +27,6 @@ #include "ui_viewmgr.h" #include "ui_menu.h" #include "ui_popup.h" +#include "ui_app.h" #define UI_VIEWMGR dynamic_cast(efl_viewmgr::ui_base_viewmgr::get_instance()) diff --git a/src/include/efl/mobile/ui_viewmgr.h b/src/include/efl/mobile/ui_viewmgr.h index 41e04d4..e5f0dc4 100644 --- a/src/include/efl/mobile/ui_viewmgr.h +++ b/src/include/efl/mobile/ui_viewmgr.h @@ -24,7 +24,6 @@ namespace efl_viewmgr { class ui_view; -class ui_viewmgr; class ui_viewmgr: public ui_base_viewmgr { diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index c860c72..e52e293 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -3,6 +3,7 @@ SET(SRCS efl/ui_base_viewmgr.cpp efl/ui_base_key_listener.cpp efl/ui_base_overlay.cpp + efl/mobile/ui_app.cpp efl/mobile/ui_menu.cpp efl/mobile/ui_popup.cpp efl/mobile/ui_view.cpp diff --git a/src/lib/efl/mobile/ui_app.cpp b/src/lib/efl/mobile/ui_app.cpp new file mode 100644 index 0000000..f83b867 --- /dev/null +++ b/src/lib/efl/mobile/ui_app.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "../../../include/efl/mobile/ui_viewmanager.h" + +using namespace efl_viewmgr; +using namespace viewmgr; + +static bool app_create(void *data) +{ + ui_app *app = static_cast(data); + return app->on_create(); +} + +static void app_terminate(void *data) +{ + ui_app *app = static_cast(data); + app->on_terminate(); +} + +static void app_pause(void *data) +{ + ui_app *app = static_cast(data); + app->on_pause(); +} + +static void app_resume(void *data) +{ + ui_app *app = static_cast(data); + app->on_resume(); +} + +static void app_control(app_control_s *app_control, void *data) +{ + ui_app *app = static_cast(data); + app->on_control(app_control); +} + +static void ui_app_lang_changed(app_event_info_h event_info, void *data) +{ + ui_app *app = static_cast(data); + app->on_lang_changed(event_info); +} + +static void ui_app_orient_changed(app_event_info_h event_info, void *data) +{ + ui_app *app = static_cast(data); + app->on_orient_changed(event_info); +} + +static void ui_app_region_changed(app_event_info_h event_info, void *data) +{ + ui_app *app = static_cast(data); + app->on_region_changed(event_info); +} + +static void ui_app_low_battery(app_event_info_h event_info, void *data) +{ + ui_app *app = static_cast(data); + app->on_low_battery(event_info); +} + +static void ui_app_low_memory(app_event_info_h event_info, void *data) +{ + ui_app *app = static_cast(data); + app->on_low_memory(event_info); +} + +void ui_app::on_lang_changed(app_event_info_h event_info) +{ + char *locale = NULL; + system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); + elm_language_set(locale); + free(locale); +} + +void ui_app::on_low_memory(app_event_info_h event_info) +{ + +} + +void ui_app::on_low_battery(app_event_info_h event_info) +{ + +} + +void ui_app::on_region_changed(app_event_info_h event_info) +{ + +} + +void ui_app::on_orient_changed(app_event_info_h event_info) +{ + +} + +bool ui_app::on_create() +{ + LOGE("create!!"); + + //FIXME: this scale value should be configurable. + elm_app_base_scale_set(2.6); + + /* Bind package locale file */ + bindtextdomain(this->pkg, this->locale_dir); + textdomain(this->pkg); + + /* Default View Manager */ + this->viewmgr = new ui_viewmgr(this->pkg); + + if (!this->viewmgr) + { + LOGE("Failed to create a viewmgr(%s)", this->pkg); + return false; + } + return true; +} + +void ui_app::on_pause() +{ + this->viewmgr->deactivate(); +} + +void ui_app::on_resume() +{ +} + +void ui_app::on_control(app_control_h app_control) +{ + /* Handle the launch request. */ + this->viewmgr->activate(); +} + +void ui_app::on_terminate() +{ +} + +ui_app::ui_app(const char *pkg, const char *locale_dir) + : viewmgr(NULL) +{ + pkg = eina_stringshare_add(pkg); + locale_dir = eina_stringshare_add(locale_dir); +} + +int ui_app::start(int argc, char **argv) +{ + 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, this); + ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, this); + ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, this); + ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, this); + ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, this); + + int ret = ui_app_main(argc, argv, &event_callback, this); + + if (ret != APP_ERROR_NONE) + { + LOGE("ui_app_main() is failed. err = %d", ret); + } + + return ret; +} + +ui_app::~ui_app() +{ + eina_stringshare_del(this->pkg); + delete (this->viewmgr); +} -- 2.34.1