colored-gpx-and-fixed-points

This commit is contained in:
fokin33 2013-12-15 14:50:57 +04:00
parent 6b717b48ec
commit faa6cae4c8
6 changed files with 182 additions and 48 deletions

View file

@ -1260,6 +1260,8 @@
<string name="osmodroid_mode_on">Остановить OsMoDroid</string> <string name="osmodroid_mode_on">Остановить OsMoDroid</string>
<string name="osmodroid_mode_off">Запустить OsMoDroid</string> <string name="osmodroid_mode_off">Запустить OsMoDroid</string>
<string name="osmodroid_refresh">Обновить каналы</string> <string name="osmodroid_refresh">Обновить каналы</string>
<string name="osmodroid_seek">Следить за</string>
<string name="osmodroid_unseek">Не следить</string>
<string name="osb_author_or_password_not_specified">Пожалуйста, укажите в настройках пароль и имя пользователя OSM</string> <string name="osb_author_or_password_not_specified">Пожалуйста, укажите в настройках пароль и имя пользователя OSM</string>
<string name="route_descr_map_location">Карта: </string> <string name="route_descr_map_location">Карта: </string>
<string name="osb_author_dialog_password">Пароль OSM (опционально)</string> <string name="osb_author_dialog_password">Пароль OSM (опционально)</string>

View file

@ -85,6 +85,8 @@
<string name="osmodroid_mode_on">Stop OsMoDroid</string> <string name="osmodroid_mode_on">Stop OsMoDroid</string>
<string name="osmodroid_mode_off">Start OsMoDroid</string> <string name="osmodroid_mode_off">Start OsMoDroid</string>
<string name="osmodroid_refresh">Refresh channels</string> <string name="osmodroid_refresh">Refresh channels</string>
<string name="osmodroid_seek">Seek object</string>
<string name="osmodroid_unseek">Unseek object</string>
<string name="announce_gpx_waypoints">Announce GPX waypoints</string> <string name="announce_gpx_waypoints">Announce GPX waypoints</string>
<string name="speak_title">Announce&#8230;</string> <string name="speak_title">Announce&#8230;</string>
<string name="speak_descr">Configure to announce street names, traffic warnings (forced stops, speed bumps), speed camera warnings, speed limits</string> <string name="speak_descr">Configure to announce street names, traffic warnings (forced stops, speed bumps), speed camera warnings, speed limits</string>

View file

@ -46,5 +46,21 @@ int getNumberOfGpx(int layerId);
String getGpxFile (int layerId, int pos); 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(); void refreshChannels();
} }

View file

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

View file

@ -27,6 +27,7 @@ import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.Paint.Cap; import android.graphics.Paint.Cap;
import android.graphics.Paint.Join; import android.graphics.Paint.Join;
@ -49,7 +50,7 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
* magic number so far * magic number so far
*/ */
private static final int radius = 10; private static final int radius = 10;
OsMoDroidPoint seekOsMoDroidPoint;
OsMoDroidPlugin myOsMoDroidPlugin; OsMoDroidPlugin myOsMoDroidPlugin;
private DisplayMetrics dm; private DisplayMetrics dm;
@ -59,8 +60,9 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
private Paint textPaint; private Paint textPaint;
ArrayList<OsMoDroidPoint> OsMoDroidPointArrayList; ArrayList<OsMoDroidPoint> osMoDroidPointArrayList;
ArrayList<GPXFile> gpxArrayList; ArrayList<OsMoDroidPoint> osMoDroidFixedPointArrayList;
ArrayList<ColoredGPX> gpxArrayList = new ArrayList<ColoredGPX>() ;
int layerId; int layerId;
String layerName; String layerName;
String layerDescription; String layerDescription;
@ -120,17 +122,25 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setTypeface(Typeface.DEFAULT_BOLD);
textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextAlign(Paint.Align.CENTER);
opIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.bicycle_location); opIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.bicycle_location);
OsMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId); osMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId);
gpxArrayList = myOsMoDroidPlugin.getGpxArrayList(layerId); osMoDroidFixedPointArrayList = myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId);
myOsMoDroidPlugin.getGpxArrayList(layerId);
initUI(); initUI();
} }
public void inGPXFilelist(ArrayList<ColoredGPX> in){
gpxArrayList=in;
map.refreshMap();
}
@Override @Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { 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; LatLon newLatlon;
try { try {
@ -178,11 +188,23 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
} }
for (GPXFile gpxFile : gpxArrayList){ for (OsMoDroidPoint point : osMoDroidFixedPointArrayList ){
gpxFile.proccessPoints(); double latitude = point.latlon.getLatitude();
List<List<WptPt>> points = gpxFile.processedPointsToDisplay; 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);
}
paint.setColor(getColor(settings)); for (ColoredGPX cg : gpxArrayList){
cg.gpxFile.proccessPoints();
List<List<WptPt>> points = cg.gpxFile.processedPointsToDisplay;
paint.setColor(cg.color);
final QuadRect latLonBounds = tileBox.getLatLonBounds(); final QuadRect latLonBounds = tileBox.getLatLonBounds();
for (List<WptPt> l : points) { for (List<WptPt> l : points) {
@ -211,37 +233,18 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
} }
private void drawSegment(Canvas canvas, RotatedTileBox tb, List<WptPt> l, int startIndex, int endIndex) { private void drawSegment(Canvas canvas, RotatedTileBox tb, List<WptPt> l, int startIndex, int endIndex) {
int px = tb.getPixXFromLonNoRot(l.get(startIndex).lon); int px = (int) tb.getPixXFromLatLon(l.get(startIndex).lat, l.get(startIndex).lon);
int py = tb.getPixYFromLatNoRot(l.get(startIndex).lat); int py = (int) tb.getPixYFromLatLon(l.get(startIndex).lat, l.get(startIndex).lon);
path.moveTo(px, py); path.moveTo(px, py);
for (int i = startIndex + 1; i <= endIndex; i++) { for (int i = startIndex + 1; i <= endIndex; i++) {
WptPt p = l.get(i); WptPt p = l.get(i);
int x = tb.getPixXFromLonNoRot(p.lon); int x = (int) tb.getPixXFromLatLon(p.lat,p.lon);
int y = tb.getPixYFromLatNoRot(p.lat); int y = (int) tb.getPixYFromLatLon(p.lat,p.lon);
path.lineTo(x, y); path.lineTo(x, y);
} }
canvas.drawPath(path, paint); 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 @Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {} public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
@ -266,6 +269,26 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
// synchronized block // 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 @Override
@ -275,11 +298,28 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
map.getMyApplication().getTargetPointsHelper().navigateToPoint(a.latlon, true, -1); 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.get_directions)).listen(listener).reg();
adapter.item(map.getString(R.string.osmodroid_seek)).listen(seeklistener).reg();
} }
} }

View file

@ -2,6 +2,7 @@ package net.osmand.plus.osmodroid;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -14,6 +15,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; 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;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices; import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
@ -25,6 +27,7 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.AsyncTask;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
@ -107,6 +110,7 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
private OsMoDroidLayer osmoDroidLayer; private OsMoDroidLayer osmoDroidLayer;
protected boolean connected = false; protected boolean connected = false;
ArrayList<OsMoDroidLayer> osmoDroidLayerList = new ArrayList<OsMoDroidLayer>(); ArrayList<OsMoDroidLayer> osmoDroidLayerList = new ArrayList<OsMoDroidLayer>();
private AsyncTask<Void, Void, ArrayList<ColoredGPX>> task;
public ArrayList<OsMoDroidPoint> getOsMoDroidPointArrayList(int id) { public ArrayList<OsMoDroidPoint> getOsMoDroidPointArrayList(int id) {
ArrayList<OsMoDroidPoint> result = new ArrayList<OsMoDroidPoint>(); ArrayList<OsMoDroidPoint> result = new ArrayList<OsMoDroidPoint>();
@ -127,6 +131,25 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
} }
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 @Override
public String getId() { public String getId() {
return ID; return ID;
@ -280,21 +303,64 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
} }
}).reg(); }).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;
} }
public ArrayList<GPXFile> getGpxArrayList(int id) { }
ArrayList<GPXFile> result = new ArrayList<GPXFile>(); }).reg();
}
public void getGpxArrayList(final int id) {
final ArrayList<ColoredGPX> result = new ArrayList<ColoredGPX>();
if(task!=null){
task.cancel(true);
}
task = new AsyncTask<Void, Void, ArrayList<ColoredGPX>>() {
@Override
protected ArrayList<ColoredGPX> doInBackground(Void... params) {
ArrayList<ColoredGPX> temp = new ArrayList<ColoredGPX>();
try { try {
for (int i = 0; i < mIRemoteService.getNumberOfGpx(id); i++) { for (int i = 0; i < mIRemoteService.getNumberOfGpx(id); i++) {
result.add( GPXUtilities.loadGPXFile(app, new File(mIRemoteService.getGpxFile(id, i)), false)); 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 result; return temp;
} catch (RemoteException e) { } catch (RemoteException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return result; return temp;
}
@Override
protected void onPostExecute(ArrayList<ColoredGPX> 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();
} }
} }