Fix issue 471. Store gpx layer
This commit is contained in:
parent
f4e268275e
commit
57bb4d9fcf
5 changed files with 126 additions and 66 deletions
18
OsmAnd/src/net/osmand/CallbackWithObject.java
Normal file
18
OsmAnd/src/net/osmand/CallbackWithObject.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package net.osmand;
|
||||
|
||||
/**
|
||||
* That class is designed to be common interface for callbacks with one param
|
||||
* @author victor
|
||||
* @param <T>
|
||||
*/
|
||||
public interface CallbackWithObject<T> {
|
||||
|
||||
|
||||
/**
|
||||
* Calls on processing result
|
||||
* @param result could be null depends on usage
|
||||
* @return processed or not
|
||||
*/
|
||||
public boolean processResult(T result);
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.Version;
|
||||
import net.osmand.GPXUtilities.GPXFileResult;
|
||||
|
@ -1006,7 +1007,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
}
|
||||
mapView.refreshMap();
|
||||
} else if (item.getItemId() == R.id.map_gpx_routing) {
|
||||
mapLayers.useGPXFileLayer(true, mapLayers.getNavigationLayer().getPointToNavigate(), mapView);
|
||||
useGPXRouting();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.map_show_point_options) {
|
||||
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
|
||||
|
@ -1169,15 +1170,20 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
return ((OsmandApplication)getApplication()).getFavorites();
|
||||
}
|
||||
|
||||
public void useGPXRouting(final LatLon endForRouting, final GPXFileResult res) {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
private void useGPXRouting() {
|
||||
final LatLon endForRouting = getPointToNavigate();
|
||||
mapLayers.selectGPXFileLayer(new CallbackWithObject<GPXFileResult>() {
|
||||
|
||||
@Override
|
||||
public boolean processResult(final GPXFileResult result) {
|
||||
Builder builder = new AlertDialog.Builder(MapActivity.this);
|
||||
builder.setItems(new String[]{getString(R.string.gpx_direct_route), getString(R.string.gpx_reverse_route)},
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
boolean reverse = which == 1;
|
||||
ArrayList<List<Location>> locations = res.locations;
|
||||
ArrayList<List<Location>> locations = result.locations;
|
||||
List<Location> l = new ArrayList<Location>();
|
||||
for(List<Location> s : locations){
|
||||
l.addAll(s);
|
||||
|
@ -1196,6 +1202,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
endPoint = point;
|
||||
mapLayers.getNavigationLayer().setPointToNavigate(point);
|
||||
}
|
||||
mapView.refreshMap();
|
||||
if(endForRouting != null){
|
||||
settings.FOLLOW_TO_THE_ROUTE.set(true);
|
||||
routingHelper.setFollowingMode(true);
|
||||
|
@ -1203,10 +1210,14 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
((OsmandApplication)getApplication()).showDialogInitializingCommandPlayer(MapActivity.this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void contextMenuPoint(final double latitude, final double longitude){
|
||||
|
|
|
@ -8,14 +8,12 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.FavouritePoint;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.OsmAndFormatter;
|
||||
import net.osmand.GPXUtilities.GPXFileResult;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.PoiFilter;
|
||||
import net.osmand.plus.PoiFiltersHelper;
|
||||
|
@ -47,7 +45,6 @@ import android.app.ProgressDialog;
|
|||
import android.app.AlertDialog.Builder;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Looper;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -184,6 +181,7 @@ public class MapActivityLayers {
|
|||
mapView.removeLayer(favoritesLayer);
|
||||
}
|
||||
}
|
||||
updateGPXLayer();
|
||||
trafficLayer.setVisible(settings.SHOW_YANDEX_TRAFFIC.get());
|
||||
}
|
||||
|
||||
|
@ -298,11 +296,11 @@ public class MapActivityLayers {
|
|||
settings.SHOW_FAVORITES.set(isChecked);
|
||||
} else if(item == 5){
|
||||
if(gpxLayer.isVisible()){
|
||||
getApplication().setGpxFileToDisplay(null);
|
||||
gpxLayer.clearCurrentGPX();
|
||||
getApplication().getFavorites().setFavoritePointsFromGPXFile(null);
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
useGPXFileLayer(false, null, mapView);
|
||||
showGPXFileLayer(mapView);
|
||||
}
|
||||
} else if(item == 6){
|
||||
if(overlayLayer.getMap() != null){
|
||||
|
@ -336,7 +334,32 @@ public class MapActivityLayers {
|
|||
builder.show();
|
||||
}
|
||||
|
||||
public void useGPXFileLayer(final boolean useRouting, final LatLon endForRouting, final OsmandMapTileView mapView) {
|
||||
public void showGPXFileLayer(final OsmandMapTileView mapView){
|
||||
final OsmandSettings settings = getApplication().getSettings();
|
||||
selectGPXFileLayer(new CallbackWithObject<GPXFileResult>() {
|
||||
@Override
|
||||
public boolean processResult(GPXFileResult result) {
|
||||
settings.SHOW_FAVORITES.set(true);
|
||||
if (result != null) {
|
||||
getApplication().setGpxFileToDisplay(result);
|
||||
updateGPXLayer();
|
||||
mapView.refreshMap();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateGPXLayer(){
|
||||
GPXFileResult gpxFileToDisplay = getApplication().getGpxFileToDisplay();
|
||||
if(gpxFileToDisplay == null){
|
||||
gpxLayer.setTracks(null);
|
||||
} else {
|
||||
gpxLayer.setTracks(gpxFileToDisplay.locations);
|
||||
}
|
||||
}
|
||||
|
||||
public void selectGPXFileLayer(final CallbackWithObject<GPXFileResult> callbackWithObject) {
|
||||
final List<String> list = new ArrayList<String>();
|
||||
final OsmandSettings settings = getApplication().getSettings();
|
||||
final File dir = settings.extendOsmandPath(ResourceManager.APP_DIR + SavingTrackHelper.TRACKS_PATH);
|
||||
|
@ -379,7 +402,6 @@ public class MapActivityLayers {
|
|||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
final GPXFileResult res = GPXUtilities.loadGPXFile(activity, f);
|
||||
if (res.error != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
@ -391,28 +413,13 @@ public class MapActivityLayers {
|
|||
|
||||
}
|
||||
dlg.dismiss();
|
||||
if(useRouting){
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.useGPXRouting(endForRouting, res);
|
||||
callbackWithObject.processResult(res);
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
settings.SHOW_FAVORITES.set(true);
|
||||
List<FavouritePoint> pts = new ArrayList<FavouritePoint>();
|
||||
for(WptPt p : res.wayPoints){
|
||||
FavouritePoint pt = new FavouritePoint();
|
||||
pt.setLatitude(p.lat);
|
||||
pt.setLongitude(p.lon);
|
||||
pt.setName(p.name);
|
||||
pts.add(pt);
|
||||
}
|
||||
getApplication().getFavorites().setFavoritePointsFromGPXFile(pts);
|
||||
gpxLayer.setTracks(res.locations);
|
||||
}
|
||||
mapView.refreshMap();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,11 +6,15 @@ import java.io.File;
|
|||
import java.io.FileWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.FavouritePoint;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.GPXUtilities.GPXFileResult;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -53,6 +57,7 @@ public class OsmandApplication extends Application {
|
|||
private List<String> startingWarnings;
|
||||
private ProgressDialog progressDlg;
|
||||
private Handler uiHandler;
|
||||
private GPXFileResult gpxFileToDisplay;
|
||||
|
||||
private boolean applicationInitializing = false;
|
||||
private Locale prefferedLocale = null;
|
||||
|
@ -89,6 +94,27 @@ public class OsmandApplication extends Application {
|
|||
return poiFilters;
|
||||
}
|
||||
|
||||
public void setGpxFileToDisplay(GPXFileResult gpxFileToDisplay) {
|
||||
this.gpxFileToDisplay = gpxFileToDisplay;
|
||||
if(gpxFileToDisplay == null){
|
||||
getFavorites().setFavoritePointsFromGPXFile(null);
|
||||
} else {
|
||||
List<FavouritePoint> pts = new ArrayList<FavouritePoint>();
|
||||
for (WptPt p : gpxFileToDisplay.wayPoints) {
|
||||
FavouritePoint pt = new FavouritePoint();
|
||||
pt.setLatitude(p.lat);
|
||||
pt.setLongitude(p.lon);
|
||||
pt.setName(p.name);
|
||||
pts.add(pt);
|
||||
}
|
||||
getFavorites().setFavoritePointsFromGPXFile(pts);
|
||||
}
|
||||
}
|
||||
|
||||
public GPXFileResult getGpxFileToDisplay() {
|
||||
return gpxFileToDisplay;
|
||||
}
|
||||
|
||||
public FavouritesDbHelper getFavorites() {
|
||||
if(favorites == null) {
|
||||
favorites = new FavouritesDbHelper(this);
|
||||
|
|
|
@ -89,8 +89,6 @@ public class FavoritesLayer implements OsmandMapLayer, ContextMenuLayer.IContext
|
|||
@Override
|
||||
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, boolean nightMode) {
|
||||
if (view.getZoom() >= startZoom) {
|
||||
|
||||
|
||||
// request to load
|
||||
for (FavouritePoint o : favorites.getFavouritePoints()) {
|
||||
if (o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left
|
||||
|
|
Loading…
Reference in a new issue