From a4eb68faf1e75d213c951a7d4d1b67727247917a Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Fri, 20 Dec 2019 15:51:30 +0900 Subject: [PATCH] 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 | 35 +++++++++++++++++ .../events/long-press-gesture-detector-devel.cpp | 42 +++++++++++++++++++++ .../events/long-press-gesture-detector-devel.h | 44 ++++++++++++++++++++++ dali/devel-api/file.list | 2 + 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 +++++---- 14 files changed, 233 insertions(+), 20 deletions(-) create mode 100644 dali/devel-api/events/long-press-gesture-detector-devel.cpp create mode 100644 dali/devel-api/events/long-press-gesture-detector-devel.h diff --git a/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-LongPressGestureDetector.cpp index b7387f1..2f9773e 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,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 index 0000000..6d11fb2 --- /dev/null +++ b/dali/devel-api/events/long-press-gesture-detector-devel.cpp @@ -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 +// #include +// #include + +// INTERNAL INCLUDES +#include +#include + +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 index 0000000..f757b21 --- /dev/null +++ b/dali/devel-api/events/long-press-gesture-detector-devel.h @@ -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 + +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 diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index 1631960..8a0db0e 100644 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -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 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..d9a2914 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 ) + { + 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