Add View rotation sample. 41/63541/4
authorWoochan Lee <wc0917.lee@samsung.com>
Thu, 24 Mar 2016 11:33:37 +0000 (20:33 +0900)
committerWoochan Lee <wc0917.lee@samsung.com>
Fri, 25 Mar 2016 08:07:18 +0000 (17:07 +0900)
page10 : using on_portrait, on_landscape
page11 : using on_rotate

Change-Id: I46734cd6bd2fc9181cfa056df96272ae665e3678

CMakeLists.txt
data/images/tizen.png [new file with mode: 0644]
packaging/ui-viewmgr.spec
src/examples/efl/main.cpp
src/examples/efl/main.h
src/examples/efl/page10.h [new file with mode: 0644]
src/examples/efl/page11.h [new file with mode: 0644]
src/examples/efl/page9.h

index 561834af98dbfe50497c78466a97d9730de08eda..23e79ee5d3023cfcd16091e97689e3edfc72a514 100644 (file)
@@ -6,6 +6,7 @@ SET(EXEC_DIR ${PREFIX})
 SET(BINDIR ${PREFIX}/bin)
 SET(LIBDIR ${PREFIX}/lib)
 SET(INCDIR ${PREFIX}/include)
+SET(IMGDIR ${PREFIX}/share/${PROJECT_NAME}/images)
 SET(VERSION_MAJOR 0)
 SET(VERSION ${VERSION_MAJOR}.1.0)
 SET(VENDOR "samsung")
@@ -48,3 +49,4 @@ ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj
    )
 ADD_DEPENDENCIES(${PROJECT_NAME} ${PROJECT_NAME}.edj)
 INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj DESTINATION /usr/share/edje/${PROJECT_NAME})
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/images/ DESTINATION ${IMGDIR} FILES_MATCHING PATTERN "*.png")
diff --git a/data/images/tizen.png b/data/images/tizen.png
new file mode 100644 (file)
index 0000000..408188a
Binary files /dev/null and b/data/images/tizen.png differ
index afd5d09ca91ae5fa082a5fda7283a4ad086efa5a..36980bb7354c3a6c04852fce512e6d0a903df777 100644 (file)
@@ -59,6 +59,7 @@ cp %{_builddir}/%{buildsubdir}/LICENSE %{buildroot}/usr/share/license/%{name}
 %defattr(-,root,root,-)
 %{_libdir}/libui-viewmgr.so.*
 %manifest %{name}.manifest
+%{_datadir}/ui-viewmgr/images/*
 /usr/share/license/%{name}
 /usr/share/edje/ui-viewmgr/ui-viewmgr.edj
 
index 95db0a4f689aec7c7f4167e8735070edd5be5b0e..9e53ce8e2c68d26e482d600db3cf7ab5bf614fa0 100644 (file)
@@ -15,6 +15,8 @@
  *
  */
 #include "main.h"
+#include "page11.h"
+#include "page10.h"
 #include "page9.h"
 #include "page8.h"
 #include "page7.h"
@@ -47,6 +49,74 @@ create_toolbar(Evas_Object *parent, const char *style)
        return toolbar;
 }
 
+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, appdata_s *ad)
+{
+       char buf[128];
+       Elm_Grid *grid;
+       Elm_Box *box;
+       Elm_Layout *layout;
+       Elm_Scroller *scroller;
+       Elm_Button *btn;
+       Elm_Image *image;
+
+       /* Scroller */
+       scroller = elm_scroller_add(parent);
+       elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+       elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+       /* Grid */
+       grid = elm_grid_add(scroller);
+       evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
+       evas_object_show(grid);
+
+       /* NoContent Layout */
+       layout = elm_layout_add(grid);
+       elm_layout_theme_set(layout, "layout", "nocontents", "default");
+       elm_object_part_text_set(layout, "elm.text", text);
+       evas_object_show(layout);
+       elm_grid_pack(grid, layout, 0, 0, 50, 100);
+
+       /* Image */
+       image = elm_image_add(grid);
+       snprintf(buf, sizeof(buf), "/usr/share/ui-viewmgr/images/tizen.png");
+       elm_image_file_set(image, buf, NULL);
+       evas_object_show(image);
+       elm_grid_pack(grid, image, 50, 0, 50, 85);
+
+       /* Box */
+       box = elm_box_add(grid);
+       elm_box_horizontal_set(box, EINA_TRUE);
+       evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
+       elm_box_padding_set(box, ELM_SCALE_SIZE(50), 0);
+       evas_object_show(box);
+       elm_grid_pack(grid, box, 0, 0, 100, 100);
+
+       /* Previous Page Button */
+       btn = elm_button_add(grid);
+       evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0);
+       elm_object_text_set(btn, "Prev");
+       evas_object_smart_callback_add(btn, "clicked", prev_btn_clicked_cb, ad);
+       evas_object_show(btn);
+       elm_box_pack_end(box, btn);
+
+       /* Next Page Button */
+       btn = elm_button_add(grid);
+       evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0);
+       elm_object_text_set(btn, "Next");
+       evas_object_smart_callback_add(btn, "clicked", next_btn_clicked_cb, ad);
+       evas_object_show(btn);
+       elm_box_pack_end(box, btn);
+
+       elm_object_content_set(scroller, grid);
+
+       return scroller;
+}
+
 Evas_Object*
 create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad)
 {
index 5846a1156b12d0e76087d43f15dea7c63a25160e..abc7ac79f54b3871cade61d60334b619c94bb07f 100644 (file)
@@ -39,5 +39,6 @@ typedef struct appdata {
        ui_viewmgr *viewmgr;
 } 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, appdata_s *ad);
 Evas_Object *create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad);
 Elm_Toolbar *create_toolbar(Evas_Object *parent, const char *style);
diff --git a/src/examples/efl/page10.h b/src/examples/efl/page10.h
new file mode 100644 (file)
index 0000000..844a9e9
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ *
+ */
+class page10: public ui_controller
+{
+private:
+       appdata_s *ad;
+
+public:
+       page10(appdata_s *ad)
+               : ad(ad)
+       {
+               /* ui_view(controller, identity name).
+                  Later, you could get the identity name using view->get_name(); */
+               ad->viewmgr->push_view(new ui_view(this, "page10"));
+       }
+
+       ~page10()
+       {
+       }
+
+       Evas_Object *create_page10_content(ui_view *view, bool is_portrait)
+       {
+               Evas_Object *content;
+
+               if (is_portrait)
+               {
+                       //Create portrait content.
+                       content = create_content(view->get_base(),
+                                       "ViewMgr Demo<br>Page 10 With<br>on_portrait(), on_landscape()",
+                                       //Prev Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                       appdata_s *ad = static_cast<appdata_s *>(data);
+                                       ad->viewmgr->pop_view();
+                                       },
+                                       //Next Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               appdata_s *ad = static_cast<appdata_s *>(data);
+                                               create_page11(ad);
+                                       },
+                                       this->ad);
+               }
+               else
+               {
+                       //Create landscape content.
+                       content = create_landscape_content(view->get_base(),
+                                       "ViewMgr Demo<br>Page 10 With<br>on_portrait(), on_landscape()",
+                                       //Prev Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                       appdata_s *ad = static_cast<appdata_s *>(data);
+                                       ad->viewmgr->pop_view();
+                                       },
+                                       //Next Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               appdata_s *ad = static_cast<appdata_s *>(data);
+                                               create_page11(ad);
+                                       },
+                                       this->ad);
+               }
+
+               return content;
+       }
+
+       void on_load()
+       {
+               Evas_Object *content;
+
+               //Initialize contents.
+               ui_view *view = dynamic_cast<ui_view *>(this->get_view());
+
+               //FIXME: Change below code to more convenient and clear way.
+               if (view->get_degree() == 90 || view->get_degree() == 270)
+                       this->on_landscape();
+               else
+                       this->on_portrait();
+       }
+
+       void on_portrait()
+       {
+               Evas_Object *content;
+
+               ui_view *view = dynamic_cast<ui_view *>(this->get_view());
+
+               content = this->create_page10_content(view, true);
+               view->set_content(content, "Title Portrait");
+       }
+
+       void on_landscape()
+       {
+               Evas_Object *content;
+
+               ui_view *view = dynamic_cast<ui_view *>(this->get_view());
+
+               content = this->create_page10_content(view, false);
+               view->set_content(content, "Title Landscape");
+       }
+
+};
+
+void create_page10(appdata_s *ad)
+{
+       new page10(ad);
+}
diff --git a/src/examples/efl/page11.h b/src/examples/efl/page11.h
new file mode 100644 (file)
index 0000000..115cf68
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ *
+ */
+
+class page11: public ui_view
+{
+private:
+       appdata_s *ad;
+
+protected:
+       Evas_Object *create_page11_content(bool is_portrait)
+       {
+               Evas_Object *content;
+
+               if (is_portrait)
+               {
+                       //Create portrait content.
+                       content = create_content(this->get_base(), "ViewMgr Demo<br>Page 11 (View inheritance)<br>With on_rotate()",
+                                       //Prev Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               appdata_s *ad = static_cast<appdata_s *>(data);
+                                               ad->viewmgr->pop_view();
+                                       },
+                                       //Next Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               appdata_s *ad = static_cast<appdata_s *>(data);
+                                               ad->viewmgr->deactivate();
+                                       },
+                                       this->ad);
+               }
+               else
+               {
+                       //Create landscape content.
+                       content = create_landscape_content(this->get_base(), "ViewMgr Demo<br>Page 11 (View inheritance)<br>With on_rotate()",
+                                       //Prev Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               appdata_s *ad = static_cast<appdata_s *>(data);
+                                               ad->viewmgr->pop_view();
+                                       },
+                                       //Next Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               appdata_s *ad = static_cast<appdata_s *>(data);
+                                               ad->viewmgr->deactivate();
+                                       },
+                                       this->ad);
+               }
+
+               return content;
+       }
+
+       virtual void on_load()
+       {
+               this->on_rotate(this->get_degree());
+       }
+
+       virtual void on_rotate(int degree)
+       {
+               Evas_Object *content;
+
+               if (this->get_degree() == 0 || this->get_degree() == 180)
+               {
+                       content = this->create_page11_content(true);
+                       this->set_content(content, "Title Portrait");
+               }
+               else
+               {
+                       content = this->create_page11_content(false);
+                       this->set_content(content, "Title Landscape");
+               }
+       }
+
+public:
+       page11(const char *name, appdata_s *ad)
+               : ui_view(name), ad(ad)
+       {
+               ad->viewmgr->push_view(this);
+       }
+
+       ~page11()
+       {
+       }
+};
+
+void create_page11(appdata_s *ad)
+{
+       /* A example for view class extension instead of using controller class. */
+       new page11("page11", ad);
+}
index 464c1adaa5da3ee751ed2298afbaa3dd6ca48f8e..f07b62cb1640f8bb7c21f014253845f132a5c7e3 100644 (file)
@@ -39,7 +39,7 @@ public:
                        [](void *data, Evas_Object *obj, void *event_info) -> void
                        {
                                appdata_s *ad = static_cast<appdata_s *>(data);
-                               ad->viewmgr->deactivate();
+                               create_page10(ad);
                        },
                        this->ad);