From 14ac84f363f4ad6b50b5b0a59389a9d8155ff7a0 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Fri, 26 Jan 2018 13:31:47 +0200 Subject: [PATCH] Boat navigation is enabled with Nautical plugin --- .../openseamapsplugin/NauticalMapsPlugin.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java index 47f4d04b8d..d2e3607fd1 100644 --- a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java @@ -6,6 +6,7 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.support.v7.app.AlertDialog; import net.osmand.IndexConstants; +import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -13,6 +14,9 @@ import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.render.RendererRegistry; +import java.util.LinkedHashSet; +import java.util.Set; + public class NauticalMapsPlugin extends OsmandPlugin { public static final String ID = "nauticalPlugin.plugin"; @@ -53,6 +57,7 @@ public class NauticalMapsPlugin extends OsmandPlugin { @Override public boolean init(final OsmandApplication app, final Activity activity) { if(activity != null) { + addBoatProfile(true); // called from UI previousRenderer = app.getSettings().RENDERER.get(); app.getSettings().RENDERER.set(RendererRegistry.NAUTICAL_RENDER); @@ -82,6 +87,17 @@ public class NauticalMapsPlugin extends OsmandPlugin { } return true; } + + public void addBoatProfile(boolean flag) { + Set selectedProfiles = new LinkedHashSet<>(ApplicationMode.values(app.getSettings())); + if((!selectedProfiles.contains(ApplicationMode.BOAT) && flag) || + ((selectedProfiles.contains(ApplicationMode.BOAT) && !flag))) { + String s = app.getSettings().AVAILABLE_APP_MODES.get(); + String currModes = flag ? s + ApplicationMode.BOAT.getStringKey() + "," + : s.replace(ApplicationMode.BOAT.getStringKey() + ",", ""); + app.getSettings().AVAILABLE_APP_MODES.set(currModes); + } + } @Override public void disable(OsmandApplication app) { @@ -89,6 +105,7 @@ public class NauticalMapsPlugin extends OsmandPlugin { if(app.getSettings().RENDERER.get().equals(RendererRegistry.NAUTICAL_RENDER)) { app.getSettings().RENDERER.set(previousRenderer); } + addBoatProfile(false); } @Override