Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2013-11-25 14:43:32 +01:00
commit 24f754a48a
3 changed files with 123 additions and 2 deletions

View file

@ -41,6 +41,10 @@ String getObjectName(int layerId, int objectId);
String getObjectDescription(int layerId, int objectId);
String getObjectColor(int layerId, int objectId);
int getNumberOfGpx(int layerId);
String getGpxFile (int layerId, int pos);
void refreshChannels();
}

View file

@ -5,21 +5,32 @@ 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.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;
@ -49,10 +60,31 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
private Paint textPaint;
ArrayList<OsMoDroidPoint> OsMoDroidPointArrayList;
ArrayList<GPXFile> gpxArrayList;
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() {
@ -69,6 +101,7 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
this.myOsMoDroidPlugin = osMoDroidPlugin;
this.layerName = layerName;
this.layerDescription = layerDescription;
}
@ -88,7 +121,8 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
textPaint.setTextAlign(Paint.Align.CENTER);
opIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.bicycle_location);
OsMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId);
gpxArrayList = myOsMoDroidPlugin.getGpxArrayList(layerId);
initUI();
}
@ -141,10 +175,73 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
canvas.drawLine(locationX, locationY, prevlocationX, prevlocationY, textPaint);
// canvas.rotate(-view.getRotate(), locationX, locationY);
// op.prevlatlon=op.latlon;
}
for (GPXFile gpxFile : gpxArrayList){
gpxFile.proccessPoints();
List<List<WptPt>> points = gpxFile.processedPointsToDisplay;
paint.setColor(getColor(settings));
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;
}
}
}
}
private void drawSegment(Canvas canvas, RotatedTileBox tb, List<WptPt> l, int startIndex, int endIndex) {
int px = tb.getPixXFromLonNoRot(l.get(startIndex).lon);
int py = tb.getPixYFromLatNoRot(l.get(startIndex).lat);
path.moveTo(px, py);
for (int i = startIndex + 1; i <= endIndex; i++) {
WptPt p = l.get(i);
int x = tb.getPixXFromLonNoRot(p.lon);
int y = tb.getPixYFromLatNoRot(p.lat);
path.lineTo(x, y);
}
canvas.drawPath(path, paint);
}
private int getColor(DrawSettings nightMode){
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
boolean n = nightMode != null && nightMode.isNightMode();
if (rrs != cachedRrs || cachedNightMode != n) {
cachedRrs = rrs;
cachedNightMode = n;
cachedColor = view.getResources().getColor(R.color.gpx_track);
if (cachedRrs != null) {
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, cachedNightMode);
if (req.searchRenderingAttribute("gpxColor")) {
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
}
}
}
return cachedColor;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}

View file

@ -1,11 +1,14 @@
package net.osmand.plus.osmodroid;
import java.io.File;
import java.util.ArrayList;
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.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
@ -52,6 +55,7 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
activity.getMapView().addLayer(myOsMoDroidLayer, 4.5f);
}
activity.refreshMap();
}
}
@ -277,4 +281,20 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
}
}).reg();
}
public ArrayList<GPXFile> getGpxArrayList(int id) {
ArrayList<GPXFile> result = new ArrayList<GPXFile>();
try {
for (int i = 0; i < mIRemoteService.getNumberOfGpx(id); i++) {
result.add( GPXUtilities.loadGPXFile(app, new File(mIRemoteService.getGpxFile(id, i)), false));
}
return result;
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
return result;
}
}