Merge pull request #4949 from osmandapp/PaulsBranch
Boat navigation is enabled with Nautical plugin
This commit is contained in:
commit
95f1f77e9c
1 changed files with 17 additions and 0 deletions
|
@ -6,6 +6,7 @@ import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
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.download.DownloadResources;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class NauticalMapsPlugin extends OsmandPlugin {
|
public class NauticalMapsPlugin extends OsmandPlugin {
|
||||||
|
|
||||||
public static final String ID = "nauticalPlugin.plugin";
|
public static final String ID = "nauticalPlugin.plugin";
|
||||||
|
@ -53,6 +57,7 @@ public class NauticalMapsPlugin extends OsmandPlugin {
|
||||||
@Override
|
@Override
|
||||||
public boolean init(final OsmandApplication app, final Activity activity) {
|
public boolean init(final OsmandApplication app, final Activity activity) {
|
||||||
if(activity != null) {
|
if(activity != null) {
|
||||||
|
addBoatProfile(true);
|
||||||
// called from UI
|
// called from UI
|
||||||
previousRenderer = app.getSettings().RENDERER.get();
|
previousRenderer = app.getSettings().RENDERER.get();
|
||||||
app.getSettings().RENDERER.set(RendererRegistry.NAUTICAL_RENDER);
|
app.getSettings().RENDERER.set(RendererRegistry.NAUTICAL_RENDER);
|
||||||
|
@ -83,12 +88,24 @@ public class NauticalMapsPlugin extends OsmandPlugin {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addBoatProfile(boolean flag) {
|
||||||
|
Set<ApplicationMode> selectedProfiles = new LinkedHashSet<>(ApplicationMode.values(app.getSettings()));
|
||||||
|
boolean isBoatEnabled = selectedProfiles.contains(ApplicationMode.BOAT);
|
||||||
|
if((!isBoatEnabled && flag) || (isBoatEnabled && !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
|
@Override
|
||||||
public void disable(OsmandApplication app) {
|
public void disable(OsmandApplication app) {
|
||||||
super.disable(app);
|
super.disable(app);
|
||||||
if(app.getSettings().RENDERER.get().equals(RendererRegistry.NAUTICAL_RENDER)) {
|
if(app.getSettings().RENDERER.get().equals(RendererRegistry.NAUTICAL_RENDER)) {
|
||||||
app.getSettings().RENDERER.set(previousRenderer);
|
app.getSettings().RENDERER.set(previousRenderer);
|
||||||
}
|
}
|
||||||
|
addBoatProfile(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue