Update display gpx
This commit is contained in:
parent
d4fe3288d2
commit
8896c1b397
3 changed files with 166 additions and 77 deletions
|
@ -9,6 +9,11 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="gpx_selection_number_of_points">%1$s points</string>
|
||||||
|
<string name="gpx_selection_current_track">recording</string>
|
||||||
|
<string name="gpx_selection_route_points">Gpx %1$s - Route points %2$s</string>
|
||||||
|
<string name="gpx_selection_points">Gpx %1$s - Points</string>
|
||||||
|
<string name="gpx_selection_track">Gpx %1$s - Track %2$s</string>
|
||||||
<string name="gpx_file_is_empty">Gpx track is empty</string>
|
<string name="gpx_file_is_empty">Gpx track is empty</string>
|
||||||
<string name="selected_track">Track</string>
|
<string name="selected_track">Track</string>
|
||||||
<string name="my_tracks">All tracks</string>
|
<string name="my_tracks">All tracks</string>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package net.osmand.plus;
|
package net.osmand.plus;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
|
import net.osmand.plus.GPXUtilities.Route;
|
||||||
|
import net.osmand.plus.GPXUtilities.Track;
|
||||||
import net.osmand.plus.GPXUtilities.WptPt;
|
import net.osmand.plus.GPXUtilities.WptPt;
|
||||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
import net.osmand.plus.activities.SavingTrackHelper;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
@ -18,58 +18,100 @@ public class GpxSelectionHelper {
|
||||||
// public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
|
// public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
|
||||||
// new BooleanPreference("show_current_gpx_track", false).makeGlobal().cache();
|
// new BooleanPreference("show_current_gpx_track", false).makeGlobal().cache();
|
||||||
private List<SelectedGpxFile> selectedGPXFiles = new java.util.concurrent.CopyOnWriteArrayList<SelectedGpxFile>();
|
private List<SelectedGpxFile> selectedGPXFiles = new java.util.concurrent.CopyOnWriteArrayList<SelectedGpxFile>();
|
||||||
|
private SavingTrackHelper savingTrackHelper;
|
||||||
|
|
||||||
public GpxSelectionHelper(OsmandApplication osmandApplication) {
|
public GpxSelectionHelper(OsmandApplication osmandApplication) {
|
||||||
this.app = osmandApplication;
|
this.app = osmandApplication;
|
||||||
|
savingTrackHelper = this.app.getSavingTrackHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearAllGpxFileToShow() {
|
public void clearAllGpxFileToShow() {
|
||||||
selectedGPXFiles.clear();
|
selectedGPXFiles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShowingCurrentTrack() {
|
|
||||||
return getCurrentTrack() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isShowingAnyGpxFiles() {
|
public boolean isShowingAnyGpxFiles() {
|
||||||
return !selectedGPXFiles.isEmpty();
|
return !selectedGPXFiles.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectedGpxFile getCurrentTrack() {
|
|
||||||
for(SelectedGpxFile s : selectedGPXFiles) {
|
|
||||||
if(s.isShowCurrentTrack()) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SelectedGpxFile> getSelectedGPXFiles() {
|
public List<SelectedGpxFile> getSelectedGPXFiles() {
|
||||||
return selectedGPXFiles;
|
return selectedGPXFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setToDisplayCurrentGpxFile(boolean show) {
|
public final String getString(int resId, Object... formatArgs) {
|
||||||
if(show != isShowingCurrentTrack()) {
|
return app.getString(resId, formatArgs);
|
||||||
if(show) {
|
|
||||||
TODO_LOAD_CURRENT_BUFFER ;
|
|
||||||
SelectedGpxFile sg = new SelectedGpxFile();
|
|
||||||
sg.setGpxFile(new GPXFile());
|
|
||||||
sg.setShowCurrentTrack(true);
|
|
||||||
selectedGPXFiles.add(sg);
|
|
||||||
} else {
|
|
||||||
Iterator<SelectedGpxFile> it = selectedGPXFiles.iterator();
|
|
||||||
while(it.hasNext()) {
|
|
||||||
if(it.next().isShowCurrentTrack()) {
|
|
||||||
it.remove();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TODO_SAVE_IN_SETTINGS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GpxDisplayGroup> getDisplayGroups() {
|
public List<GpxDisplayGroup> getDisplayGroups() {
|
||||||
TODO;
|
List<GpxDisplayGroup> dg = new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
|
||||||
|
for(SelectedGpxFile s : selectedGPXFiles) {
|
||||||
|
GPXFile g = s.getGpxFile();
|
||||||
|
collectDisplayGroups(dg, g);
|
||||||
|
|
||||||
|
}
|
||||||
|
return dg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectDisplayGroups(List<GpxDisplayGroup> dg, GPXFile g) {
|
||||||
|
String name = g.path;
|
||||||
|
if(g.showCurrentTrack){
|
||||||
|
name = getString(R.string.gpx_selection_current_track);
|
||||||
|
} else {
|
||||||
|
int i = name.indexOf('/');
|
||||||
|
if(i >= 0) {
|
||||||
|
name = name.substring(i + 1);
|
||||||
|
}
|
||||||
|
if(name.endsWith(".gpx")) {
|
||||||
|
name = name.substring(0, name.length() - 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (g.tracks.size() > 0) {
|
||||||
|
int k = 0;
|
||||||
|
for (Track t : g.tracks) {
|
||||||
|
GpxDisplayGroup group = new GpxDisplayGroup(g);
|
||||||
|
group.setType(GpxDisplayItemType.TRACK_POINTS);
|
||||||
|
group.setTrack(t);
|
||||||
|
String ks = (k++) + "";
|
||||||
|
group.setName(getString(R.string.gpx_selection_track, name, g.tracks.size() == 1 ? "" : ks));
|
||||||
|
String d = "";
|
||||||
|
if(t.name != null && t.name.length() > 0) {
|
||||||
|
d = t.name + " " + d;
|
||||||
|
}
|
||||||
|
group.setDescription(d);
|
||||||
|
dg.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (g.routes.size() > 0) {
|
||||||
|
int k = 0;
|
||||||
|
for (Route r : g.routes) {
|
||||||
|
GpxDisplayGroup group = new GpxDisplayGroup(g);
|
||||||
|
group.setType(GpxDisplayItemType.TRACK_ROUTE_POINTS);
|
||||||
|
String d = getString(R.string.gpx_selection_number_of_points, r.points.size());
|
||||||
|
if(r.name != null && r.name.length() > 0) {
|
||||||
|
d = r.name + " " + d;
|
||||||
|
}
|
||||||
|
group.setDescription(d);
|
||||||
|
String ks = (k++) + "";
|
||||||
|
group.setName(getString(R.string.gpx_selection_route_points, name, g.routes.size() == 1 ? "" : ks));
|
||||||
|
dg.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g.points.size() > 0) {
|
||||||
|
GpxDisplayGroup group = new GpxDisplayGroup(g);
|
||||||
|
group.setType(GpxDisplayItemType.TRACK_POINTS);
|
||||||
|
group.setDescription(getString(R.string.gpx_selection_number_of_points, g.points.size()));
|
||||||
|
group.setName(getString(R.string.gpx_selection_points));
|
||||||
|
dg.add(group);
|
||||||
|
List<GpxDisplayItem> list = group.getModifiableList();
|
||||||
|
for (WptPt r : g.points) {
|
||||||
|
GpxDisplayItem item = new GpxDisplayItem();
|
||||||
|
item.description = r.desc;
|
||||||
|
item.name = r.name;
|
||||||
|
item.locationStart = r;
|
||||||
|
item.locationEnd = r;
|
||||||
|
list.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectedGpxFile getSelectedFileByPath(String path) {
|
public SelectedGpxFile getSelectedFileByPath(String path) {
|
||||||
|
@ -81,37 +123,45 @@ public class GpxSelectionHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectedGpxFile setGpxFileToDisplay(GPXFile... gpx) {
|
public void setGpxFileToDisplay(GPXFile... gpxs) {
|
||||||
// special case for gpx current route
|
// special case for gpx current route
|
||||||
SelectedGpxFile sf = getSelectedFileByPath(gpx.path);
|
for(GPXFile gpx : gpxs) {
|
||||||
boolean displayed = sf != null;
|
boolean show = true;
|
||||||
if(displayed != show) {
|
selectGpxFileImpl(gpx, show);
|
||||||
if(show) {
|
|
||||||
sf = new SelectedGpxFile();
|
|
||||||
sf.setGpxFile(gpx);
|
|
||||||
selectedGPXFiles.add(sf);
|
|
||||||
} else {
|
|
||||||
selectedGPXFiles.remove(sf);
|
|
||||||
}
|
}
|
||||||
}
|
saveCurrentSelections();
|
||||||
return sf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectedGpxFile setGpxFileToDisplay(String path, boolean show) {
|
private void saveCurrentSelections() {
|
||||||
SelectedGpxFile sf = getSelectedFileByPath(path);
|
// TODO;
|
||||||
boolean displayed = sf != null;
|
}
|
||||||
|
|
||||||
|
private void selectGpxFileImpl(GPXFile gpx, boolean show) {
|
||||||
|
boolean displayed = false;
|
||||||
|
SelectedGpxFile sf ;
|
||||||
|
if(gpx.showCurrentTrack) {
|
||||||
|
sf = savingTrackHelper.getCurrentTrack();
|
||||||
|
displayed = selectedGPXFiles.contains(sf);
|
||||||
|
} else {
|
||||||
|
sf = getSelectedFileByPath(gpx.path);
|
||||||
|
displayed = sf != null;
|
||||||
|
if(show && sf == null) {
|
||||||
|
sf = new SelectedGpxFile();
|
||||||
|
sf.setGpxFile(gpx);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(displayed != show) {
|
if(displayed != show) {
|
||||||
if(show) {
|
if(show) {
|
||||||
TODO_ASYNC;
|
|
||||||
GPXFile r = GPXUtilities.loadGPXFile(app, new File(path));
|
|
||||||
sf = new SelectedGpxFile();
|
|
||||||
sf.setGpxFile(r);
|
|
||||||
selectedGPXFiles.add(sf);
|
selectedGPXFiles.add(sf);
|
||||||
} else {
|
} else {
|
||||||
selectedGPXFiles.remove(sf);
|
selectedGPXFiles.remove(sf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sf;
|
}
|
||||||
|
|
||||||
|
public void selectGpxFile(GPXFile gpx, boolean show) {
|
||||||
|
selectGpxFileImpl(gpx, show);
|
||||||
|
saveCurrentSelections();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SelectedGpxFile {
|
public static class SelectedGpxFile {
|
||||||
|
@ -160,14 +210,48 @@ public class GpxSelectionHelper {
|
||||||
|
|
||||||
private GpxDisplayItemType type = GpxDisplayItemType.TRACK_SEGMENT;
|
private GpxDisplayItemType type = GpxDisplayItemType.TRACK_SEGMENT;
|
||||||
private List<GpxDisplayItem> list = new ArrayList<GpxDisplayItem>();
|
private List<GpxDisplayItem> list = new ArrayList<GpxDisplayItem>();
|
||||||
|
private GPXFile gpx;
|
||||||
|
private Track track;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public GpxDisplayGroup(GPXFile gpx) {
|
||||||
|
this.gpx = gpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrack(Track track) {
|
||||||
|
this.track = track;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Track getTrack() {
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
||||||
public GpxDisplayGroup cloneInstance() {
|
public GpxDisplayGroup cloneInstance() {
|
||||||
GpxDisplayGroup group = new GpxDisplayGroup();
|
GpxDisplayGroup group = new GpxDisplayGroup(gpx);
|
||||||
group.type = type;
|
group.type = type;
|
||||||
|
group.name = name;
|
||||||
|
group.description = description;
|
||||||
|
group.track = track;
|
||||||
group.list = new ArrayList<GpxSelectionHelper.GpxDisplayItem>(list);
|
group.list = new ArrayList<GpxSelectionHelper.GpxDisplayItem>(list);
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public List<GpxDisplayItem> getModifiableList() {
|
public List<GpxDisplayItem> getModifiableList() {
|
||||||
return list;
|
return list;
|
||||||
|
@ -183,24 +267,20 @@ public class GpxSelectionHelper {
|
||||||
|
|
||||||
|
|
||||||
public String getGroupName(Context ctx) {
|
public String getGroupName(Context ctx) {
|
||||||
return TODO;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GpxDisplayItem {
|
public static class GpxDisplayItem {
|
||||||
|
|
||||||
private boolean filter;
|
public WptPt locationStart;
|
||||||
private String description;
|
public WptPt locationEnd;
|
||||||
private Bitmap image;
|
public String name;
|
||||||
private String url;
|
public String description;
|
||||||
|
public String url;
|
||||||
|
public Bitmap image;
|
||||||
|
|
||||||
public boolean isFilter() {
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilter(boolean filter) {
|
|
||||||
this.filter = filter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -371,4 +371,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
||||||
return currentTrack.getGpxFile();
|
return currentTrack.getGpxFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SelectedGpxFile getCurrentTrack() {
|
||||||
|
return currentTrack;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue