[Tizen] Add an environment variable for long press gesture 30/221130/1 accepted/tizen/5.5/unified/20200102.013922 submit/tizen_5.5/20191227.100026 submit/tizen_5.5/20191230.003219
authorJiyun Yang <ji.yang@samsung.com>
Fri, 20 Dec 2019 06:51:30 +0000 (15:51 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Fri, 27 Dec 2019 09:12:31 +0000 (18:12 +0900)
DALI_LONG_PRESS_MINIMUM_HOLDING_TIME
The minimum holding time required to be recognized as a long press gesture

Change-Id: Ie6ed848b090ac5564a4b4944b1426c7be4af19ef
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
automated-tests/src/dali/utc-Dali-LongPressGestureDetector.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/long-press-gesture/long-press-gesture-detector-impl.cpp
dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h
dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp
dali/internal/event/events/long-press-gesture/long-press-gesture-processor.h
dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.cpp
dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.h

index b7387f1..ccde1b5 100644 (file)
@@ -20,7 +20,9 @@
 #include <stdlib.h>
 #include <dali/public-api/dali-core.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/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h>
 #include <dali-test-suite-utils.h>
 #include <test-touch-utils.h>
 
@@ -959,3 +961,38 @@ int UtcDaliLongPressGestureLayerConsumesTouch(void)
 
   END_TEST;
 }
+
+int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
+{
+  TestApplication application;
+
+  const uint32_t kMinumumHolding1 = 5000;
+  const uint32_t kMinumumHolding2 = 3000;
+
+  Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
+
+  Actor actor = Actor::New();
+  actor.SetSize( 100.0f, 100.0f );
+  actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  Stage::GetCurrent().Add( actor );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  SignalData data;
+  GestureReceivedFunctor functor( data );
+
+  LongPressGestureDetector detector = LongPressGestureDetector::New();
+  detector.Attach(actor);
+  detector.DetectedSignal().Connect(&application, functor);
+
+  Internal::LongPressGestureDetector& detectorImpl = Dali::GetImplementation( detector );
+
+  DALI_TEST_EQUALS( detectorImpl.GetMinimumHoldingTime(), kMinumumHolding1, TEST_LOCATION );
+
+  Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
+  DALI_TEST_EQUALS( detectorImpl.GetMinimumHoldingTime(), kMinumumHolding2, TEST_LOCATION );
+
+  END_TEST;
+}
index 54eb9fb..b432b9e 100644 (file)
@@ -120,6 +120,12 @@ void SetPinchGestureMinimumDistance( float value )
   eventProcessor.SetPinchGestureMinimumDistance( value );
 }
 
+void SetLongPressMinimumHoldingTime( unsigned int value )
+{
+  GestureEventProcessor& eventProcessor = ThreadLocalStorage::Get().GetGestureEventProcessor();
+  eventProcessor.SetLongPressMinimumHoldingTime( value );
+}
+
 
 } // namespace Integration
 
index 464eff7..f4df355 100644 (file)
@@ -163,6 +163,14 @@ DALI_CORE_API void SetPanGestureMinimumPanEvents( int value );
  * @param[in] value Distance to move in pixels
  */
 DALI_CORE_API void SetPinchGestureMinimumDistance( float value );
+
+/**
+ * @brief Sets the minimum holding time required to be recognized as a long press gesture
+ *
+ * @param[in] value The time value in milliseconds
+ */
+DALI_CORE_API void SetLongPressMinimumHoldingTime( unsigned int value );
+
 } // namespace Integration
 
 } // namespace Dali
index fbfad1b..04863ff 100644 (file)
@@ -321,6 +321,16 @@ void GestureEventProcessor::SetPinchGestureMinimumDistance( float value)
   mPinchGestureProcessor.SetMinimumPinchDistance( value );
 }
 
+void GestureEventProcessor::SetLongPressMinimumHoldingTime( uint32_t value )
+{
+  mLongPressGestureProcessor.SetMinimumHoldingTime( value );
+}
+
+uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
+{
+  return mLongPressGestureProcessor.GetMinimumHoldingTime();
+}
+
 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
 {
   return mPanGestureProcessor;
index a181588..9ae5d6f 100644 (file)
@@ -252,6 +252,18 @@ public: // Called by Core
    */
   void SetPinchGestureMinimumDistance( float value);
 
+  /**
+   * @brief Sets the minimum holding time required to be recognized as a long press gesture
+   *
+   * @param[in] value The time value in milliseconds
+   */
+  void SetLongPressMinimumHoldingTime( uint32_t value );
+
+  /**
+   * @return The minimum holding time required to be recognized as a long press gesture in milliseconds
+   */
+  uint32_t GetLongPressMinimumHoldingTime() const;
+
 public: // needed for PanGesture
 
   /**
index d7f1778..21adbe5 100644 (file)
@@ -173,6 +173,11 @@ void LongPressGestureDetector::OnActorDestroyed(Object& object)
   // Do nothing
 }
 
+uint32_t LongPressGestureDetector::GetMinimumHoldingTime() const
+{
+  return mGestureEventProcessor.GetLongPressMinimumHoldingTime();
+}
+
 } // namespace Internal
 
 } // namespace Dali
index b049433..561012b 100644 (file)
@@ -97,6 +97,11 @@ public:
    */
   unsigned int GetMaximumTouchesRequired() const;
 
+  /**
+   * @return The minimum holding time required to be recognized as a long press gesture in milliseconds
+   */
+  uint32_t GetMinimumHoldingTime() const;
+
 public:
 
   /**
index e08d7e8..b707e24 100644 (file)
@@ -42,6 +42,8 @@ namespace Internal
 namespace
 {
 
+const unsigned long DEFAULT_MINIMUM_HOLDING_TIME = 500u;
+
 /**
  * Creates a LongPressGesture and asks the specified detector to emit its detected signal.
  * @param[in]  actor             The actor on which the long press gesture has occurred.
@@ -106,7 +108,8 @@ LongPressGestureProcessor::LongPressGestureProcessor()
   mCurrentRenderTask(),
   mMinTouchesRequired( 1 ),
   mMaxTouchesRequired( 1 ),
-  mCurrentLongPressEvent( NULL )
+  mCurrentLongPressEvent( NULL ),
+  mMinimumHoldingTime( DEFAULT_MINIMUM_HOLDING_TIME )
 {
 }
 
@@ -230,7 +233,7 @@ void LongPressGestureProcessor::AddGestureDetector( LongPressGestureDetector* ge
 
     Size size = scene.GetSize();
 
-    mGestureRecognizer = new LongPressGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const LongPressGestureRequest&>(request));
+    mGestureRecognizer = new LongPressGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const LongPressGestureRequest&>(request), mMinimumHoldingTime );
   }
   else
   {
@@ -264,6 +267,28 @@ void LongPressGestureProcessor::GestureDetectorUpdated( LongPressGestureDetector
   UpdateDetection();
 }
 
+void LongPressGestureProcessor::SetMinimumHoldingTime( uint32_t time )
+{
+  if( time > 0u )
+  {
+    mMinimumHoldingTime = time;
+
+    if( mGestureRecognizer )
+    {
+      LongPressGestureRecognizer* longPressRecognizer = dynamic_cast<LongPressGestureRecognizer*>( mGestureRecognizer.Get() );
+      if( longPressRecognizer )
+      {
+        longPressRecognizer->SetMinimumHoldingTime( time );
+      }
+    }
+  }
+}
+
+uint32_t LongPressGestureProcessor::GetMinimumHoldingTime() const
+{
+  return mMinimumHoldingTime;
+}
+
 void LongPressGestureProcessor::UpdateDetection()
 {
   DALI_ASSERT_DEBUG(!mLongPressGestureDetectors.empty());
index 4933c46..8026167 100644 (file)
@@ -88,6 +88,18 @@ public: // To be called by GestureEventProcessor
    */
   void GestureDetectorUpdated(LongPressGestureDetector* gestureDetector);
 
+  /**
+   * @brief This method sets the minimum holding time required to be recognized as a long press gesture
+   *
+   * @param[in] value The time value in milliseconds
+   */
+  void SetMinimumHoldingTime( uint32_t time );
+
+  /**
+   * @return The minimum holding time required to be recognized as a long press gesture in milliseconds
+   */
+  uint32_t GetMinimumHoldingTime() const;
+
 private:
 
   // Undefined
@@ -130,6 +142,8 @@ private:
   uint32_t mMaxTouchesRequired;
 
   const LongPressGestureEvent* mCurrentLongPressEvent; ///< Pointer to current longPressEvent, used when calling ProcessAndEmit()
+
+  uint32_t mMinimumHoldingTime;
 };
 
 } // namespace Internal
index 6e0b24d..1d5d116 100644 (file)
@@ -39,18 +39,18 @@ namespace
 {
 // TODO: Set these according to DPI
 const float MAXIMUM_MOTION_ALLOWED = 60.0f;
-// TODO: Set this time according to system setting (vconf)
-const unsigned long LONG_PRESS_TIME = 500u;
+
 } // unnamed namespace
 
-LongPressGestureRecognizer::LongPressGestureRecognizer(Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request )
+LongPressGestureRecognizer::LongPressGestureRecognizer(Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime )
 : GestureRecognizer( screenSize, Gesture::LongPress ),
   mObserver( observer ),
   mState( Clear ),
   mMinimumTouchesRequired( request.minTouches ),
   mMaximumTouchesRequired( request.maxTouches ),
   mTouchTime( 0 ),
-  mTimerId( 0 )
+  mTimerId( 0 ),
+  mMinimumHoldingTime( minimumHoldingTime )
 {
 }
 
@@ -77,7 +77,7 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 
         mTouchTime = event.time;
 
-        mTimerId = platformAbstraction.StartTimer(GetSystemValue(), MakeCallback( this, &LongPressGestureRecognizer::TimerCallback));
+        mTimerId = platformAbstraction.StartTimer( mMinimumHoldingTime, MakeCallback( this, &LongPressGestureRecognizer::TimerCallback ) );
 
         // A long press gesture may be possible, tell Core about this and change state to Touched.
         mState = Touched;
@@ -186,6 +186,12 @@ void LongPressGestureRecognizer::Update(const GestureRequest& request)
   mMaximumTouchesRequired = longPress.maxTouches;
 }
 
+void LongPressGestureRecognizer::SetMinimumHoldingTime( uint32_t time )
+{
+  mMinimumHoldingTime = time;
+}
+
+
 bool LongPressGestureRecognizer::TimerCallback()
 {
   EmitGesture(Gesture::Started);
@@ -217,7 +223,7 @@ void LongPressGestureRecognizer::EmitGesture(Gesture::State state)
     longPress.time = mTouchTime;
     if ( state != Gesture::Possible )
     {
-      longPress.time += GetSystemValue();
+      longPress.time += mMinimumHoldingTime;
     }
 
     if( mScene )
@@ -230,11 +236,6 @@ void LongPressGestureRecognizer::EmitGesture(Gesture::State state)
   }
 }
 
-int LongPressGestureRecognizer::GetSystemValue()
-{
-  return LONG_PRESS_TIME;
-}
-
 } // namespace Internal
 
 } // namespace Dali
index 7bcab05..cb2cbfa 100644 (file)
@@ -56,8 +56,9 @@ public:
    * @param[in] coreEventInterface Used to send events to Core.
    * @param[in] screenSize  The size of the screen.
    * @param[in] request     The long press gesture request.
+   * @param[in] minimumHoldingTime The minimum holding time required in milliseconds.
    */
-  LongPressGestureRecognizer( Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request );
+  LongPressGestureRecognizer( Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime );
 
   /**
    * Virtual destructor.
@@ -76,6 +77,13 @@ public:
    */
   virtual void Update(const GestureRequest& request);
 
+  /**
+   * @brief This method sets the minimum holding time required to be recognized as a long press gesture
+   *
+   * @param[in] value The time value in milliseconds
+   */
+  void SetMinimumHoldingTime( uint32_t time );
+
 private:
 
   /**
@@ -90,12 +98,6 @@ private:
    */
   void EmitGesture(Gesture::State state);
 
-  /**
-   * Get current system setting value for tap and hold gesture
-   * @return system value for tap and hold gesture [ms]
-   */
-  int GetSystemValue();
-
 private:
 
   // Reference to the gesture processor for this recognizer
@@ -121,6 +123,8 @@ private:
   uint32_t mTouchTime;               ///< The time we first pressed down.
 
   uint32_t mTimerId;
+
+  uint32_t mMinimumHoldingTime;
 };
 
 } // namespace Internal