Add plugin dependent items to custom plugins

This commit is contained in:
Vitaliy 2020-03-17 12:53:17 +02:00
parent dc5d22228b
commit 30a34b12a9
9 changed files with 108 additions and 62 deletions

View file

@ -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<String> rendererNames = new ArrayList<>();
public List<String> routerNames = new ArrayList<>();
public List<ApplicationMode> appModes = new ArrayList<>();
public List<QuickAction> quickActions = new ArrayList<>();
public List<PoiUIFilter> poiUIFilters = new ArrayList<>();
public List<ITileSource> mapSources = new ArrayList<>();
public List<AvoidSpecificRoads.AvoidRoadInfo> avoidRoadInfos = new ArrayList<>();
public CustomOsmandPlugin(OsmandApplication app) {
super(app);
}
@ -62,4 +78,39 @@ public class CustomOsmandPlugin extends OsmandPlugin {
return json.toString();
}
@Override
public List<String> getRendererNames() {
return rendererNames;
}
@Override
public List<String> getRouterNames() {
return routerNames;
}
@Override
public List<ApplicationMode> getAddedAppModes() {
return appModes;
}
@Override
public List<QuickAction> getQuickActions() {
return quickActions;
}
@Override
public List<PoiUIFilter> getPoiUIFilters() {
return poiUIFilters;
}
@Override
public List<ITileSource> getMapSources() {
return mapSources;
}
@Override
public List<AvoidSpecificRoads.AvoidRoadInfo> getAvoidRoadInfos() {
return avoidRoadInfos;
}
}

View file

@ -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<QuickAction> getQuickActions() {
return Collections.emptyList();
}
public List<PoiUIFilter> getPoiUIFilters() {
return Collections.emptyList();
}
public List<ITileSource> getMapSources() {
return Collections.emptyList();
}
public List<AvoidSpecificRoads.AvoidRoadInfo> 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() {

View file

@ -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

View file

@ -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<ApplicationMode> 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;

View file

@ -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<ApplicationMode> 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;

View file

@ -1,8 +1,8 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28
buildToolsVersion "28.0.3"
signingConfigs {
development {

View file

@ -1,8 +1,8 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28
buildToolsVersion "28.0.3"
signingConfigs {
development {

View file

@ -1,8 +1,8 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28
buildToolsVersion "28.0.3"
signingConfigs {
development {

View file

@ -1,8 +1,8 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28
buildToolsVersion "28.0.3"
signingConfigs {
development {