From 8d6a4a19e355cb3c789f7bd74537ad9997226790 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 9 Feb 2015 00:48:31 +0100 Subject: [PATCH] update plugins --- OsmAnd/res/values/strings.xml | 4 + .../osmand/access/AccessibilityPlugin.java | 2 +- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 14 +-- .../plus/activities/PluginActivity.java | 2 +- .../plus/activities/PluginsActivity.java | 34 ++++--- .../audionotes/AudioVideoNotesPlugin.java | 2 +- .../plus/dashboard/DashPluginsFragment.java | 13 +-- .../development/OsmandDevelopmentPlugin.java | 2 +- .../DistanceCalculatorPlugin.java | 2 +- .../monitoring/OsmandMonitoringPlugin.java | 2 +- .../openseamapsplugin/NauticalMapsPlugin.java | 94 +++++++++++++++++++ .../openseamapsplugin/OpenSeaMapsPlugin.java | 45 --------- .../osmand/plus/osmedit/OsmEditingPlugin.java | 2 +- .../src/net/osmand/plus/osmo/OsMoPlugin.java | 2 +- .../parkingpoint/ParkingPositionPlugin.java | 2 +- .../rastermaps/OsmandRasterMapsPlugin.java | 2 +- .../osmand/plus/render/RendererRegistry.java | 7 +- .../RoutePointsPlugin.java | 2 +- .../plus/skimapsplugin/SkiMapsPlugin.java | 55 ++++++++++- .../osmand/plus/srtmplugin/SRTMPlugin.java | 2 +- 20 files changed, 195 insertions(+), 95 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java delete mode 100644 OsmAnd/src/net/osmand/plus/openseamapsplugin/OpenSeaMapsPlugin.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 05d2d2c2c2..822e6379d6 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Ski Maps + Nautical Maps + In order to display ski maps, the special offline map needs to be downloaded + In order to display nautical maps, the special offline map needs to be downloaded Edit group Parking place REMOVE THE TAG diff --git a/OsmAnd/src/net/osmand/access/AccessibilityPlugin.java b/OsmAnd/src/net/osmand/access/AccessibilityPlugin.java index b8c42759be..608cedcd7a 100644 --- a/OsmAnd/src/net/osmand/access/AccessibilityPlugin.java +++ b/OsmAnd/src/net/osmand/access/AccessibilityPlugin.java @@ -20,7 +20,7 @@ public class AccessibilityPlugin extends OsmandPlugin { } @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index e1fc3ea560..1fe27671b9 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.pm.PackageManager.NameNotFoundException; import android.preference.PreferenceScreen; import android.support.v4.app.Fragment; +import android.widget.CompoundButton.OnCheckedChangeListener; import net.osmand.IProgress; import net.osmand.Location; import net.osmand.PlatformUtil; @@ -18,7 +19,7 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; -import net.osmand.plus.openseamapsplugin.OpenSeaMapsPlugin; +import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmo.OsMoPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; @@ -62,8 +63,9 @@ public abstract class OsmandPlugin { /** * Initialize plugin runs just after creation + * @param activity TODO */ - public abstract boolean init(OsmandApplication app); + public abstract boolean init(OsmandApplication app, Activity activity); public void setActive(boolean active) { this.active = active; @@ -100,7 +102,7 @@ public abstract class OsmandPlugin { checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null); allPlugins.add(new AudioVideoNotesPlugin(app)); checkMarketPlugin(app, new RoutePointsPlugin(app), false /*FIXME*/, RoutePointsPlugin.ROUTE_POINTS_PLUGIN_COMPONENT, null); - checkMarketPlugin(app, new OpenSeaMapsPlugin(app), false, OpenSeaMapsPlugin.COMPONENT, null); + checkMarketPlugin(app, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null); checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null); allPlugins.add(new DistanceCalculatorPlugin(app)); allPlugins.add(new AccessibilityPlugin(app)); @@ -110,7 +112,7 @@ public abstract class OsmandPlugin { for (OsmandPlugin plugin : allPlugins) { if (enabledPlugins.contains(plugin.getId()) || plugin.isActive()) { try { - if (plugin.init(app)) { + if (plugin.init(app, null)) { plugin.setActive(true); } } catch (Exception e) { @@ -141,9 +143,9 @@ public abstract class OsmandPlugin { } } - public static boolean enablePlugin(OsmandApplication app, OsmandPlugin plugin, boolean enable) { + public static boolean enablePlugin(Activity activity, OsmandApplication app, OsmandPlugin plugin, boolean enable) { if (enable) { - if (!plugin.init(app)) { + if (!plugin.init(app, activity)) { plugin.setActive(false); return false; } else { diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java index 47ba9afd5b..3f58bf5723 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java @@ -77,7 +77,7 @@ public class PluginActivity extends OsmandActionBarActivity { return; } - boolean ok = OsmandPlugin.enablePlugin((OsmandApplication)getApplication(), + boolean ok = OsmandPlugin.enablePlugin(PluginActivity.this, (OsmandApplication)getApplication(), plugin, isChecked); if (!ok) { return; diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java index d455b38cea..5f7d2723f2 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java @@ -51,7 +51,7 @@ public class PluginsActivity extends OsmandListActivity { } private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) { - boolean ok = OsmandPlugin.enablePlugin(((OsmandApplication) getApplication()), plugin, + boolean ok = OsmandPlugin.enablePlugin(this, ((OsmandApplication) getApplication()), plugin, enable); if (!ok) { return; @@ -94,7 +94,11 @@ public class PluginsActivity extends OsmandListActivity { pluginLogo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - enableDisablePlugin(plugin, !plugin.isActive()); + if(!plugin.isActive() && plugin.needsInstallation()) { + // nothing + } else { + enableDisablePlugin(plugin, !plugin.isActive()); + } } }); @@ -126,18 +130,20 @@ public class PluginsActivity extends OsmandListActivity { final Class settingsActivity = plugin.getSettingsActivity(); final PopupMenu optionsMenu = new PopupMenu(this, v); - - MenuItem enableDisableItem = optionsMenu.getMenu().add(plugin.isActive() - ? R.string.disable_plugin2 - : R.string.enable_plugin2); - enableDisableItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - enableDisablePlugin(plugin, !plugin.isActive()); - optionsMenu.dismiss(); - return true; - } - }); + if (plugin.isActive() || !plugin.needsInstallation()) { + MenuItem enableDisableItem = optionsMenu.getMenu().add( + plugin.isActive() ? R.string.disable_plugin2 + : R.string.enable_plugin2); + enableDisableItem + .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + enableDisablePlugin(plugin, !plugin.isActive()); + optionsMenu.dismiss(); + return true; + } + }); + } if (settingsActivity != null) { MenuItem settingsItem = optionsMenu.getMenu().add(R.string.settings); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index af72317784..cf5da003ab 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -366,7 +366,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } @Override - public boolean init(final OsmandApplication app) { + public boolean init(final OsmandApplication app, Activity activity) { initializeRemoteControlRegistrationMethods(); AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); if (am != null) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java index 7a83c2932d..7d2d9d1f03 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java @@ -37,22 +37,12 @@ public class DashPluginsFragment extends DashBaseFragment { if (plugin.isActive() == isChecked || plugin.needsInstallation()) { return; } - if (OsmandPlugin.enablePlugin(getMyApplication(), plugin, isChecked)) { + if (OsmandPlugin.enablePlugin(getActivity(), getMyApplication(), plugin, isChecked)) { updatePluginState(pluginView); } } }; - private final View.OnClickListener toggleEnableDisableListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - View pluginView = AndroidUtils.findParentViewById(view, R.id.dash_plugin_item); - OsmandPlugin plugin = (OsmandPlugin)pluginView.getTag(); - if (OsmandPlugin.enablePlugin(getMyApplication(), plugin, !plugin.isActive())) { - updatePluginState(pluginView); - } - } - }; private final View.OnClickListener getListener = new View.OnClickListener() { @Override @@ -164,7 +154,6 @@ public class DashPluginsFragment extends DashBaseFragment { nameView.setText(plugin.getName()); ImageButton logoView = (ImageButton)view.findViewById(R.id.plugin_logo); - logoView.setOnClickListener(toggleEnableDisableListener); logoView.setImageResource(plugin.getLogoResourceId()); CompoundButton enableDisableButton = diff --git a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java index 5933287463..944095a77e 100644 --- a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java +++ b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java @@ -26,7 +26,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin { } @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java index 7d3602a3b1..e39152bf96 100644 --- a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java +++ b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java @@ -98,7 +98,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { } @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index f387c28c79..dec854ac18 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -74,7 +74,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn } @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { settings = app.getSettings(); return true; } diff --git a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java new file mode 100644 index 0000000000..75b0c399af --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java @@ -0,0 +1,94 @@ +package net.osmand.plus.openseamapsplugin; + +import net.osmand.IndexConstants; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.render.RendererRegistry; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; + +public class NauticalMapsPlugin extends OsmandPlugin { + + public static final String ID = "nauticalPlugin.plugin"; + public static final String COMPONENT = "net.osmand.nauticalPlugin"; + private static String previousRenderer = RendererRegistry.DEFAULT_RENDER; + private OsmandApplication app; + + + public NauticalMapsPlugin(OsmandApplication app) { + this.app = app; + } + + + @Override + public String getDescription() { + return "Nautical Maps plugin provides detailed maps for sea and channels based on OSM data.\n " + + "(Here could be description of provided details)\n" + + "It changes default rendering style to 'nautical'. You can change it back in 'Configure Map' menu (Translation)"; + } + + @Override + public String getName() { + return app.getString(net.osmand.plus.R.string.plugin_nautical_name); + } + + @Override + public boolean init(final OsmandApplication app, final Activity activity) { + if(activity != null) { + // called from UI + previousRenderer = app.getSettings().RENDERER.get(); + app.getSettings().RENDERER.set(RendererRegistry.NAUTICAL_RENDER); + if(!app.getResourceManager().getIndexFileNames().containsKey("World_seamarks"+ + "_" +IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_MAP_INDEX_EXT)){ + Builder dlg = new AlertDialog.Builder(activity); + dlg.setMessage(net.osmand.plus.R.string.nautical_maps_missing); + dlg.setPositiveButton(R.string.default_buttons_ok, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + final Intent intent = new Intent(activity, app.getAppCustomization().getDownloadIndexActivity()); + intent.putExtra(DownloadActivity.FILTER_KEY, app.getString(net.osmand.plus.R.string.index_item_world_seamarks)); + intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); + activity.startActivity(intent); + } + }); + dlg.setNegativeButton(R.string.default_buttons_cancel, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + app.getSettings().RENDERER.set(previousRenderer); + } + }); + dlg.show(); + } + + } + return true; + } + + @Override + public void disable(OsmandApplication app) { + super.disable(app); + if(app.getSettings().RENDERER.get().equals(RendererRegistry.NAUTICAL_RENDER)) { + app.getSettings().RENDERER.set(previousRenderer); + } + } + + + @Override + public String getId() { + return ID; + } + + + @Override + public Class getSettingsActivity() { + return null; + } +} diff --git a/OsmAnd/src/net/osmand/plus/openseamapsplugin/OpenSeaMapsPlugin.java b/OsmAnd/src/net/osmand/plus/openseamapsplugin/OpenSeaMapsPlugin.java deleted file mode 100644 index cefed2c80b..0000000000 --- a/OsmAnd/src/net/osmand/plus/openseamapsplugin/OpenSeaMapsPlugin.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.osmand.plus.openseamapsplugin; - -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import android.app.Activity; - -public class OpenSeaMapsPlugin extends OsmandPlugin { - - public static final String ID = "openseamaps.plugin"; - public static final String COMPONENT = "net.osmand.openseamapsPlugin"; - private OsmandApplication app; - - - public OpenSeaMapsPlugin(OsmandApplication app) { - this.app = app; - } - - - @Override - public String getDescription() { - return "This will be a plugin enabling openseamaps (TODO)"; - } - - @Override - public String getName() { - return "Open Sea Maps"; - } - - @Override - public boolean init(final OsmandApplication app) { - return true; - } - - - @Override - public String getId() { - return ID; - } - - - @Override - public Class getSettingsActivity() { - return null; - } -} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 32b8d8b9b6..1407c60f55 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -52,7 +52,7 @@ public class OsmEditingPlugin extends OsmandPlugin { } @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { settings = app.getSettings(); return true; } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java index 973bfe415b..7a0184eca8 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java @@ -79,7 +79,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer } @Override - public boolean init(final OsmandApplication app) { + public boolean init(final OsmandApplication app, Activity activity) { if(app.getSettings().OSMO_AUTO_CONNECT.get() || (System.currentTimeMillis() - app.getSettings().OSMO_LAST_PING.get() < 5 * 60 * 1000 )) { service.connect(true); diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index dc63f69ce9..5c40691490 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -146,7 +146,7 @@ public class ParkingPositionPlugin extends OsmandPlugin { @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index fcf0d7a45b..e4afceea53 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -58,7 +58,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { } @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { settings = app.getSettings(); return true; } diff --git a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java index 2bd9500a6d..746cf42112 100644 --- a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java +++ b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java @@ -24,6 +24,9 @@ public class RendererRegistry { private final static Log log = PlatformUtil.getLog(RendererRegistry.class); public final static String DEFAULT_RENDER = "OsmAnd"; //$NON-NLS-1$ + public final static String NAUTICAL_RENDER = "Nautical"; //$NON-NLS-1$ + + public static final String WINTER_SKI_RENDER = "Winter-and-ski"; private RenderingRulesStorage defaultRender = null; private RenderingRulesStorage currentSelectedRender = null; @@ -45,8 +48,8 @@ public class RendererRegistry { internalRenderers.put("UniRS", "UniRS" + ".render.xml"); internalRenderers.put("LightRS", "LightRS" + ".render.xml"); internalRenderers.put("High-contrast-roads", "High-contrast-roads" + ".render.xml"); - internalRenderers.put("Winter-and-ski", "Winter-and-ski" + ".render.xml"); - internalRenderers.put("Nautical", "nautical" + ".render.xml"); + internalRenderers.put(WINTER_SKI_RENDER, "Winter-and-ski" + ".render.xml"); + internalRenderers.put(NAUTICAL_RENDER, "nautical" + ".render.xml"); } public RenderingRulesStorage defaultRender() { diff --git a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java index 8d9330089e..4fbff58072 100644 --- a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java @@ -169,7 +169,7 @@ public class RoutePointsPlugin extends OsmandPlugin { } @Override - public boolean init(OsmandApplication app) { + public boolean init(OsmandApplication app, Activity activity) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java b/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java index ec4495f437..0cedbdbd0d 100644 --- a/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java @@ -1,14 +1,23 @@ package net.osmand.plus.skimapsplugin; +import net.osmand.IndexConstants; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.render.RendererRegistry; import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; public class SkiMapsPlugin extends OsmandPlugin { public static final String ID = "skimaps.plugin"; public static final String COMPONENT = "net.osmand.skimapsPlugin"; private OsmandApplication app; + private String previousRenderer = RendererRegistry.DEFAULT_RENDER; public SkiMapsPlugin(OsmandApplication app) { this.app = app; @@ -16,18 +25,56 @@ public class SkiMapsPlugin extends OsmandPlugin { @Override public String getDescription() { - return "This will be a plugin enabling ski maps (TODO)"; + return "Nautical Maps plugin provides maps for pistes based on OSM data.\n " + + "(Here could be description of provided details)\n" + + "It changes default rendering style to 'Winter-Ski'. You can change it back in 'Configure Map' menu (Translation)"; } @Override public String getName() { - return "Ski Maps"; + return app.getString(net.osmand.plus.R.string.plugin_ski_name); } - @Override - public boolean init(final OsmandApplication app) { + public boolean init(final OsmandApplication app, final Activity activity) { + if(activity != null) { + // called from UI + previousRenderer = app.getSettings().RENDERER.get(); + app.getSettings().RENDERER.set(RendererRegistry.WINTER_SKI_RENDER); + if(!app.getResourceManager().getIndexFileNames().containsKey("World-ski"+ + "_" +IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_MAP_INDEX_EXT)){ + Builder dlg = new AlertDialog.Builder(activity); + dlg.setMessage(net.osmand.plus.R.string.world_ski_missing); + dlg.setPositiveButton(net.osmand.plus.R.string.default_buttons_ok, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + final Intent intent = new Intent(activity, app.getAppCustomization().getDownloadIndexActivity()); + intent.putExtra(DownloadActivity.FILTER_KEY, app.getString(net.osmand.plus.R.string.index_item_world_ski)); + intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); + activity.startActivity(intent); + } + }); + dlg.setNegativeButton(net.osmand.plus.R.string.default_buttons_cancel, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + app.getSettings().RENDERER.set(previousRenderer); + } + }); + dlg.show(); + } + + } return true; } + + @Override + public void disable(OsmandApplication app) { + super.disable(app); + if(app.getSettings().RENDERER.get().equals(RendererRegistry.WINTER_SKI_RENDER)) { + app.getSettings().RENDERER.set(previousRenderer); + } + } @Override diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 980f9f8e9a..c0a4970ef5 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -43,7 +43,7 @@ public class SRTMPlugin extends OsmandPlugin { } @Override - public boolean init(final OsmandApplication app) { + public boolean init(final OsmandApplication app, Activity activity) { HILLSHADE = app.getSettings().registerBooleanPreference("hillshade_layer", true); OsmandSettings settings = app.getSettings(); CommonPreference pref = settings.getCustomRenderProperty("contourLines");