Add an environment variable for long press gesture 42/220642/5
authorJiyun Yang <ji.yang@samsung.com>
Fri, 20 Dec 2019 06:51:30 +0000 (15:51 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Thu, 16 Jan 2020 11:40:34 +0000 (20:40 +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>
14 files changed:
automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp
dali/devel-api/events/long-press-gesture-detector-devel.cpp [new file with mode: 0644]
dali/devel-api/events/long-press-gesture-detector-devel.h [new file with mode: 0644]
dali/devel-api/file.list
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..2f9773e 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/devel-api/events/long-press-gesture-detector-devel.h>
 #include <dali-test-suite-utils.h>
 #include <test-touch-utils.h>
 
@@ -959,3 +961,36 @@ 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);
+
+  DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
+
+  Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
+  DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );
+
+  END_TEST;
+}
diff --git a/dali/devel-api/events/long-press-gesture-detector-devel.cpp b/dali/devel-api/events/long-press-gesture-detector-devel.cpp
new file mode 100644 (file)
index 0000000..6d11fb2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2020 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.
+ *
+ */
+
+// // EXTERNAL INCLUDES
+// #include <dali/public-api/events/key-event.h>
+// #include <dali/public-api/events/touch-event.h>
+// #include <dali/public-api/events/wheel-event.h>
+
+// INTERNAL INCLUDES
+#include <dali/devel-api/events/long-press-gesture-detector-devel.h>
+#include <dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h>
+
+namespace Dali
+{
+
+namespace DevelLongPressGestureDetector
+{
+
+uint32_t GetMinimumHoldingTime( LongPressGestureDetector longPressGestureDetector )
+{
+  return GetImplementation( longPressGestureDetector ).GetMinimumHoldingTime();
+}
+
+
+} // namespace DevelLongPressGestureDetector
+
+} // namespace Dali
+
diff --git a/dali/devel-api/events/long-press-gesture-detector-devel.h b/dali/devel-api/events/long-press-gesture-detector-devel.h
new file mode 100644 (file)
index 0000000..f757b21
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef DALI_LONG_PRESS_GESTURE_DETECTOR_DEVEL_H
+#define DALI_LONG_PRESS_GESTURE_DETECTOR_DEVEL_H
+
+/*
+ * Copyright (c) 2020 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/events/long-press-gesture-detector.h>
+
+namespace Dali
+{
+
+class LongPressGestureDetector;
+
+namespace DevelLongPressGestureDetector
+{
+
+/**
+ * @brief Get the minimum holding time required to be recognized as a long press gesture in milliseconds
+ *
+ * @param[in] longPressGestureDetector The target LongPressGestureDetector instance
+ * @return The time value in milliseconds
+ */
+DALI_CORE_API uint32_t GetMinimumHoldingTime( LongPressGestureDetector longPressGestureDetector );
+
+} // namespace DevelLongPressGestureDetector
+
+} // namespace Dali
+
+#endif // DALI_LONG_PRESS_GESTURE_DETECTOR_DEVEL_H
index 1631960..8a0db0e 100644 (file)
@@ -11,6 +11,7 @@ SET( devel_api_src_files
   ${devel_api_src_dir}/common/hash.cpp
   ${devel_api_src_dir}/common/stage-devel.cpp
   ${devel_api_src_dir}/events/hit-test-algorithm.cpp
+  ${devel_api_src_dir}/events/long-press-gesture-detector-devel.cpp
   ${devel_api_src_dir}/events/rotation-gesture.cpp
   ${devel_api_src_dir}/events/rotation-gesture-detector.cpp
   ${devel_api_src_dir}/events/touch-data-devel.cpp
@@ -61,6 +62,7 @@ SET( devel_api_core_common_header_files
 SET( devel_api_core_events_header_files
   ${devel_api_src_dir}/events/gesture-devel.h
   ${devel_api_src_dir}/events/hit-test-algorithm.h
+  ${devel_api_src_dir}/events/long-press-gesture-detector-devel.h
   ${devel_api_src_dir}/events/rotation-gesture.h
   ${devel_api_src_dir}/events/rotation-gesture-detector.h
   ${devel_api_src_dir}/events/touch-data-devel.h
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..d9a2914 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 )
+  {
+    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