pr changes - removed static method, add callback to aidl service, fixed concurrency issue to RouteHelper, add types to params in javadoc

This commit is contained in:
madwasp79 2019-04-17 10:36:16 +03:00
parent f7f6dec1b3
commit b1e236bdad
5 changed files with 279 additions and 220 deletions

View file

@ -0,0 +1,9 @@
package net.osmand.aidl;
import java.util.Map;
public interface AidlCallbackListener{
void addAidlCallback(IOsmAndAidlCallback callback, int key);
boolean removeAidlCallback(long id);
Map<Long, OsmandAidlService.AidlCallbackParams> getAidlCallbacks();
}

View file

@ -91,30 +91,30 @@ interface IOsmAndAidlInterface {
/** /**
* Add map marker at given location. * Add map marker at given location.
* *
* @param lat - latitude. * @param lat (double) - latitude.
* @param lon - longitude. * @param lon (double) - longitude.
* @param name - name. * @param name (String)- name of marker.
*/ */
boolean addMapMarker(in AddMapMarkerParams params); boolean addMapMarker(in AddMapMarkerParams params);
/** /**
* Remove map marker at given location with name. * Add map marker at given location.
* *
* @param lat - latitude. * @param lat (double) - latitude.
* @param lon - longitude. * @param lon (double) - longitude.
* @param name - name. * @param name (String)- name of marker.
*/ */
boolean removeMapMarker(in RemoveMapMarkerParams params); boolean removeMapMarker(in RemoveMapMarkerParams params);
/** /**
* Update map marker at given location with name. * Update map marker at given location with name.
* *
* @param latPrev - latitude (current marker). * @param latPrev (double) - latitude (current marker).
* @param lonPrev - longitude (current marker). * @param lonPrev (double) - longitude (current marker).
* @param namePrev - name (current marker). * @param namePrev (String) - name (current marker).
* @param latNew - latitude (new marker). * @param latNew (double) - latitude (new marker).
* @param lonNew - longitude (new marker). * @param lonNew (double) - longitude (new marker).
* @param nameNew - name (new marker). * @param nameNew (String) - name (new marker).
*/ */
boolean updateMapMarker(in UpdateMapMarkerParams params); boolean updateMapMarker(in UpdateMapMarkerParams params);
@ -122,22 +122,22 @@ interface IOsmAndAidlInterface {
* Add map widget to the right side of the main screen. * Add map widget to the right side of the main screen.
* Note: any specified icon should exist in OsmAnd app resources. * Note: any specified icon should exist in OsmAnd app resources.
* *
* @param id - widget id. * @param id (String) - widget id.
* @param menuIconName - icon name (configure map menu). * @param menuIconName (String) - icon name (configure map menu).
* @param menuTitle - widget name (configure map menu). * @param menuTitle (String) - widget name (configure map menu).
* @param lightIconName - icon name for the light theme (widget). * @param lightIconName (String) - icon name for the light theme (widget).
* @param darkIconName - icon name for the dark theme (widget). * @param darkIconName (String) - icon name for the dark theme (widget).
* @param text - main widget text. * @param text (String) - main widget text.
* @param description - sub text, like "km/h". * @param description (String) - sub text, like "km/h".
* @param order - order position in the widgets list. * @param order (int) - order position in the widgets list.
* @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent). * @param intentOnClick (String) - onClick intent. Called after click on widget as startActivity(Intent intent).
*/ */
boolean addMapWidget(in AddMapWidgetParams params); boolean addMapWidget(in AddMapWidgetParams params);
/** /**
* Remove map widget. * Remove map widget.
* *
* @param id - widget id. * @param (String) id - widget id.
*/ */
boolean removeMapWidget(in RemoveMapWidgetParams params); boolean removeMapWidget(in RemoveMapWidgetParams params);
@ -145,30 +145,30 @@ interface IOsmAndAidlInterface {
* Update map widget. * Update map widget.
* Note: any specified icon should exist in OsmAnd app resources. * Note: any specified icon should exist in OsmAnd app resources.
* *
* @param id - widget id. * @param id (String) - widget id.
* @param menuIconName - icon name (configure map menu). * @param menuIconName (String) - icon name (configure map menu).
* @param menuTitle - widget name (configure map menu). * @param menuTitle (String) - widget name (configure map menu).
* @param lightIconName - icon name for the light theme (widget). * @param lightIconName (String) - icon name for the light theme (widget).
* @param darkIconName - icon name for the dark theme (widget). * @param darkIconName (String) - icon name for the dark theme (widget).
* @param text - main widget text. * @param text (String) - main widget text.
* @param description - sub text, like "km/h". * @param description (String) - sub text, like "km/h".
* @param order - order position in the widgets list. * @param order (int) - order position in the widgets list.
* @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent). * @param intentOnClick (String) - onClick intent. Called after click on widget as startActivity(Intent intent).
*/ */
boolean updateMapWidget(in UpdateMapWidgetParams params); boolean updateMapWidget(in UpdateMapWidgetParams params);
/** /**
* Add point to user layer. * Add point to user layer.
* *
* @param layerId - layer id. Note: layer should be added first. * @param layerId (String) - layer id. Note: layer should be added first.
* @param pointId - point id. * @param pointId (String) - point id.
* @param shortName - short name (single char). Displayed on the map. * @param shortName (String) - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row. * @param fullName (String) - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row. * @param typeName (String) - type name. Displayed in context menu on second row.
* @param color - color of circle's background. * @param color (int) - color of circle's background.
* @param location - location of the point. * @param location (ALatLon) - location of the point.
* @param details - list of details. Displayed under context menu. * @param details (List<String>)- list of details. Displayed under context menu.
* @param params - optional map of params for point. * @param params (Map<String, String>) - optional map of params for point.
*/ */
boolean addMapPoint(in AddMapPointParams params); boolean addMapPoint(in AddMapPointParams params);
@ -176,79 +176,79 @@ interface IOsmAndAidlInterface {
/** /**
* Remove point. * Remove point.
* *
* @param layerId - layer id. * @param layerId (String) - layer id.
* @param pointId - point id. * @param pointId (String) - point id.
*/ */
boolean removeMapPoint(in RemoveMapPointParams params); boolean removeMapPoint(in RemoveMapPointParams params);
/** /**
* Update point. * Update point.
* *
* @param layerId - layer id. * @param layerId (String) - layer id.
* @param pointId - point id. * @param pointId (String) - point id.
* @param shortName - short name (single char). Displayed on the map. * @param shortName (String) - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row. * @param fullName (String) - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row. * @param typeName (String) - type name. Displayed in context menu on second row.
* @param color - color of circle's background. * @param color (String) - color of circle's background.
* @param location - location of the point. * @param location (ALatLon)- location of the point.
* @param details - list of details. Displayed under context menu. * @param details (List<String>) - list of details. Displayed under context menu.
* @param params - optional map of params for point. * @param params (Map<String, String>) - optional map of params for point.
*/ */
boolean updateMapPoint(in UpdateMapPointParams params); boolean updateMapPoint(in UpdateMapPointParams params);
/** /**
* Add user layer on the map. * Add user layer on the map.
* *
* @param id - layer id. * @param id (String) - layer id.
* @param name - layer name. * @param name (String) - layer name.
* @param zOrder - z-order position of layer. Default value is 5.5f * @param zOrder (float) - z-order position of layer. Default value is 5.5f
* @param points - initial list of points. Nullable. * @param points Map<Sting, AMapPoint> - initial list of points. Nullable.
* @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited. * @param imagePoints (boolean) - use new style for points on map or not. Also default zoom bounds for new style can be edited.
*/ */
boolean addMapLayer(in AddMapLayerParams params); boolean addMapLayer(in AddMapLayerParams params);
/** /**
* Remove user layer. * Remove user layer.
* *
* @param id - layer id. * @param id (String) - layer id.
*/ */
boolean removeMapLayer(in RemoveMapLayerParams params); boolean removeMapLayer(in RemoveMapLayerParams params);
/** /**
* Update user layer. * Update user layer.
* *
* @param id - layer id. * @param id (String) - layer id.
* @param name - layer name. * @param name (String) - layer name.
* @param zOrder - z-order position of layer. Default value is 5.5f * @param zOrder (float) - z-order position of layer. Default value is 5.5f
* @param points - list of points. Nullable. * @param points Map<Sting, AMapPoint> - list of points. Nullable.
* @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited. * @param imagePoints (boolean) - use new style for points on map or not. Also default zoom bounds for new style can be edited.
*/ */
boolean updateMapLayer(in UpdateMapLayerParams params); boolean updateMapLayer(in UpdateMapLayerParams params);
/** /**
* Import GPX file to OsmAnd (from URI or file). * Import GPX file to OsmAnd (from URI or file).
* *
* @param gpxUri - URI created by FileProvider (preferable method). * @param gpxUri (Uri) - URI created by FileProvider (preferable method).
* @param file - File which represents GPX track (not recomended, OsmAnd should have rights to access file location). * @param file (File) - File which represents GPX track (not recomended, OsmAnd should have rights to access file location).
* @param fileName - Destination file name. May contain dirs. * @param fileName (String) - Destination file name. May contain dirs.
* @param color - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple", * @param color (String) - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple",
* "translucent_red", "translucent_orange", "translucent_lightblue", * "translucent_red", "translucent_orange", "translucent_lightblue",
* "translucent_blue", "translucent_purple" * "translucent_blue", "translucent_purple"
* @param show - show track on the map after import * @param show (boolean) - show track on the map after import
*/ */
boolean importGpx(in ImportGpxParams params); boolean importGpx(in ImportGpxParams params);
/** /**
* Show GPX file on map. * Show GPX file on map.
* *
* @param fileName - file name to show. Must be imported first. * @param fileName (String) - file name to show. Must be imported first.
*/ */
boolean showGpx(in ShowGpxParams params); boolean showGpx(in ShowGpxParams params);
/** /**
* Hide GPX file. * Hide GPX file.
* *
* @param fileName - file name to hide. * @param fileName (String) - file name to hide.
*/ */
boolean hideGpx(in HideGpxParams params); boolean hideGpx(in HideGpxParams params);
@ -262,10 +262,10 @@ interface IOsmAndAidlInterface {
/** /**
* Set map view to current location. * Set map view to current location.
* *
* @param latitude - latitude of new map center. * @param latitude (double) - latitude of new map center.
* @param longitude - longitude of new map center. * @param longitude (double) - longitude of new map center.
* @param zoom - map zoom level. Set 0 to keep zoom unchanged. * @param zoom (float) - map zoom level. Set 0 to keep zoom unchanged.
* @param animated - set true to animate changes. * @param animated (boolean) - set true to animate changes.
*/ */
boolean setMapLocation(in SetMapLocationParams params); boolean setMapLocation(in SetMapLocationParams params);
@ -280,73 +280,73 @@ interface IOsmAndAidlInterface {
/** /**
* Add favorite group with given params. * Add favorite group with given params.
* *
* @param name - group name. * @param name (String) - group name.
* @param color - group color. Can be one of: "red", "orange", "yellow", * @param color (String) - group color. Can be one of: "red", "orange", "yellow",
* "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown".
* @param visible - group visibility. * @param visible (boolean) - group visibility.
*/ */
boolean addFavoriteGroup(in AddFavoriteGroupParams params); boolean addFavoriteGroup(in AddFavoriteGroupParams params);
/** /**
* Update favorite group with given params. * Update favorite group with given params.
* *
* @param namePrev - group name (current). * @param namePrev (String) - group name (current).
* @param colorPrev - group color (current). * @param colorPrev (String) - group color (current).
* @param visiblePrev - group visibility (current). * @param visiblePrev (boolean) - group visibility (current).
* @param nameNew - group name (new). * @param nameNew (String) - group name (new).
* @param colorNew - group color (new). * @param colorNew (String) - group color (new).
* @param visibleNew - group visibility (new). * @param visibleNew (boolean) - group visibility (new).
*/ */
boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params); boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params);
/** /**
* Remove favorite group with given name. * Remove favorite group with given name.
* *
* @param name - name of favorite group. * @param name (String) - name of favorite group.
*/ */
boolean updateFavoriteGroup(in UpdateFavoriteGroupParams params); boolean updateFavoriteGroup(in UpdateFavoriteGroupParams params);
/** /**
* Add favorite at given location with given params. * Add favorite at given location with given params.
* *
* @param lat - latitude. * @param lat (double) - latitude.
* @param lon - longitude. * @param lon (double) - longitude.
* @param name - name of favorite item. * @param name (String) - name of favorite item.
* @param description - description of favorite item. * @param description (String) - description of favorite item.
* @param category - category of favorite item. * @param category (String) - category of favorite item.
* @param color - color of favorite item. Can be one of: "red", "orange", "yellow", * @param color (String) - color of favorite item. Can be one of: "red", "orange", "yellow",
* "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown".
* @param visible - should favorite item be visible after creation. * @param visible (boolean) - should favorite item be visible after creation.
*/ */
boolean addFavorite(in AddFavoriteParams params); boolean addFavorite(in AddFavoriteParams params);
/** /**
* Update favorite at given location with given params. * Update favorite at given location with given params.
* *
* @param latPrev - latitude (current favorite). * @param latPrev (double) - latitude (current favorite).
* @param lonPrev - longitude (current favorite). * @param lonPrev (double) - longitude (current favorite).
* @param namePrev - name of favorite item (current favorite). * @param namePrev (String) - name of favorite item (current favorite).
* @param categoryPrev - category of favorite item (current favorite). * @param categoryPrev (String) - category of favorite item (current favorite).
* @param latNew - latitude (new favorite). * @param latNew (double) - latitude (new favorite).
* @param lonNew - longitude (new favorite). * @param lonNew (double) - longitude (new favorite).
* @param nameNew - name of favorite item (new favorite). * @param nameNew (String) - name of favorite item (new favorite).
* @param descriptionNew - description of favorite item (new favorite). * @param descriptionNew (String) - description of favorite item (new favorite).
* @param categoryNew - category of favorite item (new favorite). Use only to create a new category, * @param categoryNew (String) - category of favorite item (new favorite). Use only to create a new category,
* not to update an existing one. If you want to update an existing category, * not to update an existing one. If you want to update an existing category,
* use the {@link #updateFavoriteGroup(String, String, boolean, String, String, boolean)} method. * use the {@link #updateFavoriteGroup(String, String, boolean, String, String, boolean)} method.
* @param colorNew - color of new category. Can be one of: "red", "orange", "yellow", * @param colorNew (String) - color of new category. Can be one of: "red", "orange", "yellow",
* "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown".
* @param visibleNew - should new category be visible after creation. * @param visibleNew (boolean) - should new category be visible after creation.
*/ */
boolean removeFavorite(in RemoveFavoriteParams params); boolean removeFavorite(in RemoveFavoriteParams params);
/** /**
* Remove favorite at given location with given params. * Remove favorite at given location with given params.
* *
* @param lat - latitude. * @param lat (double) - latitude.
* @param lon - longitude. * @param lon (double) - longitude.
* @param name - name of favorite item. * @param name (String) - name of favorite item.
* @param category - category of favorite item. * @param category (String) - category of favorite item.
*/ */
boolean updateFavorite(in UpdateFavoriteParams params); boolean updateFavorite(in UpdateFavoriteParams params);
@ -363,24 +363,24 @@ interface IOsmAndAidlInterface {
/** /**
* Take photo note. * Take photo note.
* *
* @param lat - latutude of photo note. * @param lat (double) - latutude of photo note.
* @param lon - longitude of photo note. * @param lon (double) - longitude of photo note.
*/ */
boolean takePhotoNote(in TakePhotoNoteParams params); boolean takePhotoNote(in TakePhotoNoteParams params);
/** /**
* Start video note recording. * Start video note recording.
* *
* @param lat - latutude of video note point. * @param lat (double) - latutude of video note point.
* @param lon - longitude of video note point. * @param lon (double) - longitude of video note point.
*/ */
boolean startVideoRecording(in StartVideoRecordingParams params); boolean startVideoRecording(in StartVideoRecordingParams params);
/** /**
* Start audio note recording. * Start audio note recording.
* *
* @param lat - latutude of audio note point. * @param lat (double) - latutude of audio note point.
* @param lon - longitude of audio note point. * @param lon (double) - longitude of audio note point.
*/ */
boolean startAudioRecording(in StartAudioRecordingParams params); boolean startAudioRecording(in StartAudioRecordingParams params);
@ -392,29 +392,29 @@ interface IOsmAndAidlInterface {
/** /**
* Start navigation. * Start navigation.
* *
* @param startName - name of the start point as it displays in OsmAnd's UI. Nullable. * @param startName (String) - name of the start point as it displays in OsmAnd's UI. Nullable.
* @param startLat - latitude of the start point. If 0 - current location is used. * @param startLat (double) - latitude of the start point. If 0 - current location is used.
* @param startLon - longitude of the start point. If 0 - current location is used. * @param startLon (double) - longitude of the start point. If 0 - current location is used.
* @param destName - name of the start point as it displays in OsmAnd's UI. * @param destName (String) - name of the start point as it displays in OsmAnd's UI.
* @param destLat - latitude of a destination point. * @param destLat (double) - latitude of a destination point.
* @param destLon - longitude of a destination point. * @param destLon (double) - longitude of a destination point.
* @param profile - One of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). * @param profile (String) - One of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default).
* @param force - ask to stop current navigation if any. False - ask. True - don't ask. * @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask.
*/ */
boolean navigate(in NavigateParams params); boolean navigate(in NavigateParams params);
/** /**
* Start navigation using gpx file. User need to grant Uri permission to OsmAnd. * Start navigation using gpx file. User need to grant Uri permission to OsmAnd.
* *
* @param gpxUri - URI created by FileProvider. * @param gpxUri (Uri) - URI created by FileProvider.
* @param force - ask to stop current navigation if any. False - ask. True - don't ask. * @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask.
*/ */
boolean navigateGpx(in NavigateGpxParams params); boolean navigateGpx(in NavigateGpxParams params);
/** /**
* Remove GPX file. * Remove GPX file.
* *
* @param fileName - file name to remove; * @param fileName (String) - file name to remove;
*/ */
boolean removeGpx(in RemoveGpxParams params); boolean removeGpx(in RemoveGpxParams params);
@ -422,15 +422,15 @@ interface IOsmAndAidlInterface {
/** /**
* Show AMapPoint on map in OsmAnd. * Show AMapPoint on map in OsmAnd.
* *
* @param layerId - layer id. Note: layer should be added first. * @param layerId (String) - layer id. Note: layer should be added first.
* @param pointId - point id. * @param pointId (String) - point id.
* @param shortName - short name (single char). Displayed on the map. * @param shortName (String) - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row. * @param fullName (String) - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row. * @param typeName (String) - type name. Displayed in context menu on second row.
* @param color - color of circle's background. * @param color (int) - color of circle's background.
* @param location - location of the point. * @param location (ALatLon) - location of the point.
* @param details - list of details. Displayed under context menu. * @param details List<String> - list of details. Displayed under context menu.
* @param params - optional map of params for point. * @param params Map<String, String> - optional map of params for point.
*/ */
boolean showMapPoint(in ShowMapPointParams params); boolean showMapPoint(in ShowMapPointParams params);
@ -474,46 +474,46 @@ interface IOsmAndAidlInterface {
/** /**
* Run search for POI / Address. * Run search for POI / Address.
* *
* @param searchQuery - search query string. * @param searchQuery (String) - search query string.
* @param searchType - type of search. Values: * @param searchType (int) - type of search. Values:
* SearchParams.SEARCH_TYPE_ALL - all kind of search * SearchParams.SEARCH_TYPE_ALL - all kind of search
* SearchParams.SEARCH_TYPE_POI - POIs only * SearchParams.SEARCH_TYPE_POI - POIs only
* SearchParams.SEARCH_TYPE_ADDRESS - addresses only * SearchParams.SEARCH_TYPE_ADDRESS - addresses only
* *
* @param latitude - latitude of original search location. * @param latitude (double) - latitude of original search location.
* @param longitude - longitude of original search location. * @param longitude (double) - longitude of original search location.
* @param radiusLevel - value from 1 to 7. Default value = 1. * @param radiusLevel (int) - value from 1 to 7. Default value = 1.
* @param totalLimit - limit of returned search result rows. Default value = -1 (unlimited). * @param totalLimit (int) - limit of returned search result rows. Default value = -1 (unlimited).
*/ */
boolean search(in SearchParams params, IOsmAndAidlCallback callback); boolean search(in SearchParams params, IOsmAndAidlCallback callback);
/** /**
* Do search and start navigation. * Do search and start navigation.
* *
* @param startName - name of the start point as it displays in OsmAnd's UI. Nullable. * @param startName (String) - name of the start point as it displays in OsmAnd's UI. Nullable.
* @param startLat - latitude of the start point. If 0 - current location is used. * @param startLat (double) - latitude of the start point. If 0 - current location is used.
* @param startLon - longitude of the start point. If 0 - current location is used. * @param startLon (double) - longitude of the start point. If 0 - current location is used.
* @param searchQuery - Text of a query for searching a destination point. Sent as URI parameter. * @param searchQuery (String) - Text of a query for searching a destination point. Sent as URI parameter.
* @param searchLat - original location of search (latitude). Sent as URI parameter. * @param searchLat (double) - original location of search (latitude). Sent as URI parameter.
* @param searchLon - original location of search (longitude). Sent as URI parameter. * @param searchLon (double) - original location of search (longitude). Sent as URI parameter.
* @param profile - one of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). * @param profile (String) - one of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default).
* @param force - ask to stop current navigation if any. False - ask. True - don't ask. * @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask.
*/ */
boolean navigateSearch(in NavigateSearchParams params); boolean navigateSearch(in NavigateSearchParams params);
/** /**
* Method to register for periodical callbacks from OsmAnd * Method to register for periodical callbacks from OsmAnd
* *
* @param updateTimeMS - period of time in millisecond after which callback is triggered * @param updateTimeMS (long)- period of time in millisecond after which callback is triggered
* @param callback - create and provide instance of {@link IOsmAndAidlCallback} interface * @param callback (IOsmAndCallback)- create and provide instance of {@link IOsmAndAidlCallback} interface
* @return id of callback in OsmAnd. Needed to unsubscribe from updates. * @return id (long) - id of callback in OsmAnd. Needed to unsubscribe from updates.
*/ */
long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback); long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback);
/** /**
* Method to unregister from periodical callbacks from OsmAnd * Method to unregister from periodical callbacks from OsmAnd
* *
* @param callbackId - id of registered callback (provided by OsmAnd * @param callbackId (long)- id of registered callback (provided by OsmAnd
* in {@link OsmAndAidlHelper#registerForUpdates(long, IOsmAndAidlCallback)}) * in {@link OsmAndAidlHelper#registerForUpdates(long, IOsmAndAidlCallback)})
*/ */
boolean unregisterFromUpdates(in long callbackId); boolean unregisterFromUpdates(in long callbackId);
@ -521,7 +521,7 @@ interface IOsmAndAidlInterface {
/** /**
* Method for adding image to the top of Osmand's NavDrawer. * Method for adding image to the top of Osmand's NavDrawer.
* *
* @param imageUri - image's URI.toString * @param imageUri (String)- image's URI.toString
* *
* @deprecated * @deprecated
* Use the {@link #setNavDrawerLogoWithParams(NavDrawerHeaderParams params)} method. * Use the {@link #setNavDrawerLogoWithParams(NavDrawerHeaderParams params)} method.
@ -531,35 +531,35 @@ interface IOsmAndAidlInterface {
/** /**
* Method for selected UI elements (like QuickSearch button) to show. * Method for selected UI elements (like QuickSearch button) to show.
* *
* @param ids - list of menu items keys from {@link OsmAndCustomizationConstants} * @param ids (List<String>)- list of menu items keys from {@link OsmAndCustomizationConstants}
*/ */
boolean setEnabledIds(in List<String> ids); boolean setEnabledIds(in List<String> ids);
/** /**
* Method for selected UI elements (like QuickSearch button) to hide. * Method for selected UI elements (like QuickSearch button) to hide.
* *
* @param ids - list of menu items keys from {@link OsmAndCustomizationConstants} * @param ids (List<String>)- list of menu items keys from {@link OsmAndCustomizationConstants}
*/ */
boolean setDisabledIds(in List<String> ids); boolean setDisabledIds(in List<String> ids);
/** /**
* Method to show selected NavDrawer's menu items. * Method to show selected NavDrawer's menu items.
* *
* @param patterns - list of menu items names from {@link OsmAndCustomizationConstants} * @param patterns (List<String>) - list of menu items names from {@link OsmAndCustomizationConstants}
*/ */
boolean setEnabledPatterns(in List<String> patterns); boolean setEnabledPatterns(in List<String> patterns);
/** /**
* Method to hide selected NavDrawer's menu items. * Method to hide selected NavDrawer's menu items.
* *
* @param patterns - list of menu items names from {@link OsmAndCustomizationConstants} * @param patterns (List<String>)- list of menu items names from {@link OsmAndCustomizationConstants}
*/ */
boolean setDisabledPatterns(in List<String> patterns); boolean setDisabledPatterns(in List<String> patterns);
/** /**
* Register OsmAnd widgets for visibility. * Register OsmAnd widgets for visibility.
* *
* @param widgetKey - widget id. * @param widgetKey ()- widget id.
* @param appModKeys - list of OsmAnd Application modes widget active with. Could be "null" for all modes. * @param appModKeys - list of OsmAnd Application modes widget active with. Could be "null" for all modes.
*/ */
boolean regWidgetVisibility(in SetWidgetsParams params); boolean regWidgetVisibility(in SetWidgetsParams params);
@ -567,16 +567,16 @@ interface IOsmAndAidlInterface {
/** /**
* Register OsmAnd widgets for availability. * Register OsmAnd widgets for availability.
* *
* @param widgetKey - widget id. * @param widgetKey (String) - widget id.
* @param appModKeys - ist of OsmAnd Application modes widget active with. Could be "null" for all modes. * @param appModKeys (List<String>)- ist of OsmAnd Application modes widget active with. Could be "null" for all modes.
*/ */
boolean regWidgetAvailability(in SetWidgetsParams params); boolean regWidgetAvailability(in SetWidgetsParams params);
/** /**
* Add custom parameters for OsmAnd settings to associate with client app. * Add custom parameters for OsmAnd settings to associate with client app.
* *
* @param sharedPreferencesName - string with name of clint's app for shared preferences key * @param sharedPreferencesName (String)- string with name of clint's app for shared preferences key
* @param bundle - bundle with keys from Settings IDs {@link OsmAndCustomizationConstants} and Settings params * @param bundle (Bundle)- bundle with keys from Settings IDs {@link OsmAndCustomizationConstants} and Settings params
*/ */
boolean customizeOsmandSettings(in OsmandSettingsParams params); boolean customizeOsmandSettings(in OsmandSettingsParams params);
@ -604,23 +604,23 @@ interface IOsmAndAidlInterface {
/** /**
* Method to show selected sqlitedb file as map overlay. * Method to show selected sqlitedb file as map overlay.
* *
* @param fileName - name of sqlitedb file * @param fileName (String) - name of sqlitedb file
*/ */
boolean showSqliteDbFile(String fileName); boolean showSqliteDbFile(String fileName);
/** /**
* Method to hide sqlitedb file from map overlay. * Method to hide sqlitedb file from map overlay.
* *
* @param fileName - name of sqlitedb file * @param fileName (String) - name of sqlitedb file
*/ */
boolean hideSqliteDbFile(String fileName); boolean hideSqliteDbFile(String fileName);
/** /**
* Method for adding image to the top of OsmAnd's NavDrawer with additional params * Method for adding image to the top of OsmAnd's NavDrawer with additional params
* *
* @param imageUri - image's URI.toString * @param imageUri (String) - image's URI.toString
* @param packageName - client's app package name * @param packageName (String) - client's app package name
* @param intent - intent for additional functionality on image click * @param intent (String) - intent for additional functionality on image click
* *
*/ */
boolean setNavDrawerLogoWithParams(in NavDrawerHeaderParams params); boolean setNavDrawerLogoWithParams(in NavDrawerHeaderParams params);
@ -629,9 +629,9 @@ interface IOsmAndAidlInterface {
* Method for adding functionality to "Powered by Osmand" logo in NavDrawer's footer * Method for adding functionality to "Powered by Osmand" logo in NavDrawer's footer
* (reset OsmAnd settings to pre-clinet app's state) * (reset OsmAnd settings to pre-clinet app's state)
* *
* @param packageName - package name * @param packageName (String) - package name
* @param intent - intent * @param intent (String) - intent
* @param appName - client's app name * @param appName (String) - client's app name
*/ */
boolean setNavDrawerFooterWithParams(in NavDrawerFooterParams params); boolean setNavDrawerFooterWithParams(in NavDrawerFooterParams params);
@ -644,14 +644,14 @@ interface IOsmAndAidlInterface {
/** /**
* Method to change state of plug-ins in OsmAnd. * Method to change state of plug-ins in OsmAnd.
* *
* @param pluginId - id (name) of plugin. * @param pluginId (String) - id (name) of plugin.
* @param newState - new state (0 - off, 1 - on). * @param newState (int) - new state (0 - off, 1 - on).
*/ */
boolean changePluginState(in PluginParams params); boolean changePluginState(in PluginParams params);
/** /**
* Method to register for callback on OsmAnd initialization * Method to register for callback on OsmAnd initialization
* @param callback - create and provide instance of {@link IOsmAndAidlCallback} interface * @param callback (IOsmAndAidlCallback) - create and provide instance of {@link IOsmAndAidlCallback} interface
*/ */
boolean registerForOsmandInitListener(in IOsmAndAidlCallback callback); boolean registerForOsmandInitListener(in IOsmAndAidlCallback callback);
@ -661,12 +661,12 @@ interface IOsmAndAidlInterface {
* to manually download appropriate map in OsmAnd or background will be empty. * to manually download appropriate map in OsmAnd or background will be empty.
* Bitmap will be returned through callback {@link IOsmAndAidlCallback#onGpxBitmapCreated(AGpxBitmap)} * Bitmap will be returned through callback {@link IOsmAndAidlCallback#onGpxBitmapCreated(AGpxBitmap)}
* *
* @param gpxUri - Uri for gpx file * @param gpxUri (Uri/File) - Uri for gpx file
* @param density - image density. Recommended to use default metrics for device's display. * @param density (float) - image density. Recommended to use default metrics for device's display.
* @param widthPixels - width of bitmap * @param widthPixels (int) - width of bitmap
* @param heightPixels - height of bitmap * @param heightPixels (int) - height of bitmap
* @param color - color in ARGB format * @param color (int) - color in ARGB format
* @param callback - instance of callback from OsmAnd. * @param callback (IOsmAndAidlCallback) - instance of callback from OsmAnd.
*/ */
boolean getBitmapForGpx(in CreateGpxBitmapParams file, IOsmAndAidlCallback callback); boolean getBitmapForGpx(in CreateGpxBitmapParams file, IOsmAndAidlCallback callback);
@ -674,10 +674,10 @@ interface IOsmAndAidlInterface {
* Method to copy files to OsmAnd part by part. For now supports only sqlitedb format. * Method to copy files to OsmAnd part by part. For now supports only sqlitedb format.
* Part size (bytearray) should not exceed 256k. * Part size (bytearray) should not exceed 256k.
* *
* @param copyPart.fileName - name of file * @param fileName (String) - name of file
* @param copyPart.filePartData - parts of file, byte[] with size 256k or less. * @param filePartData (byte[]) - parts of file, byte[] with size 256k or less.
* @param copyPart.startTime - timestamp of copying start. * @param startTime (long) - timestamp of copying start.
* @param copyPart.isDone - boolean to mark end of copying. * @param isDone (boolean) - boolean to mark end of copying.
* @return number of last successfully received file part or error(-1). * @return number of last successfully received file part or error(-1).
*/ */
int copyFile(in CopyFileParams filePart); int copyFile(in CopyFileParams filePart);
@ -686,9 +686,9 @@ interface IOsmAndAidlInterface {
/** /**
* Method to register for updates during navgation. Notifies user about distance to the next turn and its type. * Method to register for updates during navgation. Notifies user about distance to the next turn and its type.
* *
* @params params.subscribeToUpdates - boolean flag to subscribe or unsubscribe from updates * @params subscribeToUpdates (boolean) - boolean flag to subscribe or unsubscribe from updates
* @params params.callbackId - id of callback, needed to unsubscribe from updates * @params callbackId (long) - id of callback, needed to unsubscribe from updates
* @params callback - callback to notify user on navigation data change * @params callback (IOsmAndAidlCallback) - callback to notify user on navigation data change
*/ */
long registerForNavigationUpdates(in ANavigationUpdateParams params, IOsmAndAidlCallback callback); long registerForNavigationUpdates(in ANavigationUpdateParams params, IOsmAndAidlCallback callback);
} }

View file

@ -127,6 +127,9 @@ import static net.osmand.aidl.OsmandAidlService.KEY_ON_NAV_DATA_UPDATE;
import static net.osmand.plus.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME; import static net.osmand.plus.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME;
public class OsmandAidlApi { public class OsmandAidlApi {
AidlCallbackListener aidlCallbackListener = null;
private static final Log LOG = PlatformUtil.getLog(OsmandAidlApi.class); private static final Log LOG = PlatformUtil.getLog(OsmandAidlApi.class);
private static final String AIDL_REFRESH_MAP = "aidl_refresh_map"; 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_SET_MAP_LOCATION = "aidl_set_map_location";
@ -1925,10 +1928,12 @@ public class OsmandAidlApi {
return app.getAppCustomization().changePluginStatus(params); return app.getAppCustomization().changePluginStatus(params);
} }
public void registerForNavigationUpdates() { private Map<Long, IRoutingDataUpdateListener> navUpdateCallbacks = new ConcurrentHashMap<>();
void registerForNavigationUpdates(long id) {
final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false);
final NextDirectionInfo baseNdi = new NextDirectionInfo(); final NextDirectionInfo baseNdi = new NextDirectionInfo();
app.getRoutingHelper().addDataUpdateListener(new IRoutingDataUpdateListener(){ IRoutingDataUpdateListener listener = new IRoutingDataUpdateListener() {
@Override @Override
public void onRoutingDataUpdate() { public void onRoutingDataUpdate() {
RoutingHelper rh = app.getRoutingHelper(); RoutingHelper rh = app.getRoutingHelper();
@ -1942,19 +1947,29 @@ public class OsmandAidlApi {
directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue());
} }
} }
for (Entry<Long, OsmandAidlService.AidlCallbackParams> cb : OsmandAidlService.getAidlCallbacks().entrySet()) { if (aidlCallbackListener != null) {
if ((cb.getValue().getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) { for (OsmandAidlService.AidlCallbackParams cb : aidlCallbackListener.getAidlCallbacks().values()) {
try { if (!aidlCallbackListener.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) {
cb.getValue().getCallback().updateNavigationInfo(directionInfo); try {
} catch (Exception e) { cb.getCallback().updateNavigationInfo(directionInfo);
LOG.debug(e.getMessage(), e); } catch (Exception e) {
LOG.debug(e.getMessage(), e);
}
} }
} }
} }
} }
}); };
navUpdateCallbacks.put(id, listener);
app.getRoutingHelper().addDataUpdateListener(listener);
} }
public void unregisterFromUpdates(long id) {
app.getRoutingHelper().removeDataUpdateListener(navUpdateCallbacks.get(id));
navUpdateCallbacks.remove(id);
}
boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels,
final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) {
if (gpxUri == null || callback == null) { if (gpxUri == null || callback == null) {
@ -2014,6 +2029,7 @@ public class OsmandAidlApi {
private Map<String, FileCopyInfo> copyFilesCache = new ConcurrentHashMap<>(); private Map<String, FileCopyInfo> copyFilesCache = new ConcurrentHashMap<>();
private class FileCopyInfo { private class FileCopyInfo {
long startTime; long startTime;
long lastAccessTime; long lastAccessTime;

View file

@ -10,6 +10,7 @@ import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback;
@ -83,7 +84,7 @@ import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS;
import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS_ERROR; import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS_ERROR;
import static net.osmand.aidl.OsmandAidlConstants.UNKNOWN_API_ERROR; import static net.osmand.aidl.OsmandAidlConstants.UNKNOWN_API_ERROR;
public class OsmandAidlService extends Service { public class OsmandAidlService extends Service implements AidlCallbackListener {
private static final Log LOG = PlatformUtil.getLog(OsmandAidlService.class); private static final Log LOG = PlatformUtil.getLog(OsmandAidlService.class);
@ -92,28 +93,16 @@ public class OsmandAidlService extends Service {
public static final int KEY_ON_UPDATE = 1; public static final int KEY_ON_UPDATE = 1;
public static final int KEY_ON_NAV_DATA_UPDATE = 2; public static final int KEY_ON_NAV_DATA_UPDATE = 2;
private static Map<Long, AidlCallbackParams> callbacks; private Map<Long, AidlCallbackParams> callbacks = new ConcurrentHashMap<>();
private Handler mHandler = null; private Handler mHandler = null;
HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread"); HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread");
private static long aidlCallbackId = 0; private long aidlCallbackId = 0;
private OsmandApplication getApp() { private OsmandApplication getApp() {
return (OsmandApplication) getApplication(); return (OsmandApplication) getApplication();
} }
public static void addAidlCallback(IOsmAndAidlCallback callback, long id, long key) {
callbacks.put(id, new AidlCallbackParams(callback, key));
}
public static boolean removeAidlCallback (long id){
return callbacks.remove(id) != null;
}
public static Map<Long, AidlCallbackParams> getAidlCallbacks() {
return callbacks;
}
@Nullable @Nullable
private OsmandAidlApi getApi(String reason) { private OsmandAidlApi getApi(String reason) {
LOG.info("Request AIDL API for " + reason); LOG.info("Request AIDL API for " + reason);
@ -137,7 +126,11 @@ public class OsmandAidlService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
callbacks = new ConcurrentHashMap<>(); OsmandAidlApi api = getApi("setting_listener");
if(api != null) {
LOG.debug("aidl api not null!");
api.aidlCallbackListener = this;
}
} }
@Override @Override
@ -147,6 +140,29 @@ public class OsmandAidlService extends Service {
callbacks.clear(); callbacks.clear();
} }
@Override
public void addAidlCallback(IOsmAndAidlCallback callback, int key) {
aidlCallbackId++;
callbacks.put(aidlCallbackId, new AidlCallbackParams(callback, key));
}
@Override
public boolean removeAidlCallback(long id) {
for (Long key : callbacks.keySet()) {
if (key == id) {
callbacks.remove(id);
return true;
}
}
return false;
}
@Override
public Map<Long, AidlCallbackParams> getAidlCallbacks() {
return callbacks;
}
private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() { private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() {
private void handleException(Exception e) { private void handleException(Exception e) {
@ -733,7 +749,7 @@ public class OsmandAidlService extends Service {
try { try {
if (updateTimeMS >= MIN_UPDATE_TIME_MS) { if (updateTimeMS >= MIN_UPDATE_TIME_MS) {
aidlCallbackId++; aidlCallbackId++;
addAidlCallback(callback, aidlCallbackId, KEY_ON_UPDATE); addAidlCallback(callback, KEY_ON_UPDATE);
startRemoteUpdates(updateTimeMS, aidlCallbackId, callback); startRemoteUpdates(updateTimeMS, aidlCallbackId, callback);
return aidlCallbackId; return aidlCallbackId;
} else { } else {
@ -1012,18 +1028,17 @@ public class OsmandAidlService extends Service {
@Override @Override
public long registerForNavigationUpdates(ANavigationUpdateParams params, final IOsmAndAidlCallback callback) { public long registerForNavigationUpdates(ANavigationUpdateParams params, final IOsmAndAidlCallback callback) {
try { try {
aidlCallbackId++;
OsmandAidlApi api = getApi("registerForNavUpdates"); OsmandAidlApi api = getApi("registerForNavUpdates");
if (api != null ) { if (api != null ) {
if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) { if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) {
api.unregisterFromUpdates(params.getCallbackId());
removeAidlCallback(params.getCallbackId()); removeAidlCallback(params.getCallbackId());
return -1; return -1;
} else { } else {
addAidlCallback(callback, aidlCallbackId, KEY_ON_NAV_DATA_UPDATE); addAidlCallback(callback, KEY_ON_NAV_DATA_UPDATE);
api.registerForNavigationUpdates(aidlCallbackId);
return aidlCallbackId;
} }
api.registerForNavigationUpdates();
return aidlCallbackId;
} else { } else {
return -1; return -1;
} }
@ -1034,6 +1049,7 @@ public class OsmandAidlService extends Service {
} }
}; };
public static class AidlCallbackParams { public static class AidlCallbackParams {
private IOsmAndAidlCallback callback; private IOsmAndAidlCallback callback;
private long key; private long key;
@ -1060,4 +1076,6 @@ public class OsmandAidlService extends Service {
this.key = key; this.key = key;
} }
} }
} }

View file

@ -29,6 +29,7 @@ import java.lang.ref.WeakReference;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION; import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION;
@ -38,8 +39,8 @@ public class RoutingHelper {
private static final float POSITION_TOLERANCE = 60; private static final float POSITION_TOLERANCE = 60;
private List<WeakReference<IRouteInformationListener>> listeners = new LinkedList<>(); private List<WeakReference<IRouteInformationListener>> listeners = new CopyOnWriteArrayList<>();
private List<WeakReference<IRoutingDataUpdateListener>> updateListeners = new LinkedList<>(); private List<WeakReference<IRoutingDataUpdateListener>> updateListeners = new CopyOnWriteArrayList<>();
private OsmandApplication app; private OsmandApplication app;
private TransportRoutingHelper transportRoutingHelper; private TransportRoutingHelper transportRoutingHelper;
@ -266,7 +267,20 @@ public class RoutingHelper {
} }
public void addDataUpdateListener(IRoutingDataUpdateListener listener) { public void addDataUpdateListener(IRoutingDataUpdateListener listener) {
updateListeners.add(new WeakReference<IRoutingDataUpdateListener>(listener)); updateListeners.add(new WeakReference<>(listener));
}
public boolean removeDataUpdateListener(IRoutingDataUpdateListener listener) {
Iterator<WeakReference<IRoutingDataUpdateListener>> it = updateListeners.iterator();
while(it.hasNext()) {
WeakReference<IRoutingDataUpdateListener> wrl = it.next();
IRoutingDataUpdateListener l = wrl.get();
if(listener == l) {
it.remove();
return true;
}
}
return false;
} }
public boolean removeListener(IRouteInformationListener lt){ public boolean removeListener(IRouteInformationListener lt){
@ -274,7 +288,7 @@ public class RoutingHelper {
while(it.hasNext()) { while(it.hasNext()) {
WeakReference<IRouteInformationListener> ref = it.next(); WeakReference<IRouteInformationListener> ref = it.next();
IRouteInformationListener l = ref.get(); IRouteInformationListener l = ref.get();
if(l == null || lt == l) { if(l == lt) {
it.remove(); it.remove();
return true; return true;
} }
@ -508,7 +522,9 @@ public class RoutingHelper {
app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION); app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
if (!updateListeners.isEmpty()) { if (!updateListeners.isEmpty()) {
for (WeakReference<IRoutingDataUpdateListener> ref : updateListeners) { for (WeakReference<IRoutingDataUpdateListener> ref : updateListeners) {
ref.get().onRoutingDataUpdate(); if (ref.get() != null) {
ref.get().onRoutingDataUpdate();
}
} }
} }