Gesture activities with new e-mod API 97/168597/10
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Mon, 29 Jan 2018 11:50:02 +0000 (12:50 +0100)
committerLukasz Oleksak <l.oleksak@samsung.com>
Tue, 30 Jan 2018 11:58:56 +0000 (11:58 +0000)
Change-Id: I182f92a7bcce7bda386974dd3467bd015d62b93c

src/DoneCallback.hpp
src/DragActivity.cpp [deleted file]
src/GestureActivity.cpp
src/TapActivity.cpp [deleted file]
src/utils.cpp
src/utils.hpp

index 3d71cd1..0f05440 100644 (file)
@@ -23,10 +23,6 @@ namespace sideEffectDelays
         */
        static constexpr auto changeValue = 10ms;
        /**
-        * @brief delay for completion of drag gestxure
-        */
-       static constexpr auto eModDrag = 100ms;
-       /**
         * @brief delay for completion of gesture executed via e-mod
         */
        static constexpr auto eModGesture = 100ms;
diff --git a/src/DragActivity.cpp b/src/DragActivity.cpp
deleted file mode 100644 (file)
index 004dc86..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#include "UIActivity.hpp"
-#include "ActivityFactory.hpp"
-#include "UniversalSwitchLog.hpp"
-#include "ScreenScannerManager.hpp"
-#include "UIElement.hpp"
-#include "dbusLocators.hpp"
-
-#include <memory>
-
-static constexpr int MIDDLE_STEPS_COUNT = 20; //DispatchDragEvent will generate 20 middle steps between start and end point
-static constexpr double NO_DELAY_AFTER_TOUCH = 0.0;
-static constexpr double LONG_PRESS_TIME = 1.0; //according to homescreen app long press duration = 0.75s
-
-template <typename DerivedType>
-class DispatchDragActivity : public UIActivity, private RegisterActivity<DerivedType>
-{
-public:
-       constexpr static const char *activityType = DerivedType::activityType;
-       DispatchDragActivity() : UIActivity(activityType)
-       {}
-
-       void update(const std::shared_ptr<UIElement> &elem) override
-       {
-               uiElements.push_back(elem);
-       }
-
-       void process(DoneCallback doneCb) override
-       {
-               ASSERT(uiElements.size() == DerivedType::REQUIRED_UIELEMENTS);
-
-               markAsCompleted();
-               auto from = uiElements[0]->getScanningCoordinates();
-               auto to = uiElements[DerivedType::REQUIRED_UIELEMENTS - 1]->getScanningCoordinates();
-
-               DBus::DBusClient dbus {dbusLocators::accessibilityEMod::BUS,
-                                                          dbusLocators::accessibilityEMod::OBJ_PATH,
-                                                          dbusLocators::accessibilityEMod::INTERFACE,
-                                                          DBus::ConnectionType::SYSTEM};
-               auto pressTime = DerivedType::HOLD_TIME;
-               DEBUG("Drag %d, %d, %d, %d, %d, %f", from.x, from.y, to.x, to.y, MIDDLE_STEPS_COUNT, pressTime);
-               dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").
-               call(from.x, from.y, to.x, to.y, MIDDLE_STEPS_COUNT, pressTime);
-               doneCb.callAfterTimeElapsed(sideEffectDelays::eModDrag);
-       }
-private:
-       std::vector<std::shared_ptr<UIElement>> uiElements;
-};
-
-class DragActivity : public DispatchDragActivity<DragActivity>
-{
-public:
-       constexpr static const char *activityType = "DRAG";
-       constexpr static double HOLD_TIME = NO_DELAY_AFTER_TOUCH;
-       constexpr static int REQUIRED_UIELEMENTS = 2;
-};
-
-class TouchAndHoldThenDragActivity : public DispatchDragActivity<TouchAndHoldThenDragActivity>
-{
-public:
-       constexpr static const char *activityType = "TOUCH_AND_HOLD_THEN_DRAG";
-       constexpr static double HOLD_TIME = LONG_PRESS_TIME;
-       constexpr static int REQUIRED_UIELEMENTS = 2;
-};
-
-class TouchAndHoldActivity : public DispatchDragActivity<TouchAndHoldActivity>
-{
-public:
-       constexpr static const char *activityType = "TOUCH_AND_HOLD";
-       constexpr static double HOLD_TIME = LONG_PRESS_TIME;
-       constexpr static int REQUIRED_UIELEMENTS = 1;
-};
-
-class CancelActivity : public Activity, private RegisterActivity<CancelActivity>
-{
-public:
-       constexpr static const char *activityType = "CANCEL";
-       CancelActivity() : Activity(activityType)
-       {}
-
-       void process(DoneCallback) override
-       {
-               markAsCompleted();
-               DEBUG("cancelled");
-       }
-};
index adbbe33..a26e549 100644 (file)
 #include "dbusLocators.hpp"
 #include "UniversalSwitch.hpp"
 #include "Window.hpp"
+#include "utils.hpp"
 
-namespace
+static constexpr int DEFAULT_STEPS_NUMBER = 20;                //DispatchDragEvent will generate 20 middle steps between start and end point
+static constexpr int NO_DELAY = 0.0;
+static constexpr double DEFAULT_HOLD_TIME = 1.0;
+static constexpr int SWIPE_LENGTH = 200;
+
+class CancelActivity : public Activity, private RegisterActivity<CancelActivity>
 {
-       enum SwipeType {
-               SWIPE_RIGHT = 1,
-               SWIPE_LEFT,
-               SWIPE_UP,
-               SWIPE_DOWN,
-               ZOOM_IN,
-               ZOOM_OUT,
-       };
+public:
+       static constexpr const char *activityType = "CANCEL";
+       CancelActivity() : Activity(activityType) {}
 
-       static const int DEFAULT_STEPS_NUMBER = 20;             //DispatchDragEvent will generate 20 middle steps between start and end point
-       static const double DEFAULT_HOLD_TIME = 0.0;    //Gesture will be proceed without holding an element
-}
+       void process(DoneCallback) override
+       {
+               markAsCompleted();
+               DEBUG("cancelled");
+       }
+};
 
 template <typename DerivedType>
-class GestureActivity : public UIActivity, private RegisterActivity<DerivedType>
+class GestureDispatcher : public UIActivity, private RegisterActivity<DerivedType>
 {
 public:
        static constexpr const char *activityType = DerivedType::activityType;
 
-       GestureActivity()
+       GestureDispatcher()
                : UIActivity(activityType)
        {}
 
+       void update(const std::shared_ptr<UIElement> &elem) override
+       {
+               uiElements.push_back(elem);
+       }
+
+       Optional<unsigned int> getRequiredNumberOfArgumentsIfAllowedInBatchProcessing() const override
+       {
+               return DerivedType::requiredArguments;
+       }
+
+protected:
+       std::vector<std::shared_ptr<UIElement>> uiElements;
+};
+
+template <typename DerivedType>
+class TouchDispatcher : public GestureDispatcher<DerivedType>
+{
+public:
+       using GestureDispatcher<DerivedType>::uiElements;
+       using GestureDispatcher<DerivedType>::markAsCompleted;
+       static constexpr unsigned int requiredArguments = 1;
+
        void process(DoneCallback doneCb) override
        {
-               auto dbus = DBus::DBusClient {dbusLocators::accessibilityEMod::BUS,
-                                                                         dbusLocators::accessibilityEMod::OBJ_PATH,
-                                                                         dbusLocators::accessibilityEMod::INTERFACE,
-                                                                         DBus::ConnectionType::SYSTEM};
-               DerivedType::dispatchEvent(dbus, uiElement.get(), std::move(doneCb));
+               ASSERT(uiElements.size() == requiredArguments);
+               auto coord = uiElements.front()->getScanningCoordinates();
+
+               utils::EventGenerator::generateTapGesture(coord.x, coord.y, DerivedType::hold_time);
                markAsCompleted();
        }
 };
 
+class TapActivity : public TouchDispatcher<TapActivity>
+{
+public:
+       static constexpr const char *activityType = "TAP";
+       static constexpr double hold_time = NO_DELAY;
+};
+
+class TouchAndHoldActivity : public TouchDispatcher<TouchAndHoldActivity>
+{
+public:
+       static constexpr const char *activityType = "TOUCH_AND_HOLD";
+       static constexpr double hold_time = DEFAULT_HOLD_TIME;
+};
+
 template <typename DerivedType>
-class DispatchGestureEventActivity : public GestureActivity<DerivedType>
+class SwipeDispatcher : public GestureDispatcher<DerivedType>
 {
 public:
-       static void dispatchEvent(DBus::DBusClient &dbus, const UIElement *uiElement, DoneCallback doneCb)
+       using GestureDispatcher<DerivedType>::uiElements;
+       using GestureDispatcher<DerivedType>::markAsCompleted;
+       static constexpr int requiredArguments = 1;
+
+       void process(DoneCallback doneCb) override
        {
-               auto point = uiElement->getScanningCoordinates();
-               const auto swipeType = DerivedType::swipeType;
-               dbus.method<void(int, int, int)>("DispatchGestureEvent").call(swipeType, point.x, point.y);
+               ASSERT(uiElements.size() == requiredArguments);
+
+               auto from = getStartPoint();
+               auto to = getEndPoint();
+
+               utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DEFAULT_STEPS_NUMBER, NO_DELAY);
                doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+               markAsCompleted();
+       }
+
+protected:
+       virtual Point getStartPoint()
+       {
+               return uiElements.front()->getScanningCoordinates();
        }
+
+       virtual Point getEndPoint() = 0;
 };
 
-class SwipeRightActivity : public DispatchGestureEventActivity<SwipeRightActivity>
+class SwipeLeftActivity : public SwipeDispatcher<SwipeLeftActivity>
 {
 public:
-       static constexpr const char *activityType = "SWIPE_RIGHT";
-       static constexpr const SwipeType swipeType = SWIPE_RIGHT;
+       static constexpr const char *activityType = "SWIPE_LEFT";
 
-       Optional<unsigned int> getRequiredNumberOfArgumentsIfAllowedInBatchProcessing() const override
+private:
+       Point getEndPoint() override
        {
-               return 0;
+               auto coord = uiElements.front()->getScanningCoordinates();
+               return Point{coord.x - SWIPE_LENGTH, coord.y};
        }
 };
 
-class SwipeLeftActivity : public DispatchGestureEventActivity<SwipeLeftActivity>
+class SwipeRightActivity : public SwipeDispatcher<SwipeRightActivity>
 {
 public:
-       static constexpr const char *activityType = "SWIPE_LEFT";
-       static constexpr SwipeType swipeType = SWIPE_LEFT;
+       static constexpr const char *activityType = "SWIPE_RIGHT";
 
-       Optional<unsigned int> getRequiredNumberOfArgumentsIfAllowedInBatchProcessing() const override
+private:
+       Point getEndPoint() override
        {
-               return 0;
+               auto coord = uiElements.front()->getScanningCoordinates();
+               return Point{coord.x + SWIPE_LENGTH, coord.y};
        }
 };
 
-class SwipeUpActivity : public DispatchGestureEventActivity<SwipeUpActivity>
+class SwipeUpActivity : public SwipeDispatcher<SwipeUpActivity>
 {
 public:
        static constexpr const char *activityType = "SWIPE_UP";
-       static constexpr SwipeType swipeType = SWIPE_UP;
 
-       Optional<unsigned int> getRequiredNumberOfArgumentsIfAllowedInBatchProcessing() const override
+private:
+       Point getEndPoint() override
        {
-               return 0;
+               auto coord = uiElements.front()->getScanningCoordinates();
+               return Point{coord.x, coord.y - SWIPE_LENGTH};
        }
 };
 
-class SwipeDownActivity : public DispatchGestureEventActivity<SwipeDownActivity>
+class SwipeDownActivity : public SwipeDispatcher<SwipeDownActivity>
 {
 public:
        static constexpr const char *activityType = "SWIPE_DOWN";
-       static constexpr SwipeType swipeType = SWIPE_DOWN;
 
-       Optional<unsigned int> getRequiredNumberOfArgumentsIfAllowedInBatchProcessing() const override
+private:
+       Point getEndPoint() override
        {
-               return 0;
+               auto coord = uiElements.front()->getScanningCoordinates();
+               return Point{coord.x, coord.y + SWIPE_LENGTH};
        }
 };
 
-class ZoomInActivity : public DispatchGestureEventActivity<ZoomInActivity>
+class LeftPageActivity : public SwipeDispatcher<LeftPageActivity>
 {
 public:
-       static constexpr const char *activityType = "ZOOM_IN";
-       static constexpr SwipeType swipeType = ZOOM_IN;
+       static constexpr const char *activityType = "LEFT_PAGE";
+
+private:
+       Point getStartPoint() override
+       {
+               auto screenSize = Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions().size;
+               return Point{screenSize.width / 4, screenSize.height / 2};
+       }
+
+       Point getEndPoint() override
+       {
+               auto screenSize = Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions().size;
+               return Point{ 3 * screenSize.width / 4, screenSize.height / 2};
+       }
 };
 
-class ZoomOutActivity : public DispatchGestureEventActivity<ZoomOutActivity>
+class RightPageActivity : public SwipeDispatcher<RightPageActivity>
 {
 public:
-       static constexpr const char *activityType = "ZOOM_OUT";
-       static constexpr SwipeType swipeType = ZOOM_OUT;
+       static constexpr const char *activityType = "RIGHT_PAGE";
+
+private:
+       Point getStartPoint() override
+       {
+               auto screenSize = Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions().size;
+               return Point{3 * screenSize.width / 4, screenSize.height / 2};
+       }
+
+       Point getEndPoint() override
+       {
+               auto screenSize = Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions().size;
+               return Point{ screenSize.width / 4, screenSize.height / 2};
+       }
 };
 
 template <typename DerivedType>
-class DispatchCustomGestureEventActivity : public GestureActivity<DerivedType>
+class DragDispatcher : public GestureDispatcher<DerivedType>
 {
 public:
-       static void dispatchEvent(DBus::DBusClient &dbus, const UIElement *uiElement, DoneCallback doneCb)
+       using GestureDispatcher<DerivedType>::uiElements;
+       using GestureDispatcher<DerivedType>::markAsCompleted;
+       static constexpr int requiredArguments = 2;
+
+       void process(DoneCallback doneCb) override
        {
-               //move: x in range 25% - 75% , and y = 50% of screen dimensions
-               auto screenSize = Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions().size;
-               Point startPoint;
-               Point endPoint;
-               switch (DerivedType::swipeType) {
-               case SWIPE_LEFT:
-                       startPoint = {screenSize.width * 3 / 4, screenSize.height / 2};
-                       endPoint = {screenSize.width / 4, screenSize.height / 2};
-                       break;
-               case SWIPE_RIGHT:
-                       startPoint = {screenSize.width / 4, screenSize.height / 2};
-                       endPoint = {screenSize.width * 3 / 4, screenSize.height / 2};
-                       break;
-               default:
-                       ERROR("Incorect gesture");
-                       return;
-               }
-               DEBUG("Swipe %d, %d, %d, %d, %d", startPoint.x, startPoint.y, endPoint.x, endPoint.y, DEFAULT_STEPS_NUMBER);
-               dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").call(startPoint.x, startPoint.y, endPoint.x, endPoint.y, DEFAULT_STEPS_NUMBER, DEFAULT_HOLD_TIME);
-               doneCb.callAfterTimeElapsed(sideEffectDelays::eModDrag);
-       }
-};
-
-class CustomSwipeRightActivity : public DispatchCustomGestureEventActivity<CustomSwipeRightActivity>
+               ASSERT(uiElements.size() == requiredArguments);
+
+               auto from = uiElements.front()->getScanningCoordinates();
+               auto to = uiElements.back()->getScanningCoordinates();
+
+               utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DerivedType::steps, DerivedType::hold_time);
+               doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+               markAsCompleted();
+       }
+};
+
+class DragActivity : public DragDispatcher<DragActivity>
 {
 public:
-       static constexpr const char *activityType = "LEFT_PAGE";
-       static constexpr SwipeType swipeType = SWIPE_RIGHT;
+       static constexpr const char *activityType = "DRAG";
+       static constexpr int steps = DEFAULT_STEPS_NUMBER;
+       static constexpr double hold_time = NO_DELAY;
 };
 
-class CustomSwipeLeftActivity : public DispatchCustomGestureEventActivity<CustomSwipeLeftActivity>
+class TouchAndHoldThenDragActivity : public DragDispatcher<TouchAndHoldThenDragActivity>
 {
 public:
-       static constexpr const char *activityType = "RIGHT_PAGE";
-       static constexpr SwipeType swipeType = SWIPE_LEFT;
+       static constexpr const char *activityType = "TOUCH_AND_HOLD_THEN_DRAG";
+       static constexpr int steps = DEFAULT_STEPS_NUMBER;
+       static constexpr double hold_time = DEFAULT_HOLD_TIME;
+};
+
+template <typename DerivedType>
+class PinchDispatcher : public GestureDispatcher<DerivedType>
+{
+public:
+       using GestureDispatcher<DerivedType>::uiElements;
+       using GestureDispatcher<DerivedType>::markAsCompleted;
+       static constexpr int requiredArguments = 1;
+
+       void process(DoneCallback doneCb) override
+       {
+               ASSERT(GestureDispatcher<DerivedType>::uiElements.size() == requiredArguments);
+               auto coord = GestureDispatcher<DerivedType>::uiElements.front()->getScanningCoordinates();
+
+               utils::EventGenerator::generatePinchGesture(coord.x, coord.y, DerivedType::radius_change, DEFAULT_STEPS_NUMBER);
+               doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+               markAsCompleted();
+       }
+};
+
+class ZoomInActivity : public PinchDispatcher<ZoomInActivity>
+{
+public:
+       static constexpr const char *activityType = "ZOOM_IN";
+       static constexpr int radius_change = SWIPE_LENGTH;
+};
+
+class ZoomOutActivity : public PinchDispatcher<ZoomOutActivity>
+{
+public:
+       static constexpr const char *activityType = "ZOOM_OUT";
+       static constexpr int radius_change = -SWIPE_LENGTH;
 };
diff --git a/src/TapActivity.cpp b/src/TapActivity.cpp
deleted file mode 100644 (file)
index fcda99f..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017  Samsung Electronics Co., Ltd
- *
- * 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 "UIActivity.hpp"
-#include "ActivityFactory.hpp"
-#include "UniversalSwitchLog.hpp"
-
-#include <memory>
-
-class TapActivity : public UIActivity, private RegisterActivity<TapActivity>
-{
-public:
-       constexpr static const char *activityType = "TAP";
-       TapActivity()
-               : UIActivity(activityType)
-       {}
-
-       void process(DoneCallback doneCb) override
-       {
-               if (!uiElement) {
-                       ERROR("process invoked before uiElement initialization");
-                       markAsCompleted();
-                       return;
-               }
-
-               uiElement->activate(std::move(doneCb));
-               markAsCompleted();
-       }
-
-       Optional<unsigned int> getRequiredNumberOfArgumentsIfAllowedInBatchProcessing() const override
-       {
-               return 1;
-       }
-};
index e4107cb..535b200 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "UniversalSwitchLog.hpp"
 #include "DoneCallback.hpp"
+#include "DBus.hpp"
+#include "dbusLocators.hpp"
 
 #include <efl_util.h>
 #include <bundle_internal.h>
@@ -91,6 +93,44 @@ namespace utils
                });
        }
 
+       void EventGenerator::generateTapGesture(int x, int y, double press_time)
+       {
+               DEBUG("Tap with drag gesture, x: %d, y: %d, press time: %d", x, y, press_time);
+
+               DBus::DBusClient dbus {dbusLocators::accessibilityEMod::BUS,
+                                                          dbusLocators::accessibilityEMod::OBJ_PATH,
+                                                          dbusLocators::accessibilityEMod::INTERFACE,
+                                                          DBus::ConnectionType::SYSTEM};
+
+               static auto tap_steps = 1;
+               dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").
+               call(x, y, x, y, tap_steps, press_time); //TODO: const for steps number
+       }
+
+       void EventGenerator::generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time)
+       {
+               DEBUG("Drag gesture, from (x, y): (%d, %d), to (x, y): (%d, %d), steps: %d, hold on first time: %lf", from_x, from_y, to_x, to_y, steps, hold_time);
+
+               DBus::DBusClient dbus {dbusLocators::accessibilityEMod::BUS,
+                                                          dbusLocators::accessibilityEMod::OBJ_PATH,
+                                                          dbusLocators::accessibilityEMod::INTERFACE,
+                                                          DBus::ConnectionType::SYSTEM};
+               dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").
+               call(from_x, from_y, to_x, to_y, steps, hold_time);
+       }
+
+       void EventGenerator::generatePinchGesture(int x, int y, int radius_change, int steps)
+       {
+               DEBUG("Pinch gesture, x: %d, y: %d, radius change: %d, steps: %d", x, y, radius_change, steps);
+
+               DBus::DBusClient dbus {dbusLocators::accessibilityEMod::BUS,
+                                                          dbusLocators::accessibilityEMod::OBJ_PATH,
+                                                          dbusLocators::accessibilityEMod::INTERFACE,
+                                                          DBus::ConnectionType::SYSTEM};
+               dbus.method<void(int, int, int, int)>("DispatchPinchEvent").
+               call(x, y, radius_change, steps);
+       }
+
        ecore::TimerRepetitionPolicy EventGenerator::createKeyDownEvent(GeneratorData genData, DoneCallback doneCb)
        {
                DEBUG("invoked");
index 98f24ff..2294af8 100644 (file)
@@ -77,6 +77,10 @@ namespace utils
                static void generateKeyPress(const std::string &keyId, DoneCallback doneCb, unsigned multiplicity = SINGLE_PRESS,
                                                                         PressType type = PressType::SHORT);
 
+               static void generateTapGesture(int x, int y, double press_time);
+               static void generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time);
+               static void generatePinchGesture(int x, int y, int radius_change, int steps);
+
        private:
                static ecore::TimerRepetitionPolicy createKeyDownEvent(GeneratorData genData, DoneCallback doneCb);
                static ecore::TimerRepetitionPolicy createKeyUpEvent(GeneratorData genData, DoneCallback doneCb);