Delete osmodroid code and add binary inspector ability to trace vrouting

This commit is contained in:
Victor Shcherb 2014-09-26 10:03:19 +02:00
parent be6cc1fa5b
commit fe84bf3a6f
7 changed files with 60 additions and 786 deletions

View file

@ -1,6 +1,7 @@
package net.osmand.binary; package net.osmand.binary;
import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.iterator.TLongIterator; import gnu.trove.iterator.TLongIterator;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
import gnu.trove.list.array.TLongArrayList; import gnu.trove.list.array.TLongArrayList;
@ -34,6 +35,8 @@ import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion; import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion;
import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiSubType; import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiSubType;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex; import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.AmenityType; import net.osmand.data.AmenityType;
@ -58,11 +61,13 @@ public class BinaryInspector {
if(args.length == 1 && "test".equals(args[0])) { if(args.length == 1 && "test".equals(args[0])) {
in.inspector(new String[]{ in.inspector(new String[]{
//"-vpoi", //"-vpoi",
"-vmap", "-vmapobjects", // "-vmap", "-vmapobjects",
// "-vrouting",
// "-vaddress", "-vcities", "-vstreets", "-vstreetgroups","-vbuildings", // "-vaddress", "-vcities", "-vstreets", "-vstreetgroups","-vbuildings",
//"-zoom=16", //"-zoom=16",
//"-bbox=4,55,7,50", //"-bbox=4,55,7,50",
"/home/victor/projects/osmand/osm-gen/Map.obf" "/home/victor/projects/osmand/osm-gen/Map.obf"
// "/home/victor/projects/osmand/osm-gen/Netherlands_europe.obf"
// "/home/victor/projects/osmand/osm-gen/World_basemap_2_b.obf___" // "/home/victor/projects/osmand/osm-gen/World_basemap_2_b.obf___"
// "/home/victor/projects/osmand/osm-gen/World_basemap_2.obf__" // "/home/victor/projects/osmand/osm-gen/World_basemap_2.obf__"
}); });
@ -106,6 +111,7 @@ public class BinaryInspector {
boolean vtransport; boolean vtransport;
boolean vpoi; boolean vpoi;
boolean vmap; boolean vmap;
boolean vrouting;
boolean vmapObjects; boolean vmapObjects;
boolean osm; boolean osm;
FileOutputStream osmOut = null; FileOutputStream osmOut = null;
@ -126,6 +132,11 @@ public class BinaryInspector {
public boolean isVmap() { public boolean isVmap() {
return vmap; return vmap;
} }
public boolean isVrouting() {
return vrouting;
}
public boolean isVpoi() { public boolean isVpoi() {
return vpoi; return vpoi;
} }
@ -150,6 +161,8 @@ public class BinaryInspector {
vintersections = true; vintersections = true;
} else if(params[i].equals("-vmap")){ } else if(params[i].equals("-vmap")){
vmap = true; vmap = true;
} else if(params[i].equals("-vrouting")){
vrouting = true;
} else if(params[i].equals("-vmapobjects")){ } else if(params[i].equals("-vmapobjects")){
vmapObjects = true; vmapObjects = true;
} else if(params[i].equals("-vpoi")){ } else if(params[i].equals("-vpoi")){
@ -451,6 +464,9 @@ public class BinaryInspector {
RouteRegion ri = ((RouteRegion) p); RouteRegion ri = ((RouteRegion) p);
println("\tBounds " + formatLatBounds(ri.getLeftLongitude(), ri.getRightLongitude(), println("\tBounds " + formatLatBounds(ri.getLeftLongitude(), ri.getRightLongitude(),
ri.getTopLatitude(), ri.getBottomLatitude())); ri.getTopLatitude(), ri.getBottomLatitude()));
if((vInfo != null && vInfo.isVrouting())){
printRouteDetailInfo(index, (RouteRegion) p);
}
} else if(p instanceof MapIndex){ } else if(p instanceof MapIndex){
MapIndex m = ((MapIndex) p); MapIndex m = ((MapIndex) p);
int j = 1; int j = 1;
@ -486,6 +502,45 @@ public class BinaryInspector {
} }
private void printRouteDetailInfo(BinaryMapIndexReader index, RouteRegion p) throws IOException {
final DamnCounter mapObjectsCounter = new DamnCounter();
final StringBuilder b = new StringBuilder();
List<RouteSubregion> regions = index.searchRouteIndexTree(
BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(vInfo.lonleft),
MapUtils.get31TileNumberX(vInfo.lonright), MapUtils.get31TileNumberY(vInfo.lattop),
MapUtils.get31TileNumberY(vInfo.latbottom), vInfo.getZoom(), null),
p.getSubregions());
index.loadRouteIndexData(regions, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject obj) {
mapObjectsCounter.value++;
b.setLength(0);
b.append("Road ");
b.append(obj.id);
for(int i = 0; i < obj.getTypes().length; i++) {
RouteTypeRule rr = obj.region.quickGetEncodingRule(obj.getTypes()[i]);
b.append(" ").append(rr.getTag()).append("='").append(rr.getValue()).append("'");
}
if (obj.getNames() != null) {
TIntObjectIterator<String> it = obj.getNames().iterator();
while (it.hasNext()) {
it.advance();
RouteTypeRule rr = obj.region.quickGetEncodingRule(it.key());
b.append(" ").append(rr.getTag()).append("='").append(it.value()).append("'");
}
}
println(b.toString());
return false;
}
@Override
public boolean isCancelled() {
return false;
}
});
println("\tTotal map objects: " + mapObjectsCounter.value);
}
private void printAddressDetailedInfo(VerboseInfo verbose, BinaryMapIndexReader index, AddressRegion region) throws IOException { private void printAddressDetailedInfo(VerboseInfo verbose, BinaryMapIndexReader index, AddressRegion region) throws IOException {
String[] cityType_String = new String[] { String[] cityType_String = new String[] {
"Cities/Towns section", "Cities/Towns section",

View file

@ -112,6 +112,8 @@ public class OsMoControlDevice implements OsMoReactor {
return true; return true;
} else if(command.equals("TP")) { } else if(command.equals("TP")) {
plugin.getDownloadGpxTask(true).execute(obj); plugin.getDownloadGpxTask(true).execute(obj);
} else if (command.equals("PP")) {
service.pushCommand("PP");
} }
return false; return false;
} }

View file

@ -168,9 +168,9 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
if (!pos.isEmpty()) { if (!pos.isEmpty()) {
StringBuilder res = new StringBuilder(); StringBuilder res = new StringBuilder();
for (OsMoDevice d : pos) { for (OsMoDevice d : pos) {
res.append(getObjectDescription(d)); res.append(getObjectDescription(d)).append("\n");
} }
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(view.getContext(), res.toString().trim(), Toast.LENGTH_LONG).show();
return true; return true;
} }
return false; return false;

View file

@ -1,8 +0,0 @@
package net.osmand.plus.osmodroid;
import net.osmand.plus.GPXUtilities.GPXFile;
public class ColoredGPX {
int color;
GPXFile gpxFile;
}

View file

@ -1,385 +0,0 @@
package net.osmand.plus.osmodroid;
import java.util.ArrayList;
import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.GPXLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
import android.content.DialogInterface;
/**
* Class represents a OsMoDroidlayer which depicts the position of Esya.ru channels objects
*
* @author Denis Fokin
* @see OsMoDroidPlugin
*
*/
public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
/**
* magic number so far
*/
private static final int radius = 10;
OsMoDroidPoint seekOsMoDroidPoint;
OsMoDroidPlugin myOsMoDroidPlugin;
private DisplayMetrics dm;
private final MapActivity map;
private OsmandMapTileView view;
private Paint textPaint;
ArrayList<OsMoDroidPoint> osMoDroidPointArrayList;
ArrayList<OsMoDroidPoint> osMoDroidFixedPointArrayList;
ArrayList<ColoredGPX> gpxArrayList = new ArrayList<ColoredGPX>() ;
int layerId;
String layerName;
String layerDescription;
private Paint paint;
private Path path;
private OsmandSettings settings;
private RenderingRulesStorage cachedRrs;
private boolean cachedNightMode;
private int cachedColor;
private void initUI() {
paint = new Paint();
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(14);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
paint.setStrokeJoin(Join.ROUND);
path = new Path();
}
private Bitmap opIcon;
public void refresh() {
map.refreshMap();
}
public OsMoDroidLayer(MapActivity map) {
this.map = map;
}
public OsMoDroidLayer(MapActivity map, int layerId, OsMoDroidPlugin osMoDroidPlugin, String layerName, String layerDescription) {
this.map = map;
this.layerId = layerId;
this.myOsMoDroidPlugin = osMoDroidPlugin;
this.layerName = layerName;
this.layerDescription = layerDescription;
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
textPaint = new Paint();
textPaint.setDither(true);
textPaint.setAntiAlias(true);
textPaint.setFilterBitmap(true);
textPaint.setTextSize(22f);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
textPaint.setTextAlign(Paint.Align.CENTER);
opIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.bicycle_location);
osMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId);
osMoDroidFixedPointArrayList = myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId);
initUI();
}
public void inGPXFilelist(ArrayList<ColoredGPX> in){
gpxArrayList=in;
map.refreshMap();
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
for (ColoredGPX cg : gpxArrayList){
List<List<WptPt>> points = cg.gpxFile.proccessPoints();
paint.setColor(cg.color);
final QuadRect latLonBounds = tileBox.getLatLonBounds();
for (List<WptPt> l : points) {
path.rewind();
int startIndex = -1;
for (int i = 0; i < l.size(); i++) {
WptPt ls = l.get(i);
if (startIndex == -1) {
if (ls.lat >= latLonBounds.bottom - 0.1 && ls.lat <= latLonBounds.top + 0.1 && ls.lon >= latLonBounds.left - 0.1
&& ls.lon <= latLonBounds.right + 0.1) {
startIndex = i > 0 ? i - 1 : i;
}
} else if (!(latLonBounds.left <= ls.lon + 0.1 && ls.lon - 0.1 <= latLonBounds.right
&& latLonBounds.bottom <= ls.lat + 0.1 && ls.lat - 0.1 <= latLonBounds.top)) {
drawSegment(canvas, tileBox, l, startIndex, i);
startIndex = -1;
}
}
if (startIndex != -1) {
drawSegment(canvas, tileBox, l, startIndex, l.size() - 1);
continue;
}
}
}
for (OsMoDroidPoint op : osMoDroidPointArrayList) {
if(seekOsMoDroidPoint!=null&&seekOsMoDroidPoint.equals(op)){
map.setMapLocation(op.latlon.getLatitude(), op.latlon.getLongitude());
}
LatLon newLatlon;
try {
newLatlon = new LatLon(myOsMoDroidPlugin.mIRemoteService.getObjectLat(layerId, op.id),
myOsMoDroidPlugin.mIRemoteService.getObjectLon(layerId, op.id));
if (!op.latlon.equals(newLatlon)) {
op.prevlatlon = op.latlon;
}
op.latlon = newLatlon;
op.speed = myOsMoDroidPlugin.mIRemoteService.getObjectSpeed(layerId, op.id);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
double latitude = op.latlon.getLatitude();
double longitude = op.latlon.getLongitude();
double prevlatitude = op.latlon.getLatitude();
double prevlongitude = op.latlon.getLongitude();
if (op.prevlatlon != null) {
prevlatitude = op.prevlatlon.getLatitude();
prevlongitude = op.prevlatlon.getLongitude();
}
int locationX = (int) tileBox.getPixXFromLatLon(latitude, longitude);
int locationY = (int) tileBox.getPixYFromLatLon(latitude, longitude);
int prevlocationX = (int) tileBox.getPixXFromLatLon(prevlatitude, prevlongitude);
int prevlocationY = (int) tileBox.getPixYFromLatLon(prevlatitude, prevlongitude);
// int y = opIcon.getHeight()/2;
// int x = opIcon.getWidth()/2;
textPaint.setColor(Color.parseColor("#013220"));
canvas.drawText(op.name, locationX, locationY - radius, textPaint);
canvas.drawText(op.speed, locationX, locationY - 2 * radius, textPaint);
textPaint.setColor(Color.parseColor("#" + op.color));
textPaint.setShadowLayer(radius, 0, 0, Color.GRAY);
canvas.drawCircle(locationX, locationY, radius, textPaint);
// canvas.drawBitmap(opIcon, locationX-x, locationY-y , textPaint);
textPaint.setStrokeWidth(radius);
canvas.drawLine(locationX, locationY, prevlocationX, prevlocationY, textPaint);
// canvas.rotate(-view.getRotate(), locationX, locationY);
// op.prevlatlon=op.latlon;
}
for (OsMoDroidPoint point : osMoDroidFixedPointArrayList ){
double latitude = point.latlon.getLatitude();
double longitude = point.latlon.getLongitude();
int locationX = (int) tileBox.getPixXFromLatLon(latitude, longitude);
int locationY = (int) tileBox.getPixYFromLatLon(latitude, longitude);
textPaint.setColor(Color.parseColor("#013220"));
canvas.drawText(point.name, locationX, locationY - radius, textPaint);
textPaint.setColor(Color.parseColor("#" + point.color));
textPaint.setShadowLayer(radius, 0, 0, Color.GRAY);
canvas.drawRect(new Rect(locationX-radius, locationY-radius, locationX+radius, locationY+radius), textPaint);
}
}
private void drawSegment(Canvas canvas, RotatedTileBox tb, List<WptPt> l, int startIndex, int endIndex) {
int px = (int) tb.getPixXFromLatLon(l.get(startIndex).lat, l.get(startIndex).lon);
int py = (int) tb.getPixYFromLatLon(l.get(startIndex).lat, l.get(startIndex).lon);
path.moveTo(px, py);
for (int i = startIndex + 1; i <= endIndex; i++) {
WptPt p = l.get(i);
int x = (int) tb.getPixXFromLatLon(p.lat,p.lon);
int y = (int) tb.getPixYFromLatLon(p.lat,p.lon);
path.lineTo(x, y);
}
canvas.drawPath(path, paint);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
public void getOsMoDroidPointFromPoint(RotatedTileBox tb,PointF point, List<? super OsMoDroidPoint> om) {
if (osMoDroidPointArrayList != null) {
int ex = (int) point.x;
int ey = (int) point.y;
try {
for (int i = 0; i < osMoDroidPointArrayList.size(); i++) {
OsMoDroidPoint n = osMoDroidPointArrayList.get(i);
if (!om.contains(n)) {
int x = (int) tb.getPixXFromLatLon(n.latlon.getLatitude(), n.latlon.getLongitude());
int y = (int) tb.getPixYFromLatLon(n.latlon.getLatitude(), n.latlon.getLongitude());
if (Math.abs(x - ex) <= opIcon.getWidth() && Math.abs(y - ey) <= opIcon.getHeight()) {
om.add(n);
}
}
}
} catch (IndexOutOfBoundsException e) {
// that's really rare case, but is much efficient than introduce
// synchronized block
}
}
if (osMoDroidFixedPointArrayList != null) {
int ex = (int) point.x;
int ey = (int) point.y;
try {
for (int i = 0; i <osMoDroidFixedPointArrayList.size(); i++) {
OsMoDroidPoint n =osMoDroidFixedPointArrayList.get(i);
if (!om.contains(n)) {
int x = (int) tb.getPixXFromLatLon(n.latlon.getLatitude(), n.latlon.getLongitude());
int y = (int) tb.getPixYFromLatLon(n.latlon.getLatitude(), n.latlon.getLongitude());
if (Math.abs(x - ex) <= opIcon.getWidth() && Math.abs(y - ey) <= opIcon.getHeight()) {
om.add(n);
}
}
}
} catch (IndexOutOfBoundsException e) {
// that's really rare case, but is much efficient than introduce
// synchronized block
}
}
}
@Override
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
if (o instanceof OsMoDroidPoint && ((OsMoDroidPoint) o).layerId == layerId) {
final OsMoDroidPoint a = (OsMoDroidPoint) o;
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
map.getMyApplication().getTargetPointsHelper().navigateToPoint(a.latlon, true, -1);
}
};
OnContextMenuClick seeklistener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if(seekOsMoDroidPoint!=null&&a.equals(seekOsMoDroidPoint))
{
seekOsMoDroidPoint=null;
isChecked=false;
} else
{
seekOsMoDroidPoint=a;
isChecked=true;
}
}
};
adapter.item(map.getString(R.string.get_directions)).listen(listener).reg();
adapter.item(map.getString(R.string.osmodroid_seek)).listen(seeklistener).reg();
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
List<OsMoDroidPoint> om = new ArrayList<OsMoDroidPoint>();
getOsMoDroidPointFromPoint(tileBox, point, om);
if (!om.isEmpty()) {
StringBuilder res = new StringBuilder();
for (int i = 0; i < om.size(); i++) {
OsMoDroidPoint n = om.get(i);
if (i > 0) {
res.append("\n\n");
}
res = res.append(n.description);
}
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return true;
}
@Override
public String getObjectName(Object o) {
if (o instanceof OsMoDroidPoint) {
return ((OsMoDroidPoint) o).name;
}
return null;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getOsMoDroidPointFromPoint(tileBox, point, o);
}
@Override
public LatLon getObjectLocation(Object o) {
if (o instanceof OsMoDroidPoint) {
return ((OsMoDroidPoint) o).latlon;
}
return null;
}
@Override
public String getObjectDescription(Object o) {
if (o instanceof OsMoDroidPoint) {
return ((OsMoDroidPoint) o).description;
}
return null;
}
}

View file

@ -1,350 +0,0 @@
package net.osmand.plus.osmodroid;
import java.io.File;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
import net.osmand.plus.views.OsmandMapTileView;
import org.apache.commons.logging.Log;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.AsyncTask;
import android.os.IBinder;
import android.os.RemoteException;
import com.OsMoDroid.IRemoteOsMoDroidListener;
import com.OsMoDroid.IRemoteOsMoDroidService;
public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoControlServices {
IRemoteOsMoDroidListener.Stub inter = new IRemoteOsMoDroidListener.Stub() {
@Override
public void channelUpdated() throws RemoteException {
if (activity != null) {
activity.refreshMap();
// test
}
}
@Override
public void channelsListUpdated() throws RemoteException {
if (activity != null && connected) {
log.debug("update channels");
for (OsMoDroidLayer myOsMoDroidLayer : osmoDroidLayerList) {
activity.getMapView().removeLayer(myOsMoDroidLayer);
}
osmoDroidLayerList.clear();
requestLayersFromOsMoDroid(activity);
for (OsMoDroidLayer myOsMoDroidLayer : osmoDroidLayerList) {
activity.getMapView().addLayer(myOsMoDroidLayer, 4.5f);
}
activity.refreshMap();
}
}
public void reRouteTo(LatLon loc) {
final OsmandApplication app = activity.getMyApplication();
final TargetPointsHelper targets = app.getTargetPointsHelper();
// If we are in following mode then just update target point
targets.navigateToPoint(loc, true, -1);
if(!app.getRoutingHelper().isFollowingMode()) {
// If we are not in following mode then request new route to calculate
// Use default application mode
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
FailSafeFuntions.enterRoutingMode(activity, null);
}
});
}
}
@Override
public void routeTo(float Lat, float Lon) throws RemoteException {
reRouteTo(new LatLon(Lat, Lon));
}
};
@Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
registerLayers(activity);
super.updateLayers(mapView, activity);
MonitoringInfoControl lock = activity.getMapLayers().getMapInfoLayer().getMonitoringInfoControl();
if(lock != null && !lock.getMonitorActions().contains(this)) {
lock.addMonitorActions(this);
}
}
MapActivity activity;
public static final String ID = "osmand.osmodroid";
private static final Log log = PlatformUtil.getLog(OsMoDroidPlugin.class);
private OsmandApplication app;
IRemoteOsMoDroidService mIRemoteService;
private ServiceConnection mConnection;
private int OSMODROID_SUPPORTED_VERSION_MIN = 5;
private OsMoDroidLayer osmoDroidLayer;
protected boolean connected = false;
ArrayList<OsMoDroidLayer> osmoDroidLayerList = new ArrayList<OsMoDroidLayer>();
private AsyncTask<Void, Void, Void> task;
public ArrayList<OsMoDroidPoint> getOsMoDroidPointArrayList(int id) {
ArrayList<OsMoDroidPoint> result = new ArrayList<OsMoDroidPoint>();
try {
for (int i = 0; i < mIRemoteService.getNumberOfObjects(id); i++) {
result.add(new OsMoDroidPoint(mIRemoteService.getObjectLat(id, mIRemoteService.getObjectId(id, i)), mIRemoteService
.getObjectLon(id, mIRemoteService.getObjectId(id, i)), mIRemoteService.getObjectName(id,
mIRemoteService.getObjectId(id, i)), mIRemoteService.getObjectDescription(id, mIRemoteService.getObjectId(id, i)),
mIRemoteService.getObjectId(id, i), id, mIRemoteService.getObjectSpeed(id, mIRemoteService.getObjectId(id, i)),
mIRemoteService.getObjectColor(id, mIRemoteService.getObjectId(id, i))));
}
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
return result;
}
public ArrayList<OsMoDroidPoint> getOsMoDroidFixedPointArrayList(int id) {
ArrayList<OsMoDroidPoint> result = new ArrayList<OsMoDroidPoint>();
try {
for (int i = 0; i < mIRemoteService.getNumberOfPoints(id); i++) {
result.add(new OsMoDroidPoint(mIRemoteService.getPointLat(id, mIRemoteService.getPointId(id, i)), mIRemoteService
.getPointLon(id, mIRemoteService.getPointId(id, i)), mIRemoteService.getPointName(id,
mIRemoteService.getPointId(id, i)), mIRemoteService.getPointDescription(id, mIRemoteService.getPointId(id, i)),
mIRemoteService.getPointId(id, i), id, null,
mIRemoteService.getPointColor(id, mIRemoteService.getPointId(id, i))));
}
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
return result;
}
@Override
public String getId() {
return ID;
}
public OsMoDroidPlugin(OsmandApplication app) {
this.app = app;
}
@Override
public String getDescription() {
return app.getString(R.string.osmodroid_plugin_description) + "\n External application.";
}
@Override
public String getName() {
return app.getString(R.string.osmodroid_plugin_name) + " (external)";
}
// test
@Override
public boolean init(final OsmandApplication app) {
mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mIRemoteService = IRemoteOsMoDroidService.Stub.asInterface(service);
try {
System.out.println(mIRemoteService.getVersion());
if (mIRemoteService.getVersion() < OSMODROID_SUPPORTED_VERSION_MIN) {
app.showToastMessage(R.string.osmodroid_plugin_old_ver_not_supported);
shutdown(app);
} else {
mIRemoteService.registerListener(inter);
connected = true;
}
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
connected = false;
mIRemoteService = null;
}
};
Intent serviceIntent = (new Intent("OsMoDroid.remote"));
app.bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
return true;
}
void requestLayersFromOsMoDroid(MapActivity activity) {
try {
for (int i = 0; i < mIRemoteService.getNumberOfLayers(); i++) {
osmoDroidLayerList.add(new OsMoDroidLayer(activity, mIRemoteService.getLayerId(i), this, mIRemoteService
.getLayerName(mIRemoteService.getLayerId(i)), mIRemoteService.getLayerDescription(mIRemoteService.getLayerId(i))));
}
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
getGpxArrayList();
}
@Override
public void registerLayers(MapActivity activity) {
this.activity = activity;
if (connected) {
for (OsMoDroidLayer myOsMoDroidLayer : osmoDroidLayerList) {
activity.getMapView().removeLayer(myOsMoDroidLayer);
}
osmoDroidLayerList.clear();
requestLayersFromOsMoDroid(activity);
for (OsMoDroidLayer myOsMoDroidLayer : osmoDroidLayerList) {
activity.getMapView().addLayer(myOsMoDroidLayer, 4.5f);
}
}
}
@Override
public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
for (OsMoDroidLayer myOsMoDroidLayer : osmoDroidLayerList) {
adapter.item(myOsMoDroidLayer.layerName).reg();
}
super.registerLayerContextMenuActions(mapView, adapter, mapActivity);
}
@Override
public void disable(OsmandApplication app) {
shutdown(app);
}
private void shutdown(OsmandApplication app) {
if (mIRemoteService != null) {
if (connected) {
try {
mIRemoteService.unregisterListener(inter);
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
}
app.unbindService(mConnection);
mIRemoteService = null;
}
}
@Override
public void addMonitorActions(final ContextMenuAdapter qa, final MonitoringInfoControl li, final OsmandMapTileView view) {
boolean o = true;
try {
o = mIRemoteService.isActive();
}
catch(Exception e) {
log.error(e.getMessage(), e);
}
final boolean off = !o;
qa.item(off ? R.string.osmodroid_mode_off : R.string.osmodroid_mode_on
).icon( off ? R.drawable.monitoring_rec_inactive : R.drawable.monitoring_rec_big).listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
try {
if (off) {
mIRemoteService.Activate();
} else {
mIRemoteService.Deactivate();
}
} catch(Exception e) {
log.error(e.getMessage(), e);
}
}
}).reg();
qa.item(R.string.osmodroid_refresh).icons(R.drawable.ic_action_grefresh_dark, R.drawable.ic_action_grefresh_light).listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked,
DialogInterface dialog) {
try {
mIRemoteService.refreshChannels();
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
}
}).reg();
qa.item(R.string.osmodroid_unseek).icons(R.drawable.abs__ic_commit_search_api_holo_dark, R.drawable.abs__ic_commit_search_api_holo_light).listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked,
DialogInterface dialog) {
for (OsMoDroidLayer l: osmoDroidLayerList){
l.seekOsMoDroidPoint=null;
}
}
}).reg();
}
public void getGpxArrayList() {
if(task!=null){
task.cancel(true);
}
task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
for (OsMoDroidLayer l : osmoDroidLayerList){
ArrayList<ColoredGPX> temp = new ArrayList<ColoredGPX>();
try {
for (int i = 0; i < mIRemoteService.getNumberOfGpx(l.layerId); i++) {
ColoredGPX cg = new ColoredGPX();
cg.gpxFile = GPXUtilities.loadGPXFile(app, new File(mIRemoteService.getGpxFile(l.layerId, i)));
cg.color = mIRemoteService.getGpxColor(l.layerId, i);
temp.add(cg);
}
l.inGPXFilelist(temp);
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
catch (ConcurrentModificationException e) {
log.error(e.getMessage(), e);
}
}
return null;
}
};
task.execute();
}
}

View file

@ -1,40 +0,0 @@
package net.osmand.plus.osmodroid;
import net.osmand.data.LatLon;
public class OsMoDroidPoint {
@Override
public boolean equals(Object o) {
if ((o instanceof OsMoDroidPoint) && this.id == ((OsMoDroidPoint) o).id) {
return true;
} else {
return false;
}
}
LatLon latlon;
LatLon prevlatlon;
String name;
String description;
int id;
int layerId;
String speed = "";
String color = "AAAAAA";
public OsMoDroidPoint(float objectLat, float objectLon, String objectName, String objectDescription, int objectId,
int layerId, String speed, String color) {
this.latlon = new LatLon(objectLat, objectLon);
this.name = objectName;
this.description = objectDescription;
this.id = objectId;
this.layerId = layerId;
if (speed != null) {
this.speed = speed;
}
if (color != null) {
this.color = color;
}
}
}