From 30a34b12a9cc3dab111adcbefa9aa03cb26e59e3 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 17 Mar 2020 12:53:17 +0200 Subject: [PATCH] Add plugin dependent items to custom plugins --- .../net/osmand/plus/CustomOsmandPlugin.java | 51 +++++++++++++++++++ OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 32 ++++++++++++ .../net/osmand/plus/helpers/ImportHelper.java | 15 ++++++ .../openseamapsplugin/NauticalMapsPlugin.java | 30 +---------- .../plus/skimapsplugin/SkiMapsPlugin.java | 26 ---------- plugins/Osmand-Nautical/build.gradle | 4 +- plugins/Osmand-ParkingPlugin/build.gradle | 4 +- plugins/Osmand-SRTMPlugin/build.gradle | 4 +- plugins/Osmand-Skimaps/build.gradle | 4 +- 9 files changed, 108 insertions(+), 62 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java b/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java index 0e25e4e0fb..a19b30e5ed 100644 --- a/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java @@ -1,14 +1,30 @@ package net.osmand.plus; +import net.osmand.map.ITileSource; +import net.osmand.plus.helpers.AvoidSpecificRoads; +import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.quickaction.QuickAction; + import org.json.JSONException; import org.json.JSONObject; +import java.util.ArrayList; +import java.util.List; + public class CustomOsmandPlugin extends OsmandPlugin { public String pluginId; public String name; public String description; + public List rendererNames = new ArrayList<>(); + public List routerNames = new ArrayList<>(); + public List appModes = new ArrayList<>(); + public List quickActions = new ArrayList<>(); + public List poiUIFilters = new ArrayList<>(); + public List mapSources = new ArrayList<>(); + public List avoidRoadInfos = new ArrayList<>(); + public CustomOsmandPlugin(OsmandApplication app) { super(app); } @@ -62,4 +78,39 @@ public class CustomOsmandPlugin extends OsmandPlugin { return json.toString(); } + + @Override + public List getRendererNames() { + return rendererNames; + } + + @Override + public List getRouterNames() { + return routerNames; + } + + @Override + public List getAddedAppModes() { + return appModes; + } + + @Override + public List getQuickActions() { + return quickActions; + } + + @Override + public List getPoiUIFilters() { + return poiUIFilters; + } + + @Override + public List getMapSources() { + return mapSources; + } + + @Override + public List getAvoidRoadInfos() { + return avoidRoadInfos; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index c7e95494d4..2dcabb2fca 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -20,6 +20,7 @@ import net.osmand.IProgress; import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.access.AccessibilityPlugin; +import net.osmand.map.ITileSource; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity.TabItem; import net.osmand.plus.api.SettingsAPI; @@ -29,6 +30,7 @@ import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.dialogs.PluginDisabledBottomSheet; import net.osmand.plus.dialogs.PluginInstalledBottomSheetDialog; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapillary.MapillaryPlugin; @@ -37,6 +39,8 @@ import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; +import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.skimapsplugin.SkiMapsPlugin; @@ -115,6 +119,12 @@ public abstract class OsmandPlugin { * Initialize plugin runs just after creation */ public boolean init(@NonNull OsmandApplication app, @Nullable Activity activity) { + if (activity != null) { + // called from UI + for (ApplicationMode appMode: getAddedAppModes()) { + ApplicationMode.changeProfileAvailability(appMode, true, app); + } + } return true; } @@ -174,10 +184,29 @@ public abstract class OsmandPlugin { return Collections.emptyList(); } + public List getQuickActions() { + return Collections.emptyList(); + } + + public List getPoiUIFilters() { + return Collections.emptyList(); + } + + public List getMapSources() { + return Collections.emptyList(); + } + + public List getAvoidRoadInfos() { + return Collections.emptyList(); + } + /** * Plugin was installed */ public void onInstall(@NonNull OsmandApplication app, @Nullable Activity activity) { + for (ApplicationMode appMode: getAddedAppModes()) { + ApplicationMode.changeProfileAvailability(appMode, true, app); + } showInstallDialog(activity); } @@ -200,6 +229,9 @@ public abstract class OsmandPlugin { } public void disable(OsmandApplication app) { + for (ApplicationMode appMode: getAddedAppModes()) { + ApplicationMode.changeProfileAvailability(appMode, false, app); + } } public String getHelpFileName() { diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index bcefdda8d9..bc64dd8557 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -809,6 +809,21 @@ public class ImportHelper { if (!Algorithms.isEmpty(pluginItems)) { for (SettingsHelper.SettingsItem item : pluginItems) { item.setShouldReplace(true); + if (item instanceof SettingsHelper.QuickActionSettingsItem) { + plugin.quickActions = ((SettingsHelper.QuickActionSettingsItem) item).getItems(); + } + if (item instanceof SettingsHelper.PoiUiFilterSettingsItem) { + plugin.poiUIFilters = ((SettingsHelper.PoiUiFilterSettingsItem) item).getItems(); + } + if (item instanceof SettingsHelper.MapSourcesSettingsItem) { + plugin.mapSources = ((SettingsHelper.MapSourcesSettingsItem) item).getItems(); + } + if (item instanceof SettingsHelper.AvoidRoadsSettingsItem) { + plugin.avoidRoadInfos = ((SettingsHelper.AvoidRoadsSettingsItem) item).getItems(); + } + if (item instanceof SettingsHelper.ProfileSettingsItem) { + plugin.appModes.add(((SettingsHelper.ProfileSettingsItem) item).getAppMode()); + } } app.getSettingsHelper().importSettings(file, pluginItems, "", 1, new SettingsHelper.SettingsImportListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java index 5d713e3667..812c5f95c5 100644 --- a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java @@ -1,10 +1,5 @@ package net.osmand.plus.openseamapsplugin; -import android.app.Activity; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -23,12 +18,12 @@ public class NauticalMapsPlugin extends OsmandPlugin { public NauticalMapsPlugin(OsmandApplication app) { super(app); } - + @Override public int getLogoResourceId() { return R.drawable.ic_plugin_nautical_map; } - + @Override public int getAssetResourceName() { return R.drawable.nautical_map; @@ -59,21 +54,6 @@ public class NauticalMapsPlugin extends OsmandPlugin { return "feature_articles/nautical-charts.html"; } - @Override - public boolean init(@NonNull final OsmandApplication app, final Activity activity) { - if (activity != null) { - // called from UI - ApplicationMode.changeProfileAvailability(ApplicationMode.BOAT, true, app); - } - return true; - } - - @Override - public void onInstall(@NonNull OsmandApplication app, @Nullable Activity activity) { - ApplicationMode.changeProfileAvailability(ApplicationMode.BOAT, true, app); - super.onInstall(app, activity); - } - @Override public List getAddedAppModes() { return Collections.singletonList(ApplicationMode.BOAT); @@ -89,12 +69,6 @@ public class NauticalMapsPlugin extends OsmandPlugin { return Collections.singletonList("boat"); } - @Override - public void disable(OsmandApplication app) { - super.disable(app); - ApplicationMode.changeProfileAvailability(ApplicationMode.BOAT, false, app); - } - @Override public String getId() { return ID; diff --git a/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java b/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java index f05ba352f5..51f63b6e9f 100644 --- a/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java @@ -1,10 +1,5 @@ package net.osmand.plus.skimapsplugin; -import android.app.Activity; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -58,21 +53,6 @@ public class SkiMapsPlugin extends OsmandPlugin { return "feature_articles/ski-plugin.html"; } - @Override - public boolean init(@NonNull final OsmandApplication app, final Activity activity) { - if (activity != null) { - // called from UI - ApplicationMode.changeProfileAvailability(ApplicationMode.SKI, true, app); - } - return true; - } - - @Override - public void onInstall(@NonNull OsmandApplication app, @Nullable Activity activity) { - ApplicationMode.changeProfileAvailability(ApplicationMode.SKI, true, app); - super.onInstall(app, activity); - } - @Override public List getAddedAppModes() { return Collections.singletonList(ApplicationMode.SKI); @@ -88,12 +68,6 @@ public class SkiMapsPlugin extends OsmandPlugin { return Collections.singletonList("ski"); } - @Override - public void disable(OsmandApplication app) { - super.disable(app); - ApplicationMode.changeProfileAvailability(ApplicationMode.SKI, false, app); - } - @Override public String getId() { return ID; diff --git a/plugins/Osmand-Nautical/build.gradle b/plugins/Osmand-Nautical/build.gradle index c21bb94dc9..bc8e716c47 100644 --- a/plugins/Osmand-Nautical/build.gradle +++ b/plugins/Osmand-Nautical/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 + buildToolsVersion "28.0.3" signingConfigs { development { diff --git a/plugins/Osmand-ParkingPlugin/build.gradle b/plugins/Osmand-ParkingPlugin/build.gradle index 30cd732fd4..5253c0e52a 100644 --- a/plugins/Osmand-ParkingPlugin/build.gradle +++ b/plugins/Osmand-ParkingPlugin/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 + buildToolsVersion "28.0.3" signingConfigs { development { diff --git a/plugins/Osmand-SRTMPlugin/build.gradle b/plugins/Osmand-SRTMPlugin/build.gradle index 1feff52d28..589776252a 100644 --- a/plugins/Osmand-SRTMPlugin/build.gradle +++ b/plugins/Osmand-SRTMPlugin/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 + buildToolsVersion "28.0.3" signingConfigs { development { diff --git a/plugins/Osmand-Skimaps/build.gradle b/plugins/Osmand-Skimaps/build.gradle index 8dd4f12b61..dcf39f487f 100644 --- a/plugins/Osmand-Skimaps/build.gradle +++ b/plugins/Osmand-Skimaps/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 + buildToolsVersion "28.0.3" signingConfigs { development {