From e8dd7a2c26b0803ff31116c3fa1afa9a7a4e182b Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Tue, 27 Oct 2015 21:13:27 +0300 Subject: [PATCH] Fixed location mode setting up and updating for Android --- android/jni/com/mapswithme/maps/Framework.cpp | 11 +++++-- android/jni/com/mapswithme/maps/Framework.hpp | 1 + drape_frontend/drape_engine.cpp | 17 +++------- drape_frontend/drape_engine.hpp | 6 ++-- drape_frontend/frontend_renderer.cpp | 3 -- drape_frontend/gui/button.cpp | 4 +-- drape_frontend/message_subclasses.hpp | 10 ------ drape_frontend/my_position_controller.cpp | 6 ---- drape_frontend/my_position_controller.hpp | 1 - iphone/Maps/Classes/EAGLView.mm | 1 - map/framework.cpp | 8 +++-- map/framework.hpp | 11 ++++--- platform/settings.cpp | 32 +++++++++++++++++++ 13 files changed, 63 insertions(+), 48 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index e4d81c56e7..000f4f5e51 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -60,8 +60,9 @@ enum MultiTouchAction }; Framework::Framework() - : m_lastCompass(0.0) - , m_currentMode(location::MODE_UNKNOWN_POSITION) + : m_lastCompass(0.0) + , m_currentMode(location::MODE_UNKNOWN_POSITION) + , m_isCurrentModeInitialized(false) { ASSERT_EQUAL ( g_framework, 0, () ); g_framework = this; @@ -148,8 +149,8 @@ bool Framework::CreateDrapeEngine(JNIEnv * env, jobject jSurface, int densityDpi p.m_surfaceWidth = factory->GetWidth(); p.m_surfaceHeight = factory->GetHeight(); p.m_visualScale = visualScale; + p.m_hasMyPositionState = m_isCurrentModeInitialized; p.m_initialMyPositionState = m_currentMode; - ASSERT(!m_guiPositions.empty(), ("GUI elements must be set-up before engine is created")); p.m_widgetsInitInfo = m_guiPositions; @@ -424,12 +425,16 @@ void Framework::SetMyPositionModeListener(location::TMyPositionModeChanged const location::EMyPositionMode Framework::GetMyPositionMode() const { + if (!m_isCurrentModeInitialized) + return location::MODE_UNKNOWN_POSITION; + return m_currentMode; } void Framework::SetMyPositionMode(location::EMyPositionMode mode) { m_currentMode = mode; + m_isCurrentModeInitialized = true; } void Framework::SetupWidget(gui::EWidget widget, float x, float y, dp::Anchor anchor) diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 91637ac0f7..78d34131aa 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -56,6 +56,7 @@ namespace android location::TMyPositionModeChanged m_myPositionModeSignal; location::EMyPositionMode m_currentMode; + bool m_isCurrentModeInitialized; public: Framework(); diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 41ba1afd00..bf224e3012 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -50,9 +50,9 @@ DrapeEngine::DrapeEngine(Params && params) m_textureManager = make_unique_dp(); m_threadCommutator = make_unique_dp(); - int modeValue = 0; - if (!Settings::Get(LocationStateMode, modeValue)) - modeValue = location::MODE_FOLLOW; + location::EMyPositionMode mode = params.m_initialMyPositionMode.first; + if (!params.m_initialMyPositionMode.second && !Settings::Get(LocationStateMode, mode)) + mode = location::MODE_FOLLOW; FrontendRenderer::Params frParams(make_ref(m_threadCommutator), params.m_factory, make_ref(m_textureManager), m_viewport, @@ -61,7 +61,7 @@ DrapeEngine::DrapeEngine(Params && params) bind(&DrapeEngine::TapEvent, this, _1, _2, _3, _4), bind(&DrapeEngine::UserPositionChanged, this, _1), bind(&DrapeEngine::MyPositionModeChanged, this, _1), - static_cast(modeValue)); + mode); m_frontend = make_unique_dp(frParams); @@ -193,9 +193,9 @@ void DrapeEngine::ModelViewChangedGuiThread(ScreenBase const & screen) void DrapeEngine::MyPositionModeChanged(location::EMyPositionMode mode) { + Settings::Set(LocationStateMode, mode); GetPlatform().RunOnGuiThread([this, mode]() { - Settings::Set(LocationStateMode, static_cast(mode)); if (m_myPositionModeChanged != nullptr) m_myPositionModeChanged(mode); }); @@ -290,13 +290,6 @@ void DrapeEngine::InvalidateMyPosition() MessagePriority::High); } -void DrapeEngine::SetupMyPositionMode(location::EMyPositionMode mode) -{ - m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread, - make_unique_dp(ChangeMyPositionModeMessage::TYPE_SETUP, -1, mode), - MessagePriority::High); -} - void DrapeEngine::SetMyPositionModeListener(location::TMyPositionModeChanged const & fn) { m_myPositionModeChanged = fn; diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 20c30c4814..cd99302a52 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -38,13 +38,15 @@ public: Viewport const & viewport, MapDataProvider const & model, double vs, - gui::TWidgetsInitInfo && info) + gui::TWidgetsInitInfo && info, + pair const & initialMyPositionMode) : m_factory(factory) , m_stringsBundle(stringBundle) , m_viewport(viewport) , m_model(model) , m_vs(vs) , m_info(move(info)) + , m_initialMyPositionMode(initialMyPositionMode) {} ref_ptr m_factory; @@ -53,6 +55,7 @@ public: MapDataProvider m_model; double m_vs; gui::TWidgetsInitInfo m_info; + pair m_initialMyPositionMode; }; DrapeEngine(Params && params); @@ -88,7 +91,6 @@ public: void CancelMyPosition(); void StopLocationFollow(); void InvalidateMyPosition(); - void SetupMyPositionMode(location::EMyPositionMode mode); void SetMyPositionModeListener(location::TMyPositionModeChanged const & fn); using TTapEventInfoFn = FrontendRenderer::TTapEventInfoFn; diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 94e4f21d17..5722df9b20 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -231,9 +231,6 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) ref_ptr msg = message; switch (msg->GetChangeType()) { - case ChangeMyPositionModeMessage::TYPE_SETUP: - m_myPositionController->Setup(msg->GetMode()); - break; case ChangeMyPositionModeMessage::TYPE_NEXT: m_myPositionController->NextMode(msg->GetPreferredZoomLevel()); break; diff --git a/drape_frontend/gui/button.cpp b/drape_frontend/gui/button.cpp index 640c15ca04..9c867ff090 100644 --- a/drape_frontend/gui/button.cpp +++ b/drape_frontend/gui/button.cpp @@ -23,9 +23,9 @@ void ApplyAnchor(dp::Anchor anchor, vector & vertices, flo normalOffset.x = -halfWidth; if (anchor & dp::Top) - normalOffset.x = halfHeight; + normalOffset.y = halfHeight; else if (anchor & dp::Bottom) - normalOffset.x = -halfHeight; + normalOffset.y = -halfHeight; for (Button::ButtonVertex & v : vertices) v.m_normal = v.m_normal + normalOffset; diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 740bdf9c24..92c16b3b0c 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -362,7 +362,6 @@ class ChangeMyPositionModeMessage : public Message public: enum EChangeType { - TYPE_SETUP, TYPE_NEXT, TYPE_CANCEL, TYPE_STOP_FOLLOW, @@ -379,23 +378,14 @@ public: , m_preferredZoomLevel(zoomLevel) {} - explicit ChangeMyPositionModeMessage(EChangeType changeType, int zoomLevel, - location::EMyPositionMode mode) - : m_changeType(changeType) - , m_preferredZoomLevel(zoomLevel) - , m_mode(mode) - {} - EChangeType GetChangeType() const { return m_changeType; } Type GetType() const override { return Message::ChangeMyPostitionMode; } int GetPreferredZoomLevel() const { return m_preferredZoomLevel; } - location::EMyPositionMode GetMode() const { return m_mode; } private: EChangeType const m_changeType; int m_preferredZoomLevel; - location::EMyPositionMode m_mode; }; class CompassInfoMessage : public Message diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index 3ee642035e..f69aa54f8f 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -278,12 +278,6 @@ void MyPositionController::Invalidate() } } -void MyPositionController::Setup(location::EMyPositionMode mode) -{ - SetModeInfo(ChangeMode(m_modeInfo, mode)); - Invalidate(); -} - void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, ScreenBase const & screen) { diff --git a/drape_frontend/my_position_controller.hpp b/drape_frontend/my_position_controller.hpp index 7195606120..42a913c509 100644 --- a/drape_frontend/my_position_controller.hpp +++ b/drape_frontend/my_position_controller.hpp @@ -74,7 +74,6 @@ public: void NextMode(int preferredZoomLevel = -1); void TurnOff(); void Invalidate(); - void Setup(location::EMyPositionMode mode); void OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, ScreenBase const & screen); void OnCompassUpdate(location::CompassInfo const & info, ScreenBase const & screen); diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index 6c3a0fcc4a..0800ef3d57 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -56,7 +56,6 @@ p.m_surfaceWidth = width; p.m_surfaceHeight = height; p.m_visualScale = self.contentScaleFactor; - p.m_initialMyPositionState = location::MODE_UNKNOWN_POSITION; [self.widgetsManager setupWidgets:p]; GetFramework().CreateDrapeEngine(make_ref(m_factory), move(p)); diff --git a/map/framework.cpp b/map/framework.cpp index b371e4ed10..03948b6d2f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1247,7 +1247,8 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, df::MapDataProvider(idReadFn, featureReadFn, updateCountryIndex, isCountryLoadedFn, downloadMapFn, downloadMapWithoutRoutingFn, downloadRetryFn), params.m_visualScale, - move(params.m_widgetsInitInfo)); + move(params.m_widgetsInitInfo), + make_pair(params.m_initialMyPositionState, params.m_hasMyPositionState)); m_drapeEngine = make_unique_dp(move(p)); AddViewportListener([this](ScreenBase const & screen) @@ -1259,7 +1260,7 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, OnSize(params.m_surfaceWidth, params.m_surfaceHeight); m_drapeEngine->SetMyPositionModeListener(m_myPositionListener); - m_drapeEngine->SetupMyPositionMode(params.m_initialMyPositionState); + m_drapeEngine->InvalidateMyPosition(); m_bmManager.InitBookmarks(); @@ -1275,7 +1276,8 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, { UserMark const * mark = OnTapEventImpl(m_lastTapEvent->m_pxPoint, m_lastTapEvent->m_isLong, m_lastTapEvent->m_isMyPosition, m_lastTapEvent->m_feature); - ActivateUserMark(mark, true); + if (mark != nullptr) + ActivateUserMark(mark, true); } // In case of the engine reinitialization recover route. diff --git a/map/framework.hpp b/map/framework.hpp index e1e284e4b3..8a06d06abb 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -296,12 +296,13 @@ private: public: struct DrapeCreationParams { - float m_visualScale; - int m_surfaceWidth; - int m_surfaceHeight; - + float m_visualScale = 1.0f; + int m_surfaceWidth = 0; + int m_surfaceHeight = 0; gui::TWidgetsInitInfo m_widgetsInitInfo; - location::EMyPositionMode m_initialMyPositionState; + + bool m_hasMyPositionState = false; + location::EMyPositionMode m_initialMyPositionState = location::MODE_UNKNOWN_POSITION; }; void CreateDrapeEngine(ref_ptr contextFactory, DrapeCreationParams && params); diff --git a/platform/settings.cpp b/platform/settings.cpp index 646ee6af62..3cbf97ca72 100644 --- a/platform/settings.cpp +++ b/platform/settings.cpp @@ -2,6 +2,7 @@ #include "platform.hpp" #include "defines.hpp" +#include "location.hpp" #include "coding/reader_streambuf.hpp" #include "coding/file_writer.hpp" @@ -336,6 +337,37 @@ namespace Settings return true; } + template <> string ToString(location::EMyPositionMode const & v) + { + switch (v) + { + case location::MODE_UNKNOWN_POSITION: return "Unknown"; + case location::MODE_PENDING_POSITION: return "Pending"; + case location::MODE_NOT_FOLLOW: return "NotFollow"; + case location::MODE_FOLLOW: return "Follow"; + case location::MODE_ROTATE_AND_FOLLOW: return "RotateAndFollow"; + default: return "Unknown"; + } + } + + template <> bool FromString(string const & s, location::EMyPositionMode & v) + { + if (s == "Unknown") + v = location::MODE_UNKNOWN_POSITION; + else if (s == "Pending") + v = location::MODE_PENDING_POSITION; + else if (s == "NotFollow") + v = location::MODE_NOT_FOLLOW; + else if (s == "Follow") + v = location::MODE_FOLLOW; + else if (s == "RotateAndFollow") + v = location::MODE_ROTATE_AND_FOLLOW; + else + return false; + + return true; + } + bool IsFirstLaunchForDate(int date) { int savedDate;