/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * 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.
// EXTERNAL INCLUDES
#include <cmath>
-#include <dali/public-api/events/touch-point.h>
+#include <dali/devel-api/events/touch-point.h>
#include <dali/public-api/math/vector2.h>
#include <dali/internal/event/common/thread-local-storage.h>
{
// 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 )
-: GestureRecognizer( screenSize, Gesture::LongPress ),
+LongPressGestureRecognizer::LongPressGestureRecognizer(Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime )
+: GestureRecognizer( screenSize, Dali::Gesture::LongPress ),
mObserver( observer ),
mState( Clear ),
mMinimumTouchesRequired( request.minTouches ),
mMaximumTouchesRequired( request.maxTouches ),
mTouchTime( 0 ),
- mTimerId( 0 )
+ mTimerId( 0 ),
+ mMinimumHoldingTime( minimumHoldingTime )
{
}
LongPressGestureRecognizer::~LongPressGestureRecognizer()
{
+ if( mTimerId != 0 && ThreadLocalStorage::Created() )
+ {
+ Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ platformAbstraction.CancelTimer(mTimerId);
+ }
}
void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
{
unsigned int pointCount( event.GetPointCount() );
Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ GestureRecognizerPtr ptr(this); // To keep us from being destroyed during the life-time of this method
switch (mState)
{
mTouchTime = event.time;
- mTimerId = platformAbstraction.StartTimer(GetSystemValue(), MakeCallback( this, &LongPressGestureRecognizer::TimerCallback));
+ if( mTimerId != 0 )
+ {
+ platformAbstraction.CancelTimer(mTimerId);
+ }
+ 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;
- EmitGesture( Gesture::Possible );
+ EmitGesture( Dali::Gesture::Possible );
}
break;
if (pointCount > mMaximumTouchesRequired)
{
// A long press did not occur, tell Core that it was cancelled and change state to Failed.
- EmitGesture( Gesture::Cancelled );
+ EmitGesture( Dali::Gesture::Cancelled );
mTouchPositions.clear();
platformAbstraction.CancelTimer(mTimerId);
+ mTimerId = 0;
mState = Failed;
break;
}
case PointState::INTERRUPTED:
{
// System has interrupted us, long press is not possible, inform Core
- EmitGesture( Gesture::Cancelled );
+ EmitGesture( Dali::Gesture::Cancelled );
mTouchPositions.clear();
platformAbstraction.CancelTimer(mTimerId);
+ mTimerId = 0;
mState = ( pointCount == 1 ) ? Clear : Failed; // Change state to Clear if only one point, Failed otherwise.
endLoop = true;
break;
if (distanceSquared > ( MAXIMUM_MOTION_ALLOWED * MAXIMUM_MOTION_ALLOWED ) )
{
// We have moved more than the allowable motion for a long press gesture. Inform Core and change state to Failed.
- EmitGesture( Gesture::Cancelled );
+ EmitGesture( Dali::Gesture::Cancelled );
platformAbstraction.CancelTimer(mTimerId);
+ mTimerId = 0;
mState = Failed;
endLoop = true;
}
if(mState == Finished)
{
// When the last touch point is lifted, we should inform the Core that the Long press has finished.
- EmitGesture(Gesture::Finished);
+ EmitGesture(Dali::Gesture::Finished);
}
mTouchPositions.clear();
mState = Clear; // Reset state to clear when last touch point is lifted.
mMaximumTouchesRequired = longPress.maxTouches;
}
+void LongPressGestureRecognizer::SetMinimumHoldingTime( uint32_t time )
+{
+ mMinimumHoldingTime = time;
+}
+
+
bool LongPressGestureRecognizer::TimerCallback()
{
- EmitGesture(Gesture::Started);
+ EmitGesture(Dali::Gesture::Started);
mState = Finished;
+ mTimerId = 0;
+
return false;
}
unsigned int touchPoints ( static_cast<unsigned int>( mTouchPositions.size() ) );
// We should tell Core about the Possible and Cancelled states regardless of whether we have satisfied long press requirements.
- if ( (state == Gesture::Possible) ||
- (state == Gesture::Cancelled) ||
+ if ( (state == Dali::Gesture::Possible) ||
+ (state == Dali::Gesture::Cancelled) ||
(touchPoints >= mMinimumTouchesRequired) )
{
LongPressGestureEvent longPress( state );
longPress.point /= static_cast<float>( touchPoints );
longPress.time = mTouchTime;
- if ( state != Gesture::Possible )
+ if ( state != Dali::Gesture::Possible )
{
- longPress.time += GetSystemValue();
+ longPress.time += mMinimumHoldingTime;
}
if( mScene )
}
}
-int LongPressGestureRecognizer::GetSystemValue()
-{
- return LONG_PRESS_TIME;
-}
-
} // namespace Internal
} // namespace Dali