forked from organicmaps/organicmaps
Merge pull request #1488 from rokuz/fixed-auto-theme-switch-android
Fixed crash on auto-switch theme on Android
This commit is contained in:
commit
49eed72527
8 changed files with 54 additions and 12 deletions
|
@ -183,6 +183,11 @@ void Framework::SetMapStyle(MapStyle mapStyle)
|
|||
m_work.SetMapStyle(mapStyle);
|
||||
}
|
||||
|
||||
void Framework::MarkMapStyle(MapStyle mapStyle)
|
||||
{
|
||||
m_work.MarkMapStyle(mapStyle);
|
||||
}
|
||||
|
||||
MapStyle Framework::GetMapStyle() const
|
||||
{
|
||||
return m_work.GetMapStyle();
|
||||
|
@ -1281,6 +1286,14 @@ extern "C"
|
|||
g_framework->SetMapStyle(val);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeMarkMapStyle(JNIEnv * env, jclass thiz, jint mapStyle)
|
||||
{
|
||||
MapStyle const val = static_cast<MapStyle>(mapStyle);
|
||||
if (val != g_framework->GetMapStyle())
|
||||
g_framework->MarkMapStyle(val);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeSetRouter(JNIEnv * env, jclass thiz, jint routerType)
|
||||
{
|
||||
|
|
|
@ -80,6 +80,7 @@ namespace android
|
|||
void AttachSurface(JNIEnv * env, jobject jSurface);
|
||||
|
||||
void SetMapStyle(MapStyle mapStyle);
|
||||
void MarkMapStyle(MapStyle mapStyle);
|
||||
MapStyle GetMapStyle() const;
|
||||
|
||||
void SetupMeasurementSystem();
|
||||
|
|
|
@ -161,6 +161,13 @@ public class Framework
|
|||
|
||||
public native static void nativeSetMapStyle(int mapStyle);
|
||||
|
||||
/**
|
||||
* This method allows to set new map style without immediate applying. It can be used before
|
||||
* engine recreation instead of nativeSetMapStyle to avoid huge flow of OpenGL invocations.
|
||||
* @param mapStyle style index
|
||||
*/
|
||||
public native static void nativeMarkMapStyle(int mapStyle);
|
||||
|
||||
public native static void nativeSetRouter(int routerType);
|
||||
|
||||
public native static int nativeGetRouter();
|
||||
|
|
|
@ -180,16 +180,23 @@ public class MapFragment extends BaseMwmFragment
|
|||
return;
|
||||
|
||||
if (getActivity() == null || !getActivity().isChangingConfigurations())
|
||||
{
|
||||
// We're in the main thread here. So nothing from the queue will be run between these two calls.
|
||||
// Destroy engine first, then clear the queue that theoretically can be filled by nativeDestroyEngine().
|
||||
nativeDestroyEngine();
|
||||
MwmApplication.get().clearFunctorsOnUiThread();
|
||||
}
|
||||
destroyEngine();
|
||||
else
|
||||
nativeDetachSurface();
|
||||
}
|
||||
|
||||
public void destroyEngine()
|
||||
{
|
||||
if (!mEngineCreated)
|
||||
return;
|
||||
|
||||
// We're in the main thread here. So nothing from the queue will be run between these two calls.
|
||||
// Destroy engine first, then clear the queue that theoretically can be filled by nativeDestroyEngine().
|
||||
nativeDestroyEngine();
|
||||
MwmApplication.get().clearFunctorsOnUiThread();
|
||||
mEngineCreated = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle b)
|
||||
{
|
||||
|
|
|
@ -750,6 +750,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
mMainMenu.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recreate()
|
||||
{
|
||||
// Explicitly destroy engine before activity recreation.
|
||||
mMapFragment.destroyEngine();
|
||||
super.recreate();
|
||||
}
|
||||
|
||||
private void initShowcase()
|
||||
{
|
||||
NativeAppwallAd.AppwallAdListener listener = new NativeAppwallAd.AppwallAdListener()
|
||||
|
|
|
@ -88,7 +88,9 @@ public final class ThemeSwitcher
|
|||
if (ThemeUtils.isNightTheme(theme))
|
||||
style = Framework.MAP_STYLE_DARK;
|
||||
|
||||
Framework.nativeSetMapStyle(style);
|
||||
// Activity and drape engine will be recreated so we have to mark new map style.
|
||||
// Changes will be applied in process of recreation.
|
||||
Framework.nativeMarkMapStyle(style);
|
||||
|
||||
Activity a = MwmApplication.backgroundTracker().getTopActivity();
|
||||
if (a != null && !a.isFinishing())
|
||||
|
|
|
@ -1392,20 +1392,23 @@ void Framework::OnUpdateGpsTrackPointsCallback(vector<pair<size_t, location::Gps
|
|||
m_drapeEngine->UpdateGpsTrackPoints(move(pointsAdd), move(indicesRemove));
|
||||
}
|
||||
|
||||
void Framework::SetMapStyle(MapStyle mapStyle)
|
||||
void Framework::MarkMapStyle(MapStyle mapStyle)
|
||||
{
|
||||
// Store current map style before classificator reloading
|
||||
Settings::Set(kMapStyleKey, static_cast<int>(mapStyle));
|
||||
GetStyleReader().SetCurrentStyle(mapStyle);
|
||||
|
||||
CallDrapeFunction(bind(&df::DrapeEngine::UpdateMapStyle, _1));
|
||||
|
||||
InvalidateUserMarks();
|
||||
|
||||
alohalytics::TStringMap details {{"mapStyle", strings::to_string(static_cast<int>(mapStyle))}};
|
||||
alohalytics::Stats::Instance().LogEvent("MapStyle_Changed", details);
|
||||
}
|
||||
|
||||
void Framework::SetMapStyle(MapStyle mapStyle)
|
||||
{
|
||||
MarkMapStyle(mapStyle);
|
||||
CallDrapeFunction(bind(&df::DrapeEngine::UpdateMapStyle, _1));
|
||||
InvalidateUserMarks();
|
||||
}
|
||||
|
||||
MapStyle Framework::GetMapStyle() const
|
||||
{
|
||||
return GetStyleReader().GetCurrentStyle();
|
||||
|
|
|
@ -318,6 +318,7 @@ public:
|
|||
void DisconnectFromGpsTracker();
|
||||
|
||||
void SetMapStyle(MapStyle mapStyle);
|
||||
void MarkMapStyle(MapStyle mapStyle);
|
||||
MapStyle GetMapStyle() const;
|
||||
|
||||
void SetupMeasurementSystem();
|
||||
|
|
Loading…
Add table
Reference in a new issue