From 04bd479bd66a95883ac906b1f745d19bde567b8d Mon Sep 17 00:00:00 2001 From: ExMix Date: Fri, 3 Oct 2014 21:52:11 +0300 Subject: [PATCH] [core, android] button "go" and core support for it --- android/jni/com/mapswithme/maps/Framework.cpp | 10 ++++- .../src/com/mapswithme/maps/Framework.java | 3 +- .../src/com/mapswithme/maps/MWMActivity.java | 11 ++++-- iphone/Maps/Classes/MapViewController.mm | 2 +- map/framework.cpp | 18 ++++++++- map/framework.hpp | 3 +- map/location_state.cpp | 18 +++++++-- map/location_state.hpp | 3 +- map/navigator.cpp | 38 +++++++++++-------- qt/draw_widget.cpp | 12 +++++- qt/mainwindow.cpp | 1 + 11 files changed, 88 insertions(+), 31 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index b0f98e5129..162f6a4e5d 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1129,9 +1129,15 @@ extern "C" } JNIEXPORT void JNICALL - Java_com_mapswithme_maps_Framework_nativeStartRoutingSession(JNIEnv * env, jclass thiz, jdouble lat, jdouble lon) + Java_com_mapswithme_maps_Framework_nativeBuildRoute(JNIEnv * env, jclass thiz, jdouble lat, jdouble lon) { - g_framework->NativeFramework()->StartRoutingSession(MercatorBounds::FromLatLon(lat, lon)); + g_framework->NativeFramework()->BuildRoute(MercatorBounds::FromLatLon(lat, lon)); + } + + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_Framework_nativeStartRoutingSession(JNIEnv * env, jclass thiz) + { + return g_framework->NativeFramework()->StartRoutingSession(); } JNIEXPORT jobject JNICALL diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index bd0b58474a..29cc21f4a0 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -131,7 +131,8 @@ public class Framework public native static void nativeCancelRoutingSession(); - public native static void nativeStartRoutingSession(double lat, double lon); + public native static void nativeBuildRoute(double lat, double lon); + public native static void nativeStartRoutingSession(); public native static LocationState.RoutingInfo nativeGetRouteFollowingInfo(); //@} diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index 07a661a8e3..9cc27115f1 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -1376,13 +1376,13 @@ public class MWMActivity extends NvEventQueueActivity startActivity(new Intent(this, MoreAppsActivity.class)); break; case R.id.iv__start_routing: - startRouting(); + buildRoute(); break; case R.id.iv__routing_close: stopRouting(); break; case R.id.btn__routing_go: - // TODO call some native magic + startRouting(); break; default: break; @@ -1390,6 +1390,11 @@ public class MWMActivity extends NvEventQueueActivity } private void startRouting() + { + Framework.nativeStartRoutingSession(); + } + + private void buildRoute() { if (LocationState.INSTANCE.getLocationStateMode() < LocationState.NOT_FOLLOW) { @@ -1407,7 +1412,7 @@ public class MWMActivity extends NvEventQueueActivity mInfoView.setState(State.HIDDEN); - Framework.nativeStartRoutingSession(mInfoView.getMapObject().getLat(), mInfoView.getMapObject().getLon()); + Framework.nativeBuildRoute(mInfoView.getMapObject().getLat(), mInfoView.getMapObject().getLon()); if (mIsLocationLocked) { final LocationState.RoutingInfo info = Framework.nativeGetRouteFollowingInfo(); diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 26d277001a..180261d720 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -764,7 +764,7 @@ { if ([MapsAppDelegate theApp].m_locationManager.lastLocation) { - GetFramework().StartRoutingSession([placePage pinPoint]); + GetFramework().BuildRoute([placePage pinPoint]); [placePage setState:PlacePageStateHidden animated:YES withCallback:YES]; [self performAfterDelay:0.3 block:^{ [self.routeView setVisible:YES animated:YES]; diff --git a/map/framework.cpp b/map/framework.cpp index ad11a7a86c..6ce183321b 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1847,7 +1847,7 @@ bool Framework::IsRoutingActive() const return m_routingSession.IsActive(); } -bool Framework::StartRoutingSession(m2::PointD const & destination) +bool Framework::BuildRoute(m2::PointD const & destination) { shared_ptr const & state = GetLocationState(); if (!GetPlatform().HasRouting() || !state->IsModeHasPosition()) @@ -1859,12 +1859,26 @@ bool Framework::StartRoutingSession(m2::PointD const & destination) m_routingSession.BuildRoute(state->Position(), destination, [&] (Route const & route) { InsertRoute(route); - state->StartRoutingMode(); + state->RouteBuilded(); + + m2::PolylineD const & poly = route.GetPoly(); + + m2::AnyRectD srcRect = GetNavigator().Screen().GlobalRect(); + m2::RectD rect = srcRect.GetGlobalRect(); + for (auto it = poly.Begin(); it != poly.End(); ++it) + rect.Add(*it); + + ShowRectExVisibleScale(rect); }); return true; } +void Framework::StartRoutingSession() +{ + GetLocationState()->StartRouteFollow(); +} + BookmarkCategory * Framework::FindCategory(string const & name) { for (size_t i = 0; i < m_bmManager.GetBmCategoriesCount(); ++i) diff --git a/map/framework.hpp b/map/framework.hpp index 3edcd2dff6..21ad3ee0d2 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -483,7 +483,8 @@ public: /// @name Routing mode //@{ bool IsRoutingActive() const; - bool StartRoutingSession(m2::PointD const & destination); + bool BuildRoute(m2::PointD const & destination); + void StartRoutingSession(); void CancelRoutingSession(); void GetRouteFollowingInfo(location::FollowingInfo & info) const; diff --git a/map/location_state.cpp b/map/location_state.cpp index 0867231c2c..8dd978d63d 100644 --- a/map/location_state.cpp +++ b/map/location_state.cpp @@ -278,12 +278,24 @@ void State::SwitchToNextMode() SetModeInfo(ChangeMode(m_modeInfo, newMode)); } -void State::StartRoutingMode() +void State::RouteBuilded() { ASSERT(GetPlatform().HasRouting(), ()); ASSERT(IsModeHasPosition(), ()); - State::Mode newMode = IsRotationActive() ? RotateAndFollow : Follow; - SetModeInfo(ChangeMode(IncludeModeBit(m_modeInfo, RoutingSessionBit), newMode)); + StopAllAnimations(); + SetModeInfo(ChangeMode(IncludeModeBit(m_modeInfo, RoutingSessionBit), NotFollow)); +} + +void State::StartRouteFollow() +{ + ASSERT(TestModeBit(m_modeInfo, RoutingSessionBit), ()); + ASSERT(GetPlatform().HasRouting(), ()); + ASSERT(IsModeHasPosition(), ()); + m2::PointD const size(m_errorRadius, m_errorRadius); + m_framework->ShowRectExVisibleScale(m2::RectD(m_position - size, m_position + size), + scales::GetUpperComfortScale()); + + SetModeInfo(ChangeMode(m_modeInfo, IsRotationActive() ? RotateAndFollow : Follow)); } void State::StopRoutingMode() diff --git a/map/location_state.hpp b/map/location_state.hpp index d77dd77954..f42f988fbb 100644 --- a/map/location_state.hpp +++ b/map/location_state.hpp @@ -60,7 +60,8 @@ namespace location bool IsModeHasPosition() const; void SwitchToNextMode(); - void StartRoutingMode(); + void RouteBuilded(); + void StartRouteFollow(); void StopRoutingMode(); int AddStateModeListener(TStateModeListener const & l); diff --git a/map/navigator.cpp b/map/navigator.cpp index 9a0c97ac09..868bd43c13 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -445,14 +445,16 @@ namespace m2::PointD const &, m2::PointD const &)> TScaleImplFn; ZoomAnim(m2::PointD const & startPt, m2::PointD const & endPt, m2::PointD const & target, TScaleImplFn const & fn, double deltaTime) - : m_targetPt(target) - , m_startPt(startPt) - , m_endPt(endPt) - , m_prevPt(startPt) - , m_fn(fn) + : m_fn(fn) , m_startTime(0.0) , m_deltaTime(deltaTime) { + m_finger1Start = target + (startPt - target); + m_prevPt1 = m_finger1Start; + m_finger1End = m_finger1Start + (endPt - startPt); + m_finger2Start = target - (startPt - target); + m_prevPt2 = m_finger2Start; + m_finger2End = m_finger2Start - (endPt - startPt); } virtual bool IsVisual() const { return true; } @@ -471,22 +473,28 @@ namespace double t = elapsed / m_deltaTime; if (t > 1.0 || my::AlmostEqual(t, 1.0)) { - m_fn(m_targetPt, m_endPt, m_targetPt, m_prevPt); + m_fn(m_finger1End, m_finger2End, m_prevPt1, m_prevPt2); End(); return; } - m2::PointD delta = (m_endPt - m_startPt) * t; - m2::PointD current = m_startPt + delta; - m_fn(m_targetPt, current, m_targetPt, m_prevPt); - m_prevPt = current; + m2::PointD delta1 = ((m_finger1End - m_finger1Start) * t); + m2::PointD delta2 = ((m_finger2End - m_finger2Start) * t); + m2::PointD current1 = m_finger1Start + delta1; + m2::PointD current2 = m_finger2Start + delta2; + m_fn(current1, current2, m_prevPt1, m_prevPt2); + m_prevPt1 = current1; + m_prevPt2 = current2; } private: - m2::PointD m_targetPt; - m2::PointD m_startPt; - m2::PointD m_endPt; - m2::PointD m_prevPt; + m2::PointD m_prevPt1; + m2::PointD m_prevPt2; + + m2::PointD m_finger1Start; + m2::PointD m_finger1End; + m2::PointD m_finger2Start; + m2::PointD m_finger2End; TScaleImplFn m_fn; double m_startTime; @@ -636,7 +644,7 @@ void Navigator::Scale(double scale) shared_ptr Navigator::ScaleAnim(double scale) { - return ScaleToPointAnim(m_Screen.PixelRect().Center(), scale, 0.3); + return ScaleToPointAnim(m_Screen.PixelRect().Center() + m2::PointD(0.0, 300.0), scale, 0.3); } void Navigator::Rotate(double angle) diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 5cdc3aaf08..9e82de20a8 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -394,9 +394,17 @@ namespace qt else if (e->modifiers() & Qt::ShiftModifier) { if (m_framework->IsRoutingActive()) - m_framework->CancelRoutingSession(); + { + static int counter = 0; + if (counter % 2 == 0) + m_framework->StartRoutingSession(); + else + m_framework->CancelRoutingSession(); + + counter++; + } else - m_framework->StartRoutingSession(m_framework->PtoG(pt)); + m_framework->BuildRoute(m_framework->PtoG(pt)); } if (e->modifiers() & Qt::AltModifier) { diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index 48c8859570..9ced53f567 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -126,6 +126,7 @@ MainWindow::MainWindow() : m_locationService(CreateDesktopLocationService(*this) #endif // NO_DOWNLOADER m_pDrawWidget->UpdateAfterSettingsChanged(); + locState->InvalidatePosition(); } #if defined(Q_WS_WIN)