Add rotated method in controller. 52/63052/10
authorWoochan Lee <wc0917.lee@samsung.com>
Tue, 22 Mar 2016 02:41:59 +0000 (11:41 +0900)
committerWoochan Lee <wc0917.lee@samsung.com>
Tue, 22 Mar 2016 11:51:36 +0000 (20:51 +0900)
Change-Id: Id136fc79a8a15b086f3dbff41f8fa861b7e375c6

src/examples/efl/page1.h
src/include/efl/ui_controller.h
src/include/efl/ui_view.h
src/include/interface/ui_iface_controller.h
src/lib/efl/ui_view.cpp
src/lib/efl/ui_viewmgr.cpp

index 0df130508f794fb9a254ded29c4745003b912cd0..e8b15b5ff6ff29e4af9a55aed6e3a491bed1fe3f 100644 (file)
@@ -45,6 +45,9 @@ public:
 
                ui_basic_view *view = dynamic_cast<ui_basic_view *>(this->get_view());
 
+               //Check the current rotation for set portrait or landscape content if any.
+               LOGE("view 1 load rotation = %d\n", view->get_degree());
+
                //Create a main content.
                Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 1",
                                //Prev Button Callback
@@ -83,6 +86,21 @@ public:
 
                return true;
        }
+
+       void rotate(int degree)
+       {
+               LOGE("Current view's degree is %d\n", degree);
+       }
+
+       void portrait()
+       {
+               LOGE("View is on portrait mode\n");
+       }
+
+       void landscape()
+       {
+               LOGE("View is on landscape mode\n");
+       }
 };
 
 void create_page1(appdata_s *ad)
index 2828c2e22444ca91d7c82bae14076b330d406e28..dcab8e56f7c22ef8ebae72afb0d3726aaa4ac4af 100644 (file)
@@ -103,7 +103,33 @@ public:
         */
        virtual void destroy() {}
 
+       /** @brief Back key callback.
+        *
+        *  @note In default. current view will be popped by viewmgr in those scenarios
+        *        that viewmgr is requested to poo the current view.
+        *        If you return false in the overriding, then popping will be stopped.
+        */
        virtual bool back() { return true; }
+
+       /** @brief View rotate callback.
+        *
+        *  @param degree Current rotation degree.
+        *
+        *  @note This method will be called when view rotation occurred.
+        */
+       virtual void rotate(int degree) {}
+
+       /** @brief Portrait callback.
+        *
+        *  @note When current view is on portrait mode.
+        */
+       virtual void portrait() {}
+
+       /** @brief Landscape callback.
+        *
+        *  @note When current view is on landscape mode.
+        */
+       virtual void landscape() {}
 };
 }
 
index 5ff67ae8fba34b1df6ccae1d4a277090cd2cf852..66a7425fbed4457055cbb82c546d1c044d447d9e 100644 (file)
@@ -43,6 +43,29 @@ class ui_view: public viewmgr::ui_iface_view
 {
        friend class ui_viewmgr;
 
+protected:
+       /** @brief Unload current view's content
+        *
+        *  @note Make this view's content as NULL, then destroy content.
+        */
+       virtual void unload_content();
+
+       /** @brief Get a parent object of view.
+        *
+        *  @note This is calling viewmgr get_base() method internally.
+        *
+        *  @return base layout of viewmgr.
+        */
+       Evas_Object *get_parent();
+
+       /** @brief toggle event block.
+        *
+        *  @note It makes internal conformant event freeze during effect showing.
+        *
+        *  @param block @c true, when blocking is enabled, otherwise @c false.
+        */
+       virtual void set_event_block(bool block);
+
 public:
        ///Constructor.
        ui_view(ui_controller *controller, const char *name = NULL);
@@ -64,36 +87,32 @@ public:
         */
        virtual Evas_Object *get_base();
 
+       /** @brief This is for calling controller's back method.
+        */
        virtual void back();
 
-       /** @brief Set the indicator mode.
-        *
-        *  @param indicator The mode to set, one of #ui_view_indicator.
+       /** @brief This is for calling controller's rotate method.
         */
-       void set_indicator(ui_view_indicator indicator);
+       virtual void rotate(int degree);
 
-protected:
-       /** @brief Unload current view's content
-        *
-        *  @note Make this view's content as NULL, then destroy content.
+       /** @brief This is for calling controller's portrait method.
         */
-       virtual void unload_content();
+       virtual void portrait();
 
-       /** @brief Get a parent object of view.
-        *
-        *  @note This is calling viewmgr get_base() method internally.
+       /** @brief This is for calling controller's landscape method.
+        */
+       virtual void landscape();
+       /** @brief Set the indicator mode.
         *
-        *  @return base layout of viewmgr.
+        *  @param indicator The mode to set, one of #ui_view_indicator.
         */
-       Evas_Object *get_parent();
+       void set_indicator(ui_view_indicator indicator);
 
-       /** @brief toggle event block.
-        *
-        *  @note It makes internal conformant event freeze during effect showing.
+       /** @brief Get current view's degree.
         *
-        *  @param block @c true, when blocking is enabled, otherwise @c false.
+        *  @return Current rotation degree, -1 if failed to get viewmgr degree.
         */
-       virtual void set_event_block(bool block);
+       int get_degree();
 };
 
 }
index 72b7d5994785ea4db77547cf38e865c4fdd25257..e854c012f667d62104c23d1fd183ff4baf489963 100644 (file)
@@ -120,6 +120,34 @@ public:
         *  @note When this view is on destroying by popping or deleting.
         */
        virtual void destroy() = 0;
+
+       /** @brief Back key callback.
+        *
+        *  @note In default. current view will be popped by viewmgr in those scenarios
+        *        that viewmgr is requested to poo the current view.
+        *        If you return false in the overriding, then popping will be stopped.
+        */
+       virtual bool back() = 0;
+
+       /** @brief View rotate callback.
+        *
+        *  @param degree Current rotation degree.
+        *
+        *  @note This method will be called when view rotation occurred.
+        */
+       virtual void rotate(int degree) = 0;
+
+       /** @brief Portrait callback.
+        *
+        *  @note When current view is on portrait mode.
+        */
+       virtual void portrait() = 0;
+
+       /** @brief Landscape callback.
+        *
+        *  @note When current view is on landscape mode.
+        */
+       virtual void landscape() = 0;
 };
 
 }
index bbc5da39c26a06459521c9cfda2ff7ae4e26322a..b5479250336eed069b3a8d77f1e3c3ff4e84fecd 100644 (file)
@@ -93,8 +93,42 @@ void ui_view::back()
        dynamic_cast<ui_viewmgr *>(this->get_viewmgr())->pop_view();
 }
 
+void ui_view::rotate(int degree)
+{
+       if (this->get_controller())
+       {
+               dynamic_cast<ui_controller *>(this->get_controller())->rotate(degree);
+       }
+}
+
+void ui_view::portrait()
+{
+       if (this->get_controller())
+       {
+               dynamic_cast<ui_controller *>(this->get_controller())->portrait();
+       }
+}
+
+void ui_view::landscape()
+{
+       if (this->get_controller())
+       {
+               dynamic_cast<ui_controller *>(this->get_controller())->landscape();
+       }
+}
 void ui_view::set_event_block(bool block)
 {
        ui_iface_view::set_event_block(block);
        evas_object_freeze_events_set(CONVERT_TO_EO(this->get_content()), block);
 }
+
+int ui_view::get_degree()
+{
+       ui_viewmgr *viewmgr = dynamic_cast<ui_viewmgr *>(ui_iface_view::get_viewmgr());
+       if (!viewmgr)
+       {
+               LOGE("Failed to get a viewmgr");
+               return -1;
+       }
+       return elm_win_rotation_get(viewmgr->get_window());
+}
index bfa12b39146a6c7fafac9fef2afd6dfc56200d92..fe954f9e3669de8a370f985e87068af853d79f10 100644 (file)
@@ -188,6 +188,7 @@ ui_viewmgr::ui_viewmgr(const char *pkg, ui_key_listener *key_listener)
                return;
        }
 
+       //FIXME: Make a method? to set available rotation degree.
        //Set window rotation
        if (elm_win_wm_rotation_supported_get(this->win))
        {
@@ -195,6 +196,20 @@ ui_viewmgr::ui_viewmgr(const char *pkg, ui_key_listener *key_listener)
                { 0, 90, 180, 270 };
                elm_win_wm_rotation_available_rotations_set(this->win, (const int *) (&rots), 4);
        }
+       evas_object_smart_callback_add(this->win, "wm,rotation,changed",
+                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                       {
+                               int rot = elm_win_rotation_get(obj);
+
+                               ui_viewmgr *viewmgr = static_cast<ui_viewmgr *>(data);
+                               ui_view *view = viewmgr->get_last_view();
+                               view->rotate(rot);
+
+                               //FIXME: Change this configurable?
+                               if (rot == 0 || rot == 180) view->portrait();
+                               else view->landscape();
+                       }
+                       , this);
 
        //Window is requested to delete.
        evas_object_smart_callback_add(this->win, "delete,request",