From 4f317a4101e4a68d5b461e1b57e329fd7508821a Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Fri, 20 Dec 2019 15:51:30 +0900 Subject: [PATCH] [Tizen] Add an environment variable for long press gesture 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 --- .../src/dali/utc-Dali-LongPressGestureDetector.cpp | 37 ++++++++++++++++++++++ dali/integration-api/input-options.cpp | 6 ++++ dali/integration-api/input-options.h | 8 +++++ .../event/events/gesture-event-processor.cpp | 10 ++++++ .../event/events/gesture-event-processor.h | 12 +++++++ .../long-press-gesture-detector-impl.cpp | 5 +++ .../long-press-gesture-detector-impl.h | 5 +++ .../long-press-gesture-processor.cpp | 29 +++++++++++++++-- .../long-press-gesture-processor.h | 14 ++++++++ .../long-press-gesture-recognizer.cpp | 23 +++++++------- .../long-press-gesture-recognizer.h | 18 +++++++---- 11 files changed, 147 insertions(+), 20 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp index b7387f1..ccde1b5 100644 --- a/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include @@ -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; +} diff --git a/dali/integration-api/input-options.cpp b/dali/integration-api/input-options.cpp index 54eb9fb..b432b9e 100644 --- a/dali/integration-api/input-options.cpp +++ b/dali/integration-api/input-options.cpp @@ -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 diff --git a/dali/integration-api/input-options.h b/dali/integration-api/input-options.h index 464eff7..f4df355 100644 --- a/dali/integration-api/input-options.h +++ b/dali/integration-api/input-options.h @@ -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 diff --git a/dali/internal/event/events/gesture-event-processor.cpp b/dali/internal/event/events/gesture-event-processor.cpp index fbfad1b..04863ff 100644 --- a/dali/internal/event/events/gesture-event-processor.cpp +++ b/dali/internal/event/events/gesture-event-processor.cpp @@ -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; diff --git a/dali/internal/event/events/gesture-event-processor.h b/dali/internal/event/events/gesture-event-processor.h index a181588..9ae5d6f 100644 --- a/dali/internal/event/events/gesture-event-processor.h +++ b/dali/internal/event/events/gesture-event-processor.h @@ -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 /** diff --git a/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.cpp b/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.cpp index d7f1778..21adbe5 100644 --- a/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.cpp +++ b/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.cpp @@ -173,6 +173,11 @@ void LongPressGestureDetector::OnActorDestroyed(Object& object) // Do nothing } +uint32_t LongPressGestureDetector::GetMinimumHoldingTime() const +{ + return mGestureEventProcessor.GetLongPressMinimumHoldingTime(); +} + } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h b/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h index b049433..561012b 100644 --- a/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h +++ b/dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h @@ -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: /** diff --git a/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp b/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp index e08d7e8..b707e24 100644 --- a/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp +++ b/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp @@ -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(request)); + mGestureRecognizer = new LongPressGestureRecognizer(*this, Vector2(size.width, size.height), static_cast(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( mGestureRecognizer.Get() ); + if( longPressRecognizer ) + { + longPressRecognizer->SetMinimumHoldingTime( time ); + } + } + } +} + +uint32_t LongPressGestureProcessor::GetMinimumHoldingTime() const +{ + return mMinimumHoldingTime; +} + void LongPressGestureProcessor::UpdateDetection() { DALI_ASSERT_DEBUG(!mLongPressGestureDetectors.empty()); diff --git a/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.h b/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.h index 4933c46..8026167 100644 --- a/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.h +++ b/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.h @@ -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 diff --git a/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.cpp b/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.cpp index 6e0b24d..1d5d116 100644 --- a/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.cpp +++ b/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.cpp @@ -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 diff --git a/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.h b/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.h index 7bcab05..cb2cbfa 100644 --- a/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.h +++ b/dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.h @@ -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 -- 2.7.4