diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index c77d6116e4..c26588dc6b 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -867,6 +867,13 @@ + + + + + + + getAidlCallbacks(); +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/AidlContextMenuButtonWrapper.java b/OsmAnd/src/net/osmand/aidl/AidlContextMenuButtonWrapper.java new file mode 100644 index 0000000000..68d72bde77 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/AidlContextMenuButtonWrapper.java @@ -0,0 +1,64 @@ +package net.osmand.aidl; + +import net.osmand.aidl.contextmenu.AContextMenuButton; + +public class AidlContextMenuButtonWrapper { + + private int buttonId; + + private String leftTextCaption; + private String rightTextCaption; + private String leftIconName; + private String rightIconName; + + private boolean needColorizeIcon; + private boolean enabled; + + public AidlContextMenuButtonWrapper(AContextMenuButton aContextMenuButton) { + buttonId = aContextMenuButton.getButtonId(); + leftTextCaption = aContextMenuButton.getLeftTextCaption(); + rightTextCaption = aContextMenuButton.getRightTextCaption(); + leftIconName = aContextMenuButton.getLeftIconName(); + rightIconName = aContextMenuButton.getRightIconName(); + needColorizeIcon = aContextMenuButton.isTintIcon(); + enabled = aContextMenuButton.isEnabled(); + } + + public AidlContextMenuButtonWrapper(net.osmand.aidl2.contextmenu.AContextMenuButton aContextMenuButton) { + buttonId = aContextMenuButton.getButtonId(); + leftTextCaption = aContextMenuButton.getLeftTextCaption(); + rightTextCaption = aContextMenuButton.getRightTextCaption(); + leftIconName = aContextMenuButton.getLeftIconName(); + rightIconName = aContextMenuButton.getRightIconName(); + needColorizeIcon = aContextMenuButton.isTintIcon(); + enabled = aContextMenuButton.isEnabled(); + } + + public int getButtonId() { + return buttonId; + } + + public String getLeftTextCaption() { + return leftTextCaption; + } + + public String getRightTextCaption() { + return rightTextCaption; + } + + public String getLeftIconName() { + return leftIconName; + } + + public String getRightIconName() { + return rightIconName; + } + + public boolean isTintIcon() { + return needColorizeIcon; + } + + public boolean isEnabled() { + return enabled; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/AidlContextMenuButtonsWrapper.java b/OsmAnd/src/net/osmand/aidl/AidlContextMenuButtonsWrapper.java new file mode 100644 index 0000000000..3b0fe022e9 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/AidlContextMenuButtonsWrapper.java @@ -0,0 +1,86 @@ +package net.osmand.aidl; + +import net.osmand.aidl.contextmenu.AContextMenuButton; +import net.osmand.aidl.contextmenu.ContextMenuButtonsParams; + +import java.util.List; + +public class AidlContextMenuButtonsWrapper { + + private AidlContextMenuButtonWrapper leftButton; + private AidlContextMenuButtonWrapper rightButton; + + private String id; + private String appPackage; + private String layerId; + + private long callbackId; + + private List pointsIds; + + public AidlContextMenuButtonsWrapper(ContextMenuButtonsParams params) { + id = params.getId(); + appPackage = params.getAppPackage(); + layerId = params.getLayerId(); + callbackId = params.getCallbackId(); + pointsIds = params.getPointsIds(); + + AContextMenuButton leftButton = params.getLeftButton(); + AContextMenuButton rightButton = params.getRightButton(); + if (leftButton != null) { + this.leftButton = new AidlContextMenuButtonWrapper(leftButton); + } + if (rightButton != null) { + this.rightButton = new AidlContextMenuButtonWrapper(rightButton); + } + } + + public AidlContextMenuButtonsWrapper(net.osmand.aidl2.contextmenu.ContextMenuButtonsParams params) { + id = params.getId(); + appPackage = params.getAppPackage(); + layerId = params.getLayerId(); + callbackId = params.getCallbackId(); + pointsIds = params.getPointsIds(); + + net.osmand.aidl2.contextmenu.AContextMenuButton leftButton = params.getLeftButton(); + net.osmand.aidl2.contextmenu.AContextMenuButton rightButton = params.getRightButton(); + if (leftButton != null) { + this.leftButton = new AidlContextMenuButtonWrapper(leftButton); + } + if (rightButton != null) { + this.leftButton = new AidlContextMenuButtonWrapper(rightButton); + } + } + + public AidlContextMenuButtonWrapper getLeftButton() { + return leftButton; + } + + public AidlContextMenuButtonWrapper getRightButton() { + return rightButton; + } + + public String getId() { + return id; + } + + public String getAppPackage() { + return appPackage; + } + + public String getLayerId() { + return layerId; + } + + public long getCallbackId() { + return callbackId; + } + + public void setCallbackId(long callbackId) { + this.callbackId = callbackId; + } + + public List getPointsIds() { + return pointsIds; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/AidlMapLayerWrapper.java b/OsmAnd/src/net/osmand/aidl/AidlMapLayerWrapper.java new file mode 100644 index 0000000000..24d50b1d17 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/AidlMapLayerWrapper.java @@ -0,0 +1,153 @@ +package net.osmand.aidl; + +import net.osmand.aidl.maplayer.AMapLayer; +import net.osmand.aidl.maplayer.point.AMapPoint; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class AidlMapLayerWrapper { + + private String id; + private String name; + private float zOrder; + private Map points = new ConcurrentHashMap<>(); + + private boolean imagePoints; + private int circlePointMinZoom; + private int circlePointMaxZoom; + private int smallPointMinZoom; + private int smallPointMaxZoom; + private int bigPointMinZoom; + private int bigPointMaxZoom; + + public AidlMapLayerWrapper(AMapLayer aMapLayer) { + id = aMapLayer.getId(); + name = aMapLayer.getName(); + zOrder = aMapLayer.getZOrder(); + imagePoints = aMapLayer.isImagePoints(); + circlePointMinZoom = aMapLayer.getCirclePointMinZoom(); + circlePointMaxZoom = aMapLayer.getCirclePointMaxZoom(); + smallPointMinZoom = aMapLayer.getSmallPointMinZoom(); + smallPointMaxZoom = aMapLayer.getSmallPointMaxZoom(); + bigPointMinZoom = aMapLayer.getBigPointMinZoom(); + bigPointMaxZoom = aMapLayer.getBigPointMaxZoom(); + + List pointList = aMapLayer.getPoints(); + if (pointList != null) { + for (AMapPoint p : pointList) { + this.points.put(p.getId(), new AidlMapPointWrapper(p)); + } + } + } + + public AidlMapLayerWrapper(net.osmand.aidl2.maplayer.AMapLayer aMapLayer) { + id = aMapLayer.getId(); + name = aMapLayer.getName(); + zOrder = aMapLayer.getZOrder(); + imagePoints = aMapLayer.isImagePoints(); + circlePointMinZoom = aMapLayer.getCirclePointMinZoom(); + circlePointMaxZoom = aMapLayer.getCirclePointMaxZoom(); + smallPointMinZoom = aMapLayer.getSmallPointMinZoom(); + smallPointMaxZoom = aMapLayer.getSmallPointMaxZoom(); + bigPointMinZoom = aMapLayer.getBigPointMinZoom(); + bigPointMaxZoom = aMapLayer.getBigPointMaxZoom(); + + List pointList = aMapLayer.getPoints(); + if (pointList != null) { + for (net.osmand.aidl2.maplayer.point.AMapPoint p : pointList) { + this.points.put(p.getId(), new AidlMapPointWrapper(p)); + } + } + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public float getZOrder() { + return zOrder; + } + + public List getPoints() { + return new ArrayList<>(points.values()); + } + + public AidlMapPointWrapper getPoint(String pointId) { + return points.get(pointId); + } + + public boolean hasPoint(String pointId) { + return points.containsKey(pointId); + } + + public void putPoint(AidlMapPointWrapper point) { + points.put(point.getId(), point); + } + + public void removePoint(String pointId) { + points.remove(pointId); + } + + public boolean isImagePoints() { + return imagePoints; + } + + public void setImagePoints(boolean imagePoints) { + this.imagePoints = imagePoints; + } + + public void copyZoomBounds(AidlMapLayerWrapper layer) { + circlePointMinZoom = layer.circlePointMinZoom; + circlePointMaxZoom = layer.circlePointMaxZoom; + smallPointMinZoom = layer.smallPointMinZoom; + smallPointMaxZoom = layer.smallPointMaxZoom; + bigPointMinZoom = layer.bigPointMinZoom; + bigPointMaxZoom = layer.bigPointMaxZoom; + } + + public void setCirclePointZoomBounds(int min, int max) { + circlePointMinZoom = min; + circlePointMaxZoom = max; + } + + public void setSmallPointZoomBounds(int min, int max) { + smallPointMinZoom = min; + smallPointMaxZoom = max; + } + + public void setBigPointZoomBounds(int min, int max) { + bigPointMinZoom = min; + bigPointMaxZoom = max; + } + + public int getCirclePointMinZoom() { + return circlePointMinZoom; + } + + public int getCirclePointMaxZoom() { + return circlePointMaxZoom; + } + + public int getSmallPointMinZoom() { + return smallPointMinZoom; + } + + public int getSmallPointMaxZoom() { + return smallPointMaxZoom; + } + + public int getBigPointMinZoom() { + return bigPointMinZoom; + } + + public int getBigPointMaxZoom() { + return bigPointMaxZoom; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/AidlMapPointWrapper.java b/OsmAnd/src/net/osmand/aidl/AidlMapPointWrapper.java new file mode 100644 index 0000000000..b58dc1d8c8 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/AidlMapPointWrapper.java @@ -0,0 +1,85 @@ +package net.osmand.aidl; + +import net.osmand.aidl.map.ALatLon; +import net.osmand.aidl.maplayer.point.AMapPoint; +import net.osmand.data.LatLon; + +import java.util.List; +import java.util.Map; + +public class AidlMapPointWrapper { + + private String id; + private String shortName; + private String fullName; + private String typeName; + private String layerId; + private int color; + private LatLon location; + private List details; + private Map params; + + public AidlMapPointWrapper(AMapPoint aMapPoint) { + id = aMapPoint.getId(); + shortName = aMapPoint.getShortName(); + fullName = aMapPoint.getFullName(); + typeName = aMapPoint.getTypeName(); + layerId = aMapPoint.getLayerId(); + color = aMapPoint.getColor(); + + ALatLon aLatLon = aMapPoint.getLocation(); + location = new LatLon(aLatLon.getLatitude(), aLatLon.getLongitude()); + details = aMapPoint.getDetails(); + params = aMapPoint.getParams(); + } + + public AidlMapPointWrapper(net.osmand.aidl2.maplayer.point.AMapPoint aMapPoint) { + id = aMapPoint.getId(); + shortName = aMapPoint.getShortName(); + fullName = aMapPoint.getFullName(); + typeName = aMapPoint.getTypeName(); + layerId = aMapPoint.getLayerId(); + color = aMapPoint.getColor(); + + net.osmand.aidl2.map.ALatLon aLatLon = aMapPoint.getLocation(); + location = new LatLon(aLatLon.getLatitude(), aLatLon.getLongitude()); + details = aMapPoint.getDetails(); + params = aMapPoint.getParams(); + } + + public String getId() { + return id; + } + + public String getShortName() { + return shortName; + } + + public String getFullName() { + return fullName; + } + + public String getTypeName() { + return typeName; + } + + public String getLayerId() { + return layerId; + } + + public int getColor() { + return color; + } + + public LatLon getLocation() { + return location; + } + + public List getDetails() { + return details; + } + + public Map getParams() { + return params; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/AidlMapWidgetWrapper.java b/OsmAnd/src/net/osmand/aidl/AidlMapWidgetWrapper.java new file mode 100644 index 0000000000..e7f91853e5 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/AidlMapWidgetWrapper.java @@ -0,0 +1,78 @@ +package net.osmand.aidl; + +import android.content.Intent; + +import net.osmand.aidl.mapwidget.AMapWidget; + +public class AidlMapWidgetWrapper { + + private String id; + private String menuIconName; + private String menuTitle; + private String lightIconName; + private String darkIconName; + private String text; + private String description; + private int order; + private Intent intentOnClick; + + public AidlMapWidgetWrapper(AMapWidget aMapWidget) { + this.id = aMapWidget.getId(); + this.menuIconName = aMapWidget.getMenuIconName(); + this.menuTitle = aMapWidget.getMenuTitle(); + this.lightIconName = aMapWidget.getLightIconName(); + this.darkIconName = aMapWidget.getDarkIconName(); + this.text = aMapWidget.getText(); + this.description = aMapWidget.getDescription(); + this.order = aMapWidget.getOrder(); + this.intentOnClick = aMapWidget.getIntentOnClick(); + } + + public AidlMapWidgetWrapper(net.osmand.aidl2.mapwidget.AMapWidget aMapWidget) { + this.id = aMapWidget.getId(); + this.menuIconName = aMapWidget.getMenuIconName(); + this.menuTitle = aMapWidget.getMenuTitle(); + this.lightIconName = aMapWidget.getLightIconName(); + this.darkIconName = aMapWidget.getDarkIconName(); + this.text = aMapWidget.getText(); + this.description = aMapWidget.getDescription(); + this.order = aMapWidget.getOrder(); + this.intentOnClick = aMapWidget.getIntentOnClick(); + } + + public String getId() { + return id; + } + + public String getMenuIconName() { + return menuIconName; + } + + public String getMenuTitle() { + return menuTitle; + } + + public String getLightIconName() { + return lightIconName; + } + + public String getDarkIconName() { + return darkIconName; + } + + public String getText() { + return text; + } + + public String getDescription() { + return description; + } + + public int getOrder() { + return order; + } + + public Intent getIntentOnClick() { + return intentOnClick; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/AidlSearchResultWrapper.java b/OsmAnd/src/net/osmand/aidl/AidlSearchResultWrapper.java new file mode 100644 index 0000000000..56a4d0bd1c --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/AidlSearchResultWrapper.java @@ -0,0 +1,52 @@ +package net.osmand.aidl; + +import java.util.ArrayList; +import java.util.List; + +public class AidlSearchResultWrapper { + + private double latitude; + private double longitude; + + private String localName; + private String localTypeName; + + private String alternateName; + private List otherNames = new ArrayList<>(); + + public AidlSearchResultWrapper(double latitude, double longitude, String localName, String localTypeName, + String alternateName, List otherNames) { + this.latitude = latitude; + this.longitude = longitude; + this.localName = localName; + this.localTypeName = localTypeName; + this.alternateName = alternateName; + if (otherNames != null) { + this.otherNames.addAll(otherNames); + } + } + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + public String getLocalName() { + return localName; + } + + public String getLocalTypeName() { + return localTypeName; + } + + public String getAlternateName() { + return alternateName; + } + + public List getOtherNames() { + return otherNames; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index eda1af39f0..8c96796c36 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -17,7 +17,6 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; -import android.os.RemoteException; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; @@ -30,27 +29,11 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; -import net.osmand.aidl.contextmenu.ContextMenuButtonsParams; -import net.osmand.aidl.copyfile.CopyFileParams; -import net.osmand.aidl.customization.CustomizationInfoParams; -import net.osmand.aidl.favorite.AFavorite; -import net.osmand.aidl.favorite.group.AFavoriteGroup; -import net.osmand.aidl.gpx.AGpxBitmap; import net.osmand.aidl.gpx.AGpxFile; import net.osmand.aidl.gpx.AGpxFileDetails; import net.osmand.aidl.gpx.ASelectedGpxFile; -import net.osmand.aidl.gpx.GpxColorParams; -import net.osmand.aidl.gpx.StartGpxRecordingParams; -import net.osmand.aidl.gpx.StopGpxRecordingParams; -import net.osmand.aidl.maplayer.AMapLayer; -import net.osmand.aidl.maplayer.point.AMapPoint; -import net.osmand.aidl.mapmarker.AMapMarker; -import net.osmand.aidl.mapwidget.AMapWidget; -import net.osmand.aidl.navdrawer.NavDrawerFooterParams; import net.osmand.aidl.navigation.ADirectionInfo; import net.osmand.aidl.navigation.OnVoiceNavigationParams; -import net.osmand.aidl.plugins.PluginParams; -import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -66,6 +49,7 @@ import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -132,6 +116,7 @@ import static net.osmand.aidl.OsmandAidlService.KEY_ON_VOICE_MESSAGE; public class OsmandAidlApi { AidlCallbackListener aidlCallbackListener = null; + AidlCallbackListenerV2 aidlCallbackListenerV2 = null; private static final Log LOG = PlatformUtil.getLog(OsmandAidlApi.class); private static final String AIDL_REFRESH_MAP = "aidl_refresh_map"; @@ -187,7 +172,7 @@ public class OsmandAidlApi { private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR; - private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ + private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[] { ApplicationMode.CAR, ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN @@ -196,14 +181,14 @@ public class OsmandAidlApi { private static final int DEFAULT_ZOOM = 15; private OsmandApplication app; - private Map widgets = new ConcurrentHashMap<>(); + private Map widgets = new ConcurrentHashMap<>(); private Map widgetControls = new ConcurrentHashMap<>(); - private Map layers = new ConcurrentHashMap<>(); + private Map layers = new ConcurrentHashMap<>(); private Map mapLayers = new ConcurrentHashMap<>(); private Map receivers = new TreeMap<>(); private Map connectedApps = new ConcurrentHashMap<>(); - private Map contextMenuButtonsParams = new ConcurrentHashMap<>(); - private Map voiceRouterMessageCallbacks= new ConcurrentHashMap<>(); + private Map contextMenuButtonsParams = new ConcurrentHashMap<>(); + private Map voiceRouterMessageCallbacks = new ConcurrentHashMap<>(); private AMapPointUpdateListener aMapPointUpdateListener; @@ -247,7 +232,7 @@ public class OsmandAidlApi { aMapPointUpdateListener = null; mapActivityActive = false; for (BroadcastReceiver b : receivers.values()) { - if(b == null) { + if (b == null) { continue; } try { @@ -264,7 +249,7 @@ public class OsmandAidlApi { } private void initOsmandTelegram() { - String[] packages = new String[]{"net.osmand.telegram", "net.osmand.telegram.debug"}; + String[] packages = new String[] {"net.osmand.telegram", "net.osmand.telegram.debug"}; Intent intent = new Intent("net.osmand.telegram.InitApp"); for (String pack : packages) { intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver")); @@ -335,7 +320,7 @@ public class OsmandAidlApi { MapActivity mapActivity = mapActivityRef.get(); String widgetId = intent.getStringExtra(AIDL_OBJECT_ID); if (mapActivity != null && widgetId != null) { - AMapWidget widget = widgets.get(widgetId); + AidlMapWidgetWrapper widget = widgets.get(widgetId); if (widget != null) { MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer(); if (layer != null) { @@ -365,7 +350,7 @@ public class OsmandAidlApi { MapActivity mapActivity = mapActivityRef.get(); String ContextMenuButtonsParamsId = intent.getStringExtra(AIDL_OBJECT_ID); if (mapActivity != null && ContextMenuButtonsParamsId != null) { - ContextMenuButtonsParams buttonsParams = contextMenuButtonsParams.get(ContextMenuButtonsParamsId); + AidlContextMenuButtonsWrapper buttonsParams = contextMenuButtonsParams.get(ContextMenuButtonsParamsId); if (buttonsParams != null) { MapContextMenu mapContextMenu = mapActivity.getContextMenu(); if (mapContextMenu.isVisible()) { @@ -378,8 +363,7 @@ public class OsmandAidlApi { registerReceiver(addContextMenuButtonsParamsReceiver, mapActivity, AIDL_ADD_CONTEXT_MENU_BUTTONS); } - private void registerReceiver(BroadcastReceiver rec, MapActivity ma, - String filter) { + private void registerReceiver(BroadcastReceiver rec, MapActivity ma, String filter) { receivers.put(filter, rec); ma.registerReceiver(rec, new IntentFilter(filter)); } @@ -406,7 +390,7 @@ public class OsmandAidlApi { } public void registerWidgetControls(MapActivity mapActivity) { - for (AMapWidget widget : widgets.values()) { + for (AidlMapWidgetWrapper widget : widgets.values()) { MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer(); if (layer != null) { TextInfoWidget control = createWidgetControl(mapActivity, widget.getId()); @@ -430,7 +414,7 @@ public class OsmandAidlApi { MapActivity mapActivity = mapActivityRef.get(); String layerId = intent.getStringExtra(AIDL_OBJECT_ID); if (mapActivity != null && layerId != null) { - AMapLayer layer = layers.get(layerId); + AidlMapLayerWrapper layer = layers.get(layerId); if (layer != null) { OsmandMapLayer mapLayer = mapLayers.get(layerId); if (mapLayer != null) { @@ -851,7 +835,7 @@ public class OsmandAidlApi { } public void registerMapLayers(MapActivity mapActivity) { - for (AMapLayer layer : layers.values()) { + for (AidlMapLayerWrapper layer : layers.values()) { OsmandMapLayer mapLayer = mapLayers.get(layer.getId()); if (mapLayer != null) { mapActivity.getMapView().removeLayer(mapLayer); @@ -873,7 +857,7 @@ public class OsmandAidlApi { @Override public boolean updateInfo(DrawSettings drawSettings) { - AMapWidget widget = widgets.get(widgetId); + AidlMapWidgetWrapper widget = widgets.get(widgetId); if (widget != null) { String txt = widget.getText(); String subtxt = widget.getDescription(); @@ -896,7 +880,7 @@ public class OsmandAidlApi { control.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - AMapWidget widget = widgets.get(widgetId); + AidlMapWidgetWrapper widget = widgets.get(widgetId); if (widget != null && widget.getIntentOnClick() != null) { app.startActivity(widget.getIntentOnClick()); } @@ -910,154 +894,122 @@ public class OsmandAidlApi { return true; } - boolean addFavoriteGroup(AFavoriteGroup favoriteGroup) { - if (favoriteGroup != null) { - FavouritesDbHelper favoritesHelper = app.getFavorites(); - List groups = favoritesHelper.getFavoriteGroups(); - for (FavouritesDbHelper.FavoriteGroup g : groups) { - if (g.name.equals(favoriteGroup.getName())) { - return false; + boolean addFavoriteGroup(String name, String colorTag, boolean visible) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(name)) { + return false; + } + } + int color = 0; + if (!Algorithms.isEmpty(colorTag)) { + color = ColorDialogs.getColorByTag(colorTag); + } + favoritesHelper.addEmptyCategory(name, color, visible); + return true; + } + + boolean removeFavoriteGroup(String name) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(name)) { + favoritesHelper.deleteGroup(g); + return true; + } + } + return false; + } + + boolean updateFavoriteGroup(String prevGroupName, String newGroupName, String colorTag, boolean visible) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(prevGroupName)) { + int color = 0; + if (!Algorithms.isEmpty(colorTag)) { + color = ColorDialogs.getColorByTag(colorTag); } + favoritesHelper.editFavouriteGroup(g, newGroupName, color, visible); + return true; } - int color = 0; - if (!Algorithms.isEmpty(favoriteGroup.getColor())) { - color = ColorDialogs.getColorByTag(favoriteGroup.getColor()); - } - favoritesHelper.addEmptyCategory(favoriteGroup.getName(), color, favoriteGroup.isVisible()); - return true; - } else { - return false; } + return false; } - boolean removeFavoriteGroup(AFavoriteGroup favoriteGroup) { - if (favoriteGroup != null) { - FavouritesDbHelper favoritesHelper = app.getFavorites(); - List groups = favoritesHelper.getFavoriteGroups(); - for (FavouritesDbHelper.FavoriteGroup g : groups) { - if (g.name.equals(favoriteGroup.getName())) { - favoritesHelper.deleteGroup(g); - return true; + boolean addFavorite(double latitude, double longitude, String name, String category, String description, String colorTag, boolean visible) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + FavouritePoint point = new FavouritePoint(latitude, longitude, name, category); + point.setDescription(description); + int color = 0; + if (!Algorithms.isEmpty(colorTag)) { + color = ColorDialogs.getColorByTag(colorTag); + } + point.setColor(color); + point.setVisible(visible); + favoritesHelper.addFavourite(point); + refreshMap(); + return true; + } + + boolean removeFavorite(String name, String category, double latitude, double longitude) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List favorites = favoritesHelper.getFavouritePoints(); + for (FavouritePoint f : favorites) { + if (f.getName().equals(name) && f.getCategory().equals(category) && + f.getLatitude() == latitude && f.getLongitude() == longitude) { + favoritesHelper.deleteFavourite(f); + refreshMap(); + return true; + } + } + return false; + } + + boolean updateFavorite(String prevName, String prevCategory, double prevLat, double prevLon, String newName, String newCategory, String newDescription, double newLat, double newLon) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List favorites = favoritesHelper.getFavouritePoints(); + for (FavouritePoint f : favorites) { + if (f.getName().equals(prevName) && f.getCategory().equals(prevCategory) && + f.getLatitude() == prevLat && f.getLongitude() == prevLon) { + if (newLat != f.getLatitude() || newLon != f.getLongitude()) { + favoritesHelper.editFavourite(f, newLat, newLon); } - } - return false; - } else { - return false; - } - } - - boolean updateFavoriteGroup(AFavoriteGroup gPrev, AFavoriteGroup gNew) { - if (gPrev != null && gNew != null) { - FavouritesDbHelper favoritesHelper = app.getFavorites(); - List groups = favoritesHelper.getFavoriteGroups(); - for (FavouritesDbHelper.FavoriteGroup g : groups) { - if (g.name.equals(gPrev.getName())) { - int color = 0; - if (!Algorithms.isEmpty(gNew.getColor())) { - color = ColorDialogs.getColorByTag(gNew.getColor()); - } - favoritesHelper.editFavouriteGroup(g, gNew.getName(), color, gNew.isVisible()); - return true; + if (!newName.equals(f.getName()) || !newDescription.equals(f.getDescription()) || + !newCategory.equals(f.getCategory())) { + favoritesHelper.editFavouriteName(f, newName, newCategory, newDescription); } + refreshMap(); + return true; } - return false; - } else { - return false; } + return false; } - boolean addFavorite(AFavorite favorite) { - if (favorite != null) { - FavouritesDbHelper favoritesHelper = app.getFavorites(); - FavouritePoint point = new FavouritePoint(favorite.getLat(), favorite.getLon(), favorite.getName(), favorite.getCategory()); - point.setDescription(favorite.getDescription()); - int color = 0; - if (!Algorithms.isEmpty(favorite.getColor())) { - color = ColorDialogs.getColorByTag(favorite.getColor()); - } - point.setColor(color); - point.setVisible(favorite.isVisible()); - favoritesHelper.addFavourite(point); - refreshMap(); - return true; - } else { - return false; - } + boolean addMapMarker(String name, double latitude, double longitude) { + PointDescription pd = new PointDescription( + PointDescription.POINT_TYPE_MAP_MARKER, name != null ? name : ""); + MapMarkersHelper markersHelper = app.getMapMarkersHelper(); + markersHelper.addMapMarker(new LatLon(latitude, longitude), pd); + refreshMap(); + return true; } - boolean removeFavorite(AFavorite favorite) { - if (favorite != null) { - FavouritesDbHelper favoritesHelper = app.getFavorites(); - List favorites = favoritesHelper.getFavouritePoints(); - for (FavouritePoint f : favorites) { - if (f.getName().equals(favorite.getName()) && f.getCategory().equals(favorite.getCategory()) && - f.getLatitude() == favorite.getLat() && f.getLongitude() == favorite.getLon()) { - favoritesHelper.deleteFavourite(f); + boolean removeMapMarker(String name, double latitude, double longitude, boolean ignoreCoordinates) { + LatLon latLon = new LatLon(latitude, longitude); + MapMarkersHelper markersHelper = app.getMapMarkersHelper(); + List mapMarkers = markersHelper.getMapMarkers(); + for (MapMarker m : mapMarkers) { + if (m.getOnlyName().equals(name)) { + if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { + markersHelper.moveMapMarkerToHistory(m); refreshMap(); return true; } } - return false; - } else { - return false; - } - } - - boolean updateFavorite(AFavorite fPrev, AFavorite fNew) { - if (fPrev != null && fNew != null) { - FavouritesDbHelper favoritesHelper = app.getFavorites(); - List favorites = favoritesHelper.getFavouritePoints(); - for (FavouritePoint f : favorites) { - if (f.getName().equals(fPrev.getName()) && f.getCategory().equals(fPrev.getCategory()) && - f.getLatitude() == fPrev.getLat() && f.getLongitude() == fPrev.getLon()) { - if (fNew.getLat() != f.getLatitude() || fNew.getLon() != f.getLongitude()) { - favoritesHelper.editFavourite(f, fNew.getLat(), fNew.getLon()); - } - if (!fNew.getName().equals(f.getName()) || !fNew.getDescription().equals(f.getDescription()) || - !fNew.getCategory().equals(f.getCategory())) { - favoritesHelper.editFavouriteName(f, fNew.getName(), fNew.getCategory(), fNew.getDescription()); - } - refreshMap(); - return true; - } - } - return false; - } else { - return false; - } - } - - boolean addMapMarker(AMapMarker marker) { - if (marker != null) { - PointDescription pd = new PointDescription( - PointDescription.POINT_TYPE_MAP_MARKER, marker.getName() != null ? marker.getName() : ""); - MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - markersHelper.addMapMarker(new LatLon(marker.getLatLon().getLatitude(), marker.getLatLon().getLongitude()), pd); - refreshMap(); - return true; - } else { - return false; - } - } - - boolean removeMapMarker(AMapMarker marker, boolean ignoreCoordinates) { - if (marker != null) { - LatLon latLon = new LatLon(marker.getLatLon().getLatitude(), marker.getLatLon().getLongitude()); - MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - List mapMarkers = markersHelper.getMapMarkers(); - for (MapMarker m : mapMarkers) { - if (m.getOnlyName().equals(marker.getName())) { - if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { - markersHelper.moveMapMarkerToHistory(m); - refreshMap(); - return true; - } - } - } - return false; - } else { - return false; } + return false; } boolean removeAllActiveMapMarkers() { @@ -1075,34 +1027,30 @@ public class OsmandAidlApi { } - boolean updateMapMarker(AMapMarker markerPrev, AMapMarker markerNew, boolean ignoreCoordinates) { - if (markerPrev != null && markerNew != null) { - LatLon latLon = new LatLon(markerPrev.getLatLon().getLatitude(), markerPrev.getLatLon().getLongitude()); - LatLon latLonNew = new LatLon(markerNew.getLatLon().getLatitude(), markerNew.getLatLon().getLongitude()); - MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - List mapMarkers = markersHelper.getMapMarkers(); - for (MapMarker m : mapMarkers) { - if (m.getOnlyName().equals(markerPrev.getName())) { - if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { - PointDescription pd = new PointDescription( - PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); - MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); - marker.id = m.id; - marker.creationDate = m.creationDate; - marker.visitedDate = m.visitedDate; - markersHelper.moveMapMarker(marker, latLonNew); - refreshMap(); - return true; - } + boolean updateMapMarker(String prevName, LatLon prevLatLon, String newName, LatLon newLatLon, boolean ignoreCoordinates) { + LatLon latLon = new LatLon(prevLatLon.getLatitude(), prevLatLon.getLongitude()); + LatLon latLonNew = new LatLon(newLatLon.getLatitude(), newLatLon.getLongitude()); + MapMarkersHelper markersHelper = app.getMapMarkersHelper(); + List mapMarkers = markersHelper.getMapMarkers(); + for (MapMarker m : mapMarkers) { + if (m.getOnlyName().equals(prevName)) { + if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { + PointDescription pd = new PointDescription( + PointDescription.POINT_TYPE_MAP_MARKER, newName != null ? newName : ""); + MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); + marker.id = m.id; + marker.creationDate = m.creationDate; + marker.visitedDate = m.visitedDate; + markersHelper.moveMapMarker(marker, latLonNew); + refreshMap(); + return true; } } - return false; - } else { - return false; } + return false; } - boolean addMapWidget(AMapWidget widget) { + boolean addMapWidget(AidlMapWidgetWrapper widget) { if (widget != null) { if (widgets.containsKey(widget.getId())) { updateMapWidget(widget); @@ -1133,7 +1081,7 @@ public class OsmandAidlApi { } } - boolean updateMapWidget(AMapWidget widget) { + boolean updateMapWidget(AidlMapWidgetWrapper widget) { if (widget != null && widgets.containsKey(widget.getId())) { widgets.put(widget.getId(), widget); refreshMap(); @@ -1143,7 +1091,7 @@ public class OsmandAidlApi { } } - boolean addMapLayer(AMapLayer layer) { + boolean addMapLayer(AidlMapLayerWrapper layer) { if (layer != null) { if (layers.containsKey(layer.getId())) { updateMapLayer(layer); @@ -1174,10 +1122,10 @@ public class OsmandAidlApi { } } - boolean updateMapLayer(AMapLayer layer) { + boolean updateMapLayer(AidlMapLayerWrapper layer) { if (layer != null && layers.containsKey(layer.getId())) { - AMapLayer existingLayer = layers.get(layer.getId()); - for (AMapPoint point : layer.getPoints()) { + AidlMapLayerWrapper existingLayer = layers.get(layer.getId()); + for (AidlMapPointWrapper point : layer.getPoints()) { existingLayer.putPoint(point); } existingLayer.copyZoomBounds(layer); @@ -1188,12 +1136,12 @@ public class OsmandAidlApi { } } - boolean showMapPoint(String layerId, AMapPoint point) { + boolean showMapPoint(String layerId, AidlMapPointWrapper point) { if (point != null) { if (!TextUtils.isEmpty(layerId)) { - AMapLayer layer = layers.get(layerId); + AidlMapLayerWrapper layer = layers.get(layerId); if (layer != null) { - AMapPoint p = layer.getPoint(point.getId()); + AidlMapPointWrapper p = layer.getPoint(point.getId()); if (p != null) { point = p; } @@ -1214,9 +1162,9 @@ public class OsmandAidlApi { return false; } - boolean putMapPoint(String layerId, AMapPoint point) { + boolean putMapPoint(String layerId, AidlMapPointWrapper point) { if (point != null) { - AMapLayer layer = layers.get(layerId); + AidlMapLayerWrapper layer = layers.get(layerId); if (layer != null) { layer.putPoint(point); refreshMap(); @@ -1226,9 +1174,9 @@ public class OsmandAidlApi { return false; } - boolean updateMapPoint(String layerId, AMapPoint point, boolean updateOpenedMenuAndMap) { + boolean updateMapPoint(String layerId, AidlMapPointWrapper point, boolean updateOpenedMenuAndMap) { if (point != null) { - AMapLayer layer = layers.get(layerId); + AidlMapLayerWrapper layer = layers.get(layerId); if (layer != null) { layer.putPoint(point); refreshMap(); @@ -1243,7 +1191,7 @@ public class OsmandAidlApi { boolean removeMapPoint(String layerId, String pointId) { if (pointId != null) { - AMapLayer layer = layers.get(layerId); + AidlMapLayerWrapper layer = layers.get(layerId); if (layer != null) { layer.removePoint(pointId); refreshMap(); @@ -1256,7 +1204,7 @@ public class OsmandAidlApi { @SuppressLint("StaticFieldLeak") private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) { int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor( - app.getRendererRegistry().getCurrentSelectedRenderer(), color); + app.getRendererRegistry().getCurrentSelectedRenderer(), color); if (!destinationExists) { GpxDataItem gpxDataItem = new GpxDataItem(destination, col); gpxDataItem.setApiImported(true); @@ -1449,69 +1397,95 @@ public class OsmandAidlApi { } boolean getActiveGpx(List files) { - if (files != null) { - List selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles(); - String gpxPath = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath(); - for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) { - GPXFile gpxFile = selectedGpxFile.getGpxFile(); - String path = gpxFile.path; - if (!Algorithms.isEmpty(path)) { - if (path.startsWith(gpxPath)) { - path = path.substring(gpxPath.length() + 1); - } - long modifiedTime = gpxFile.modifiedTime; - long fileSize = new File(gpxFile.path).length(); - files.add(new ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetails(selectedGpxFile.getTrackAnalysis()))); + List selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles(); + String gpxPath = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath(); + for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) { + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + String path = gpxFile.path; + if (!Algorithms.isEmpty(path)) { + if (path.startsWith(gpxPath)) { + path = path.substring(gpxPath.length() + 1); } + long modifiedTime = gpxFile.modifiedTime; + long fileSize = new File(gpxFile.path).length(); + files.add(new ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetails(selectedGpxFile.getTrackAnalysis()))); } - return true; } - return false; + return true; + } + + boolean getActiveGpxV2(List files) { + List selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles(); + String gpxPath = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath(); + for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) { + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + String path = gpxFile.path; + if (!Algorithms.isEmpty(path)) { + if (path.startsWith(gpxPath)) { + path = path.substring(gpxPath.length() + 1); + } + long modifiedTime = gpxFile.modifiedTime; + long fileSize = new File(gpxFile.path).length(); + files.add(new net.osmand.aidl2.gpx.ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetailsV2(selectedGpxFile.getTrackAnalysis()))); + } + } + return true; + } + + boolean getImportedGpxV2(List files) { + List gpxDataItems = app.getGpxDatabase().getItems(); + for (GpxDataItem dataItem : gpxDataItems) { + File file = dataItem.getFile(); + if (file.exists()) { + String fileName = file.getName(); + boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null; + long modifiedTime = dataItem.getFileLastModifiedTime(); + long fileSize = file.length(); + net.osmand.aidl2.gpx.AGpxFileDetails details = null; + GPXTrackAnalysis analysis = dataItem.getAnalysis(); + if (analysis != null) { + details = createGpxFileDetailsV2(analysis); + } + files.add(new net.osmand.aidl2.gpx.AGpxFile(fileName, modifiedTime, fileSize, active, details)); + } + } + return true; } boolean getImportedGpx(List files) { - if (files != null) { - List gpxDataItems = app.getGpxDatabase().getItems(); - for (GpxDataItem dataItem : gpxDataItems) { - //if (dataItem.isApiImported()) { - File file = dataItem.getFile(); - if (file.exists()) { - String fileName = file.getName(); - boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null; - long modifiedTime = dataItem.getFileLastModifiedTime(); - long fileSize = file.length(); - AGpxFileDetails details = null; - GPXTrackAnalysis analysis = dataItem.getAnalysis(); - if (analysis != null) { - details = createGpxFileDetails(analysis); - } - files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details)); - } - //} + List gpxDataItems = app.getGpxDatabase().getItems(); + for (GpxDataItem dataItem : gpxDataItems) { + File file = dataItem.getFile(); + if (file.exists()) { + String fileName = file.getName(); + boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null; + long modifiedTime = dataItem.getFileLastModifiedTime(); + long fileSize = file.length(); + AGpxFileDetails details = null; + GPXTrackAnalysis analysis = dataItem.getAnalysis(); + if (analysis != null) { + details = createGpxFileDetails(analysis); + } + files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details)); } - return true; } - return false; + return true; } - boolean getGpxColor(GpxColorParams params) { - if (params != null) { - List gpxDataItems = app.getGpxDatabase().getItems(); - for (GpxDataItem dataItem : gpxDataItems) { - File file = dataItem.getFile(); - if (file.exists()) { - if (file.getName().equals(params.getFileName())) { - int color = dataItem.getColor(); - if (color != 0) { - String colorName = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color); - params.setGpxColor(colorName); - return true; - } + String getGpxColor(String gpxFileName) { + List gpxDataItems = app.getGpxDatabase().getItems(); + for (GpxDataItem dataItem : gpxDataItems) { + File file = dataItem.getFile(); + if (file.exists()) { + if (file.getName().equals(gpxFileName)) { + int color = dataItem.getColor(); + if (color != 0) { + return ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color); } } } } - return false; + return null; } boolean removeGpx(String fileName) { @@ -1530,27 +1504,45 @@ public class OsmandAidlApi { } private boolean getSqliteDbFiles(List fileNames, boolean activeOnly) { - if (fileNames != null) { - File tilesPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR); - if (tilesPath.canRead()) { - File[] files = tilesPath.listFiles(); - if (files != null) { - String activeFile = app.getSettings().MAP_OVERLAY.get(); - for (File tileFile : files) { - String fileName = tileFile.getName(); - String fileNameLC = fileName.toLowerCase(); - if (tileFile.isFile() && !fileNameLC.startsWith("hillshade") && fileNameLC.endsWith(SQLiteTileSource.EXT)) { - boolean active = fileName.equals(activeFile); - if (!activeOnly || active) { - fileNames.add(new ASqliteDbFile(fileName, tileFile.lastModified(), tileFile.length(), active)); - } + File tilesPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR); + if (tilesPath.canRead()) { + File[] files = tilesPath.listFiles(); + if (files != null) { + String activeFile = app.getSettings().MAP_OVERLAY.get(); + for (File tileFile : files) { + String fileName = tileFile.getName(); + String fileNameLC = fileName.toLowerCase(); + if (tileFile.isFile() && !fileNameLC.startsWith("hillshade") && fileNameLC.endsWith(SQLiteTileSource.EXT)) { + boolean active = fileName.equals(activeFile); + if (!activeOnly || active) { + fileNames.add(new ASqliteDbFile(fileName, tileFile.lastModified(), tileFile.length(), active)); } } } } - return true; } - return false; + return true; + } + + private boolean getSqliteDbFilesV2(List fileNames, boolean activeOnly) { + File tilesPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR); + if (tilesPath.canRead()) { + File[] files = tilesPath.listFiles(); + if (files != null) { + String activeFile = app.getSettings().MAP_OVERLAY.get(); + for (File tileFile : files) { + String fileName = tileFile.getName(); + String fileNameLC = fileName.toLowerCase(); + if (tileFile.isFile() && !fileNameLC.startsWith("hillshade") && fileNameLC.endsWith(SQLiteTileSource.EXT)) { + boolean active = fileName.equals(activeFile); + if (!activeOnly || active) { + fileNames.add(new net.osmand.aidl2.tiles.ASqliteDbFile(fileName, tileFile.lastModified(), tileFile.length(), active)); + } + } + } + } + } + return true; } boolean getSqliteDbFiles(List fileNames) { @@ -1561,6 +1553,14 @@ public class OsmandAidlApi { return getSqliteDbFiles(fileNames, true); } + boolean getSqliteDbFilesV2(List fileNames) { + return getSqliteDbFilesV2(fileNames, false); + } + + boolean getActiveSqliteDbFilesV2(List fileNames) { + return getSqliteDbFilesV2(fileNames, true); + } + boolean showSqliteDbFile(String fileName) { if (!Algorithms.isEmpty(fileName)) { File tileFile = new File(app.getAppPath(IndexConstants.TILES_INDEX_DIR), fileName); @@ -1608,7 +1608,7 @@ public class OsmandAidlApi { return true; } - boolean startGpxRecording(StartGpxRecordingParams params) { + boolean startGpxRecording() { final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); if (plugin != null) { plugin.startGPXMonitoring(null); @@ -1618,7 +1618,7 @@ public class OsmandAidlApi { return false; } - boolean stopGpxRecording(StopGpxRecordingParams params) { + boolean stopGpxRecording() { final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); if (plugin != null) { plugin.stopRecording(); @@ -1663,8 +1663,8 @@ public class OsmandAidlApi { } boolean navigate(String startName, double startLat, double startLon, - String destName, double destLat, double destLon, - String profile, boolean force) { + String destName, double destLat, double destLon, + String profile, boolean force) { Intent intent = new Intent(); intent.setAction(AIDL_NAVIGATE); intent.putExtra(AIDL_START_NAME, startName); @@ -1680,8 +1680,8 @@ public class OsmandAidlApi { } boolean navigateSearch(String startName, double startLat, double startLon, - String searchQuery, double searchLat, double searchLon, - String profile, boolean force) { + String searchQuery, double searchLat, double searchLon, + String profile, boolean force) { Intent intent = new Intent(); intent.setAction(AIDL_NAVIGATE_SEARCH); intent.putExtra(AIDL_START_NAME, startName); @@ -1742,7 +1742,7 @@ public class OsmandAidlApi { } boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude, - final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) { + final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) { if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) { return false; } @@ -1763,8 +1763,7 @@ public class OsmandAidlApi { return true; } - boolean registerForOsmandInitialization(final OsmandAppInitCallback callback) - throws RemoteException { + boolean registerForOsmandInitialization(final OsmandAppInitCallback callback) { if (app.isApplicationInitializing()) { app.getAppInitializer().addListener(new AppInitializeListener() { @Override @@ -1786,7 +1785,7 @@ public class OsmandAidlApi { return true; } - boolean setNavDrawerItems(String appPackage, List items) { + boolean setNavDrawerItems(String appPackage, List items) { return app.getAppCustomization().setNavDrawerItems(appPackage, items); } @@ -1887,7 +1886,7 @@ public class OsmandAidlApi { } boolean setNavDrawerLogo(@Nullable String uri) { - return app.getAppCustomization().setNavDrawerLogo(uri,null, null); + return app.getAppCustomization().setNavDrawerLogo(uri, null, null); } boolean setEnabledIds(Collection ids) { @@ -1930,38 +1929,38 @@ public class OsmandAidlApi { return app.getAppCustomization().setNavDrawerLogoWithParams(uri, packageName, intent); } - boolean setNavDrawerFooterWithParams(@NonNull NavDrawerFooterParams params) { - return app.getAppCustomization().setNavDrawerFooterParams(params); + boolean setNavDrawerFooterWithParams(String uri, @Nullable String packageName, @Nullable String intent) { + return app.getAppCustomization().setNavDrawerFooterParams(uri, packageName, intent); } boolean restoreOsmand() { return app.getAppCustomization().restoreOsmand(); } - boolean changePluginState(PluginParams params) { - return app.getAppCustomization().changePluginStatus(params); + boolean changePluginState(String pluginId, int newState) { + return app.getAppCustomization().changePluginStatus(pluginId, newState); } private Map navUpdateCallbacks = new ConcurrentHashMap<>(); void registerForNavigationUpdates(long id) { - final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); final NextDirectionInfo baseNdi = new NextDirectionInfo(); IRoutingDataUpdateListener listener = new IRoutingDataUpdateListener() { @Override public void onRoutingDataUpdate() { - RoutingHelper rh = app.getRoutingHelper(); - if (rh.isDeviatedFromRoute()) { - directionInfo.setTurnType(TurnType.OFFR); - directionInfo.setDistanceTo((int) rh.getRouteDeviation()); - } else { - NextDirectionInfo ndi = rh.getNextRouteDirectionInfo(baseNdi, true); - if (ndi != null && ndi.distanceTo > 0 && ndi.directionInfo != null) { - directionInfo.setDistanceTo(ndi.distanceTo); - directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); - } - } if (aidlCallbackListener != null) { + ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); + RoutingHelper rh = app.getRoutingHelper(); + if (rh.isDeviatedFromRoute()) { + directionInfo.setTurnType(TurnType.OFFR); + directionInfo.setDistanceTo((int) rh.getRouteDeviation()); + } else { + NextDirectionInfo ndi = rh.getNextRouteDirectionInfo(baseNdi, true); + if (ndi != null && ndi.distanceTo > 0 && ndi.directionInfo != null) { + directionInfo.setDistanceTo(ndi.distanceTo); + directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); + } + } for (OsmandAidlService.AidlCallbackParams cb : aidlCallbackListener.getAidlCallbacks().values()) { if (!aidlCallbackListener.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) { try { @@ -1972,6 +1971,29 @@ public class OsmandAidlApi { } } } + if (aidlCallbackListenerV2 != null) { + net.osmand.aidl2.navigation.ADirectionInfo directionInfo = new net.osmand.aidl2.navigation.ADirectionInfo(-1, -1, false); + RoutingHelper rh = app.getRoutingHelper(); + if (rh.isDeviatedFromRoute()) { + directionInfo.setTurnType(TurnType.OFFR); + directionInfo.setDistanceTo((int) rh.getRouteDeviation()); + } else { + NextDirectionInfo ndi = rh.getNextRouteDirectionInfo(baseNdi, true); + if (ndi != null && ndi.distanceTo > 0 && ndi.directionInfo != null) { + directionInfo.setDistanceTo(ndi.distanceTo); + directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); + } + } + for (OsmandAidlServiceV2.AidlCallbackParams cb : aidlCallbackListenerV2.getAidlCallbacks().values()) { + if (!aidlCallbackListenerV2.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) { + try { + cb.getCallback().updateNavigationInfo(directionInfo); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + } + } + } } }; navUpdateCallbacks.put(id, listener); @@ -1998,6 +2020,17 @@ public class OsmandAidlApi { } } } + if (aidlCallbackListenerV2 != null) { + for (OsmandAidlServiceV2.AidlCallbackParams cb : aidlCallbackListenerV2.getAidlCallbacks().values()) { + if (!aidlCallbackListenerV2.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_VOICE_MESSAGE) > 0) { + try { + cb.getCallback().onVoiceRouterNotify(new net.osmand.aidl2.navigation.OnVoiceNavigationParams(cmds, played)); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + } + } + } } }; voiceRouterMessageCallbacks.put(id, listener); @@ -2009,11 +2042,11 @@ public class OsmandAidlApi { voiceRouterMessageCallbacks.remove(id); } - public Map getContextMenuButtonsParams() { + public Map getContextMenuButtonsParams() { return contextMenuButtonsParams; } - boolean addContextMenuButtons(ContextMenuButtonsParams buttonsParams, long callbackId) { + boolean addContextMenuButtons(AidlContextMenuButtonsWrapper buttonsParams, long callbackId) { if (buttonsParams != null) { if (contextMenuButtonsParams.containsKey(buttonsParams.getId())) { updateContextMenuButtons(buttonsParams, callbackId); @@ -2045,7 +2078,7 @@ public class OsmandAidlApi { } } - boolean updateContextMenuButtons(ContextMenuButtonsParams buttonsParams, long callbackId) { + boolean updateContextMenuButtons(AidlContextMenuButtonsWrapper buttonsParams, long callbackId) { if (buttonsParams != null && contextMenuButtonsParams.containsKey(buttonsParams.getId())) { contextMenuButtonsParams.put(buttonsParams.getId(), buttonsParams); addContextMenuButtonListener(buttonsParams, callbackId); @@ -2059,12 +2092,7 @@ public class OsmandAidlApi { return app.getAppCustomization().areSettingsCustomizedForPreference(sharedPreferencesName); } - boolean setCustomization(CustomizationInfoParams params) { - app.getAppCustomization().setCustomization(params); - return true; - } - - private void addContextMenuButtonListener(ContextMenuButtonsParams buttonsParams, long callbackId) { + private void addContextMenuButtonListener(AidlContextMenuButtonsWrapper buttonsParams, long callbackId) { IContextMenuButtonListener listener = new IContextMenuButtonListener() { @Override @@ -2080,6 +2108,17 @@ public class OsmandAidlApi { } } } + if (aidlCallbackListenerV2 != null) { + for (OsmandAidlServiceV2.AidlCallbackParams cb : aidlCallbackListenerV2.getAidlCallbacks().values()) { + if (!aidlCallbackListenerV2.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_CONTEXT_MENU_BUTTONS_CLICK) > 0) { + try { + cb.getCallback().onContextMenuButtonClicked(buttonId, pointId, layerId); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + } + } + } } }; buttonsParams.setCallbackId(callbackId); @@ -2096,7 +2135,7 @@ public class OsmandAidlApi { } boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, - final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { + final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { if (gpxUri == null || callback == null) { return false; } @@ -2116,7 +2155,7 @@ public class OsmandAidlApi { @Override public void drawTrackBitmap(Bitmap bitmap) { - callback.onGpxBitmapCreatedComplete(new AGpxBitmap(bitmap)); + callback.onGpxBitmapCreatedComplete(bitmap); } }; @@ -2167,27 +2206,26 @@ public class OsmandAidlApi { } } - int copyFile(final CopyFileParams params) { - if (Algorithms.isEmpty(params.getFileName()) || params.getFilePartData() == null) { + int copyFile(String fileName, byte[] filePartData, long startTime, boolean done) { + if (Algorithms.isEmpty(fileName) || filePartData == null) { return COPY_FILE_PARAMS_ERROR; } - if (params.getFilePartData().length > COPY_FILE_PART_SIZE_LIMIT) { + if (filePartData.length > COPY_FILE_PART_SIZE_LIMIT) { return COPY_FILE_PART_SIZE_LIMIT_ERROR; } - if (params.getFileName().endsWith(IndexConstants.SQLITE_EXT)) { - return copyFileImpl(params, IndexConstants.TILES_INDEX_DIR); + if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { + return copyFileImpl(fileName, filePartData, startTime, done, IndexConstants.TILES_INDEX_DIR); } else { return COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR; } } - private int copyFileImpl(CopyFileParams params, String destinationDir) { - File file = app.getAppPath(IndexConstants.TEMP_DIR + params.getFileName()); + private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) { + File file = app.getAppPath(IndexConstants.TEMP_DIR + fileName); File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); if (!tempDir.exists()) { tempDir.mkdirs(); } - String fileName = params.getFileName(); File destFile = app.getAppPath(destinationDir + fileName); long currentTime = System.currentTimeMillis(); try { @@ -2195,32 +2233,32 @@ public class OsmandAidlApi { if (info == null) { FileOutputStream fos = new FileOutputStream(file, true); copyFilesCache.put(fileName, - new FileCopyInfo(params.getStartTime(), currentTime, fos)); - if (params.isDone()) { - if (!finishFileCopy(params, file, fos, fileName, destFile)) { + new FileCopyInfo(startTime, currentTime, fos)); + if (done) { + if (!finishFileCopy(filePartData, file, fos, fileName, destFile)) { return COPY_FILE_IO_ERROR; } } else { - fos.write(params.getFilePartData()); + fos.write(filePartData); } } else { - if (info.startTime != params.getStartTime()) { + if (info.startTime != startTime) { if (currentTime - info.lastAccessTime < COPY_FILE_MAX_LOCK_TIME_MS) { return COPY_FILE_WRITE_LOCK_ERROR; } else { file.delete(); copyFilesCache.remove(fileName); - return copyFileImpl(params, destinationDir); + return copyFileImpl(fileName, filePartData, startTime, done, destinationDir); } } FileOutputStream fos = info.fileOutputStream; info.lastAccessTime = currentTime; - if (params.isDone()) { - if (!finishFileCopy(params, file, fos, fileName, destFile)) { + if (done) { + if (!finishFileCopy(filePartData, file, fos, fileName, destFile)) { return COPY_FILE_IO_ERROR; } } else { - fos.write(params.getFilePartData()); + fos.write(filePartData); } } } catch (IOException e) { @@ -2230,9 +2268,8 @@ public class OsmandAidlApi { return OK_RESPONSE; } - private boolean finishFileCopy(CopyFileParams params, File file, FileOutputStream fos, String fileName, File destFile) throws IOException { + private boolean finishFileCopy(byte[] data, File file, FileOutputStream fos, String fileName, File destFile) throws IOException { boolean res = true; - byte[] data = params.getFilePartData(); if (data.length > 0) { fos.write(data); } @@ -2282,8 +2319,6 @@ public class OsmandAidlApi { } } - - private static AGpxFileDetails createGpxFileDetails(@NonNull GPXTrackAnalysis a) { return new AGpxFileDetails(a.totalDistance, a.totalTracks, a.startTime, a.endTime, a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown, @@ -2291,6 +2326,13 @@ public class OsmandAidlApi { a.points, a.wptPoints, a.wptCategoryNames); } + private static net.osmand.aidl2.gpx.AGpxFileDetails createGpxFileDetailsV2(@NonNull GPXTrackAnalysis a) { + return new net.osmand.aidl2.gpx.AGpxFileDetails(a.totalDistance, a.totalTracks, a.startTime, a.endTime, + a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown, + a.avgElevation, a.minElevation, a.maxElevation, a.minSpeed, a.maxSpeed, a.avgSpeed, + a.points, a.wptPoints, a.wptCategoryNames); + } + public static class ConnectedApp implements Comparable { static final String PACK_KEY = "pack"; @@ -2332,11 +2374,11 @@ public class OsmandAidlApi { } public interface SearchCompleteCallback { - void onSearchComplete(List resultSet); + void onSearchComplete(List resultSet); } public interface GpxBitmapCreatedCallback { - void onGpxBitmapCreatedComplete(AGpxBitmap aGpxBitmap); + void onGpxBitmapCreatedComplete(Bitmap bitmap); } public interface OsmandAppInitCallback { @@ -2344,6 +2386,6 @@ public class OsmandAidlApi { } public interface AMapPointUpdateListener { - void onAMapPointUpdated(AMapPoint point, String layerId); + void onAMapPointUpdated(AidlMapPointWrapper point, String layerId); } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 9a2725f22b..b183462bfc 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -2,8 +2,8 @@ package net.osmand.aidl; import android.app.Service; import android.content.Intent; +import android.graphics.Bitmap; import android.os.Binder; -import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; @@ -23,9 +23,11 @@ import net.osmand.aidl.customization.CustomizationInfoParams; import net.osmand.aidl.customization.OsmandSettingsInfoParams; import net.osmand.aidl.customization.OsmandSettingsParams; import net.osmand.aidl.customization.SetWidgetsParams; +import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.favorite.AddFavoriteParams; import net.osmand.aidl.favorite.RemoveFavoriteParams; import net.osmand.aidl.favorite.UpdateFavoriteParams; +import net.osmand.aidl.favorite.group.AFavoriteGroup; import net.osmand.aidl.favorite.group.AddFavoriteGroupParams; import net.osmand.aidl.favorite.group.RemoveFavoriteGroupParams; import net.osmand.aidl.favorite.group.UpdateFavoriteGroupParams; @@ -40,6 +42,7 @@ import net.osmand.aidl.gpx.RemoveGpxParams; import net.osmand.aidl.gpx.ShowGpxParams; import net.osmand.aidl.gpx.StartGpxRecordingParams; import net.osmand.aidl.gpx.StopGpxRecordingParams; +import net.osmand.aidl.map.ALatLon; import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.maplayer.AddMapLayerParams; import net.osmand.aidl.maplayer.RemoveMapLayerParams; @@ -48,6 +51,7 @@ import net.osmand.aidl.maplayer.point.AddMapPointParams; import net.osmand.aidl.maplayer.point.RemoveMapPointParams; import net.osmand.aidl.maplayer.point.ShowMapPointParams; import net.osmand.aidl.maplayer.point.UpdateMapPointParams; +import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapmarker.AddMapMarkerParams; import net.osmand.aidl.mapmarker.RemoveMapMarkerParams; import net.osmand.aidl.mapmarker.RemoveMapMarkersParams; @@ -57,6 +61,7 @@ import net.osmand.aidl.mapwidget.RemoveMapWidgetParams; import net.osmand.aidl.mapwidget.UpdateMapWidgetParams; import net.osmand.aidl.navdrawer.NavDrawerFooterParams; import net.osmand.aidl.navdrawer.NavDrawerHeaderParams; +import net.osmand.aidl.navdrawer.NavDrawerItem; import net.osmand.aidl.navdrawer.SetNavDrawerItemsParams; import net.osmand.aidl.navigation.ANavigationUpdateParams; import net.osmand.aidl.navigation.ANavigationVoiceRouterMessageParams; @@ -76,6 +81,8 @@ import net.osmand.aidl.plugins.PluginParams; import net.osmand.aidl.search.SearchParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; +import net.osmand.data.LatLon; +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; import net.osmand.util.Algorithms; @@ -96,8 +103,6 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { private static final Log LOG = PlatformUtil.getLog(OsmandAidlService.class); - private static final String DATA_KEY_RESULT_SET = "resultSet"; - public static final int KEY_ON_UPDATE = 1; public static final int KEY_ON_NAV_DATA_UPDATE = 2; public static final int KEY_ON_CONTEXT_MENU_BUTTONS_CLICK = 4; @@ -207,7 +212,13 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean addFavoriteGroup(AddFavoriteGroupParams params) { try { OsmandAidlApi api = getApi("addFavoriteGroup"); - return params != null && api != null && api.addFavoriteGroup(params.getFavoriteGroup()); + if (params != null && api != null) { + AFavoriteGroup favoriteGroup = params.getFavoriteGroup(); + if (favoriteGroup != null) { + return api.addFavoriteGroup(favoriteGroup.getName(), favoriteGroup.getColor(), favoriteGroup.isVisible()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -218,7 +229,13 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean removeFavoriteGroup(RemoveFavoriteGroupParams params) { try { OsmandAidlApi api = getApi("removeFavoriteGroup"); - return params != null && api != null && api.removeFavoriteGroup(params.getFavoriteGroup()); + if (params != null && api != null) { + AFavoriteGroup favoriteGroup = params.getFavoriteGroup(); + if (favoriteGroup != null) { + return api.removeFavoriteGroup(favoriteGroup.getName()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -229,7 +246,14 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean updateFavoriteGroup(UpdateFavoriteGroupParams params) { try { OsmandAidlApi api = getApi("updateFavoriteGroup"); - return params != null && api != null && api.updateFavoriteGroup(params.getFavoriteGroupPrev(), params.getFavoriteGroupNew()); + if (params != null && api != null) { + AFavoriteGroup prevGroup = params.getFavoriteGroupPrev(); + AFavoriteGroup newGroup = params.getFavoriteGroupNew(); + if (prevGroup != null && newGroup != null) { + return api.updateFavoriteGroup(prevGroup.getName(), newGroup.getName(), newGroup.getColor(), newGroup.isVisible()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -240,7 +264,13 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean addFavorite(AddFavoriteParams params) { try { OsmandAidlApi api = getApi("addFavorite"); - return params != null && api != null && api.addFavorite(params.getFavorite()); + if (params != null && api != null) { + AFavorite fav = params.getFavorite(); + if (fav != null) { + return api.addFavorite(fav.getLat(), fav.getLon(), fav.getName(), fav.getCategory(), fav.getDescription(), fav.getColor(), fav.isVisible()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -251,7 +281,13 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean removeFavorite(RemoveFavoriteParams params) { try { OsmandAidlApi api = getApi("removeFavorite"); - return params != null && api != null && api.removeFavorite(params.getFavorite()); + if (params != null && api != null) { + AFavorite fav = params.getFavorite(); + if (fav != null) { + return api.removeFavorite(fav.getName(), fav.getCategory(), fav.getLat(), fav.getLon()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -262,7 +298,15 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean updateFavorite(UpdateFavoriteParams params) { try { OsmandAidlApi api = getApi("updateFavorite"); - return params != null && api != null && api.updateFavorite(params.getFavoritePrev(), params.getFavoriteNew()); + if (params != null && api != null) { + AFavorite prevFav = params.getFavoritePrev(); + AFavorite newFav = params.getFavoriteNew(); + if (prevFav != null && newFav != null) { + return api.updateFavorite(prevFav.getName(), prevFav.getCategory(), prevFav.getLat(), prevFav.getLon(), + newFav.getName(), newFav.getCategory(), newFav.getDescription(), newFav.getLat(), newFav.getLon()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -273,7 +317,13 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean addMapMarker(AddMapMarkerParams params) { try { OsmandAidlApi api = getApi("addMapMarker"); - return params != null && api != null && api.addMapMarker(params.getMarker()); + if (params != null && api != null) { + AMapMarker mapMarker = params.getMarker(); + if (mapMarker != null) { + return api.addMapMarker(mapMarker.getName(), mapMarker.getLatLon().getLatitude(), mapMarker.getLatLon().getLongitude()); + } + } + return false; } catch (Exception e) { return false; } @@ -283,7 +333,14 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean removeMapMarker(RemoveMapMarkerParams params) { try { OsmandAidlApi api = getApi("removeMapMarker"); - return params != null && api != null && api.removeMapMarker(params.getMarker(), params.getIgnoreCoordinates()); + if (params != null && api != null) { + AMapMarker mapMarker = params.getMarker(); + if (mapMarker != null) { + ALatLon aLatLon = mapMarker.getLatLon(); + return api.removeMapMarker(mapMarker.getName(), aLatLon.getLatitude(), aLatLon.getLongitude(), params.getIgnoreCoordinates()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -294,7 +351,19 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean updateMapMarker(UpdateMapMarkerParams params) { try { OsmandAidlApi api = getApi("updateMapMarker"); - return params != null && api != null && api.updateMapMarker(params.getMarkerPrev(), params.getMarkerNew(), params.getIgnoreCoordinates()); + if (params != null && api != null) { + AMapMarker markerPrev = params.getMarkerPrev(); + AMapMarker markerNew = params.getMarkerNew(); + if (markerPrev != null && markerNew != null) { + ALatLon aLatLonPrev = markerPrev.getLatLon(); + ALatLon aLatLonNew = markerNew.getLatLon(); + LatLon prevLatLon = new LatLon(aLatLonPrev.getLatitude(), aLatLonPrev.getLongitude()); + LatLon newLatLon = new LatLon(aLatLonNew.getLatitude(), aLatLonNew.getLongitude()); + + return api.updateMapMarker(markerPrev.getName(), prevLatLon, markerNew.getName(), newLatLon, params.getIgnoreCoordinates()); + } + } + return false; } catch (Exception e) { handleException(e); return false; @@ -305,7 +374,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean addMapWidget(AddMapWidgetParams params) { try { OsmandAidlApi api = getApi("addMapWidget"); - return params != null && api != null && api.addMapWidget(params.getWidget()); + return params != null && api != null && api.addMapWidget(new AidlMapWidgetWrapper(params.getWidget())); } catch (Exception e) { handleException(e); return false; @@ -326,7 +395,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean updateMapWidget(UpdateMapWidgetParams params) { try { OsmandAidlApi api = getApi("updateMapWidget"); - return params != null && api != null && api.updateMapWidget(params.getWidget()); + return params != null && api != null && api.updateMapWidget(new AidlMapWidgetWrapper(params.getWidget())); } catch (Exception e) { handleException(e); return false; @@ -337,7 +406,7 @@ 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(), params.getPoint()); + return params != null && api != null && api.showMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint())); } catch (Exception e) { handleException(e); return false; @@ -348,7 +417,7 @@ 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(), params.getPoint()); + return params != null && api != null && api.putMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint())); } catch (Exception e) { handleException(e); return false; @@ -370,7 +439,7 @@ 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(), params.getPoint(), params.isUpdateOpenedMenuAndMap()); + return params != null && api != null && api.updateMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint()), params.isUpdateOpenedMenuAndMap()); } catch (Exception e) { handleException(e); return false; @@ -381,7 +450,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean addMapLayer(AddMapLayerParams params) { try { OsmandAidlApi api = getApi("addMapLayer"); - return params != null && api != null && api.addMapLayer(params.getLayer()); + return params != null && api != null && api.addMapLayer(new AidlMapLayerWrapper(params.getLayer())); } catch (Exception e) { handleException(e); return false; @@ -403,7 +472,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean updateMapLayer(UpdateMapLayerParams params) { try { OsmandAidlApi api = getApi("updateMapLayer"); - return params != null && api != null && api.updateMapLayer(params.getLayer()); + return params != null && api != null && api.updateMapLayer(new AidlMapLayerWrapper(params.getLayer())); } catch (Exception e) { handleException(e); return false; @@ -467,7 +536,10 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean getActiveGpx(List files) { try { OsmandAidlApi api = getApi("getActiveGpx"); - return api != null && api.getActiveGpx(files); + if (api != null && files != null) { + return api.getActiveGpx(files); + } + return false; } catch (Exception e) { handleException(e); return false; @@ -478,7 +550,10 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean getImportedGpx(List files) { try { OsmandAidlApi api = getApi("getImportedGpx"); - return api != null && api.getImportedGpx(files); + if (api != null && files != null) { + return api.getImportedGpx(files); + } + return false; } catch (Exception e) { handleException(e); return false; @@ -574,7 +649,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean startGpxRecording(StartGpxRecordingParams params) { try { OsmandAidlApi api = getApi("startGpxRecording"); - return api != null && api.startGpxRecording(params); + return api != null && api.startGpxRecording(); } catch (Exception e) { handleException(e); return false; @@ -585,7 +660,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean stopGpxRecording(StopGpxRecordingParams params) { try { OsmandAidlApi api = getApi("stopGpxRecording"); - return api != null && api.stopGpxRecording(params); + return api != null && api.stopGpxRecording(); } catch (Exception e) { handleException(e); return false; @@ -720,7 +795,10 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean setNavDrawerItems(SetNavDrawerItemsParams params) { try { OsmandAidlApi api = getApi("setNavDrawerItems"); - return params != null && api != null && api.setNavDrawerItems(params.getAppPackage(), params.getItems()); + if (api != null && params != null) { + return api.setNavDrawerItems(params.getAppPackage(), convertNavDrawerItems(params.getItems())); + } + return false; } catch (Exception e) { handleException(e); return false; @@ -734,13 +812,15 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { return params != null && api != null && api.search(params.getSearchQuery(), params.getSearchType(), params.getLatitude(), params.getLongitude(), params.getRadiusLevel(), params.getTotalLimit(), new SearchCompleteCallback() { @Override - public void onSearchComplete(List resultSet) { - Bundle data = new Bundle(); - if (resultSet.size() > 0) { - data.putParcelableArrayList(DATA_KEY_RESULT_SET, new ArrayList<>(resultSet)); - } + public void onSearchComplete(List resultSet) { try { - callback.onSearchComplete(resultSet); + List searchResults = new ArrayList<>(); + for (AidlSearchResultWrapper item : resultSet) { + SearchResult result = new SearchResult(item.getLatitude(), item.getLongitude(), item.getLocalName(), + item.getLocalTypeName(), item.getAlternateName(), item.getOtherNames()); + searchResults.add(result); + } + callback.onSearchComplete(searchResults); } catch (RemoteException e) { handleException(e); } @@ -963,7 +1043,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean setNavDrawerFooterWithParams(NavDrawerFooterParams params) { try { OsmandAidlApi api = getApi("setNavDrawerFooterParams"); - return api != null && api.setNavDrawerFooterWithParams(params); + return api != null && api.setNavDrawerFooterWithParams( + params.getAppName(), params.getPackageName(), params.getIntent()); } catch (Exception e) { handleException(e); return false; @@ -985,7 +1066,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean changePluginState(PluginParams params) { try { OsmandAidlApi api = getApi("changePluginState"); - return api != null && api.changePluginState(params); + return api != null && api.changePluginState(params.getPluginId(), params.getNewState()); } catch (Exception e) { handleException(e); return false; @@ -1018,9 +1099,9 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { OsmandAidlApi api = getApi("getBitmapForGpx"); return params != null && api != null && api.getBitmapForGpx(params.getGpxUri(), params.getDensity(), params.getWidthPixels(), params.getHeightPixels(), params.getColor(), new GpxBitmapCreatedCallback() { @Override - public void onGpxBitmapCreatedComplete(AGpxBitmap aGpxBitmap) { + public void onGpxBitmapCreatedComplete(Bitmap gpxBitmap) { try { - callback.onGpxBitmapCreated(aGpxBitmap); + callback.onGpxBitmapCreated(new AGpxBitmap(gpxBitmap)); } catch (RemoteException e) { handleException(e); } @@ -1033,13 +1114,13 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { } @Override - public int copyFile(CopyFileParams copyFileParams) { + public int copyFile(CopyFileParams params) { try { OsmandAidlApi api = getApi("copyFile"); if (api == null) { return CANNOT_ACCESS_API_ERROR; } - return api.copyFile(copyFileParams); + return api.copyFile(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone()); } catch (Exception e) { handleException(e); return UNKNOWN_API_ERROR; @@ -1079,7 +1160,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { callbackId = addAidlCallback(callback, KEY_ON_CONTEXT_MENU_BUTTONS_CLICK); params.setCallbackId(callbackId); } - boolean buttonsAdded = api.addContextMenuButtons(params, callbackId); + boolean buttonsAdded = api.addContextMenuButtons(new AidlContextMenuButtonsWrapper(params), callbackId); return buttonsAdded ? callbackId : -1; } else { return -1; @@ -1111,7 +1192,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { OsmandAidlApi api = getApi("updateContextMenuButtons"); if (params != null && api != null) { ContextMenuButtonsParams buttonsParams = params.getContextMenuButtonsParams(); - return api.updateContextMenuButtons(buttonsParams, buttonsParams.getCallbackId()); + return api.updateContextMenuButtons(new AidlContextMenuButtonsWrapper(buttonsParams), buttonsParams.getCallbackId()); } return false; } catch (Exception e) { @@ -1135,7 +1216,11 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean setCustomization(CustomizationInfoParams params) { try { OsmandAidlApi api = getApi("setCustomization"); - return api != null && params != null && api.setCustomization(params); + if (api != null && params != null) { + OsmandAidlService.this.setCustomization(api, params); + return true; + } + return false; } catch (Exception e) { handleException(e); return false; @@ -1143,10 +1228,10 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { } @Override - public long registerForVoiceRouterMessages(ANavigationVoiceRouterMessageParams params, final IOsmAndAidlCallback callback) throws RemoteException { + public long registerForVoiceRouterMessages(ANavigationVoiceRouterMessageParams params, final IOsmAndAidlCallback callback) { try { OsmandAidlApi api = getApi("registerForVoiceRouterMessages"); - if (api != null ) { + if (api != null) { if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) { api.unregisterFromVoiceRouterMessages(params.getCallbackId()); removeAidlCallback(params.getCallbackId()); @@ -1177,10 +1262,14 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { } @Override - public boolean getGpxColor(GpxColorParams params) throws RemoteException { + public boolean getGpxColor(GpxColorParams params) { try { OsmandAidlApi api = getApi("getGpxColor"); - return api != null && api.getGpxColor(params); + if (api != null && params != null) { + String colorName = api.getGpxColor(params.getFileName()); + params.setGpxColor(colorName); + } + return false; } catch (Exception e) { handleException(e); return false; @@ -1188,6 +1277,79 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { } }; + private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { + OsmandSettingsParams settingsParams = params.getSettingsParams(); + if (settingsParams != null) { + api.customizeOsmandSettings(settingsParams.getSharedPreferencesName(), settingsParams.getBundle()); + } + NavDrawerHeaderParams navDrawerHeaderParams = params.getNavDrawerHeaderParams(); + NavDrawerFooterParams navDrawerFooterParams = params.getNavDrawerFooterParams(); + SetNavDrawerItemsParams navDrawerItemsParams = params.getNavDrawerItemsParams(); + + setNavDrawerParams(api, navDrawerHeaderParams, navDrawerFooterParams, navDrawerItemsParams); + + ArrayList visibilityWidgetsParams = params.getVisibilityWidgetsParams(); + ArrayList availabilityWidgetsParams = params.getAvailabilityWidgetsParams(); + + regWidgetsVisibility(api, visibilityWidgetsParams); + regWidgetsAvailability(api, availabilityWidgetsParams); + + ArrayList pluginsParams = params.getPluginsParams(); + if (pluginsParams != null) { + changePluginsStatus(api, pluginsParams); + } + + List enabledIds = params.getFeaturesEnabledIds(); + List disabledIds = params.getFeaturesDisabledIds(); + + api.setEnabledIds(enabledIds); + api.setDisabledIds(disabledIds); + + List enabledPatterns = params.getFeaturesEnabledPatterns(); + List disabledPatterns = params.getFeaturesDisabledPatterns(); + + api.setEnabledPatterns(enabledPatterns); + api.setDisabledPatterns(disabledPatterns); + } + + private void setNavDrawerParams(OsmandAidlApi api, NavDrawerHeaderParams navDrawerHeaderParams, NavDrawerFooterParams navDrawerFooterParams, SetNavDrawerItemsParams navDrawerItemsParams) { + if (navDrawerHeaderParams != null) { + api.setNavDrawerLogoWithParams(navDrawerHeaderParams.getImageUri(), navDrawerHeaderParams.getPackageName(), navDrawerHeaderParams.getIntent()); + } + if (navDrawerFooterParams != null) { + api.setNavDrawerFooterWithParams(navDrawerFooterParams.getAppName(), navDrawerFooterParams.getPackageName(), navDrawerFooterParams.getIntent()); + } + if (navDrawerItemsParams != null) { + api.setNavDrawerItems(navDrawerItemsParams.getAppPackage(), convertNavDrawerItems(navDrawerItemsParams.getItems())); + } + } + + private void regWidgetsVisibility(OsmandAidlApi api, ArrayList visibilityWidgetsParams) { + for (SetWidgetsParams setWidgetsParams : visibilityWidgetsParams) { + api.regWidgetVisibility(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys()); + } + } + + private void regWidgetsAvailability(OsmandAidlApi api, ArrayList availabilityWidgetsParams) { + for (SetWidgetsParams setWidgetsParams : availabilityWidgetsParams) { + api.regWidgetAvailability(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys()); + } + } + + public void changePluginsStatus(OsmandAidlApi api, List pluginsParams) { + for (PluginParams pluginParams : pluginsParams) { + api.changePluginState(pluginParams.getPluginId(), pluginParams.getNewState()); + } + } + + private List convertNavDrawerItems(List drawerItems) { + List customizationItems = new ArrayList<>(); + for (NavDrawerItem item : drawerItems) { + customizationItems.add(new OsmAndAppCustomization.NavDrawerItem(item.getName(), item.getUri(), item.getIconName(), item.getFlags())); + } + return customizationItems; + } + public static class AidlCallbackParams { private IOsmAndAidlCallback callback; private long key; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java new file mode 100644 index 0000000000..518987b1c5 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -0,0 +1,1329 @@ +package net.osmand.aidl; + +import android.app.Service; +import android.content.Intent; +import android.graphics.Bitmap; +import android.os.Binder; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.IBinder; +import android.os.RemoteException; +import android.support.annotation.Nullable; + +import net.osmand.PlatformUtil; +import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; +import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; +import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback; +import net.osmand.aidl2.IOsmAndAidlCallback; +import net.osmand.aidl2.IOsmAndAidlInterface; +import net.osmand.aidl2.calculateroute.CalculateRouteParams; +import net.osmand.aidl2.contextmenu.ContextMenuButtonsParams; +import net.osmand.aidl2.contextmenu.RemoveContextMenuButtonsParams; +import net.osmand.aidl2.contextmenu.UpdateContextMenuButtonsParams; +import net.osmand.aidl2.copyfile.CopyFileParams; +import net.osmand.aidl2.customization.CustomizationInfoParams; +import net.osmand.aidl2.customization.OsmandSettingsInfoParams; +import net.osmand.aidl2.customization.OsmandSettingsParams; +import net.osmand.aidl2.customization.SetWidgetsParams; +import net.osmand.aidl2.favorite.AFavorite; +import net.osmand.aidl2.favorite.AddFavoriteParams; +import net.osmand.aidl2.favorite.RemoveFavoriteParams; +import net.osmand.aidl2.favorite.UpdateFavoriteParams; +import net.osmand.aidl2.favorite.group.AFavoriteGroup; +import net.osmand.aidl2.favorite.group.AddFavoriteGroupParams; +import net.osmand.aidl2.favorite.group.RemoveFavoriteGroupParams; +import net.osmand.aidl2.favorite.group.UpdateFavoriteGroupParams; +import net.osmand.aidl2.gpx.AGpxBitmap; +import net.osmand.aidl2.gpx.AGpxFile; +import net.osmand.aidl2.gpx.ASelectedGpxFile; +import net.osmand.aidl2.gpx.CreateGpxBitmapParams; +import net.osmand.aidl2.gpx.GpxColorParams; +import net.osmand.aidl2.gpx.HideGpxParams; +import net.osmand.aidl2.gpx.ImportGpxParams; +import net.osmand.aidl2.gpx.RemoveGpxParams; +import net.osmand.aidl2.gpx.ShowGpxParams; +import net.osmand.aidl2.gpx.StartGpxRecordingParams; +import net.osmand.aidl2.gpx.StopGpxRecordingParams; +import net.osmand.aidl2.map.ALatLon; +import net.osmand.aidl2.map.SetMapLocationParams; +import net.osmand.aidl2.maplayer.AddMapLayerParams; +import net.osmand.aidl2.maplayer.RemoveMapLayerParams; +import net.osmand.aidl2.maplayer.UpdateMapLayerParams; +import net.osmand.aidl2.maplayer.point.AddMapPointParams; +import net.osmand.aidl2.maplayer.point.RemoveMapPointParams; +import net.osmand.aidl2.maplayer.point.ShowMapPointParams; +import net.osmand.aidl2.maplayer.point.UpdateMapPointParams; +import net.osmand.aidl2.mapmarker.AMapMarker; +import net.osmand.aidl2.mapmarker.AddMapMarkerParams; +import net.osmand.aidl2.mapmarker.RemoveMapMarkerParams; +import net.osmand.aidl2.mapmarker.RemoveMapMarkersParams; +import net.osmand.aidl2.mapmarker.UpdateMapMarkerParams; +import net.osmand.aidl2.mapwidget.AddMapWidgetParams; +import net.osmand.aidl2.mapwidget.RemoveMapWidgetParams; +import net.osmand.aidl2.mapwidget.UpdateMapWidgetParams; +import net.osmand.aidl2.navdrawer.NavDrawerFooterParams; +import net.osmand.aidl2.navdrawer.NavDrawerHeaderParams; +import net.osmand.aidl2.navdrawer.NavDrawerItem; +import net.osmand.aidl2.navdrawer.SetNavDrawerItemsParams; +import net.osmand.aidl2.navigation.ANavigationUpdateParams; +import net.osmand.aidl2.navigation.ANavigationVoiceRouterMessageParams; +import net.osmand.aidl2.navigation.MuteNavigationParams; +import net.osmand.aidl2.navigation.NavigateGpxParams; +import net.osmand.aidl2.navigation.NavigateParams; +import net.osmand.aidl2.navigation.NavigateSearchParams; +import net.osmand.aidl2.navigation.PauseNavigationParams; +import net.osmand.aidl2.navigation.ResumeNavigationParams; +import net.osmand.aidl2.navigation.StopNavigationParams; +import net.osmand.aidl2.navigation.UnmuteNavigationParams; +import net.osmand.aidl2.note.StartAudioRecordingParams; +import net.osmand.aidl2.note.StartVideoRecordingParams; +import net.osmand.aidl2.note.StopRecordingParams; +import net.osmand.aidl2.note.TakePhotoNoteParams; +import net.osmand.aidl2.plugins.PluginParams; +import net.osmand.aidl2.search.SearchParams; +import net.osmand.aidl2.search.SearchResult; +import net.osmand.aidl2.tiles.ASqliteDbFile; +import net.osmand.data.LatLon; +import net.osmand.plus.OsmAndAppCustomization; +import net.osmand.plus.OsmandApplication; +import net.osmand.util.Algorithms; + +import org.apache.commons.logging.Log; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; + +import static net.osmand.OsmandAidlConstants.CANNOT_ACCESS_API_ERROR; +import static net.osmand.OsmandAidlConstants.MIN_UPDATE_TIME_MS; +import static net.osmand.OsmandAidlConstants.MIN_UPDATE_TIME_MS_ERROR; +import static net.osmand.OsmandAidlConstants.UNKNOWN_API_ERROR; + +public class OsmandAidlServiceV2 extends Service implements AidlCallbackListenerV2 { + + private static final Log LOG = PlatformUtil.getLog(OsmandAidlService.class); + + public static final int KEY_ON_UPDATE = 1; + public static final int KEY_ON_NAV_DATA_UPDATE = 2; + public static final int KEY_ON_CONTEXT_MENU_BUTTONS_CLICK = 4; + public static final int KEY_ON_VOICE_MESSAGE = 5; + + private Map callbacks = new ConcurrentHashMap<>(); + private Handler mHandler = null; + HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceV2Thread"); + + private final AtomicLong aidlCallbackId = new AtomicLong(0); + + private OsmandApplication getApp() { + return (OsmandApplication) getApplication(); + } + + @Nullable + private OsmandAidlApi getApi(String reason) { + LOG.info("Request AIDL API V2 for " + reason); + OsmandAidlApi api = getApp().getAidlApi(); + String pack = getApp().getPackageManager().getNameForUid(Binder.getCallingUid()); + if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) { + return null; + } + return api; + } + + @Override + public IBinder onBind(Intent intent) { + mHandlerThread.start(); + mHandler = new Handler(mHandlerThread.getLooper()); + + // Return the interface + return mBinder; + } + + @Override + public void onCreate() { + super.onCreate(); + OsmandAidlApi api = getApi("setting_listener"); + if (api != null) { + api.aidlCallbackListenerV2 = this; + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + + callbacks.clear(); + OsmandAidlApi api = getApi("clear_listener"); + if (api != null) { + api.aidlCallbackListenerV2 = null; + } + mHandlerThread.quit(); + } + + private long getCallbackId() { + return aidlCallbackId.get(); + } + + private long getAndIncrementCallbackId() { + return aidlCallbackId.getAndIncrement(); + } + + @Override + public long addAidlCallback(IOsmAndAidlCallback callback, int key) { + long id = getAndIncrementCallbackId(); + callbacks.put(id, new AidlCallbackParams(callback, key)); + return id; + } + + @Override + public boolean removeAidlCallback(long id) { + for (Long key : callbacks.keySet()) { + if (key == id) { + callbacks.remove(id); + return true; + } + } + return false; + } + + @Override + public Map getAidlCallbacks() { + return callbacks; + } + + private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() { + + private void handleException(Exception e) { + LOG.error("AIDL V2 e.getMessage()", e); + } + + @Override + public boolean refreshMap() { + try { + OsmandAidlApi api = getApi("refreshMap"); + return api != null && api.reloadMap(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean addFavoriteGroup(AddFavoriteGroupParams params) { + try { + OsmandAidlApi api = getApi("addFavoriteGroup"); + if (params != null && api != null) { + AFavoriteGroup favoriteGroup = params.getFavoriteGroup(); + if (favoriteGroup != null) { + return api.addFavoriteGroup(favoriteGroup.getName(), favoriteGroup.getColor(), favoriteGroup.isVisible()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean removeFavoriteGroup(RemoveFavoriteGroupParams params) { + try { + OsmandAidlApi api = getApi("removeFavoriteGroup"); + if (params != null && api != null) { + AFavoriteGroup favoriteGroup = params.getFavoriteGroup(); + if (favoriteGroup != null) { + return api.removeFavoriteGroup(favoriteGroup.getName()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean updateFavoriteGroup(UpdateFavoriteGroupParams params) { + try { + OsmandAidlApi api = getApi("updateFavoriteGroup"); + if (params != null && api != null) { + AFavoriteGroup prevGroup = params.getFavoriteGroupPrev(); + AFavoriteGroup newGroup = params.getFavoriteGroupNew(); + if (prevGroup != null && newGroup != null) { + return api.updateFavoriteGroup(prevGroup.getName(), newGroup.getName(), newGroup.getColor(), newGroup.isVisible()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean addFavorite(AddFavoriteParams params) { + try { + OsmandAidlApi api = getApi("addFavorite"); + if (params != null && api != null) { + AFavorite fav = params.getFavorite(); + if (fav != null) { + return api.addFavorite(fav.getLat(), fav.getLon(), fav.getName(), fav.getCategory(), fav.getDescription(), fav.getColor(), fav.isVisible()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean removeFavorite(RemoveFavoriteParams params) { + try { + OsmandAidlApi api = getApi("removeFavorite"); + if (params != null && api != null) { + AFavorite fav = params.getFavorite(); + if (fav != null) { + return api.removeFavorite(fav.getName(), fav.getCategory(), fav.getLat(), fav.getLon()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean updateFavorite(UpdateFavoriteParams params) { + try { + OsmandAidlApi api = getApi("updateFavorite"); + if (params != null && api != null) { + AFavorite prevFav = params.getFavoritePrev(); + AFavorite newFav = params.getFavoriteNew(); + if (prevFav != null && newFav != null) { + return api.updateFavorite(prevFav.getName(), prevFav.getCategory(), prevFav.getLat(), prevFav.getLon(), + newFav.getName(), newFav.getCategory(), newFav.getDescription(), newFav.getLat(), newFav.getLon()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean addMapMarker(AddMapMarkerParams params) { + try { + OsmandAidlApi api = getApi("addMapMarker"); + if (params != null && api != null) { + AMapMarker mapMarker = params.getMarker(); + if (mapMarker != null) { + return api.addMapMarker(mapMarker.getName(), mapMarker.getLatLon().getLatitude(), mapMarker.getLatLon().getLongitude()); + } + } + return false; + } catch (Exception e) { + return false; + } + } + + @Override + public boolean removeMapMarker(RemoveMapMarkerParams params) { + try { + OsmandAidlApi api = getApi("removeMapMarker"); + if (params != null && api != null) { + AMapMarker mapMarker = params.getMarker(); + if (mapMarker != null) { + ALatLon aLatLon = mapMarker.getLatLon(); + return api.removeMapMarker(mapMarker.getName(), aLatLon.getLatitude(), aLatLon.getLongitude(), params.getIgnoreCoordinates()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean updateMapMarker(UpdateMapMarkerParams params) { + try { + OsmandAidlApi api = getApi("updateMapMarker"); + if (params != null && api != null) { + AMapMarker markerPrev = params.getMarkerPrev(); + AMapMarker markerNew = params.getMarkerNew(); + if (markerPrev != null && markerNew != null) { + ALatLon aLatLonPrev = markerPrev.getLatLon(); + ALatLon aLatLonNew = markerNew.getLatLon(); + LatLon prevLatLon = new LatLon(aLatLonPrev.getLatitude(), aLatLonPrev.getLongitude()); + LatLon newLatLon = new LatLon(aLatLonNew.getLatitude(), aLatLonNew.getLongitude()); + + return api.updateMapMarker(markerPrev.getName(), prevLatLon, markerNew.getName(), newLatLon, params.getIgnoreCoordinates()); + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean addMapWidget(AddMapWidgetParams params) { + try { + OsmandAidlApi api = getApi("addMapWidget"); + return params != null && api != null && api.addMapWidget(new AidlMapWidgetWrapper(params.getWidget())); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean removeMapWidget(RemoveMapWidgetParams params) { + try { + OsmandAidlApi api = getApi("removeMapWidget"); + return params != null && api != null && api.removeMapWidget(params.getId()); + } catch (Exception e) { + return false; + } + } + + @Override + public boolean updateMapWidget(UpdateMapWidgetParams params) { + try { + OsmandAidlApi api = getApi("updateMapWidget"); + return params != null && api != null && api.updateMapWidget(new AidlMapWidgetWrapper(params.getWidget())); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean showMapPoint(ShowMapPointParams params) { + try { + OsmandAidlApi api = getApi("showMapPoint"); + return params != null && api != null && api.showMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint())); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean addMapPoint(AddMapPointParams params) { + try { + OsmandAidlApi api = getApi("addMapPoint"); + return params != null && api != null && api.putMapPoint(params.getLayerId(), new AidlMapPointWrapper(params.getPoint())); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean removeMapPoint(RemoveMapPointParams params) { + try { + OsmandAidlApi api = getApi("removeMapPoint"); + return params != null && api != null && api.removeMapPoint(params.getLayerId(), params.getPointId()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + 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()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean addMapLayer(AddMapLayerParams params) { + try { + OsmandAidlApi api = getApi("addMapLayer"); + return params != null && api != null && api.addMapLayer(new AidlMapLayerWrapper(params.getLayer())); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean removeMapLayer(RemoveMapLayerParams params) { + try { + OsmandAidlApi api = getApi("removeMapLayer"); + return params != null && api != null && api.removeMapLayer(params.getId()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean updateMapLayer(UpdateMapLayerParams params) { + try { + OsmandAidlApi api = getApi("updateMapLayer"); + return params != null && api != null && api.updateMapLayer(new AidlMapLayerWrapper(params.getLayer())); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean importGpx(ImportGpxParams params) { + try { + if (params != null && !Algorithms.isEmpty(params.getDestinationPath())) { + OsmandAidlApi api = getApi("importGpx"); + if (api != null) { + if (params.getGpxFile() != null) { + return api.importGpxFromFile(params.getGpxFile(), params.getDestinationPath(), + params.getColor(), params.isShow()); + } else if (params.getGpxUri() != null) { + return api.importGpxFromUri(params.getGpxUri(), params.getDestinationPath(), + params.getColor(), params.isShow()); + } else if (params.getSourceRawData() != null) { + return api.importGpxFromData(params.getSourceRawData(), params.getDestinationPath(), + params.getColor(), params.isShow()); + } + } + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean showGpx(ShowGpxParams params) { + try { + if (params != null && params.getFileName() != null) { + OsmandAidlApi api = getApi("showGpx"); + return api != null && api.showGpx(params.getFileName()); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean hideGpx(HideGpxParams params) { + try { + if (params != null && params.getFileName() != null) { + OsmandAidlApi api = getApi("hideGpx"); + return api != null && api.hideGpx(params.getFileName()); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean getActiveGpx(List files) { + try { + OsmandAidlApi api = getApi("getActiveGpx"); + if (api != null && files != null) { + return api.getActiveGpxV2(files); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean getImportedGpx(List files) { + try { + OsmandAidlApi api = getApi("getImportedGpx"); + if (api != null && files != null) { + return api.getImportedGpxV2(files); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean removeGpx(RemoveGpxParams params) { + try { + if (params != null && params.getFileName() != null) { + OsmandAidlApi api = getApi("removeGpx"); + return api != null && api.removeGpx(params.getFileName()); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setMapLocation(SetMapLocationParams params) { + try { + if (params != null) { + OsmandAidlApi api = getApi("setMapLocation"); + return api != null && api.setMapLocation(params.getLatitude(), params.getLongitude(), + params.getZoom(), params.isAnimated()); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean calculateRoute(CalculateRouteParams params) { + return false; + } + + @Override + public boolean startGpxRecording(StartGpxRecordingParams params) { + try { + OsmandAidlApi api = getApi("startGpxRecording"); + return api != null && api.startGpxRecording(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean stopGpxRecording(StopGpxRecordingParams params) { + try { + OsmandAidlApi api = getApi("stopGpxRecording"); + return api != null && api.stopGpxRecording(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean takePhotoNote(TakePhotoNoteParams params) { + try { + OsmandAidlApi api = getApi("takePhotoNote"); + return params != null && api != null && api.takePhotoNote(params.getLatitude(), params.getLongitude()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean startVideoRecording(StartVideoRecordingParams params) { + try { + OsmandAidlApi api = getApi("startVideoRecording"); + return params != null && api != null && api.startVideoRecording(params.getLatitude(), params.getLongitude()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean startAudioRecording(StartAudioRecordingParams params) { + try { + OsmandAidlApi api = getApi("startAudioRecording"); + return params != null && api != null && api.startAudioRecording(params.getLatitude(), params.getLongitude()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean stopRecording(StopRecordingParams params) { + try { + OsmandAidlApi api = getApi("stopRecording"); + return api != null && api.stopRecording(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean navigate(NavigateParams params) { + try { + OsmandAidlApi api = getApi("navigate"); + return params != null && api != null && api.navigate( + params.getStartName(), params.getStartLat(), params.getStartLon(), + params.getDestName(), params.getDestLat(), params.getDestLon(), + params.getProfile(), params.isForce()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean navigateGpx(NavigateGpxParams params) { + try { + OsmandAidlApi api = getApi("navigateGpx"); + return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), params.isForce()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean pauseNavigation(PauseNavigationParams params) { + try { + OsmandAidlApi api = getApi("pauseNavigation"); + return api != null && api.pauseNavigation(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean resumeNavigation(ResumeNavigationParams params) { + try { + OsmandAidlApi api = getApi("resumeNavigation"); + return api != null && api.resumeNavigation(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean stopNavigation(StopNavigationParams params) { + try { + OsmandAidlApi api = getApi("stopNavigation"); + return api != null && api.stopNavigation(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean muteNavigation(MuteNavigationParams params) { + try { + OsmandAidlApi api = getApi("muteNavigation"); + return api != null && api.muteNavigation(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean unmuteNavigation(UnmuteNavigationParams params) { + try { + OsmandAidlApi api = getApi("unmuteNavigation"); + return api != null && api.unmuteNavigation(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setNavDrawerItems(SetNavDrawerItemsParams params) { + try { + OsmandAidlApi api = getApi("setNavDrawerItems"); + if (api != null && params != null) { + return api.setNavDrawerItems(params.getAppPackage(), convertNavDrawerItems(params.getItems())); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean search(SearchParams params, final IOsmAndAidlCallback callback) { + try { + OsmandAidlApi api = getApi("search"); + return params != null && api != null && api.search(params.getSearchQuery(), params.getSearchType(), + params.getLatitude(), params.getLongitude(), params.getRadiusLevel(), params.getTotalLimit(), new SearchCompleteCallback() { + @Override + public void onSearchComplete(List resultSet) { + try { + List searchResults = new ArrayList<>(); + for (AidlSearchResultWrapper item : resultSet) { + SearchResult result = new SearchResult(item.getLatitude(), item.getLongitude(), item.getLocalName(), + item.getLocalTypeName(), item.getAlternateName(), item.getOtherNames()); + searchResults.add(result); + } + callback.onSearchComplete(searchResults); + } catch (RemoteException e) { + handleException(e); + } + } + }); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean navigateSearch(NavigateSearchParams params) { + try { + OsmandAidlApi api = getApi("navigateSearch"); + return params != null && api != null && api.navigateSearch( + params.getStartName(), params.getStartLat(), params.getStartLon(), + params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(), + params.getProfile(), params.isForce()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public long registerForUpdates(long updateTimeMS, IOsmAndAidlCallback callback) { + try { + if (updateTimeMS >= MIN_UPDATE_TIME_MS) { + long id = addAidlCallback(callback, KEY_ON_UPDATE); + startRemoteUpdates(updateTimeMS, id, callback); + return id; + } else { + return MIN_UPDATE_TIME_MS_ERROR; + } + } catch (Exception e) { + handleException(e); + return UNKNOWN_API_ERROR; + } + } + + @Override + public boolean unregisterFromUpdates(long callbackId) { + try { + return removeAidlCallback(callbackId); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setNavDrawerLogo(String imageUri) { + try { + OsmandAidlApi api = getApi("setNavDrawerLogo"); + return api != null && api.setNavDrawerLogo(imageUri); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setEnabledIds(List ids) { + try { + OsmandAidlApi api = getApi("setFeaturesEnabledIds"); + return api != null && api.setEnabledIds(ids); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setDisabledIds(List ids) { + try { + OsmandAidlApi api = getApi("setFeaturesDisabledIds"); + return api != null && api.setDisabledIds(ids); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setEnabledPatterns(List patterns) { + try { + OsmandAidlApi api = getApi("setFeaturesEnabledPatterns"); + return api != null && api.setEnabledPatterns(patterns); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setDisabledPatterns(List patterns) { + try { + OsmandAidlApi api = getApi("setFeaturesDisabledPatterns"); + return api != null && api.setDisabledPatterns(patterns); + } catch (Exception e) { + handleException(e); + return false; + } + } + + void startRemoteUpdates(final long updateTimeMS, final long callbackId, final IOsmAndAidlCallback callback) { + try { + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + try { + if (callbacks.containsKey(callbackId)) { + OsmandAidlApi api = getApi("isUpdateAllowed"); + if (api != null && api.isUpdateAllowed()) { + callback.onUpdate(); + } + startRemoteUpdates(updateTimeMS, callbackId, callback); + } + } catch (RemoteException e) { + handleException(e); + } + } + }, updateTimeMS); + } catch (Exception e) { + handleException(e); + } + } + + @Override + public boolean regWidgetVisibility(SetWidgetsParams params) { + try { + OsmandAidlApi api = getApi("regWidgetVisibility"); + return api != null && api.regWidgetVisibility(params.getWidgetKey(), params.getAppModesKeys()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean regWidgetAvailability(SetWidgetsParams params) { + try { + OsmandAidlApi api = getApi("regWidgetVisibility"); + return api != null && api.regWidgetAvailability(params.getWidgetKey(), params.getAppModesKeys()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean customizeOsmandSettings(OsmandSettingsParams params) { + try { + OsmandAidlApi api = getApi("customizeOsmandSettings"); + return api != null && api.customizeOsmandSettings(params.getSharedPreferencesName(), params.getBundle()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean getSqliteDbFiles(List files) { + try { + OsmandAidlApi api = getApi("getSqliteDbFiles"); + return api != null && api.getSqliteDbFilesV2(files); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean getActiveSqliteDbFiles(List files) { + try { + OsmandAidlApi api = getApi("getActiveSqliteDbFiles"); + return api != null && api.getActiveSqliteDbFilesV2(files); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean showSqliteDbFile(String fileName) { + try { + OsmandAidlApi api = getApi("showSqliteDbFile"); + return api != null && api.showSqliteDbFile(fileName); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean hideSqliteDbFile(String fileName) { + try { + OsmandAidlApi api = getApi("hideSqliteDbFile"); + return api != null && api.hideSqliteDbFile(fileName); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setNavDrawerLogoWithParams(NavDrawerHeaderParams params) { + try { + OsmandAidlApi api = getApi("setNavDrawerLogoWithParams"); + return api != null && api.setNavDrawerLogoWithParams( + params.getImageUri(), params.getPackageName(), params.getIntent()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setNavDrawerFooterWithParams(NavDrawerFooterParams params) { + try { + OsmandAidlApi api = getApi("setNavDrawerFooterParams"); + return api != null && api.setNavDrawerFooterWithParams( + params.getAppName(), params.getPackageName(), params.getIntent()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean restoreOsmand() { + try { + OsmandAidlApi api = getApi("restoreOsmand"); + return api != null && api.restoreOsmand(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean changePluginState(PluginParams params) { + try { + OsmandAidlApi api = getApi("changePluginState"); + return api != null && api.changePluginState(params.getPluginId(), params.getNewState()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean registerForOsmandInitListener(final IOsmAndAidlCallback callback) { + try { + OsmandAidlApi api = getApi("registerForOsmandInitListener"); + return api != null && api.registerForOsmandInitialization(new OsmandAppInitCallback() { + @Override + public void onAppInitialized() { + try { + callback.onAppInitialized(); + } catch (Exception e) { + handleException(e); + } + } + }); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean getBitmapForGpx(CreateGpxBitmapParams params, final IOsmAndAidlCallback callback) { + try { + OsmandAidlApi api = getApi("getBitmapForGpx"); + return params != null && api != null && api.getBitmapForGpx(params.getGpxUri(), params.getDensity(), params.getWidthPixels(), params.getHeightPixels(), params.getColor(), new GpxBitmapCreatedCallback() { + @Override + public void onGpxBitmapCreatedComplete(Bitmap gpxBitmap) { + try { + callback.onGpxBitmapCreated(new AGpxBitmap(gpxBitmap)); + } catch (RemoteException e) { + handleException(e); + } + } + }); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public int copyFile(CopyFileParams params) { + try { + OsmandAidlApi api = getApi("copyFile"); + if (api == null) { + return CANNOT_ACCESS_API_ERROR; + } + return api.copyFile(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone()); + } catch (Exception e) { + handleException(e); + return UNKNOWN_API_ERROR; + } + } + + @Override + public long registerForNavigationUpdates(ANavigationUpdateParams params, final IOsmAndAidlCallback callback) { + try { + OsmandAidlApi api = getApi("registerForNavUpdates"); + if (api != null) { + if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) { + api.unregisterFromUpdates(params.getCallbackId()); + removeAidlCallback(params.getCallbackId()); + return -1; + } else { + long id = addAidlCallback(callback, KEY_ON_NAV_DATA_UPDATE); + api.registerForNavigationUpdates(id); + return id; + } + } else { + return -1; + } + } catch (Exception e) { + handleException(e); + return UNKNOWN_API_ERROR; + } + } + + @Override + public long addContextMenuButtons(ContextMenuButtonsParams params, final IOsmAndAidlCallback callback) { + try { + OsmandAidlApi api = getApi("addContextMenuButtons"); + if (api != null && params != null) { + long callbackId = params.getCallbackId(); + if (callbackId == -1 || !callbacks.containsKey(callbackId)) { + callbackId = addAidlCallback(callback, KEY_ON_CONTEXT_MENU_BUTTONS_CLICK); + params.setCallbackId(callbackId); + } + boolean buttonsAdded = api.addContextMenuButtons(new AidlContextMenuButtonsWrapper(params), callbackId); + return buttonsAdded ? callbackId : -1; + } else { + return -1; + } + } catch (Exception e) { + handleException(e); + return UNKNOWN_API_ERROR; + } + } + + @Override + public boolean removeContextMenuButtons(RemoveContextMenuButtonsParams params) { + try { + OsmandAidlApi api = getApi("removeContextMenuButtons"); + if (params != null && api != null) { + long callbackId = params.getCallbackId(); + removeAidlCallback(callbackId); + return api.removeContextMenuButtons(params.getParamsId(), callbackId); + } + return false; + } catch (Exception e) { + return false; + } + } + + @Override + public boolean updateContextMenuButtons(UpdateContextMenuButtonsParams params) { + try { + OsmandAidlApi api = getApi("updateContextMenuButtons"); + if (params != null && api != null) { + ContextMenuButtonsParams buttonsParams = params.getContextMenuButtonsParams(); + return api.updateContextMenuButtons(new AidlContextMenuButtonsWrapper(buttonsParams), buttonsParams.getCallbackId()); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean areOsmandSettingsCustomized(OsmandSettingsInfoParams params) { + try { + OsmandAidlApi api = getApi("areOsmandSettingsCustomized"); + return api != null && api.areOsmandSettingsCustomized(params.getSharedPreferencesName()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean setCustomization(CustomizationInfoParams params) { + try { + OsmandAidlApi api = getApi("setCustomization"); + if (api != null && params != null) { + OsmandAidlServiceV2.this.setCustomization(api, params); + return true; + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public long registerForVoiceRouterMessages(ANavigationVoiceRouterMessageParams params, final IOsmAndAidlCallback callback) { + try { + OsmandAidlApi api = getApi("registerForVoiceRouterMessages"); + if (api != null) { + if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) { + api.unregisterFromVoiceRouterMessages(params.getCallbackId()); + removeAidlCallback(params.getCallbackId()); + return -1; + } else { + long id = addAidlCallback(callback, KEY_ON_VOICE_MESSAGE); + api.registerForVoiceRouterMessages(id); + return id; + } + } else { + return -1; + } + } catch (Exception e) { + handleException(e); + return UNKNOWN_API_ERROR; + } + } + + @Override + public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { + try { + OsmandAidlApi api = getApi("removeAllActiveMapMarkers"); + return api != null && api.removeAllActiveMapMarkers(); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean getGpxColor(GpxColorParams params) { + try { + OsmandAidlApi api = getApi("getGpxColor"); + if (api != null && params != null) { + String colorName = api.getGpxColor(params.getFileName()); + params.setGpxColor(colorName); + } + return false; + } catch (Exception e) { + handleException(e); + return false; + } + } + }; + + private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { + OsmandSettingsParams settingsParams = params.getSettingsParams(); + if (settingsParams != null) { + api.customizeOsmandSettings(settingsParams.getSharedPreferencesName(), settingsParams.getBundle()); + } + NavDrawerHeaderParams navDrawerHeaderParams = params.getNavDrawerHeaderParams(); + NavDrawerFooterParams navDrawerFooterParams = params.getNavDrawerFooterParams(); + SetNavDrawerItemsParams navDrawerItemsParams = params.getNavDrawerItemsParams(); + + setNavDrawerParams(api, navDrawerHeaderParams, navDrawerFooterParams, navDrawerItemsParams); + + ArrayList visibilityWidgetsParams = params.getVisibilityWidgetsParams(); + ArrayList availabilityWidgetsParams = params.getAvailabilityWidgetsParams(); + + regWidgetsVisibility(api, visibilityWidgetsParams); + regWidgetsAvailability(api, availabilityWidgetsParams); + + ArrayList pluginsParams = params.getPluginsParams(); + if (pluginsParams != null) { + changePluginsStatus(api, pluginsParams); + } + + List enabledIds = params.getFeaturesEnabledIds(); + List disabledIds = params.getFeaturesDisabledIds(); + + api.setEnabledIds(enabledIds); + api.setDisabledIds(disabledIds); + + List enabledPatterns = params.getFeaturesEnabledPatterns(); + List disabledPatterns = params.getFeaturesDisabledPatterns(); + + api.setEnabledPatterns(enabledPatterns); + api.setDisabledPatterns(disabledPatterns); + } + + private void setNavDrawerParams(OsmandAidlApi api, NavDrawerHeaderParams navDrawerHeaderParams, NavDrawerFooterParams navDrawerFooterParams, SetNavDrawerItemsParams navDrawerItemsParams) { + if (navDrawerHeaderParams != null) { + api.setNavDrawerLogoWithParams(navDrawerHeaderParams.getImageUri(), navDrawerHeaderParams.getPackageName(), navDrawerHeaderParams.getIntent()); + } + if (navDrawerFooterParams != null) { + api.setNavDrawerFooterWithParams(navDrawerFooterParams.getAppName(), navDrawerFooterParams.getPackageName(), navDrawerFooterParams.getIntent()); + } + if (navDrawerItemsParams != null) { + api.setNavDrawerItems(navDrawerItemsParams.getAppPackage(), convertNavDrawerItems(navDrawerItemsParams.getItems())); + } + } + + private void regWidgetsVisibility(OsmandAidlApi api, ArrayList visibilityWidgetsParams) { + for (SetWidgetsParams setWidgetsParams : visibilityWidgetsParams) { + api.regWidgetVisibility(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys()); + } + } + + private void regWidgetsAvailability(OsmandAidlApi api, ArrayList availabilityWidgetsParams) { + for (SetWidgetsParams setWidgetsParams : availabilityWidgetsParams) { + api.regWidgetAvailability(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys()); + } + } + + public void changePluginsStatus(OsmandAidlApi api, List pluginsParams) { + for (PluginParams pluginParams : pluginsParams) { + api.changePluginState(pluginParams.getPluginId(), pluginParams.getNewState()); + } + } + + private List convertNavDrawerItems(List drawerItems) { + List customizationItems = new ArrayList<>(); + for (NavDrawerItem item : drawerItems) { + customizationItems.add(new OsmAndAppCustomization.NavDrawerItem(item.getName(), item.getUri(), item.getIconName(), item.getFlags())); + } + return customizationItems; + } + + public static class AidlCallbackParams { + private IOsmAndAidlCallback callback; + private long key; + + AidlCallbackParams(IOsmAndAidlCallback callback, long key) { + this.callback = callback; + + this.key = key; + } + + public IOsmAndAidlCallback getCallback() { + return callback; + } + + public void setCallback(IOsmAndAidlCallback callback) { + this.callback = callback; + } + + public long getKey() { + return key; + } + + public void setKey(long key) { + this.key = key; + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java index 5f61159d56..e089b98c48 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java @@ -16,13 +16,6 @@ import android.widget.ArrayAdapter; import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.aidl.OsmandAidlApi; -import net.osmand.aidl.customization.CustomizationInfoParams; -import net.osmand.aidl.customization.OsmandSettingsParams; -import net.osmand.aidl.customization.SetWidgetsParams; -import net.osmand.aidl.navdrawer.NavDrawerFooterParams; -import net.osmand.aidl.navdrawer.NavDrawerHeaderParams; -import net.osmand.aidl.navdrawer.SetNavDrawerItemsParams; -import net.osmand.aidl.plugins.PluginParams; import net.osmand.data.LocationPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.PluginsActivity; @@ -63,7 +56,10 @@ public class OsmAndAppCustomization { private Bitmap navDrawerLogo; private ArrayList navDrawerParams; - private NavDrawerFooterParams navDrawerFooterParams; + + private String navDrawerFooterIntent; + private String navDrawerFooterAppName; + private String navDrawerFooterPackageName; private Set featuresEnabledIds = new HashSet<>(); private Set featuresDisabledIds = new HashSet<>(); @@ -253,13 +249,15 @@ public class OsmAndAppCustomization { return true; } - public boolean setNavDrawerFooterParams(NavDrawerFooterParams params) { - navDrawerFooterParams = params; + public boolean setNavDrawerFooterParams(String uri, @Nullable String packageName, @Nullable String intent) { + navDrawerFooterAppName = uri; + navDrawerFooterIntent = intent; + navDrawerFooterPackageName = packageName; return true; } - public NavDrawerFooterParams getNavFooterParams() { - return navDrawerFooterParams; + public String getNavFooterAppName() { + return navDrawerFooterAppName; } public void setFeaturesEnabledIds(@NonNull Collection ids) { @@ -300,89 +298,6 @@ public class OsmAndAppCustomization { return set; } - public void regWidgetsVisibility(@NonNull ArrayList visibilityWidgetsParams) { - for (SetWidgetsParams setWidgetsParams : visibilityWidgetsParams) { - regWidgetVisibility(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys()); - } - } - - public void regWidgetsAvailability(@NonNull ArrayList availabilityWidgetsParams) { - for (SetWidgetsParams setWidgetsParams : availabilityWidgetsParams) { - regWidgetAvailability(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys()); - } - } - - public void setCustomization(CustomizationInfoParams params) { - OsmandSettingsParams settingsParams = params.getSettingsParams(); - if (settingsParams != null) { - customizeOsmandSettings(settingsParams.getSharedPreferencesName(), settingsParams.getBundle()); - } - NavDrawerHeaderParams navDrawerHeaderParams = params.getNavDrawerHeaderParams(); - NavDrawerFooterParams navDrawerFooterParams = params.getNavDrawerFooterParams(); - SetNavDrawerItemsParams navDrawerItemsParams = params.getNavDrawerItemsParams(); - - setNavDrawerParams(navDrawerHeaderParams, navDrawerFooterParams, navDrawerItemsParams); - - ArrayList visibilityWidgetsParams = params.getVisibilityWidgetsParams(); - ArrayList availabilityWidgetsParams = params.getAvailabilityWidgetsParams(); - - setWidgetsParams(visibilityWidgetsParams, availabilityWidgetsParams); - - ArrayList pluginsParams = params.getPluginsParams(); - if (pluginsParams != null) { - changePluginsStatus(pluginsParams); - } - - List enabledIds = params.getFeaturesEnabledIds(); - List disabledIds = params.getFeaturesDisabledIds(); - - setFeaturesIds(enabledIds, disabledIds); - - List enabledPatterns = params.getFeaturesEnabledPatterns(); - List disabledPatterns = params.getFeaturesDisabledPatterns(); - - setFeaturesPatterns(enabledPatterns, disabledPatterns); - } - - public void setNavDrawerParams(NavDrawerHeaderParams navDrawerHeaderParams, NavDrawerFooterParams navDrawerFooterParams, SetNavDrawerItemsParams navDrawerItemsParams) { - if (navDrawerHeaderParams != null) { - setNavDrawerLogoWithParams(navDrawerHeaderParams.getImageUri(), navDrawerHeaderParams.getPackageName(), navDrawerHeaderParams.getIntent()); - } - if (navDrawerFooterParams != null) { - setNavDrawerFooterParams(navDrawerFooterParams); - } - if (navDrawerItemsParams != null) { - setNavDrawerItems(navDrawerItemsParams.getAppPackage(), navDrawerItemsParams.getItems()); - } - } - - public void setWidgetsParams(ArrayList visibilityWidgetsParams, ArrayList availabilityWidgetsParams) { - if (visibilityWidgetsParams != null) { - regWidgetsVisibility(visibilityWidgetsParams); - } - if (availabilityWidgetsParams != null) { - regWidgetsAvailability(availabilityWidgetsParams); - } - } - - public void setFeaturesIds(List enabledIds, List disabledIds) { - if (enabledIds != null) { - setFeaturesEnabledIds(enabledIds); - } - if (disabledIds != null) { - setFeaturesDisabledIds(disabledIds); - } - } - - public void setFeaturesPatterns(List enabledPatterns, List disabledPatterns) { - if (enabledPatterns != null) { - setFeaturesEnabledPatterns(enabledPatterns); - } - if (disabledPatterns != null) { - setFeaturesDisabledPatterns(disabledPatterns); - } - } - public boolean isWidgetVisible(@NonNull String key, ApplicationMode appMode) { Set set = widgetsVisibilityMap.get(key); if (set == null) { @@ -404,25 +319,19 @@ public class OsmAndAppCustomization { return setNavDrawerLogo(imageUri, packageName, intent); } - public void changePluginsStatus(List pluginsParams) { - for (PluginParams pluginParams : pluginsParams) { - changePluginStatus(pluginParams); - } - } - - public boolean changePluginStatus(PluginParams params) { - if (params.getNewState() == 0) { + public boolean changePluginStatus(String pluginId, int newState) { + if (newState == 0) { for (OsmandPlugin plugin : OsmandPlugin.getEnabledPlugins()) { - if (plugin.getId().equals(params.getPluginId())) { + if (plugin.getId().equals(pluginId)) { OsmandPlugin.enablePlugin(null, app, plugin, false); } } return true; } - if (params.getNewState() == 1) { + if (newState == 1) { for (OsmandPlugin plugin : OsmandPlugin.getAvailablePlugins()) { - if (plugin.getId().equals(params.getPluginId())) { + if (plugin.getId().equals(pluginId)) { OsmandPlugin.enablePlugin(null, app, plugin, true); } } @@ -432,7 +341,7 @@ public class OsmAndAppCustomization { return false; } - public boolean setNavDrawerItems(String appPackage, List items) { + public boolean setNavDrawerItems(String appPackage, List items) { if (!TextUtils.isEmpty(appPackage) && items != null) { clearNavDrawerItems(appPackage); if (items.isEmpty()) { @@ -441,11 +350,9 @@ public class OsmAndAppCustomization { List newItems = new ArrayList<>(MAX_NAV_DRAWER_ITEMS_PER_APP); boolean success = true; for (int i = 0; i < items.size() && i <= MAX_NAV_DRAWER_ITEMS_PER_APP; i++) { - net.osmand.aidl.navdrawer.NavDrawerItem item = items.get(i); - String name = item.getName(); - String uri = item.getUri(); - if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(uri)) { - newItems.add(new NavDrawerItem(name, uri, item.getIconName(), item.getFlags())); + NavDrawerItem item = items.get(i); + if (!TextUtils.isEmpty(item.name) && !TextUtils.isEmpty(item.uri)) { + newItems.add(item); } else { success = false; break; @@ -654,7 +561,7 @@ public class OsmAndAppCustomization { this.listeners.remove(listener); } - private static class NavDrawerItem { + public static class NavDrawerItem { static final String NAME_KEY = "name"; static final String URI_KEY = "uri"; @@ -666,7 +573,7 @@ public class OsmAndAppCustomization { private String iconName; private int flags; - NavDrawerItem(String name, String uri, String iconName, int flags) { + public NavDrawerItem(String name, String uri, String iconName, int flags) { this.name = name; this.uri = uri; this.iconName = iconName; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 9063f3ce09..116573e385 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -50,9 +50,8 @@ import net.osmand.SecondSplashScreenFragment; import net.osmand.StateChangedListener; import net.osmand.ValueHolder; import net.osmand.access.MapAccessibilityActions; +import net.osmand.aidl.AidlMapPointWrapper; import net.osmand.aidl.OsmandAidlApi.AMapPointUpdateListener; -import net.osmand.aidl.map.ALatLon; -import net.osmand.aidl.maplayer.point.AMapPoint; import net.osmand.core.android.AtlasMapRendererView; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -1923,13 +1922,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } @Override - public void onAMapPointUpdated(final AMapPoint point, String layerId) { + public void onAMapPointUpdated(final AidlMapPointWrapper point, String layerId) { if (canUpdateAMapPointMenu(point, layerId)) { app.runInUIThread(new Runnable() { @Override public void run() { - ALatLon loc = point.getLocation(); - LatLon latLon = new LatLon(loc.getLatitude(), loc.getLongitude()); + LatLon latLon = point.getLocation(); PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_MARKER, point.getFullName()); mapContextMenu.update(latLon, pointDescription, point); mapContextMenu.centerMarkerLocation(); @@ -1938,12 +1936,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } } - private boolean canUpdateAMapPointMenu(AMapPoint point, String layerId) { + private boolean canUpdateAMapPointMenu(AidlMapPointWrapper point, String layerId) { Object object = mapContextMenu.getObject(); - if (!mapContextMenu.isVisible() || !(object instanceof AMapPoint)) { + if (!mapContextMenu.isVisible() || !(object instanceof AidlMapPointWrapper)) { return false; } - AMapPoint oldPoint = (AMapPoint) object; + AidlMapPointWrapper oldPoint = (AidlMapPointWrapper) object; return oldPoint.getLayerId().equals(layerId) && oldPoint.getId().equals(point.getId()); } diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/OsmandRestoreOrExitDialog.java b/OsmAnd/src/net/osmand/plus/activities/actions/OsmandRestoreOrExitDialog.java index ee3e27ba43..e1298fe5b9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/OsmandRestoreOrExitDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/OsmandRestoreOrExitDialog.java @@ -25,7 +25,7 @@ public class OsmandRestoreOrExitDialog extends BottomSheetDialogFragment { View view = getActivity().getLayoutInflater() .inflate(R.layout.dash_restore_osmand_fragment, container, false); try { - clientAppTitle = getMyApplication().getAppCustomization().getNavFooterParams().getAppName(); + clientAppTitle = getMyApplication().getAppCustomization().getNavFooterAppName(); } catch (Exception e) { e.printStackTrace(); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 6bc43505bb..e61dc78cd9 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -15,8 +15,8 @@ import net.osmand.IndexConstants; import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi; +import net.osmand.aidl.AidlSearchResultWrapper; import net.osmand.aidl.search.SearchParams; -import net.osmand.aidl.search.SearchResult; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -663,7 +663,7 @@ public class ExternalApiHelper { searchLocation.getLatitude(), searchLocation.getLongitude(), 1, 1, new OsmandAidlApi.SearchCompleteCallback() { @Override - public void onSearchComplete(final List resultSet) { + public void onSearchComplete(final List resultSet) { final MapActivity mapActivity = mapActivityRef.get(); if (mapActivity != null) { mapActivity.getMyApplication().runInUIThread(new Runnable() { @@ -674,7 +674,7 @@ public class ExternalApiHelper { dlg.dismiss(); } if (resultSet.size() > 0) { - final SearchResult res = resultSet.get(0); + final AidlSearchResultWrapper res = resultSet.get(0); LatLon to = new LatLon(res.getLatitude(), res.getLongitude()); PointDescription toDesc = new PointDescription( PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName()); @@ -707,13 +707,13 @@ public class ExternalApiHelper { core.setOnResultsComplete(new Runnable() { @Override public void run() { - List resultSet = new ArrayList<>(); + List resultSet = new ArrayList<>(); SearchUICore.SearchResultCollection resultCollection = core.getCurrentSearchResult(); int count = 0; for (net.osmand.search.core.SearchResult r : resultCollection.getCurrentSearchResults()) { String name = QuickSearchListItem.getName(app, r); String typeName = QuickSearchListItem.getTypeName(app, r); - SearchResult result = new SearchResult(r.location.getLatitude(), r.location.getLongitude(), + AidlSearchResultWrapper result = new AidlSearchResultWrapper(r.location.getLatitude(), r.location.getLongitude(), name, typeName, r.alternateName, new ArrayList<>(r.otherNames)); resultSet.add(result); count++; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 7f6a23b10c..c89fee0cbf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -2,9 +2,7 @@ package net.osmand.plus.mapcontextmenu; import android.content.Context; import android.graphics.drawable.Drawable; -import android.graphics.drawable.StateListDrawable; import android.os.AsyncTask; -import android.os.Build; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; @@ -17,13 +15,11 @@ import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; -import java.util.Map; -import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.Location; import net.osmand.NativeLibrary.RenderedObject; import net.osmand.PlatformUtil; -import net.osmand.aidl.maplayer.point.AMapPoint; +import net.osmand.aidl.AidlMapPointWrapper; import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.RouteDataObject; @@ -211,8 +207,8 @@ public abstract class MenuController extends BaseMenuController implements Colla menuController = new TransportRouteController(mapActivity, pointDescription, (TransportStopRoute) object); } else if (object instanceof TransportStop) { menuController = new TransportStopController(mapActivity, pointDescription, (TransportStop) object); - } else if (object instanceof AMapPoint) { - menuController = new AMapPointMenuController(mapActivity, pointDescription, (AMapPoint) object); + } else if (object instanceof AidlMapPointWrapper) { + menuController = new AMapPointMenuController(mapActivity, pointDescription, (AidlMapPointWrapper) object); } else if (object instanceof LatLon) { if (pointDescription.isParking()) { menuController = new ParkingPositionMenuController(mapActivity, pointDescription); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java index 52ea9d5740..56ec551a7f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java @@ -10,9 +10,10 @@ import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Pair; -import net.osmand.aidl.contextmenu.AContextMenuButton; -import net.osmand.aidl.contextmenu.ContextMenuButtonsParams; -import net.osmand.aidl.maplayer.point.AMapPoint; +import net.osmand.aidl.AidlContextMenuButtonWrapper; +import net.osmand.aidl.AidlContextMenuButtonsWrapper; +import net.osmand.aidl.AidlMapPointWrapper; +import net.osmand.aidl2.maplayer.point.AMapPoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.OsmAndFormatter; @@ -24,7 +25,6 @@ import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.util.Algorithms; -import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -35,19 +35,19 @@ public class AMapPointMenuController extends MenuController { private static final float NO_VALUE = -1; private static final int NO_ICON = 0; - private AMapPoint point; + private AidlMapPointWrapper point; private Drawable pointDrawable; - public AMapPointMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull final AMapPoint point) { + public AMapPointMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull final AidlMapPointWrapper point) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); this.point = point; pointDrawable = getPointDrawable(); final OsmandApplication app = mapActivity.getMyApplication(); - Map buttonsParamsMap = app.getAidlApi().getContextMenuButtonsParams(); + Map buttonsParamsMap = app.getAidlApi().getContextMenuButtonsParams(); if (!buttonsParamsMap.isEmpty()) { additionalButtonsControllers = new ArrayList<>(); - for (ContextMenuButtonsParams buttonsParams : buttonsParamsMap.values()) { + for (AidlContextMenuButtonsWrapper buttonsParams : buttonsParamsMap.values()) { List pointsIds = buttonsParams.getPointsIds(); if (((pointsIds == null || pointsIds.isEmpty()) || pointsIds.contains(point.getId())) || buttonsParams.getLayerId().equals(point.getLayerId())) { long callbackId = buttonsParams.getCallbackId(); @@ -61,8 +61,8 @@ public class AMapPointMenuController extends MenuController { @Override protected void setObject(Object object) { - if (object instanceof AMapPoint) { - this.point = (AMapPoint) object; + if (object instanceof AidlMapPointWrapper) { + this.point = (AidlMapPointWrapper) object; } } @@ -179,7 +179,7 @@ public class AMapPointMenuController extends MenuController { return false; } - private TitleButtonController createAdditionButtonController(final AContextMenuButton contextMenuButton, final long callbackId) { + private TitleButtonController createAdditionButtonController(final AidlContextMenuButtonWrapper contextMenuButton, final long callbackId) { MapActivity mapActivity = getMapActivity(); if (mapActivity == null || contextMenuButton == null) { return null; diff --git a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java index 8241ee636f..8d6044090d 100644 --- a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java @@ -16,9 +16,9 @@ import android.support.annotation.Nullable; import android.text.TextUtils; import net.osmand.AndroidUtils; -import net.osmand.aidl.map.ALatLon; -import net.osmand.aidl.maplayer.AMapLayer; -import net.osmand.aidl.maplayer.point.AMapPoint; +import net.osmand.aidl.AidlMapLayerWrapper; +import net.osmand.aidl.AidlMapPointWrapper; +import net.osmand.aidl2.maplayer.point.AMapPoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; @@ -39,7 +39,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider, MapTextLayer.MapTextProvider { +public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider, MapTextLayer.MapTextProvider { private static final float POINT_IMAGE_VERTICAL_OFFSET = 0.91f; @@ -51,7 +51,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider private final MapActivity map; private OsmandMapTileView view; - private AMapLayer aidlLayer; + private AidlMapLayerWrapper aidlLayer; private Paint pointInnerCircle; private Paint pointOuterCircle; @@ -75,9 +75,9 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider private Map pointImages = new ConcurrentHashMap<>(); private Set imageRequests = new HashSet<>(); - private List displayedPoints = new ArrayList<>(); + private List displayedPoints = new ArrayList<>(); - public AidlMapLayer(MapActivity map, AMapLayer aidlLayer) { + public AidlMapLayer(MapActivity map, AidlMapLayerWrapper aidlLayer) { this.map = map; this.aidlLayer = aidlLayer; } @@ -140,8 +140,8 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); String selectedPointId = getSelectedContextMenuPointId(); - for (AMapPoint point : aidlLayer.getPoints()) { - ALatLon l = point.getLocation(); + for (AidlMapPointWrapper point : aidlLayer.getPoints()) { + LatLon l = point.getLocation(); if (l != null) { int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude()); int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude()); @@ -169,7 +169,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider mapTextLayer.putData(this, displayedPoints); } - private void drawPoint(Canvas canvas, int x, int y, RotatedTileBox tb, AMapPoint point, Bitmap image, boolean selected) { + private void drawPoint(Canvas canvas, int x, int y, RotatedTileBox tb, AidlMapPointWrapper point, Bitmap image, boolean selected) { if (image == null) { image = placeholder; } @@ -205,8 +205,8 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider private String getSelectedContextMenuPointId() { MapContextMenu mapContextMenu = map.getContextMenu(); Object object = mapContextMenu.getObject(); - if (mapContextMenu.isVisible() && object instanceof AMapPoint) { - AMapPoint aMapPoint = (AMapPoint) object; + if (mapContextMenu.isVisible() && object instanceof AidlMapPointWrapper) { + AidlMapPointWrapper aMapPoint = (AidlMapPointWrapper) object; return aMapPoint.getId(); } return null; @@ -226,7 +226,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider return rect; } - private boolean isStale(AMapPoint point) { + private boolean isStale(AidlMapPointWrapper point) { return Boolean.parseBoolean(point.getParams().get(AMapPoint.POINT_STALE_LOC_PARAM)); } @@ -251,7 +251,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider @Override public boolean isObjectClickable(Object o) { - return o instanceof AMapPoint; + return o instanceof AidlMapPointWrapper; } @Override @@ -266,40 +266,33 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider @Override public LatLon getObjectLocation(Object o) { - if (o instanceof AMapPoint) { - ALatLon loc = ((AMapPoint) o).getLocation(); - if (loc != null) { - return new LatLon(loc.getLatitude(), loc.getLongitude()); - } + if (o instanceof AidlMapPointWrapper) { + return ((AidlMapPointWrapper) o).getLocation(); } return null; } @Override public PointDescription getObjectName(Object o) { - if (o instanceof AMapPoint) { - return new PointDescription(PointDescription.POINT_TYPE_MARKER, ((AMapPoint) o).getFullName()); + if (o instanceof AidlMapPointWrapper) { + return new PointDescription(PointDescription.POINT_TYPE_MARKER, ((AidlMapPointWrapper) o).getFullName()); } else { return null; } } @Nullable - public AMapPoint getPoint(@NonNull String id) { + public AidlMapPointWrapper getPoint(@NonNull String id) { return aidlLayer.getPoint(id); } @Override - public LatLon getTextLocation(AMapPoint o) { - ALatLon loc = o.getLocation(); - if (loc != null) { - return new LatLon(loc.getLatitude(), loc.getLongitude()); - } - return null; + public LatLon getTextLocation(AidlMapPointWrapper o) { + return o.getLocation(); } @Override - public int getTextShift(AMapPoint o, RotatedTileBox rb) { + public int getTextShift(AidlMapPointWrapper o, RotatedTileBox rb) { if (pointsType == PointsType.STANDARD) { return (int) (getRadiusPoi(rb) * 1.5); } else if (pointsType == PointsType.CIRCLE) { @@ -313,7 +306,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider } @Override - public String getText(AMapPoint o) { + public String getText(AidlMapPointWrapper o) { return o.getShortName(); } @@ -376,13 +369,13 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider return r * 3 / 2; } - private void getFromPoint(RotatedTileBox tb, PointF point, List points) { + private void getFromPoint(RotatedTileBox tb, PointF point, List points) { if (view != null) { int ex = (int) point.x; int ey = (int) point.y; int radius = getPointRadius(tb); - for (AMapPoint p : aidlLayer.getPoints()) { - ALatLon position = p.getLocation(); + for (AidlMapPointWrapper p : aidlLayer.getPoints()) { + LatLon position = p.getLocation(); if (position != null) { int x = (int) tb.getPixXFromLatLon(position.getLatitude(), position.getLongitude()); int y = (int) tb.getPixYFromLatLon(position.getLatitude(), position.getLongitude()); diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 8bf1c1454c..e37ed3728a 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -25,7 +25,7 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.NativeLibrary.RenderedObject; import net.osmand.RenderingContext; -import net.osmand.aidl.maplayer.point.AMapPoint; +import net.osmand.aidl.AidlMapPointWrapper; import net.osmand.core.android.MapRendererView; import net.osmand.core.jni.AmenitySymbolsProvider.AmenitySymbolsGroup; import net.osmand.core.jni.AreaI; @@ -205,7 +205,7 @@ public class ContextMenuLayer extends OsmandMapLayer { RenderedObject r = (RenderedObject) selectedObject; x = r.getX(); y = r.getY(); - } else if (selectedObject instanceof AMapPoint) { + } else if (selectedObject instanceof AidlMapPointWrapper) { markerCustomized = true; } if (x != null && y != null && x.size() > 2) {