From 4553804ba4ab045258cd8e12d49ab1df84179020 Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Thu, 22 Jul 2021 17:33:32 +0900 Subject: [PATCH] Add SetTapMaximumAllowedTime Sets the MaximumAllowedTime of the tap gesture as an environment variable. Change-Id: Ic506a936171860aeb4c5e6e96fcdc9fa244c64f1 --- .../dali/utc-Dali-TapGestureRecognizer.cpp | 57 +++++++++++++++++++ dali/integration-api/input-options.cpp | 6 ++ dali/integration-api/input-options.h | 9 ++- .../event/events/gesture-event-processor.cpp | 5 ++ .../event/events/gesture-event-processor.h | 7 +++ .../tap-gesture/tap-gesture-processor.cpp | 29 +++++++++- .../tap-gesture/tap-gesture-processor.h | 9 +++ .../tap-gesture/tap-gesture-recognizer.cpp | 21 ++++--- .../tap-gesture/tap-gesture-recognizer.h | 13 ++++- 9 files changed, 143 insertions(+), 13 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp b/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp index e39e244c2..e33a21c07 100644 --- a/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp +++ b/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -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; +} diff --git a/dali/integration-api/input-options.cpp b/dali/integration-api/input-options.cpp index 3dfca89e8..e77ab701d 100644 --- a/dali/integration-api/input-options.cpp +++ b/dali/integration-api/input-options.cpp @@ -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 diff --git a/dali/integration-api/input-options.h b/dali/integration-api/input-options.h index 3789cc942..a585e03ab 100644 --- a/dali/integration-api/input-options.h +++ b/dali/integration-api/input-options.h @@ -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 diff --git a/dali/internal/event/events/gesture-event-processor.cpp b/dali/internal/event/events/gesture-event-processor.cpp index 12b3bf6bd..118c783f6 100644 --- a/dali/internal/event/events/gesture-event-processor.cpp +++ b/dali/internal/event/events/gesture-event-processor.cpp @@ -334,6 +334,11 @@ const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor() return mPanGestureProcessor; } +void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time) +{ + mTapGestureProcessor.SetMaximumAllowedTime(time); +} + } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/events/gesture-event-processor.h b/dali/internal/event/events/gesture-event-processor.h index ebef0e28b..d2b1930fc 100644 --- a/dali/internal/event/events/gesture-event-processor.h +++ b/dali/internal/event/events/gesture-event-processor.h @@ -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 diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp b/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp index 39dd060ed..085f627b1 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp +++ b/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp @@ -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(request)); + mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast(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(mGestureRecognizer.Get()); + if(tapRecognizer) + { + tapRecognizer->SetMaximumAllowedTime(time); + } + } + } +} + void TapGestureProcessor::UpdateDetection() { DALI_ASSERT_DEBUG(!mTapGestureDetectors.empty()); diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-processor.h b/dali/internal/event/events/tap-gesture/tap-gesture-processor.h index e0b5b7a18..9804679f5 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-processor.h +++ b/dali/internal/event/events/tap-gesture/tap-gesture-processor.h @@ -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 diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp index 975c847ce..b1799c17c 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp +++ b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp @@ -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) || diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h index f87d2ec82..b4fbda913 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h +++ b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h @@ -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 -- 2.34.1