forked from organicmaps/organicmaps
Added setting my-position to follow mode after spending some time in background
This commit is contained in:
parent
c1d1942f4d
commit
35d85ece35
10 changed files with 83 additions and 16 deletions
|
@ -42,14 +42,20 @@ DrapeEngine::DrapeEngine(Params && params)
|
|||
mode = location::Follow;
|
||||
}
|
||||
|
||||
double timeInBackground = 0.0;
|
||||
double lastEnterBackground = 0.0;
|
||||
if (settings::Get("LastEnterBackground", lastEnterBackground))
|
||||
timeInBackground = my::Timer::LocalTime() - lastEnterBackground;
|
||||
|
||||
FrontendRenderer::Params frParams(make_ref(m_threadCommutator), params.m_factory,
|
||||
make_ref(m_textureManager), m_viewport,
|
||||
bind(&DrapeEngine::ModelViewChanged, this, _1),
|
||||
bind(&DrapeEngine::TapEvent, this, _1),
|
||||
bind(&DrapeEngine::UserPositionChanged, this, _1),
|
||||
bind(&DrapeEngine::MyPositionModeChanged, this, _1, _2),
|
||||
mode, make_ref(m_requestedTiles), params.m_allow3dBuildings,
|
||||
params.m_blockTapEvents, params.m_isFirstLaunch);
|
||||
mode, make_ref(m_requestedTiles), timeInBackground,
|
||||
params.m_allow3dBuildings, params.m_blockTapEvents,
|
||||
params.m_isFirstLaunch);
|
||||
|
||||
m_frontend = make_unique_dp<FrontendRenderer>(frParams);
|
||||
|
||||
|
@ -470,4 +476,11 @@ void DrapeEngine::SetKineticScrollEnabled(bool enabled)
|
|||
MessagePriority::High);
|
||||
}
|
||||
|
||||
void DrapeEngine::SetTimeInBackground(double time)
|
||||
{
|
||||
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
|
||||
make_unique_dp<SetTimeInBackgroundMessage>(time),
|
||||
MessagePriority::High);
|
||||
}
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -134,6 +134,8 @@ public:
|
|||
|
||||
void SetKineticScrollEnabled(bool enabled);
|
||||
|
||||
void SetTimeInBackground(double time);
|
||||
|
||||
private:
|
||||
void AddUserEvent(UserEvent const & e);
|
||||
void ModelViewChanged(ScreenBase const & screen);
|
||||
|
|
|
@ -138,7 +138,8 @@ FrontendRenderer::FrontendRenderer(Params const & params)
|
|||
ASSERT(m_tapEventInfoFn, ());
|
||||
ASSERT(m_userPositionChangedFn, ());
|
||||
|
||||
m_myPositionController.reset(new MyPositionController(params.m_initMyPositionMode, params.m_firstLaunch));
|
||||
m_myPositionController.reset(new MyPositionController(params.m_initMyPositionMode,
|
||||
params.m_timeInBackground, params.m_firstLaunch));
|
||||
m_myPositionController->SetModeListener(params.m_myPositionModeCallback);
|
||||
|
||||
StartThread();
|
||||
|
@ -686,6 +687,13 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
break;
|
||||
}
|
||||
|
||||
case Message::SetTimeInBackground:
|
||||
{
|
||||
ref_ptr<SetTimeInBackgroundMessage> msg = message;
|
||||
m_myPositionController->SetTimeInBackground(msg->GetTime());
|
||||
break;
|
||||
}
|
||||
|
||||
case Message::Invalidate:
|
||||
{
|
||||
// Do nothing here, new frame will be rendered because of this message processing.
|
||||
|
|
|
@ -79,6 +79,7 @@ public:
|
|||
location::TMyPositionModeChanged myPositionModeCallback,
|
||||
location::EMyPositionMode initMode,
|
||||
ref_ptr<RequestedTiles> requestedTiles,
|
||||
double timeInBackground,
|
||||
bool allow3dBuildings,
|
||||
bool blockTapEvents,
|
||||
bool firstLaunch)
|
||||
|
@ -90,6 +91,7 @@ public:
|
|||
, m_myPositionModeCallback(myPositionModeCallback)
|
||||
, m_initMyPositionMode(initMode)
|
||||
, m_requestedTiles(requestedTiles)
|
||||
, m_timeInBackground(timeInBackground)
|
||||
, m_allow3dBuildings(allow3dBuildings)
|
||||
, m_blockTapEvents(blockTapEvents)
|
||||
, m_firstLaunch(firstLaunch)
|
||||
|
@ -102,6 +104,7 @@ public:
|
|||
location::TMyPositionModeChanged m_myPositionModeCallback;
|
||||
location::EMyPositionMode m_initMyPositionMode;
|
||||
ref_ptr<RequestedTiles> m_requestedTiles;
|
||||
double m_timeInBackground;
|
||||
bool m_allow3dBuildings;
|
||||
bool m_blockTapEvents;
|
||||
bool m_firstLaunch;
|
||||
|
|
|
@ -53,7 +53,8 @@ public:
|
|||
ClearGpsTrackPoints,
|
||||
ShowChoosePositionMark,
|
||||
SetKineticScrollEnabled,
|
||||
BlockTapEvents
|
||||
BlockTapEvents,
|
||||
SetTimeInBackground
|
||||
};
|
||||
|
||||
virtual ~Message() {}
|
||||
|
|
|
@ -761,4 +761,18 @@ public:
|
|||
Type GetType() const override { return Message::ClearGpsTrackPoints; }
|
||||
};
|
||||
|
||||
class SetTimeInBackgroundMessage : public Message
|
||||
{
|
||||
public:
|
||||
SetTimeInBackgroundMessage(double time)
|
||||
: m_time(time)
|
||||
{}
|
||||
|
||||
Type GetType() const override { return Message::SetTimeInBackground; }
|
||||
double GetTime() const { return m_time; }
|
||||
|
||||
private:
|
||||
double m_time;
|
||||
};
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -22,7 +22,10 @@ int const kPositionOffsetYIn3D = 80;
|
|||
double const kGpsBearingLifetimeSec = 5.0;
|
||||
double const kMinSpeedThresholdMps = 1.0;
|
||||
|
||||
double const kMaxPendingLocationTimeSec = 15.0;
|
||||
double const kMaxPendingLocationTimeSec = 60.0;
|
||||
double const kMaxTimeInBackgroundSec = 60.0 * 60;
|
||||
|
||||
int const kDoNotChangeZoom = -1;
|
||||
|
||||
string LocationModeStatisticsName(location::EMyPositionMode mode)
|
||||
{
|
||||
|
@ -83,7 +86,8 @@ private:
|
|||
double m_rotateDuration;
|
||||
};
|
||||
|
||||
MyPositionController::MyPositionController(location::EMyPositionMode initMode, bool isFirstLaunch)
|
||||
MyPositionController::MyPositionController(location::EMyPositionMode initMode,
|
||||
double timeInBackground, bool isFirstLaunch)
|
||||
: m_mode(initMode)
|
||||
, m_isFirstLaunch(isFirstLaunch)
|
||||
, m_isInRouting(false)
|
||||
|
@ -104,7 +108,7 @@ MyPositionController::MyPositionController(location::EMyPositionMode initMode, b
|
|||
{
|
||||
if (isFirstLaunch)
|
||||
m_mode = location::NotFollowNoPosition;
|
||||
else if (m_mode == location::NotFollowNoPosition)
|
||||
else if (m_mode == location::NotFollowNoPosition || timeInBackground >= kMaxTimeInBackgroundSec)
|
||||
m_mode = location::Follow;
|
||||
}
|
||||
|
||||
|
@ -307,12 +311,16 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
|
|||
}
|
||||
else
|
||||
{
|
||||
ChangeModelView(m_position, -1);
|
||||
ChangeModelView(m_position, kDoNotChangeZoom);
|
||||
}
|
||||
}
|
||||
else if (!m_isPositionAssigned)
|
||||
{
|
||||
ChangeMode(m_mode);
|
||||
if (m_mode == location::Follow)
|
||||
ChangeModelView(m_position, kDoNotChangeZoom);
|
||||
else if (m_mode == location::FollowAndRotate)
|
||||
ChangeModelView(m_position, m_drawDirection, GetRotationPixelCenter(), kDoNotChangeZoom);
|
||||
}
|
||||
|
||||
m_isPositionAssigned = true;
|
||||
|
@ -321,9 +329,7 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
|
|||
|
||||
void MyPositionController::LoseLocation()
|
||||
{
|
||||
if (IsWaitingForLocation())
|
||||
ChangeMode(location::NotFollowNoPosition);
|
||||
|
||||
ChangeMode(location::NotFollowNoPosition);
|
||||
SetIsVisible(false);
|
||||
}
|
||||
|
||||
|
@ -442,6 +448,15 @@ void MyPositionController::StopLocationFollow()
|
|||
ChangeMode(location::NotFollow);
|
||||
}
|
||||
|
||||
void MyPositionController::SetTimeInBackground(double time)
|
||||
{
|
||||
if (time >= kMaxTimeInBackgroundSec && m_mode == location::NotFollow)
|
||||
{
|
||||
ChangeMode(location::Follow);
|
||||
UpdateViewport();
|
||||
}
|
||||
}
|
||||
|
||||
void MyPositionController::OnCompassTapped()
|
||||
{
|
||||
alohalytics::LogEvent("$compassClicked", {{"mode", LocationModeStatisticsName(m_mode)},
|
||||
|
@ -485,9 +500,9 @@ void MyPositionController::UpdateViewport()
|
|||
return;
|
||||
|
||||
if (m_mode == location::Follow)
|
||||
ChangeModelView(m_position, -1);
|
||||
ChangeModelView(m_position, kDoNotChangeZoom);
|
||||
else if (m_mode == location::FollowAndRotate)
|
||||
ChangeModelView(m_position, m_drawDirection, GetRotationPixelCenter(), -1);
|
||||
ChangeModelView(m_position, m_drawDirection, GetRotationPixelCenter(), kDoNotChangeZoom);
|
||||
}
|
||||
|
||||
m2::PointD MyPositionController::GetRotationPixelCenter() const
|
||||
|
@ -596,7 +611,7 @@ void MyPositionController::DeactivateRouting()
|
|||
|
||||
ChangeMode(location::Follow);
|
||||
if (m_mode == location::FollowAndRotate)
|
||||
ChangeModelView(m_position, 0.0, m_centerPixelPosition, -1);
|
||||
ChangeModelView(m_position, 0.0, m_centerPixelPosition, kDoNotChangeZoom);
|
||||
else
|
||||
ChangeModelView(0.0);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
RenderMyPosition = 0x2
|
||||
};
|
||||
|
||||
MyPositionController(location::EMyPositionMode initMode, bool isFirstLaunch);
|
||||
MyPositionController(location::EMyPositionMode initMode, double timeInBackground, bool isFirstLaunch);
|
||||
~MyPositionController();
|
||||
|
||||
void OnNewPixelRect();
|
||||
|
@ -78,6 +78,8 @@ public:
|
|||
void NextMode();
|
||||
void LoseLocation();
|
||||
|
||||
void SetTimeInBackground(double time);
|
||||
|
||||
void OnCompassTapped();
|
||||
|
||||
void OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, ScreenBase const & screen);
|
||||
|
|
|
@ -286,8 +286,11 @@ Framework::Framework()
|
|||
, m_bmManager(*this)
|
||||
, m_isRenderingEnabled(true)
|
||||
, m_fixedSearchResults(0)
|
||||
, m_startForegroundTime(0.0)
|
||||
, m_lastReportedCountry(kInvalidCountryId)
|
||||
{
|
||||
m_startBackgroundTime = my::Timer::LocalTime();
|
||||
|
||||
// Restore map style before classificator loading
|
||||
int mapStyle;
|
||||
if (!settings::Get(kMapStyleKey, mapStyle))
|
||||
|
@ -1156,12 +1159,15 @@ void Framework::MemoryWarning()
|
|||
|
||||
void Framework::EnterBackground()
|
||||
{
|
||||
m_startBackgroundTime = my::Timer::LocalTime();
|
||||
settings::Set("LastEnterBackground", m_startBackgroundTime);
|
||||
|
||||
SaveViewport();
|
||||
|
||||
ms::LatLon const ll = MercatorBounds::ToLatLon(GetViewportCenter());
|
||||
alohalytics::Stats::Instance().LogEvent("Framework::EnterBackground", {{"zoom", strings::to_string(GetDrawScale())},
|
||||
{"foregroundSeconds", strings::to_string(
|
||||
static_cast<int>(my::Timer::LocalTime() - m_startForegroundTime))}},
|
||||
static_cast<int>(m_startBackgroundTime - m_startForegroundTime))}},
|
||||
alohalytics::Location::FromLatLon(ll.lat, ll.lon));
|
||||
// Do not clear caches for Android. This function is called when main activity is paused,
|
||||
// but at the same time search activity (for example) is enabled.
|
||||
|
@ -1174,6 +1180,8 @@ void Framework::EnterBackground()
|
|||
void Framework::EnterForeground()
|
||||
{
|
||||
m_startForegroundTime = my::Timer::LocalTime();
|
||||
double const time = m_startForegroundTime - m_startBackgroundTime;
|
||||
CallDrapeFunction(bind(&df::DrapeEngine::SetTimeInBackground, _1, time));
|
||||
}
|
||||
|
||||
bool Framework::GetCurrentPosition(double & lat, double & lon) const
|
||||
|
|
|
@ -126,6 +126,7 @@ protected:
|
|||
drape_ptr<df::watch::CPUDrawer> m_cpuDrawer;
|
||||
|
||||
double m_startForegroundTime;
|
||||
double m_startBackgroundTime;
|
||||
|
||||
storage::Storage m_storage;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue