Sets the MaximumAllowedTime of the tap gesture as an environment variable.
Change-Id: Ic506a936171860aeb4c5e6e96fcdc9fa244c64f1
#include <dali-test-suite-utils.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/public-api/dali-core.h>
#include <stdlib.h>
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;
+}
eventProcessor.SetLongPressMinimumHoldingTime(value);
}
+void SetTapMaximumAllowedTime(uint32_t time)
+{
+ GestureEventProcessor& eventProcessor = ThreadLocalStorage::Get().GetGestureEventProcessor();
+ eventProcessor.SetTapMaximumAllowedTime(time);
+}
+
} // namespace Integration
} // namespace Dali
#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.
*/
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
return mPanGestureProcessor;
}
+void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time)
+{
+ mTapGestureProcessor.SetMaximumAllowedTime(time);
+}
+
} // namespace Internal
} // namespace Dali
*/
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
{
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.
mMinTouchesRequired(1),
mMaxTouchesRequired(1),
mCurrentTapEvent(nullptr),
- mPossibleProcessed(false)
+ mPossibleProcessed(false),
+ mMaximumAllowedTime(DEFAULT_MAXIMUM_ALLOWED_TIME)
{
}
request.maxTouches = mMaxTouchesRequired;
Size size = scene.GetSize();
- mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const TapGestureRequest&>(request));
+ mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const TapGestureRequest&>(request), mMaximumAllowedTime);
}
else
{
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<TapGestureRecognizer*>(mGestureRecognizer.Get());
+ if(tapRecognizer)
+ {
+ tapRecognizer->SetMaximumAllowedTime(time);
+ }
+ }
+ }
+}
+
void TapGestureProcessor::UpdateDetection()
{
DALI_ASSERT_DEBUG(!mTapGestureDetectors.empty());
*/
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&);
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
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),
mTouchPosition(),
mTouchTime(0u),
mLastTapTime(0u),
- mGestureSourceType(GestureSourceType::INVALID)
+ mGestureSourceType(GestureSourceType::INVALID),
+ mMaximumAllowedTime(maximumAllowedTime)
{
}
if(pointState == PointState::UP)
{
- if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
+ if(deltaBetweenTouchDownTouchUp < mMaximumAllowedTime)
{
mLastTapTime = mTouchTime;
EmitSingleTap(event.time, point);
// 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);
if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
distanceDelta.y > MAXIMUM_MOTION_ALLOWED ||
- timeDelta > MAXIMUM_TIME_ALLOWED)
+ timeDelta > mMaximumAllowedTime)
{
SetupForTouchDown(event, point);
}
mMaximumTapsRequired = tap.maxTaps;
}
+void TapGestureRecognizer::SetMaximumAllowedTime(uint32_t time)
+{
+ mMaximumAllowedTime = time;
+}
+
void TapGestureRecognizer::EmitGesture(GestureState state, uint32_t time)
{
if((state == GestureState::CANCELLED) ||
* @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.
*/
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.
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