From 064bd72d4eec9546cabed61daa398c9db0308a9d Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Mon, 18 Feb 2019 17:50:54 +0300 Subject: [PATCH] [power_managment] traffic jams and gps tracking for traffic are supported. --- .../src/com/mapswithme/maps/MwmActivity.java | 82 ++++++++----------- map/framework.cpp | 11 ++- map/framework.hpp | 4 +- map/routing_manager.cpp | 5 ++ map/routing_manager.hpp | 13 ++- 5 files changed, 61 insertions(+), 54 deletions(-) diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 4da0aa6eb4..66616bd22b 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -195,7 +195,8 @@ public class MwmActivity extends BaseMwmFragmentActivity private RoutingPlanInplaceController mRoutingPlanInplaceController; - @Nullable + @SuppressWarnings("NullableProblems") + @NonNull private NavigationController mNavigationController; private MainMenu mMainMenu; @@ -525,6 +526,8 @@ public class MwmActivity extends BaseMwmFragmentActivity } mNavigationController = new NavigationController(this); + TrafficManager.INSTANCE.attach(mNavigationController); + initMainMenu(); initOnmapDownloader(); initPositionChooser(); @@ -689,6 +692,7 @@ public class MwmActivity extends BaseMwmFragmentActivity TrafficButton traffic = new TrafficButton(trafficBtn); View subway = frame.findViewById(R.id.subway); mToggleMapLayerController = new MapLayerCompositeController(traffic, subway, this); + mToggleMapLayerController.attachCore(); } public boolean closePlacePage() @@ -823,8 +827,7 @@ public class MwmActivity extends BaseMwmFragmentActivity fragment.saveRoutingPanelState(outState); } - if (mNavigationController != null) - mNavigationController.onSaveState(outState); + mNavigationController.onSaveState(outState); RoutingController.get().onSaveState(); outState.putBoolean(EXTRA_LOCATION_DIALOG_IS_ANNOYING, mLocationErrorDialogAnnoying); @@ -869,8 +872,7 @@ public class MwmActivity extends BaseMwmFragmentActivity if (!mIsTabletLayout && RoutingController.get().isPlanning()) mRoutingPlanInplaceController.restoreState(savedInstanceState); - if (mNavigationController != null) - mNavigationController.onRestoreState(savedInstanceState); + mNavigationController.onRestoreState(savedInstanceState); if (mNavMyPosition != null) mNavMyPosition.onRestoreState(savedInstanceState); @@ -1176,8 +1178,9 @@ public class MwmActivity extends BaseMwmFragmentActivity }); if (mOnmapDownloader != null) mOnmapDownloader.onResume(); - if (mNavigationController != null) - mNavigationController.onResume(); + + mNavigationController.onResume(); + if (mNavAnimationController != null) mNavAnimationController.onResume(); mPlacePageController.onActivityResumed(this); @@ -1231,9 +1234,6 @@ public class MwmActivity extends BaseMwmFragmentActivity RoutingController.get().attach(this); if (MapFragment.nativeIsEngineCreated()) LocationHelper.INSTANCE.attach(this); - mToggleMapLayerController.attachCore(); - if (mNavigationController != null) - TrafficManager.INSTANCE.attach(mNavigationController); mPlacePageController.onActivityStarted(this); } @@ -1247,8 +1247,6 @@ public class MwmActivity extends BaseMwmFragmentActivity BookmarkManager.INSTANCE.removeCatalogListener(this); LocationHelper.INSTANCE.detach(!isFinishing()); RoutingController.get().detach(); - TrafficManager.INSTANCE.detachAll(); - mToggleMapLayerController.detachCore(); mPlacePageController.onActivityStopped(this); } @@ -1260,8 +1258,10 @@ public class MwmActivity extends BaseMwmFragmentActivity mAdsRemovalPurchaseController.destroy(); if (mBookmarkPurchaseController != null) mBookmarkPurchaseController.destroy(); - if (mNavigationController != null) - mNavigationController.destroy(); + + mNavigationController.destroy(); + mToggleMapLayerController.detachCore(); + TrafficManager.INSTANCE.detachAll(); mPlacePageController.destroy(); } @@ -1406,8 +1406,9 @@ public class MwmActivity extends BaseMwmFragmentActivity private BaseMenu getCurrentMenu() { - return (RoutingController.get().isNavigating() && mNavigationController != null - ? mNavigationController.getNavMenu() : mMainMenu); + return (RoutingController.get().isNavigating() + ? mNavigationController.getNavMenu() + : mMainMenu); } private void setFullscreen(boolean isFullscreen) @@ -1677,16 +1678,12 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public void run() { - if (mNavigationController != null) - { mNavigationController.showSearchButtons(RoutingController.get().isPlanning() || RoutingController.get().isBuilt()); - } if (RoutingController.get().isNavigating()) { - if (mNavigationController != null) - mNavigationController.show(true); + mNavigationController.show(true); mSearchController.hide(); mMainMenu.setState(MainMenu.State.NAVIGATION, false, mIsFullscreen); return; @@ -1900,8 +1897,7 @@ public class MwmActivity extends BaseMwmFragmentActivity showAddStartOrFinishFrame(RoutingController.get(), false); int width = UiUtils.dimen(R.dimen.panel_width); adjustTraffic(width, UiUtils.getStatusBarHeight(getApplicationContext())); - if (mNavigationController != null) - mNavigationController.adjustSearchButtons(width); + mNavigationController.adjustSearchButtons(width); } else { @@ -1916,8 +1912,7 @@ public class MwmActivity extends BaseMwmFragmentActivity { adjustCompassAndTraffic(UiUtils.getStatusBarHeight(getApplicationContext())); setNavButtonsTopLimit(0); - if (mNavigationController != null) - mNavigationController.adjustSearchButtons(0); + mNavigationController.adjustSearchButtons(0); } else { @@ -1925,9 +1920,7 @@ public class MwmActivity extends BaseMwmFragmentActivity } closeAllFloatingPanels(); - - if (mNavigationController != null) - mNavigationController.resetSearchWheel(); + mNavigationController.resetSearchWheel(); if (completionListener != null) completionListener.run(); @@ -1997,8 +1990,7 @@ public class MwmActivity extends BaseMwmFragmentActivity { // TODO: // mPlacePage.refreshViews(); - if (mNavigationController != null) - mNavigationController.show(show); + mNavigationController.show(show); refreshFade(); if (mOnmapDownloader != null) mOnmapDownloader.updateState(false); @@ -2059,8 +2051,7 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public void onNavigationCancelled() { - if (mNavigationController != null) - mNavigationController.stop(this); + mNavigationController.stop(this); updateSearchBar(); ThemeSwitcher.restart(isMapRendererActive()); } @@ -2089,8 +2080,7 @@ public class MwmActivity extends BaseMwmFragmentActivity if (!RoutingController.get().isPlanning()) return; - if (mNavigationController != null) - mNavigationController.resetSearchWheel(); + mNavigationController.resetSearchWheel(); } @Override @@ -2122,8 +2112,7 @@ public class MwmActivity extends BaseMwmFragmentActivity if (!RoutingController.get().isNavigating()) return; - if (mNavigationController != null) - mNavigationController.update(Framework.nativeGetRouteFollowingInfo()); + mNavigationController.update(Framework.nativeGetRouteFollowingInfo()); TtsPlayer.INSTANCE.playTurnNotifications(getApplicationContext()); } @@ -2132,8 +2121,7 @@ public class MwmActivity extends BaseMwmFragmentActivity public void onCompassUpdated(@NonNull CompassData compass) { MapFragment.nativeCompassUpdated(compass.getMagneticNorth(), compass.getTrueNorth(), false); - if (mNavigationController != null) - mNavigationController.updateNorth(compass.getNorth()); + mNavigationController.updateNorth(compass.getNorth()); } @Override @@ -2151,23 +2139,20 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public void onTranslationChanged(float translation) { - if (mNavigationController != null) - mNavigationController.updateSearchButtonsTranslation(translation); + mNavigationController.updateSearchButtonsTranslation(translation); } @Override public void onFadeInZoomButtons() { - if (mNavigationController != null - && (RoutingController.get().isPlanning() || RoutingController.get().isNavigating())) + if (RoutingController.get().isPlanning() || RoutingController.get().isNavigating()) mNavigationController.fadeInSearchButtons(); } @Override public void onFadeOutZoomButtons() { - if (mNavigationController != null - && (RoutingController.get().isPlanning() || RoutingController.get().isNavigating())) + if (RoutingController.get().isPlanning() || RoutingController.get().isNavigating()) { if (UiUtils.isLandscape(this)) mToggleMapLayerController.hide(); @@ -2255,12 +2240,9 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public void onSearchRoutePoint(@RoutePointInfo.RouteMarkType int pointType) { - if (mNavigationController != null) - { - RoutingController.get().waitForPoiPick(pointType); - mNavigationController.performSearchClick(); - Statistics.INSTANCE.trackRoutingTooltipEvent(pointType, true); - } + RoutingController.get().waitForPoiPick(pointType); + mNavigationController.performSearchClick(); + Statistics.INSTANCE.trackRoutingTooltipEvent(pointType, true); } @Override diff --git a/map/framework.cpp b/map/framework.cpp index 54977cb166..fd5a9e5385 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -415,7 +415,8 @@ Framework::Framework(FrameworkParams const & params) [this]() -> DataSource & { return m_model.GetDataSource(); }, [this]() -> storage::CountryInfoGetter & { return GetCountryInfoGetter(); }, [this](string const & id) -> string { return m_storage.GetParentIdFor(id); }, - [this]() -> StringsBundle const & { return m_stringsBundle; }), + [this]() -> StringsBundle const & { return m_stringsBundle; }, + [this]() -> power_management::PowerManager const & { return m_powerManager; }), static_cast(*this)) , m_trafficManager(bind(&Framework::GetMwmsByRect, this, _1, false /* rough */), kMaxTrafficCacheSizeBytes, m_routingManager.RoutingSession()) @@ -3792,6 +3793,14 @@ void Framework::OnPowerFacilityChanged(power_management::Facility const facility Allow3dMode(allow3d, allow3dBuildings); } + else if (facility == power_management::Facility::TrafficJams) + { + auto trafficState = enabled && LoadTrafficEnabled(); + if (trafficState == GetTrafficManager().IsEnabled()) + return; + + GetTrafficManager().SetEnabled(trafficState); + } } TipsApi const & Framework::GetTipsApi() const diff --git a/map/framework.hpp b/map/framework.hpp index 412aea61e6..0795ccda57 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -230,6 +230,9 @@ protected: bool m_isRenderingEnabled; + // Note. |m_powerManager| should be declared before |m_routingManager| + power_management::PowerManager m_powerManager; + TransitReadManager m_transitManager; // Note. |m_routingManager| should be declared before |m_trafficManager| @@ -904,7 +907,6 @@ private: std::unique_ptr m_purchase; TipsApi m_tipsApi; notifications::NotificationManager m_notificationManager; - power_management::PowerManager m_powerManager; public: TipsApi const & GetTipsApi() const; diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index 5f601b09e4..886f048ad1 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -1,6 +1,7 @@ #include "routing_manager.hpp" #include "map/chart_generator.hpp" +#include "map/power_management/power_manager.hpp" #include "map/routing_mark.hpp" #include "private.h" @@ -1092,6 +1093,10 @@ bool RoutingManager::GenerateRouteAltitudeChart(uint32_t width, uint32_t height, bool RoutingManager::IsTrackingReporterEnabled() const { + auto const & pm = m_callbacks.m_powerManagerGetter(); + if (!pm.IsFacilityEnabled(power_management::Facility::GpsTrackingForTraffic)) + return false; + if (m_currentRouterType != RouterType::Vehicle) return false; diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp index d99bb30ed2..09e1ed2caf 100644 --- a/map/routing_manager.hpp +++ b/map/routing_manager.hpp @@ -44,6 +44,11 @@ class NumMwmIds; class DataSource; +namespace power_management +{ + class PowerManager; +} + struct RoutePointInfo { std::string m_name; @@ -72,16 +77,19 @@ public: using CountryInfoGetterFn = std::function; using CountryParentNameGetterFn = std::function; using GetStringsBundleFn = std::function; + using PowerManagerGetter = std::function; template + typename CountryParentNameGetter, typename StringsBundleGetter, + typename PowerManagerGetter> Callbacks(DataSourceGetter && dataSourceGetter, CountryInfoGetter && countryInfoGetter, CountryParentNameGetter && countryParentNameGetter, - StringsBundleGetter && stringsBundleGetter) + StringsBundleGetter && stringsBundleGetter, PowerManagerGetter && powerManagerGetter) : m_dataSourceGetter(std::forward(dataSourceGetter)) , m_countryInfoGetter(std::forward(countryInfoGetter)) , m_countryParentNameGetterFn(std::forward(countryParentNameGetter)) , m_stringsBundleGetter(std::forward(stringsBundleGetter)) + , m_powerManagerGetter(std::forward(powerManagerGetter)) { } @@ -89,6 +97,7 @@ public: CountryInfoGetterFn m_countryInfoGetter; CountryParentNameGetterFn m_countryParentNameGetterFn; GetStringsBundleFn m_stringsBundleGetter; + PowerManagerGetter m_powerManagerGetter; }; using RouteBuildingCallback =