Add aidl service for support v2 api

This commit is contained in:
Chumva 2019-10-10 12:50:44 +03:00
parent 4b59c038f7
commit 63eca2c6a2
19 changed files with 2540 additions and 552 deletions

View file

@ -867,6 +867,13 @@
</intent-filter>
</service>
<service android:name="net.osmand.aidl.OsmandAidlServiceV2" android:exported="true" >
<intent-filter>
<action android:name="net.osmand.aidl.OsmandAidlServiceV2"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
<service
android:name="net.osmand.plus.download.DownloadService"
android:label="@string/process_downloading_service"

View file

@ -0,0 +1,36 @@
package net.osmand.aidl;
import net.osmand.aidl2.IOsmAndAidlCallback;
import java.util.Map;
public interface AidlCallbackListenerV2 {
/**
* Add AidlCallbackListener to OsmandAidlService's map of listeners. Key is unique to each AIDL
* method that wants to register callback and used to access only "own" callbacks.
*
* @param callback
* @param key - every AIDL method which uses that register callbacks in service need to use its own bit key
* 1 - key for registerForUpdates(...)
* 2 - key for registerForNavigationUpdates(...)
* 4 - key for onContextMenuButtonClicked(...)
* 8 - key for... future use
* 16 - key for... future use
* @return long - unique id of callback. Could be used for unregistering callback
*/
long addAidlCallback(IOsmAndAidlCallback callback, int key);
/**
* Unregister AidlCallbackListener from OsmandAidlService's map
*
* @param id - unique id of callback
* @return - true if callback successfully unregistered
*/
boolean removeAidlCallback(long id);
/**
* @return map of all callbacks. AidlCallbackParams contains method key and callback.
*/
Map<Long, OsmandAidlServiceV2.AidlCallbackParams> getAidlCallbacks();
}

View file

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

View file

@ -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<String> 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<String> getPointsIds() {
return pointsIds;
}
}

View file

@ -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<String, AidlMapPointWrapper> 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<AMapPoint> 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<net.osmand.aidl2.maplayer.point.AMapPoint> 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<AidlMapPointWrapper> 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;
}
}

View file

@ -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<String> details;
private Map<String, String> 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<String> getDetails() {
return details;
}
public Map<String, String> getParams() {
return params;
}
}

View file

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

View file

@ -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<String> otherNames = new ArrayList<>();
public AidlSearchResultWrapper(double latitude, double longitude, String localName, String localTypeName,
String alternateName, List<String> 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<String> getOtherNames() {
return otherNames;
}
}

View file

@ -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<String, AMapWidget> widgets = new ConcurrentHashMap<>();
private Map<String, AidlMapWidgetWrapper> widgets = new ConcurrentHashMap<>();
private Map<String, TextInfoWidget> widgetControls = new ConcurrentHashMap<>();
private Map<String, AMapLayer> layers = new ConcurrentHashMap<>();
private Map<String, AidlMapLayerWrapper> layers = new ConcurrentHashMap<>();
private Map<String, OsmandMapLayer> mapLayers = new ConcurrentHashMap<>();
private Map<String, BroadcastReceiver> receivers = new TreeMap<>();
private Map<String, ConnectedApp> connectedApps = new ConcurrentHashMap<>();
private Map<String, ContextMenuButtonsParams> contextMenuButtonsParams = new ConcurrentHashMap<>();
private Map<Long, VoiceRouter.VoiceMessageListener> voiceRouterMessageCallbacks= new ConcurrentHashMap<>();
private Map<String, AidlContextMenuButtonsWrapper> contextMenuButtonsParams = new ConcurrentHashMap<>();
private Map<Long, VoiceRouter.VoiceMessageListener> 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,143 +894,114 @@ public class OsmandAidlApi {
return true;
}
boolean addFavoriteGroup(AFavoriteGroup favoriteGroup) {
if (favoriteGroup != null) {
boolean addFavoriteGroup(String name, String colorTag, boolean visible) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritesDbHelper.FavoriteGroup> groups = favoritesHelper.getFavoriteGroups();
for (FavouritesDbHelper.FavoriteGroup g : groups) {
if (g.name.equals(favoriteGroup.getName())) {
if (g.name.equals(name)) {
return false;
}
}
int color = 0;
if (!Algorithms.isEmpty(favoriteGroup.getColor())) {
color = ColorDialogs.getColorByTag(favoriteGroup.getColor());
if (!Algorithms.isEmpty(colorTag)) {
color = ColorDialogs.getColorByTag(colorTag);
}
favoritesHelper.addEmptyCategory(favoriteGroup.getName(), color, favoriteGroup.isVisible());
favoritesHelper.addEmptyCategory(name, color, visible);
return true;
} else {
return false;
}
}
boolean removeFavoriteGroup(AFavoriteGroup favoriteGroup) {
if (favoriteGroup != null) {
boolean removeFavoriteGroup(String name) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritesDbHelper.FavoriteGroup> groups = favoritesHelper.getFavoriteGroups();
for (FavouritesDbHelper.FavoriteGroup g : groups) {
if (g.name.equals(favoriteGroup.getName())) {
if (g.name.equals(name)) {
favoritesHelper.deleteGroup(g);
return true;
}
}
return false;
} else {
return false;
}
}
boolean updateFavoriteGroup(AFavoriteGroup gPrev, AFavoriteGroup gNew) {
if (gPrev != null && gNew != null) {
boolean updateFavoriteGroup(String prevGroupName, String newGroupName, String colorTag, boolean visible) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritesDbHelper.FavoriteGroup> groups = favoritesHelper.getFavoriteGroups();
for (FavouritesDbHelper.FavoriteGroup g : groups) {
if (g.name.equals(gPrev.getName())) {
if (g.name.equals(prevGroupName)) {
int color = 0;
if (!Algorithms.isEmpty(gNew.getColor())) {
color = ColorDialogs.getColorByTag(gNew.getColor());
if (!Algorithms.isEmpty(colorTag)) {
color = ColorDialogs.getColorByTag(colorTag);
}
favoritesHelper.editFavouriteGroup(g, gNew.getName(), color, gNew.isVisible());
favoritesHelper.editFavouriteGroup(g, newGroupName, color, visible);
return true;
}
}
return false;
} else {
return false;
}
}
boolean addFavorite(AFavorite favorite) {
if (favorite != null) {
boolean addFavorite(double latitude, double longitude, String name, String category, String description, String colorTag, boolean visible) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
FavouritePoint point = new FavouritePoint(favorite.getLat(), favorite.getLon(), favorite.getName(), favorite.getCategory());
point.setDescription(favorite.getDescription());
FavouritePoint point = new FavouritePoint(latitude, longitude, name, category);
point.setDescription(description);
int color = 0;
if (!Algorithms.isEmpty(favorite.getColor())) {
color = ColorDialogs.getColorByTag(favorite.getColor());
if (!Algorithms.isEmpty(colorTag)) {
color = ColorDialogs.getColorByTag(colorTag);
}
point.setColor(color);
point.setVisible(favorite.isVisible());
point.setVisible(visible);
favoritesHelper.addFavourite(point);
refreshMap();
return true;
} else {
return false;
}
}
boolean removeFavorite(AFavorite favorite) {
if (favorite != null) {
boolean removeFavorite(String name, String category, double latitude, double longitude) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritePoint> 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()) {
if (f.getName().equals(name) && f.getCategory().equals(category) &&
f.getLatitude() == latitude && f.getLongitude() == longitude) {
favoritesHelper.deleteFavourite(f);
refreshMap();
return true;
}
}
return false;
} else {
return false;
}
}
boolean updateFavorite(AFavorite fPrev, AFavorite fNew) {
if (fPrev != null && fNew != null) {
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<FavouritePoint> 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 (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);
}
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());
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;
}
}
boolean addMapMarker(AMapMarker marker) {
if (marker != null) {
boolean addMapMarker(String name, double latitude, double longitude) {
PointDescription pd = new PointDescription(
PointDescription.POINT_TYPE_MAP_MARKER, marker.getName() != null ? marker.getName() : "");
PointDescription.POINT_TYPE_MAP_MARKER, name != null ? name : "");
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
markersHelper.addMapMarker(new LatLon(marker.getLatLon().getLatitude(), marker.getLatLon().getLongitude()), pd);
markersHelper.addMapMarker(new LatLon(latitude, longitude), 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());
boolean removeMapMarker(String name, double latitude, double longitude, boolean ignoreCoordinates) {
LatLon latLon = new LatLon(latitude, longitude);
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
for (MapMarker m : mapMarkers) {
if (m.getOnlyName().equals(marker.getName())) {
if (m.getOnlyName().equals(name)) {
if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
markersHelper.moveMapMarkerToHistory(m);
refreshMap();
@ -1055,9 +1010,6 @@ public class OsmandAidlApi {
}
}
return false;
} else {
return false;
}
}
boolean removeAllActiveMapMarkers() {
@ -1075,17 +1027,16 @@ 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());
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<MapMarker> mapMarkers = markersHelper.getMapMarkers();
for (MapMarker m : mapMarkers) {
if (m.getOnlyName().equals(markerPrev.getName())) {
if (m.getOnlyName().equals(prevName)) {
if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
PointDescription pd = new PointDescription(
PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : "");
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;
@ -1097,12 +1048,9 @@ public class OsmandAidlApi {
}
}
return false;
} else {
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();
@ -1449,7 +1397,6 @@ public class OsmandAidlApi {
}
boolean getActiveGpx(List<ASelectedGpxFile> files) {
if (files != null) {
List<SelectedGpxFile> selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
String gpxPath = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath();
for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) {
@ -1466,14 +1413,48 @@ public class OsmandAidlApi {
}
return true;
}
return false;
boolean getActiveGpxV2(List<net.osmand.aidl2.gpx.ASelectedGpxFile> files) {
List<SelectedGpxFile> 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<net.osmand.aidl2.gpx.AGpxFile> files) {
List<GpxDataItem> 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<AGpxFile> files) {
if (files != null) {
List<GpxDataItem> gpxDataItems = app.getGpxDatabase().getItems();
for (GpxDataItem dataItem : gpxDataItems) {
//if (dataItem.isApiImported()) {
File file = dataItem.getFile();
if (file.exists()) {
String fileName = file.getName();
@ -1487,31 +1468,24 @@ public class OsmandAidlApi {
}
files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details));
}
//}
}
return true;
}
return false;
}
boolean getGpxColor(GpxColorParams params) {
if (params != null) {
String getGpxColor(String gpxFileName) {
List<GpxDataItem> gpxDataItems = app.getGpxDatabase().getItems();
for (GpxDataItem dataItem : gpxDataItems) {
File file = dataItem.getFile();
if (file.exists()) {
if (file.getName().equals(params.getFileName())) {
if (file.getName().equals(gpxFileName)) {
int color = dataItem.getColor();
if (color != 0) {
String colorName = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
params.setGpxColor(colorName);
return true;
return ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
}
}
}
}
}
return false;
return null;
}
boolean removeGpx(String fileName) {
@ -1530,7 +1504,6 @@ public class OsmandAidlApi {
}
private boolean getSqliteDbFiles(List<ASqliteDbFile> fileNames, boolean activeOnly) {
if (fileNames != null) {
File tilesPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
if (tilesPath.canRead()) {
File[] files = tilesPath.listFiles();
@ -1550,7 +1523,26 @@ public class OsmandAidlApi {
}
return true;
}
return false;
private boolean getSqliteDbFilesV2(List<net.osmand.aidl2.tiles.ASqliteDbFile> 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<ASqliteDbFile> fileNames) {
@ -1561,6 +1553,14 @@ public class OsmandAidlApi {
return getSqliteDbFiles(fileNames, true);
}
boolean getSqliteDbFilesV2(List<net.osmand.aidl2.tiles.ASqliteDbFile> fileNames) {
return getSqliteDbFilesV2(fileNames, false);
}
boolean getActiveSqliteDbFilesV2(List<net.osmand.aidl2.tiles.ASqliteDbFile> 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();
@ -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<net.osmand.aidl.navdrawer.NavDrawerItem> items) {
boolean setNavDrawerItems(String appPackage, List<OsmAndAppCustomization.NavDrawerItem> 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<String> ids) {
@ -1930,26 +1929,27 @@ 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<Long, IRoutingDataUpdateListener> 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() {
if (aidlCallbackListener != null) {
ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false);
RoutingHelper rh = app.getRoutingHelper();
if (rh.isDeviatedFromRoute()) {
directionInfo.setTurnType(TurnType.OFFR);
@ -1961,7 +1961,6 @@ public class OsmandAidlApi {
directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue());
}
}
if (aidlCallbackListener != null) {
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<String, ContextMenuButtonsParams> getContextMenuButtonsParams() {
public Map<String, AidlContextMenuButtonsWrapper> 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);
@ -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<ConnectedApp> {
static final String PACK_KEY = "pack";
@ -2332,11 +2374,11 @@ public class OsmandAidlApi {
}
public interface SearchCompleteCallback {
void onSearchComplete(List<SearchResult> resultSet);
void onSearchComplete(List<AidlSearchResultWrapper> 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);
}
}

View file

@ -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<ASelectedGpxFile> 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<AGpxFile> 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<SearchResult> resultSet) {
Bundle data = new Bundle();
if (resultSet.size() > 0) {
data.putParcelableArrayList(DATA_KEY_RESULT_SET, new ArrayList<>(resultSet));
}
public void onSearchComplete(List<AidlSearchResultWrapper> resultSet) {
try {
callback.onSearchComplete(resultSet);
List<SearchResult> 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<SetWidgetsParams> visibilityWidgetsParams = params.getVisibilityWidgetsParams();
ArrayList<SetWidgetsParams> availabilityWidgetsParams = params.getAvailabilityWidgetsParams();
regWidgetsVisibility(api, visibilityWidgetsParams);
regWidgetsAvailability(api, availabilityWidgetsParams);
ArrayList<PluginParams> pluginsParams = params.getPluginsParams();
if (pluginsParams != null) {
changePluginsStatus(api, pluginsParams);
}
List<String> enabledIds = params.getFeaturesEnabledIds();
List<String> disabledIds = params.getFeaturesDisabledIds();
api.setEnabledIds(enabledIds);
api.setDisabledIds(disabledIds);
List<String> enabledPatterns = params.getFeaturesEnabledPatterns();
List<String> 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<SetWidgetsParams> visibilityWidgetsParams) {
for (SetWidgetsParams setWidgetsParams : visibilityWidgetsParams) {
api.regWidgetVisibility(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys());
}
}
private void regWidgetsAvailability(OsmandAidlApi api, ArrayList<SetWidgetsParams> availabilityWidgetsParams) {
for (SetWidgetsParams setWidgetsParams : availabilityWidgetsParams) {
api.regWidgetAvailability(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys());
}
}
public void changePluginsStatus(OsmandAidlApi api, List<PluginParams> pluginsParams) {
for (PluginParams pluginParams : pluginsParams) {
api.changePluginState(pluginParams.getPluginId(), pluginParams.getNewState());
}
}
private List<OsmAndAppCustomization.NavDrawerItem> convertNavDrawerItems(List<NavDrawerItem> drawerItems) {
List<OsmAndAppCustomization.NavDrawerItem> 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;

File diff suppressed because it is too large Load diff

View file

@ -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<String> navDrawerParams;
private NavDrawerFooterParams navDrawerFooterParams;
private String navDrawerFooterIntent;
private String navDrawerFooterAppName;
private String navDrawerFooterPackageName;
private Set<String> featuresEnabledIds = new HashSet<>();
private Set<String> 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<String> ids) {
@ -300,89 +298,6 @@ public class OsmAndAppCustomization {
return set;
}
public void regWidgetsVisibility(@NonNull ArrayList<SetWidgetsParams> visibilityWidgetsParams) {
for (SetWidgetsParams setWidgetsParams : visibilityWidgetsParams) {
regWidgetVisibility(setWidgetsParams.getWidgetKey(), setWidgetsParams.getAppModesKeys());
}
}
public void regWidgetsAvailability(@NonNull ArrayList<SetWidgetsParams> 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<SetWidgetsParams> visibilityWidgetsParams = params.getVisibilityWidgetsParams();
ArrayList<SetWidgetsParams> availabilityWidgetsParams = params.getAvailabilityWidgetsParams();
setWidgetsParams(visibilityWidgetsParams, availabilityWidgetsParams);
ArrayList<PluginParams> pluginsParams = params.getPluginsParams();
if (pluginsParams != null) {
changePluginsStatus(pluginsParams);
}
List<String> enabledIds = params.getFeaturesEnabledIds();
List<String> disabledIds = params.getFeaturesDisabledIds();
setFeaturesIds(enabledIds, disabledIds);
List<String> enabledPatterns = params.getFeaturesEnabledPatterns();
List<String> 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<SetWidgetsParams> visibilityWidgetsParams, ArrayList<SetWidgetsParams> availabilityWidgetsParams) {
if (visibilityWidgetsParams != null) {
regWidgetsVisibility(visibilityWidgetsParams);
}
if (availabilityWidgetsParams != null) {
regWidgetsAvailability(availabilityWidgetsParams);
}
}
public void setFeaturesIds(List<String> enabledIds, List<String> disabledIds) {
if (enabledIds != null) {
setFeaturesEnabledIds(enabledIds);
}
if (disabledIds != null) {
setFeaturesDisabledIds(disabledIds);
}
}
public void setFeaturesPatterns(List<String> enabledPatterns, List<String> disabledPatterns) {
if (enabledPatterns != null) {
setFeaturesEnabledPatterns(enabledPatterns);
}
if (disabledPatterns != null) {
setFeaturesDisabledPatterns(disabledPatterns);
}
}
public boolean isWidgetVisible(@NonNull String key, ApplicationMode appMode) {
Set<ApplicationMode> set = widgetsVisibilityMap.get(key);
if (set == null) {
@ -404,25 +319,19 @@ public class OsmAndAppCustomization {
return setNavDrawerLogo(imageUri, packageName, intent);
}
public void changePluginsStatus(List<PluginParams> 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<net.osmand.aidl.navdrawer.NavDrawerItem> items) {
public boolean setNavDrawerItems(String appPackage, List<NavDrawerItem> items) {
if (!TextUtils.isEmpty(appPackage) && items != null) {
clearNavDrawerItems(appPackage);
if (items.isEmpty()) {
@ -441,11 +350,9 @@ public class OsmAndAppCustomization {
List<NavDrawerItem> 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;

View file

@ -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());
}

View file

@ -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();
}

View file

@ -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<SearchResult> resultSet) {
public void onSearchComplete(final List<AidlSearchResultWrapper> 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<SearchResult> resultSet = new ArrayList<>();
List<AidlSearchResultWrapper> 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++;

View file

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

View file

@ -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<String, ContextMenuButtonsParams> buttonsParamsMap = app.getAidlApi().getContextMenuButtonsParams();
Map<String, AidlContextMenuButtonsWrapper> buttonsParamsMap = app.getAidlApi().getContextMenuButtonsParams();
if (!buttonsParamsMap.isEmpty()) {
additionalButtonsControllers = new ArrayList<>();
for (ContextMenuButtonsParams buttonsParams : buttonsParamsMap.values()) {
for (AidlContextMenuButtonsWrapper buttonsParams : buttonsParamsMap.values()) {
List<String> 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;

View file

@ -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<AMapPoint> {
public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider, MapTextLayer.MapTextProvider<AidlMapPointWrapper> {
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<String, Bitmap> pointImages = new ConcurrentHashMap<>();
private Set<String> imageRequests = new HashSet<>();
private List<AMapPoint> displayedPoints = new ArrayList<>();
private List<AidlMapPointWrapper> 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<? super AMapPoint> points) {
private void getFromPoint(RotatedTileBox tb, PointF point, List<? super AidlMapPointWrapper> 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());

View file

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