Add SetTapMaximumAllowedTime 69/261669/14
authorjoogab.yun <joogab.yun@samsung.com>
Thu, 22 Jul 2021 08:33:32 +0000 (17:33 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Thu, 5 Aug 2021 10:39:22 +0000 (19:39 +0900)
Sets the MaximumAllowedTime of the tap gesture as an environment variable.

Change-Id: Ic506a936171860aeb4c5e6e96fcdc9fa244c64f1

automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp
dali/integration-api/input-options.cpp
dali/integration-api/input-options.h
dali/internal/event/events/gesture-event-processor.cpp
dali/internal/event/events/gesture-event-processor.h
dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp
dali/internal/event/events/tap-gesture/tap-gesture-processor.h
dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp
dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h

index e39e244c200b76478f9e44efb135e88f81d6913c..e33a21c07f0b99cb1e4861eb8a2b604d0d6060ca 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <dali-test-suite-utils.h>
 #include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/input-options.h>
 #include <dali/integration-api/render-task-list-integ.h>
 #include <dali/public-api/dali-core.h>
 #include <stdlib.h>
@@ -563,3 +564,59 @@ int UtcDaliTapGestureRecognizerTripleTap(void)
 
   END_TEST;
 }
+
+int UtcDaliTapGestureSetMaximumAllowedTime(void)
+{
+  TestApplication application;
+
+  TapGestureDetector detector = TapGestureDetector::New(2);
+
+  Actor actor = Actor::New();
+  actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  application.GetScene().Add(actor);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  detector.Attach(actor);
+
+  try
+  {
+    Integration::SetTapMaximumAllowedTime(0);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+
+  // Reduce the maximum allowable time. 500 -> 100
+  Integration::SetTapMaximumAllowedTime(100);
+
+  SignalData             data;
+  GestureReceivedFunctor functor(data);
+  detector.DetectedSignal().Connect(&application, functor);
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
+
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
+
+  application.SendNotification();
+
+  // The double tap fails because the maximum allowed time has been exceeded
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+
+  // reset maximum allowed time
+  Integration::SetTapMaximumAllowedTime(500);
+
+  END_TEST;
+}
index 3dfca89e828949974e4edf7cc5b9351985c4016c..e77ab701d8dc3153a35e4ce46ab90b00906ab231 100644 (file)
@@ -148,6 +148,12 @@ void SetLongPressMinimumHoldingTime(unsigned int value)
   eventProcessor.SetLongPressMinimumHoldingTime(value);
 }
 
+void SetTapMaximumAllowedTime(uint32_t time)
+{
+  GestureEventProcessor& eventProcessor = ThreadLocalStorage::Get().GetGestureEventProcessor();
+  eventProcessor.SetTapMaximumAllowedTime(time);
+}
+
 } // namespace Integration
 
 } // namespace Dali
index 3789cc9424a2fdd859a53d61ed6301034e3c0f78..a585e03abf8d8770e0beba74e5ec6952a4b1b9d7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTEGRATION_INPUT_OPTIONS_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -198,6 +198,13 @@ DALI_CORE_API void SetRotationGestureMinimumTouchEventsAfterStart(uint32_t value
  */
 DALI_CORE_API void SetLongPressMinimumHoldingTime(unsigned int value);
 
+/**
+ * @brief Sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond)
+ *
+ * @param[in] time The time value in milliseconds
+ */
+DALI_CORE_API void SetTapMaximumAllowedTime(uint32_t time);
+
 } // namespace Integration
 
 } // namespace Dali
index 12b3bf6bd0ea2b4940891503a4e5e62078a04e4b..118c783f64397a96ac1cb9170de5117079e5c32e 100644 (file)
@@ -334,6 +334,11 @@ const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
   return mPanGestureProcessor;
 }
 
+void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time)
+{
+  mTapGestureProcessor.SetMaximumAllowedTime(time);
+}
+
 } // namespace Internal
 
 } // namespace Dali
index ebef0e28b7bb6cd96b15d4ef81a86afbb1675edf..d2b1930fc29d619fb7776e6a53a9f7e87f135b64 100644 (file)
@@ -284,6 +284,13 @@ public: // Called by Core
    */
   uint32_t GetLongPressMinimumHoldingTime() const;
 
+  /**
+   * @brief Sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond)
+   *
+   * @param[in] time The time value in milliseconds
+   */
+  void SetTapMaximumAllowedTime(uint32_t time);
+
 public: // needed for PanGesture
   /**
    * @return the pan gesture processor
index 39dd060ed7c86761854e704614c5e968de88b423..085f627b145774d66b37a3527b73a68e748a11c9 100644 (file)
@@ -41,6 +41,8 @@ namespace Internal
 {
 namespace
 {
+constexpr uint32_t DEFAULT_MAXIMUM_ALLOWED_TIME = 500u;
+
 /**
  * Creates a TapGesture and asks the specified detector to emit its detected signal.
  * @param[in]  actor             The actor on which a tap has occurred.
@@ -80,7 +82,8 @@ TapGestureProcessor::TapGestureProcessor()
   mMinTouchesRequired(1),
   mMaxTouchesRequired(1),
   mCurrentTapEvent(nullptr),
-  mPossibleProcessed(false)
+  mPossibleProcessed(false),
+  mMaximumAllowedTime(DEFAULT_MAXIMUM_ALLOWED_TIME)
 {
 }
 
@@ -180,7 +183,7 @@ void TapGestureProcessor::AddGestureDetector(TapGestureDetector* gestureDetector
     request.maxTouches = mMaxTouchesRequired;
 
     Size size          = scene.GetSize();
-    mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const TapGestureRequest&>(request));
+    mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const TapGestureRequest&>(request), mMaximumAllowedTime);
   }
   else
   {
@@ -242,6 +245,28 @@ void TapGestureProcessor::GestureDetectorUpdated(TapGestureDetector* gestureDete
   UpdateDetection();
 }
 
+void TapGestureProcessor::SetMaximumAllowedTime(uint32_t time)
+{
+  if(time == 0u)
+  {
+    DALI_LOG_WARNING("MaximumAllowedTime must be greater than zero.");
+    return;
+  }
+  if(mMaximumAllowedTime != time)
+  {
+    mMaximumAllowedTime = time;
+
+    if(mGestureRecognizer)
+    {
+      TapGestureRecognizer* tapRecognizer = dynamic_cast<TapGestureRecognizer*>(mGestureRecognizer.Get());
+      if(tapRecognizer)
+      {
+        tapRecognizer->SetMaximumAllowedTime(time);
+      }
+    }
+  }
+}
+
 void TapGestureProcessor::UpdateDetection()
 {
   DALI_ASSERT_DEBUG(!mTapGestureDetectors.empty());
index e0b5b7a180268a6a7a6560b2aa9bf3fa1c1d7751..9804679f58dff6cfd13e14b070a9d7bb72eaaf05 100644 (file)
@@ -84,6 +84,13 @@ public: // To be called by GestureEventProcessor
    */
   void GestureDetectorUpdated(TapGestureDetector* gestureDetector);
 
+  /**
+   * @brief This method sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond)
+   *
+   * @param[in] time The time value in milliseconds
+   */
+  void SetMaximumAllowedTime(uint32_t time);
+
 private:
   // Undefined
   TapGestureProcessor(const TapGestureProcessor&);
@@ -126,6 +133,8 @@ private:
   ActorObserver          mCurrentTapActor;   ///< Observer for the current gesture actor
   const TapGestureEvent* mCurrentTapEvent;   ///< Pointer to current TapEvent, used when calling ProcessAndEmit()
   bool                   mPossibleProcessed; ///< Indication of whether we've processed a touch down for this gestuee
+
+  uint32_t mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond)
 };
 
 } // namespace Internal
index 975c847ce545f681ac5046e29f6b0c61f122f4d6..b1799c17cea0b04ce83c7eab1637043253eab20d 100644 (file)
@@ -36,11 +36,10 @@ namespace Internal
 namespace
 {
 // TODO: Set these according to DPI
-const float         MAXIMUM_MOTION_ALLOWED = 20.0f;
-const unsigned long MAXIMUM_TIME_ALLOWED   = 500u;
+constexpr float MAXIMUM_MOTION_ALLOWED = 20.0f;
 } // unnamed namespace
 
-TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request)
+TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime)
 : GestureRecognizer(screenSize, GestureType::TAP),
   mObserver(observer),
   mState(CLEAR),
@@ -50,7 +49,8 @@ TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSiz
   mTouchPosition(),
   mTouchTime(0u),
   mLastTapTime(0u),
-  mGestureSourceType(GestureSourceType::INVALID)
+  mGestureSourceType(GestureSourceType::INVALID),
+  mMaximumAllowedTime(maximumAllowedTime)
 {
 }
 
@@ -112,7 +112,7 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 
         if(pointState == PointState::UP)
         {
-          if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
+          if(deltaBetweenTouchDownTouchUp < mMaximumAllowedTime)
           {
             mLastTapTime = mTouchTime;
             EmitSingleTap(event.time, point);
@@ -137,12 +137,12 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
           // This is a possible multiple tap, so has it been quick enough?
           uint32_t timeDelta                    = event.time - mLastTapTime;
           uint32_t deltaBetweenTouchDownTouchUp = event.time - mTouchTime;
-          if(timeDelta > MAXIMUM_TIME_ALLOWED) // If exceeded time between taps then just a single tap
+          if(timeDelta > mMaximumAllowedTime) // If exceeded time between taps then just a single tap
           {
             mLastTapTime = event.time;
             EmitSingleTap(event.time, point);
           }
-          else if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
+          else if(deltaBetweenTouchDownTouchUp < mMaximumAllowedTime)
           {
             ++mTapsRegistered;
             EmitGesture(GestureState::STARTED, event.time);
@@ -162,7 +162,7 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 
           if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
              distanceDelta.y > MAXIMUM_MOTION_ALLOWED ||
-             timeDelta > MAXIMUM_TIME_ALLOWED)
+             timeDelta > mMaximumAllowedTime)
           {
             SetupForTouchDown(event, point);
           }
@@ -220,6 +220,11 @@ void TapGestureRecognizer::Update(const GestureRequest& request)
   mMaximumTapsRequired = tap.maxTaps;
 }
 
+void TapGestureRecognizer::SetMaximumAllowedTime(uint32_t time)
+{
+  mMaximumAllowedTime = time;
+}
+
 void TapGestureRecognizer::EmitGesture(GestureState state, uint32_t time)
 {
   if((state == GestureState::CANCELLED) ||
index f87d2ec82944c126a64dfa088555d91b99a87329..b4fbda913d1eaabfadace20befc26143bdb980da 100644 (file)
@@ -51,8 +51,9 @@ public:
    * @param[in] coreEventInterface Used to send events to Core.
    * @param[in]  screenSize  The size of the screen.
    * @param[in]  request     The tap gesture request.
+   * @param[in]  maximumAllowedTime    The maximum allowed time required in milliseconds.
    */
-  TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request);
+  TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime);
 
   /**
    * Virtual destructor.
@@ -70,6 +71,13 @@ public:
    */
   void Update(const GestureRequest& request) override;
 
+  /**
+   * @brief This method sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond)
+   *
+   * @param[in] time The time value in milliseconds
+   */
+  void SetMaximumAllowedTime(uint32_t time);
+
 private:
   /**
    * Checks if registered taps are within required bounds and emits tap gesture if they are.
@@ -142,7 +150,8 @@ private:
   uint32_t mTouchTime;     ///< The initial touch down time.
   uint32_t mLastTapTime;   ///< Time last tap gesture was registered
 
-  GestureSourceType mGestureSourceType; /// < Gesture input source type value.
+  GestureSourceType mGestureSourceType;  /// < Gesture input source type value.
+  uint32_t          mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond)
 };
 
 } // namespace Internal