Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-09-15 15:43:16 +02:00
commit 7a47866847
17 changed files with 90 additions and 38 deletions

View file

@ -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 : "";

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,38 @@ public class GPXUtilities {
private Track generalTrack;
private TrkSegment generalSegment;
public List<WptPt> 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<? extends WptPt> collection) {
points.addAll(collection);
}
public boolean removePoint(WptPt point) {
return points.remove(point);
}
public boolean isCloudmadeRouteFile() {
return "cloudmade".equalsIgnoreCase(author);
}

View file

@ -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<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;
@ -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<? extends WptPt> 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;

View file

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

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();
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<String, GPXFile> files = collectRecordedData();
currentTrack.getModifiableGpxFile().tracks.clear();
for (Map.Entry<String, GPXFile> 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();

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);
getMyApplication().getSelectedGpxHelper().addPoint(wpt, file);
}
}
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();
app.getSelectedGpxHelper().clearPoints(gpx);
} 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());
app.getSelectedGpxHelper().addPoint(lt.getFirst(), gpx);
} 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.isPointsEmpty()) {
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

@ -21,7 +21,7 @@ import java.util.Random;
public class MapMarkersDbHelper {
private static final int DB_VERSION = 2;
private static final int DB_VERSION = 7;
public static final String DB_NAME = "map_markers_db";
private static final String MARKERS_TABLE_NAME = "map_markers";
@ -117,7 +117,10 @@ public class MapMarkersDbHelper {
}
private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
// When the DB_VERSION will increase from 7, DROP TABLE must be removed. Existing markers should not be deleted.
db.execSQL("DROP TABLE IF EXISTS " + MARKERS_TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + GROUPS_TABLE_NAME);
onCreate(db);
}
private void saveExistingMarkersToDb() {

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.isPointsEmpty()) {
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) {