summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Nazarov <i.nazarov@samsung.com>2017-04-11 18:29:38 +0300
committerIgor Nazarov <i.nazarov@samsung.com>2017-04-11 18:29:38 +0300
commit4fd0cbdc289bbb30c7432f544445444deecfd4f0 (patch)
tree761a659e45e1b4741cb1958a65086f6f70823422
parent61f0077e2e34394c9c834dd956b18190cec1d8d4 (diff)
downloadgallery-4fd0cbdc289bbb30c7432f544445444deecfd4f0.tar.gz
gallery-4fd0cbdc289bbb30c7432f544445444deecfd4f0.tar.bz2
gallery-4fd0cbdc289bbb30c7432f544445444deecfd4f0.zip
TizenRefApp-8359 [Gallery] Add parsing Hold gesture into TouchParser
- Added Tap and Hold gesture to the ToouchParser; - Integrated Tap and Hold gesture into ImageGrid. Change-Id: Ie7081a8cb5ccdd08a53e236cfcc58af4880e07a8
-rw-r--r--inc/view/ImageGrid.h3
-rw-r--r--inc/view/TouchParser.h7
-rw-r--r--src/view/ImageGrid.cpp10
-rw-r--r--src/view/TouchParser.cpp38
4 files changed, 57 insertions, 1 deletions
diff --git a/inc/view/ImageGrid.h b/inc/view/ImageGrid.h
index d251b86..9c7756c 100644
--- a/inc/view/ImageGrid.h
+++ b/inc/view/ImageGrid.h
@@ -34,7 +34,8 @@ namespace gallery {
enum ItemEvent {
ITEM_EVENT_CLICK,
- ITEM_EVENT_DOUBLE_TAP
+ ITEM_EVENT_DOUBLE_TAP,
+ ITEM_EVENT_TAP_AND_HOLD
};
class Builder {
diff --git a/inc/view/TouchParser.h b/inc/view/TouchParser.h
index 98334e5..6551e3c 100644
--- a/inc/view/TouchParser.h
+++ b/inc/view/TouchParser.h
@@ -35,6 +35,7 @@ namespace gallery {
public:
void setTapHandler(TapHandler handler);
void setDoubleTapHandler(TapHandler handler);
+ void setTapAndHoldHandler(TapHandler handler);
private:
void onMouseDown(ucl::Widget &widget, void *eventInfo);
@@ -46,9 +47,15 @@ namespace gallery {
bool isFastTap(ucl::UInt curTime, int curX, int curY) const;
double calcDownDistance(int curX, int curY) const;
+ void restartHoldTimer();
+ void stopHoldTimer();
+ Eina_Bool onHoldTimer();
+
private:
TapHandler m_tapHandler;
TapHandler m_doubleTapHandler;
+ TapHandler m_tapAndHoldHandler;
+ Ecore_Timer *m_holdTimer;
ucl::UInt m_downTime;
int m_downX;
int m_downY;
diff --git a/src/view/ImageGrid.cpp b/src/view/ImageGrid.cpp
index da5b427..adb8791 100644
--- a/src/view/ImageGrid.cpp
+++ b/src/view/ImageGrid.cpp
@@ -244,6 +244,8 @@ namespace gallery {
m_touchParser = makeShared<TouchParser>(m_btn);
m_touchParser->setDoubleTapHandler(
DELEGATE(Item::onDoubleTap, this));
+ m_touchParser->setTapAndHoldHandler(
+ DELEGATE(Item::onTapAndHold, this));
}
Widget &getWidget()
@@ -402,6 +404,14 @@ namespace gallery {
}
}
+ void onTapAndHold(const int x, const int y)
+ {
+ if (isRealized()) {
+ m_imageGrid.handleItemEvent(m_realizeIndex,
+ ITEM_EVENT_TAP_AND_HOLD, x, y);
+ }
+ }
+
private:
const ImageGrid &m_imageGrid;
StyledWidget m_btn;
diff --git a/src/view/TouchParser.cpp b/src/view/TouchParser.cpp
index ed1d600..119a7eb 100644
--- a/src/view/TouchParser.cpp
+++ b/src/view/TouchParser.cpp
@@ -23,6 +23,7 @@ namespace gallery { namespace { namespace impl {
constexpr auto TAP_MOVE_THRESHOLD = 30;
constexpr auto FAST_TAP_DISTANCE = 60;
constexpr auto FAST_TAP_DELAY_MS = 300;
+ constexpr auto TAP_AND_HOLD_DELAY_SEC = (500.0 / 1000.0);
}}}
namespace gallery {
@@ -31,6 +32,7 @@ namespace gallery {
TouchParser::TouchParser(RefCountObjBase &rc, Widget &eventSource) :
RefCountAware(&rc),
+ m_holdTimer(nullptr),
m_downTime(0),
m_downX(0),
m_downY(0),
@@ -50,6 +52,7 @@ namespace gallery {
TouchParser::~TouchParser()
{
+ stopHoldTimer();
}
void TouchParser::setTapHandler(TapHandler handler)
@@ -62,6 +65,11 @@ namespace gallery {
m_doubleTapHandler = handler;
}
+ void TouchParser::setTapAndHoldHandler(TapHandler handler)
+ {
+ m_tapAndHoldHandler = handler;
+ }
+
void TouchParser::onMouseDown(Widget &widget, void *eventInfo)
{
if (m_isMouseDown) {
@@ -73,6 +81,7 @@ namespace gallery {
if (!isFastTap(e->timestamp, e->canvas.x, e->canvas.y)) {
m_tapCounter = 0;
+ restartHoldTimer();
} else if (m_doubleTapHandler && (m_tapCounter == 1)) {
m_doubleTapHandler(m_downX, m_downY);
}
@@ -92,6 +101,7 @@ namespace gallery {
const auto e = static_cast<Evas_Event_Mouse_Up *>(eventInfo);
+ stopHoldTimer();
updateIsTapPossible(e->event_flags, e->canvas.x, e->canvas.y);
if (!m_isTapPossible) {
@@ -115,6 +125,10 @@ namespace gallery {
const auto e = static_cast<Evas_Event_Mouse_Move *>(eventInfo);
updateIsTapPossible(e->event_flags, e->cur.canvas.x, e->cur.canvas.y);
+
+ if (!m_isTapPossible) {
+ stopHoldTimer();
+ }
}
void TouchParser::updateIsTapPossible(const int flags,
@@ -144,4 +158,28 @@ namespace gallery {
return sqrt(1.0 * dx * dx + 1.0 * dy * dy);
}
+
+ void TouchParser::restartHoldTimer()
+ {
+ stopHoldTimer();
+ m_holdTimer = ecore_timer_add(impl::TAP_AND_HOLD_DELAY_SEC,
+ CALLBACK_A(TouchParser::onHoldTimer), this);
+ }
+
+ void TouchParser::stopHoldTimer()
+ {
+ if (m_holdTimer) {
+ ecore_timer_del(m_holdTimer);
+ m_holdTimer = nullptr;
+ }
+ }
+
+ Eina_Bool TouchParser::onHoldTimer()
+ {
+ m_holdTimer = nullptr;
+ if (m_tapAndHoldHandler) {
+ m_tapAndHoldHandler(m_downX, m_downY);
+ }
+ return ECORE_CALLBACK_CANCEL;
+ }
}