Aidl layers in configure map initial commit

This commit is contained in:
Chumva 2019-12-04 11:34:03 +02:00
parent 082cd608ec
commit e95b964f62
4 changed files with 58 additions and 34 deletions

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

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

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;
@ -54,6 +56,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 +87,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("layers_" + packName, true);
}
@Override
@ -139,7 +148,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 +243,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 +278,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);
}
}