From faa6cae4c86fb329175c35425e2747ba6f1da10e Mon Sep 17 00:00:00 2001 From: fokin33 Date: Sun, 15 Dec 2013 14:50:57 +0400 Subject: [PATCH] colored-gpx-and-fixed-points --- OsmAnd/res/values-ru/strings.xml | 2 + OsmAnd/res/values/strings.xml | 2 + .../OsMoDroid/IRemoteOsMoDroidService.aidl | 16 +++ .../net/osmand/plus/osmodroid/ColoredGPX.java | 8 ++ .../osmand/plus/osmodroid/OsMoDroidLayer.java | 112 ++++++++++++------ .../plus/osmodroid/OsMoDroidPlugin.java | 90 ++++++++++++-- 6 files changed, 182 insertions(+), 48 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/osmodroid/ColoredGPX.java diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 5a55065030..c1eb10c61e 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1260,6 +1260,8 @@ Остановить OsMoDroid Запустить OsMoDroid Обновить каналы + Следить за + Не следить Пожалуйста, укажите в настройках пароль и имя пользователя OSM Карта: Пароль OSM (опционально) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 5e36d65c15..25f410d468 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -85,6 +85,8 @@ Stop OsMoDroid Start OsMoDroid Refresh channels + Seek object + Unseek object Announce GPX waypoints Announce… Configure to announce street names, traffic warnings (forced stops, speed bumps), speed camera warnings, speed limits diff --git a/OsmAnd/src/com/OsMoDroid/IRemoteOsMoDroidService.aidl b/OsmAnd/src/com/OsMoDroid/IRemoteOsMoDroidService.aidl index ad4763c2d1..deb79cae2d 100644 --- a/OsmAnd/src/com/OsMoDroid/IRemoteOsMoDroidService.aidl +++ b/OsmAnd/src/com/OsMoDroid/IRemoteOsMoDroidService.aidl @@ -45,6 +45,22 @@ String getObjectColor(int layerId, int objectId); int getNumberOfGpx(int layerId); String getGpxFile (int layerId, int pos); + +int getGpxColor (int layerId, int pos); + +int getNumberOfPoints(int layerId); + +int getPointId(int layerId, int pos); + +float getPointLat(int layerId, int pointId); + +float getPointLon(int layerId, int pointId); + +String getPointName(int layerId, int pointId); + +String getPointDescription(int layerId, int pointId); + +String getPointColor(int layerId, int pointId); void refreshChannels(); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmodroid/ColoredGPX.java b/OsmAnd/src/net/osmand/plus/osmodroid/ColoredGPX.java new file mode 100644 index 0000000000..7a348dd710 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmodroid/ColoredGPX.java @@ -0,0 +1,8 @@ +package net.osmand.plus.osmodroid; + +import net.osmand.plus.GPXUtilities.GPXFile; + +public class ColoredGPX { + int color; + GPXFile gpxFile; +} diff --git a/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidLayer.java b/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidLayer.java index d4a52eb346..4039549638 100644 --- a/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidLayer.java @@ -27,6 +27,7 @@ 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; @@ -49,7 +50,7 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I * magic number so far */ private static final int radius = 10; - + OsMoDroidPoint seekOsMoDroidPoint; OsMoDroidPlugin myOsMoDroidPlugin; private DisplayMetrics dm; @@ -59,8 +60,9 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I private Paint textPaint; - ArrayList OsMoDroidPointArrayList; - ArrayList gpxArrayList; + ArrayList osMoDroidPointArrayList; + ArrayList osMoDroidFixedPointArrayList; + ArrayList gpxArrayList = new ArrayList() ; int layerId; String layerName; String layerDescription; @@ -120,17 +122,25 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setTextAlign(Paint.Align.CENTER); opIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.bicycle_location); - OsMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId); - gpxArrayList = myOsMoDroidPlugin.getGpxArrayList(layerId); + osMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId); + osMoDroidFixedPointArrayList = myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId); + myOsMoDroidPlugin.getGpxArrayList(layerId); initUI(); } - + + public void inGPXFilelist(ArrayList in){ + gpxArrayList=in; + map.refreshMap(); + } @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { - - for (OsMoDroidPoint op : OsMoDroidPointArrayList) { + + for (OsMoDroidPoint op : osMoDroidPointArrayList) { + if(seekOsMoDroidPoint!=null&&seekOsMoDroidPoint.equals(op)){ + map.setMapLocation(op.latlon.getLatitude(), op.latlon.getLongitude()); + } LatLon newLatlon; try { @@ -178,11 +188,23 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I } - for (GPXFile gpxFile : gpxArrayList){ - gpxFile.proccessPoints(); - List> points = gpxFile.processedPointsToDisplay; + 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); + } + + for (ColoredGPX cg : gpxArrayList){ + cg.gpxFile.proccessPoints(); + List> points = cg.gpxFile.processedPointsToDisplay; - paint.setColor(getColor(settings)); + paint.setColor(cg.color); final QuadRect latLonBounds = tileBox.getLatLonBounds(); for (List l : points) { @@ -211,37 +233,18 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I } private void drawSegment(Canvas canvas, RotatedTileBox tb, List l, int startIndex, int endIndex) { - int px = tb.getPixXFromLonNoRot(l.get(startIndex).lon); - int py = tb.getPixYFromLatNoRot(l.get(startIndex).lat); + 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 = tb.getPixXFromLonNoRot(p.lon); - int y = tb.getPixYFromLatNoRot(p.lat); + 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); } - 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) {} @@ -266,6 +269,26 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I // synchronized block } } + if (myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId) != null) { + int ex = (int) point.x; + int ey = (int) point.y; + + try { + for (int i = 0; i < myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId).size(); i++) { + OsMoDroidPoint n = myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId).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 @@ -275,11 +298,28 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I 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(); } } diff --git a/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidPlugin.java b/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidPlugin.java index dbbabceb52..01ce0cb164 100644 --- a/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmodroid/OsMoDroidPlugin.java @@ -2,6 +2,7 @@ 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; @@ -14,6 +15,7 @@ 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.routing.RouteProvider.GPXRouteParams; import net.osmand.plus.views.MonitoringInfoControl; import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices; import net.osmand.plus.views.OsmandMapTileView; @@ -25,6 +27,7 @@ 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; @@ -107,6 +110,7 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr private OsMoDroidLayer osmoDroidLayer; protected boolean connected = false; ArrayList osmoDroidLayerList = new ArrayList(); + private AsyncTask> task; public ArrayList getOsMoDroidPointArrayList(int id) { ArrayList result = new ArrayList(); @@ -126,6 +130,25 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr return result; } + + public ArrayList getOsMoDroidFixedPointArrayList(int id) { + ArrayList result = new ArrayList(); + 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() { @@ -278,23 +301,66 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr 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 ArrayList getGpxArrayList(int id) { - ArrayList result = new ArrayList(); - - - 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); + public void getGpxArrayList(final int id) { + final ArrayList result = new ArrayList(); + if(task!=null){ + task.cancel(true); } - return result; + task = new AsyncTask>() { + @Override + protected ArrayList doInBackground(Void... params) { + ArrayList temp = new ArrayList(); + try { + for (int i = 0; i < mIRemoteService.getNumberOfGpx(id); i++) { + ColoredGPX cg = new ColoredGPX(); + cg.gpxFile = GPXUtilities.loadGPXFile(app, new File(mIRemoteService.getGpxFile(id, i)), false); + cg.color = mIRemoteService.getGpxColor(id, i); + temp.add(cg); + } + return temp; + } catch (RemoteException e) { + log.error(e.getMessage(), e); + } + return temp; + } + + @Override + protected void onPostExecute(ArrayList backgroundresult) { + if(backgroundresult!=null){ + try { + for (OsMoDroidLayer l : osmoDroidLayerList){ + if (l.layerId==id){ + l.inGPXFilelist(backgroundresult); + } + } + } catch (ConcurrentModificationException e) { + log.error(e.getMessage(), e); + } + + + + } + } + }; + task.execute(); + + + } }