diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 6ab73a355f..709f1664df 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -414,7 +414,7 @@ public class FavouritesDbHelper { if (p.getOriginObjectName().length() > 0) { pt.comment = p.getOriginObjectName(); } - gpx.points.add(pt); + context.getSelectedGpxHelper().addPoint(pt, gpx); } return gpx; } @@ -565,7 +565,7 @@ public class FavouritesDbHelper { if (res.warning != null) { return false; } - for (WptPt p : res.points) { + for (WptPt p : res.getPoints()) { int c; String name = p.name; String categoryName = p.category != null ? p.category : ""; diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 4cd24455c3..f0021ef8c3 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -39,6 +39,7 @@ import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; @@ -745,7 +746,7 @@ public class GPXUtilities { public static class GPXFile extends GPXExtensions { public String author; public List tracks = new ArrayList<>(); - public List points = new ArrayList<>(); + private List points = new ArrayList<>(); public List routes = new ArrayList<>(); public String warning = null; @@ -756,6 +757,38 @@ public class GPXUtilities { private Track generalTrack; private TrkSegment generalSegment; + public List getPoints() { + return Collections.unmodifiableList(points); + } + + public boolean isPointsEmpty() { + return points.isEmpty(); + } + + int getPointsSize() { + return points.size(); + } + + boolean containsPoint(WptPt point) { + return points.contains(point); + } + + void clearPoints() { + points.clear(); + } + + public void addPoint(WptPt point) { + points.add(point); + } + + void addPoints(Collection collection) { + points.addAll(collection); + } + + public boolean removePoint(WptPt point) { + return points.remove(point); + } + public boolean isCloudmadeRouteFile() { return "cloudmade".equalsIgnoreCase(author); } diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 5fcb91e40d..9612eec32d 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -26,6 +26,7 @@ import org.json.JSONObject; import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.List; public class GpxSelectionHelper { @@ -76,7 +77,7 @@ public class GpxSelectionHelper { public SelectedGpxFile getSelectedGPXFile(WptPt point) { for (SelectedGpxFile g : selectedGPXFiles) { - if (g.getGpxFile().points.contains(point)) { + if (g.getGpxFile().containsPoint(point)) { return g; } } @@ -214,16 +215,16 @@ public class GpxSelectionHelper { } } - if (g.points.size() > 0) { + if (!g.isPointsEmpty()) { GpxDisplayGroup group = new GpxDisplayGroup(g); group.gpxName = name; group.setType(GpxDisplayItemType.TRACK_POINTS); - group.setDescription(getString(R.string.gpx_selection_number_of_points, g.points.size())); + group.setDescription(getString(R.string.gpx_selection_number_of_points, g.getPointsSize())); group.setName(getString(R.string.gpx_selection_points, name)); dg.add(group); List list = group.getModifiableList(); int k = 0; - for (WptPt r : g.points) { + for (WptPt r : g.getPoints()) { GpxDisplayItem item = new GpxDisplayItem(); item.group = group; item.description = r.desc; @@ -488,6 +489,22 @@ public class GpxSelectionHelper { return sf; } + public void clearPoints(GPXFile gpxFile) { + gpxFile.clearPoints(); + } + + public void addPoint(WptPt point, GPXFile gpxFile) { + gpxFile.addPoint(point); + } + + public void addPoints(Collection collection, GPXFile gpxFile) { + gpxFile.addPoints(collection); + } + + public boolean removePoint(WptPt point, GPXFile gpxFile) { + return gpxFile.removePoint(point); + } + public static class SelectedGpxFile { public boolean notShowNavigationDialog = false; diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 501f009d7e..9b98196b1a 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -701,13 +701,13 @@ public class MapMarkersHelper { fout = new File(dir, fileName + "_" + (++ind) + ".gpx"); } GPXUtilities.GPXFile file = new GPXUtilities.GPXFile(); - for (MapMarker marker : markersDbHelper.getActiveMarkers()) { + for (MapMarker marker : mapMarkers) { GPXUtilities.WptPt wpt = new GPXUtilities.WptPt(); wpt.lat = marker.getLatitude(); wpt.lon = marker.getLongitude(); wpt.setColor(ctx.getResources().getColor(MapMarker.getColorId(marker.colorIndex))); wpt.name = marker.getOnlyName(); - file.points.add(wpt); + file.addPoint(wpt); } GPXUtilities.writeGpxFile(fout, file, ctx); } diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 464c2626fd..d874cf108f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -4,6 +4,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.text.format.DateFormat; + import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.plus.GPXDatabase.GpxDataItem; @@ -19,7 +20,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; -import net.osmand.plus.notifications.OsmandNotification; import net.osmand.plus.notifications.OsmandNotification.NotificationType; import net.osmand.util.MapUtils; @@ -252,7 +252,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { distance = 0; points = 0; duration = 0; - currentTrack.getModifiableGpxFile().points.clear(); + ctx.getSelectedGpxHelper().clearPoints(currentTrack.getModifiableGpxFile()); currentTrack.getModifiableGpxFile().tracks.clear(); currentTrack.getModifiablePointsToDisplay().clear(); currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis(); @@ -305,7 +305,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { gpx = new GPXFile(); dataTracks.put(date, gpx); } - gpx.points.add(pt); + ctx.getSelectedGpxHelper().addPoint(pt, gpx); } while (query.moveToNext()); } @@ -469,7 +469,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { if (color != 0) { pt.setColor(color); } - currentTrack.getModifiableGpxFile().points.add(pt); + ctx.getSelectedGpxHelper().addPoint(pt, currentTrack.getModifiableGpxFile()); currentTrack.getModifiableGpxFile().modifiedTime = time; points++; execWithClose(insertPointsScript, new Object[] { lat, lon, time, description, name, category, color }); @@ -541,7 +541,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } public void deletePointData(WptPt pt) { - currentTrack.getModifiableGpxFile().points.remove(pt); + ctx.getSelectedGpxHelper().removePoint(pt, currentTrack.getModifiableGpxFile()); currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis(); points--; @@ -598,7 +598,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { Map files = collectRecordedData(); currentTrack.getModifiableGpxFile().tracks.clear(); for (Map.Entry entry : files.entrySet()){ - currentTrack.getModifiableGpxFile().points.addAll(entry.getValue().points); + ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile()); currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks); } currentTrack.processPoints(); diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index aff88e1662..0cd778acb5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -4,7 +4,6 @@ import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; @@ -18,8 +17,8 @@ import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXUtilities; -import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; @@ -159,7 +158,7 @@ public class TrackActivity extends TabActivity { } } } - for (WptPt p : getGpx().points) { + for (WptPt p : getGpx().getPoints()) { if (left == 0 && right == 0) { left = p.getLongitude(); right = p.getLongitude(); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java index 6f02d6dde7..1c49bd9c97 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java @@ -311,7 +311,7 @@ public class NotesFragment extends OsmAndListFragment { wpt.link = r.getFileName(); wpt.time = r.getFile().lastModified(); wpt.category = r.getSearchHistoryType(); - file.points.add(wpt); + getMyApplication().getSelectedGpxHelper().addPoint(wpt, file); } } GPXUtilities.writeGpxFile(tmpFile, file, getMyApplication()); diff --git a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java index a119bbaa1c..75720cc882 100644 --- a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java +++ b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java @@ -236,7 +236,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { LinkedList l = new LinkedList(r.points); measurementPoints.add(l); } - for (WptPt p : result.points) { + for (WptPt p : result.getPoints()) { LinkedList l = new LinkedList(); l.add(p); measurementPoints.add(l); @@ -336,14 +336,14 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { saveTrackToRte = originalGPX.routes.size() > 0 && originalGPX.tracks.size() == 0; gpx.tracks.clear(); gpx.routes.clear(); - gpx.points.clear(); + app.getSelectedGpxHelper().clearPoints(gpx); } else { gpx = new GPXFile(); } for (int i = 0; i < measurementPoints.size(); i++) { LinkedList lt = measurementPoints.get(i); if (lt.size() == 1) { - gpx.points.add(lt.getFirst()); + app.getSelectedGpxHelper().addPoint(lt.getFirst(), gpx); } else if (lt.size() > 1) { if (saveTrackToRte) { Route rt = new Route(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java index c42960194b..f74a874db7 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java @@ -225,7 +225,7 @@ public class GpxImportHelper { @Override protected GPXFile doInBackground(Void... nothing) { - final List favourites = asFavourites(gpxFile.points, fileName, forceImportFavourites); + final List favourites = asFavourites(gpxFile.getPoints(), fileName, forceImportFavourites); final FavouritesDbHelper favoritesHelper = app.getFavorites(); for (final FavouritePoint favourite : favourites) { favoritesHelper.deleteFavourite(favourite, false); @@ -492,7 +492,7 @@ public class GpxImportHelper { private void importFavourites(final GPXFile gpxFile, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) { - if (gpxFile == null || gpxFile.points == null || gpxFile.points.size() == 0) { + if (gpxFile == null || gpxFile.isPointsEmpty()) { if (forceImportFavourites) { final DialogInterface.OnClickListener importAsTrackListener = new DialogInterface.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index 4b88b2089b..d4bba497d5 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -870,7 +870,7 @@ public class MapMarkerDialogHelper { //wpt.link = r.getFileName(); //wpt.time = r.getFile().lastModified(); //wpt.category = r.getSearchHistoryType(); - file.points.add(wpt); + file.addPoint(wpt); } GPXUtilities.writeGpxFile(fout, file, app); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index ba5ec52e89..b3166dc624 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -702,7 +702,7 @@ public class TrackSegmentFragment extends OsmAndListFragment { } private void drawPoints(Canvas canvas, RotatedTileBox tileBox, SelectedGpxFile g) { - List pts = g.getGpxFile().points; + List pts = g.getGpxFile().getPoints(); @ColorInt int fileColor = g.getColor() == 0 ? defPointColor : g.getColor(); for (WptPt o : pts) { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java index 8e2b5fa2db..96431875cf 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java @@ -345,14 +345,14 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { } for (WptPt point : params) { if (point.deleted) { - for (WptPt pointInTrack : g.points) { + for (WptPt pointInTrack : g.getPoints()) { if (pointInTrack.getExtensionsToRead().get("u").equals( point.getExtensionsToRead().get("u"))) { - g.points.remove(pointInTrack); + g.removePoint(pointInTrack); } } } else { - g.points.add(point); + g.addPoint(point); } } errors = GPXUtilities.writeGpxFile(ps, g, app); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 57d1ae0e60..fef10ce10f 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -238,8 +238,8 @@ public class RouteProvider { calculateOsmAndRouteParts = builder.calculateOsmAndRouteParts; useIntermediatePointsRTE = builder.useIntermediatePointsRTE; builder.calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute; - if (!file.points.isEmpty()) { - wpt = new ArrayList(file.points); + if (!file.isPointsEmpty()) { + wpt = new ArrayList(file.getPoints()); } if (file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)) { directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10); @@ -845,7 +845,7 @@ public class RouteProvider { boolean leftSide, float defSpeed) { List directions = null; if (!osmandRouter) { - for (WptPt pt : gpxFile.points) { + for (WptPt pt : gpxFile.getPoints()) { res.add(createLocation(pt)); } } else { @@ -1092,7 +1092,7 @@ public class RouteProvider { } pt.desc = pt.name; } - gpx.points.add(pt); + gpx.addPoint(pt); } return gpx; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 95c3981cbb..2e92e7dc81 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1887,7 +1887,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (hasTypeInDescription) { pt.desc = h.getName().getTypeName(); } - gpx.points.add(pt); + gpx.addPoint(pt); } return gpx; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 4f97f07c11..f2c5c9384d 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -118,7 +118,7 @@ public class QuickSearchHelper implements ResourceListener { List list = app.getSelectedGpxHelper().getSelectedGPXFiles(); for (GpxSelectionHelper.SelectedGpxFile selectedGpx : list) { if (selectedGpx != null) { - for (GPXUtilities.WptPt point : selectedGpx.getGpxFile().points) { + for (GPXUtilities.WptPt point : selectedGpx.getGpxFile().getPoints()) { SearchResult sr = new SearchResult(phrase); sr.localeName = point.getPointDescription(app).getName(); sr.object = point; diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 7933b0d696..3957c50e36 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -501,7 +501,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } private List getListStarPoints(SelectedGpxFile g) { - return g.getGpxFile().points; + return g.getGpxFile().getPoints(); } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {