diff --git a/OsmAnd/src/net/osmand/aidl/ALatLon.aidl b/OsmAnd/src/net/osmand/aidl/ALatLon.aidl deleted file mode 100644 index ed8bd49956..0000000000 --- a/OsmAnd/src/net/osmand/aidl/ALatLon.aidl +++ /dev/null @@ -1,3 +0,0 @@ -package net.osmand.aidl; - -parcelable ALatLon; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 25b1a5219b..b03eb12fc3 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -1,12 +1,20 @@ package net.osmand.aidl; -import net.osmand.aidl.ALatLon; +import net.osmand.aidl.map.ALatLon; +import net.osmand.aidl.map.SetMapLocationParams; + import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapmarker.AddMapMarkerParams; import net.osmand.aidl.mapmarker.RemoveMapMarkerParams; import net.osmand.aidl.mapmarker.UpdateMapMarkerParams; + import net.osmand.aidl.calculateroute.CalculateRouteParams; +import net.osmand.aidl.gpx.ImportGpxParams; +import net.osmand.aidl.gpx.ShowGpxParams; +import net.osmand.aidl.gpx.HideGpxParams; +import net.osmand.aidl.gpx.ASelectedGpxFile; + import net.osmand.aidl.mapwidget.AMapWidget; import net.osmand.aidl.mapwidget.AddMapWidgetParams; import net.osmand.aidl.mapwidget.RemoveMapWidgetParams; @@ -39,5 +47,11 @@ interface IOsmAndAidlInterface { boolean removeMapLayer(in RemoveMapLayerParams params); boolean updateMapLayer(in UpdateMapLayerParams params); + boolean importGpx(in ImportGpxParams params); + boolean showGpx(in ShowGpxParams params); + boolean hideGpx(in HideGpxParams params); + boolean getActiveGpx(out List files); + + boolean setMapLocation(in SetMapLocationParams params); boolean calculateRoute(in CalculateRouteParams params); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 9066281919..37b42efe43 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -4,14 +4,21 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.net.Uri; +import android.os.ParcelFileDescriptor; import android.view.View; +import net.osmand.IndexConstants; +import net.osmand.aidl.gpx.ASelectedGpxFile; 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.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.plus.GPXUtilities; +import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; @@ -20,10 +27,18 @@ import net.osmand.plus.views.AidlMapLayer; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; +import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.util.Algorithms; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -31,6 +46,12 @@ import java.util.concurrent.ConcurrentHashMap; public class OsmandAidlApi { private static final String AIDL_REFRESH_MAP = "aidl_refresh_map"; + private static final String AIDL_SET_MAP_LOCATION = "aidl_set_map_location"; + private static final String AIDL_LATITUDE = "aidl_latitude"; + private static final String AIDL_LONGITUDE = "aidl_longitude"; + private static final String AIDL_ZOOM = "aidl_zoom"; + private static final String AIDL_ANIMATED = "aidl_animated"; + private static final String AIDL_OBJECT_ID = "aidl_object_id"; private static final String AIDL_ADD_MAP_WIDGET = "aidl_add_map_widget"; @@ -46,6 +67,7 @@ public class OsmandAidlApi { private Map mapLayers = new ConcurrentHashMap<>(); private BroadcastReceiver refreshMapReceiver; + private BroadcastReceiver setMapLocationReceiver; private BroadcastReceiver addMapWidgetReceiver; private BroadcastReceiver removeMapWidgetReceiver; private BroadcastReceiver addMapLayerReceiver; @@ -57,6 +79,7 @@ public class OsmandAidlApi { public void onCreateMapActivity(final MapActivity mapActivity) { registerRefreshMapReceiver(mapActivity); + registerSetMapLocationReceiver(mapActivity); registerAddMapWidgetReceiver(mapActivity); registerRemoveMapWidgetReceiver(mapActivity); registerAddMapLayerReceiver(mapActivity); @@ -67,6 +90,9 @@ public class OsmandAidlApi { if (refreshMapReceiver != null) { mapActivity.unregisterReceiver(refreshMapReceiver); } + if (setMapLocationReceiver != null) { + mapActivity.unregisterReceiver(setMapLocationReceiver); + } if (addMapWidgetReceiver != null) { mapActivity.unregisterReceiver(addMapWidgetReceiver); @@ -94,6 +120,35 @@ public class OsmandAidlApi { mapActivity.registerReceiver(refreshMapReceiver, new IntentFilter(AIDL_REFRESH_MAP)); } + private void registerSetMapLocationReceiver(final MapActivity mapActivity) { + setMapLocationReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN); + double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN); + int zoom = intent.getIntExtra(AIDL_ZOOM, 0); + boolean animated = intent.getBooleanExtra(AIDL_ANIMATED, false); + if (!Double.isNaN(lat) && !Double.isNaN(lon)) { + OsmandMapTileView mapView = mapActivity.getMapView(); + if (zoom == 0) { + zoom = mapView.getZoom(); + } else { + zoom = zoom > mapView.getMaxZoom() ? mapView.getMaxZoom() : zoom; + zoom = zoom < mapView.getMinZoom() ? mapView.getMinZoom() : zoom; + } + if (animated) { + mapView.getAnimatedDraggingThread().startMoving(lat, lon, zoom, true); + } else { + mapView.setLatLon(lat, lon); + mapView.setIntZoom(zoom); + } + } + mapActivity.refreshMap(); + } + }; + mapActivity.registerReceiver(setMapLocationReceiver, new IntentFilter(AIDL_SET_MAP_LOCATION)); + } + private int getDrawableId(String id) { if (Algorithms.isEmpty(id)) { return 0; @@ -418,4 +473,135 @@ public class OsmandAidlApi { } return false; } + + boolean importGpxFromFile(File source, String destinationPath) { + if (source != null && !Algorithms.isEmpty(destinationPath)) { + if (source.exists() && source.canRead()) { + File destination = app.getAppPath(IndexConstants.GPX_INDEX_DIR + destinationPath); + if (destination.getParentFile().canWrite()) { + try { + Algorithms.fileCopy(source, destination); + return true; + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + return false; + } + + boolean importGpxFromUri(Uri gpxUri, String destinationPath) { + if (gpxUri != null && !Algorithms.isEmpty(destinationPath)) { + File destination = app.getAppPath(IndexConstants.GPX_INDEX_DIR + destinationPath); + ParcelFileDescriptor gpxParcelDescriptor = null; + try { + gpxParcelDescriptor = app.getContentResolver().openFileDescriptor(gpxUri, "r"); + if (gpxParcelDescriptor != null) { + FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor(); + InputStream is = new FileInputStream(fileDescriptor); + FileOutputStream fout = new FileOutputStream(destination); + try { + Algorithms.streamCopy(is, fout); + } finally { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + fout.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return true; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return false; + } + + boolean importGpxFromData(String sourceRawData, String destinationPath) { + if (!Algorithms.isEmpty(sourceRawData) && !Algorithms.isEmpty(destinationPath)) { + File destination = app.getAppPath(IndexConstants.GPX_INDEX_DIR + destinationPath); + try { + InputStream is = new ByteArrayInputStream(sourceRawData.getBytes()); + FileOutputStream fout = new FileOutputStream(destination); + try { + Algorithms.streamCopy(is, fout); + } finally { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + fout.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return true; + } catch (IOException e) { + e.printStackTrace(); + } + } + return false; + } + + boolean showGpx(String fileName) { + if (!Algorithms.isEmpty(fileName)) { + File f = app.getAppPath(IndexConstants.GPX_INDEX_DIR + fileName); + if (f.exists()) { + GPXFile gpx = GPXUtilities.loadGPXFile(app, f); + app.getSelectedGpxHelper().selectGpxFile(gpx, true, false); + refreshMap(); + return true; + } + } + return false; + } + + boolean hideGpx(String fileName) { + if (!Algorithms.isEmpty(fileName)) { + SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByName(fileName); + if (selectedGpxFile != null) { + app.getSelectedGpxHelper().selectGpxFile(selectedGpxFile.getGpxFile(), false, false); + refreshMap(); + } + } + return false; + } + + boolean getActiveGpx(List files) { + if (files != null) { + List selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles(); + String gpxPath = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath(); + for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) { + String path = selectedGpxFile.getGpxFile().path; + if (!Algorithms.isEmpty(path)) { + if (path.startsWith(gpxPath)) { + path = path.substring(gpxPath.length() + 1); + } + files.add(new ASelectedGpxFile(path)); + } + } + return true; + } + return false; + } + + boolean setMapLocation(double latitude, double longitude, int zoom, boolean animated) { + Intent intent = new Intent(); + intent.setAction(AIDL_SET_MAP_LOCATION); + intent.putExtra(AIDL_LATITUDE, latitude); + intent.putExtra(AIDL_LONGITUDE, longitude); + intent.putExtra(AIDL_ZOOM, zoom); + intent.putExtra(AIDL_ANIMATED, animated); + app.sendBroadcast(intent); + return true; + } } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 9dceef778e..5e7d106be3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -2,10 +2,17 @@ package net.osmand.aidl; import android.app.Service; import android.content.Intent; +import android.net.Uri; +import android.os.Build; import android.os.IBinder; import android.os.RemoteException; import net.osmand.aidl.calculateroute.CalculateRouteParams; +import net.osmand.aidl.gpx.ASelectedGpxFile; +import net.osmand.aidl.gpx.HideGpxParams; +import net.osmand.aidl.gpx.ImportGpxParams; +import net.osmand.aidl.gpx.ShowGpxParams; +import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.maplayer.AddMapLayerParams; import net.osmand.aidl.maplayer.RemoveMapLayerParams; import net.osmand.aidl.maplayer.UpdateMapLayerParams; @@ -19,6 +26,9 @@ import net.osmand.aidl.mapwidget.AddMapWidgetParams; import net.osmand.aidl.mapwidget.RemoveMapWidgetParams; import net.osmand.aidl.mapwidget.UpdateMapWidgetParams; import net.osmand.plus.OsmandApplication; +import net.osmand.util.Algorithms; + +import java.util.List; public class OsmandAidlService extends Service { @@ -146,6 +156,50 @@ public class OsmandAidlService extends Service { } } + @Override + public boolean importGpx(ImportGpxParams params) throws RemoteException { + if (params != null && !Algorithms.isEmpty(params.getDestinationPath())) { + if (params.getGpxFile() != null) { + return getApi().importGpxFromFile(params.getGpxFile(), params.getDestinationPath()); + } else if (params.getGpxUri() != null) { + return getApi().importGpxFromUri(params.getGpxUri(), params.getDestinationPath()); + } else if (params.getSourceRawData() != null) { + return getApi().importGpxFromData(params.getSourceRawData(), params.getDestinationPath()); + } + } + return false; + } + + @Override + public boolean showGpx(ShowGpxParams params) throws RemoteException { + if (params != null && params.getFileName() != null) { + return getApi().showGpx(params.getFileName()); + } + return false; + } + + @Override + public boolean hideGpx(HideGpxParams params) throws RemoteException { + if (params != null && params.getFileName() != null) { + return getApi().hideGpx(params.getFileName()); + } + return false; + } + + @Override + public boolean getActiveGpx(List files) throws RemoteException { + return getApi().getActiveGpx(files); + } + + @Override + public boolean setMapLocation(SetMapLocationParams params) throws RemoteException { + if (params != null) { + return getApi().setMapLocation(params.getLatitude(), params.getLongitude(), + params.getZoom(), params.isAnimated()); + } + return false; + } + @Override public boolean calculateRoute(CalculateRouteParams params) throws RemoteException { if (params == null || params.getEndPoint() == null) { diff --git a/OsmAnd/src/net/osmand/aidl/calculateroute/CalculateRouteParams.java b/OsmAnd/src/net/osmand/aidl/calculateroute/CalculateRouteParams.java index c22a0c6d37..3cc660ec8a 100644 --- a/OsmAnd/src/net/osmand/aidl/calculateroute/CalculateRouteParams.java +++ b/OsmAnd/src/net/osmand/aidl/calculateroute/CalculateRouteParams.java @@ -3,7 +3,7 @@ package net.osmand.aidl.calculateroute; import android.os.Parcel; import android.os.Parcelable; -import net.osmand.aidl.ALatLon; +import net.osmand.aidl.map.ALatLon; import java.util.ArrayList; import java.util.List; diff --git a/OsmAnd/src/net/osmand/aidl/gpx/ASelectedGpxFile.aidl b/OsmAnd/src/net/osmand/aidl/gpx/ASelectedGpxFile.aidl new file mode 100644 index 0000000000..23fc3312b4 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/ASelectedGpxFile.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.gpx; + +parcelable ASelectedGpxFile; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/gpx/ASelectedGpxFile.java b/OsmAnd/src/net/osmand/aidl/gpx/ASelectedGpxFile.java new file mode 100644 index 0000000000..54d51bf882 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/ASelectedGpxFile.java @@ -0,0 +1,45 @@ +package net.osmand.aidl.gpx; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ASelectedGpxFile implements Parcelable { + + private String fileName; + + public ASelectedGpxFile(String fileName) { + this.fileName = fileName; + } + + public ASelectedGpxFile(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public ASelectedGpxFile createFromParcel(Parcel in) { + return new ASelectedGpxFile(in); + } + + public ASelectedGpxFile[] newArray(int size) { + return new ASelectedGpxFile[size]; + } + }; + + public String getFileName() { + return fileName; + } + + public void writeToParcel(Parcel out, int flags) { + out.writeString(fileName); + } + + private void readFromParcel(Parcel in) { + fileName = in.readString(); + } + + public int describeContents() { + return 0; + } +} + diff --git a/OsmAnd/src/net/osmand/aidl/gpx/HideGpxParams.aidl b/OsmAnd/src/net/osmand/aidl/gpx/HideGpxParams.aidl new file mode 100644 index 0000000000..4c8992552c --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/HideGpxParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.gpx; + +parcelable HideGpxParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/gpx/HideGpxParams.java b/OsmAnd/src/net/osmand/aidl/gpx/HideGpxParams.java new file mode 100644 index 0000000000..5e37c66f80 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/HideGpxParams.java @@ -0,0 +1,45 @@ +package net.osmand.aidl.gpx; + +import android.os.Parcel; +import android.os.Parcelable; + +public class HideGpxParams implements Parcelable { + + private String fileName; + + public HideGpxParams(String fileName) { + this.fileName = fileName; + } + + public HideGpxParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public HideGpxParams createFromParcel(Parcel in) { + return new HideGpxParams(in); + } + + public HideGpxParams[] newArray(int size) { + return new HideGpxParams[size]; + } + }; + + public String getFileName() { + return fileName; + } + + public void writeToParcel(Parcel out, int flags) { + out.writeString(fileName); + } + + private void readFromParcel(Parcel in) { + fileName = in.readString(); + } + + public int describeContents() { + return 0; + } +} + diff --git a/OsmAnd/src/net/osmand/aidl/gpx/ImportGpxParams.aidl b/OsmAnd/src/net/osmand/aidl/gpx/ImportGpxParams.aidl new file mode 100644 index 0000000000..23ecdb6ff3 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/ImportGpxParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.gpx; + +parcelable ImportGpxParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/gpx/ImportGpxParams.java b/OsmAnd/src/net/osmand/aidl/gpx/ImportGpxParams.java new file mode 100644 index 0000000000..4776cf8503 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/ImportGpxParams.java @@ -0,0 +1,86 @@ +package net.osmand.aidl.gpx; + +import android.net.Uri; +import android.os.Parcel; +import android.os.Parcelable; + +import java.io.File; + +public class ImportGpxParams implements Parcelable { + + private File gpxFile; + private Uri gpxUri; + private String sourceRawData; + private String destinationPath; + + public ImportGpxParams(File gpxFile, String destinationPath) { + this.gpxFile = gpxFile; + this.destinationPath = destinationPath; + } + + public ImportGpxParams(Uri gpxUri, String destinationPath) { + this.gpxUri = gpxUri; + this.destinationPath = destinationPath; + } + + public ImportGpxParams(String sourceRawData, String destinationPath) { + this.sourceRawData = sourceRawData; + this.destinationPath = destinationPath; + } + + public ImportGpxParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public ImportGpxParams createFromParcel(Parcel in) { + return new ImportGpxParams(in); + } + + public ImportGpxParams[] newArray(int size) { + return new ImportGpxParams[size]; + } + }; + + public File getGpxFile() { + return gpxFile; + } + + public Uri getGpxUri() { + return gpxUri; + } + + public String getSourceRawData() { + return sourceRawData; + } + + public String getDestinationPath() { + return destinationPath; + } + + public void writeToParcel(Parcel out, int flags) { + if (gpxFile != null) { + out.writeString(gpxFile.getAbsolutePath()); + } else { + out.writeString(null); + } + out.writeParcelable(gpxUri, flags); + out.writeString(sourceRawData); + out.writeString(destinationPath); + } + + private void readFromParcel(Parcel in) { + String gpxAbsolutePath = in.readString(); + if (gpxAbsolutePath != null) { + gpxFile = new File(gpxAbsolutePath); + } + gpxUri = in.readParcelable(Uri.class.getClassLoader()); + sourceRawData = in.readString(); + destinationPath = in.readString(); + } + + public int describeContents() { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/gpx/ShowGpxParams.aidl b/OsmAnd/src/net/osmand/aidl/gpx/ShowGpxParams.aidl new file mode 100644 index 0000000000..217f600c4e --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/ShowGpxParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.gpx; + +parcelable ShowGpxParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/gpx/ShowGpxParams.java b/OsmAnd/src/net/osmand/aidl/gpx/ShowGpxParams.java new file mode 100644 index 0000000000..4d385a65a4 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/ShowGpxParams.java @@ -0,0 +1,44 @@ +package net.osmand.aidl.gpx; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ShowGpxParams implements Parcelable { + + private String fileName; + + public ShowGpxParams(String fileName) { + this.fileName = fileName; + } + + public ShowGpxParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public ShowGpxParams createFromParcel(Parcel in) { + return new ShowGpxParams(in); + } + + public ShowGpxParams[] newArray(int size) { + return new ShowGpxParams[size]; + } + }; + + public String getFileName() { + return fileName; + } + + public void writeToParcel(Parcel out, int flags) { + out.writeString(fileName); + } + + private void readFromParcel(Parcel in) { + fileName = in.readString(); + } + + public int describeContents() { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/map/ALatLon.aidl b/OsmAnd/src/net/osmand/aidl/map/ALatLon.aidl new file mode 100644 index 0000000000..33d5930f02 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/ALatLon.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.map; + +parcelable ALatLon; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/ALatLon.java b/OsmAnd/src/net/osmand/aidl/map/ALatLon.java similarity index 98% rename from OsmAnd/src/net/osmand/aidl/ALatLon.java rename to OsmAnd/src/net/osmand/aidl/map/ALatLon.java index fe3f0b48bc..377344fd6a 100644 --- a/OsmAnd/src/net/osmand/aidl/ALatLon.java +++ b/OsmAnd/src/net/osmand/aidl/map/ALatLon.java @@ -1,4 +1,4 @@ -package net.osmand.aidl; +package net.osmand.aidl.map; import android.os.Parcel; import android.os.Parcelable; diff --git a/OsmAnd/src/net/osmand/aidl/map/SetMapLocationParams.aidl b/OsmAnd/src/net/osmand/aidl/map/SetMapLocationParams.aidl new file mode 100644 index 0000000000..9edde4f616 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/SetMapLocationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.map; + +parcelable SetMapLocationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/map/SetMapLocationParams.java b/OsmAnd/src/net/osmand/aidl/map/SetMapLocationParams.java new file mode 100644 index 0000000000..929c817d9d --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/SetMapLocationParams.java @@ -0,0 +1,68 @@ +package net.osmand.aidl.map; + +import android.os.Parcel; +import android.os.Parcelable; + +public class SetMapLocationParams implements Parcelable { + + private double latitude; + private double longitude; + private int zoom; + private boolean animated; + + public SetMapLocationParams(double latitude, double longitude, int zoom, boolean animated) { + this.latitude = latitude; + this.longitude = longitude; + this.zoom = zoom; + this.animated = animated; + } + + public SetMapLocationParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public SetMapLocationParams createFromParcel(Parcel in) { + return new SetMapLocationParams(in); + } + + public SetMapLocationParams[] newArray(int size) { + return new SetMapLocationParams[size]; + } + }; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + public int getZoom() { + return zoom; + } + + public boolean isAnimated() { + return animated; + } + + public void writeToParcel(Parcel out, int flags) { + out.writeDouble(latitude); + out.writeDouble(longitude); + out.writeInt(zoom); + out.writeByte((byte) (animated ? 1 : 0)); + } + + private void readFromParcel(Parcel in) { + latitude = in.readDouble(); + longitude = in.readDouble(); + zoom = in.readInt(); + animated = in.readByte() != 0; + } + + public int describeContents() { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java b/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java index 1c731b653a..1d0d2e01e8 100644 --- a/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java +++ b/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java @@ -3,21 +3,31 @@ package net.osmand.aidl.maplayer.point; import android.os.Parcel; import android.os.Parcelable; -import net.osmand.aidl.ALatLon; +import net.osmand.aidl.map.ALatLon; + +import java.util.ArrayList; +import java.util.List; public class AMapPoint implements Parcelable { private String id; private String shortName; private String fullName; + private String typeName; private int color; private ALatLon location; + private List details = new ArrayList<>(); - public AMapPoint(String id, String shortName, String fullName, int color, ALatLon location) { + public AMapPoint(String id, String shortName, String fullName, String typeName, int color, + ALatLon location, List details) { this.id = id; this.shortName = shortName; this.fullName = fullName; + this.typeName = typeName; this.color = color; this.location = location; + if (details != null) { + this.details.addAll(details); + } } public AMapPoint(Parcel in) { @@ -47,6 +57,10 @@ public class AMapPoint implements Parcelable { return fullName; } + public String getTypeName() { + return typeName; + } + public int getColor() { return color; } @@ -55,20 +69,28 @@ public class AMapPoint implements Parcelable { return location; } + public List getDetails() { + return details; + } + public void writeToParcel(Parcel out, int flags) { out.writeString(id); out.writeString(shortName); out.writeString(fullName); + out.writeString(typeName); out.writeInt(color); out.writeParcelable(location, flags); + out.writeStringList(details); } private void readFromParcel(Parcel in) { id = in.readString(); shortName = in.readString(); fullName = in.readString(); + typeName = in.readString(); color = in.readInt(); location = in.readParcelable(ALatLon.class.getClassLoader()); + in.readStringList(details); } public int describeContents() { diff --git a/OsmAnd/src/net/osmand/aidl/mapmarker/AMapMarker.java b/OsmAnd/src/net/osmand/aidl/mapmarker/AMapMarker.java index dc6084e680..083b5bbb37 100644 --- a/OsmAnd/src/net/osmand/aidl/mapmarker/AMapMarker.java +++ b/OsmAnd/src/net/osmand/aidl/mapmarker/AMapMarker.java @@ -3,7 +3,7 @@ package net.osmand.aidl.mapmarker; import android.os.Parcel; import android.os.Parcelable; -import net.osmand.aidl.ALatLon; +import net.osmand.aidl.map.ALatLon; public class AMapMarker implements Parcelable { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index dd580971cb..4a034ffda6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -8,6 +8,7 @@ import android.widget.LinearLayout; import net.osmand.IndexConstants; import net.osmand.NativeLibrary.RenderedObject; +import net.osmand.aidl.maplayer.point.AMapPoint; import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.RouteDataObject; @@ -33,6 +34,7 @@ import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.SearchHistoryHelper; +import net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController; import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController; import net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController; import net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController; @@ -150,6 +152,8 @@ public abstract class MenuController extends BaseMenuController { 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 LatLon) { if (pointDescription.isParking()) { menuController = new ParkingPositionMenuController(mapActivity, pointDescription); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java new file mode 100644 index 0000000000..4821d345d9 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java @@ -0,0 +1,83 @@ +package net.osmand.plus.mapcontextmenu.controllers; + +import android.graphics.drawable.Drawable; +import android.view.View; + +import net.osmand.aidl.maplayer.point.AMapPoint; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MapContextMenu; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.views.TransportStopsLayer; +import net.osmand.util.Algorithms; + +public class AMapPointMenuController extends MenuController { + + private AMapPoint point; + + public AMapPointMenuController(MapActivity mapActivity, PointDescription pointDescription, final AMapPoint point) { + super(new MenuBuilder(mapActivity), pointDescription, mapActivity); + this.point = point; + } + + @Override + protected void setObject(Object object) { + if (object instanceof AMapPoint) { + this.point = (AMapPoint) object; + } + } + + @Override + protected Object getObject() { + return point; + } + + @Override + public boolean displayDistanceDirection() { + return true; + } + + @Override + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) { + for (String detail : point.getDetails()) { + builder.addPlainMenuItem(R.drawable.ic_action_info_dark, detail, true, false, null); + } + super.addPlainMenuItems(typeStr, pointDescription, latLon); + } + + @Override + public Drawable getLeftIcon() { + return getIcon(R.drawable.ic_action_get_my_location); + } + + @Override + public Drawable getSecondLineTypeIcon() { + if (!Algorithms.isEmpty(point.getShortName())) { + return getIcon(R.drawable.ic_small_group); + } else { + return null; + } + } + + @Override + public String getTypeStr() { + if (!Algorithms.isEmpty(point.getTypeName())) { + return point.getTypeName(); + } else { + return ""; + } + } + + @Override + public String getCommonTypeStr() { + return getMapActivity().getString(R.string.shared_string_location); + } + + @Override + public boolean needStreetName() { + return false; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java index 3135098c02..e6a7a562e0 100644 --- a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java @@ -4,19 +4,23 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.PointF; import android.util.DisplayMetrics; import android.view.WindowManager; -import net.osmand.aidl.ALatLon; +import net.osmand.aidl.map.ALatLon; import net.osmand.aidl.maplayer.AMapLayer; import net.osmand.aidl.maplayer.point.AMapPoint; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import java.util.List; -public class AidlMapLayer extends OsmandMapLayer { +public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider { private static int POINT_OUTER_COLOR = 0x88555555; private static int PAINT_TEXT_ICON_COLOR = Color.BLACK; @@ -108,4 +112,65 @@ public class AidlMapLayer extends OsmandMapLayer { view.refreshMap(); } } + + @Override + public boolean disableSingleTap() { + return false; + } + + @Override + public boolean disableLongPressOnMap() { + return false; + } + + @Override + public boolean isObjectClickable(Object o) { + return o instanceof AMapPoint; + } + + @Override + public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { + getFromPoint(tileBox, point, o); + } + + @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()); + } + } + return null; + } + + @Override + public PointDescription getObjectName(Object o) { + if (o instanceof AMapPoint) { + return new PointDescription(PointDescription.POINT_TYPE_MARKER, ((AMapPoint) o).getFullName()); + } else { + return null; + } + } + + private void getFromPoint(RotatedTileBox tb, PointF point, List points) { + if (view != null) { + int ex = (int) point.x; + int ey = (int) point.y; + final int rp = getRadiusPoi(tb); + int compare = rp; + int radius = rp * 3 / 2; + for (AMapPoint p : aidlLayer.getPoints()) { + ALatLon position = p.getLocation(); + if (position != null) { + int x = (int) tb.getPixXFromLatLon(position.getLatitude(), position.getLongitude()); + int y = (int) tb.getPixYFromLatLon(position.getLatitude(), position.getLongitude()); + if (Math.abs(x - ex) <= compare && Math.abs(y - ey) <= compare) { + compare = radius; + points.add(p); + } + } + } + } + } }