From 8bb4e6fda4c46f59a038ce1739cbcf0ef81572f8 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 8 Jul 2014 02:14:56 +0200 Subject: [PATCH] Add split km view to GPX layer (visible on map) --- .../layout-v14/osmo_groups_list_header.xml | 2 + OsmAnd/res/layout/osmo_groups_list_header.xml | 2 + .../net/osmand/plus/GpxSelectionHelper.java | 30 ++++ .../plus/activities/SelectedGPXFragment.java | 24 +-- .../src/net/osmand/plus/osmo/OsMoPlugin.java | 2 +- .../src/net/osmand/plus/views/GPXLayer.java | 150 ++++++++++++++---- 6 files changed, 155 insertions(+), 55 deletions(-) diff --git a/OsmAnd/res/layout-v14/osmo_groups_list_header.xml b/OsmAnd/res/layout-v14/osmo_groups_list_header.xml index 6e3576aeed..bc67bb1327 100644 --- a/OsmAnd/res/layout-v14/osmo_groups_list_header.xml +++ b/OsmAnd/res/layout-v14/osmo_groups_list_header.xml @@ -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" /> diff --git a/OsmAnd/res/layout/osmo_groups_list_header.xml b/OsmAnd/res/layout/osmo_groups_list_header.xml index 04dbb7cd65..ac08b60ac2 100644 --- a/OsmAnd/res/layout/osmo_groups_list_header.xml +++ b/OsmAnd/res/layout/osmo_groups_list_header.xml @@ -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" /> diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index fef8133173..e96cf83d5b 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -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 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; diff --git a/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java index 8f74de3c59..92d69871bc 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/SelectedGPXFragment.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java index a09cbd3c0f..98656e2212 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java @@ -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 { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 42116cf6c5..e950743a90 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -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 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> 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 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 selectedGPXFiles, + DrawSettings settings) { + if (tileBox.getZoom() >= startZoom) { + // request to load + for (SelectedGpxFile g : selectedGPXFiles) { + List groups = g.getDisplayGroups(); + if (groups != null) { + for (GpxDisplayGroup group : groups) { + List items = group.getModifiableList(); + drawSplitItems(canvas, tileBox, items, settings); } } } } - if(textLayer.isVisible()) { - textLayer.putData(this, cache); + } + + private void drawSplitItems(Canvas canvas, RotatedTileBox tileBox, List 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 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 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 selectedGPXFiles, DrawSettings settings) { + int clr = getColor(settings); + for (SelectedGpxFile g : selectedGPXFiles) { + List> points = g.getPointsToDisplay(); + boolean routePoints = g.isRoutePoints(); + int fcolor = g.getColor() == 0 ? clr : g.getColor(); + paint.setColor(fcolor); + drawSegments(canvas, tileBox, points, routePoints); } }