Introduce ui_app class. 46/67246/3
authorHermet Park <hermet@hermet.pe.kr>
Tue, 26 Apr 2016 04:50:27 +0000 (13:50 +0900)
committerHermet Park <hermet@hermet.pe.kr>
Tue, 26 Apr 2016 10:39:08 +0000 (19:39 +0900)
This class is designed for application framework abstractor.

Change-Id: I5edfdd56f957d105b5234b04993c57656aec3ff2

src/examples/efl/main.cpp
src/examples/efl/main.h
src/include/efl/mobile/ui_app.h [new file with mode: 0644]
src/include/efl/mobile/ui_viewmanager.h
src/include/efl/mobile/ui_viewmgr.h
src/lib/CMakeLists.txt
src/lib/efl/mobile/ui_app.cpp [new file with mode: 0644]

index ffeb83599ca9eee1bf14bcb1ad45865af29687be..157f7391cbc994f83458bd08804ceba67c7b0926 100644 (file)
 #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);
 }
index 6364456ff3820efe441d42483a3cc33deb148981..8b8b45cfc766254d7eee32115b17dd0d9544a16d 100644 (file)
@@ -14,8 +14,6 @@
  *  limitations under the License.
  *
  */
-#include <app.h>
-#include <system_settings.h>
 #include <dlog.h>
 #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 (file)
index 0000000..f81dc89
--- /dev/null
@@ -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 */
index bebbadc23fc543a5a5bbbfd6889a557a31946c35..5a692a71961b3f1a0cd56b221af02a35669b1733 100644 (file)
@@ -15,6 +15,7 @@
  *
  */
 #include <dlog.h>
+#include <system_settings.h>
 
 #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<ui_viewmgr *>(efl_viewmgr::ui_base_viewmgr::get_instance())
index 41e04d4beb924765b9b2ec487eb84868a2e78daf..e5f0dc4654e18718aca4a7a0d1dda7bf74e5d3ef 100644 (file)
@@ -24,7 +24,6 @@ namespace efl_viewmgr
 {
 
 class ui_view;
-class ui_viewmgr;
 
 class ui_viewmgr: public ui_base_viewmgr
 {
index c860c72bf62fd0bbbacdf952c91122f0dfae6e88..e52e293797af3b0f8d2de2b6bb1a70a491dbaf51 100644 (file)
@@ -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 (file)
index 0000000..f83b867
--- /dev/null
@@ -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<ui_app *>(data);
+       return app->on_create();
+}
+
+static void app_terminate(void *data)
+{
+       ui_app *app = static_cast<ui_app *>(data);
+       app->on_terminate();
+}
+
+static void app_pause(void *data)
+{
+       ui_app *app = static_cast<ui_app *>(data);
+       app->on_pause();
+}
+
+static void app_resume(void *data)
+{
+       ui_app *app = static_cast<ui_app *>(data);
+       app->on_resume();
+}
+
+static void app_control(app_control_s *app_control, void *data)
+{
+       ui_app *app = static_cast<ui_app *>(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<ui_app *>(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<ui_app *>(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<ui_app *>(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<ui_app *>(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<ui_app *>(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);
+}