diff --git a/tizen/MapsWithMe/inc/MapsWithMeForm.hpp b/tizen/MapsWithMe/inc/MapsWithMeForm.hpp index b2832fdf2b..6ef2b31cb1 100644 --- a/tizen/MapsWithMe/inc/MapsWithMeForm.hpp +++ b/tizen/MapsWithMe/inc/MapsWithMeForm.hpp @@ -3,8 +3,8 @@ #include #include #include -#include "../../../std/vector.hpp" #include "../../../map/user_mark.hpp" +#include "TouchProcessor.hpp" namespace tizen { @@ -44,16 +44,13 @@ public: Tizen::Ui::TouchEventInfo const & touchInfo){} virtual void OnTouchMoved (Tizen::Ui::Control const & source, Tizen::Graphics::Point const & currentPosition, - Tizen::Ui::TouchEventInfo const & touchInfo); + Tizen::Ui::TouchEventInfo const & touchInfo){} virtual void OnTouchPressed (Tizen::Ui::Control const & source, Tizen::Graphics::Point const & currentPosition, Tizen::Ui::TouchEventInfo const & touchInfo); virtual void OnTouchReleased (Tizen::Ui::Control const & source, Tizen::Graphics::Point const & currentPosition, - Tizen::Ui::TouchEventInfo const & touchInfo); - virtual void OnTouchLongPressed(Tizen::Ui::Control const & source, - Tizen::Graphics::Point const & currentPosition, - Tizen::Ui::TouchEventInfo const & touchInfo); + Tizen::Ui::TouchEventInfo const & touchInfo){} // IActionEventListener virtual void OnActionPerformed(Tizen::Ui::Control const & source, int actionId); @@ -118,7 +115,6 @@ public: private: bool m_locationEnabled; - std::vector > m_prev_pts; enum EEventIDs { @@ -154,6 +150,5 @@ private: tizen::Framework * m_pFramework; - bool m_wasLongPress; - pair m_startTouchPoint; + TouchProcessor m_touchProcessor; }; diff --git a/tizen/MapsWithMe/inc/TouchProcessor.cpp b/tizen/MapsWithMe/inc/TouchProcessor.cpp new file mode 100644 index 0000000000..804a1baefb --- /dev/null +++ b/tizen/MapsWithMe/inc/TouchProcessor.cpp @@ -0,0 +1,152 @@ +#include "TouchProcessor.hpp" +#include "MapsWithMeForm.hpp" +#include "Framework.hpp" + +#include "../../../map/framework.hpp" +#include "../../../gui/controller.hpp" + +#include +#include + +using namespace Tizen::Ui; +using Tizen::Ui::TouchEventManager; +using namespace Tizen::Graphics; +using Tizen::Base::Collection::IListT; + +namespace detail +{ +typedef vector > TPointPairs; + +TPointPairs GetTouchedPoints(Rectangle const & rect) +{ + TPointPairs res; + IListT * pList = TouchEventManager::GetInstance()->GetTouchInfoListN(); + if (pList) + { + int count = pList->GetCount(); + for (int i = 0; i < count; ++i) + { + TouchEventInfo * pTouchInfo; + pList->GetAt(i, pTouchInfo); + Point pt = pTouchInfo->GetCurrentPosition(); + res.push_back(std::make_pair(pt.x - rect.x, pt.y - rect.y)); + } + + pList->RemoveAll(); + delete pList; + } + return res; +} +} + +using namespace detail; + + +TouchProcessor::TouchProcessor(MapsWithMeForm * pForm) +:m_pForm(pForm) +{ + +} +void TouchProcessor::OnTouchPressed(Tizen::Ui::Control const & source, + Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo) +{ + + m_wasLongPress = false; + TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds()); + ::Framework * pFramework = tizen::Framework::GetInstance(); + // pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(pts[0].first, pts[0].second), false)); + + m_startTouchPoint = make_pair(pts[0].first, pts[0].second); + if (!pFramework->GetGuiController()->OnTapStarted(m2::PointD(pts[0].first, pts[0].second))) + { + if (pts.size() == 1) + pFramework->StartDrag(DragEvent(pts[0].first, pts[0].second)); + else if (pts.size() > 1) + pFramework->StartScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); + } + + std::swap(m_prev_pts, pts); +} + +void TouchProcessor::OnTouchLongPressed(Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo) +{ + m_wasLongPress = true; + TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds()); + if (pts.size() > 0) + { + ::Framework * pFramework = tizen::Framework::GetInstance(); + pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(pts[0].first, pts[0].second), true)); + } +} + +void TouchProcessor::OnTouchDoublePressed(Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo) +{ + ::Framework * pFramework = tizen::Framework::GetInstance(); + pFramework->ScaleDefault(true); + +} + +void TouchProcessor::OnTouchMoved(Tizen::Ui::Control const & source, + Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo) +{ + TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds()); + ::Framework * pFramework = tizen::Framework::GetInstance(); + + if (!pFramework->GetGuiController()->OnTapMoved(m2::PointD(pts[0].first, pts[0].second))) + { + if (pts.size() == 1 && m_prev_pts.size() > 1) + { + pFramework->StopScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); + pFramework->StartDrag(DragEvent(pts[0].first, pts[0].second)); + } + else if (pts.size() == 1) + { + pFramework->DoDrag(DragEvent(pts[0].first, pts[0].second)); + } + else if (pts.size() > 1 && m_prev_pts.size() == 1) + { + pFramework->StopDrag(DragEvent(m_prev_pts[0].first, m_prev_pts[0].second)); + pFramework->StartScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); + } + else if (pts.size() > 1) + { + pFramework->DoScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); + } + } + std::swap(m_prev_pts, pts); +} + +void TouchProcessor::OnTouchReleased(Tizen::Ui::Control const & source, + Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo) +{ + TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds()); + ::Framework * pFramework = tizen::Framework::GetInstance(); + + + //using prev_pts because pts contains not all points + if (!m_prev_pts.empty()) + { + pair cur = make_pair(m_prev_pts[0].first, m_prev_pts[0].second); + double dist = sqrt(pow(cur.first - m_startTouchPoint.first, 2) + pow(cur.second - m_startTouchPoint.second, 2)); + if (dist < 20 && !m_wasLongPress) + { + ::Framework * pFramework = tizen::Framework::GetInstance(); + pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(m_startTouchPoint.first, m_startTouchPoint.second), false)); + } + if (!pFramework->GetGuiController()->OnTapEnded(m2::PointD(m_prev_pts[0].first, m_prev_pts[0].second))) + { + if (m_prev_pts.size() == 1) + pFramework->StopDrag(DragEvent(m_prev_pts[0].first, m_prev_pts[0].second)); + else if (m_prev_pts.size() > 1) + pFramework->StopScale(ScaleEvent(m_prev_pts[0].first, m_prev_pts[0].second, m_prev_pts[1].first, m_prev_pts[1].second)); + } + m_prev_pts.clear(); + } +} diff --git a/tizen/MapsWithMe/inc/TouchProcessor.hpp b/tizen/MapsWithMe/inc/TouchProcessor.hpp new file mode 100644 index 0000000000..6dc26a061a --- /dev/null +++ b/tizen/MapsWithMe/inc/TouchProcessor.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include "../../../std/utility.hpp" +#include "../../../std/vector.hpp" + +class MapsWithMeForm; + +class TouchProcessor: public Tizen::Ui::ITouchEventListener +{ +public: + TouchProcessor(MapsWithMeForm * pForm); + // ITouchEventListener + virtual void OnTouchFocusIn (Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo){} + virtual void OnTouchFocusOut (Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo){} + virtual void OnTouchMoved (Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo); + virtual void OnTouchPressed (Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo); + virtual void OnTouchReleased (Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo); + virtual void OnTouchLongPressed(Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo); + virtual void OnTouchDoublePressed(Tizen::Ui::Control const & source, + Tizen::Graphics::Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo); +private: + + MapsWithMeForm * m_pForm; + + bool m_wasLongPress; + pair m_startTouchPoint; + vector > m_prev_pts; +}; diff --git a/tizen/MapsWithMe/src/FormFactory.cpp b/tizen/MapsWithMe/src/FormFactory.cpp index f66410d6f5..1d4be0a71f 100644 --- a/tizen/MapsWithMe/src/FormFactory.cpp +++ b/tizen/MapsWithMe/src/FormFactory.cpp @@ -48,7 +48,6 @@ Tizen::Ui::Controls::Form * FormFactory::CreateFormN(String const & formId, Scen { pMWMForm = new MapsWithMeForm(); pMWMForm->Initialize(); - pMWMForm->AddTouchEventListener(*pMWMForm); pSceneManager->AddSceneEventListener(sceneId, *pMWMForm); pNewForm = pMWMForm; } diff --git a/tizen/MapsWithMe/src/MapsWithMeForm.cpp b/tizen/MapsWithMe/src/MapsWithMeForm.cpp index 7b781c0d14..6551860daa 100644 --- a/tizen/MapsWithMe/src/MapsWithMeForm.cpp +++ b/tizen/MapsWithMe/src/MapsWithMeForm.cpp @@ -3,9 +3,13 @@ #include "Framework.hpp" #include "SceneRegister.hpp" #include "AppResourceId.h" +#include "Utils.hpp" +#include "Constants.hpp" +#include "UserMarkPanel.hpp" +#include "BookMarkSplitPanel.hpp" +#include "BookMarkUtils.hpp" #include "../../../map/framework.hpp" -#include "../../../map/balloon_manager.hpp" #include "../../../gui/controller.hpp" #include "../../../platform/tizen_utils.hpp" #include "../../../platform/settings.hpp" @@ -15,11 +19,6 @@ #include #include #include -#include "Utils.hpp" -#include "Constants.hpp" -#include "UserMarkPanel.hpp" -#include "BookMarkSplitPanel.hpp" -#include "BookMarkUtils.hpp" using namespace Tizen::Ui; using namespace Tizen::Ui::Controls; @@ -37,7 +36,8 @@ MapsWithMeForm::MapsWithMeForm() :m_pLocProvider(0), m_userMarkPanel(0), m_bookMarkSplitPanel(0), - m_pFramework(0) + m_pFramework(0), + m_touchProcessor(this) { SetMultipointTouchEnabled(true); } @@ -112,6 +112,8 @@ result MapsWithMeForm::OnInitializing(void) pinManager.ConnectUserMarkListener(bind(&MapsWithMeForm::OnUserMark, this, _1)); pinManager.ConnectDismissListener(bind(&MapsWithMeForm::OnDismissListener, this)); + AddTouchEventListener(m_touchProcessor); + UpdateButtons(); return E_SUCCESS; @@ -197,30 +199,8 @@ int ConverToSecondsFrom1970(DateTime const & time) return difftime(mktime(&cur_t),mktime(&y1970)); } - -typedef vector > TPointPairs; - -TPointPairs GetTouchedPoints(Rectangle const & rect) -{ - TPointPairs res; - IListT * pList = TouchEventManager::GetInstance()->GetTouchInfoListN(); - if (pList) - { - int count = pList->GetCount(); - for (int i = 0; i < count; ++i) - { - TouchEventInfo * pTouchInfo; - pList->GetAt(i, pTouchInfo); - Point pt = pTouchInfo->GetCurrentPosition(); - res.push_back(std::make_pair(pt.x - rect.x, pt.y - rect.y)); - } - - pList->RemoveAll(); - delete pList; - } - return res; -} } + using namespace detail; using bookmark::BookMarkManager; @@ -278,34 +258,6 @@ result MapsWithMeForm::OnDraw(void) return E_SUCCESS; } -void MapsWithMeForm::OnTouchPressed(Tizen::Ui::Control const & source, - Point const & currentPosition, - Tizen::Ui::TouchEventInfo const & touchInfo) -{ - if (m_splitPanelEnabled) - { - HideSplitPanel(); - } - else - { - m_wasLongPress = false; - TPointPairs pts = detail::GetTouchedPoints(GetClientAreaBounds()); - ::Framework * pFramework = tizen::Framework::GetInstance(); - // pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(pts[0].first, pts[0].second), false)); - - m_startTouchPoint = make_pair(pts[0].first, pts[0].second); - if (!pFramework->GetGuiController()->OnTapStarted(m2::PointD(pts[0].first, pts[0].second))) - { - if (pts.size() == 1) - pFramework->StartDrag(DragEvent(pts[0].first, pts[0].second)); - else if (pts.size() > 1) - pFramework->StartScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); - } - - std::swap(m_prev_pts, pts); - } -} - void MapsWithMeForm::OnUserMark(UserMarkCopy * pCopy) { BookMarkManager::GetInstance().ActivateBookMark(pCopy); @@ -314,88 +266,10 @@ void MapsWithMeForm::OnUserMark(UserMarkCopy * pCopy) void MapsWithMeForm::OnDismissListener() { - LOG(LINFO, ("OnDismissListener")); HideBookMarkPanel(); GetFramework()->ActivateUserMark(0); } -void MapsWithMeForm::OnTouchLongPressed(Tizen::Ui::Control const & source, - Tizen::Graphics::Point const & currentPosition, - Tizen::Ui::TouchEventInfo const & touchInfo) -{ - m_wasLongPress = true; - TPointPairs pts = detail::GetTouchedPoints(GetClientAreaBounds()); - if (pts.size() > 0) - { - ::Framework * pFramework = tizen::Framework::GetInstance(); - pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(pts[0].first, pts[0].second), true)); - } -} - -void MapsWithMeForm::OnTouchMoved(Tizen::Ui::Control const & source, - Point const & currentPosition, - Tizen::Ui::TouchEventInfo const & touchInfo) -{ - if (&source != this) - return; - TPointPairs pts = detail::GetTouchedPoints(GetClientAreaBounds()); - ::Framework * pFramework = tizen::Framework::GetInstance(); - - if (!pFramework->GetGuiController()->OnTapMoved(m2::PointD(pts[0].first, pts[0].second))) - { - if (pts.size() == 1 && m_prev_pts.size() > 1) - { - pFramework->StopScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); - pFramework->StartDrag(DragEvent(pts[0].first, pts[0].second)); - } - else if (pts.size() == 1) - { - pFramework->DoDrag(DragEvent(pts[0].first, pts[0].second)); - } - else if (pts.size() > 1 && m_prev_pts.size() == 1) - { - pFramework->StopDrag(DragEvent(m_prev_pts[0].first, m_prev_pts[0].second)); - pFramework->StartScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); - } - else if (pts.size() > 1) - { - pFramework->DoScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); - } - } - std::swap(m_prev_pts, pts); -} - -void MapsWithMeForm::OnTouchReleased(Tizen::Ui::Control const & source, - Point const & currentPosition, - Tizen::Ui::TouchEventInfo const & touchInfo) -{ - if (&source != this) - return; - TPointPairs pts = detail::GetTouchedPoints(GetClientAreaBounds()); - ::Framework * pFramework = tizen::Framework::GetInstance(); - - - //using prev_pts because pts contains not all points - if (!m_prev_pts.empty()) - { - pair cur = make_pair(m_prev_pts[0].first, m_prev_pts[0].second); - double dist = sqrt(pow(cur.first - m_startTouchPoint.first, 2) + pow(cur.second - m_startTouchPoint.second, 2)); - if (dist < 20 && !m_wasLongPress) - { - ::Framework * pFramework = tizen::Framework::GetInstance(); - pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(m_startTouchPoint.first, m_startTouchPoint.second), false)); - } - if (!pFramework->GetGuiController()->OnTapEnded(m2::PointD(m_prev_pts[0].first, m_prev_pts[0].second))) - { - if (m_prev_pts.size() == 1) - pFramework->StopDrag(DragEvent(m_prev_pts[0].first, m_prev_pts[0].second)); - else if (m_prev_pts.size() > 1) - pFramework->StopScale(ScaleEvent(m_prev_pts[0].first, m_prev_pts[0].second, m_prev_pts[1].first, m_prev_pts[1].second)); - } - m_prev_pts.clear(); - } -} - void MapsWithMeForm::CreateSplitPanel() { m_pSplitPanel = new SplitPanel(); @@ -522,7 +396,6 @@ void MapsWithMeForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar & sou void MapsWithMeForm::CreateSearchBar() { m_pSearchBar = static_cast(GetControl(IDC_SEARCHBAR, true)); - m_pSearchBar->AddTouchEventListener(*this); m_pSearchBar->AddSearchBarEventListener(*this); m_pSearchBar->AddTextEventListener(*this); } @@ -651,6 +524,16 @@ int MapsWithMeForm::GetItemCount(void) return 3; } +void MapsWithMeForm::OnTouchPressed(Tizen::Ui::Control const & source, + Point const & currentPosition, + Tizen::Ui::TouchEventInfo const & touchInfo) +{ + if (m_splitPanelEnabled) + { + HideSplitPanel(); + } +} + void MapsWithMeForm::OnListViewItemStateChanged(ListView & listView, int index, int elementId, ListItemStatus status) { switch (index)