TizenRefApp-6941 Perform necessary optimizations to improve application launch time 20/83920/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 15 Aug 2016 11:15:11 +0000 (14:15 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Wed, 17 Aug 2016 06:49:15 +0000 (23:49 -0700)
[Implementation] Implemented possibility to delay onCreated() callback.
Delayed initialization of invisible tabs to improve launch time.

Change-Id: I7fad05d8b3029304c1b5a63b591a7064d5d47a2c
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
contacts-app/src/OperationDefaultController.cpp
lib-apps-common/inc/Ui/Control.h
lib-apps-common/src/Ui/Control.cpp
lib-apps-common/src/Ui/View.cpp
lib-contacts/inc/Contacts/List/ListView.h
lib-contacts/src/Contacts/List/ListView.cpp
lib-logs/src/Logs/List/LogsView.cpp
lib-phone/inc/Phone/Dialer/DialerView.h
lib-phone/src/Phone/Dialer/DialerView.cpp

index 07bd25d..e052df2 100644 (file)
@@ -32,6 +32,8 @@
 #define PREFERENCE_KEY_LAST_TAB     "last_tab"
 #define PREFERENCE_KEY_LOGS_FILTER  "logs_filter"
 
+#define TAB_CREATE_DELAY 1.0
+
 using Contacts::List::ListView;
 using Logs::List::LogsView;
 using Phone::Dialer::DialerView;
@@ -58,6 +60,7 @@ void OperationDefaultController::onCreate()
        m_Tabs[TabContacts] = new ListView();
 
        for (auto &&tab : m_Tabs) {
+               tab->setCreateTimer(TAB_CREATE_DELAY);
                m_Navigator->addView(tab);
        }
 }
index eded21d..863a77d 100644 (file)
@@ -58,6 +58,18 @@ namespace Ui
                Evas_Object *create(Evas_Object *parent);
 
                /**
+                * @brief Set delay between onCreate() and onCreated().
+                * @param[in]   time    Delay time
+                */
+               void setCreateTimer(double time);
+
+               /**
+                * @brief Remove delay between onCreate() and onCreated().
+                * @remark If timer is currently running onCreated() will be called immediately.
+                */
+               void resetCreateTimer();
+
+               /**
                 * @return Control type.
                 */
                int getType() const;
@@ -115,6 +127,7 @@ namespace Ui
 
                int m_Type;
                Evas_Object *m_Object;
+               Ecore_Timer *m_CreateTimer;
        };
 
        template <typename ControlType>
index d2d6bac..9c1974e 100644 (file)
 using namespace Ui;
 
 Control::Control(int type)
-       : m_Type(type), m_Object(nullptr)
+       : m_Type(type), m_Object(nullptr), m_CreateTimer(nullptr)
 {
 }
 
 Control::~Control()
 {
+       if (m_CreateTimer) {
+               ecore_timer_del(m_CreateTimer);
+       }
+
        destroyEvasObject();
 }
 
@@ -36,12 +40,43 @@ Evas_Object *Control::create(Evas_Object *parent)
 {
        if (!m_Object) {
                setEvasObject(onCreate(parent));
-               onCreated();
+               if (!m_CreateTimer) {
+                       onCreated();
+               } else {
+                       ecore_timer_thaw(m_CreateTimer);
+               }
        }
 
        return m_Object;
 }
 
+void Control::setCreateTimer(double time)
+{
+       if (m_CreateTimer) {
+               ecore_timer_del(m_CreateTimer);
+       }
+
+       m_CreateTimer = ecore_timer_add(time, [](void *data) {
+               Control *control = (Control *) data;
+               control->m_CreateTimer = nullptr;
+               control->onCreated();
+               return EINA_FALSE;
+       }, this);
+       ecore_timer_freeze(m_CreateTimer);
+}
+
+void Control::resetCreateTimer()
+{
+       if (m_CreateTimer) {
+               ecore_timer_del(m_CreateTimer);
+               m_CreateTimer = nullptr;
+
+               if (m_Object) {
+                       onCreated();
+               }
+       }
+}
+
 int Control::getType() const
 {
        return m_Type;
index cd12fdb..6c18e12 100644 (file)
@@ -72,6 +72,7 @@ void View::onNavigation(bool isCurrent, int degree)
 {
        m_IsCurrent = isCurrent;
        if (m_IsCurrent) {
+               resetCreateTimer();
                onRotation(degree);
        }
 
index 818646d..2bae303 100644 (file)
@@ -141,6 +141,7 @@ namespace Contacts
                        Ui::GenGroupItem *createListSection(SectionId sectionId);
                        void fillPersonList();
 
+                       void fillLayout();
                        Ui::Genlist *createGenlist(Evas_Object *parent);
                        Evas_Object *createEmptyLayout(Evas_Object *parent);
                        void updateEmptyLayout();
index 850aabd..de9dc00 100644 (file)
@@ -124,25 +124,12 @@ bool ListView::isListEmpty()
 
 Evas_Object *ListView::onCreate(Evas_Object *parent)
 {
-       Evas_Object *layout = elm_layout_add(parent);
-       elm_layout_theme_set(layout, "layout", "application", "fastscroll");
-
-       m_Box = elm_box_add(layout);
-       m_NoContent = createEmptyLayout(m_Box);
-       m_Genlist = createGenlist(m_Box);
-       elm_box_pack_end(m_Box, m_Genlist->getEvasObject());
-
-       elm_object_part_content_set(layout, "elm.swallow.content", m_Box);
-       elm_object_part_content_set(layout, "elm.swallow.fastscroll", createIndex(layout));
-
-       m_SearchItem = createSearchItem();
-       m_AddButton = createAddButton(layout);
-
-       return layout;
+       return elm_layout_add(parent);
 }
 
 void ListView::onCreated()
 {
+       fillLayout();
        fillPersonList();
        updateSections();
        updateEmptyState();
@@ -392,14 +379,33 @@ void ListView::fillPersonList()
        }
 }
 
+void ListView::fillLayout()
+{
+       Evas_Object *layout = getEvasObject();
+       elm_layout_theme_set(layout, "layout", "application", "fastscroll");
+
+       m_Index = createIndex(layout);
+       elm_object_part_content_set(layout, "elm.swallow.fastscroll", m_Index);
+
+       m_Box = elm_box_add(layout);
+       elm_object_part_content_set(layout, "elm.swallow.content", m_Box);
+
+       m_NoContent = createEmptyLayout(m_Box);
+       m_Genlist = createGenlist(m_Box);
+       elm_box_pack_end(m_Box, m_Genlist->getEvasObject());
+
+       m_SearchItem = createSearchItem();
+       m_AddButton = createAddButton(layout);
+}
+
 Ui::Genlist *ListView::createGenlist(Evas_Object *parent)
 {
        Ui::Genlist *genlist = new Ui::Genlist();
-       genlist->create(parent);
+       Evas_Object *obj = genlist->create(parent);
 
-       evas_object_size_hint_weight_set(genlist->getEvasObject(), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       evas_object_size_hint_align_set(genlist->getEvasObject(), EVAS_HINT_FILL, EVAS_HINT_FILL);
-       evas_object_show(genlist->getEvasObject());
+       evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
+       evas_object_show(obj);
 
        return genlist;
 }
@@ -623,16 +629,16 @@ void ListView::updateAddButton()
 
 Evas_Object *ListView::createIndex(Evas_Object *parent)
 {
-       m_Index = elm_index_add(parent);
-       elm_index_autohide_disabled_set(m_Index, EINA_TRUE);
-       elm_index_omit_enabled_set(m_Index, EINA_TRUE);
+       Evas_Object *index = elm_index_add(parent);
+       elm_index_autohide_disabled_set(index, EINA_TRUE);
+       elm_index_omit_enabled_set(index, EINA_TRUE);
 
-       evas_object_smart_callback_add(m_Index, "changed",
+       evas_object_smart_callback_add(index, "changed",
                        (Evas_Smart_Cb) makeCallback(&ListView::onIndexChanged), this);
-       evas_object_smart_callback_add(m_Index, "selected",
+       evas_object_smart_callback_add(index, "selected",
                        (Evas_Smart_Cb) makeCallback(&ListView::onIndexSelected), this);
 
-       return m_Index;
+       return index;
 }
 
 void ListView::updateIndex()
index 4cf653c..f7a8e17 100644 (file)
@@ -83,7 +83,6 @@ Evas_Object *LogsView::onCreate(Evas_Object *parent)
 void LogsView::onCreated()
 {
        m_LogProvider.setInsertCallback(std::bind(&LogsView::onLogInserted, this, _1));
-
        fillLayout();
 }
 
index 03d0c0e..348b3af 100644 (file)
@@ -57,6 +57,7 @@ namespace Phone
                        virtual void onNavigation(bool isCurrentView) override;
                        virtual void onMenuPressed() override;
 
+                       void fillLayout();
                        Evas_Object *createEntry(Evas_Object *parent);
                        Evas_Object *createSearchControl(Evas_Object *parent);
                        Evas_Object *createKeypad(Evas_Object *parent);
index 46594d8..ab39c52 100644 (file)
@@ -71,23 +71,13 @@ void DialerView::onCreated()
                        makeCallbackWithLastParam(&DialerView::onDbChanged), this);
        contacts_db_add_changed_cb(_contacts_phone_log._uri,
                        makeCallbackWithLastParam(&DialerView::onDbChanged), this);
+
+       fillLayout();
 }
 
 Evas_Object *DialerView::onCreate(Evas_Object *parent)
 {
-       elm_theme_extension_add(nullptr, App::getResourcePath(APPS_COMMON_BUTTONS_EDJ).c_str());
-
-       Evas_Object *layout = elm_layout_add(parent);
-       Eina_Bool res = elm_layout_file_set(layout, layoutFilePath.c_str(), GROUP_DIALER);
-       WARN_IF(res != EINA_TRUE, "elm_layout_file_set() failed");
-
-       elm_object_part_content_set(layout, PART_SWALLOW_ENTRY, createEntry(layout));
-       elm_object_part_content_set(layout, PART_SWALLOW_PREDICTIVE, createSearchControl(layout));
-       elm_object_part_content_set(layout, PART_SWALLOW_KEYPAD, createKeypad(layout));
-       elm_object_part_content_set(layout, PART_SWALLOW_CALL, createCallButton(layout));
-       elm_object_part_content_set(layout, PART_SWALLOW_BACKSPACE, createBackspaceButton(layout));
-
-       return layout;
+       return elm_layout_add(parent);
 }
 
 void DialerView::setNumber(const std::string &number)
@@ -146,6 +136,19 @@ void DialerView::onMenuPressed()
        menu->show();
 }
 
+void DialerView::fillLayout()
+{
+       Evas_Object *layout = getEvasObject();
+       Eina_Bool res = elm_layout_file_set(layout, layoutFilePath.c_str(), GROUP_DIALER);
+       WARN_IF(res != EINA_TRUE, "elm_layout_file_set() failed");
+
+       elm_object_part_content_set(layout, PART_SWALLOW_ENTRY, createEntry(layout));
+       elm_object_part_content_set(layout, PART_SWALLOW_PREDICTIVE, createSearchControl(layout));
+       elm_object_part_content_set(layout, PART_SWALLOW_KEYPAD, createKeypad(layout));
+       elm_object_part_content_set(layout, PART_SWALLOW_CALL, createCallButton(layout));
+       elm_object_part_content_set(layout, PART_SWALLOW_BACKSPACE, createBackspaceButton(layout));
+}
+
 Evas_Object *DialerView::createEntry(Evas_Object *parent)
 {
        m_Entry = new KeypadEntry();
@@ -185,6 +188,8 @@ Evas_Object *DialerView::createKeypad(Evas_Object *parent)
 
 Evas_Object *DialerView::createCallButton(Evas_Object *parent)
 {
+       elm_theme_extension_add(nullptr, App::getResourcePath(APPS_COMMON_BUTTONS_EDJ).c_str());
+
        Evas_Object *button = elm_button_add(parent);
        elm_object_style_set(button, BUTTON_STYLE_CUSTOM_CIRCLE);
        evas_object_smart_callback_add(button, "clicked",