Added aidl for markers and widgets

This commit is contained in:
Alexey Kulish 2017-04-22 22:54:51 +03:00
parent ece6dd79aa
commit 364f11d6b5
45 changed files with 1697 additions and 7 deletions

View file

@ -714,6 +714,13 @@
</intent-filter> </intent-filter>
</service> </service>
<service android:name="net.osmand.aidl.OsmandAidlService" android:exported="true" >
<intent-filter>
<action android:name="net.osmand.aidl.OsmandAidlService"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
<receiver android:name="net.osmand.plus.OnNavigationServiceAlarmReceiver" /> <receiver android:name="net.osmand.plus.OnNavigationServiceAlarmReceiver" />
<receiver android:name="net.osmand.plus.notifications.NotificationDismissReceiver" /> <receiver android:name="net.osmand.plus.notifications.NotificationDismissReceiver" />

View file

@ -0,0 +1,3 @@
package net.osmand.aidl;
parcelable ALatLon;

View file

@ -0,0 +1,83 @@
package net.osmand.aidl;
import android.os.Parcel;
import android.os.Parcelable;
public class ALatLon implements Parcelable {
private double longitude;
private double latitude;
public ALatLon(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public ALatLon(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<ALatLon> CREATOR = new
Parcelable.Creator<ALatLon>() {
public ALatLon createFromParcel(Parcel in) {
return new ALatLon(in);
}
public ALatLon[] newArray(int size) {
return new ALatLon[size];
}
};
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int temp;
temp = (int)Math.floor(latitude * 10000);
result = prime * result + temp;
temp = (int)Math.floor(longitude * 10000);
result = prime * result + temp;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ALatLon other = (ALatLon) obj;
return Math.abs(latitude - other.latitude) < 0.00001
&& Math.abs(longitude - other.longitude) < 0.00001;
}
@Override
public String toString() {
return "Lat " + ((float)latitude) + " Lon " + ((float)longitude);
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(latitude);
out.writeDouble(longitude);
}
public void readFromParcel(Parcel in) {
latitude = in.readDouble();
longitude = in.readDouble();
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,43 @@
package net.osmand.aidl;
import net.osmand.aidl.ALatLon;
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.mapwidget.AMapWidget;
import net.osmand.aidl.mapwidget.AddMapWidgetParams;
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams;
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams;
import net.osmand.aidl.maplayer.point.AMapPoint;
import net.osmand.aidl.maplayer.point.AddMapPointParams;
import net.osmand.aidl.maplayer.point.RemoveMapPointParams;
import net.osmand.aidl.maplayer.point.UpdateMapPointParams;
import net.osmand.aidl.maplayer.AMapLayer;
import net.osmand.aidl.maplayer.AddMapLayerParams;
import net.osmand.aidl.maplayer.RemoveMapLayerParams;
import net.osmand.aidl.maplayer.UpdateMapLayerParams;
interface IOsmAndAidlInterface {
boolean addMapMarker(in AddMapMarkerParams params);
boolean removeMapMarker(in RemoveMapMarkerParams params);
boolean updateMapMarker(in UpdateMapMarkerParams params);
boolean addMapWidget(in AddMapWidgetParams params);
boolean removeMapWidget(in RemoveMapWidgetParams params);
boolean updateMapWidget(in UpdateMapWidgetParams params);
boolean addMapPoint(in AddMapPointParams params);
boolean removeMapPoint(in RemoveMapPointParams params);
boolean updateMapPoint(in UpdateMapPointParams params);
boolean addMapLayer(in AddMapLayerParams params);
boolean removeMapLayer(in RemoveMapLayerParams params);
boolean updateMapLayer(in UpdateMapLayerParams params);
boolean calculateRoute(in CalculateRouteParams params);
}

View file

@ -0,0 +1,283 @@
package net.osmand.aidl;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.View;
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.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.util.Algorithms;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class OsmandAidlApi {
private static final String AIDL_REFRESH_MAP = "aidl_refresh_map";
private static final String AIDL_ADD_MAP_WIDGET = "aidl_add_map_widget";
private static final String AIDL_REMOVE_MAP_WIDGET = "aidl_remove_map_widget";
private static final String AIDL_MAP_WIDGET_ID = "aidl_map_widget_id";
private OsmandApplication app;
private Map<String, AMapWidget> widgets = new ConcurrentHashMap<>();
private Map<String, TextInfoWidget> widgetControls = new ConcurrentHashMap<>();
private BroadcastReceiver refreshMapReceiver;
private BroadcastReceiver addMapWidgetReceiver;
private BroadcastReceiver removeMapWidgetReceiver;
public OsmandAidlApi(OsmandApplication app) {
this.app = app;
}
public void onCreateMapActivity(final MapActivity mapActivity) {
registerRefreshMapReceiver(mapActivity);
registerAddMapWidgetReceiver(mapActivity);
registerRemoveMapWidgetReceiver(mapActivity);
}
public void onDestroyMapActivity(final MapActivity mapActivity) {
if (refreshMapReceiver != null) {
mapActivity.unregisterReceiver(refreshMapReceiver);
}
if (addMapWidgetReceiver != null) {
mapActivity.unregisterReceiver(addMapWidgetReceiver);
}
if (removeMapWidgetReceiver != null) {
mapActivity.unregisterReceiver(removeMapWidgetReceiver);
}
widgetControls.clear();
}
private void registerRefreshMapReceiver(final MapActivity mapActivity) {
refreshMapReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mapActivity.refreshMap();
}
};
mapActivity.registerReceiver(refreshMapReceiver, new IntentFilter(AIDL_REFRESH_MAP));
}
private int getDrawableId(String id) {
if (Algorithms.isEmpty(id)) {
return 0;
} else {
return app.getResources().getIdentifier(id, "drawable", app.getPackageName());
}
}
private void registerAddMapWidgetReceiver(final MapActivity mapActivity) {
addMapWidgetReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String widgetId = intent.getStringExtra(AIDL_MAP_WIDGET_ID);
if (widgetId != null) {
AMapWidget widget = widgets.get(widgetId);
if (widget != null) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
if (layer != null) {
TextInfoWidget control = createWidgetControl(mapActivity, widgetId);
widgetControls.put(widgetId, control);
int menuIconId = getDrawableId(widget.getMenuIconName());
MapWidgetRegInfo widgetInfo = layer.registerSideWidget(control,
menuIconId, widget.getMenuTitle(), "aidl_widget_" + widgetId,
false, widget.getOrder());
if (!mapActivity.getMapLayers().getMapWidgetRegistry().isVisible(widgetInfo.key)) {
mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(widgetInfo, true, false);
}
layer.recreateControls();
}
}
}
}
};
mapActivity.registerReceiver(addMapWidgetReceiver, new IntentFilter(AIDL_ADD_MAP_WIDGET));
}
private void registerRemoveMapWidgetReceiver(final MapActivity mapActivity) {
removeMapWidgetReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String widgetId = intent.getStringExtra(AIDL_MAP_WIDGET_ID);
if (widgetId != null) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
TextInfoWidget widgetControl = widgetControls.get(widgetId);
if (layer != null && widgetControl != null) {
layer.removeSideWidget(widgetControl);
widgetControls.remove(widgetId);
layer.recreateControls();
}
}
}
};
mapActivity.registerReceiver(removeMapWidgetReceiver, new IntentFilter(AIDL_REMOVE_MAP_WIDGET));
}
public void registerWidgetControls(MapActivity mapActivity) {
for (AMapWidget widget : widgets.values()) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
if (layer != null) {
TextInfoWidget control = createWidgetControl(mapActivity, widget.getId());
widgetControls.put(widget.getId(), control);
int menuIconId = getDrawableId(widget.getMenuIconName());
MapWidgetRegInfo widgetInfo = layer.registerSideWidget(control,
menuIconId, widget.getMenuTitle(), "aidl_widget_" + widget.getId(),
false, widget.getOrder());
if (!mapActivity.getMapLayers().getMapWidgetRegistry().isVisible(widgetInfo.key)) {
mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(widgetInfo, true, false);
}
}
}
}
private void refreshMap() {
Intent intent = new Intent();
intent.setAction(AIDL_REFRESH_MAP);
app.sendBroadcast(intent);
}
public TextInfoWidget createWidgetControl(final MapActivity mapActivity, final String widgetId) {
final TextInfoWidget control = new TextInfoWidget(mapActivity) {
@Override
public boolean updateInfo(DrawSettings drawSettings) {
AMapWidget widget = widgets.get(widgetId);
if (widget != null) {
String txt = widget.getText();
String subtxt = widget.getDescription();
boolean night = drawSettings != null && drawSettings.isNightMode();
int icon = night ? getDrawableId(widget.getDarkIconName()) : getDrawableId(widget.getLightIconName());
setText(txt, subtxt);
if (icon != 0) {
setImageDrawable(icon);
} else {
setImageDrawable(null);
}
return true;
} else {
return false;
}
}
};
control.updateInfo(null);
control.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AMapWidget widget = widgets.get(widgetId);
if (widget != null && widget.getIntentOnClick() != null) {
app.startActivity(widget.getIntentOnClick());
}
}
});
return control;
}
boolean addMapMarker(AMapMarker marker) {
if (marker != null) {
PointDescription pd = new PointDescription(
PointDescription.POINT_TYPE_MAP_MARKER, marker.getName() != null ? marker.getName() : "");
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
markersHelper.addMapMarker(new LatLon(marker.getLatLon().getLatitude(), marker.getLatLon().getLongitude()), pd);
refreshMap();
return true;
} else {
return false;
}
}
boolean removeMapMarker(AMapMarker marker) {
if (marker != null) {
LatLon latLon = new LatLon(marker.getLatLon().getLatitude(), marker.getLatLon().getLongitude());
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
for (MapMarker m : mapMarkers) {
if (m.getOnlyName().equals(marker.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
markersHelper.removeMapMarker(m);
refreshMap();
return true;
}
}
return false;
} else {
return false;
}
}
boolean updateMapMarker(AMapMarker markerPrev, AMapMarker markerNew) {
if (markerPrev != null && markerNew != null) {
LatLon latLon = new LatLon(markerPrev.getLatLon().getLatitude(), markerPrev.getLatLon().getLongitude());
LatLon latLonNew = new LatLon(markerNew.getLatLon().getLatitude(), markerNew.getLatLon().getLongitude());
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
for (MapMarker m : mapMarkers) {
if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
PointDescription pd = new PointDescription(
PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : "");
MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index);
markersHelper.moveMapMarker(marker, latLonNew);
refreshMap();
return true;
}
}
return false;
} else {
return false;
}
}
boolean addMapWidget(AMapWidget widget) {
if (widget != null) {
if (widgets.containsKey(widget.getId())) {
updateMapWidget(widget);
} else {
widgets.put(widget.getId(), widget);
Intent intent = new Intent();
intent.setAction(AIDL_ADD_MAP_WIDGET);
intent.putExtra(AIDL_MAP_WIDGET_ID, widget.getId());
app.sendBroadcast(intent);
}
refreshMap();
return true;
} else {
return false;
}
}
boolean removeMapWidget(String widgetId) {
if (!Algorithms.isEmpty(widgetId) && widgets.containsKey(widgetId)) {
widgets.remove(widgetId);
Intent intent = new Intent();
intent.setAction(AIDL_REMOVE_MAP_WIDGET);
intent.putExtra(AIDL_MAP_WIDGET_ID, widgetId);
app.sendBroadcast(intent);
return true;
} else {
return false;
}
}
boolean updateMapWidget(AMapWidget widget) {
if (widget != null && widgets.containsKey(widget.getId())) {
widgets.put(widget.getId(), widget);
refreshMap();
return true;
} else {
return false;
}
}
}

View file

@ -0,0 +1,176 @@
package net.osmand.aidl;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import net.osmand.aidl.calculateroute.CalculateRouteParams;
import net.osmand.aidl.maplayer.AddMapLayerParams;
import net.osmand.aidl.maplayer.RemoveMapLayerParams;
import net.osmand.aidl.maplayer.UpdateMapLayerParams;
import net.osmand.aidl.maplayer.point.AddMapPointParams;
import net.osmand.aidl.maplayer.point.RemoveMapPointParams;
import net.osmand.aidl.maplayer.point.UpdateMapPointParams;
import net.osmand.aidl.mapmarker.AddMapMarkerParams;
import net.osmand.aidl.mapmarker.RemoveMapMarkerParams;
import net.osmand.aidl.mapmarker.UpdateMapMarkerParams;
import net.osmand.aidl.mapwidget.AddMapWidgetParams;
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams;
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams;
import net.osmand.plus.OsmandApplication;
public class OsmandAidlService extends Service {
OsmandApplication getApp() {
return (OsmandApplication) getApplication();
}
OsmandAidlApi getApi() {
return getApp().getAidlApi();
}
@Override
public IBinder onBind(Intent intent) {
// Return the interface
return mBinder;
}
private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() {
@Override
public boolean addMapMarker(AddMapMarkerParams params) throws RemoteException {
try {
return params != null && getApi().addMapMarker(params.getMarker());
} catch (Exception e) {
return false;
}
}
@Override
public boolean removeMapMarker(RemoveMapMarkerParams params) throws RemoteException {
try {
return params != null && getApi().removeMapMarker(params.getMarker());
} catch (Exception e) {
return false;
}
}
@Override
public boolean updateMapMarker(UpdateMapMarkerParams params) throws RemoteException {
try {
return params != null && getApi().updateMapMarker(params.getMarkerPrev(), params.getMarkerNew());
} catch (Exception e) {
return false;
}
}
@Override
public boolean addMapWidget(AddMapWidgetParams params) throws RemoteException {
try {
return params != null && getApi().addMapWidget(params.getWidget());
} catch (Exception e) {
return false;
}
}
@Override
public boolean removeMapWidget(RemoveMapWidgetParams params) throws RemoteException {
try {
return params != null && getApi().removeMapWidget(params.getId());
} catch (Exception e) {
return false;
}
}
@Override
public boolean updateMapWidget(UpdateMapWidgetParams params) throws RemoteException {
try {
return params != null && getApi().updateMapWidget(params.getWidget());
} catch (Exception e) {
return false;
}
}
@Override
public boolean addMapPoint(AddMapPointParams params) throws RemoteException {
return false;
}
@Override
public boolean removeMapPoint(RemoveMapPointParams params) throws RemoteException {
return false;
}
@Override
public boolean updateMapPoint(UpdateMapPointParams params) throws RemoteException {
return false;
}
@Override
public boolean addMapLayer(AddMapLayerParams params) throws RemoteException {
return false;
}
@Override
public boolean removeMapLayer(RemoveMapLayerParams params) throws RemoteException {
return false;
}
@Override
public boolean updateMapLayer(UpdateMapLayerParams params) throws RemoteException {
return false;
}
@Override
public boolean calculateRoute(CalculateRouteParams params) throws RemoteException {
if (params == null || params.getEndPoint() == null) {
return false;
} else {
/*
final TargetPointsHelper targets = app.getTargetPointsHelper();
targets.removeAllWayPoints(false, true);
List<ALatLon> intermediatePoints = params.getIntermediatePoints();
List<String> intermediateNames = params.getIntermediateNames();
ALatLon intermediatePoint;
String intermediateName;
for (int i = 0; i < intermediatePoints.size(); i++ ) {
intermediatePoint = intermediatePoints.get(i);
if (i < intermediateNames.size()) {
intermediateName = intermediateNames.get(i);
} else {
intermediateName = "";
}
if (intermediateName == null) {
intermediateName = "";
}
targets.navigateToPoint(
new LatLon(intermediatePoint.getLatitude(), intermediatePoint.getLongitude()),
false, -1, new PointDescription(PointDescription.POINT_TYPE_LOCATION, intermediateName));
}
PointDescription endPointDescription = null;
if (params.getEndPointName() != null) {
endPointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, params.getEndPointName());
}
targets.navigateToPoint(
new LatLon(params.getEndPoint().getLatitude(), params.getEndPoint().getLongitude()),
true, -1, endPointDescription);
LatLon startPoint = null;
if (params.getStartPoint() != null) {
startPoint = new LatLon(params.getStartPoint().getLatitude(), params.getStartPoint().getLongitude());
}
PointDescription startPointDescription = null;
if (params.getStartPointName() != null) {
startPointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, params.getStartPointName());
}
//mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, startPoint, startPointDescription, true, false);
*/
return true;
}
}
};
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.calculateroute;
parcelable CalculateRouteParams;

View file

@ -0,0 +1,100 @@
package net.osmand.aidl.calculateroute;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.aidl.ALatLon;
import java.util.ArrayList;
import java.util.List;
public class CalculateRouteParams implements Parcelable {
private ALatLon startPoint;
private String startPointName;
private ALatLon endPoint;
private String endPointName;
private List<ALatLon> intermediatePoints = new ArrayList<>();
private List<String> intermediateNames = new ArrayList<>();
public CalculateRouteParams(ALatLon startPoint, String startPointName,
ALatLon endPoint, String endPointName,
List<ALatLon> intermediatePoints, List<String> intermediateNames) {
if (endPoint == null) {
throw new IllegalArgumentException("endPoint cannot be null");
}
this.startPoint = startPoint;
this.startPointName = startPointName;
this.endPoint = endPoint;
this.endPointName = endPointName;
if (intermediatePoints != null) {
this.intermediatePoints.addAll(intermediatePoints);
}
if (intermediateNames != null) {
this.intermediateNames.addAll(intermediateNames);
}
}
public CalculateRouteParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<CalculateRouteParams> CREATOR = new
Parcelable.Creator<CalculateRouteParams>() {
public CalculateRouteParams createFromParcel(Parcel in) {
return new CalculateRouteParams(in);
}
public CalculateRouteParams[] newArray(int size) {
return new CalculateRouteParams[size];
}
};
public ALatLon getStartPoint() {
return startPoint;
}
public String getStartPointName() {
return startPointName;
}
public ALatLon getEndPoint() {
return endPoint;
}
public String getEndPointName() {
return endPointName;
}
public List<ALatLon> getIntermediatePoints() {
return intermediatePoints;
}
public List<String> getIntermediateNames() {
return intermediateNames;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(startPoint, flags);
out.writeString(startPointName);
out.writeParcelable(endPoint, flags);
out.writeString(endPointName);
out.writeTypedList(intermediatePoints);
out.writeStringList(intermediateNames);
}
private void readFromParcel(Parcel in) {
startPoint = in.readParcelable(ALatLon.class.getClassLoader());
startPointName = in.readString();
endPoint = in.readParcelable(ALatLon.class.getClassLoader());
endPointName = in.readString();
in.readTypedList(intermediatePoints, ALatLon.CREATOR);
in.readStringList(intermediateNames);
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer;
parcelable AMapLayer;

View file

@ -0,0 +1,63 @@
package net.osmand.aidl.maplayer;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.aidl.maplayer.point.AMapPoint;
import java.util.HashMap;
public class AMapLayer implements Parcelable {
private String id;
private String name;
private HashMap<String, AMapPoint> points = new HashMap<>();
public AMapLayer(String id, String name, HashMap<String, AMapPoint> points) {
this.id = id;
this.name = name;
this.points = points;
}
public AMapLayer(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AMapLayer> CREATOR = new
Parcelable.Creator<AMapLayer>() {
public AMapLayer createFromParcel(Parcel in) {
return new AMapLayer(in);
}
public AMapLayer[] newArray(int size) {
return new AMapLayer[size];
}
};
public String getId() {
return id;
}
public String getName() {
return name;
}
public HashMap<String, AMapPoint> getPoints() {
return points;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(id);
out.writeString(name);
out.writeMap(points);
}
private void readFromParcel(Parcel in) {
id = in.readString();
name = in.readString();
in.readMap(points, HashMap.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer;
parcelable AddMapLayerParams;

View file

@ -0,0 +1,43 @@
package net.osmand.aidl.maplayer;
import android.os.Parcel;
import android.os.Parcelable;
public class AddMapLayerParams implements Parcelable {
private AMapLayer layer;
public AddMapLayerParams(AMapLayer layer) {
this.layer = layer;
}
public AddMapLayerParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AddMapLayerParams> CREATOR = new
Parcelable.Creator<AddMapLayerParams>() {
public AddMapLayerParams createFromParcel(Parcel in) {
return new AddMapLayerParams(in);
}
public AddMapLayerParams[] newArray(int size) {
return new AddMapLayerParams[size];
}
};
public AMapLayer getLayer() {
return layer;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(layer, flags);
}
private void readFromParcel(Parcel in) {
layer = in.readParcelable(AMapLayer.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer;
parcelable RemoveMapLayerParams;

View file

@ -0,0 +1,43 @@
package net.osmand.aidl.maplayer;
import android.os.Parcel;
import android.os.Parcelable;
public class RemoveMapLayerParams implements Parcelable {
private String id;
public RemoveMapLayerParams(String id) {
this.id = id;
}
public RemoveMapLayerParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<RemoveMapLayerParams> CREATOR = new
Parcelable.Creator<RemoveMapLayerParams>() {
public RemoveMapLayerParams createFromParcel(Parcel in) {
return new RemoveMapLayerParams(in);
}
public RemoveMapLayerParams[] newArray(int size) {
return new RemoveMapLayerParams[size];
}
};
public String getId() {
return id;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(id);
}
private void readFromParcel(Parcel in) {
id = in.readString();
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer;
parcelable UpdateMapLayerParams;

View file

@ -0,0 +1,43 @@
package net.osmand.aidl.maplayer;
import android.os.Parcel;
import android.os.Parcelable;
public class UpdateMapLayerParams implements Parcelable {
private AMapLayer layer;
public UpdateMapLayerParams(AMapLayer layer) {
this.layer = layer;
}
public UpdateMapLayerParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<UpdateMapLayerParams> CREATOR = new
Parcelable.Creator<UpdateMapLayerParams>() {
public UpdateMapLayerParams createFromParcel(Parcel in) {
return new UpdateMapLayerParams(in);
}
public UpdateMapLayerParams[] newArray(int size) {
return new UpdateMapLayerParams[size];
}
};
public AMapLayer getLayer() {
return layer;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(layer, flags);
}
private void readFromParcel(Parcel in) {
layer = in.readParcelable(AMapLayer.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer.point;
parcelable AMapPoint;

View file

@ -0,0 +1,77 @@
package net.osmand.aidl.maplayer.point;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.aidl.ALatLon;
public class AMapPoint implements Parcelable {
private String id;
private String shortName;
private String fullName;
private int color;
private ALatLon location;
public AMapPoint(String id, String shortName, String fullName, int color, ALatLon location) {
this.id = id;
this.shortName = shortName;
this.fullName = fullName;
this.color = color;
this.location = location;
}
public AMapPoint(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AMapPoint> CREATOR = new
Parcelable.Creator<AMapPoint>() {
public AMapPoint createFromParcel(Parcel in) {
return new AMapPoint(in);
}
public AMapPoint[] newArray(int size) {
return new AMapPoint[size];
}
};
public String getId() {
return id;
}
public String getShortName() {
return shortName;
}
public String getFullName() {
return fullName;
}
public int getColor() {
return color;
}
public ALatLon getLocation() {
return location;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(id);
out.writeString(shortName);
out.writeString(fullName);
out.writeInt(color);
out.writeParcelable(location, flags);
}
private void readFromParcel(Parcel in) {
id = in.readString();
shortName = in.readString();
shortName = in.readString();
color = in.readInt();
location = in.readParcelable(ALatLon.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer.point;
parcelable AddMapPointParams;

View file

@ -0,0 +1,51 @@
package net.osmand.aidl.maplayer.point;
import android.os.Parcel;
import android.os.Parcelable;
public class AddMapPointParams implements Parcelable {
private String layerId;
private AMapPoint point;
public AddMapPointParams(String layerId, AMapPoint point) {
this.layerId = layerId;
this.point = point;
}
public AddMapPointParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AddMapPointParams> CREATOR = new
Parcelable.Creator<AddMapPointParams>() {
public AddMapPointParams createFromParcel(Parcel in) {
return new AddMapPointParams(in);
}
public AddMapPointParams[] newArray(int size) {
return new AddMapPointParams[size];
}
};
public String getLayerId() {
return layerId;
}
public AMapPoint getPoint() {
return point;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(layerId);
out.writeParcelable(point, flags);
}
private void readFromParcel(Parcel in) {
layerId = in.readString();
point = in.readParcelable(AMapPoint.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer.point;
parcelable RemoveMapPointParams;

View file

@ -0,0 +1,51 @@
package net.osmand.aidl.maplayer.point;
import android.os.Parcel;
import android.os.Parcelable;
public class RemoveMapPointParams implements Parcelable {
private String layerId;
private String pointId;
public RemoveMapPointParams(String layerId, String pointId) {
this.layerId = layerId;
this.pointId = pointId;
}
public RemoveMapPointParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<RemoveMapPointParams> CREATOR = new
Parcelable.Creator<RemoveMapPointParams>() {
public RemoveMapPointParams createFromParcel(Parcel in) {
return new RemoveMapPointParams(in);
}
public RemoveMapPointParams[] newArray(int size) {
return new RemoveMapPointParams[size];
}
};
public String getLayerId() {
return layerId;
}
public String getPointId() {
return pointId;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(layerId);
out.writeString(pointId);
}
private void readFromParcel(Parcel in) {
layerId = in.readString();
pointId = in.readString();
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.maplayer.point;
parcelable UpdateMapPointParams;

View file

@ -0,0 +1,51 @@
package net.osmand.aidl.maplayer.point;
import android.os.Parcel;
import android.os.Parcelable;
public class UpdateMapPointParams implements Parcelable {
private String layerId;
private AMapPoint point;
public UpdateMapPointParams(String layerId, AMapPoint point) {
this.layerId = layerId;
this.point = point;
}
public UpdateMapPointParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<UpdateMapPointParams> CREATOR = new
Parcelable.Creator<UpdateMapPointParams>() {
public UpdateMapPointParams createFromParcel(Parcel in) {
return new UpdateMapPointParams(in);
}
public UpdateMapPointParams[] newArray(int size) {
return new UpdateMapPointParams[size];
}
};
public String getLayerId() {
return layerId;
}
public AMapPoint getPoint() {
return point;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(layerId);
out.writeParcelable(point, flags);
}
private void readFromParcel(Parcel in) {
layerId = in.readString();
point = in.readParcelable(AMapPoint.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapmarker;
parcelable AMapMarker;

View file

@ -0,0 +1,63 @@
package net.osmand.aidl.mapmarker;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.aidl.ALatLon;
public class AMapMarker implements Parcelable {
private ALatLon latLon;
private String name;
public AMapMarker(ALatLon latLon, String name) {
if (latLon == null) {
throw new IllegalArgumentException("latLon cannot be null");
}
if (name == null) {
name = "";
}
this.latLon = latLon;
this.name = name;
}
public AMapMarker(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AMapMarker> CREATOR = new
Parcelable.Creator<AMapMarker>() {
public AMapMarker createFromParcel(Parcel in) {
return new AMapMarker(in);
}
public AMapMarker[] newArray(int size) {
return new AMapMarker[size];
}
};
public ALatLon getLatLon() {
return latLon;
}
public String getName() {
return name;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(latLon, flags);
out.writeString(name);
}
private void readFromParcel(Parcel in) {
latLon = in.readParcelable(ALatLon.class.getClassLoader());
name = in.readString();
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapmarker;
parcelable AddMapMarkerParams;

View file

@ -0,0 +1,44 @@
package net.osmand.aidl.mapmarker;
import android.os.Parcel;
import android.os.Parcelable;
public class AddMapMarkerParams implements Parcelable {
private AMapMarker marker;
public AddMapMarkerParams(AMapMarker marker) {
this.marker = marker;
}
public AddMapMarkerParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AddMapMarkerParams> CREATOR = new
Parcelable.Creator<AddMapMarkerParams>() {
public AddMapMarkerParams createFromParcel(Parcel in) {
return new AddMapMarkerParams(in);
}
public AddMapMarkerParams[] newArray(int size) {
return new AddMapMarkerParams[size];
}
};
public AMapMarker getMarker() {
return marker;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(marker, flags);
}
private void readFromParcel(Parcel in) {
marker = in.readParcelable(AMapMarker.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapmarker;
parcelable RemoveMapMarkerParams;

View file

@ -0,0 +1,44 @@
package net.osmand.aidl.mapmarker;
import android.os.Parcel;
import android.os.Parcelable;
public class RemoveMapMarkerParams implements Parcelable {
private AMapMarker marker;
public RemoveMapMarkerParams(AMapMarker marker) {
this.marker = marker;
}
public RemoveMapMarkerParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<RemoveMapMarkerParams> CREATOR = new
Parcelable.Creator<RemoveMapMarkerParams>() {
public RemoveMapMarkerParams createFromParcel(Parcel in) {
return new RemoveMapMarkerParams(in);
}
public RemoveMapMarkerParams[] newArray(int size) {
return new RemoveMapMarkerParams[size];
}
};
public AMapMarker getMarker() {
return marker;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(marker, flags);
}
private void readFromParcel(Parcel in) {
marker = in.readParcelable(AMapMarker.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapmarker;
parcelable UpdateMapMarkerParams;

View file

@ -0,0 +1,52 @@
package net.osmand.aidl.mapmarker;
import android.os.Parcel;
import android.os.Parcelable;
public class UpdateMapMarkerParams implements Parcelable {
private AMapMarker markerPrev;
private AMapMarker markerNew;
public UpdateMapMarkerParams(AMapMarker markerPrev, AMapMarker markerNew) {
this.markerPrev = markerPrev;
this.markerNew = markerNew;
}
public UpdateMapMarkerParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<UpdateMapMarkerParams> CREATOR = new
Parcelable.Creator<UpdateMapMarkerParams>() {
public UpdateMapMarkerParams createFromParcel(Parcel in) {
return new UpdateMapMarkerParams(in);
}
public UpdateMapMarkerParams[] newArray(int size) {
return new UpdateMapMarkerParams[size];
}
};
public AMapMarker getMarkerPrev() {
return markerPrev;
}
public AMapMarker getMarkerNew() {
return markerNew;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(markerPrev, flags);
out.writeParcelable(markerNew, flags);
}
private void readFromParcel(Parcel in) {
markerPrev = in.readParcelable(AMapMarker.class.getClassLoader());
markerNew = in.readParcelable(AMapMarker.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapwidget;
parcelable AMapWidget;

View file

@ -0,0 +1,110 @@
package net.osmand.aidl.mapwidget;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
public class AMapWidget implements Parcelable {
private String id;
private String menuIconName;
private String menuTitle;
private String lightIconName;
private String darkIconName;
private String text;
private String description;
private int order;
private Intent intentOnClick;
public AMapWidget(String id, String menuIconName, String menuTitle,
String lightIconName, String darkIconName, String text, String description,
int order, Intent intentOnClick) {
this.id = id;
this.menuIconName = menuIconName;
this.menuTitle = menuTitle;
this.lightIconName = lightIconName;
this.darkIconName = darkIconName;
this.text = text;
this.description = description;
this.order = order;
this.intentOnClick = intentOnClick;
}
public AMapWidget(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AMapWidget> CREATOR = new
Parcelable.Creator<AMapWidget>() {
public AMapWidget createFromParcel(Parcel in) {
return new AMapWidget(in);
}
public AMapWidget[] newArray(int size) {
return new AMapWidget[size];
}
};
public String getId() {
return id;
}
public String getMenuIconName() {
return menuIconName;
}
public String getMenuTitle() {
return menuTitle;
}
public String getLightIconName() {
return lightIconName;
}
public String getDarkIconName() {
return darkIconName;
}
public String getText() {
return text;
}
public String getDescription() {
return description;
}
public int getOrder() {
return order;
}
public Intent getIntentOnClick() {
return intentOnClick;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(id);
out.writeString(menuIconName);
out.writeString(menuTitle);
out.writeString(lightIconName);
out.writeString(darkIconName);
out.writeString(text);
out.writeString(description);
out.writeInt(order);
out.writeParcelable(intentOnClick, flags);
}
private void readFromParcel(Parcel in) {
id = in.readString();
menuIconName = in.readString();
menuTitle = in.readString();
lightIconName = in.readString();
darkIconName = in.readString();
text = in.readString();
description = in.readString();
order = in.readInt();
intentOnClick = in.readParcelable(Intent.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapwidget;
parcelable AddMapWidgetParams;

View file

@ -0,0 +1,43 @@
package net.osmand.aidl.mapwidget;
import android.os.Parcel;
import android.os.Parcelable;
public class AddMapWidgetParams implements Parcelable {
private AMapWidget widget;
public AddMapWidgetParams(AMapWidget widget) {
this.widget = widget;
}
public AddMapWidgetParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<AddMapWidgetParams> CREATOR = new
Parcelable.Creator<AddMapWidgetParams>() {
public AddMapWidgetParams createFromParcel(Parcel in) {
return new AddMapWidgetParams(in);
}
public AddMapWidgetParams[] newArray(int size) {
return new AddMapWidgetParams[size];
}
};
public AMapWidget getWidget() {
return widget;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(widget, flags);
}
private void readFromParcel(Parcel in) {
widget = in.readParcelable(AMapWidget.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapwidget;
parcelable RemoveMapWidgetParams;

View file

@ -0,0 +1,43 @@
package net.osmand.aidl.mapwidget;
import android.os.Parcel;
import android.os.Parcelable;
public class RemoveMapWidgetParams implements Parcelable {
private String id;
public RemoveMapWidgetParams(String id) {
this.id = id;
}
public RemoveMapWidgetParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<RemoveMapWidgetParams> CREATOR = new
Parcelable.Creator<RemoveMapWidgetParams>() {
public RemoveMapWidgetParams createFromParcel(Parcel in) {
return new RemoveMapWidgetParams(in);
}
public RemoveMapWidgetParams[] newArray(int size) {
return new RemoveMapWidgetParams[size];
}
};
public String getId() {
return id;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(id);
}
private void readFromParcel(Parcel in) {
id = in.readString();
}
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.mapwidget;
parcelable UpdateMapWidgetParams;

View file

@ -0,0 +1,43 @@
package net.osmand.aidl.mapwidget;
import android.os.Parcel;
import android.os.Parcelable;
public class UpdateMapWidgetParams implements Parcelable {
private AMapWidget widget;
public UpdateMapWidgetParams(AMapWidget widget) {
this.widget = widget;
}
public UpdateMapWidgetParams(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<UpdateMapWidgetParams> CREATOR = new
Parcelable.Creator<UpdateMapWidgetParams>() {
public UpdateMapWidgetParams createFromParcel(Parcel in) {
return new UpdateMapWidgetParams(in);
}
public UpdateMapWidgetParams[] newArray(int size) {
return new UpdateMapWidgetParams[size];
}
};
public AMapWidget getWidget() {
return widget;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(widget, flags);
}
private void readFromParcel(Parcel in) {
widget = in.readParcelable(AMapWidget.class.getClassLoader());
}
public int describeContents() {
return 0;
}
}

View file

@ -13,6 +13,7 @@ import android.support.v7.app.AlertDialog;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.map.OsmandRegions.RegionTranslation; import net.osmand.map.OsmandRegions.RegionTranslation;
@ -363,6 +364,7 @@ public class AppInitializer implements IProgress {
app.gpxDatabase = startupInit(new GPXDatabase(app), GPXDatabase.class); app.gpxDatabase = startupInit(new GPXDatabase(app), GPXDatabase.class);
app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.class); app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.class);
app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class); app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class);
app.aidlApi = startupInit(new OsmandAidlApi(app), OsmandAidlApi.class);
app.regions = startupInit(new OsmandRegions(), OsmandRegions.class); app.regions = startupInit(new OsmandRegions(), OsmandRegions.class);
updateRegionVars(); updateRegionVars();

View file

@ -27,6 +27,8 @@ import android.widget.Toast;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibilityPlugin;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.aidl.OsmandAidlService;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
@ -86,6 +88,8 @@ public class OsmandApplication extends MultiDexApplication {
NavigationService navigationService; NavigationService navigationService;
OsmandAidlApi aidlApi;
// start variables // start variables
ResourceManager resourceManager; ResourceManager resourceManager;
OsmAndLocationProvider locationProvider; OsmAndLocationProvider locationProvider;
@ -449,6 +453,10 @@ public class OsmandApplication extends MultiDexApplication {
this.navigationService = navigationService; this.navigationService = navigationService;
} }
public OsmandAidlApi getAidlApi() {
return aidlApi;
}
public void stopNavigation() { public void stopNavigation() {
if (locationProvider.getLocationSimulation().isRouteAnimating()) { if (locationProvider.getLocationSimulation().isRouteAnimating()) {
locationProvider.getLocationSimulation().stop(); locationProvider.getLocationSimulation().stop();

View file

@ -292,6 +292,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
screenOffReceiver = new ScreenOffReceiver(); screenOffReceiver = new ScreenOffReceiver();
registerReceiver(screenOffReceiver, filter); registerReceiver(screenOffReceiver, filter);
app.getAidlApi().onCreateMapActivity(this);
mIsDestroyed = false; mIsDestroyed = false;
} }
@ -964,6 +966,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
unregisterReceiver(screenOffReceiver); unregisterReceiver(screenOffReceiver);
app.getAidlApi().onDestroyMapActivity(this);
FailSafeFuntions.quitRouteRestoreDialog(); FailSafeFuntions.quitRouteRestoreDialog();
OsmandPlugin.onMapActivityDestroy(this); OsmandPlugin.onMapActivityDestroy(this);
getMyApplication().unsubscribeInitListener(initListener); getMyApplication().unsubscribeInitListener(initListener);

View file

@ -82,6 +82,7 @@ public class MapInfoLayer extends OsmandMapLayer {
expand = (ImageButton) map.findViewById(R.id.map_collapse_button); expand = (ImageButton) map.findViewById(R.id.map_collapse_button);
// update and create controls // update and create controls
registerAllControls(); registerAllControls();
map.getMyApplication().getAidlApi().registerWidgetControls(map);
recreateControls(); recreateControls();
} }
@ -92,6 +93,13 @@ public class MapInfoLayer extends OsmandMapLayer {
updateReg(calculateTextState(), reg); updateReg(calculateTextState(), reg);
} }
public MapWidgetRegInfo registerSideWidget(TextInfoWidget widget, int drawableMenu,
String message, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, drawableMenu, message, key, left, priorityOrder);
updateReg(calculateTextState(), reg);
return reg;
}
public void registerSideWidget(TextInfoWidget widget, WidgetState widgetState, String key, boolean left, int priorityOrder) { public void registerSideWidget(TextInfoWidget widget, WidgetState widgetState, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, widgetState, key, left, priorityOrder); MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, widgetState, key, left, priorityOrder);
updateReg(calculateTextState(), reg); updateReg(calculateTextState(), reg);

View file

@ -159,6 +159,23 @@ public class MapWidgetRegistry {
return ii; return ii;
} }
public MapWidgetRegInfo registerSideWidgetInternal(TextInfoWidget widget,
@DrawableRes int drawableMenu,
String message,
String key, boolean left, int priorityOrder) {
MapWidgetRegInfo ii = new MapWidgetRegInfo(key, widget, drawableMenu,
message, priorityOrder, left);
processVisibleModes(key, ii);
if (widget != null) {
widget.setContentTitle(message);
}
if (left) {
this.leftWidgetSet.add(ii);
} else {
this.rightWidgetSet.add(ii);
}
return ii;
}
public MapWidgetRegInfo registerSideWidgetInternal(TextInfoWidget widget, public MapWidgetRegInfo registerSideWidgetInternal(TextInfoWidget widget,
@DrawableRes int drawableMenu, @DrawableRes int drawableMenu,
@ -221,7 +238,7 @@ public class MapWidgetRegistry {
return elements != null && elements.contains(key); return elements != null && elements.contains(key);
} }
private void setVisibility(MapWidgetRegInfo m, boolean visible, boolean collapsed) { public void setVisibility(MapWidgetRegInfo m, boolean visible, boolean collapsed) {
ApplicationMode mode = settings.APPLICATION_MODE.get(); ApplicationMode mode = settings.APPLICATION_MODE.get();
defineDefaultSettingsElement(mode); defineDefaultSettingsElement(mode);
// clear everything // clear everything
@ -375,6 +392,9 @@ public class MapWidgetRegistry {
} }
public String getText(Context ctx, final ApplicationMode mode, final MapWidgetRegInfo r) { public String getText(Context ctx, final ApplicationMode mode, final MapWidgetRegInfo r) {
if (r.getMessage() != null) {
return (r.visibleCollapsed(mode) ? " + " : " ") + r.getMessage();
}
return (r.visibleCollapsed(mode) ? " + " : " ") + ctx.getString(r.getMessageId()); return (r.visibleCollapsed(mode) ? " + " : " ") + ctx.getString(r.getMessageId());
} }
@ -447,7 +467,7 @@ public class MapWidgetRegistry {
final boolean selected = r.visibleCollapsed(mode) || r.visible(mode); final boolean selected = r.visibleCollapsed(mode) || r.visible(mode);
final String desc = mapActivity.getString(R.string.shared_string_collapse); final String desc = mapActivity.getString(R.string.shared_string_collapse);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(r.getMessageId(), mapActivity) ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder()
.setIcon(r.getDrawableMenu()) .setIcon(r.getDrawableMenu())
.setSelected(selected) .setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
@ -519,7 +539,11 @@ public class MapWidgetRegistry {
} }
ContextMenuItem item = adapter.getItem(pos); ContextMenuItem item = adapter.getItem(pos);
item.setIcon(r.getDrawableMenu()); item.setIcon(r.getDrawableMenu());
item.setTitle(mapActivity.getResources().getString(r.getMessageId())); if (r.getMessage() != null) {
item.setTitle(r.getMessage());
} else {
item.setTitle(mapActivity.getResources().getString(r.getMessageId()));
}
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
return true; return true;
} }
@ -555,7 +579,13 @@ public class MapWidgetRegistry {
item.setDescription(visible && collapsed ? desc : null); item.setDescription(visible && collapsed ? desc : null);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
}).createItem()); });
if (r.getMessage() != null) {
itemBuilder.setTitle(r.getMessage());
} else {
itemBuilder.setTitleId(r.getMessageId(), mapActivity);
}
contextMenuAdapter.addItem(itemBuilder.createItem());
} }
} }
@ -566,6 +596,7 @@ public class MapWidgetRegistry {
private int drawableMenu; private int drawableMenu;
@StringRes @StringRes
private int messageId; private int messageId;
private String message;
private WidgetState widgetState; private WidgetState widgetState;
public final String key; public final String key;
public final boolean left; public final boolean left;
@ -584,6 +615,16 @@ public class MapWidgetRegistry {
this.left = left; this.left = left;
} }
public MapWidgetRegInfo(String key, TextInfoWidget widget, @DrawableRes int drawableMenu,
String message, int priorityOrder, boolean left) {
this.key = key;
this.widget = widget;
this.drawableMenu = drawableMenu;
this.message = message;
this.priorityOrder = priorityOrder;
this.left = left;
}
public MapWidgetRegInfo(String key, TextInfoWidget widget, WidgetState widgetState, public MapWidgetRegInfo(String key, TextInfoWidget widget, WidgetState widgetState,
int priorityOrder, boolean left) { int priorityOrder, boolean left) {
this.key = key; this.key = key;
@ -601,6 +642,10 @@ public class MapWidgetRegistry {
} }
} }
public String getMessage() {
return message;
}
public int getMessageId() { public int getMessageId() {
if (widgetState != null) { if (widgetState != null) {
return widgetState.getMenuTitleId(); return widgetState.getMenuTitleId();
@ -667,6 +712,9 @@ public class MapWidgetRegistry {
@Override @Override
public int hashCode() { public int hashCode() {
if (getMessage() != null) {
return getMessage().hashCode();
}
return getMessageId(); return getMessageId();
} }
@ -680,16 +728,27 @@ public class MapWidgetRegistry {
return false; return false;
} }
MapWidgetRegInfo other = (MapWidgetRegInfo) obj; MapWidgetRegInfo other = (MapWidgetRegInfo) obj;
if (getMessageId() == 0 && other.getMessageId() == 0) {
return key.equals(other.key);
}
return getMessageId() == other.getMessageId(); return getMessageId() == other.getMessageId();
} }
@Override @Override
public int compareTo(@NonNull MapWidgetRegInfo another) { public int compareTo(@NonNull MapWidgetRegInfo another) {
if (getMessageId() == another.getMessageId()) { if (getMessageId() == 0 && another.getMessageId() == 0) {
if (key.equals(another.key)) {
return 0;
}
} else if (getMessageId() == another.getMessageId()) {
return 0; return 0;
} }
if (priorityOrder == another.priorityOrder) { if (priorityOrder == another.priorityOrder) {
return getMessageId() - another.getMessageId(); if (getMessageId() == 0 && another.getMessageId() == 0) {
return key.compareTo(key);
} else {
return getMessageId() - another.getMessageId();
}
} }
return priorityOrder - another.priorityOrder; return priorityOrder - another.priorityOrder;
} }