From d5f191cfa6dc7d2a1eda96c713b3b3d19256c0c5 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 12 Jun 2015 01:57:03 +0200 Subject: [PATCH] Allow to display tracks with different colors (colors are not stored back to gpx). Add to Release Notes? --- OsmAnd/res/layout/selected_track_edit.xml | 21 ++++++++++++++++ OsmAnd/src/net/osmand/plus/GPXUtilities.java | 3 ++- .../activities/FavoritesTreeFragment.java | 2 +- .../plus/myplaces/SelectedGPXFragment.java | 24 ++++++++++++++++++- .../src/net/osmand/plus/views/GPXLayer.java | 2 +- 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/selected_track_edit.xml b/OsmAnd/res/layout/selected_track_edit.xml index 291700b900..cd243481f2 100644 --- a/OsmAnd/res/layout/selected_track_edit.xml +++ b/OsmAnd/res/layout/selected_track_edit.xml @@ -26,6 +26,27 @@ android:layout_marginRight="10dp" /> + + + + + + + proccessPoints() { List tpoints = new ArrayList(); for (Track t : tracks) { + int trackColor = t.getColor(getColor(0)); for (TrkSegment ts : t.segments) { if (ts.points.size() > 0) { TrkSegment sgmt = new TrkSegment(); tpoints.add(sgmt); sgmt.points.addAll(ts.points); - sgmt.setColor(t.getColor(0)); + sgmt.setColor(trackColor); } } } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 963a08373c..21cb9c48c5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -506,8 +506,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { protected void openChangeGroupDialog(final FavoriteGroup group) { Builder bld = new AlertDialog.Builder(getActivity()); View favEdit = getActivity().getLayoutInflater().inflate(R.layout.fav_group_edit, null); - final Spinner colorSpinner = (Spinner) favEdit.findViewById(R.id.ColorSpinner); final TIntArrayList list = new TIntArrayList(); + final Spinner colorSpinner = (Spinner) favEdit.findViewById(R.id.ColorSpinner); final int intColor = group.color == 0? getResources().getColor(R.color.color_favorite) : group.color; ColorDialogs.setupColorSpinner(getActivity(), intColor, colorSpinner, list); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java index adcc5167c5..e3a497a36c 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java @@ -15,6 +15,7 @@ import net.osmand.data.PointDescription; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; @@ -24,10 +25,12 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmAndListFragment; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.dialogs.DirectionsDialogs; +import net.osmand.plus.helpers.ColorDialogs; import net.osmand.util.Algorithms; import android.app.Activity; import android.app.AlertDialog; @@ -265,6 +268,12 @@ public class SelectedGPXFragment extends OsmAndListFragment { final List groups = filterGroups(GpxDisplayItemType.TRACK_SEGMENT); View view = getMyActivity().getLayoutInflater().inflate(R.layout.selected_track_edit, null); + + final TIntArrayList list = new TIntArrayList(); + final Spinner colorSpinner = (Spinner) view.findViewById(R.id.ColorSpinner); + ColorDialogs.setupColorSpinner(getActivity(), getGpx().getColor(0), colorSpinner, list); + + final Spinner sp = (Spinner) view.findViewById(R.id.Spinner); Builder bld = new AlertDialog.Builder(getMyActivity()); final List distanceSplit = new ArrayList(); @@ -324,10 +333,23 @@ public class SelectedGPXFragment extends OsmAndListFragment { @Override public void onClick(DialogInterface dialog, int which) { SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false); + int clr = list.get(colorSpinner.getSelectedItemPosition()); + if(clr != 0 ) { + sf.getModifiableGpxFile().setColor(clr); + sf.processPoints(); + } if (groups.size() > 0) { updateSplit(groups, distanceSplit, timeSplit, sp.getSelectedItemPosition(), vis.isChecked() ? sf : null); } + if(vis.isChecked() && sf.getGpxFile() != null) { + WptPt wpt = sf.getGpxFile().findPointToShow(); + if (wpt != null) { + app.getSettings().setMapLocationToShow(wpt.getLatitude(), wpt.getLongitude(), 15, null, false, + false); //$NON-NLS-1$ + MapActivity.launchMapActivityMoveToTop(activity); + } + } } }); @@ -464,7 +486,7 @@ public class SelectedGPXFragment extends OsmAndListFragment { OsmandSettings settings = app.getSettings(); final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); DirectionsDialogs.createDirectionActionsPopUpMenu(optionsMenu, location, child.locationStart, name, settings.getLastKnownMapZoom(), - getActivity(), true, false); + getActivity(), false, false); optionsMenu.show(); // } else { // child.expanded = !child.expanded; diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 1dd18a2113..20fefa6663 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -363,7 +363,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex canvas.drawPath(path, shadowPaint); } int clr = paint.getColor(); - if(clr != l.getColor(clr)) { + if(clr != l.getColor(clr) && l.getColor(clr) != 0) { paint.setColor(l.getColor(clr)); } canvas.drawPath(path, paint);