Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-06-02 14:02:05 +02:00
commit 8ea9dc37d5
4 changed files with 122 additions and 54 deletions

View file

@ -12,7 +12,6 @@ import net.osmand.PlatformUtil;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.Renderable;
import net.osmand.util.Algorithms;
@ -85,7 +84,7 @@ public class GPXUtilities {
public Map<String, String> getExtensionsToWrite() {
if (extensions == null) {
extensions = new LinkedHashMap<String, String>();
extensions = new LinkedHashMap<>();
}
return extensions;
}
@ -124,26 +123,24 @@ public class GPXUtilities {
public WptPt() {
}
// public WptPt(WptPt toCopy) {
// this.lat = toCopy.lat;
// this.lon = toCopy.lon;
// if (toCopy.name != null) {
// this.name = new String(toCopy.name);
// }
// if (toCopy.link != null) {
// this.link = new String(toCopy.link);
// }
// if (toCopy.category != null) {
// this.category = new String(toCopy.category);
// }
// this.time = toCopy.time;
// this.ele = toCopy.ele;
// this.speed = toCopy.speed;
// this.hdop = toCopy.hdop;
// this.deleted = toCopy.deleted;
// this.colourARGB = toCopy.colourARGB;
// this.distance = toCopy.distance;
// }
public WptPt(WptPt wptPt) {
this.lat = wptPt.lat;
this.lon = wptPt.lon;
this.name = wptPt.name;
this.link = wptPt.link;
this.category = wptPt.category;
this.desc = wptPt.desc;
this.comment = wptPt.comment;
this.time = wptPt.time;
this.ele = wptPt.ele;
this.speed = wptPt.speed;
this.hdop = wptPt.hdop;
this.deleted = wptPt.deleted;
this.colourARGB = wptPt.colourARGB;
this.distance = wptPt.distance;
}
public void setDistance(double dist) {
distance = dist;
@ -217,8 +214,7 @@ public class GPXUtilities {
}
public static class TrkSegment extends GPXExtensions {
public List<WptPt> points = new ArrayList<WptPt>();
private OsmandMapTileView view;
public List<WptPt> points = new ArrayList<>();
public List<Renderable.RenderableSegment> renders = new ArrayList<>();
@ -231,7 +227,7 @@ public class GPXUtilities {
}
private List<GPXTrackAnalysis> split(SplitMetric metric, SplitMetric secondaryMetric, double metricLimit) {
List<SplitSegment> splitSegments = new ArrayList<GPXUtilities.SplitSegment>();
List<SplitSegment> splitSegments = new ArrayList<>();
splitSegment(metric, secondaryMetric, metricLimit, splitSegments, this);
return convert(splitSegments);
}
@ -246,14 +242,14 @@ public class GPXUtilities {
public static class Track extends GPXExtensions {
public String name = null;
public String desc = null;
public List<TrkSegment> segments = new ArrayList<TrkSegment>();
public List<TrkSegment> segments = new ArrayList<>();
}
public static class Route extends GPXExtensions {
public String name = null;
public String desc = null;
public List<WptPt> points = new ArrayList<WptPt>();
public List<WptPt> points = new ArrayList<>();
}
@ -710,7 +706,7 @@ public class GPXUtilities {
}
private static List<GPXTrackAnalysis> convert(List<SplitSegment> splitSegments) {
List<GPXTrackAnalysis> ls = new ArrayList<GPXUtilities.GPXTrackAnalysis>();
List<GPXTrackAnalysis> ls = new ArrayList<>();
for (SplitSegment s : splitSegments) {
GPXTrackAnalysis a = new GPXTrackAnalysis();
a.prepareInformation(0, s);
@ -721,19 +717,64 @@ public class GPXUtilities {
public static class GPXFile extends GPXExtensions {
public String author;
public List<Track> tracks = new ArrayList<Track>();
public List<WptPt> points = new ArrayList<WptPt>();
public List<Route> routes = new ArrayList<Route>();
public List<Track> tracks = new ArrayList<>();
public List<WptPt> points = new ArrayList<>();
public List<Route> routes = new ArrayList<>();
public String warning = null;
public String path = "";
public boolean showCurrentTrack;
public long modifiedTime = 0;
private Track generalTrack;
private TrkSegment generalSegment;
public boolean isCloudmadeRouteFile() {
return "cloudmade".equalsIgnoreCase(author);
}
public void addGeneralTrack() {
Track generalTrack = getGeneralTrack();
if (generalTrack != null && !tracks.contains(generalTrack)) {
tracks.add(0, generalTrack);
}
}
public Track getGeneralTrack() {
TrkSegment generalSegment = getGeneralSegment();
if (generalTrack == null && generalSegment != null) {
Track track = new Track();
track.segments = new ArrayList<>();
track.segments.add(generalSegment);
generalTrack = track;
}
return generalTrack;
}
public TrkSegment getGeneralSegment() {
if (generalSegment == null && getNonEmptySegmentsCount() > 1) {
buildGeneralSegment();
}
return generalSegment;
}
private void buildGeneralSegment() {
TrkSegment segment = new TrkSegment();
for (Track track : tracks) {
for (TrkSegment s : track.segments) {
if (s.points.size() > 0) {
List<WptPt> waypoints = new ArrayList<>(s.points.size());
for (WptPt wptPt : s.points) {
waypoints.add(new WptPt(wptPt));
}
segment.points.addAll(waypoints);
}
}
}
if (segment.points.size() > 0) {
generalSegment = segment;
}
}
public GPXTrackAnalysis getAnalysis(long fileTimestamp) {
GPXTrackAnalysis g = new GPXTrackAnalysis();
@ -909,7 +950,17 @@ public class GPXUtilities {
return points.isEmpty() && routes.isEmpty();
}
public int getNonEmptySegmentsCount() {
int count = 0;
for (Track t : tracks) {
for (TrkSegment s : t.segments) {
if (s.points.size() > 0) {
count++;
}
}
}
return count;
}
}
public static String asString(GPXFile file, OsmandApplication ctx) {
@ -1057,7 +1108,7 @@ public class GPXUtilities {
public static class GPXFileResult {
public ArrayList<List<Location>> locations = new ArrayList<List<Location>>();
public ArrayList<WptPt> wayPoints = new ArrayList<WptPt>();
public ArrayList<WptPt> wayPoints = new ArrayList<>();
// special case for cloudmate gpx : they discourage common schema
// by using waypoint as track points and rtept are not very close to real way
// such as wpt. However they provide additional information into gpx.

View file

@ -86,6 +86,23 @@ public class GpxSelectionHelper {
return app.getString(resId, formatArgs);
}
public GpxDisplayGroup buildGeneralGpxDisplayGroup(GPXFile g, Track t) {
GpxDisplayGroup group = new GpxDisplayGroup(g);
String name = getGroupName(g);
group.gpxName = name;
group.color = t.getColor(g.getColor(0));
group.setType(GpxDisplayItemType.TRACK_SEGMENT);
group.setTrack(t);
group.setName(getString(R.string.gpx_selection_track, name, ""));
String d = "";
if (t.name != null && t.name.length() > 0) {
d = t.name + " " + d;
}
group.setDescription(d);
processGroupTrack(app, group);
return group;
}
public GpxDisplayGroup buildGpxDisplayGroup(GPXFile g, int trackIndex, String name) {
Track t = g.tracks.get(trackIndex);
GpxDisplayGroup group = new GpxDisplayGroup(g);

View file

@ -88,7 +88,7 @@ public class TrackActivity extends TabActivity {
@Override
protected GPXFile doInBackground(Void... params) {
long startTime = System.currentTimeMillis();
GPXFile result = null;
GPXFile result;
if (file == null) {
result = getMyApplication().getSavingTrackHelper().getCurrentGpx();
} else {
@ -100,9 +100,11 @@ public class TrackActivity extends TabActivity {
}
}
if (result != null) {
while (System.currentTimeMillis() - startTime < 200) {
result.addGeneralTrack();
long timeout = 200 - (System.currentTimeMillis() - startTime);
if (timeout > 0) {
try {
Thread.sleep(50);
Thread.sleep(timeout);
} catch (InterruptedException e) {
// ignore
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.myplaces;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
@ -51,6 +50,7 @@ import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
@ -95,8 +95,6 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import static net.osmand.plus.R.id.items;
public class AvailableGPXFragment extends OsmandExpandableListFragment {
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
@ -1257,26 +1255,26 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
protected GpxDisplayItem doInBackground(Void... voids) {
List<GpxDisplayGroup> gpxDisplayGroupList;
GpxDisplayGroup gpxDisplayGroup = null;
GPXFile gpxFile = null;
Track generalTrack = null;
if (gpxInfo.gpx == null) {
GPXFile gpxFile;
if (gpxInfo.file == null) {
gpxFile = getMyApplication().getSavingTrackHelper().getCurrentGpx();
} else {
if (gpxInfo.file != null) {
gpxFile = GPXUtilities.loadGPXFile(getActivity(), gpxInfo.file);
}
gpxDisplayGroupList = selectedGpxHelper.collectDisplayGroups(gpxFile);
} else {
gpxDisplayGroupList = selectedGpxHelper.collectDisplayGroups(gpxInfo.gpx);
gpxFile = gpxInfo.gpx;
}
if (gpxFile != null) {
generalTrack = gpxFile.getGeneralTrack();
}
if (generalTrack != null) {
gpxFile.addGeneralTrack();
gpxDisplayGroup = selectedGpxHelper.buildGeneralGpxDisplayGroup(gpxFile, generalTrack);
}
List<GpxDisplayItem> items = null;
if (gpxDisplayGroupList != null) {
for (GpxDisplayGroup group : gpxDisplayGroupList) {
if (group.getType() == GpxSelectionHelper.GpxDisplayItemType.TRACK_SEGMENT) {
items = group.getModifiableList();
break;
}
}
if (gpxDisplayGroup != null) {
items = gpxDisplayGroup.getModifiableList();
}
if (items != null && items.size() > 0) {
return items.get(0);
@ -1331,7 +1329,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
GPXTrackAnalysis analysis;
if ((analysis = getGpxTrackAnalysis(gpxInfo, app)) != null) {
if (analysis.totalDistance != 0) {
if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
item = optionsMenu.getMenu().add(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override