Add split km view to GPX layer (visible on map)

This commit is contained in:
Victor Shcherb 2014-07-08 02:14:56 +02:00
parent bb7f279b58
commit 8bb4e6fda4
6 changed files with 155 additions and 55 deletions

View file

@ -36,6 +36,8 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:gravity="center_vertical"
android:text="@string/osmo_enable_tracker" />

View file

@ -36,6 +36,8 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:gravity="center_vertical"
android:text="@string/osmo_enable_tracker" />

View file

@ -17,6 +17,7 @@ import net.osmand.plus.GPXUtilities.Route;
import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.util.Algorithms;
@ -191,6 +192,7 @@ public class GpxSelectionHelper {
item.group = group;
if(split) {
item.splitMetric = analysis.metricEnd;
item.splitName = formatSplitName(analysis.metricEnd, group, app);
}
item.description = GpxUiHelper.getDescription(app, analysis, true);
@ -244,6 +246,29 @@ public class GpxSelectionHelper {
}
}
private static String formatSplitName(double metricEnd, GpxDisplayGroup group, OsmandApplication app) {
if (group.isSplitDistance()) {
MetricsConstants mc = app.getSettings().METRIC_SYSTEM.get();
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
final double sd = group.getSplitDistance();
int digits = sd < 100 ? 2 : (sd < 1000 ? 1 : 0);
int rem1000 = (int) (metricEnd + 0.5) % 1000;
if (rem1000 > 1 && digits < 1) {
digits = 1;
}
int rem100 = (int) (metricEnd + 0.5) % 100;
if (rem100 > 1 && digits < 2) {
digits = 2;
}
return OsmAndFormatter.getFormattedRoundDistanceKm((float) metricEnd, digits, app);
} else {
return OsmAndFormatter.getFormattedDistance((float) metricEnd, app);
}
} else {
return Algorithms.formatDuration((int) metricEnd);
}
}
public SelectedGpxFile getSelectedFileByPath(String path) {
for(SelectedGpxFile s : selectedGPXFiles) {
if(s.getGpxFile().path.equals(path)) {
@ -403,6 +428,10 @@ public class GpxSelectionHelper {
return processedPointsToDisplay;
}
public List<GpxDisplayGroup> getDisplayGroups() {
return displayGroups;
}
public GPXFile getGpxFile() {
return gpxFile;
}
@ -545,6 +574,7 @@ public class GpxSelectionHelper {
public WptPt locationStart;
public WptPt locationEnd;
public double splitMetric = -1;
public String splitName;
public String name;
public String description;
public String url;

View file

@ -525,30 +525,10 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
TextView description = (TextView) row.findViewById(R.id.description);
TextView additional = (TextView) row.findViewById(R.id.additional);
ImageView icon = (ImageView) row.findViewById(R.id.icon);
if(child.splitMetric >= 0) {
if(child.splitMetric >= 0 && child.splitName != null) {
additional.setVisibility(View.VISIBLE);
icon.setVisibility(View.INVISIBLE);
if(child.group.isSplitDistance()) {
MetricsConstants mc = app.getSettings().METRIC_SYSTEM.get();
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
final double sd = child.group.getSplitDistance();
int digits = sd < 100 ? 2 : (sd < 1000 ? 1 : 0);
int rem1000 = (int) (child.splitMetric + 0.5) % 1000;
if (rem1000 > 1 && digits < 1) {
digits = 1;
}
int rem100 = (int) (child.splitMetric + 0.5) % 100;
if (rem100 > 1 && digits < 2) {
digits = 2;
}
additional.setText(OsmAndFormatter.getFormattedRoundDistanceKm((float) child.splitMetric,
digits, app));
} else {
additional.setText(OsmAndFormatter.getFormattedDistance((float) child.splitMetric, app));
}
} else{
additional.setText(Algorithms.formatDuration((int) child.splitMetric));
}
additional.setText(child.splitName);
} else {
icon.setVisibility(View.VISIBLE);
additional.setVisibility(View.INVISIBLE);

View file

@ -219,7 +219,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
if (uname.length() > 7 && uname.indexOf(' ') != -1) {
uname = uname.substring(0, uname.indexOf(' '));
}
if (uname.length() > 4 && uname.indexOf(' ') != -1) {
if (uname.length() > 4) {
txt = "";
subtxt = uname;
} else {

View file

@ -9,6 +9,8 @@ import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable;
@ -16,8 +18,10 @@ import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
@ -47,6 +51,12 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private DashPathEffect pathEffect;
private Paint paintOuter;
private Paint paintInnerCircle;
private Paint paintTextIcon;
// private Drawable favoriteIcon;
@ -65,9 +75,24 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paintBmp.setFilterBitmap(true);
paintBmp.setDither(true);
paintTextIcon = new Paint();
paintTextIcon.setTextSize(10 * view.getDensity());
paintTextIcon.setTextAlign(Align.CENTER);
paintTextIcon.setFakeBoldText(true);
paintTextIcon.setColor(Color.BLACK);
paintTextIcon.setAntiAlias(true);
textLayer = view.getLayerByClass(MapTextLayer.class);
//favoriteIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.poi_favourite);
paintOuter = new Paint();
paintOuter.setColor(0x88555555);
paintOuter.setAntiAlias(true);
paintOuter.setStyle(Style.FILL_AND_STROKE);
paintInnerCircle = new Paint();
paintInnerCircle.setStyle(Style.FILL_AND_STROKE);
paintInnerCircle.setColor(0xddFFFFFF);
paintInnerCircle.setAntiAlias(true);
}
@Override
@ -101,45 +126,106 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
List<SelectedGpxFile> selectedGPXFiles = selectedGpxHelper.getSelectedGPXFiles();
int clr = getColor(settings);
cache.clear();
int defPointColor = view.getResources().getColor(R.color.gpx_color_point);
int visitedColor = view.getContext().getResources().getColor(R.color.color_ok);
if (!selectedGPXFiles.isEmpty()) {
for (SelectedGpxFile g : selectedGPXFiles) {
List<List<WptPt>> points = g.getPointsToDisplay();
boolean routePoints = g.isRoutePoints();
int fcolor = g.getColor() == 0 ? clr : g.getColor();
paint.setColor(fcolor);
drawSegments(canvas, tileBox, points, routePoints);
}
drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
if (tileBox.getZoom() >= startZoom) {
// request to load
final QuadRect latLonBounds = tileBox.getLatLonBounds();
for (SelectedGpxFile g : selectedGPXFiles) {
List<WptPt> pts = getListStarPoints(g);
int fcolor = g.getColor() == 0 ? defPointColor : g.getColor();
for (WptPt o : pts) {
boolean visit = isPointVisited(o);
int pointColor = visit ? visitedColor : o.getColor(fcolor);
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor);
if (o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top
&& o.lon >= latLonBounds.left && o.lon <= latLonBounds.right) {
cache.add(o);
int x = (int) tileBox.getPixXFromLatLon(o.lat, o.lon);
int y = (int) tileBox.getPixYFromLatLon(o.lat, o.lon);
fid.drawBitmapInCenter(canvas, x, y, tileBox.getDensity());
// canvas.drawBitmap(favoriteIcon, x - favoriteIcon.getWidth() / 2,
// y - favoriteIcon.getHeight(), paint);
}
drawSelectedFilesSplits(canvas, tileBox, selectedGPXFiles, settings);
drawSelectedFilesPoints(canvas, tileBox, selectedGPXFiles);
}
if(textLayer.isVisible()) {
textLayer.putData(this, cache);
}
}
private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles,
DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
// request to load
for (SelectedGpxFile g : selectedGPXFiles) {
List<GpxDisplayGroup> groups = g.getDisplayGroups();
if (groups != null) {
for (GpxDisplayGroup group : groups) {
List<GpxDisplayItem> items = group.getModifiableList();
drawSplitItems(canvas, tileBox, items, settings);
}
}
}
}
if(textLayer.isVisible()) {
textLayer.putData(this, cache);
}
private void drawSplitItems(Canvas canvas, RotatedTileBox tileBox, List<GpxDisplayItem> items, DrawSettings settings) {
final QuadRect latLonBounds = tileBox.getLatLonBounds();
int r = (int) (12 * tileBox.getDensity());
int dr = r * 3 / 2;
int px = -1;
int py = -1;
for(int k = 0; k < items.size(); k++) {
GpxDisplayItem i = items.get(k);
WptPt o = i.locationEnd;
if (o != null && o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top && o.lon >= latLonBounds.left
&& o.lon <= latLonBounds.right) {
int x = (int) tileBox.getPixXFromLatLon(o.lat, o.lon);
int y = (int) tileBox.getPixYFromLatLon(o.lat, o.lon);
if (px != -1 || py != -1) {
if (Math.abs(x - px) <= dr && Math.abs(y - py) <= dr) {
continue;
}
}
px = x;
py = y;
String nm = i.splitName;
if (nm != null) {
int ind = nm.indexOf(' ');
if (ind > 0) {
nm = nm.substring(0, ind);
}
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintOuter);
canvas.drawCircle(x, y, r - (float) Math.ceil(tileBox.getDensity()), paintInnerCircle);
paintTextIcon.setTextSize(r);
canvas.drawText(nm, x, y + r / 2, paintTextIcon);
}
}
}
}
private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
int defPointColor = view.getResources().getColor(R.color.gpx_color_point);
int visitedColor = view.getContext().getResources().getColor(R.color.color_ok);
if (tileBox.getZoom() >= startZoom) {
// request to load
final QuadRect latLonBounds = tileBox.getLatLonBounds();
for (SelectedGpxFile g : selectedGPXFiles) {
List<WptPt> pts = getListStarPoints(g);
int fcolor = g.getColor() == 0 ? defPointColor : g.getColor();
for (WptPt o : pts) {
boolean visit = isPointVisited(o);
int pointColor = visit ? visitedColor : o.getColor(fcolor);
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor);
if (o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top
&& o.lon >= latLonBounds.left && o.lon <= latLonBounds.right) {
cache.add(o);
int x = (int) tileBox.getPixXFromLatLon(o.lat, o.lon);
int y = (int) tileBox.getPixYFromLatLon(o.lat, o.lon);
fid.drawBitmapInCenter(canvas, x, y, tileBox.getDensity());
// canvas.drawBitmap(favoriteIcon, x - favoriteIcon.getWidth() / 2,
// y - favoriteIcon.getHeight(), paint);
}
}
}
}
}
private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox,
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
int clr = getColor(settings);
for (SelectedGpxFile g : selectedGPXFiles) {
List<List<WptPt>> points = g.getPointsToDisplay();
boolean routePoints = g.isRoutePoints();
int fcolor = g.getColor() == 0 ? clr : g.getColor();
paint.setColor(fcolor);
drawSegments(canvas, tileBox, points, routePoints);
}
}