Fix gpx color (display from track)
This commit is contained in:
parent
864f5db826
commit
c6b7082f6e
8 changed files with 66 additions and 41 deletions
|
@ -377,9 +377,16 @@ public class Algorithms {
|
|||
|
||||
public static String colorToString(int color) {
|
||||
if ((0xFF000000 & color) == 0xFF000000) {
|
||||
return "#" + Integer.toHexString(color & 0x00FFFFFF); //$NON-NLS-1$
|
||||
return "#" + format(6, Integer.toHexString(color & 0x00FFFFFF)); //$NON-NLS-1$
|
||||
} else {
|
||||
return "#" + Integer.toHexString(color); //$NON-NLS-1$
|
||||
return "#" + format(8, Integer.toHexString(color)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(int i, String hexString) {
|
||||
while(hexString.length() < i) {
|
||||
hexString = "0" + hexString;
|
||||
}
|
||||
return hexString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -531,22 +531,27 @@ public class GPXUtilities {
|
|||
return false;
|
||||
}
|
||||
|
||||
public List<List<WptPt>> processRoutePoints() {
|
||||
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();
|
||||
public List<TrkSegment> processRoutePoints() {
|
||||
List<TrkSegment> tpoints = new ArrayList<TrkSegment>();
|
||||
if (routes.size() > 0) {
|
||||
for (Route r : routes) {
|
||||
tpoints.add(r.points);
|
||||
TrkSegment sgmt = new TrkSegment();
|
||||
tpoints.add(sgmt);
|
||||
sgmt.points.addAll(r.points);
|
||||
}
|
||||
}
|
||||
return tpoints;
|
||||
}
|
||||
|
||||
public List<List<WptPt>> proccessPoints() {
|
||||
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();
|
||||
public List<TrkSegment> proccessPoints() {
|
||||
List<TrkSegment> tpoints = new ArrayList<TrkSegment>();
|
||||
for (Track t : tracks) {
|
||||
for (TrkSegment ts : t.segments) {
|
||||
if (ts.points.size() > 0) {
|
||||
tpoints.add(ts.points);
|
||||
TrkSegment sgmt = new TrkSegment();
|
||||
tpoints.add(sgmt);
|
||||
sgmt.points.addAll(ts.points);
|
||||
sgmt.setColor(t.getColor(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ public class GpxSelectionHelper {
|
|||
private int color;
|
||||
private GPXTrackAnalysis trackAnalysis;
|
||||
private long modifiedTime = -1;
|
||||
private List<List<WptPt>> processedPointsToDisplay = new ArrayList<List<WptPt>>();
|
||||
private List<TrkSegment> processedPointsToDisplay = new ArrayList<TrkSegment>();
|
||||
private boolean routePoints;
|
||||
|
||||
private List<GpxDisplayGroup> displayGroups;
|
||||
|
@ -428,11 +428,11 @@ public class GpxSelectionHelper {
|
|||
return routePoints;
|
||||
}
|
||||
|
||||
public List<List<WptPt>> getPointsToDisplay() {
|
||||
public List<TrkSegment> getPointsToDisplay() {
|
||||
return processedPointsToDisplay;
|
||||
}
|
||||
|
||||
public List<List<WptPt>> getModifiablePointsToDisplay() {
|
||||
public List<TrkSegment> getModifiablePointsToDisplay() {
|
||||
return processedPointsToDisplay;
|
||||
}
|
||||
|
||||
|
|
|
@ -388,19 +388,19 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
private void addTrackPoint(WptPt pt, boolean newSegment, long time) {
|
||||
List<List<WptPt>> points = currentTrack.getModifiablePointsToDisplay();
|
||||
List<TrkSegment> points = currentTrack.getModifiablePointsToDisplay();
|
||||
Track track = currentTrack.getGpxFile().tracks.get(0);
|
||||
assert track.segments.size() == points.size();
|
||||
if (points.size() == 0 || newSegment) {
|
||||
points.add(new ArrayList<WptPt>());
|
||||
points.add(new TrkSegment());
|
||||
}
|
||||
if(track.segments.size() == 0 || newSegment) {
|
||||
track.segments.add(new TrkSegment());
|
||||
}
|
||||
if (pt != null) {
|
||||
int ind = points.size() - 1;
|
||||
List<WptPt> last = points.get(ind);
|
||||
last.add(pt);
|
||||
TrkSegment last = points.get(ind);
|
||||
last.points.add(pt);
|
||||
TrkSegment lt = track.segments.get(track.segments.size() - 1);
|
||||
lt.points.add(pt);
|
||||
}
|
||||
|
@ -448,7 +448,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
currentTrack.getModifiableGpxFile().tracks.add(new Track());
|
||||
}
|
||||
while(currentTrack.getPointsToDisplay().size() < currentTrack.getModifiableGpxFile().tracks.size()) {
|
||||
currentTrack.getModifiablePointsToDisplay().add(new ArrayList<GPXUtilities.WptPt>());
|
||||
TrkSegment trkSegment = new TrkSegment();
|
||||
currentTrack.getModifiablePointsToDisplay().add(trkSegment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -228,7 +228,8 @@ public class OsMoGroupsStorage {
|
|||
protected boolean active;
|
||||
protected boolean deleted;
|
||||
|
||||
protected Map<String, OsMoDevice> users = new ConcurrentHashMap<String, OsMoDevice>();
|
||||
protected Map<String, OsMoDevice> users = new ConcurrentHashMap<String, OsMoDevice>();
|
||||
protected List<String> groupTracks = new ArrayList<String>();
|
||||
|
||||
public List<OsMoDevice> getGroupUsers(String mygid) {
|
||||
// filter deleted
|
||||
|
@ -244,6 +245,10 @@ public class OsMoGroupsStorage {
|
|||
return dvs;
|
||||
}
|
||||
|
||||
public List<String> getGroupTracks() {
|
||||
return groupTracks;
|
||||
}
|
||||
|
||||
public List<OsMoDevice> getVisibleGroupUsers(String mygid) {
|
||||
if(!isActive() && !isMainGroup()) {
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -417,23 +417,23 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
|
|||
}
|
||||
fout.close();
|
||||
is.close();
|
||||
if(color != 0) {
|
||||
try {
|
||||
GPXFile loaded = GPXUtilities.loadGPXFile(app, f);
|
||||
if(loaded.tracks.size() > 0) {
|
||||
for(Track t : loaded.tracks) {
|
||||
t.setColor(color);
|
||||
}
|
||||
GPXUtilities.writeGpxFile(f, loaded, app);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(!f.setLastModified(timestamp)) {
|
||||
log.error("Timestamp updates are not supported");
|
||||
}
|
||||
}
|
||||
if(color != 0) {
|
||||
try {
|
||||
GPXFile loaded = GPXUtilities.loadGPXFile(app, f);
|
||||
if(loaded.tracks.size() > 0) {
|
||||
for(Track t : loaded.tracks) {
|
||||
t.setColor(color);
|
||||
}
|
||||
GPXUtilities.writeGpxFile(f, loaded, app);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
publishProgress(app.getString(R.string.osmo_gpx_track_downloaded, obj.getString("name")));
|
||||
}
|
||||
if(visible && (changed || makeVisible)) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.osmand.map.MapTileDownloader.DownloadRequest;
|
|||
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.TrkSegment;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -94,8 +95,8 @@ public class SherpafyStageItineraryFragment extends SherpafyStageInfoFragment im
|
|||
double left = llon, right = llon;
|
||||
double top = llat, bottom = llat;
|
||||
if (gpx != null) {
|
||||
for (List<WptPt> list : gpx.proccessPoints()) {
|
||||
for (WptPt l : list) {
|
||||
for (TrkSegment list : gpx.proccessPoints()) {
|
||||
for (WptPt l : list.points) {
|
||||
left = Math.min(left, l.getLongitude());
|
||||
right = Math.max(right, l.getLongitude());
|
||||
top = Math.max(top, l.getLatitude());
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.osmand.data.PointDescription;
|
|||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
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;
|
||||
|
@ -69,7 +70,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
|
||||
private OsmandRenderer osmandRenderer;
|
||||
|
||||
private List<List<WptPt>> points;
|
||||
private List<TrkSegment> points;
|
||||
private GPXFile gpx;
|
||||
|
||||
|
||||
|
@ -272,7 +273,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox,
|
||||
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
|
||||
for (SelectedGpxFile g : selectedGPXFiles) {
|
||||
List<List<WptPt>> points = g.getPointsToDisplay();
|
||||
List<TrkSegment> points = g.getPointsToDisplay();
|
||||
boolean routePoints = g.isRoutePoints();
|
||||
updatePaints(g.getColor(), routePoints, settings, tileBox);
|
||||
drawSegments(canvas, tileBox, points);
|
||||
|
@ -298,17 +299,17 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
return pts;
|
||||
}
|
||||
|
||||
private void drawSegments(Canvas canvas, RotatedTileBox tileBox, List<List<WptPt>> points) {
|
||||
private void drawSegments(Canvas canvas, RotatedTileBox tileBox, List<TrkSegment> points) {
|
||||
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||
for (List<WptPt> l : points) {
|
||||
for (TrkSegment l : points) {
|
||||
path.rewind();
|
||||
int startIndex = -1;
|
||||
int endIndex = -1;
|
||||
int prevCross = 0;
|
||||
boolean intersect = false;
|
||||
|
||||
for (int i = 0; i < l.size(); i++) {
|
||||
WptPt ls = l.get(i);
|
||||
for (int i = 0; i < l.points.size(); i++) {
|
||||
WptPt ls = l.points.get(i);
|
||||
int cross = 0;
|
||||
cross |= (ls.lon < latLonBounds.left - 0.1 ? 1 : 0);
|
||||
cross |= (ls.lon > latLonBounds.right + 0.1 ? 2 : 0);
|
||||
|
@ -329,7 +330,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
prevCross = cross;
|
||||
}
|
||||
if (startIndex != -1) {
|
||||
drawSegment(canvas, tileBox, l, startIndex, l.size() - 1);
|
||||
drawSegment(canvas, tileBox, l, startIndex, l.points.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -340,13 +341,13 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
|
||||
|
||||
|
||||
private void drawSegment(Canvas canvas, RotatedTileBox tb, List<WptPt> l, int startIndex, int endIndex) {
|
||||
private void drawSegment(Canvas canvas, RotatedTileBox tb, TrkSegment l, int startIndex, int endIndex) {
|
||||
TIntArrayList tx = new TIntArrayList();
|
||||
TIntArrayList ty = new TIntArrayList();
|
||||
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||
|
||||
for (int i = startIndex; i <= endIndex; i++) {
|
||||
WptPt p = l.get(i);
|
||||
WptPt p = l.points.get(i);
|
||||
int x = (int) tb.getPixXFromLatLon(p.lat, p.lon);
|
||||
int y = (int) tb.getPixYFromLatLon(p.lat, p.lon);
|
||||
// int x = tb.getPixXFromLonNoRot(p.lon);
|
||||
|
@ -361,7 +362,12 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
if(isShadowPaint) {
|
||||
canvas.drawPath(path, shadowPaint);
|
||||
}
|
||||
int clr = paint.getColor();
|
||||
if(clr != l.getColor(clr)) {
|
||||
paint.setColor(l.getColor(clr));
|
||||
}
|
||||
canvas.drawPath(path, paint);
|
||||
paint.setColor(clr);
|
||||
if(isPaint2) {
|
||||
canvas.drawPath(path, paint2);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue