From b891b1e1337e34d2119a7348e7f2f8376302ceda Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 14 Mar 2017 17:30:58 +0300 Subject: [PATCH] Fix current track color --- .../src/net/osmand/plus/OsmandSettings.java | 2 ++ .../plus/myplaces/TrackSegmentFragment.java | 23 ++++++++++++++++--- .../src/net/osmand/plus/views/GPXLayer.java | 5 ++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b907bf8e7d..71e3763fc8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1051,6 +1051,8 @@ public class OsmandSettings { public final OsmandPreference LAST_UPDATES_CARD_REFRESH = new LongPreference("last_updates_card_refresh", 0).makeGlobal(); + public final CommonPreference CURRENT_TRACK_COLOR = new IntPreference("current_track_color", 0).makeGlobal().cache(); + // this value string is synchronized with settings_pref.xml preference name public final CommonPreference SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index ec985990b1..e2aae9594c 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -125,6 +125,7 @@ public class TrackSegmentFragment extends OsmAndListFragment { private boolean updateEnable; private View headerView; private int trackColor; + private int currentTrackColor; private Paint paint; private Bitmap selectedPoint; private LatLon selectedPointLatLon; @@ -322,6 +323,9 @@ public class TrackSegmentFragment extends OsmAndListFragment { } else if (getGpxDataItem() != null) { app.getGpxDatabase().updateColor(getGpxDataItem(), clr); } + if (getGpx().showCurrentTrack) { + app.getSettings().CURRENT_TRACK_COLOR.set(clr); + } refreshTrackBitmap(); } } @@ -435,8 +439,14 @@ public class TrackSegmentFragment extends OsmAndListFragment { } private void refreshTrackBitmap() { - SelectedGpxFile sf = new SelectedGpxFile(); - sf.setGpxFile(getGpx()); + currentTrackColor = app.getSettings().CURRENT_TRACK_COLOR.get(); + SelectedGpxFile sf; + if (getGpx().showCurrentTrack) { + sf = app.getSavingTrackHelper().getCurrentTrack(); + } else { + sf = new SelectedGpxFile(); + sf.setGpxFile(getGpx()); + } Bitmap bmp = mapBitmap.copy(mapBitmap.getConfig(), true); Canvas canvas = new Canvas(bmp); drawTrack(canvas, rotatedTileBox, sf); @@ -458,6 +468,9 @@ public class TrackSegmentFragment extends OsmAndListFragment { List segments = g.getPointsToDisplay(); for (TrkSegment ts : segments) { int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (g.isShowCurrentTrack()) { + color = currentTrackColor; + } if (color == 0) { color = ts.getColor(trackColor); } @@ -580,7 +593,11 @@ public class TrackSegmentFragment extends OsmAndListFragment { final ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage); int color = getGpxDataItem() != null ? getGpxDataItem().getColor() : 0; if (color == 0 && getGpx() != null) { - color = getGpx().getColor(0); + if (getGpx().showCurrentTrack) { + color = app.getSettings().CURRENT_TRACK_COLOR.get(); + } else { + color = getGpx().getColor(0); + } } if (color == 0) { final RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index e6bc21b060..6487087751 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -66,6 +66,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private int cachedColor; private Paint paintIcon; private Bitmap pointSmall; + private int currentTrackColor; private Bitmap selectedPoint; private LatLon selectedPointLatLon; @@ -173,6 +174,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } else { List selectedGPXFiles = selectedGpxHelper.getSelectedGPXFiles(); cache.clear(); + currentTrackColor = view.getSettings().CURRENT_TRACK_COLOR.get(); if (!selectedGPXFiles.isEmpty()) { drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings); canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); @@ -389,6 +391,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex List segments = g.getPointsToDisplay(); for (TrkSegment ts : segments) { int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (g.isShowCurrentTrack()) { + color = currentTrackColor; + } if (color == 0) { color = ts.getColor(cachedColor); }