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.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name.
* @param lat (double) - latitude.
* @param lon (double) - longitude.
* @param name (String)- name of marker.
*/
boolean addMapMarker(in AddMapMarkerParams params);
/**
* Remove map marker at given location with name.
* Add map marker at given location.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name.
* @param lat (double) - latitude.
* @param lon (double) - longitude.
* @param name (String)- name of marker.
*/
boolean removeMapMarker(in RemoveMapMarkerParams params);
/**
* Update map marker at given location with name.
*
* @param latPrev - latitude (current marker).
* @param lonPrev - longitude (current marker).
* @param namePrev - name (current marker).
* @param latNew - latitude (new marker).
* @param lonNew - longitude (new marker).
* @param nameNew - name (new marker).
* @param latPrev (double) - latitude (current marker).
* @param lonPrev (double) - longitude (current marker).
* @param namePrev (String) - name (current marker).
* @param latNew (double) - latitude (new marker).
* @param lonNew (double) - longitude (new marker).
* @param nameNew (String) - name (new marker).
*/
boolean updateMapMarker(in UpdateMapMarkerParams params);
@ -122,22 +122,22 @@ interface IOsmAndAidlInterface {
* Add map widget to the right side of the main screen.
* Note: any specified icon should exist in OsmAnd app resources.
*
* @param id - widget id.
* @param menuIconName - icon name (configure map menu).
* @param menuTitle - widget name (configure map menu).
* @param lightIconName - icon name for the light theme (widget).
* @param darkIconName - icon name for the dark theme (widget).
* @param text - main widget text.
* @param description - sub text, like "km/h".
* @param order - order position in the widgets list.
* @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent).
* @param id (String) - widget id.
* @param menuIconName (String) - icon name (configure map menu).
* @param menuTitle (String) - widget name (configure map menu).
* @param lightIconName (String) - icon name for the light theme (widget).
* @param darkIconName (String) - icon name for the dark theme (widget).
* @param text (String) - main widget text.
* @param description (String) - sub text, like "km/h".
* @param order (int) - order position in the widgets list.
* @param intentOnClick (String) - onClick intent. Called after click on widget as startActivity(Intent intent).
*/
boolean addMapWidget(in AddMapWidgetParams params);
/**
* Remove map widget.
*
* @param id - widget id.
* @param (String) id - widget id.
*/
boolean removeMapWidget(in RemoveMapWidgetParams params);
@ -145,30 +145,30 @@ interface IOsmAndAidlInterface {
* Update map widget.
* Note: any specified icon should exist in OsmAnd app resources.
*
* @param id - widget id.
* @param menuIconName - icon name (configure map menu).
* @param menuTitle - widget name (configure map menu).
* @param lightIconName - icon name for the light theme (widget).
* @param darkIconName - icon name for the dark theme (widget).
* @param text - main widget text.
* @param description - sub text, like "km/h".
* @param order - order position in the widgets list.
* @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent).
* @param id (String) - widget id.
* @param menuIconName (String) - icon name (configure map menu).
* @param menuTitle (String) - widget name (configure map menu).
* @param lightIconName (String) - icon name for the light theme (widget).
* @param darkIconName (String) - icon name for the dark theme (widget).
* @param text (String) - main widget text.
* @param description (String) - sub text, like "km/h".
* @param order (int) - order position in the widgets list.
* @param intentOnClick (String) - onClick intent. Called after click on widget as startActivity(Intent intent).
*/
boolean updateMapWidget(in UpdateMapWidgetParams params);
/**
* Add point to user layer.
*
* @param layerId - layer id. Note: layer should be added first.
* @param pointId - point id.
* @param shortName - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row.
* @param color - color of circle's background.
* @param location - location of the point.
* @param details - list of details. Displayed under context menu.
* @param params - optional map of params for point.
* @param layerId (String) - layer id. Note: layer should be added first.
* @param pointId (String) - point id.
* @param shortName (String) - short name (single char). Displayed on the map.
* @param fullName (String) - full name. Displayed in the context menu on first row.
* @param typeName (String) - type name. Displayed in context menu on second row.
* @param color (int) - color of circle's background.
* @param location (ALatLon) - location of the point.
* @param details (List<String>)- list of details. Displayed under context menu.
* @param params (Map<String, String>) - optional map of params for point.
*/
boolean addMapPoint(in AddMapPointParams params);
@ -176,79 +176,79 @@ interface IOsmAndAidlInterface {
/**
* Remove point.
*
* @param layerId - layer id.
* @param pointId - point id.
* @param layerId (String) - layer id.
* @param pointId (String) - point id.
*/
boolean removeMapPoint(in RemoveMapPointParams params);
/**
* Update point.
*
* @param layerId - layer id.
* @param pointId - point id.
* @param shortName - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row.
* @param color - color of circle's background.
* @param location - location of the point.
* @param details - list of details. Displayed under context menu.
* @param params - optional map of params for point.
* @param layerId (String) - layer id.
* @param pointId (String) - point id.
* @param shortName (String) - short name (single char). Displayed on the map.
* @param fullName (String) - full name. Displayed in the context menu on first row.
* @param typeName (String) - type name. Displayed in context menu on second row.
* @param color (String) - color of circle's background.
* @param location (ALatLon)- location of the point.
* @param details (List<String>) - list of details. Displayed under context menu.
* @param params (Map<String, String>) - optional map of params for point.
*/
boolean updateMapPoint(in UpdateMapPointParams params);
/**
* Add user layer on the map.
*
* @param id - layer id.
* @param name - layer name.
* @param zOrder - z-order position of layer. Default value is 5.5f
* @param points - 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 id (String) - layer id.
* @param name (String) - layer name.
* @param zOrder (float) - z-order position of layer. Default value is 5.5f
* @param points Map<Sting, AMapPoint> - initial list of points. Nullable.
* @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);
/**
* Remove user layer.
*
* @param id - layer id.
* @param id (String) - layer id.
*/
boolean removeMapLayer(in RemoveMapLayerParams params);
/**
* Update user layer.
*
* @param id - layer id.
* @param name - layer name.
* @param zOrder - z-order position of layer. Default value is 5.5f
* @param points - 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 id (String) - layer id.
* @param name (String) - layer name.
* @param zOrder (float) - z-order position of layer. Default value is 5.5f
* @param points Map<Sting, AMapPoint> - list of points. Nullable.
* @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);
/**
* Import GPX file to OsmAnd (from URI or file).
*
* @param gpxUri - URI created by FileProvider (preferable method).
* @param 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 color - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple",
* @param gpxUri (Uri) - URI created by FileProvider (preferable method).
* @param file (File) - File which represents GPX track (not recomended, OsmAnd should have rights to access file location).
* @param fileName (String) - Destination file name. May contain dirs.
* @param color (String) - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple",
* "translucent_red", "translucent_orange", "translucent_lightblue",
* "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);
/**
* 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);
/**
* Hide GPX file.
*
* @param fileName - file name to hide.
* @param fileName (String) - file name to hide.
*/
boolean hideGpx(in HideGpxParams params);
@ -262,10 +262,10 @@ interface IOsmAndAidlInterface {
/**
* Set map view to current location.
*
* @param latitude - latitude of new map center.
* @param longitude - longitude of new map center.
* @param zoom - map zoom level. Set 0 to keep zoom unchanged.
* @param animated - set true to animate changes.
* @param latitude (double) - latitude of new map center.
* @param longitude (double) - longitude of new map center.
* @param zoom (float) - map zoom level. Set 0 to keep zoom unchanged.
* @param animated (boolean) - set true to animate changes.
*/
boolean setMapLocation(in SetMapLocationParams params);
@ -280,73 +280,73 @@ interface IOsmAndAidlInterface {
/**
* Add favorite group with given params.
*
* @param name - group name.
* @param color - group color. Can be one of: "red", "orange", "yellow",
* @param name (String) - group name.
* @param color (String) - group color. Can be one of: "red", "orange", "yellow",
* "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown".
* @param visible - group visibility.
* @param visible (boolean) - group visibility.
*/
boolean addFavoriteGroup(in AddFavoriteGroupParams params);
/**
* Update favorite group with given params.
*
* @param namePrev - group name (current).
* @param colorPrev - group color (current).
* @param visiblePrev - group visibility (current).
* @param nameNew - group name (new).
* @param colorNew - group color (new).
* @param visibleNew - group visibility (new).
* @param namePrev (String) - group name (current).
* @param colorPrev (String) - group color (current).
* @param visiblePrev (boolean) - group visibility (current).
* @param nameNew (String) - group name (new).
* @param colorNew (String) - group color (new).
* @param visibleNew (boolean) - group visibility (new).
*/
boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params);
/**
* Remove favorite group with given name.
*
* @param name - name of favorite group.
* @param name (String) - name of favorite group.
*/
boolean updateFavoriteGroup(in UpdateFavoriteGroupParams params);
/**
* Add favorite at given location with given params.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name of favorite item.
* @param description - description of favorite item.
* @param category - category of favorite item.
* @param color - color of favorite item. Can be one of: "red", "orange", "yellow",
* @param lat (double) - latitude.
* @param lon (double) - longitude.
* @param name (String) - name of favorite item.
* @param description (String) - description of favorite item.
* @param category (String) - category of favorite item.
* @param color (String) - color of favorite item. Can be one of: "red", "orange", "yellow",
* "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);
/**
* Update favorite at given location with given params.
*
* @param latPrev - latitude (current favorite).
* @param lonPrev - longitude (current favorite).
* @param namePrev - name of favorite item (current favorite).
* @param categoryPrev - category of favorite item (current favorite).
* @param latNew - latitude (new favorite).
* @param lonNew - longitude (new favorite).
* @param nameNew - name of favorite item (new favorite).
* @param descriptionNew - description of favorite item (new favorite).
* @param categoryNew - category of favorite item (new favorite). Use only to create a new category,
* @param latPrev (double) - latitude (current favorite).
* @param lonPrev (double) - longitude (current favorite).
* @param namePrev (String) - name of favorite item (current favorite).
* @param categoryPrev (String) - category of favorite item (current favorite).
* @param latNew (double) - latitude (new favorite).
* @param lonNew (double) - longitude (new favorite).
* @param nameNew (String) - name of favorite item (new favorite).
* @param descriptionNew (String) - description of favorite item (new favorite).
* @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,
* 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".
* @param visibleNew - should new category be visible after creation.
* @param visibleNew (boolean) - should new category be visible after creation.
*/
boolean removeFavorite(in RemoveFavoriteParams params);
/**
* Remove favorite at given location with given params.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name of favorite item.
* @param category - category of favorite item.
* @param lat (double) - latitude.
* @param lon (double) - longitude.
* @param name (String) - name of favorite item.
* @param category (String) - category of favorite item.
*/
boolean updateFavorite(in UpdateFavoriteParams params);
@ -363,24 +363,24 @@ interface IOsmAndAidlInterface {
/**
* Take photo note.
*
* @param lat - latutude of photo note.
* @param lon - longitude of photo note.
* @param lat (double) - latutude of photo note.
* @param lon (double) - longitude of photo note.
*/
boolean takePhotoNote(in TakePhotoNoteParams params);
/**
* Start video note recording.
*
* @param lat - latutude of video note point.
* @param lon - longitude of video note point.
* @param lat (double) - latutude of video note point.
* @param lon (double) - longitude of video note point.
*/
boolean startVideoRecording(in StartVideoRecordingParams params);
/**
* Start audio note recording.
*
* @param lat - latutude of audio note point.
* @param lon - longitude of audio note point.
* @param lat (double) - latutude of audio note point.
* @param lon (double) - longitude of audio note point.
*/
boolean startAudioRecording(in StartAudioRecordingParams params);
@ -392,29 +392,29 @@ interface IOsmAndAidlInterface {
/**
* Start navigation.
*
* @param startName - 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 startLon - 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 destLat - latitude of a destination point.
* @param destLon - longitude of a destination point.
* @param profile - 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 startName (String) - name of the start point as it displays in OsmAnd's UI. Nullable.
* @param startLat (double) - latitude 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 (String) - name of the start point as it displays in OsmAnd's UI.
* @param destLat (double) - latitude of a destination point.
* @param destLon (double) - longitude of a destination point.
* @param profile (String) - One of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default).
* @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask.
*/
boolean navigate(in NavigateParams params);
/**
* Start navigation using gpx file. User need to grant Uri permission to OsmAnd.
*
* @param gpxUri - URI created by FileProvider.
* @param force - ask to stop current navigation if any. False - ask. True - don't ask.
* @param gpxUri (Uri) - URI created by FileProvider.
* @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask.
*/
boolean navigateGpx(in NavigateGpxParams params);
/**
* Remove GPX file.
*
* @param fileName - file name to remove;
* @param fileName (String) - file name to remove;
*/
boolean removeGpx(in RemoveGpxParams params);
@ -422,15 +422,15 @@ interface IOsmAndAidlInterface {
/**
* Show AMapPoint on map in OsmAnd.
*
* @param layerId - layer id. Note: layer should be added first.
* @param pointId - point id.
* @param shortName - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row.
* @param color - color of circle's background.
* @param location - location of the point.
* @param details - list of details. Displayed under context menu.
* @param params - optional map of params for point.
* @param layerId (String) - layer id. Note: layer should be added first.
* @param pointId (String) - point id.
* @param shortName (String) - short name (single char). Displayed on the map.
* @param fullName (String) - full name. Displayed in the context menu on first row.
* @param typeName (String) - type name. Displayed in context menu on second row.
* @param color (int) - color of circle's background.
* @param location (ALatLon) - location of the point.
* @param details List<String> - list of details. Displayed under context menu.
* @param params Map<String, String> - optional map of params for point.
*/
boolean showMapPoint(in ShowMapPointParams params);
@ -474,46 +474,46 @@ interface IOsmAndAidlInterface {
/**
* Run search for POI / Address.
*
* @param searchQuery - search query string.
* @param searchType - type of search. Values:
* @param searchQuery (String) - search query string.
* @param searchType (int) - type of search. Values:
* SearchParams.SEARCH_TYPE_ALL - all kind of search
* SearchParams.SEARCH_TYPE_POI - POIs only
* SearchParams.SEARCH_TYPE_ADDRESS - addresses only
*
* @param latitude - latitude of original search location.
* @param longitude - longitude of original search location.
* @param radiusLevel - value from 1 to 7. Default value = 1.
* @param totalLimit - limit of returned search result rows. Default value = -1 (unlimited).
* @param latitude (double) - latitude of original search location.
* @param longitude (double) - longitude of original search location.
* @param radiusLevel (int) - value from 1 to 7. Default value = 1.
* @param totalLimit (int) - limit of returned search result rows. Default value = -1 (unlimited).
*/
boolean search(in SearchParams params, IOsmAndAidlCallback callback);
/**
* Do search and start navigation.
*
* @param startName - 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 startLon - 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 searchLat - original location of search (latitude). Sent as URI parameter.
* @param searchLon - 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 force - ask to stop current navigation if any. False - ask. True - don't ask.
* @param startName (String) - name of the start point as it displays in OsmAnd's UI. Nullable.
* @param startLat (double) - latitude 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 (String) - Text of a query for searching a destination point. Sent as URI parameter.
* @param searchLat (double) - original location of search (latitude). Sent as URI parameter.
* @param searchLon (double) - original location of search (longitude). Sent as URI parameter.
* @param profile (String) - one of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default).
* @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask.
*/
boolean navigateSearch(in NavigateSearchParams params);
/**
* Method to register for periodical callbacks from OsmAnd
*
* @param updateTimeMS - period of time in millisecond after which callback is triggered
* @param callback - create and provide instance of {@link IOsmAndAidlCallback} interface
* @return id of callback in OsmAnd. Needed to unsubscribe from updates.
* @param updateTimeMS (long)- period of time in millisecond after which callback is triggered
* @param callback (IOsmAndCallback)- create and provide instance of {@link IOsmAndAidlCallback} interface
* @return id (long) - id of callback in OsmAnd. Needed to unsubscribe from updates.
*/
long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback);
/**
* 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)})
*/
boolean unregisterFromUpdates(in long callbackId);
@ -521,7 +521,7 @@ interface IOsmAndAidlInterface {
/**
* 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
* Use the {@link #setNavDrawerLogoWithParams(NavDrawerHeaderParams params)} method.
@ -531,35 +531,35 @@ interface IOsmAndAidlInterface {
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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.
*/
boolean regWidgetVisibility(in SetWidgetsParams params);
@ -567,16 +567,16 @@ interface IOsmAndAidlInterface {
/**
* Register OsmAnd widgets for availability.
*
* @param widgetKey - widget id.
* @param appModKeys - ist of OsmAnd Application modes widget active with. Could be "null" for all modes.
* @param widgetKey (String) - widget id.
* @param appModKeys (List<String>)- ist of OsmAnd Application modes widget active with. Could be "null" for all modes.
*/
boolean regWidgetAvailability(in SetWidgetsParams params);
/**
* 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 bundle - bundle with keys from Settings IDs {@link OsmAndCustomizationConstants} and Settings params
* @param sharedPreferencesName (String)- string with name of clint's app for shared preferences key
* @param bundle (Bundle)- bundle with keys from Settings IDs {@link OsmAndCustomizationConstants} and Settings params
*/
boolean customizeOsmandSettings(in OsmandSettingsParams params);
@ -604,23 +604,23 @@ interface IOsmAndAidlInterface {
/**
* 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);
/**
* 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);
/**
* Method for adding image to the top of OsmAnd's NavDrawer with additional params
*
* @param imageUri - image's URI.toString
* @param packageName - client's app package name
* @param intent - intent for additional functionality on image click
* @param imageUri (String) - image's URI.toString
* @param packageName (String) - client's app package name
* @param intent (String) - intent for additional functionality on image click
*
*/
boolean setNavDrawerLogoWithParams(in NavDrawerHeaderParams params);
@ -629,9 +629,9 @@ interface IOsmAndAidlInterface {
* Method for adding functionality to "Powered by Osmand" logo in NavDrawer's footer
* (reset OsmAnd settings to pre-clinet app's state)
*
* @param packageName - package name
* @param intent - intent
* @param appName - client's app name
* @param packageName (String) - package name
* @param intent (String) - intent
* @param appName (String) - client's app name
*/
boolean setNavDrawerFooterWithParams(in NavDrawerFooterParams params);
@ -644,14 +644,14 @@ interface IOsmAndAidlInterface {
/**
* Method to change state of plug-ins in OsmAnd.
*
* @param pluginId - id (name) of plugin.
* @param newState - new state (0 - off, 1 - on).
* @param pluginId (String) - id (name) of plugin.
* @param newState (int) - new state (0 - off, 1 - on).
*/
boolean changePluginState(in PluginParams params);
/**
* 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);
@ -661,12 +661,12 @@ interface IOsmAndAidlInterface {
* to manually download appropriate map in OsmAnd or background will be empty.
* Bitmap will be returned through callback {@link IOsmAndAidlCallback#onGpxBitmapCreated(AGpxBitmap)}
*
* @param gpxUri - Uri for gpx file
* @param density - image density. Recommended to use default metrics for device's display.
* @param widthPixels - width of bitmap
* @param heightPixels - height of bitmap
* @param color - color in ARGB format
* @param callback - instance of callback from OsmAnd.
* @param gpxUri (Uri/File) - Uri for gpx file
* @param density (float) - image density. Recommended to use default metrics for device's display.
* @param widthPixels (int) - width of bitmap
* @param heightPixels (int) - height of bitmap
* @param color (int) - color in ARGB format
* @param callback (IOsmAndAidlCallback) - instance of callback from OsmAnd.
*/
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.
* Part size (bytearray) should not exceed 256k.
*
* @param copyPart.fileName - name of file
* @param copyPart.filePartData - parts of file, byte[] with size 256k or less.
* @param copyPart.startTime - timestamp of copying start.
* @param copyPart.isDone - boolean to mark end of copying.
* @param fileName (String) - name of file
* @param filePartData (byte[]) - parts of file, byte[] with size 256k or less.
* @param startTime (long) - timestamp of copying start.
* @param isDone (boolean) - boolean to mark end of copying.
* @return number of last successfully received file part or error(-1).
*/
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.
*
* @params params.subscribeToUpdates - boolean flag to subscribe or unsubscribe from updates
* @params params.callbackId - id of callback, needed to unsubscribe from updates
* @params callback - callback to notify user on navigation data change
* @params subscribeToUpdates (boolean) - boolean flag to subscribe or unsubscribe from updates
* @params callbackId (long) - id of callback, needed to unsubscribe from updates
* @params callback (IOsmAndAidlCallback) - callback to notify user on navigation data change
*/
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;
public class OsmandAidlApi {
AidlCallbackListener aidlCallbackListener = null;
private static final Log LOG = PlatformUtil.getLog(OsmandAidlApi.class);
private static final String AIDL_REFRESH_MAP = "aidl_refresh_map";
private static final String AIDL_SET_MAP_LOCATION = "aidl_set_map_location";
@ -1925,10 +1928,12 @@ public class OsmandAidlApi {
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 NextDirectionInfo baseNdi = new NextDirectionInfo();
app.getRoutingHelper().addDataUpdateListener(new IRoutingDataUpdateListener(){
IRoutingDataUpdateListener listener = new IRoutingDataUpdateListener() {
@Override
public void onRoutingDataUpdate() {
RoutingHelper rh = app.getRoutingHelper();
@ -1942,19 +1947,29 @@ public class OsmandAidlApi {
directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue());
}
}
for (Entry<Long, OsmandAidlService.AidlCallbackParams> cb : OsmandAidlService.getAidlCallbacks().entrySet()) {
if ((cb.getValue().getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) {
try {
cb.getValue().getCallback().updateNavigationInfo(directionInfo);
} catch (Exception e) {
LOG.debug(e.getMessage(), e);
if (aidlCallbackListener != null) {
for (OsmandAidlService.AidlCallbackParams cb : aidlCallbackListener.getAidlCallbacks().values()) {
if (!aidlCallbackListener.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) {
try {
cb.getCallback().updateNavigationInfo(directionInfo);
} 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,
final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) {
if (gpxUri == null || callback == null) {
@ -2014,6 +2029,7 @@ public class OsmandAidlApi {
private Map<String, FileCopyInfo> copyFilesCache = new ConcurrentHashMap<>();
private class FileCopyInfo {
long startTime;
long lastAccessTime;

View file

@ -10,6 +10,7 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import net.osmand.PlatformUtil;
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.UNKNOWN_API_ERROR;
public class OsmandAidlService extends Service {
public class OsmandAidlService extends Service implements AidlCallbackListener {
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_NAV_DATA_UPDATE = 2;
private static Map<Long, AidlCallbackParams> callbacks;
private Map<Long, AidlCallbackParams> callbacks = new ConcurrentHashMap<>();
private Handler mHandler = null;
HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread");
private static long aidlCallbackId = 0;
private long aidlCallbackId = 0;
private OsmandApplication getApp() {
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
private OsmandAidlApi getApi(String reason) {
LOG.info("Request AIDL API for " + reason);
@ -137,7 +126,11 @@ public class OsmandAidlService extends Service {
@Override
public void onCreate() {
super.onCreate();
callbacks = new ConcurrentHashMap<>();
OsmandAidlApi api = getApi("setting_listener");
if(api != null) {
LOG.debug("aidl api not null!");
api.aidlCallbackListener = this;
}
}
@Override
@ -147,6 +140,29 @@ public class OsmandAidlService extends Service {
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 void handleException(Exception e) {
@ -733,7 +749,7 @@ public class OsmandAidlService extends Service {
try {
if (updateTimeMS >= MIN_UPDATE_TIME_MS) {
aidlCallbackId++;
addAidlCallback(callback, aidlCallbackId, KEY_ON_UPDATE);
addAidlCallback(callback, KEY_ON_UPDATE);
startRemoteUpdates(updateTimeMS, aidlCallbackId, callback);
return aidlCallbackId;
} else {
@ -1012,18 +1028,17 @@ public class OsmandAidlService extends Service {
@Override
public long registerForNavigationUpdates(ANavigationUpdateParams params, final IOsmAndAidlCallback callback) {
try {
aidlCallbackId++;
OsmandAidlApi api = getApi("registerForNavUpdates");
if (api != null ) {
if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) {
api.unregisterFromUpdates(params.getCallbackId());
removeAidlCallback(params.getCallbackId());
return -1;
} 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 {
return -1;
}
@ -1034,6 +1049,7 @@ public class OsmandAidlService extends Service {
}
};
public static class AidlCallbackParams {
private IOsmAndAidlCallback callback;
private long key;
@ -1060,4 +1076,6 @@ public class OsmandAidlService extends Service {
this.key = key;
}
}
}

View file

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