TizenRefApp-8331 [Gallery] Integrate TouchParser and ViewerPage into 70/123470/2
authorIgor Nazarov <i.nazarov@samsung.com>
Wed, 5 Apr 2017 16:05:40 +0000 (19:05 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Wed, 5 Apr 2017 16:47:11 +0000 (19:47 +0300)
application

- ImageGrid updated. Added support of double tap event using
  TouchParser;
- TouchParser integrated into ViewerPage;
- ViewerPage integrated with PreviewPage;
- Minor UCL update.

Change-Id: Ie9eb5f98f35f33e76917df72a6b2dd4d29717451

16 files changed:
edc/button.edc
edc/image-grid.edc
inc/model/MediaItem.h
inc/presentation/IImageGridListener.h
inc/presentation/ImageGrid.h
inc/presentation/PreviewPage.h
inc/presentation/ThumbnailPage.h
inc/presentation/ViewerPage.h
src/model/MediaItem.cpp
src/presentation/ImageGrid.cpp
src/presentation/ImageViewer.cpp
src/presentation/PreviewPage.cpp
src/presentation/ThumbnailPage.cpp
src/presentation/ViewerPage.cpp
ucl/inc/ucl/gui/EdjeWidget.h
ucl/inc/ucl/gui/WidgetItem.h

index 9d3f15c0c216f70b6293edbac20d7fd2d6d12415..75be9d64657a26774adc7b03de3e6ad835f409e1 100644 (file)
@@ -153,6 +153,17 @@ group{ "elm/button/base/gallery_image";
             color: GALLERY_COLOR_IMG_EF_DISABLED;
          }
       }
+      rect { "blocker";
+         norepeat;
+         desc { "default";
+            color: 0 0 0 0;
+            hid;
+         }
+         desc { "block";
+            inherit: "default";
+            vis;
+         }
+      }
    }
    programs {
       program { "on_disabled";
@@ -179,5 +190,17 @@ group{ "elm/button/base/gallery_image";
          action: STATE_SET "default";
          target: "event";
       }
+      program { "on_block_clicks";
+         signal: "gallery,block,clicks";
+         source: "";
+         action: STATE_SET "block";
+         target: "blocker";
+      }
+      program { "on_unblock_clicks";
+         signal: "gallery,unblock,clicks";
+         source: "";
+         action: STATE_SET "default";
+         target: "blocker";
+      }
    }
 }
index f8e368be371cf7ccc5e37558943393b73a17cccc..751509edd37979761bece0f34eeb489dcaa6fc50 100644 (file)
@@ -167,14 +167,5 @@ group { "elm/layout/gallery_image_grid/linear";
             rel2.to: "image_mask_0";
          }
       }
-      rect { "blocker";
-         norepeat;
-         desc { "default";
-            fixed: 1 1;
-            color: 0 0 0 0;
-            rel1.to: "image_mask_0";
-            rel2.to: "image_mask_0";
-         }
-      }
    }
 }
index 1c504a3698dca26559e58eebbc5a1d477c48fc61..fb0310d7978a2d6a80e35a3a00ba759d8ccc2bc9 100644 (file)
@@ -33,6 +33,8 @@ namespace gallery {
                bool isValid() const;
                MediaType getType() const;
 
+               const std::string &getId() const;
+
                void getResolution(int &x, int &y) const;
 
                const std::string &getFilePath() const;
index abc1abf806e8696bdb748088cbafd8985ccc3bd7..dd77813c7cbe695ce0bf6752954e6b7cf937ff93 100644 (file)
@@ -25,7 +25,7 @@ namespace gallery {
        public:
                virtual void onItemRealized(int itemIndex) = 0;
                virtual void onItemUnrealized(int itemIndex) = 0;
-               virtual void onItemClicked(int itemIndex) = 0;
+               virtual void onItemEvent(int itemIndex, int event, int x, int y) = 0;
        };
 }
 
index f8373a1363380c50621f6692baa45f0ad531ab75..dd0694d8a650486fa9f8318208a27731ed9182c3 100644 (file)
@@ -32,6 +32,11 @@ namespace gallery {
                        LINEAR
                };
 
+               enum ItemEvent {
+                       ITEM_EVENT_CLICK,
+                       ITEM_EVENT_DOUBLE_TAP
+               };
+
                class Builder {
                public:
                        Builder();
@@ -45,7 +50,8 @@ namespace gallery {
 
                enum {
                        UF_LOSE_IMAGE = 1,
-                       UF_LOSE_BG = 2
+                       UF_LOSE_BG = 2,
+                       UF_BLOCK_CLICKS = 4
                };
 
                struct ItemParams {
@@ -106,7 +112,7 @@ namespace gallery {
                void addUnrealizeLock();
                void removeUnrealizeLock();
 
-               void handleItemClick(int itemIndex) const;
+               void handleItemEvent(int itemIndex, int event, int x, int y) const;
 
                // Initialization
                void prepare();
index 6c32acb1269ccc2ff02b9b61056bd4c138cd6efb..a2ea01e9c938c3cb9e7b992172eec0890b220f2a 100644 (file)
@@ -56,6 +56,8 @@ namespace gallery {
 
                bool onEachMedia(MediaItemSRef &&media);
 
+               void onPageExitRequest(Page &page);
+
                // Page //
 
                virtual void onActivate() final override;
@@ -65,7 +67,8 @@ namespace gallery {
 
                virtual void onItemRealized(int itemIndex) final override;
                virtual void onItemUnrealized(int itemIndex) final override;
-               virtual void onItemClicked(int itemIndex) final override;
+               virtual void onItemEvent(int itemIndex,
+                               int event, int x, int y) final override;
 
        private:
                class Item;
@@ -75,6 +78,7 @@ namespace gallery {
                const IMediaAlbumSRef m_album;
                ImageGridSRef m_imageGrid;
                std::vector<ItemUPtr> m_items;
+               PageWRef m_page;
        };
 }
 
index 13ec7a8b842c0faf78c946c96b63382fb1b8caee..0b53f142d9e79ccccb23351334322ee5a66f5b2a 100644 (file)
@@ -64,7 +64,8 @@ namespace gallery {
 
                virtual void onItemRealized(int itemIndex) final override;
                virtual void onItemUnrealized(int itemIndex) final override;
-               virtual void onItemClicked(int itemIndex) final override;
+               virtual void onItemEvent(int itemIndex,
+                               int event, int x, int y) final override;
 
        private:
                class RealizedItem;
index fc4fcb7d5d7315593cc0e6c10f90dc08649eb41f..3d298fb0c8be5ee2d0e3005e251bc6ec1eadf961 100644 (file)
@@ -31,16 +31,19 @@ namespace gallery {
                        ~Builder();
                        Builder &setNaviframe(const ucl::NaviframeSRef &navi);
                        Builder &setMedia(const MediaItemSRef &media);
+                       Builder &setZoomIn(int x, int y);
                        Builder &setExitOnZoomOut(bool value);
                        ViewerPageSRef build(ExitRequestHandler onExitRequest) const;
                private:
                        ucl::NaviframeSRef m_navi;
                        MediaItemSRef m_media;
+                       int m_zoomInX;
+                       int m_zoomInY;
                        bool m_exitOnZoomOut;
                };
 
        public:
-               void zoomIn(int originX, int originY);
+               const std::string &getMediaId() const;
 
        private:
                friend class ucl::RefCountObj<ViewerPage>;
@@ -51,8 +54,11 @@ namespace gallery {
 
                ucl::Result prepare();
 
+               void zoomIn(int originX, int originY);
+
                void onThumbnail(ucl::Result result, const std::string &path);
                void onZoomEnd(ucl::Widget &widget, void *eventInfo);
+               void onDoubleTap(int x, int y);
 
                // Page //
 
@@ -62,6 +68,7 @@ namespace gallery {
                const MediaItemSRef m_media;
                const bool m_exitOnZoomOut;
                ImageViewerSRef m_imageViewer;
+               TouchParserSRef m_touchParser;
        };
 }
 
index 5771b7dea576d1b99a4058c3f555491024f305b7..c25d2c3e1530286b4db3c59f5e64d6d5ab1a8b54 100644 (file)
@@ -133,6 +133,11 @@ namespace gallery {
                return m_type;
        }
 
+       const std::string &MediaItem::getId() const
+       {
+               return m_mediaId;
+       }
+
        void MediaItem::getResolution(int &x, int &y) const
        {
                x = m_resolutionX;
index a998b5eeabbee6bf1ad2e3e5e42b4f20172d564f..76aefa2b4bfecff72451219bb0f99cca1be77400 100644 (file)
@@ -22,6 +22,7 @@
 #include "ucl/gui/Layout.h"
 
 #include "presentation/IImageGridListener.h"
+#include "presentation/TouchParser.h"
 
 #include "common.h"
 
@@ -36,6 +37,8 @@ namespace gallery { namespace { namespace impl {
        constexpr ElmStyle ITEM_BTN_STYLE {"gallery_image"};
        constexpr EdjePart PART_BTN_BG {"swallow.bg"};
        constexpr SmartEvent BTN_CLICKED {"clicked"};
+       constexpr EdjeSignal BTN_BLOCK_CLICKS {"gallery,block,clicks"};
+       constexpr EdjeSignal BTN_UNBLOCK_CLICKS {"gallery,unblock,clicks"};
 
        // Other //
        constexpr auto HCOMB_SCROLL_LIMIT = 1000;
@@ -200,7 +203,8 @@ namespace gallery {
                                m_image(elm_image_add(m_btn)),
                                m_realizeIndex(-1),
                                m_imageLoadSize(0),
-                               m_wasUpdated(false)
+                               m_wasUpdated(false),
+                               m_isClicksBlocked(false)
                        {
                                m_btn.setFocusAlowed(false);
                                m_btn.setStyle(impl::ITEM_BTN_STYLE);
@@ -214,6 +218,10 @@ namespace gallery {
 
                                m_btn.addEventHandler(impl::BTN_CLICKED, WEAK_DELEGATE(
                                                Item::onClicked, asWeak(*this)));
+
+                               m_touchParser = makeShared<TouchParser>(m_btn);
+                               m_touchParser->setDoubleTapHandler(
+                                               DELEGATE(Item::onDoubleTap, this));
                        }
 
                        Widget &getWidget()
@@ -273,6 +281,7 @@ namespace gallery {
                                        return false;
                                }
 
+                               updateClicksBlock(params);
                                updateImage(params);
                                updateBgImage(params);
 
@@ -284,6 +293,19 @@ namespace gallery {
                        }
 
                private:
+                       void updateClicksBlock(const ItemParams &params)
+                       {
+                               if (params.flags & UF_BLOCK_CLICKS) {
+                                       if (!m_isClicksBlocked) {
+                                               m_isClicksBlocked = true;
+                                               m_btn.emitSignal(impl::BTN_BLOCK_CLICKS);
+                                       }
+                               } else if (m_isClicksBlocked) {
+                                       m_isClicksBlocked = false;
+                                       m_btn.emitSignal(impl::BTN_UNBLOCK_CLICKS);
+                               }
+                       }
+
                        void updateImage(const ItemParams &params)
                        {
                                if (isEmpty(params.imagePath)) {
@@ -333,7 +355,16 @@ namespace gallery {
                        void onClicked(Widget &wifget, void *eventInfo)
                        {
                                if (isRealized()) {
-                                       m_imageGrid.handleItemClick(m_realizeIndex);
+                                       m_imageGrid.handleItemEvent(m_realizeIndex,
+                                                       ITEM_EVENT_CLICK, -1, -1);
+                               }
+                       }
+
+                       void onDoubleTap(const int x, const int y)
+                       {
+                               if (isRealized()) {
+                                       m_imageGrid.handleItemEvent(m_realizeIndex,
+                                                       ITEM_EVENT_DOUBLE_TAP, x, y);
                                }
                        }
 
@@ -342,9 +373,11 @@ namespace gallery {
                        StyledWidget m_btn;
                        StyledWidget m_image;
                        WidgetSRef m_bgImage;
+                       TouchParserSRef m_touchParser;
                        int m_realizeIndex;
                        int m_imageLoadSize;
                        bool m_wasUpdated;
+                       bool m_isClicksBlocked;
                };
 
        public:
@@ -566,8 +599,13 @@ namespace gallery {
                                        "eext_circle_object_scroller_add() failed!");
                }
 
-               eext_circle_object_scroller_policy_set(m_circleScroller,
-                               ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
+               if (m_info.isHorizontal) {
+                       eext_circle_object_scroller_policy_set(m_circleScroller,
+                                       ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
+               } else {
+                       eext_circle_object_scroller_policy_set(m_circleScroller,
+                                       ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+               }
        }
 
        void ImageGrid::setListener(IImageGridListener *const listener)
@@ -705,10 +743,11 @@ namespace gallery {
                }
        }
 
-       void ImageGrid::handleItemClick(const int itemIndex) const
+       void ImageGrid::handleItemEvent(const int itemIndex, const int event,
+                       const int x, const int y) const
        {
                if (m_listener) {
-                       m_listener->onItemClicked(itemIndex);
+                       m_listener->onItemEvent(itemIndex, event, x, y);
                }
        }
 
index a74f1943fc557e982360936eb422004fd32a00f6..4fd27648f29035e0c946ec07a056badb66f0e513 100644 (file)
@@ -22,6 +22,7 @@ namespace gallery { namespace { namespace impl {
 
        constexpr auto ANIMATION_START_TIMEOUT_SEC = (1.0 / 30.0);
        constexpr auto ANIMATION_RUNTIME_SEC = (300.0 / 1000.0);
+       constexpr auto ANIMATION_STOP_POS = 0.999999;
 }}}
 
 namespace gallery {
@@ -110,6 +111,8 @@ namespace gallery {
                elm_scroller_bounce_set(*m_scroller, EINA_TRUE, EINA_TRUE);
                elm_scroller_policy_set(*m_scroller,
                                ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
+               elm_scroller_single_direction_set(*m_scroller,
+                               ELM_SCROLLER_SINGLE_DIRECTION_NONE);
                elm_object_scroll_freeze_push(*m_scroller);
                show(*m_scroller);
 
@@ -342,7 +345,7 @@ namespace gallery {
                updateGridSize();
                updateScrollOffset();
 
-               if (pos == 1.0) {
+               if (pos >= impl::ANIMATION_STOP_POS) {
                        m_animator = nullptr;
                        if (m_state == State::ZOOMING_IN) {
                                m_state = State::ZOOMED_IN;
index bf70d87c5a46efb2146e64f476d7a96294f12a01..102022691d6bfbc527b1f3f2e5c8c255b8b944bb 100644 (file)
@@ -20,6 +20,7 @@
 #include "model/MediaItem.h"
 
 #include "presentation/ImageGrid.h"
+#include "presentation/ViewerPage.h"
 
 #include "common.h"
 
@@ -108,6 +109,11 @@ namespace gallery {
                        m_media->cancelThumbnailPathGet();
                }
 
+               MediaItemSRef getMedia()
+               {
+                       return m_media;
+               }
+
        private:
                void onThumbnail(const Result result, const std::string &path)
                {
@@ -117,6 +123,7 @@ namespace gallery {
                        m_media->getResolution(params.aspectX, params.aspectY);
                        params.imagePath = m_media->getFilePath();
                        params.bgImagePath = path;
+                       params.flags = ImageGrid::UF_BLOCK_CLICKS;
 
                        m_imageGrid.updateItem(m_index, params);
                }
@@ -140,6 +147,9 @@ namespace gallery {
 
        PreviewPage::~PreviewPage()
        {
+               if (m_page) {
+                       m_page->exitNoTransition();
+               }
                m_imageGrid->setListener(nullptr);
        }
 
@@ -154,6 +164,22 @@ namespace gallery {
                                "m_album->forEachMedia() failed!");
 
                m_imageGrid->setItemCount(m_items.size());
+
+               const auto viewerPage = dynamicRefCast<ViewerPage>(m_page);
+               if (viewerPage) {
+                       const auto mediaId = viewerPage->getMediaId();
+                       const auto it = std::find_if(m_items.begin(), m_items.end(),
+                               [&mediaId](const ItemUPtr &item)
+                               {
+                                       return (item->getMedia()->getId() == mediaId);
+                               });
+                       if (it == m_items.end()) {
+                               DLOG("Viewed media item was removed.");
+                               deleteTo();
+                       } else {
+                               m_imageGrid->scrollToItem(it - m_items.begin());
+                       }
+               }
        }
 
        Result PreviewPage::prepare()
@@ -214,8 +240,22 @@ namespace gallery {
                m_items[itemIndex]->unrealize();
        }
 
-       void PreviewPage::onItemClicked(const int itemIndex)
+       void PreviewPage::onItemEvent(const int itemIndex,
+                       const int event, const int x, const int y)
+       {
+               if (!isActive() || (event != ImageGrid::ITEM_EVENT_DOUBLE_TAP)) {
+                       return;
+               }
+
+               m_page = ViewerPage::Builder().
+                               setNaviframe(asShared(getNaviframe())).
+                               setZoomIn(x, y).
+                               setMedia(m_items[itemIndex]->getMedia()).
+                               build(DELEGATE(PreviewPage::onPageExitRequest, this));
+       }
+
+       void PreviewPage::onPageExitRequest(Page &page)
        {
-               ILOG("TODO Not implemented. Item: %d;", itemIndex);
+               deleteTo();
        }
 }
index 6ce03443065812235ab5dcf37108190ce00bfec7..2628d9889b7b0993cf8865d3b75186de99141a54 100644 (file)
@@ -211,8 +211,13 @@ namespace gallery {
                }
        }
 
-       void ThumbnailPage::onItemClicked(const int itemIndex)
+       void ThumbnailPage::onItemEvent(const int itemIndex,
+                       const int event, const int x, const int y)
        {
+               if (!isActive() || (event != ImageGrid::ITEM_EVENT_CLICK)) {
+                       return;
+               }
+
                m_page = PreviewPage::Builder().
                                setNaviframe(asShared(getNaviframe())).
                                setAlbum(m_album).
index 99e75e0a7103926fa78f7f75d1fa17e778e3b113..60ad7c27f6d0020a7a2eecde2a1c68510597a670 100644 (file)
@@ -19,6 +19,7 @@
 #include "model/MediaItem.h"
 
 #include "presentation/ImageViewer.h"
+#include "presentation/TouchParser.h"
 
 #include "common.h"
 
@@ -29,6 +30,8 @@ namespace gallery {
        // ViewerPage::Builder //
 
        ViewerPage::Builder::Builder() :
+               m_zoomInX(-1),
+               m_zoomInY(-1),
                m_exitOnZoomOut(true)
        {
        }
@@ -51,6 +54,14 @@ namespace gallery {
                return *this;
        }
 
+       ViewerPage::Builder &ViewerPage::Builder::setZoomIn(
+                       const int x, const int y)
+       {
+               m_zoomInX = x;
+               m_zoomInY = y;
+               return *this;
+       }
+
        ViewerPage::Builder &ViewerPage::Builder::setExitOnZoomOut(const bool value)
        {
                m_exitOnZoomOut = value;
@@ -76,6 +87,10 @@ namespace gallery {
 
                FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!");
 
+               if ((m_zoomInX >= 0) && (m_zoomInY >= 0)) {
+                       result->zoomIn(m_zoomInX, m_zoomInY);
+               }
+
                return result;
        }
 
@@ -96,11 +111,6 @@ namespace gallery {
        {
        }
 
-       void ViewerPage::zoomIn(const int originX, const int originY)
-       {
-               m_imageViewer->zoomIn(originX, originY);
-       }
-
        Result ViewerPage::prepare()
        {
                int mediaW = 0;
@@ -135,9 +145,23 @@ namespace gallery {
                        }),
                        "Page::prepare() failed!");
 
+               m_touchParser = makeShared<TouchParser>(*m_imageViewer);
+               m_touchParser->setDoubleTapHandler(
+                               DELEGATE(ViewerPage::onDoubleTap, this));
+
                return RES_OK;
        }
 
+       void ViewerPage::zoomIn(const int originX, const int originY)
+       {
+               m_imageViewer->zoomIn(originX, originY);
+       }
+
+       const std::string &ViewerPage::getMediaId() const
+       {
+               return m_media->getId();
+       }
+
        void ViewerPage::onThumbnail(const Result result, const std::string &path)
        {
                FAIL_RETURN_VOID(result, "Failed to get thumbnail!");
@@ -152,13 +176,24 @@ namespace gallery {
                }
        }
 
+       void ViewerPage::onDoubleTap(int x, int y)
+       {
+               if (!isActive()) {
+                       return;
+               }
+               if (m_imageViewer->isZoomedOut()) {
+                       m_imageViewer->zoomIn(x, y);
+               } else if (m_imageViewer->isZoomedIn()) {
+                       m_imageViewer->zoomOut();
+               }
+       }
+
        void ViewerPage::onBackKey()
        {
                if (m_imageViewer->isZoomedOut()) {
                        requestExit();
-                       return;
+               } else if (m_imageViewer->isZoomedIn()) {
+                       m_imageViewer->zoomOut();
                }
-
-               m_imageViewer->zoomOut();
        }
 }
index 5700187f231b637b3c137517873803db717fe0da..ee3313d8778c6f9a060c1efb1de5ce408a1a8e10 100644 (file)
@@ -39,7 +39,8 @@ namespace ucl {
                Evas_Object *getContent() const;
                Evas_Object *getContent(EdjePart part) const;
 
-               void emitSignal(EdjeSignal signal, EdjeSignalSrc source);
+               void emitSignal(EdjeSignal signal, EdjeSignalSrc source =
+                               EdjeSignalSrc(""));
 
        protected:
                EdjeWidget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner = false);
index db769656219d23fef3b4c3c247ba60495b9cb82e..daef146de3faea08f6aa00fa91478f7227dc05b3 100644 (file)
@@ -57,7 +57,8 @@ namespace ucl {
                Evas_Object *getContent() const;
                Evas_Object *getContent(EdjePart part) const;
 
-               void emitSignal(EdjeSignal signal, EdjeSignalSrc source) const;
+               void emitSignal(EdjeSignal signal,EdjeSignalSrc source =
+                               EdjeSignalSrc("")) const;
 
        private:
                Elm_Object_Item *m_it;