Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp24
-rw-r--r--android/src/com/mapswithme/maps/Framework.java11
-rw-r--r--android/src/com/mapswithme/maps/routing/RoutingController.java88
-rw-r--r--iphone/Maps/Core/Routing/MWMRouter.mm7
-rw-r--r--map/routing_manager.cpp192
-rw-r--r--map/routing_manager.hpp9
-rw-r--r--qt/draw_widget.cpp8
7 files changed, 197 insertions, 142 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index 155ba552fd..32614b352b 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -666,6 +666,15 @@ void CallRouteRecommendationListener(shared_ptr<jobject> listener,
env->CallVoidMethod(*listener, methodId, static_cast<int>(recommendation));
}
+void CallSetRoutingLoadPointsListener(shared_ptr<jobject> listener, bool success)
+{
+ JNIEnv * env = jni::GetEnv();
+ jmethodID const methodId = jni::GetMethodID(env, *listener, "onRoutePointsLoaded", "(Z)V");
+ env->CallVoidMethod(*listener, methodId, static_cast<jboolean>(success));
+}
+
+RoutingManager::LoadRouteHandler g_loadRouteHandler;
+
/// @name JNI EXPORTS
//@{
JNIEXPORT jstring JNICALL
@@ -1160,6 +1169,17 @@ Java_com_mapswithme_maps_Framework_nativeSetRoutingRecommendationListener(JNIEnv
}
JNIEXPORT void JNICALL
+Java_com_mapswithme_maps_Framework_nativeSetRoutingLoadPointsListener(
+ JNIEnv *, jclass, jobject listener)
+{
+ CHECK(g_framework, ("Framework isn't created yet!"));
+ if (listener != nullptr)
+ g_loadRouteHandler = bind(&CallSetRoutingLoadPointsListener, jni::make_global_ref(listener), _1);
+ else
+ g_loadRouteHandler = nullptr;
+}
+
+JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeDeactivatePopup(JNIEnv * env, jclass)
{
return g_framework->DeactivatePopup();
@@ -1504,10 +1524,10 @@ Java_com_mapswithme_maps_Framework_nativeHasSavedRoutePoints()
return frm()->GetRoutingManager().HasSavedRoutePoints();
}
-JNIEXPORT jboolean JNICALL
+JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeLoadRoutePoints()
{
- return frm()->GetRoutingManager().LoadRoutePoints();
+ frm()->GetRoutingManager().LoadRoutePoints(g_loadRouteHandler);
}
JNIEXPORT void JNICALL
diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java
index 2f3474287f..81be3f0016 100644
--- a/android/src/com/mapswithme/maps/Framework.java
+++ b/android/src/com/mapswithme/maps/Framework.java
@@ -125,6 +125,12 @@ public class Framework
void onRecommend(@RouteRecommendationType int recommendation);
}
+ @SuppressWarnings("unused")
+ public interface RoutingLoadPointsListener
+ {
+ void onRoutePointsLoaded(boolean success);
+ }
+
public static class Params3dMode
{
public boolean enabled;
@@ -305,6 +311,9 @@ public class Framework
public static native void nativeSetRoutingRecommendationListener(RoutingRecommendationListener listener);
+ public static native void nativeSetRoutingLoadPointsListener(
+ @Nullable RoutingLoadPointsListener listener);
+
public static native void nativeShowCountry(String countryId, boolean zoomToDownloadButton);
public static native void nativeSetMapStyle(int mapStyle);
@@ -401,7 +410,7 @@ public class Framework
public static native int nativeInvalidRoutePointsTransactionId();
public static native boolean nativeHasSavedRoutePoints();
- public static native boolean nativeLoadRoutePoints();
+ public static native void nativeLoadRoutePoints();
public static native void nativeSaveRoutePoints();
public static native void nativeDeleteSavedRoutePoints();
diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java
index f23b51646a..c990a842b6 100644
--- a/android/src/com/mapswithme/maps/routing/RoutingController.java
+++ b/android/src/com/mapswithme/maps/routing/RoutingController.java
@@ -121,70 +121,48 @@ public class RoutingController implements TaxiManager.TaxiListener
public void onRoutingEvent(final int resultCode, @Nullable final String[] missingMaps)
{
mLogger.d(TAG, "onRoutingEvent(resultCode: " + resultCode + ")");
+ UiThread.run(() -> {
+ mLastResultCode = resultCode;
+ mLastMissingMaps = missingMaps;
+ mContainsCachedResult = true;
- UiThread.run(new Runnable()
- {
- @Override
- public void run()
+ if (mLastResultCode == ResultCodesHelper.NO_ERROR
+ || ResultCodesHelper.isMoreMapsNeeded(mLastResultCode))
{
- mLastResultCode = resultCode;
- mLastMissingMaps = missingMaps;
- mContainsCachedResult = true;
-
- if (mLastResultCode == ResultCodesHelper.NO_ERROR
- || ResultCodesHelper.isMoreMapsNeeded(mLastResultCode))
- {
- mCachedRoutingInfo = Framework.nativeGetRouteFollowingInfo();
- if (mLastRouterType == Framework.ROUTER_TYPE_TRANSIT)
- mCachedTransitRouteInfo = Framework.nativeGetTransitRouteInfo();
- setBuildState(BuildState.BUILT);
- mLastBuildProgress = 100;
- if (mContainer != null)
- mContainer.onBuiltRoute();
- }
-
- processRoutingEvent();
+ mCachedRoutingInfo = Framework.nativeGetRouteFollowingInfo();
+ if (mLastRouterType == Framework.ROUTER_TYPE_TRANSIT)
+ mCachedTransitRouteInfo = Framework.nativeGetTransitRouteInfo();
+ setBuildState(BuildState.BUILT);
+ mLastBuildProgress = 100;
+ if (mContainer != null)
+ mContainer.onBuiltRoute();
}
+
+ processRoutingEvent();
});
}
};
@SuppressWarnings("FieldCanBeLocal")
- private final Framework.RoutingProgressListener mRoutingProgressListener = new Framework.RoutingProgressListener()
- {
- @Override
- public void onRouteBuildingProgress(final float progress)
- {
- UiThread.run(new Runnable()
- {
- @Override
- public void run()
- {
- mLastBuildProgress = (int) progress;
- updateProgress();
- }
- });
- }
- };
+ private final Framework.RoutingProgressListener mRoutingProgressListener =
+ progress -> UiThread.run(() -> {
+ mLastBuildProgress = (int) progress;
+ updateProgress();
+ });
@SuppressWarnings("FieldCanBeLocal")
private final Framework.RoutingRecommendationListener mRoutingRecommendationListener =
- new Framework.RoutingRecommendationListener()
- {
- @Override
- public void onRecommend(@Framework.RouteRecommendationType final int recommendation)
- {
- UiThread.run(new Runnable()
- {
- @Override
- public void run()
- {
- if (recommendation == Framework.ROUTE_REBUILD_AFTER_POINTS_LOADING)
- setStartPoint(LocationHelper.INSTANCE.getMyPosition());
- }
- });
- }
- };
+ recommendation -> UiThread.run(() -> {
+ if (recommendation == Framework.ROUTE_REBUILD_AFTER_POINTS_LOADING)
+ setStartPoint(LocationHelper.INSTANCE.getMyPosition());
+ });
+
+ @SuppressWarnings("FieldCanBeLocal")
+ private final Framework.RoutingLoadPointsListener mRoutingLoadPointsListener =
+ success -> {
+ if (success)
+ prepare(getStartPoint(), getEndPoint());
+ };
public static RoutingController get()
{
@@ -281,6 +259,7 @@ public class RoutingController implements TaxiManager.TaxiListener
Framework.nativeSetRoutingListener(mRoutingListener);
Framework.nativeSetRouteProgressListener(mRoutingProgressListener);
Framework.nativeSetRoutingRecommendationListener(mRoutingRecommendationListener);
+ Framework.nativeSetRoutingLoadPointsListener(mRoutingLoadPointsListener);
TaxiManager.INSTANCE.setTaxiListener(this);
}
@@ -387,10 +366,7 @@ public class RoutingController implements TaxiManager.TaxiListener
public void restoreRoute()
{
if (Framework.nativeHasSavedRoutePoints())
- {
Framework.nativeLoadRoutePoints();
- prepare(getStartPoint(), getEndPoint());
- }
}
public void saveRoute()
diff --git a/iphone/Maps/Core/Routing/MWMRouter.mm b/iphone/Maps/Core/Routing/MWMRouter.mm
index 90ab885948..36db37e72f 100644
--- a/iphone/Maps/Core/Routing/MWMRouter.mm
+++ b/iphone/Maps/Core/Routing/MWMRouter.mm
@@ -708,8 +708,11 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType)
auto & rm = GetFramework().GetRoutingManager();
if ([self isRoutingActive] || !rm.HasSavedRoutePoints())
return;
- rm.LoadRoutePoints();
- [self rebuildWithBestRouter:YES];
+ rm.LoadRoutePoints([self](bool success)
+ {
+ if (success)
+ [self rebuildWithBestRouter:YES];
+ });
}
else
{
diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp
index fe276aec74..79b2d202a6 100644
--- a/map/routing_manager.cpp
+++ b/map/routing_manager.cpp
@@ -142,24 +142,12 @@ RouteMarkData DeserializeRoutePoint(json_t * node)
return data;
}
-string SerializeRoutePoints(BookmarkManager * bmManager, vector<RouteMarkData> const & points)
+string SerializeRoutePoints(vector<RouteMarkData> const & points)
{
ASSERT_GREATER_OR_EQUAL(points.size(), 2, ());
auto pointsNode = my::NewJSONArray();
-
- // Save last passed point. It will be used on points loading if my position
- // isn't determined.
- auto lastPassedPoint = GetLastPassedPoint(bmManager, points);
- auto lastPassedNode = my::NewJSONObject();
- SerializeRoutePoint(lastPassedNode.get(), lastPassedPoint);
- json_array_append_new(pointsNode.get(), lastPassedNode.release());
-
for (auto const & p : points)
{
- // Here we skip passed points and the start point.
- if (p.m_isPassed || p.m_pointType == RouteMarkType::Start)
- continue;
-
auto pointNode = my::NewJSONObject();
SerializeRoutePoint(pointNode.get(), p);
json_array_append_new(pointsNode.get(), pointNode.release());
@@ -335,6 +323,8 @@ void RoutingManager::OnRoutePointPassed(RouteMarkType type, size_t intermediateI
if (type == RouteMarkType::Finish)
RemoveRoute(false /* deactivateFollowing */);
+
+ SaveRoutePoints();
}
RouterType RoutingManager::GetBestRouter(m2::PointD const & startPoint,
@@ -447,7 +437,7 @@ void RoutingManager::InsertRoute(Route const & route)
// TODO: Now we always update whole route, so we need to remove previous one.
RemoveRoute(false /* deactivateFollowing */);
- std::shared_ptr<TransitRouteDisplay> transitRouteDisplay;
+ shared_ptr<TransitRouteDisplay> transitRouteDisplay;
auto numMwmIds = make_shared<NumMwmIds>();
if (m_currentRouterType == RouterType::Transit)
{
@@ -555,7 +545,7 @@ void RoutingManager::InsertRoute(Route const & route)
if (m_currentRouterType == RouterType::Transit)
{
- GetPlatform().RunTask(Platform::Thread::Gui, [transitRouteDisplay = std::move(transitRouteDisplay)]()
+ GetPlatform().RunTask(Platform::Thread::Gui, [transitRouteDisplay = move(transitRouteDisplay)]()
{
transitRouteDisplay->CreateTransitMarks();
});
@@ -973,11 +963,11 @@ void RoutingManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine, bool is3dAl
symbols.push_back(typePair.second + "-l");
}
m_drapeEngine.SafeCall(&df::DrapeEngine::RequestSymbolsSize, symbols,
- [this, is3dAllowed](std::map<std::string, m2::PointF> && sizes)
+ [this, is3dAllowed](map<string, m2::PointF> && sizes)
{
- GetPlatform().RunTask(Platform::Thread::Gui, [this, is3dAllowed, sizes = std::move(sizes)]() mutable
+ GetPlatform().RunTask(Platform::Thread::Gui, [this, is3dAllowed, sizes = move(sizes)]() mutable
{
- m_transitSymbolSizes = std::move(sizes);
+ m_transitSymbolSizes = move(sizes);
// In case of the engine reinitialization recover route.
if (IsRoutingActive())
@@ -1130,87 +1120,139 @@ bool RoutingManager::HasSavedRoutePoints() const
return GetPlatform().IsFileExistsByFullPath(fileName);
}
-bool RoutingManager::LoadRoutePoints()
+void RoutingManager::LoadRoutePoints(LoadRouteHandler const & handler)
{
- if (!HasSavedRoutePoints())
- return false;
+ GetPlatform().RunTask(Platform::Thread::File, [this, handler]()
+ {
+ if (!HasSavedRoutePoints())
+ {
+ if (handler)
+ handler(false /* success */);
+ return;
+ }
- // Delete file after loading.
- auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile);
- MY_SCOPE_GUARD(routePointsFileGuard, bind(&FileWriter::DeleteFileX, cref(fileName)));
+ // Delete file after loading.
+ auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile);
+ MY_SCOPE_GUARD(routePointsFileGuard, bind(&FileWriter::DeleteFileX, cref(fileName)));
- string data;
- try
- {
- ReaderPtr<Reader>(GetPlatform().GetReader(fileName)).ReadAsString(data);
- }
- catch (RootException const & ex)
- {
- LOG(LWARNING, ("Loading road points failed:", ex.Msg()));
- return false;
- }
+ string data;
+ try
+ {
+ ReaderPtr<Reader>(GetPlatform().GetReader(fileName)).ReadAsString(data);
+ }
+ catch (RootException const & ex)
+ {
+ LOG(LWARNING, ("Loading road points failed:", ex.Msg()));
+ if (handler)
+ handler(false /* success */);
+ return;
+ }
- auto points = DeserializeRoutePoints(data);
+ auto points = DeserializeRoutePoints(data);
+ if (handler && points.empty())
+ {
+ handler(false /* success */);
+ return;
+ }
+
+ GetPlatform().RunTask(Platform::Thread::Gui,
+ [this, handler, points = move(points)]() mutable
+ {
+ ASSERT(m_bmManager != nullptr, ());
+ // If we have found my position, we use my position as start point.
+ auto const & myPosMark = m_bmManager->MyPositionMark();
+ auto editSession = m_bmManager->GetEditSession();
+ editSession.ClearGroup(UserMark::Type::ROUTING);
+ for (auto & p : points)
+ {
+ if (p.m_pointType == RouteMarkType::Start && myPosMark.HasPosition())
+ {
+ RouteMarkData startPt;
+ startPt.m_pointType = RouteMarkType::Start;
+ startPt.m_isMyPosition = true;
+ startPt.m_position = myPosMark.GetPivot();
+ AddRoutePoint(move(startPt));
+ }
+ else
+ {
+ AddRoutePoint(move(p));
+ }
+ }
+
+ // If we don't have my position, save loading timestamp. Probably
+ // we will get my position soon.
+ if (!myPosMark.HasPosition())
+ m_loadRoutePointsTimestamp = chrono::steady_clock::now();
+
+ if (handler)
+ handler(true /* success */);
+ });
+ });
+}
+
+void RoutingManager::SaveRoutePoints()
+{
+ auto points = GetRoutePointsToSave();
if (points.empty())
- return false;
+ {
+ DeleteSavedRoutePoints();
+ return;
+ }
- // If we have found my position, we use my position as start point.
- auto const & myPosMark = m_bmManager->MyPositionMark();
- ASSERT(m_bmManager != nullptr, ());
- auto editSession = m_bmManager->GetEditSession();
- editSession.ClearGroup(UserMark::Type::ROUTING);
- for (auto & p : points)
+ GetPlatform().RunTask(Platform::Thread::File, [points = move(points)]()
{
- if (p.m_pointType == RouteMarkType::Start && myPosMark.HasPosition())
+ try
{
- RouteMarkData startPt;
- startPt.m_pointType = RouteMarkType::Start;
- startPt.m_isMyPosition = true;
- startPt.m_position = myPosMark.GetPivot();
- AddRoutePoint(move(startPt));
+ auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile);
+ FileWriter writer(fileName);
+ string const pointsData = SerializeRoutePoints(points);
+ writer.Write(pointsData.c_str(), pointsData.length());
}
- else
+ catch (RootException const & ex)
{
- AddRoutePoint(move(p));
+ LOG(LWARNING, ("Saving road points failed:", ex.Msg()));
}
- }
-
- // If we don't have my position, save loading timestamp. Probably
- // we will get my position soon.
- if (!myPosMark.HasPosition())
- m_loadRoutePointsTimestamp = chrono::steady_clock::now();
-
- return true;
+ });
}
-void RoutingManager::SaveRoutePoints() const
+vector<RouteMarkData> RoutingManager::GetRoutePointsToSave() const
{
auto points = GetRoutePoints();
- if (points.size() < 2)
- return;
+ if (points.size() < 2 || points.back().m_isPassed)
+ return {};
- if (points.back().m_isPassed)
- return;
+ vector<RouteMarkData> result;
+ result.reserve(points.size());
- try
- {
- auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile);
- FileWriter writer(fileName);
- string const pointsData = SerializeRoutePoints(m_bmManager, points);
- writer.Write(pointsData.c_str(), pointsData.length());
- }
- catch (RootException const & ex)
+ // Save last passed point. It will be used on points loading if my position
+ // isn't determined.
+ result.emplace_back(GetLastPassedPoint(m_bmManager, points));
+
+ for (auto & p : points)
{
- LOG(LWARNING, ("Saving road points failed:", ex.Msg()));
+ // Here we skip passed points and the start point.
+ if (p.m_isPassed || p.m_pointType == RouteMarkType::Start)
+ continue;
+
+ result.push_back(std::move(p));
}
+
+ if (result.size() < 2)
+ return {};
+
+ return result;
}
void RoutingManager::DeleteSavedRoutePoints()
{
if (!HasSavedRoutePoints())
return;
- auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile);
- FileWriter::DeleteFileX(fileName);
+
+ GetPlatform().RunTask(Platform::Thread::File, []()
+ {
+ auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile);
+ FileWriter::DeleteFileX(fileName);
+ });
}
void RoutingManager::UpdatePreviewMode()
@@ -1260,7 +1302,7 @@ TransitRouteInfo RoutingManager::GetTransitRouteInfo() const
return m_transitRouteInfo;
}
-std::vector<dp::DrapeID> RoutingManager::GetSubrouteIds() const
+vector<dp::DrapeID> RoutingManager::GetSubrouteIds() const
{
lock_guard<mutex> lock(m_drapeSubroutesMutex);
return m_drapeSubroutes;
diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp
index f19a4573fd..c1bf656960 100644
--- a/map/routing_manager.hpp
+++ b/map/routing_manager.hpp
@@ -248,10 +248,11 @@ public:
/// \returns true if there are route points saved in file and false otherwise.
bool HasSavedRoutePoints() const;
/// \brief It loads road points from file and delete file after loading.
- /// \returns true if route points loaded and false otherwise.
- bool LoadRoutePoints();
+ /// The result of the loading will be sent via SafeCallback.
+ using LoadRouteHandler = platform::SafeCallback<void(bool success)>;
+ void LoadRoutePoints(LoadRouteHandler const & handler);
/// \brief It saves route points to file.
- void SaveRoutePoints() const;
+ void SaveRoutePoints();
/// \brief It deletes file with saved route points if it exists.
void DeleteSavedRoutePoints();
@@ -278,6 +279,8 @@ private:
void CancelRecommendation(Recommendation recommendation);
+ std::vector<RouteMarkData> GetRoutePointsToSave() const;
+
RouteBuildingCallback m_routingCallback = nullptr;
RouteRecommendCallback m_routeRecommendCallback = nullptr;
Callbacks m_callbacks;
diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp
index fb001d23f5..81653b6bfa 100644
--- a/qt/draw_widget.cpp
+++ b/qt/draw_widget.cpp
@@ -157,9 +157,11 @@ void DrawWidget::initializeGL()
m_framework.LoadBookmarks();
MapWidget::initializeGL();
- auto & routingManager = m_framework.GetRoutingManager();
- if (routingManager.LoadRoutePoints())
- routingManager.BuildRoute(0 /* timeoutSec */);
+ m_framework.GetRoutingManager().LoadRoutePoints([this](bool success)
+ {
+ if (success)
+ m_framework.GetRoutingManager().BuildRoute(0 /* timeoutSec */);
+ });
}
void DrawWidget::mousePressEvent(QMouseEvent * e)