Fix issue 900. Update latest GPX track while display
This commit is contained in:
parent
ffa149b460
commit
78d624b008
9 changed files with 78 additions and 85 deletions
|
@ -246,10 +246,22 @@ public class GPXUtilities {
|
|||
public String warning = null;
|
||||
public String path = "";
|
||||
|
||||
public List<List<WptPt>> processedPointsToDisplay = new ArrayList<List<WptPt>>();
|
||||
|
||||
public boolean isCloudmadeRouteFile(){
|
||||
return "cloudmade".equalsIgnoreCase(author);
|
||||
}
|
||||
|
||||
public void proccessPoints(){
|
||||
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();
|
||||
for (Track t : tracks) {
|
||||
for (TrkSegment ts : t.segments) {
|
||||
tpoints.add(ts.points);
|
||||
}
|
||||
}
|
||||
processedPointsToDisplay = tpoints;
|
||||
}
|
||||
|
||||
public WptPt findPointToShow(){
|
||||
for(Track t : tracks){
|
||||
for(TrkSegment s : t.segments){
|
||||
|
|
|
@ -95,8 +95,8 @@ public class NavigationService extends Service implements LocationListener {
|
|||
serviceOffInterval = settings.SERVICE_OFF_INTERVAL.get();
|
||||
serviceOffProvider = settings.SERVICE_OFF_PROVIDER.get();
|
||||
serviceError = settings.SERVICE_OFF_WAIT_INTERVAL.get();
|
||||
savingTrackHelper = new SavingTrackHelper(this);
|
||||
liveMonitoringHelper = new LiveMonitoringHelper(this);
|
||||
savingTrackHelper = ((OsmandApplication) getApplication()).getSavingTrackHelper();
|
||||
liveMonitoringHelper = ((OsmandApplication) getApplication()).getLiveMonitoringHelper();
|
||||
|
||||
routingHelper = ((OsmandApplication)getApplication()).getRoutingHelper();
|
||||
((OsmandApplication)getApplication()).setNavigationService(this);
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.osmand.LogUtil;
|
|||
import net.osmand.access.AccessibilityMode;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.activities.DayNightHelper;
|
||||
import net.osmand.plus.activities.LiveMonitoringHelper;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||
|
@ -71,9 +72,12 @@ public class OsmandApplication extends Application {
|
|||
private List<String> startingWarnings;
|
||||
private Handler uiHandler;
|
||||
private GPXFile gpxFileToDisplay;
|
||||
private SavingTrackHelper savingTrackHelper;
|
||||
private LiveMonitoringHelper liveMonitoringHelper;
|
||||
|
||||
private boolean applicationInitializing = false;
|
||||
private Locale prefferedLocale = null;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -85,6 +89,8 @@ public class OsmandApplication extends Application {
|
|||
manager = new ResourceManager(this);
|
||||
daynightHelper = new DayNightHelper(this);
|
||||
bidforfix = new BidForFixHelper("osmand.net", getString(R.string.default_buttons_support), getString(R.string.default_buttons_cancel));
|
||||
savingTrackHelper = new SavingTrackHelper(this);
|
||||
liveMonitoringHelper = new LiveMonitoringHelper(this);
|
||||
uiHandler = new Handler();
|
||||
rendererRegistry = new RendererRegistry();
|
||||
checkPrefferedLocale();
|
||||
|
@ -134,6 +140,14 @@ public class OsmandApplication extends Application {
|
|||
return osmandSettings;
|
||||
}
|
||||
|
||||
public SavingTrackHelper getSavingTrackHelper() {
|
||||
return savingTrackHelper;
|
||||
}
|
||||
|
||||
public LiveMonitoringHelper getLiveMonitoringHelper() {
|
||||
return liveMonitoringHelper;
|
||||
}
|
||||
|
||||
|
||||
public PoiFiltersHelper getPoiFilters() {
|
||||
if (poiFilters == null) {
|
||||
|
@ -159,6 +173,7 @@ public class OsmandApplication extends Application {
|
|||
pt.setName(p.name);
|
||||
pts.add(pt);
|
||||
}
|
||||
gpxFileToDisplay.proccessPoints();
|
||||
getFavorites().setFavoritePointsFromGPXFile(pts);
|
||||
}
|
||||
}
|
||||
|
@ -387,12 +402,11 @@ public class OsmandApplication extends Application {
|
|||
}
|
||||
warnings.addAll(manager.reloadIndexes(startDialog));
|
||||
player = null;
|
||||
SavingTrackHelper helper = new SavingTrackHelper(OsmandApplication.this);
|
||||
if (helper.hasDataToSave()) {
|
||||
if (savingTrackHelper.hasDataToSave()) {
|
||||
startDialog.startTask(getString(R.string.saving_gpx_tracks), -1);
|
||||
warnings.addAll(helper.saveDataToGpx());
|
||||
warnings.addAll(savingTrackHelper.saveDataToGpx());
|
||||
}
|
||||
helper.close();
|
||||
savingTrackHelper.close();
|
||||
|
||||
// restore backuped favorites to normal file
|
||||
final File appDir = getSettings().extendOsmandPath(ResourceManager.APP_DIR);
|
||||
|
|
|
@ -198,8 +198,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
|
|||
});
|
||||
|
||||
|
||||
savingTrackHelper = new SavingTrackHelper(this);
|
||||
liveMonitoringHelper = new LiveMonitoringHelper(this);
|
||||
savingTrackHelper = getMyApplication().getSavingTrackHelper();
|
||||
liveMonitoringHelper = getMyApplication().getLiveMonitoringHelper();
|
||||
LatLon pointToNavigate = settings.getPointToNavigate();
|
||||
|
||||
routingHelper = getMyApplication().getRoutingHelper();
|
||||
|
@ -750,11 +750,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
|
|||
if (settings.SAVE_TRACK_TO_GPX.get()) {
|
||||
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
|
||||
location.getSpeed(), location.getAccuracy(), locationTime, settings);
|
||||
if (settings.SHOW_CURRENT_GPX_TRACK.get()) {
|
||||
WptPt pt = new GPXUtilities.WptPt(location.getLatitude(), location.getLongitude(), locationTime,
|
||||
location.getAltitude(), location.getSpeed(), location.getAccuracy());
|
||||
mapLayers.getGpxLayer().addTrackPoint(pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(settings.LIVE_MONITORING.get()){
|
||||
|
|
|
@ -186,7 +186,6 @@ public class MapActivityLayers {
|
|||
}
|
||||
}
|
||||
OsmandPlugin.refreshLayers(mapView, activity);
|
||||
updateGPXLayer();
|
||||
}
|
||||
|
||||
public void updateMapSource(OsmandMapTileView mapView, CommonPreference<String> settingsToWarnAboutMap){
|
||||
|
@ -262,7 +261,6 @@ public class MapActivityLayers {
|
|||
} else if(itemId == R.string.layer_gpx_layer){
|
||||
if(getApplication().getGpxFileToDisplay() != null){
|
||||
getApplication().setGpxFileToDisplay(null, false);
|
||||
gpxLayer.clearCurrentGPX();
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
showGPXFileLayer(mapView);
|
||||
|
@ -365,22 +363,12 @@ public class MapActivityLayers {
|
|||
mapView.getAnimatedDraggingThread().startMoving(loc.lat, loc.lon,
|
||||
mapView.getZoom(), true);
|
||||
}
|
||||
updateGPXLayer();
|
||||
mapView.refreshMap();
|
||||
return true;
|
||||
}
|
||||
}, true, true);
|
||||
}
|
||||
|
||||
private void updateGPXLayer(){
|
||||
GPXFile gpxFileToDisplay = getApplication().getGpxFileToDisplay();
|
||||
if(gpxFileToDisplay == null){
|
||||
gpxLayer.setTracks(null);
|
||||
} else {
|
||||
gpxLayer.setTracks(gpxFileToDisplay.tracks);
|
||||
}
|
||||
}
|
||||
|
||||
public void selectGPXFileLayer(final CallbackWithObject<GPXFile> callbackWithObject, final boolean convertCloudmade,
|
||||
final boolean showCurrentGpx) {
|
||||
final List<String> list = new ArrayList<String>();
|
||||
|
|
|
@ -20,7 +20,6 @@ import net.osmand.plus.ResourceManager;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
@ -46,17 +45,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
public final static String POINT_COL_DESCRIPTION = "description"; //$NON-NLS-1$
|
||||
|
||||
public final static Log log = LogUtil.getLog(SavingTrackHelper.class);
|
||||
|
||||
|
||||
|
||||
|
||||
private String updateScript;
|
||||
private String updatePointsScript;
|
||||
|
||||
private long lastTimeUpdated = 0;
|
||||
private final Context ctx;
|
||||
private final OsmandApplication ctx;
|
||||
|
||||
public SavingTrackHelper(Context ctx){
|
||||
public SavingTrackHelper(OsmandApplication ctx){
|
||||
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
this.ctx = ctx;
|
||||
updateScript = "INSERT INTO " + TRACK_NAME +
|
||||
|
@ -257,6 +253,30 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() * 1000) {
|
||||
execWithClose(updateScript, new Object[] { lat, lon, alt, speed, hdop, time });
|
||||
lastTimeUpdated = time;
|
||||
if (settings.SHOW_CURRENT_GPX_TRACK.get()) {
|
||||
WptPt pt = new GPXUtilities.WptPt(lat, lon, time,
|
||||
alt, speed, hdop);
|
||||
addTrackPoint(pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addTrackPoint(WptPt pt) {
|
||||
GPXFile file = ctx.getGpxFileToDisplay();
|
||||
if (file != null && ctx.getSettings().SHOW_CURRENT_GPX_TRACK.get()) {
|
||||
List<List<WptPt>> points = file.processedPointsToDisplay;
|
||||
if (points.size() == 0) {
|
||||
points.add(new ArrayList<WptPt>());
|
||||
}
|
||||
List<WptPt> last = points.get(points.size() - 1);
|
||||
if (last.size() == 0 || last.get(last.size() - 1).time - pt.time < 6 * 60 * 1000) {
|
||||
// 6 minutes same segment
|
||||
last.add(pt);
|
||||
} else {
|
||||
ArrayList<WptPt> l = new ArrayList<WptPt>();
|
||||
l.add(pt);
|
||||
points.add(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,9 +102,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
SavingTrackHelper helper = new SavingTrackHelper(activity);
|
||||
SavingTrackHelper helper = app.getSavingTrackHelper();
|
||||
if (helper.hasDataToSave()) {
|
||||
saveCurrentTracks(activity);
|
||||
saveCurrentTracks(helper, activity);
|
||||
} else {
|
||||
helper.close();
|
||||
}
|
||||
|
@ -127,14 +127,13 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
|
||||
}
|
||||
|
||||
private void saveCurrentTracks(final SettingsActivity activity) {
|
||||
private void saveCurrentTracks(final SavingTrackHelper helper, final SettingsActivity activity) {
|
||||
activity.progressDlg = ProgressDialog.show(activity, activity.getString(R.string.saving_gpx_tracks), activity.getString(R.string.saving_gpx_tracks), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(activity.progressDlg);
|
||||
impl.setRunnable("SavingGPX", new Runnable() { //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SavingTrackHelper helper = new SavingTrackHelper(activity);
|
||||
helper.saveDataToGpx();
|
||||
helper.close();
|
||||
} finally {
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.GPXUtilities.Track;
|
||||
import net.osmand.GPXUtilities.TrkSegment;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import android.graphics.Canvas;
|
||||
|
@ -22,16 +19,17 @@ public class GPXLayer extends OsmandMapLayer {
|
|||
|
||||
private OsmandMapTileView view;
|
||||
|
||||
private List<List<WptPt>> points = new ArrayList<List<WptPt>>();
|
||||
private Paint paint;
|
||||
|
||||
private Path path;
|
||||
|
||||
private OsmandSettings settings;
|
||||
private boolean fluorescent;
|
||||
|
||||
|
||||
private void initUI() {
|
||||
paint = new Paint();
|
||||
fluorescent = view.getSettings().FLUORESCENT_OVERLAYS.get();
|
||||
if (view.getSettings().FLUORESCENT_OVERLAYS.get()) {
|
||||
paint.setColor(view.getResources().getColor(R.color.gpx_track_fluorescent));
|
||||
} else {
|
||||
|
@ -57,11 +55,14 @@ public class GPXLayer extends OsmandMapLayer {
|
|||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) {
|
||||
initUI(); //to change color immediately when needed
|
||||
List<List<WptPt>> points = this.points;
|
||||
if(points.isEmpty()){
|
||||
GPXFile gpxFile = view.getApplication().getGpxFileToDisplay();
|
||||
if(gpxFile == null){
|
||||
return;
|
||||
}
|
||||
List<List<WptPt>> points = gpxFile.processedPointsToDisplay;
|
||||
if(view.getSettings().FLUORESCENT_OVERLAYS.get() != fluorescent) {
|
||||
initUI(); //to change color immediately when needed
|
||||
}
|
||||
|
||||
for (List<WptPt> l : points) {
|
||||
path.rewind();
|
||||
|
@ -111,41 +112,6 @@ public class GPXLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
|
||||
public void clearCurrentGPX(){
|
||||
points.clear();
|
||||
}
|
||||
|
||||
public void setTracks(List<Track> tracks){
|
||||
if(tracks == null){
|
||||
clearCurrentGPX();
|
||||
} else {
|
||||
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();
|
||||
for (Track t : tracks) {
|
||||
for (TrkSegment ts : t.segments) {
|
||||
tpoints.add(ts.points);
|
||||
}
|
||||
}
|
||||
points = tpoints;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void addTrackPoint(WptPt pt){
|
||||
if(points.size() == 0){
|
||||
points.add(new ArrayList<WptPt>());
|
||||
}
|
||||
List<WptPt> last = points.get(points.size() - 1);
|
||||
if(last.size() == 0 || last.get(last.size() - 1).time - pt.time < 6 * 60 * 1000) {
|
||||
// 6 minutes same segment
|
||||
last.add(pt);
|
||||
} else {
|
||||
ArrayList<WptPt> l = new ArrayList<WptPt>();
|
||||
l.add(pt);
|
||||
points.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.views;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
|
@ -17,7 +16,6 @@ import android.graphics.PointF;
|
|||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.location.Location;
|
||||
import android.util.Log;
|
||||
|
||||
public class RouteLayer extends OsmandMapLayer {
|
||||
|
||||
|
@ -30,6 +28,8 @@ public class RouteLayer extends OsmandMapLayer {
|
|||
private Paint paint;
|
||||
|
||||
private Path path;
|
||||
|
||||
private Boolean fluorescent;
|
||||
|
||||
public RouteLayer(RoutingHelper helper){
|
||||
this.helper = helper;
|
||||
|
@ -40,6 +40,7 @@ public class RouteLayer extends OsmandMapLayer {
|
|||
boundsRect = new Rect(0, 0, view.getWidth(), view.getHeight());
|
||||
tileRect = new RectF();
|
||||
paint = new Paint();
|
||||
fluorescent = view.getSettings().FLUORESCENT_OVERLAYS.get();
|
||||
if (view.getSettings().FLUORESCENT_OVERLAYS.get()) {
|
||||
paint.setColor(view.getResources().getColor(R.color.nav_track_fluorescent));
|
||||
} else {
|
||||
|
@ -63,10 +64,11 @@ public class RouteLayer extends OsmandMapLayer {
|
|||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) {
|
||||
initUI(); //to change color immediately when needed
|
||||
path.reset();
|
||||
if (helper.hasPointsToShow()) {
|
||||
long time = System.currentTimeMillis();
|
||||
if(view.getSettings().FLUORESCENT_OVERLAYS.get() != fluorescent) {
|
||||
initUI(); //to change color immediately when needed
|
||||
}
|
||||
int w = view.getWidth();
|
||||
int h = view.getHeight();
|
||||
if(helper.getCurrentLocation() != null &&
|
||||
|
@ -84,9 +86,6 @@ public class RouteLayer extends OsmandMapLayer {
|
|||
double lat = topLatitude - bottomLatitude + 0.1;
|
||||
double lon = rightLongitude - leftLongitude + 0.1;
|
||||
helper.fillLocationsToShow(topLatitude + lat, leftLongitude - lon, bottomLatitude - lat, rightLongitude + lon, points);
|
||||
if((System.currentTimeMillis() - time) > 80){
|
||||
Log.e(LogUtil.TAG, "Calculate route layer " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if (points.size() > 0) {
|
||||
int px = view.getMapXForPoint(points.get(0).getLongitude());
|
||||
|
|
Loading…
Reference in a new issue