diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 9e048c9409..fba0c89bb8 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -4,6 +4,7 @@ #include "../core/jni_helper.hpp" #include "../core/render_context.hpp" + #include "../platform/Platform.hpp" #include "../../../../../map/framework.hpp" @@ -12,22 +13,23 @@ #include "../../../../../gui/controller.hpp" +#include "../../../../../graphics/opengl/framebuffer.hpp" +#include "../../../../../graphics/opengl/opengl.hpp" + #include "../../../../../indexer/drawing_rules.hpp" #include "../../../../../coding/file_container.hpp" #include "../../../../../coding/file_name_utils.hpp" -#include "../../../../../graphics/opengl/framebuffer.hpp" -#include "../../../../../graphics/opengl/opengl.hpp" +#include "../../../../../geometry/angles.hpp" #include "../../../../../platform/platform.hpp" #include "../../../../../platform/location.hpp" +#include "../../../../../platform/preferred_languages.hpp" #include "../../../../../base/math.hpp" #include "../../../../../base/logging.hpp" -#include "../../../../../platform/preferred_languages.hpp" - namespace { @@ -47,6 +49,7 @@ namespace android : m_mask(0), m_isCleanSingleClick(false), m_doLoadState(true), + m_lastCompass(0.0), m_wasLongClick(false) { ASSERT_EQUAL ( g_framework, 0, () ); @@ -67,12 +70,20 @@ namespace android void Framework::OnLocationUpdated(location::GpsInfo const & info) { - Platform::RunOnGuiThreadImpl(bind(&::Framework::OnLocationUpdate, ref(m_work), info)); + Platform::RunOnGuiThreadImpl(bind(&::Framework::OnLocationUpdate, ref(m_work), info), false); } void Framework::OnCompassUpdated(location::CompassInfo const & info) { - Platform::RunOnGuiThreadImpl(bind(&::Framework::OnCompassUpdate, ref(m_work), info)); + static double const COMPASS_THRASHOLD = my::DegToRad(1.0); + + /// @todo Do not emit compass bearing too often while we are passing it through nv-queue. + /// Need to make more experiments in future. + if (fabs(ang::GetShortestDistance(m_lastCompass, info.m_bearing)) >= COMPASS_THRASHOLD) + { + m_lastCompass = info.m_bearing; + Platform::RunOnGuiThreadImpl(bind(&::Framework::OnCompassUpdate, ref(m_work), info), false); + } } void Framework::UpdateCompassSensor(int ind, float * arr) diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index a5022daf92..60694e478d 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -46,6 +46,7 @@ namespace android //@} math::LowPassVector m_sensors[2]; + double m_lastCompass; unique_ptr m_scheduledTask; bool m_wasLongClick; diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index 87e4ee0dab..adae19c30f 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -57,7 +57,7 @@ string Platform::UniqueClientId() const void Platform::RunOnGuiThread(TFunctor const & fn) { - android::Platform::RunOnGuiThreadImpl(fn); + android::Platform::RunOnGuiThreadImpl(fn, true); } namespace android @@ -137,9 +137,9 @@ namespace android return platform; } - void Platform::RunOnGuiThreadImpl(TFunctor const & fn) + void Platform::RunOnGuiThreadImpl(TFunctor const & fn, bool blocking) { - postMWMEvent(new TFunctor(fn)); + postMWMEvent(new TFunctor(fn), blocking); } } diff --git a/android/jni/com/mapswithme/platform/Platform.hpp b/android/jni/com/mapswithme/platform/Platform.hpp index d5d54669a8..0bb9dafa6b 100644 --- a/android/jni/com/mapswithme/platform/Platform.hpp +++ b/android/jni/com/mapswithme/platform/Platform.hpp @@ -24,7 +24,7 @@ namespace android bool HasAvailableSpaceForWriting(uint64_t size) const; - static void RunOnGuiThreadImpl(TFunctor const & fn); + static void RunOnGuiThreadImpl(TFunctor const & fn, bool blocking); static Platform & Instance(); }; diff --git a/android/jni/nv_event/nv_event.cpp b/android/jni/nv_event/nv_event.cpp index bc4ad2e97f..46d295d338 100644 --- a/android/jni/nv_event/nv_event.cpp +++ b/android/jni/nv_event/nv_event.cpp @@ -799,19 +799,22 @@ static jboolean postUserEvent(JNIEnv* env, jobject thiz, return NVEventInsertBlocking(&ev); } else - { - NVEventInsert(&ev); - return true; - } + { + NVEventInsert(&ev); + return true; + } } -void postMWMEvent(void * pFn) +void postMWMEvent(void * pFn, bool blocking) { NVEvent ev; ev.m_type = NV_EVENT_MWM; ev.m_data.m_mwm.m_pFn = pFn; - NVEventInsertBlocking(&ev); + if (blocking) + (void) NVEventInsertBlocking(&ev); + else + NVEventInsert(&ev); } /////////////////////////////////////////////////////////////////////////////// diff --git a/android/jni/nv_event/nv_event.hpp b/android/jni/nv_event/nv_event.hpp index 3ed4c2aaa7..59d1f2c8fa 100644 --- a/android/jni/nv_event/nv_event.hpp +++ b/android/jni/nv_event/nv_event.hpp @@ -544,6 +544,6 @@ NVEventPlatformAppHandle NVEventGetPlatformAppHandle(); void InitNVEvent(JavaVM * jvm); -void postMWMEvent(void * pFn); +void postMWMEvent(void * pFn, bool blocking); #endif diff --git a/android/src/com/mapswithme/maps/location/LocationService.java b/android/src/com/mapswithme/maps/location/LocationService.java index 220dbbeeb3..09729c8b3d 100644 --- a/android/src/com/mapswithme/maps/location/LocationService.java +++ b/android/src/com/mapswithme/maps/location/LocationService.java @@ -195,7 +195,7 @@ public enum LocationService implements { if (mSensorManager != null) { - final int COMPASS_REFRESH_MKS = SensorManager.SENSOR_DELAY_NORMAL; + final int COMPASS_REFRESH_MKS = SensorManager.SENSOR_DELAY_UI; if (mAccelerometer != null) mSensorManager.registerListener(this, mAccelerometer, COMPASS_REFRESH_MKS); diff --git a/map/location_state.cpp b/map/location_state.cpp index 475baaa506..c8001bf058 100644 --- a/map/location_state.cpp +++ b/map/location_state.cpp @@ -29,6 +29,9 @@ namespace { static const int POSITION_Y_OFFSET = 120; +static const double POSITION_TOLERANCE = 1.0E-6; // much less than coordinates coding error +static const double ANGLE_TOLERANCE = my::DegToRad(3.0); + uint16_t IncludeModeBit(uint16_t mode, uint16_t bit) { @@ -72,6 +75,11 @@ public: { ASSERT(m_angleAnim != nullptr, ()); ASSERT(m_posAnim != nullptr, ()); + + if (dstPos.EqualDxDy(m_posAnim->GetCurrentValue(), POSITION_TOLERANCE) && + fabs(ang::GetShortestDistance(m_angleAnim->GetCurrentValue(), dstAngle)) < ANGLE_TOLERANCE) + return; + double const posSpeed = m_fw->GetNavigator().ComputeMoveSpeed(m_posAnim->GetCurrentValue(), dstPos); double const angleSpeed = 1.5;//m_fw->GetAnimator().GetRotationSpeed(); @@ -799,7 +807,10 @@ void State::AnimateFollow() return; if (!FollowCompass()) - m_framework->SetViewportCenterAnimated(Position()); + { + if (!m_position.EqualDxDy(m_framework->GetViewportCenter(), POSITION_TOLERANCE)) + m_framework->SetViewportCenterAnimated(m_position); + } } } diff --git a/routing/route.cpp b/routing/route.cpp index c474a52a36..71bf9c5f18 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -14,8 +14,6 @@ namespace routing { -static double const TIME_THRESHOLD_SECONDS = 60.0*1.0; - double GetDistanceOnEarth(m2::PointD const & p1, m2::PointD const & p2) { return ms::DistanceOnEarth(MercatorBounds::YToLat(p1.y), @@ -70,9 +68,10 @@ void Route::MoveIterator(m2::PointD const & currPos, location::GpsInfo const & i { /// @todo Need to distinguish GPS and WiFi locations. /// They may have different time metrics in case of incorrect system time on a device. + static double const LOCATION_TIME_THRESHOLD = 60.0*1.0; double const deltaT = info.m_timestamp - m_currentTime; - if (deltaT > 0.0 && deltaT < TIME_THRESHOLD_SECONDS) + if (deltaT > 0.0 && deltaT < LOCATION_TIME_THRESHOLD) predictDistance = info.m_speed * deltaT; }