Convert points to private field; replace direct access with methods

This commit is contained in:
Alexander Sytnyk 2017-09-14 19:00:37 +03:00
parent d6a20eb1d1
commit 71abe29c27
15 changed files with 58 additions and 38 deletions

View file

@ -408,7 +408,7 @@ public class FavouritesDbHelper {
if (p.getOriginObjectName().length() > 0) {
pt.comment = p.getOriginObjectName();
}
gpx.points.add(pt);
gpx.addPoint(pt);
}
return gpx;
}
@ -560,7 +560,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 : "";

View file

@ -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<Track> tracks = new ArrayList<>();
public List<WptPt> points = new ArrayList<>();
private List<WptPt> points = new ArrayList<>();
public List<Route> routes = new ArrayList<>();
public String warning = null;
@ -756,6 +757,26 @@ public class GPXUtilities {
private Track generalTrack;
private TrkSegment generalSegment;
public List<WptPt> getPoints() {
return points;
}
public void clearPoints() {
points.clear();
}
public void addPoint(WptPt point) {
points.add(point);
}
public void addAllPoints(Collection<? extends WptPt> collection) {
points.addAll(collection);
}
public boolean removePoint(WptPt point) {
return points.remove(point);
}
public boolean isCloudmadeRouteFile() {
return "cloudmade".equalsIgnoreCase(author);
}
@ -1200,7 +1221,7 @@ public class GPXUtilities {
serializer.endTag(null, "rte"); //$NON-NLS-1$
}
for (WptPt l : file.points) {
for (WptPt l : file.getPoints()) {
serializer.startTag(null, "wpt"); //$NON-NLS-1$
writeWpt(format, serializer, l);
serializer.endTag(null, "wpt"); //$NON-NLS-1$
@ -1381,7 +1402,7 @@ public class GPXUtilities {
}
if (parser.getName().equals("wpt")) {
WptPt wptPt = parseWptAttributes(parser);
((GPXFile) parse).points.add(wptPt);
((GPXFile) parse).addPoint(wptPt);
parserState.push(wptPt);
}
} else if (parse instanceof Route) {
@ -1556,8 +1577,8 @@ public class GPXUtilities {
if (from.showCurrentTrack) {
to.showCurrentTrack = true;
}
if (from.points != null) {
to.points.addAll(from.points);
if (from.getPoints() != null) {
to.addAllPoints(from.getPoints());
}
if (from.tracks != null) {
to.tracks.addAll(from.tracks);

View file

@ -76,7 +76,7 @@ public class GpxSelectionHelper {
public SelectedGpxFile getSelectedGPXFile(WptPt point) {
for (SelectedGpxFile g : selectedGPXFiles) {
if (g.getGpxFile().points.contains(point)) {
if (g.getGpxFile().getPoints().contains(point)) {
return g;
}
}
@ -214,16 +214,16 @@ public class GpxSelectionHelper {
}
}
if (g.points.size() > 0) {
if (g.getPoints().size() > 0) {
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.getPoints().size()));
group.setName(getString(R.string.gpx_selection_points, name));
dg.add(group);
List<GpxDisplayItem> 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;

View file

@ -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();
currentTrack.getModifiableGpxFile().clearPoints();
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);
gpx.addPoint(pt);
} while (query.moveToNext());
}
@ -469,7 +469,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
if (color != 0) {
pt.setColor(color);
}
currentTrack.getModifiableGpxFile().points.add(pt);
currentTrack.getModifiableGpxFile().addPoint(pt);
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);
currentTrack.getModifiableGpxFile().removePoint(pt);
currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
points--;
@ -598,7 +598,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
Map<String, GPXFile> files = collectRecordedData();
currentTrack.getModifiableGpxFile().tracks.clear();
for (Map.Entry<String, GPXFile> entry : files.entrySet()){
currentTrack.getModifiableGpxFile().points.addAll(entry.getValue().points);
currentTrack.getModifiableGpxFile().addAllPoints(entry.getValue().getPoints());
currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks);
}
currentTrack.processPoints();

View file

@ -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();

View file

@ -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);
file.addPoint(wpt);
}
}
GPXUtilities.writeGpxFile(tmpFile, file, getMyApplication());

View file

@ -236,7 +236,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
LinkedList<WptPt> l = new LinkedList<WptPt>(r.points);
measurementPoints.add(l);
}
for (WptPt p : result.points) {
for (WptPt p : result.getPoints()) {
LinkedList<WptPt> l = new LinkedList<WptPt>();
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();
gpx.clearPoints();
} else {
gpx = new GPXFile();
}
for (int i = 0; i < measurementPoints.size(); i++) {
LinkedList<WptPt> lt = measurementPoints.get(i);
if (lt.size() == 1) {
gpx.points.add(lt.getFirst());
gpx.addPoint(lt.getFirst());
} else if (lt.size() > 1) {
if (saveTrackToRte) {
Route rt = new Route();

View file

@ -225,7 +225,7 @@ public class GpxImportHelper {
@Override
protected GPXFile doInBackground(Void... nothing) {
final List<FavouritePoint> favourites = asFavourites(gpxFile.points, fileName, forceImportFavourites);
final List<FavouritePoint> 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.getPoints() == null || gpxFile.getPoints().size() == 0) {
if (forceImportFavourites) {
final DialogInterface.OnClickListener importAsTrackListener = new DialogInterface.OnClickListener() {
@Override

View file

@ -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);
}

View file

@ -702,7 +702,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
}
private void drawPoints(Canvas canvas, RotatedTileBox tileBox, SelectedGpxFile g) {
List<WptPt> pts = g.getGpxFile().points;
List<WptPt> pts = g.getGpxFile().getPoints();
@ColorInt
int fileColor = g.getColor() == 0 ? defPointColor : g.getColor();
for (WptPt o : pts) {

View file

@ -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);

View file

@ -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<LocationPoint>(file.points);
if (!file.getPoints().isEmpty()) {
wpt = new ArrayList<LocationPoint>(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<RouteDirectionInfo> 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;
}

View file

@ -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;
}

View file

@ -118,7 +118,7 @@ public class QuickSearchHelper implements ResourceListener {
List<GpxSelectionHelper.SelectedGpxFile> 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;

View file

@ -501,7 +501,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
private List<WptPt> getListStarPoints(SelectedGpxFile g) {
return g.getGpxFile().points;
return g.getGpxFile().getPoints();
}
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {