diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-01-20 17:09:48 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-01-21 15:39:17 +0300 |
commit | 6b1642cb2098db131453b36cab71526a5c2f7974 (patch) | |
tree | 75fa724fd6d1d628a97360967641ac194b982a66 | |
parent | 8d9e8da47299f7b7622e60d433a177d337396bc5 (diff) |
Route following fixed after style switching on android.
-rw-r--r-- | android/jni/com/mapswithme/maps/Framework.cpp | 5 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/routing/RoutingController.java | 3 | ||||
-rwxr-xr-x | drape_frontend/frontend_renderer.cpp | 44 | ||||
-rwxr-xr-x | drape_frontend/frontend_renderer.hpp | 24 | ||||
-rw-r--r-- | drape_frontend/user_event_stream.cpp | 28 | ||||
-rw-r--r-- | drape_frontend/user_event_stream.hpp | 1 | ||||
-rw-r--r-- | map/framework.cpp | 29 | ||||
-rw-r--r-- | map/framework.hpp | 4 |
8 files changed, 116 insertions, 22 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index fdd6bf0a09..db3476459b 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1088,7 +1088,10 @@ extern "C" JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeFollowRoute(JNIEnv * env, jclass thiz) { - frm()->FollowRoute(); + g_framework->PostDrapeTask([]() + { + frm()->FollowRoute(); + }); } JNIEXPORT void JNICALL diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index 827f48c945..cc3fb8612f 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -373,12 +373,13 @@ public class RoutingController Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_START); AlohaHelper.logClick(AlohaHelper.ROUTING_START); setState(State.NAVIGATION); - Framework.nativeFollowRoute(); mContainer.showRoutePlan(false, null); mContainer.showNavigation(true); ThemeSwitcher.restart(); + + Framework.nativeFollowRoute(); } private void suggestRebuildRoute() diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index e417f3cf71..a3e4eee4ce 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -366,6 +366,14 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message) } m_myPositionController->ActivateRouting(); +#ifdef OMIM_OS_ANDROID + if (m_pendingFollowRoute != nullptr) + { + FollowRoute(m_pendingFollowRoute->m_preferredZoomLevel, m_pendingFollowRoute->m_preferredZoomLevelIn3d, + m_pendingFollowRoute->m_rotationAngle, m_pendingFollowRoute->m_angleFOV); + m_pendingFollowRoute.reset(); + } +#endif break; } @@ -394,15 +402,21 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message) case Message::FollowRoute: { ref_ptr<FollowRouteMessage> const msg = message; - m_myPositionController->NextMode(!m_enablePerspectiveInNavigation ? msg->GetPreferredZoomLevel() - : msg->GetPreferredZoomLevelIn3d()); - m_overlayTree->SetFollowingMode(true); - if (m_enablePerspectiveInNavigation) +#ifdef OMIM_OS_ANDROID + // After night style switching on android and drape engine reinitialization FrontendRenderer + // receive FollowRoute message before FlushRoute message, so we need to postpone its processing. + if (!m_myPositionController->IsInRouting()) { - bool immediatelyStart = !m_myPositionController->IsRotationActive(); - AddUserEvent(EnablePerspectiveEvent(msg->GetRotationAngle(), msg->GetAngleFOV(), - true /* animated */, immediatelyStart)); + m_pendingFollowRoute.reset( + new FollowRouteData(msg->GetPreferredZoomLevel(), msg->GetPreferredZoomLevelIn3d(), + msg->GetRotationAngle(), msg->GetAngleFOV())); + break; } +#else + ASSERT(m_myPositionController->IsInRouting(), ()); +#endif + FollowRoute(msg->GetPreferredZoomLevel(), msg->GetPreferredZoomLevelIn3d(), + msg->GetRotationAngle(), msg->GetAngleFOV()); break; } @@ -574,6 +588,22 @@ unique_ptr<threads::IRoutine> FrontendRenderer::CreateRoutine() return make_unique<Routine>(*this); } +void FrontendRenderer::FollowRoute(int preferredZoomLevel, int preferredZoomLevelIn3d, + double rotationAngle, double angleFOV) +{ + if (m_enablePerspectiveInNavigation) + { + bool immediatelyStart = !m_myPositionController->IsRotationActive(); + AddUserEvent(EnablePerspectiveEvent(rotationAngle, angleFOV, + true /* animated */, immediatelyStart)); + } + + m_myPositionController->NextMode(!m_enablePerspectiveInNavigation ? preferredZoomLevel + : preferredZoomLevelIn3d); + m_overlayTree->SetFollowingMode(true); + +} + void FrontendRenderer::InvalidateRect(m2::RectD const & gRect) { TTilesCollection tiles; diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index 7daa76588a..8967f5cd06 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -213,6 +213,8 @@ private: using TRenderGroupRemovePredicate = function<bool(drape_ptr<RenderGroup> const &)>; void RemoveRenderGroups(TRenderGroupRemovePredicate const & predicate); + void FollowRoute(int preferredZoomLevel, int preferredZoomLevelIn3d, + double rotationAngle, double angleFOV); void InvalidateRect(m2::RectD const & gRect); bool CheckTileGenerations(TileKey const & tileKey); @@ -264,6 +266,28 @@ private: uint64_t m_maxGeneration; int m_mergeBucketsCounter = 0; +#ifdef OMIM_OS_ANDROID + struct FollowRouteData + { + FollowRouteData(int preferredZoomLevel, + int preferredZoomLevelIn3d, + double rotationAngle, + double angleFOV) + : m_preferredZoomLevel(preferredZoomLevel) + , m_preferredZoomLevelIn3d(preferredZoomLevelIn3d) + , m_rotationAngle(rotationAngle) + , m_angleFOV(angleFOV) + {} + + int m_preferredZoomLevel; + int m_preferredZoomLevelIn3d; + double m_rotationAngle; + double m_angleFOV; + }; + + unique_ptr<FollowRouteData> m_pendingFollowRoute; +#endif + #ifdef DEBUG bool m_isTeardowned; #endif diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index 127c9183cc..f3b921825e 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -193,6 +193,7 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool & } break; case UserEvent::EVENT_FOLLOW_AND_ROTATE: + m_pendingPerspective = false; breakAnim = SetFollowAndRotate(e.m_followAndRotate.m_userPos, e.m_followAndRotate.m_pixelZero, e.m_followAndRotate.m_azimuth, e.m_followAndRotate.m_preferredZoomLevel, e.m_followAndRotate.m_isAnim); @@ -200,7 +201,10 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool & break; case UserEvent::EVENT_ENABLE_PERSPECTIVE: if (!e.m_enable3dMode.m_immediatelyStart) + { + m_pendingPerspective = true; m_pendingEvent.reset(new UserEvent(e.m_enable3dMode)); + } else SetEnable3dMode(e.m_enable3dMode.m_rotationAngle, e.m_enable3dMode.m_angleFOV, e.m_enable3dMode.m_isAnim, viewportChanged); @@ -242,19 +246,19 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool & m_navigator.SetFromRect(rect); modelViewChange = true; if (m_animation->IsFinished()) - { - if (m_animation->GetType() == ModelViewAnimationType::FollowAndRotate && - m_pendingEvent != nullptr && m_pendingEvent->m_type == UserEvent::EVENT_ENABLE_PERSPECTIVE) - { - SetEnable3dMode(m_pendingEvent->m_enable3dMode.m_rotationAngle, - m_pendingEvent->m_enable3dMode.m_angleFOV, - m_pendingEvent->m_enable3dMode.m_isAnim, - viewportChanged); - - m_pendingEvent.reset(); - } m_animation.reset(); - } + } + + if (m_pendingEvent != nullptr && + m_pendingEvent->m_type == UserEvent::EVENT_ENABLE_PERSPECTIVE && + !m_pendingPerspective && m_animation == nullptr) + { + SetEnable3dMode(m_pendingEvent->m_enable3dMode.m_rotationAngle, + m_pendingEvent->m_enable3dMode.m_angleFOV, + m_pendingEvent->m_enable3dMode.m_isAnim, + viewportChanged); + modelViewChange = true; + m_pendingEvent.reset(); } if (m_perspectiveAnimation != nullptr) diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index 4b72969bd4..836c32e72b 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -368,6 +368,7 @@ private: drape_ptr<BaseModelViewAnimation> m_animation; unique_ptr<PerspectiveAnimation> m_perspectiveAnimation; + bool m_pendingPerspective = false; unique_ptr<UserEvent> m_pendingEvent; double m_discardedFOV = 0.0; double m_discardedAngle = 0.0; diff --git a/map/framework.cpp b/map/framework.cpp index 6c7d2fd9f8..82b9259c96 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -163,6 +163,10 @@ void Framework::OnLocationUpdate(GpsInfo const & info) #else GpsInfo rInfo(info); #endif + +#ifdef OMIM_OS_ANDROID + m_lastGPSInfo.reset(new GpsInfo(rInfo)); +#endif location::RouteMatchingInfo routeMatchingInfo; CheckLocationForRouting(rInfo); @@ -181,6 +185,9 @@ void Framework::OnCompassUpdate(CompassInfo const & info) CompassInfo const & rInfo = info; #endif +#ifdef OMIM_OS_ANDROID + m_lastCompassInfo.reset(new CompassInfo(rInfo)); +#endif CallDrapeFunction(bind(&df::DrapeEngine::SetCompassInfo, _1, rInfo)); } @@ -659,7 +666,18 @@ void Framework::PrepareToShutdown() void Framework::SaveState() { - Settings::Set("ScreenClipRect", m_currentModelView.GlobalRect()); + m2::AnyRectD rect; + if (m_currentModelView.isPerspective()) + { + ScreenBase modelView = m_currentModelView; + modelView.ResetPerspective(); + rect = modelView.GlobalRect(); + } + else + { + rect = m_currentModelView.GlobalRect(); + } + Settings::Set("ScreenClipRect", rect); } void Framework::LoadState() @@ -1320,6 +1338,15 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory, ActivateUserMark(mark, true); } +#ifdef OMIM_OS_ANDROID + // In case of the engine reinitialization recover compass and location data + // for correct my position state. + if (m_lastCompassInfo != nullptr) + OnCompassUpdate(*m_lastCompassInfo.release()); + if (m_lastGPSInfo != nullptr) + OnLocationUpdate(*m_lastGPSInfo.release()); +#endif + Allow3dMode(allow3d, allow3dBuildings); // In case of the engine reinitialization recover route. diff --git a/map/framework.hpp b/map/framework.hpp index 859c5a5a4a..be87f99eb2 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -276,6 +276,10 @@ private: FeatureID m_feature; }; unique_ptr<TapEventData> m_lastTapEvent; +#ifdef OMIM_OS_ANDROID + unique_ptr<location::CompassInfo> m_lastCompassInfo; + unique_ptr<location::GpsInfo> m_lastGPSInfo; +#endif void OnTapEvent(m2::PointD pxPoint, bool isLong, bool isMyPosition, FeatureID const & feature); UserMark const * OnTapEventImpl(m2::PointD pxPoint, bool isLong, bool isMyPosition, FeatureID const & feature); |