Merge pull request #8037 from osmandapp/plugins_improvements

Connected aidl apps profile dependent
This commit is contained in:
max-klaus 2019-12-05 14:15:04 +03:00 committed by GitHub
commit 8030287b88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 622 additions and 440 deletions

View file

@ -53,8 +53,10 @@ import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.util.Algorithms;
import java.io.File;
import java.util.Collections;
@ -437,6 +439,13 @@ public class AndroidUtils {
return outValue.getFloat();
}
public static int getDrawableId(OsmandApplication app, String id) {
if (!Algorithms.isEmpty(id)) {
return app.getResources().getIdentifier(id, "drawable", app.getPackageName());
}
return 0;
}
public static int getStatusBarHeight(Context ctx) {
int result = 0;
int resourceId = ctx.getResources().getIdentifier("status_bar_height", "dimen", "android");

View file

@ -0,0 +1,357 @@
package net.osmand.aidl;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import net.osmand.AndroidUtils;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.AidlMapLayer;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.util.Algorithms;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ConnectedApp implements Comparable<ConnectedApp> {
public static final String AIDL_LAYERS_PREFIX = "aidl_layers_";
public static final String AIDL_WIDGETS_PREFIX = "aidl_widgets_";
static final String AIDL_OBJECT_ID = "aidl_object_id";
static final String AIDL_PACKAGE_NAME = "aidl_package_name";
static final String AIDL_ADD_MAP_WIDGET = "aidl_add_map_widget";
static final String AIDL_REMOVE_MAP_WIDGET = "aidl_remove_map_widget";
static final String AIDL_ADD_MAP_LAYER = "aidl_add_map_layer";
static final String AIDL_REMOVE_MAP_LAYER = "aidl_remove_map_layer";
static final String PACK_KEY = "pack";
static final String ENABLED_KEY = "enabled";
private OsmandApplication app;
private Map<String, AidlMapWidgetWrapper> widgets = new ConcurrentHashMap<>();
private Map<String, TextInfoWidget> widgetControls = new ConcurrentHashMap<>();
private Map<String, AidlMapLayerWrapper> layers = new ConcurrentHashMap<>();
private Map<String, OsmandMapLayer> mapLayers = new ConcurrentHashMap<>();
private OsmandSettings.CommonPreference<Boolean> layersPref;
private String pack;
private String name;
private Drawable icon;
private boolean enabled;
ConnectedApp(OsmandApplication app, String pack, boolean enabled) {
this.app = app;
this.pack = pack;
this.enabled = enabled;
layersPref = app.getSettings().registerBooleanPreference(AIDL_LAYERS_PREFIX + pack, true).cache();
}
public boolean isEnabled() {
return enabled;
}
@Nullable
public String getName() {
return name;
}
@NonNull
public String getPack() {
return pack;
}
@Nullable
public Drawable getIcon() {
return icon;
}
@NonNull
public Map<String, AidlMapWidgetWrapper> getWidgets() {
return widgets;
}
@NonNull
public Map<String, TextInfoWidget> getWidgetControls() {
return widgetControls;
}
@NonNull
public Map<String, AidlMapLayerWrapper> getLayers() {
return layers;
}
@NonNull
public Map<String, OsmandMapLayer> getMapLayers() {
return mapLayers;
}
void switchEnabled() {
enabled = !enabled;
}
void registerMapLayers(@NonNull MapActivity mapActivity) {
for (AidlMapLayerWrapper layer : layers.values()) {
OsmandMapLayer mapLayer = mapLayers.get(layer.getId());
if (mapLayer != null) {
mapActivity.getMapView().removeLayer(mapLayer);
}
mapLayer = new AidlMapLayer(mapActivity, layer, pack);
mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder());
mapLayers.put(layer.getId(), mapLayer);
}
}
void registerLayerContextMenu(final ContextMenuAdapter menuAdapter, final MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
CompoundButton btn = view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
menuAdapter.getItem(position).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
return false;
}
return true;
}
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId,
int position, boolean isChecked, int[] viewCoordinates) {
if (layersPref.set(isChecked)) {
ContextMenuItem item = adapter.getItem(position);
if (item != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setSelected(isChecked);
adapter.notifyDataSetChanged();
}
mapActivity.refreshMap();
}
return false;
}
};
boolean layersEnabled = layersPref.get();
menuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(AIDL_LAYERS_PREFIX + pack)
.setTitle(name)
.setListener(listener)
.setSelected(layersEnabled)
.setIcon(R.drawable.ic_extension_dark)
.setColor(layersEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.createItem());
}
void registerWidgetControls(MapActivity mapActivity) {
for (AidlMapWidgetWrapper widget : widgets.values()) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
if (layer != null) {
TextInfoWidget control = createWidgetControl(mapActivity, widget.getId());
widgetControls.put(widget.getId(), control);
int menuIconId = AndroidUtils.getDrawableId(mapActivity.getMyApplication(), widget.getMenuIconName());
MapWidgetRegistry.MapWidgetRegInfo widgetInfo = layer.registerSideWidget(control, menuIconId,
widget.getMenuTitle(), "aidl_widget_" + widget.getId(), false, widget.getOrder());
if (!mapActivity.getMapLayers().getMapWidgetRegistry().isVisible(widgetInfo.key)) {
mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(widgetInfo, true, false);
}
}
}
}
TextInfoWidget createWidgetControl(final MapActivity mapActivity, final String widgetId) {
TextInfoWidget control = new TextInfoWidget(mapActivity) {
@Override
public boolean updateInfo(OsmandMapLayer.DrawSettings drawSettings) {
AidlMapWidgetWrapper widget = widgets.get(widgetId);
if (widget != null) {
String txt = widget.getText();
String subtext = widget.getDescription();
boolean night = drawSettings != null && drawSettings.isNightMode();
int icon = AndroidUtils.getDrawableId(mapActivity.getMyApplication(), night ? widget.getDarkIconName() : widget.getLightIconName());
setText(txt, subtext);
if (icon != 0) {
setImageDrawable(icon);
} else {
setImageDrawable(null);
}
return true;
}
return false;
}
};
control.updateInfo(null);
control.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AidlMapWidgetWrapper widget = widgets.get(widgetId);
if (widget != null && widget.getIntentOnClick() != null) {
app.startActivity(widget.getIntentOnClick());
}
}
});
return control;
}
boolean addMapWidget(AidlMapWidgetWrapper widget) {
if (widget != null) {
if (widgets.containsKey(widget.getId())) {
updateMapWidget(widget);
} else {
widgets.put(widget.getId(), widget);
Intent intent = new Intent();
intent.setAction(AIDL_ADD_MAP_WIDGET);
intent.putExtra(AIDL_OBJECT_ID, widget.getId());
intent.putExtra(AIDL_PACKAGE_NAME, pack);
app.sendBroadcast(intent);
}
app.getAidlApi().reloadMap();
return true;
}
return false;
}
boolean removeMapWidget(String widgetId) {
if (!Algorithms.isEmpty(widgetId) && widgets.containsKey(widgetId)) {
widgets.remove(widgetId);
Intent intent = new Intent();
intent.setAction(AIDL_REMOVE_MAP_WIDGET);
intent.putExtra(AIDL_OBJECT_ID, widgetId);
intent.putExtra(AIDL_PACKAGE_NAME, pack);
app.sendBroadcast(intent);
return true;
}
return false;
}
boolean updateMapWidget(AidlMapWidgetWrapper widget) {
if (widget != null && widgets.containsKey(widget.getId())) {
widgets.put(widget.getId(), widget);
app.getAidlApi().reloadMap();
return true;
}
return false;
}
boolean addMapLayer(AidlMapLayerWrapper layer) {
if (layer != null) {
if (layers.containsKey(layer.getId())) {
updateMapLayer(layer);
} else {
layers.put(layer.getId(), layer);
Intent intent = new Intent();
intent.setAction(AIDL_ADD_MAP_LAYER);
intent.putExtra(AIDL_OBJECT_ID, layer.getId());
intent.putExtra(AIDL_PACKAGE_NAME, pack);
app.sendBroadcast(intent);
}
app.getAidlApi().reloadMap();
return true;
}
return false;
}
boolean removeMapLayer(String layerId) {
if (!Algorithms.isEmpty(layerId) && layers.containsKey(layerId)) {
layers.remove(layerId);
Intent intent = new Intent();
intent.setAction(AIDL_REMOVE_MAP_LAYER);
intent.putExtra(AIDL_OBJECT_ID, layerId);
intent.putExtra(AIDL_PACKAGE_NAME, pack);
app.sendBroadcast(intent);
return true;
}
return false;
}
boolean updateMapLayer(AidlMapLayerWrapper layer) {
if (layer != null) {
AidlMapLayerWrapper existingLayer = layers.get(layer.getId());
if (existingLayer != null) {
for (AidlMapPointWrapper point : layer.getPoints()) {
existingLayer.putPoint(point);
}
existingLayer.copyZoomBounds(layer);
app.getAidlApi().reloadMap();
return true;
}
}
return false;
}
boolean putMapPoint(String layerId, AidlMapPointWrapper point) {
AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) {
layer.putPoint(point);
app.getAidlApi().reloadMap();
return true;
}
return false;
}
boolean updateMapPoint(String layerId, AidlMapPointWrapper point, boolean updateOpenedMenuAndMap) {
AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) {
layer.putPoint(point);
app.getAidlApi().reloadMap();
if (updateOpenedMenuAndMap && app.getAidlApi().getAMapPointUpdateListener() != null) {
app.getAidlApi().getAMapPointUpdateListener().onAMapPointUpdated(point, layerId);
}
return true;
}
return false;
}
boolean removeMapPoint(String layerId, String pointId) {
AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) {
layer.removePoint(pointId);
app.getAidlApi().reloadMap();
return true;
}
return false;
}
boolean updateApplicationInfo(PackageManager pm) {
try {
ApplicationInfo ai = pm.getPackageInfo(pack, 0).applicationInfo;
name = ai.loadLabel(pm).toString();
icon = ai.loadIcon(pm);
return true;
} catch (PackageManager.NameNotFoundException e) {
// ignore
}
return false;
}
@Override
public int compareTo(@NonNull ConnectedApp app) {
if (name != null && app.name != null) {
return name.compareTo(app.name);
}
return 0;
}
}

View file

@ -20,9 +20,11 @@ import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
@ -43,6 +45,7 @@ import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper;
@ -53,6 +56,8 @@ import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.SettingsHelper;
import net.osmand.plus.activities.MapActivity;
@ -96,12 +101,18 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.aidl.ConnectedApp.AIDL_OBJECT_ID;
import static net.osmand.aidl.ConnectedApp.AIDL_PACKAGE_NAME;
import static net.osmand.aidl.ConnectedApp.AIDL_ADD_MAP_LAYER;
import static net.osmand.aidl.ConnectedApp.AIDL_ADD_MAP_WIDGET;
import static net.osmand.aidl.ConnectedApp.AIDL_REMOVE_MAP_LAYER;
import static net.osmand.aidl.ConnectedApp.AIDL_REMOVE_MAP_WIDGET;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_IO_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_MAX_LOCK_TIME_MS;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PARAMS_ERROR;
@ -122,6 +133,7 @@ public class OsmandAidlApi {
public static final int KEY_ON_VOICE_MESSAGE = 5;
private static final Log LOG = PlatformUtil.getLog(OsmandAidlApi.class);
private static final String AIDL_REFRESH_MAP = "aidl_refresh_map";
private static final String AIDL_SET_MAP_LOCATION = "aidl_set_map_location";
private static final String AIDL_LATITUDE = "aidl_latitude";
@ -143,18 +155,9 @@ public class OsmandAidlApi {
private static final String AIDL_SEARCH_LAT = "aidl_search_lat";
private static final String AIDL_SEARCH_LON = "aidl_search_lon";
private static final String AIDL_OBJECT_ID = "aidl_object_id";
private static final String AIDL_PACKAGE_NAME = "aidl_package_name";
private static final String AIDL_ADD_MAP_WIDGET = "aidl_add_map_widget";
private static final String AIDL_REMOVE_MAP_WIDGET = "aidl_remove_map_widget";
private static final String AIDL_ADD_CONTEXT_MENU_BUTTONS = "aidl_add_context_menu_buttons";
private static final String AIDL_REMOVE_CONTEXT_MENU_BUTTONS = "aidl_remove_context_menu_buttons";
private static final String AIDL_ADD_MAP_LAYER = "aidl_add_map_layer";
private static final String AIDL_REMOVE_MAP_LAYER = "aidl_remove_map_layer";
private static final String AIDL_TAKE_PHOTO_NOTE = "aidl_take_photo_note";
private static final String AIDL_START_VIDEO_RECORDING = "aidl_start_video_recording";
private static final String AIDL_START_AUDIO_RECORDING = "aidl_start_audio_recording";
@ -185,10 +188,6 @@ public class OsmandAidlApi {
private static final int DEFAULT_ZOOM = 15;
private OsmandApplication app;
private Map<String, AidlMapWidgetWrapper> widgets = new ConcurrentHashMap<>();
private Map<String, TextInfoWidget> widgetControls = new ConcurrentHashMap<>();
private Map<String, AidlMapLayerWrapper> layers = new ConcurrentHashMap<>();
private Map<String, OsmandMapLayer> mapLayers = new ConcurrentHashMap<>();
private Map<String, BroadcastReceiver> receivers = new TreeMap<>();
private Map<String, ConnectedApp> connectedApps = new ConcurrentHashMap<>();
private Map<String, AidlContextMenuButtonsWrapper> contextMenuButtonsParams = new ConcurrentHashMap<>();
@ -252,6 +251,10 @@ public class OsmandAidlApi {
return mapActivityActive;
}
AMapPointUpdateListener getAMapPointUpdateListener() {
return aMapPointUpdateListener;
}
private void initOsmandTelegram() {
String[] packages = new String[] {"net.osmand.telegram", "net.osmand.telegram.debug"};
Intent intent = new Intent("net.osmand.telegram.InitApp");
@ -308,14 +311,6 @@ public class OsmandAidlApi {
registerReceiver(setMapLocationReceiver, mapActivity, AIDL_SET_MAP_LOCATION);
}
private int getDrawableId(String id) {
if (Algorithms.isEmpty(id)) {
return 0;
} else {
return app.getResources().getIdentifier(id, "drawable", app.getPackageName());
}
}
private void registerAddMapWidgetReceiver(MapActivity mapActivity) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
BroadcastReceiver addMapWidgetReceiver = new BroadcastReceiver() {
@ -323,14 +318,17 @@ public class OsmandAidlApi {
public void onReceive(Context context, Intent intent) {
MapActivity mapActivity = mapActivityRef.get();
String widgetId = intent.getStringExtra(AIDL_OBJECT_ID);
if (mapActivity != null && widgetId != null) {
AidlMapWidgetWrapper widget = widgets.get(widgetId);
if (widget != null) {
String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
if (mapActivity != null && widgetId != null && packName != null) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
AidlMapWidgetWrapper widget = connectedApp.getWidgets().get(widgetId);
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
if (layer != null) {
TextInfoWidget control = createWidgetControl(mapActivity, widgetId);
widgetControls.put(widgetId, control);
int menuIconId = getDrawableId(widget.getMenuIconName());
if (widget != null && layer != null) {
ApplicationMode.regWidgetVisibility(widget.getId(), (ApplicationMode[]) null);
TextInfoWidget control = connectedApp.createWidgetControl(mapActivity, widgetId);
connectedApp.getWidgetControls().put(widgetId, control);
int menuIconId = AndroidUtils.getDrawableId(app, widget.getMenuIconName());
MapWidgetRegInfo widgetInfo = layer.registerSideWidget(control,
menuIconId, widget.getMenuTitle(), "aidl_widget_" + widgetId,
false, widget.getOrder());
@ -379,13 +377,17 @@ public class OsmandAidlApi {
public void onReceive(Context context, Intent intent) {
MapActivity mapActivity = mapActivityRef.get();
String widgetId = intent.getStringExtra(AIDL_OBJECT_ID);
if (mapActivity != null && widgetId != null) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
TextInfoWidget widgetControl = widgetControls.get(widgetId);
if (layer != null && widgetControl != null) {
layer.removeSideWidget(widgetControl);
widgetControls.remove(widgetId);
layer.recreateControls();
String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
if (mapActivity != null && widgetId != null && packName != null) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
TextInfoWidget widgetControl = connectedApp.getWidgetControls().get(widgetId);
if (layer != null && widgetControl != null) {
layer.removeSideWidget(widgetControl);
connectedApp.getWidgetControls().remove(widgetId);
layer.recreateControls();
}
}
}
}
@ -394,19 +396,8 @@ public class OsmandAidlApi {
}
public void registerWidgetControls(MapActivity mapActivity) {
for (AidlMapWidgetWrapper widget : widgets.values()) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
if (layer != null) {
TextInfoWidget control = createWidgetControl(mapActivity, widget.getId());
widgetControls.put(widget.getId(), control);
int menuIconId = getDrawableId(widget.getMenuIconName());
MapWidgetRegInfo widgetInfo = layer.registerSideWidget(control,
menuIconId, widget.getMenuTitle(), "aidl_widget_" + widget.getId(),
false, widget.getOrder());
if (!mapActivity.getMapLayers().getMapWidgetRegistry().isVisible(widgetInfo.key)) {
mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(widgetInfo, true, false);
}
}
for (ConnectedApp connectedApp : connectedApps.values()) {
connectedApp.registerWidgetControls(mapActivity);
}
}
@ -418,16 +409,19 @@ public class OsmandAidlApi {
MapActivity mapActivity = mapActivityRef.get();
String layerId = intent.getStringExtra(AIDL_OBJECT_ID);
String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
if (mapActivity != null && packName != null && layerId != null) {
AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) {
OsmandMapLayer mapLayer = mapLayers.get(layerId);
if (mapLayer != null) {
mapActivity.getMapView().removeLayer(mapLayer);
if (mapActivity != null && layerId != null && packName != null) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
AidlMapLayerWrapper layer = connectedApp.getLayers().get(layerId);
if (layer != null) {
OsmandMapLayer mapLayer = connectedApp.getMapLayers().get(layerId);
if (mapLayer != null) {
mapActivity.getMapView().removeLayer(mapLayer);
}
mapLayer = new AidlMapLayer(mapActivity, layer, connectedApp.getPack());
mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder());
connectedApp.getMapLayers().put(layerId, mapLayer);
}
mapLayer = new AidlMapLayer(mapActivity, layer, packName);
mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder());
mapLayers.put(layerId, mapLayer);
}
}
}
@ -442,11 +436,15 @@ public class OsmandAidlApi {
public void onReceive(Context context, Intent intent) {
MapActivity mapActivity = mapActivityRef.get();
String layerId = intent.getStringExtra(AIDL_OBJECT_ID);
if (mapActivity != null && layerId != null) {
OsmandMapLayer mapLayer = mapLayers.remove(layerId);
if (mapLayer != null) {
mapActivity.getMapView().removeLayer(mapLayer);
mapActivity.refreshMap();
String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
if (mapActivity != null && layerId != null && packName != null) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
OsmandMapLayer mapLayer = connectedApp.getMapLayers().remove(layerId);
if (mapLayer != null) {
mapActivity.getMapView().removeLayer(mapLayer);
mapActivity.refreshMap();
}
}
}
}
@ -837,19 +835,9 @@ public class OsmandAidlApi {
registerReceiver(hideSqliteDbFileReceiver, mapActivity, AIDL_HIDE_SQLITEDB_FILE);
}
public void registerMapLayers(MapActivity mapActivity) {
for (AidlMapLayerWrapper layer : layers.values()) {
OsmandMapLayer mapLayer = mapLayers.get(layer.getId());
String packName = "";
if (mapLayer != null) {
if (mapLayer instanceof AidlMapLayer) {
packName = ((AidlMapLayer) mapLayer).getPackName();
}
mapActivity.getMapView().removeLayer(mapLayer);
}
mapLayer = new AidlMapLayer(mapActivity, layer, packName);
mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder());
mapLayers.put(layer.getId(), mapLayer);
public void registerMapLayers(@NonNull MapActivity mapActivity) {
for (ConnectedApp connectedApp : connectedApps.values()) {
connectedApp.registerMapLayers(mapActivity);
}
}
@ -859,43 +847,6 @@ public class OsmandAidlApi {
app.sendBroadcast(intent);
}
private TextInfoWidget createWidgetControl(MapActivity mapActivity, final String widgetId) {
final TextInfoWidget control = new TextInfoWidget(mapActivity) {
@Override
public boolean updateInfo(DrawSettings drawSettings) {
AidlMapWidgetWrapper widget = widgets.get(widgetId);
if (widget != null) {
String txt = widget.getText();
String subtxt = widget.getDescription();
boolean night = drawSettings != null && drawSettings.isNightMode();
int icon = night ? getDrawableId(widget.getDarkIconName()) : getDrawableId(widget.getLightIconName());
setText(txt, subtxt);
if (icon != 0) {
setImageDrawable(icon);
} else {
setImageDrawable(null);
}
return true;
} else {
return false;
}
}
};
control.updateInfo(null);
control.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AidlMapWidgetWrapper widget = widgets.get(widgetId);
if (widget != null && widget.getIntentOnClick() != null) {
app.startActivity(widget.getIntentOnClick());
}
}
});
return control;
}
boolean reloadMap() {
refreshMap();
return true;
@ -1057,97 +1008,71 @@ public class OsmandAidlApi {
return false;
}
boolean addMapWidget(AidlMapWidgetWrapper widget) {
boolean addMapWidget(String packName, AidlMapWidgetWrapper widget) {
if (widget != null) {
if (widgets.containsKey(widget.getId())) {
updateMapWidget(widget);
} else {
widgets.put(widget.getId(), widget);
Intent intent = new Intent();
intent.setAction(AIDL_ADD_MAP_WIDGET);
intent.putExtra(AIDL_OBJECT_ID, widget.getId());
app.sendBroadcast(intent);
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.addMapWidget(widget);
}
refreshMap();
return true;
} else {
return false;
}
return false;
}
boolean removeMapWidget(String widgetId) {
if (!Algorithms.isEmpty(widgetId) && widgets.containsKey(widgetId)) {
widgets.remove(widgetId);
Intent intent = new Intent();
intent.setAction(AIDL_REMOVE_MAP_WIDGET);
intent.putExtra(AIDL_OBJECT_ID, widgetId);
app.sendBroadcast(intent);
return true;
} else {
return false;
boolean removeMapWidget(String packName, String widgetId) {
if (!Algorithms.isEmpty(widgetId)) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.removeMapWidget(widgetId);
}
}
return false;
}
boolean updateMapWidget(AidlMapWidgetWrapper widget) {
if (widget != null && widgets.containsKey(widget.getId())) {
widgets.put(widget.getId(), widget);
refreshMap();
return true;
} else {
return false;
boolean updateMapWidget(String packName, AidlMapWidgetWrapper widget) {
if (widget != null) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.updateMapWidget(widget);
}
}
return false;
}
boolean addMapLayer(String packName, AidlMapLayerWrapper layer) {
if (layer != null) {
if (layers.containsKey(layer.getId())) {
updateMapLayer(layer);
} else {
layers.put(layer.getId(), layer);
Intent intent = new Intent();
intent.setAction(AIDL_ADD_MAP_LAYER);
intent.putExtra(AIDL_OBJECT_ID, layer.getId());
intent.putExtra(AIDL_PACKAGE_NAME, packName);
app.sendBroadcast(intent);
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.addMapLayer(layer);
}
refreshMap();
return true;
} else {
return false;
}
return false;
}
boolean removeMapLayer(String layerId) {
if (!Algorithms.isEmpty(layerId) && layers.containsKey(layerId)) {
layers.remove(layerId);
Intent intent = new Intent();
intent.setAction(AIDL_REMOVE_MAP_LAYER);
intent.putExtra(AIDL_OBJECT_ID, layerId);
app.sendBroadcast(intent);
return true;
} else {
return false;
}
}
boolean updateMapLayer(AidlMapLayerWrapper layer) {
if (layer != null && layers.containsKey(layer.getId())) {
AidlMapLayerWrapper existingLayer = layers.get(layer.getId());
for (AidlMapPointWrapper point : layer.getPoints()) {
existingLayer.putPoint(point);
boolean removeMapLayer(String packName, String layerId) {
if (!Algorithms.isEmpty(layerId)) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.removeMapLayer(layerId);
}
existingLayer.copyZoomBounds(layer);
refreshMap();
return true;
} else {
return false;
}
return false;
}
boolean showMapPoint(String layerId, AidlMapPointWrapper point) {
boolean updateMapLayer(String packName, AidlMapLayerWrapper layer) {
if (layer != null) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.updateMapLayer(layer);
}
}
return false;
}
boolean showMapPoint(String packName, String layerId, AidlMapPointWrapper point) {
if (point != null) {
if (!TextUtils.isEmpty(layerId)) {
AidlMapLayerWrapper layer = layers.get(layerId);
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null && !Algorithms.isEmpty(layerId)) {
AidlMapLayerWrapper layer = connectedApp.getLayers().get(layerId);
if (layer != null) {
AidlMapPointWrapper p = layer.getPoint(point.getId());
if (p != null) {
@ -1170,40 +1095,31 @@ public class OsmandAidlApi {
return false;
}
boolean putMapPoint(String layerId, AidlMapPointWrapper point) {
boolean putMapPoint(String packName, String layerId, AidlMapPointWrapper point) {
if (point != null) {
AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) {
layer.putPoint(point);
refreshMap();
return true;
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.putMapPoint(layerId, point);
}
}
return false;
}
boolean updateMapPoint(String layerId, AidlMapPointWrapper point, boolean updateOpenedMenuAndMap) {
boolean updateMapPoint(String packName, String layerId, AidlMapPointWrapper point, boolean updateOpenedMenuAndMap) {
if (point != null) {
AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) {
layer.putPoint(point);
refreshMap();
if (updateOpenedMenuAndMap && aMapPointUpdateListener != null) {
aMapPointUpdateListener.onAMapPointUpdated(point, layerId);
}
return true;
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.updateMapPoint(layerId, point, updateOpenedMenuAndMap);
}
}
return false;
}
boolean removeMapPoint(String layerId, String pointId) {
if (pointId != null) {
AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) {
layer.removePoint(pointId);
refreshMap();
return true;
boolean removeMapPoint(String packName, String layerId, String pointId) {
if (layerId != null && pointId != null) {
ConnectedApp connectedApp = connectedApps.get(packName);
if (connectedApp != null) {
return connectedApp.removeMapPoint(layerId, pointId);
}
}
return false;
@ -1808,9 +1724,9 @@ public class OsmandAidlApi {
public ConnectedApp getConnectedApp(@NonNull String pack) {
List<ConnectedApp> connectedApps = getConnectedApps();
for (ConnectedApp app : connectedApps) {
if (app.pack.equals(pack)) {
return app;
for (ConnectedApp connectedApp : connectedApps) {
if (connectedApp.getPack().equals(pack)) {
return connectedApp;
}
}
return null;
@ -1820,13 +1736,8 @@ public class OsmandAidlApi {
List<ConnectedApp> res = new ArrayList<>(connectedApps.size());
PackageManager pm = app.getPackageManager();
for (ConnectedApp app : connectedApps.values()) {
try {
ApplicationInfo ai = pm.getPackageInfo(app.pack, 0).applicationInfo;
app.name = ai.loadLabel(pm).toString();
app.icon = ai.loadIcon(pm);
if (app.updateApplicationInfo(pm)) {
res.add(app);
} catch (PackageManager.NameNotFoundException e) {
// ignore
}
}
Collections.sort(res);
@ -1834,41 +1745,30 @@ public class OsmandAidlApi {
}
public boolean switchEnabled(@NonNull ConnectedApp connectedApp) {
connectedApp.enabled = !connectedApp.enabled;
ApplicationMode selectedAppMode = app.getSettings().APPLICATION_MODE.get();
return saveConnectedApps(selectedAppMode, connectedApps);
connectedApp.switchEnabled();
return saveConnectedApps();
}
public boolean isAppEnabled(@NonNull String pack) {
ConnectedApp app = connectedApps.get(pack);
if (app == null) {
app = new ConnectedApp(pack, true);
connectedApps.put(pack, app);
saveNewConnectedApp(app);
ConnectedApp connectedApp = connectedApps.get(pack);
if (connectedApp == null) {
connectedApp = new ConnectedApp(app, pack, true);
connectedApps.put(pack, connectedApp);
saveConnectedApps();
}
return app.enabled;
return connectedApp.isEnabled();
}
private void saveNewConnectedApp(ConnectedApp connectedApp) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
Map<String, ConnectedApp> connectedApps = loadConnectedAppsForMode(mode);
if (!connectedApps.containsKey(connectedApp.pack)) {
connectedApps.put(connectedApp.pack, connectedApp);
saveConnectedApps(mode, connectedApps);
}
}
}
private boolean saveConnectedApps(ApplicationMode mode, Map<String, ConnectedApp> connectedApps) {
private boolean saveConnectedApps() {
try {
JSONArray array = new JSONArray();
for (ConnectedApp app : connectedApps.values()) {
for (ConnectedApp connectedApp : connectedApps.values()) {
JSONObject obj = new JSONObject();
obj.put(ConnectedApp.ENABLED_KEY, app.enabled);
obj.put(ConnectedApp.PACK_KEY, app.pack);
obj.put(ConnectedApp.ENABLED_KEY, connectedApp.isEnabled());
obj.put(ConnectedApp.PACK_KEY, connectedApp.getPack());
array.put(obj);
}
return app.getSettings().API_CONNECTED_APPS_JSON.setModeValue(mode, array.toString());
return app.getSettings().API_CONNECTED_APPS_JSON.set(array.toString());
} catch (JSONException e) {
e.printStackTrace();
}
@ -1876,26 +1776,18 @@ public class OsmandAidlApi {
}
public void loadConnectedApps() {
ApplicationMode selectedAppMode = app.getSettings().APPLICATION_MODE.get();
Map<String, ConnectedApp> appsForMode = loadConnectedAppsForMode(selectedAppMode);
connectedApps.clear();
connectedApps.putAll(appsForMode);
}
private Map<String, ConnectedApp> loadConnectedAppsForMode(ApplicationMode mode) {
Map<String, ConnectedApp> connectedApps = new HashMap<>();
try {
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.getModeValue(mode));
connectedApps.clear();
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.get());
for (int i = 0; i < array.length(); i++) {
JSONObject obj = array.getJSONObject(i);
String pack = obj.optString(ConnectedApp.PACK_KEY, "");
boolean enabled = obj.optBoolean(ConnectedApp.ENABLED_KEY, true);
connectedApps.put(pack, new ConnectedApp(pack, enabled));
connectedApps.put(pack, new ConnectedApp(app, pack, enabled));
}
} catch (JSONException e) {
e.printStackTrace();
}
return connectedApps;
}
boolean setNavDrawerLogo(@Nullable String uri) {
@ -2218,6 +2110,12 @@ public class OsmandAidlApi {
return false;
}
public void registerLayerContextMenu(ContextMenuAdapter adapter, MapActivity mapActivity) {
for (ConnectedApp connectedApp : getConnectedApps()) {
connectedApp.registerLayerContextMenu(adapter, mapActivity);
}
}
private class FileCopyInfo {
long startTime;
long lastAccessTime;
@ -2357,46 +2255,6 @@ public class OsmandAidlApi {
a.points, a.wptPoints, a.wptCategoryNames);
}
public static class ConnectedApp implements Comparable<ConnectedApp> {
static final String PACK_KEY = "pack";
static final String ENABLED_KEY = "enabled";
private String pack;
private boolean enabled;
private String name;
private Drawable icon;
ConnectedApp(String pack, boolean enabled) {
this.pack = pack;
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
public String getName() {
return name;
}
public String getPack() {
return pack;
}
public Drawable getIcon() {
return icon;
}
@Override
public int compareTo(@NonNull ConnectedApp app) {
if (name != null && app.name != null) {
return name.compareTo(app.name);
}
return 0;
}
}
public interface SearchCompleteCallback {
void onSearchComplete(List<AidlSearchResultWrapper> resultSet);
}

View file

@ -122,8 +122,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
private OsmandAidlApi getApi(String reason) {
LOG.info("Request AIDL API for " + reason);
OsmandAidlApi api = getApp().getAidlApi();
String pack = getCallingAppPackName();
if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) {
String packName = getCallingAppPackName();
if (packName != null && !packName.equals(getApp().getPackageName()) && !api.isAppEnabled(packName)) {
return null;
}
return api;
@ -378,7 +378,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean addMapWidget(AddMapWidgetParams params) {
try {
OsmandAidlApi api = getApi("addMapWidget");
return params != null && api != null && api.addMapWidget(new AidlMapWidgetWrapper(params.getWidget()));
String packName = getCallingAppPackName();
return params != null && api != null && api.addMapWidget(packName, new AidlMapWidgetWrapper(params.getWidget()));
} catch (Exception e) {
handleException(e);
return false;
@ -389,7 +390,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean removeMapWidget(RemoveMapWidgetParams params) {
try {
OsmandAidlApi api = getApi("removeMapWidget");
return params != null && api != null && api.removeMapWidget(params.getId());
String packName = getCallingAppPackName();
return params != null && api != null && api.removeMapWidget(packName, params.getId());
} catch (Exception e) {
return false;
}
@ -399,7 +401,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean updateMapWidget(UpdateMapWidgetParams params) {
try {
OsmandAidlApi api = getApi("updateMapWidget");
return params != null && api != null && api.updateMapWidget(new AidlMapWidgetWrapper(params.getWidget()));
String packName = getCallingAppPackName();
return params != null && api != null && api.updateMapWidget(packName, new AidlMapWidgetWrapper(params.getWidget()));
} catch (Exception e) {
handleException(e);
return false;
@ -410,7 +413,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean showMapPoint(ShowMapPointParams params) {
try {
OsmandAidlApi api = getApi("showMapPoint");
return params != null && api != null && api.showMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
String packName = getCallingAppPackName();
return params != null && api != null && api.showMapPoint(packName, params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
} catch (Exception e) {
handleException(e);
return false;
@ -421,7 +425,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean addMapPoint(AddMapPointParams params) {
try {
OsmandAidlApi api = getApi("addMapPoint");
return params != null && api != null && api.putMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
String packName = getCallingAppPackName();
return params != null && api != null && api.putMapPoint(packName, params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
} catch (Exception e) {
handleException(e);
return false;
@ -432,7 +437,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean removeMapPoint(RemoveMapPointParams params) {
try {
OsmandAidlApi api = getApi("removeMapPoint");
return params != null && api != null && api.removeMapPoint(params.getLayerId(), params.getPointId());
String packName = getCallingAppPackName();
return params != null && api != null && api.removeMapPoint(packName, params.getLayerId(), params.getPointId());
} catch (Exception e) {
handleException(e);
return false;
@ -443,7 +449,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean updateMapPoint(UpdateMapPointParams params) {
try {
OsmandAidlApi api = getApi("updateMapPoint");
return params != null && api != null && api.updateMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint()), params.isUpdateOpenedMenuAndMap());
String packName = getCallingAppPackName();
return params != null && api != null && api.updateMapPoint(packName, params.getLayerId(), new AidlMapPointWrapper(params.getPoint()), params.isUpdateOpenedMenuAndMap());
} catch (Exception e) {
handleException(e);
return false;
@ -454,8 +461,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean addMapLayer(AddMapLayerParams params) {
try {
OsmandAidlApi api = getApi("addMapLayer");
String pack = getCallingAppPackName();
return params != null && api != null && api.addMapLayer(pack, new AidlMapLayerWrapper(params.getLayer()));
String packName = getCallingAppPackName();
return params != null && api != null && api.addMapLayer(packName, new AidlMapLayerWrapper(params.getLayer()));
} catch (Exception e) {
handleException(e);
return false;
@ -466,7 +473,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean removeMapLayer(RemoveMapLayerParams params) {
try {
OsmandAidlApi api = getApi("removeMapLayer");
return params != null && api != null && api.removeMapLayer(params.getId());
String packName = getCallingAppPackName();
return params != null && api != null && api.removeMapLayer(packName, params.getId());
} catch (Exception e) {
handleException(e);
return false;
@ -477,7 +485,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean updateMapLayer(UpdateMapLayerParams params) {
try {
OsmandAidlApi api = getApi("updateMapLayer");
return params != null && api != null && api.updateMapLayer(new AidlMapLayerWrapper(params.getLayer()));
String packName = getCallingAppPackName();
return params != null && api != null && api.updateMapLayer(packName, new AidlMapLayerWrapper(params.getLayer()));
} catch (Exception e) {
handleException(e);
return false;

View file

@ -123,8 +123,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
private OsmandAidlApi getApi(String reason) {
LOG.info("Request AIDL API V2 for " + reason);
OsmandAidlApi api = getApp().getAidlApi();
String pack = getCallingAppPackName();
if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) {
String packName = getCallingAppPackName();
if (packName != null && !packName.equals(getApp().getPackageName()) && !api.isAppEnabled(packName)) {
return null;
}
return api;
@ -378,7 +378,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean addMapWidget(AddMapWidgetParams params) {
try {
OsmandAidlApi api = getApi("addMapWidget");
return params != null && api != null && api.addMapWidget(new AidlMapWidgetWrapper(params.getWidget()));
String packName = getCallingAppPackName();
return params != null && api != null && api.addMapWidget(packName, new AidlMapWidgetWrapper(params.getWidget()));
} catch (Exception e) {
handleException(e);
return false;
@ -389,7 +390,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean removeMapWidget(RemoveMapWidgetParams params) {
try {
OsmandAidlApi api = getApi("removeMapWidget");
return params != null && api != null && api.removeMapWidget(params.getId());
String packName = getCallingAppPackName();
return params != null && api != null && api.removeMapWidget(packName, params.getId());
} catch (Exception e) {
return false;
}
@ -399,7 +401,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean updateMapWidget(UpdateMapWidgetParams params) {
try {
OsmandAidlApi api = getApi("updateMapWidget");
return params != null && api != null && api.updateMapWidget(new AidlMapWidgetWrapper(params.getWidget()));
String packName = getCallingAppPackName();
return params != null && api != null && api.updateMapWidget(packName, new AidlMapWidgetWrapper(params.getWidget()));
} catch (Exception e) {
handleException(e);
return false;
@ -410,7 +413,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean showMapPoint(ShowMapPointParams params) {
try {
OsmandAidlApi api = getApi("showMapPoint");
return params != null && api != null && api.showMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
String packName = getCallingAppPackName();
return params != null && api != null && api.showMapPoint(packName, params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
} catch (Exception e) {
handleException(e);
return false;
@ -421,7 +425,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean addMapPoint(AddMapPointParams params) {
try {
OsmandAidlApi api = getApi("addMapPoint");
return params != null && api != null && api.putMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
String packName = getCallingAppPackName();
return params != null && api != null && api.putMapPoint(packName, params.getLayerId(), new AidlMapPointWrapper(params.getPoint()));
} catch (Exception e) {
handleException(e);
return false;
@ -432,7 +437,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean removeMapPoint(RemoveMapPointParams params) {
try {
OsmandAidlApi api = getApi("removeMapPoint");
return params != null && api != null && api.removeMapPoint(params.getLayerId(), params.getPointId());
String packName = getCallingAppPackName();
return params != null && api != null && api.removeMapPoint(packName, params.getLayerId(), params.getPointId());
} catch (Exception e) {
handleException(e);
return false;
@ -443,7 +449,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean updateMapPoint(UpdateMapPointParams params) {
try {
OsmandAidlApi api = getApi("updateMapPoint");
return params != null && api != null && api.updateMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint()), params.isUpdateOpenedMenuAndMap());
String packName = getCallingAppPackName();
return params != null && api != null && api.updateMapPoint(packName, params.getLayerId(), new AidlMapPointWrapper(params.getPoint()), params.isUpdateOpenedMenuAndMap());
} catch (Exception e) {
handleException(e);
return false;
@ -454,8 +461,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean addMapLayer(AddMapLayerParams params) {
try {
OsmandAidlApi api = getApi("addMapLayer");
String pack = getCallingAppPackName();
return params != null && api != null && api.addMapLayer(pack, new AidlMapLayerWrapper(params.getLayer()));
String packName = getCallingAppPackName();
return params != null && api != null && api.addMapLayer(packName, new AidlMapLayerWrapper(params.getLayer()));
} catch (Exception e) {
handleException(e);
return false;
@ -466,7 +473,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean removeMapLayer(RemoveMapLayerParams params) {
try {
OsmandAidlApi api = getApi("removeMapLayer");
return params != null && api != null && api.removeMapLayer(params.getId());
String packName = getCallingAppPackName();
return params != null && api != null && api.removeMapLayer(packName, params.getId());
} catch (Exception e) {
handleException(e);
return false;
@ -477,7 +485,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean updateMapLayer(UpdateMapLayerParams params) {
try {
OsmandAidlApi api = getApi("updateMapLayer");
return params != null && api != null && api.updateMapLayer(new AidlMapLayerWrapper(params.getLayer()));
String packName = getCallingAppPackName();
return params != null && api != null && api.updateMapLayer(packName, new AidlMapLayerWrapper(params.getLayer()));
} catch (Exception e) {
handleException(e);
return false;

View file

@ -38,6 +38,7 @@ import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.liveupdates.LiveUpdatesHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.NativeOsmandLibrary;
@ -768,7 +769,7 @@ public class AppInitializer implements IProgress {
app.savingTrackHelper.loadGpxFromDatabase();
}
}
if (app.savingTrackHelper.getIsRecording()) {
if(app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get() && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null){
int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get();
app.startNavigationService(NavigationService.USED_BY_GPX, app.navigationServiceGpsInterval(interval));
}

View file

@ -13,9 +13,10 @@ import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.ArrayAdapter;
import net.osmand.AndroidUtils;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.aidl.ConnectedApp;
import net.osmand.data.LocationPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginsActivity;
@ -409,10 +410,11 @@ public class OsmAndAppCustomization {
intent.addFlags(item.flags);
}
final Intent finalIntent = intent;
int iconId = AndroidUtils.getDrawableId(app, item.iconName);
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(item.getId())
.setTitle(item.name)
.setIcon(getIconId(item.iconName))
.setIcon(iconId != 0 ? iconId : ContextMenuItem.INVALID_ID)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
@ -432,7 +434,7 @@ public class OsmAndAppCustomization {
JSONObject allItems = new JSONObject(app.getSettings().API_NAV_DRAWER_ITEMS_JSON.get());
for (Iterator<?> it = allItems.keys(); it.hasNext(); ) {
String appPackage = (String) it.next();
OsmandAidlApi.ConnectedApp connectedApp = app.getAidlApi().getConnectedApp(appPackage);
ConnectedApp connectedApp = app.getAidlApi().getConnectedApp(appPackage);
if (connectedApp != null && connectedApp.isEnabled()) {
JSONArray jArray = allItems.getJSONArray(appPackage);
List<NavDrawerItem> list = new ArrayList<>();
@ -454,14 +456,6 @@ public class OsmAndAppCustomization {
return res;
}
private int getIconId(@Nullable String iconName) {
if (!TextUtils.isEmpty(iconName)) {
int id = app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
return id == 0 ? -1 : id;
}
return -1;
}
@NonNull
private HashSet<ApplicationMode> getAppModesSet(@Nullable List<String> appModeKeys) {
HashSet<ApplicationMode> set = new HashSet<>();

View file

@ -208,21 +208,6 @@ public abstract class OsmandPlugin {
}
}
public static void updateActivatedPlugins(OsmandApplication app) {
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
for (OsmandPlugin plugin : OsmandPlugin.getMarketPlugins()) {
updateMarketPlugin(app, enabledPlugins, plugin);
}
for (OsmandPlugin plugin : allPlugins) {
if (enabledPlugins.contains(plugin.getId())) {
initPlugin(app, plugin);
} else if (plugin.isActive()) {
plugin.setActive(false);
plugin.disable(app);
}
}
}
private static void initPlugin(OsmandApplication app, OsmandPlugin plugin) {
try {
if (plugin.init(app, null)) {
@ -267,23 +252,6 @@ public abstract class OsmandPlugin {
return false;
}
public static boolean isPluginEnabledForMode(@NonNull OsmandApplication app, @NonNull OsmandPlugin plugin, @NonNull ApplicationMode mode) {
if (plugin.isMarketPlugin()) {
boolean marketEnabled = Version.isMarketEnabled(app);
boolean pckg = checkPluginPackage(app, plugin);
if ((Version.isDeveloperVersion(app) || !Version.isProductionVersion(app)) && !plugin.isPaid()) {
// for test reasons
marketEnabled = false;
}
if (pckg || (!marketEnabled && !plugin.isPaid())) {
return pckg && !app.getSettings().getPluginsForMode(mode).contains("-" + plugin.getId());
}
return false;
} else {
return app.getSettings().getEnabledPluginsForMode(mode).contains(plugin.getId());
}
}
public static void checkInstalledMarketPlugins(@NonNull OsmandApplication app, @Nullable Activity activity) {
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
for (OsmandPlugin plugin : OsmandPlugin.getMarketPlugins()) {

View file

@ -437,8 +437,6 @@ public class OsmandSettings {
OsmandAidlApi aidlApi = ctx.getAidlApi();
if (aidlApi != null) {
aidlApi.loadConnectedApps();
OsmandPlugin.updateActivatedPlugins(ctx);
ctx.poiFilters.loadSelectedPoiFilters();
}
@ -1017,14 +1015,10 @@ public class OsmandSettings {
return super.getProfileDefaultValue(mode);
}
}
}.makeProfile();
}.makeGlobal();
public Set<String> getEnabledPlugins() {
return getEnabledPluginsForMode(APPLICATION_MODE.get());
}
public Set<String> getEnabledPluginsForMode(ApplicationMode mode) {
String plugs = PLUGINS.getModeValue(mode);
String plugs = PLUGINS.get();
StringTokenizer toks = new StringTokenizer(plugs, ",");
Set<String> res = new LinkedHashSet<String>();
while (toks.hasMoreTokens()) {
@ -1037,11 +1031,7 @@ public class OsmandSettings {
}
public Set<String> getPlugins() {
return getPluginsForMode(APPLICATION_MODE.get());
}
public Set<String> getPluginsForMode(ApplicationMode mode) {
String plugs = PLUGINS.getModeValue(mode);
String plugs = PLUGINS.get();
StringTokenizer toks = new StringTokenizer(plugs, ",");
Set<String> res = new LinkedHashSet<String>();
while (toks.hasMoreTokens()) {
@ -1051,11 +1041,7 @@ public class OsmandSettings {
}
public boolean enablePlugin(String pluginId, boolean enable) {
return enablePluginForMode(pluginId, enable, APPLICATION_MODE.get());
}
public boolean enablePluginForMode(String pluginId, boolean enable, ApplicationMode mode) {
Set<String> set = getPluginsForMode(mode);
Set<String> set = getPlugins();
if (enable) {
set.remove("-" + pluginId);
set.add(pluginId);
@ -1071,8 +1057,8 @@ public class OsmandSettings {
serialization.append(",");
}
}
if (!serialization.toString().equals(PLUGINS.getModeValue(mode))) {
return PLUGINS.setModeValue(mode, serialization.toString());
if (!serialization.toString().equals(PLUGINS.get())) {
return PLUGINS.set(serialization.toString());
}
return false;
}
@ -1172,7 +1158,7 @@ public class OsmandSettings {
return super.getProfileDefaultValue(mode);
}
}
}.makeProfile();
}.makeGlobal();
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
@ -1607,7 +1593,7 @@ public class OsmandSettings {
public static final Integer DAILY_DIRECTORY = 2;
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> SAVE_HEADING_TO_GPX = new BooleanPreference("save_heading_to_gpx", false).makeProfile().makeGeneral();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile().makeGeneral();

View file

@ -1516,7 +1516,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
});
getMapView().refreshMap(true);
applyScreenOrientation();
getMyApplication().getNotificationHelper().refreshNotifications();
}
public void updateMapSettings() {

View file

@ -16,7 +16,7 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.aidl.OsmandAidlApi.ConnectedApp;
import net.osmand.aidl.ConnectedApp;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;

View file

@ -5,20 +5,22 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.format.DateFormat;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.Track;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.Version;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import net.osmand.util.MapUtils;
@ -426,7 +428,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
heading = NO_HEADING;
}
boolean record = false;
if (location != null && OsmAndLocationProvider.isNotSimulatedLocation(location)) {
if (location != null && OsmAndLocationProvider.isNotSimulatedLocation(location)
&& OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
if (settings.SAVE_TRACK_TO_GPX.get()
&& locationTime - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get()
&& ctx.getRoutingHelper().isFollowingMode()) {
@ -667,8 +670,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
public boolean getIsRecording() {
return ctx.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get() ||
(ctx.getSettings().SAVE_TRACK_TO_GPX.get() && ctx.getRoutingHelper().isFollowingMode());
return OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null
&& ctx.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()
|| (ctx.getSettings().SAVE_TRACK_TO_GPX.get() && ctx.getRoutingHelper().isFollowingMode());
}
public float getDistance() {

View file

@ -541,6 +541,7 @@ public class ConfigureMapMenu {
srtmPlugin.registerLayerContextMenuActions(activity.getMapView(), adapter, activity);
}
}
app.getAidlApi().registerLayerContextMenu(adapter, activity);
}
public static void refreshMapComplete(final MapActivity activity) {

View file

@ -134,10 +134,10 @@ public abstract class ImageCard extends AbstractCard {
this.externalLink = imageObject.getBoolean("externalLink");
}
if (imageObject.has("topIcon") && !imageObject.isNull("topIcon")) {
this.topIconId = getDrawableId(imageObject.getString("topIcon"));
this.topIconId = AndroidUtils.getDrawableId(getMyApplication(), imageObject.getString("topIcon"));
}
if (imageObject.has("buttonIcon") && !imageObject.isNull("buttonIcon")) {
this.buttonIconId = getDrawableId(imageObject.getString("buttonIcon"));
this.buttonIconId = AndroidUtils.getDrawableId(getMyApplication(), imageObject.getString("buttonIcon"));
}
if (imageObject.has("buttonText") && !imageObject.isNull("buttonText")) {
this.buttonText = imageObject.getString("buttonText");
@ -169,14 +169,6 @@ public abstract class ImageCard extends AbstractCard {
}
}
private int getDrawableId(String id) {
if (Algorithms.isEmpty(id)) {
return 0;
} else {
return getMyApplication().getResources().getIdentifier(id, "drawable", getMyApplication().getPackageName());
}
}
private static ImageCard createCard(MapActivity mapActivity, JSONObject imageObject) {
ImageCard imageCard = null;
try {

View file

@ -10,6 +10,7 @@ import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Pair;
import net.osmand.AndroidUtils;
import net.osmand.aidl.AidlContextMenuButtonWrapper;
import net.osmand.aidl.AidlContextMenuButtonsWrapper;
import net.osmand.aidl.AidlMapPointWrapper;
@ -196,10 +197,11 @@ public class AMapPointMenuController extends MenuController {
}
}
};
OsmandApplication app = mapActivity.getMyApplication();
titleButtonController.caption = contextMenuButton.getLeftTextCaption();
titleButtonController.rightTextCaption = contextMenuButton.getRightTextCaption();
titleButtonController.leftIconId = getIconIdByName(contextMenuButton.getLeftIconName());
titleButtonController.rightIconId = getIconIdByName(contextMenuButton.getRightIconName());
titleButtonController.leftIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getLeftIconName());
titleButtonController.rightIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getRightIconName());
titleButtonController.enabled = contextMenuButton.isEnabled();
titleButtonController.tintIcon = contextMenuButton.isTintIcon();
@ -211,7 +213,7 @@ public class AMapPointMenuController extends MenuController {
if (activity != null) {
String iconName = point.getParams().get(AMapPoint.POINT_TYPE_ICON_NAME_PARAM);
if (!TextUtils.isEmpty(iconName)) {
return getIconIdByName(iconName);
return AndroidUtils.getDrawableId(activity.getMyApplication(), iconName);
}
}
if (!TextUtils.isEmpty(point.getShortName())) {
@ -220,15 +222,6 @@ public class AMapPointMenuController extends MenuController {
return NO_ICON;
}
private int getIconIdByName(String iconName) {
MapActivity activity = getMapActivity();
if (activity != null && !TextUtils.isEmpty(iconName)) {
OsmandApplication app = activity.getMyApplication();
return app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
}
return 0;
}
private float getPointSpeed() {
String speed = point.getParams().get(AMapPoint.POINT_SPEED_PARAM);
if (!TextUtils.isEmpty(speed)) {

View file

@ -7,6 +7,7 @@ import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.util.MapUtils;
@ -46,7 +47,9 @@ public class LiveMonitoringHelper {
public void updateLocation(net.osmand.Location location) {
boolean record = false;
long locationTime = System.currentTimeMillis();
if (location != null && isLiveMonitoringEnabled() && OsmAndLocationProvider.isNotSimulatedLocation(location)) {
if (location != null && isLiveMonitoringEnabled()
&& OsmAndLocationProvider.isNotSimulatedLocation(location)
&& OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
if (locationTime - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get()) {
record = true;
}

View file

@ -62,7 +62,7 @@ public class ErrorNotification extends OsmandNotification {
boolean planning = routingHelper.isRoutePlanningMode();
boolean pause = routingHelper.isPauseNavigation();
boolean gpxEnabled = app.getSavingTrackHelper().getIsRecording() || OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null;
boolean gpxEnabled = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null;
String usedBy = service != null ? "" + service.getUsedBy() : "X";
notificationText = "Info: " + (following ? "1" : "") + (planning ? "2" : "") + (pause ? "3" : "") + (gpxEnabled ? "4" : "") + "-" + usedBy + ". "

View file

@ -40,7 +40,7 @@ public class GpxNotification extends OsmandNotification {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.saveCurrentTrack();
if (!app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
@ -54,7 +54,7 @@ public class GpxNotification extends OsmandNotification {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.startGPXMonitoring(null);
plugin.updateControl();
@ -66,7 +66,7 @@ public class GpxNotification extends OsmandNotification {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.stopRecording();
plugin.updateControl();
@ -95,7 +95,7 @@ public class GpxNotification extends OsmandNotification {
@Override
public boolean isEnabled() {
return app.getSavingTrackHelper().getIsRecording() || OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null;
return OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null;
}
@Override

View file

@ -29,7 +29,7 @@ import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.aidl.OsmandAidlApi.ConnectedApp;
import net.osmand.aidl.ConnectedApp;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -262,13 +262,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
if (plugin instanceof SkiMapsPlugin || plugin instanceof NauticalMapsPlugin) {
continue;
}
boolean pluginEnabled = OsmandPlugin.isPluginEnabledForMode(app, plugin, getSelectedAppMode());
SwitchPreferenceEx preference = new SwitchPreferenceEx(ctx);
preference.setPersistent(false);
preference.setKey(plugin.getId());
preference.setTitle(plugin.getName());
preference.setChecked(pluginEnabled);
preference.setIcon(getPluginIcon(plugin, pluginEnabled));
preference.setChecked(plugin.isActive());
preference.setIcon(getPluginIcon(plugin));
preference.setIntent(getPluginIntent(plugin));
preference.setLayoutResource(R.layout.preference_dialog_and_switch);
@ -276,9 +275,9 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
}
}
private Drawable getPluginIcon(OsmandPlugin plugin, boolean pluginEnabled) {
private Drawable getPluginIcon(OsmandPlugin plugin) {
int iconResId = plugin.getLogoResourceId();
return pluginEnabled ? getActiveIcon(iconResId) : getIcon(iconResId, isNightMode() ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light);
return plugin.isActive() ? getActiveIcon(iconResId) : getIcon(iconResId, isNightMode() ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light);
}
private Intent getPluginIntent(OsmandPlugin plugin) {
@ -349,15 +348,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
if (plugin != null) {
if (newValue instanceof Boolean) {
if ((plugin.isActive() || !plugin.needsInstallation())) {
ApplicationMode selectedMode = getSelectedAppMode();
boolean pluginChanged;
if (selectedMode.equals(settings.APPLICATION_MODE.get())) {
pluginChanged = OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue);
} else {
pluginChanged = settings.enablePluginForMode(plugin.getId(), (Boolean) newValue, selectedMode);
}
if (pluginChanged) {
preference.setIcon(getPluginIcon(plugin, (Boolean) newValue));
if (OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue)) {
preference.setIcon(getPluginIcon(plugin));
return true;
}
} else if (plugin.needsInstallation() && preference.getIntent() != null) {

View file

@ -22,6 +22,8 @@ import net.osmand.aidlapi.maplayer.point.AMapPoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -39,6 +41,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.aidl.ConnectedApp.AIDL_LAYERS_PREFIX;
public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider, MapTextLayer.MapTextProvider<AidlMapPointWrapper> {
private static final float POINT_IMAGE_VERTICAL_OFFSET = 0.91f;
@ -54,6 +58,9 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
private String packName;
private AidlMapLayerWrapper aidlLayer;
private CommonPreference<Boolean> layerPref;
private CommonPreference<Boolean> appLayersPref;
private Paint pointInnerCircle;
private Paint pointOuterCircle;
private Paint bitmapPaint;
@ -82,6 +89,10 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
this.map = map;
this.aidlLayer = aidlLayer;
this.packName = packName;
OsmandApplication app = map.getMyApplication();
layerPref = app.getSettings().registerBooleanPreference(packName + "_" + aidlLayer.getId(), true);
appLayersPref = app.getSettings().registerBooleanPreference(AIDL_LAYERS_PREFIX + packName, true);
}
@Override
@ -139,7 +150,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
displayedPoints.clear();
imageRequests.clear();
if (isAppEnabled()) {
if (isLayerEnabled()) {
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
String selectedPointId = getSelectedContextMenuPointId();
@ -234,12 +245,8 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
return Boolean.parseBoolean(point.getParams().get(AMapPoint.POINT_STALE_LOC_PARAM));
}
private boolean isAppEnabled() {
return map.getMyApplication().getAidlApi().isAppEnabled(packName);
}
public String getPackName() {
return packName;
private boolean isLayerEnabled() {
return map.getMyApplication().getAidlApi().isAppEnabled(packName) && appLayersPref.get() && layerPref.get();
}
@Override
@ -273,7 +280,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (isAppEnabled()) {
if (isLayerEnabled()) {
getFromPoint(tileBox, point, o);
}
}