From a29feb454b74a0bfe89c17aba990eeb9f21ee6f9 Mon Sep 17 00:00:00 2001 From: Sergey Pisarchik Date: Fri, 9 May 2014 10:09:31 +0300 Subject: [PATCH] [Tizen] Add GPS location --- platform/location.hpp | 3 +- platform/platform_tizen.cpp | 3 + tizen/MapsWithMe/.cproject | 208 +++++++++++++++++++++--- tizen/MapsWithMe/inc/MapsWithMeForm.hpp | 16 ++ tizen/MapsWithMe/manifest.xml | 2 +- tizen/MapsWithMe/src/MapsWithMeForm.cpp | 167 +++++++++++++++---- 6 files changed, 350 insertions(+), 49 deletions(-) diff --git a/platform/location.hpp b/platform/location.hpp index 814ebf87ef..16da6a0e49 100644 --- a/platform/location.hpp +++ b/platform/location.hpp @@ -20,7 +20,8 @@ namespace location EAppleNative, EWindowsNative, EAndroidNative, - EGoogle + EGoogle, + ETizen }; /// Our structure ALWAYS has valid lat, lon and horizontal accuracy. diff --git a/platform/platform_tizen.cpp b/platform/platform_tizen.cpp index 694843fb4b..e70c619eb5 100644 --- a/platform/platform_tizen.cpp +++ b/platform/platform_tizen.cpp @@ -38,6 +38,9 @@ Platform::Platform() LOG(LDEBUG, ("Tmp directory:", m_tmpDir)); LOG(LDEBUG, ("Settings directory:", m_settingsDir)); LOG(LDEBUG, ("Client ID:", UniqueClientId())); + + m_flags[HAS_BOOKMARKS] = true; + m_flags[HAS_ROTATION] = true; } int Platform::CpuCores() const diff --git a/tizen/MapsWithMe/.cproject b/tizen/MapsWithMe/.cproject index d8f15e26bc..5db0752fee 100644 --- a/tizen/MapsWithMe/.cproject +++ b/tizen/MapsWithMe/.cproject @@ -5,6 +5,9 @@ + + + @@ -126,25 +129,25 @@ @@ -451,6 +454,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tizen/MapsWithMe/inc/MapsWithMeForm.hpp b/tizen/MapsWithMe/inc/MapsWithMeForm.hpp index ec057ad6de..b351a0131e 100644 --- a/tizen/MapsWithMe/inc/MapsWithMeForm.hpp +++ b/tizen/MapsWithMe/inc/MapsWithMeForm.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "../../../std/vector.hpp" class MapsWithMeApp; @@ -10,6 +11,7 @@ class MapsWithMeForm : public Tizen::Ui::Controls::Form , public Tizen::Ui::ITouchEventListener , public Tizen::Ui::IActionEventListener + , public Tizen::Locations::ILocationProviderListener { public: MapsWithMeForm(MapsWithMeApp* pApp); @@ -19,6 +21,7 @@ public: bool Initialize(void); virtual result OnInitializing(void); + // ITouchEventListener virtual void OnTouchFocusIn (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo); @@ -35,8 +38,21 @@ public: const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo); + // IActionEventListener virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + + // ILocationProviderListener + virtual void OnLocationUpdated(const Tizen::Locations::Location& location); + virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus status); + virtual void OnAccuracyChanged(Tizen::Locations::LocationAccuracy accuracy); private: + + bool m_locationEnabled; std::vector > m_prev_pts; + static const int ID_BUTTON = 101; + + Tizen::Locations::LocationProvider * m_pLocProvider; + Tizen::Ui::Controls::Label * m_pLabel; + Tizen::Ui::Controls::Button * m_pButton; MapsWithMeApp* m_pApp; }; diff --git a/tizen/MapsWithMe/manifest.xml b/tizen/MapsWithMe/manifest.xml index add8532982..1af8598125 100644 --- a/tizen/MapsWithMe/manifest.xml +++ b/tizen/MapsWithMe/manifest.xml @@ -10,7 +10,7 @@ 2.2 http://tizen.org/privilege/http - http://tizen.org/privilege/download + http://tizen.org/privilege/location diff --git a/tizen/MapsWithMe/src/MapsWithMeForm.cpp b/tizen/MapsWithMe/src/MapsWithMeForm.cpp index 4dbbf5d503..525e515021 100644 --- a/tizen/MapsWithMe/src/MapsWithMeForm.cpp +++ b/tizen/MapsWithMe/src/MapsWithMeForm.cpp @@ -3,6 +3,7 @@ #include "Framework.hpp" #include "../../../map/framework.hpp" #include "../../../gui/controller.hpp" +#include "../../../platform/tizen_string_utils.hpp" #include #include #include @@ -15,15 +16,24 @@ using namespace Tizen::Media; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Base::Utility; +using namespace Tizen::Locations; MapsWithMeForm::MapsWithMeForm(MapsWithMeApp* pApp) -: m_pApp(pApp) +:m_pLocProvider(0), + m_pLabel(0), + m_pButton(0), + m_pApp(pApp) { SetMultipointTouchEnabled(true); } MapsWithMeForm::~MapsWithMeForm(void) { + if (m_pLocProvider) + { + m_pLocProvider->StopLocationUpdates(); + delete m_pLocProvider; + } } bool MapsWithMeForm::Initialize(void) @@ -36,11 +46,108 @@ bool MapsWithMeForm::Initialize(void) result MapsWithMeForm::OnInitializing(void) { LOG(LDEBUG, ("MapsWithMeForm::OnInitializing")); + + int width; + int height; + GetSize(width, height); + // Create a Label + m_pLabel = new (std::nothrow) Label(); + m_pLabel->Construct(Rectangle(width / 4, 10, width *3/4, 120), L"GPS off"); + m_pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE); + m_pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT); + AddControl(m_pLabel); + // Create a Button + m_pButton = new (std::nothrow) Button(); + m_pButton->Construct(Rectangle(width - 150, height -150, 100, 100)); + m_pButton->SetText(L"GPS\noff"); + m_pButton->SetActionId(ID_BUTTON); + m_pButton->AddActionEventListener(*this); + AddControl(m_pButton); + + m_locationEnabled = false; return E_SUCCESS; } void MapsWithMeForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) { + switch(actionId) + { + case ID_BUTTON: + { + ::Framework * pFramework = tizen::Framework::GetInstance(); + m_locationEnabled = !m_locationEnabled; + if (m_locationEnabled) + { + LocationCriteria criteria; +// criteria.SetAccuracy(LOC_ACCURACY_FINEST); + criteria.SetAccuracy(LOC_ACCURACY_TEN_METERS); + //criteria.SetAccuracy(LOC_ACCURACY_ANY); + m_pLocProvider = new LocationProvider(); + m_pLocProvider->Construct(criteria, *this); + int updateInterval = 1; + m_pLocProvider->StartLocationUpdatesByInterval(updateInterval); +// double distanceThreshold = 1.0; +// m_pLocProvider->StartLocationUpdatesByDistance(distanceThreshold); + m_pLabel->SetText(L"GPS ENABLED"); + m_pButton->SetText(L"GPS\nON"); + pFramework->StartLocation(); + } + else + { + m_pLocProvider->StopLocationUpdates(); + delete m_pLocProvider; + m_pLocProvider = 0; + pFramework->StopLocation(); + m_pLabel->SetText(L"GPS off"); + m_pButton->SetText(L"GPS\noff"); + } + } + break; + } + Invalidate(true); +} + +void MapsWithMeForm::OnLocationUpdated(const Tizen::Locations::Location& location) +{ + ::Framework * pFramework = tizen::Framework::GetInstance(); + location::GpsInfo info; + Coordinates const & coord = location.GetCoordinates(); + + info.m_source = location::ETizen; + long long ticks = 0; + Tizen::System::SystemTime::GetTicks(ticks); + + info.m_timestamp = ticks/1000; //!< seconds from 1st Jan 1970 + info.m_latitude = coord.GetLatitude(); //!< degrees + info.m_longitude = coord.GetLongitude(); //!< degrees + info.m_horizontalAccuracy = location.GetHorizontalAccuracy(); //!< metres + info.m_altitude = coord.GetAltitude(); //!< metres + info.m_verticalAccuracy = location.GetVerticalAccuracy(); //!< metres + info.m_course = 0; //!< positive degrees from the true North + info.m_speed = 0; + + static int count = 0; + count++; + String s = "LocationUpdated "; + s.Append(count); + s.Append("\nLat:"); + s.Append(info.m_latitude); + s.Append(" Lon:"); + s.Append(info.m_longitude); + s.Append("\nAccuracy:"); + s.Append(info.m_horizontalAccuracy); + m_pLabel->SetText(s); + pFramework->OnLocationUpdate(info); + Draw(); +} + +void MapsWithMeForm::OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus status) +{ + +} +void MapsWithMeForm::OnAccuracyChanged(Tizen::Locations::LocationAccuracy accuracy) +{ + } result MapsWithMeForm::OnDraw(void) @@ -50,27 +157,27 @@ result MapsWithMeForm::OnDraw(void) namespace detail { - std::vector > GetTouchedPoints() +std::vector > GetTouchedPoints() +{ + std::vector > res; + IListT * pList = TouchEventManager::GetInstance()->GetTouchInfoListN(); + if (pList) { - std::vector > res; - IListT * pList = TouchEventManager::GetInstance()->GetTouchInfoListN(); - if (pList) + int count = pList->GetCount(); + for (int i = 0; i < count; ++i) { - 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, pt.y)); - } - - pList->RemoveAll(); - delete pList; + TouchEventInfo * pTouchInfo; + pList->GetAt(i, pTouchInfo); + Point pt = pTouchInfo->GetCurrentPosition(); + res.push_back(std::make_pair(pt.x, pt.y)); } - return res; + + pList->RemoveAll(); + delete pList; } + return res; +} } void MapsWithMeForm::OnTouchPressed(const Tizen::Ui::Control& source, @@ -100,19 +207,23 @@ void MapsWithMeForm::OnTouchMoved(const Tizen::Ui::Control& source, if (!pFramework->GetGuiController()->OnTapMoved(m2::PointD(pts[0].first, pts[0].second))) { - if (pts.size() == 1) + 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) { - if (m_prev_pts.size() > 1) - { - pFramework->DoScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); - } - else if (!m_prev_pts.empty()) - { - 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)); - } + pFramework->DoScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second)); } } std::swap(m_prev_pts, pts); @@ -131,7 +242,7 @@ void MapsWithMeForm::OnTouchReleased(const Tizen::Ui::Control& source, 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)); + 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)); }