From a1095ea959abb0c074467e1fd38589bc3d7e9987 Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Tue, 22 Apr 2014 22:44:21 +0200 Subject: [PATCH 1/7] import gpx --- OsmAnd/AndroidManifest.xml | 5 ++ .../osmand/plus/activities/MapActivity.java | 61 ++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 1d14c3103c..3944759dbb 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -68,6 +68,11 @@ + + + + + diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 3e5b0dd727..fdefeedb4a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1,11 +1,13 @@ package net.osmand.plus.activities; +import java.io.File; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import net.osmand.CallbackWithObject; import net.osmand.Location; import net.osmand.StateChangedListener; import net.osmand.access.AccessibilityPlugin; @@ -19,6 +21,8 @@ import net.osmand.map.MapTileDownloader.DownloadRequest; import net.osmand.map.MapTileDownloader.IMapDownloaderCallback; import net.osmand.plus.ApplicationMode; import net.osmand.plus.BusyIndicator; +import net.osmand.plus.GPXUtilities; +import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -63,6 +67,7 @@ import android.view.Window; import android.widget.FrameLayout; import android.widget.ProgressBar; import android.widget.Toast; +import org.apache.http.client.protocol.ClientContext; public class MapActivity extends AccessibleActivity { @@ -318,6 +323,16 @@ public class MapActivity extends AccessibleActivity { mapViewTrackingUtilities.setMapLinkedToLocation(false); } + final Intent intent = getIntent(); + if (intent != null && intent.getData() != null) + { + final Uri data = intent.getData(); + if ("file".equalsIgnoreCase(data.getScheme())) + { + navigateImportedGpx(data.getPath()); + } + } + View progress = mapLayers.getMapInfoLayer().getProgressBar(); if (progress != null) { app.getResourceManager().setBusyIndicator(new BusyIndicator(this, progress)); @@ -641,7 +656,7 @@ public class MapActivity extends AccessibleActivity { } } } - + public MapActivityActions getMapActions() { return mapActions; } @@ -666,7 +681,49 @@ public class MapActivity extends AccessibleActivity { public void refreshMap() { getMapView().refreshMap(); } - + private void navigateImportedGpx(final String gpxFile) + { + final CallbackWithObject callback = new CallbackWithObject() + { + @Override + public boolean processResult(GPXFile result) + { + getMapActions().setGPXRouteParams(result); + getMyApplication().getTargetPointsHelper().updateRoutingHelper(); + getRoutingHelper().recalculateRouteDueToSettingsChange(); + return true; + } + }; + final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading_data)); + new Thread(new Runnable() + { + @Override + public void run() + { + final GPXFile res = GPXUtilities.loadGPXFile(getApplication(), new File(gpxFile)); + dlg.dismiss(); + if (res != null) + { + MapActivity.this.runOnUiThread(new Runnable() + { + @Override + public void run() + { + if (res.warning != null) + { + AccessibleToast.makeText(MapActivity.this, res.warning, Toast.LENGTH_LONG).show(); + } + else + { + callback.processResult(res); + } + } + }); + } + } + + }, "Loading gpx").start(); //$NON-NLS-1$ + } } From 3536f44f4c40230d56ce92c2513df20cb53fd913 Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Tue, 22 Apr 2014 22:46:36 +0200 Subject: [PATCH 2/7] show imported gpx file --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index fdefeedb4a..e8b33ef4e5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -689,6 +689,7 @@ public class MapActivity extends AccessibleActivity { @Override public boolean processResult(GPXFile result) { + getMyApplication().setGpxFileToDisplay(result, true); getMapActions().setGPXRouteParams(result); getMyApplication().getTargetPointsHelper().updateRoutingHelper(); getRoutingHelper().recalculateRouteDueToSettingsChange(); From 011ebf7b25a4b2dda6a03194f2e1ec2d41d96fa9 Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Tue, 22 Apr 2014 22:46:36 +0200 Subject: [PATCH 3/7] - use AsyncTask - only show gpx route --- .../osmand/plus/activities/MapActivity.java | 68 ++++++++----------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index e8b33ef4e5..82db0cf491 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -7,7 +7,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import net.osmand.CallbackWithObject; +import android.os.AsyncTask; import net.osmand.Location; import net.osmand.StateChangedListener; import net.osmand.access.AccessibilityPlugin; @@ -53,6 +53,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.media.AudioManager; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -67,7 +68,6 @@ import android.view.Window; import android.widget.FrameLayout; import android.widget.ProgressBar; import android.widget.Toast; -import org.apache.http.client.protocol.ClientContext; public class MapActivity extends AccessibleActivity { @@ -329,7 +329,7 @@ public class MapActivity extends AccessibleActivity { final Uri data = intent.getData(); if ("file".equalsIgnoreCase(data.getScheme())) { - navigateImportedGpx(data.getPath()); + showImportedGpx(data.getPath()); } } @@ -682,49 +682,41 @@ public class MapActivity extends AccessibleActivity { getMapView().refreshMap(); } - private void navigateImportedGpx(final String gpxFile) + private void showImportedGpx(final String gpxFile) { - final CallbackWithObject callback = new CallbackWithObject() + new AsyncTask() { - @Override - public boolean processResult(GPXFile result) - { - getMyApplication().setGpxFileToDisplay(result, true); - getMapActions().setGPXRouteParams(result); - getMyApplication().getTargetPointsHelper().updateRoutingHelper(); - getRoutingHelper().recalculateRouteDueToSettingsChange(); - return true; - } - }; + ProgressDialog progress = null; - final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading_data)); - new Thread(new Runnable() - { @Override - public void run() + protected void onPreExecute() { - final GPXFile res = GPXUtilities.loadGPXFile(getApplication(), new File(gpxFile)); - dlg.dismiss(); - if (res != null) + progress = ProgressDialog.show(MapActivity.this, getString(R.string.loading), getString(R.string.loading_data)); + } + + @Override + protected GPXFile doInBackground(Void... nothing) + { + return GPXUtilities.loadGPXFile(getMyApplication(), new File(gpxFile)); + } + + @Override + protected void onPostExecute(GPXFile result) + { + progress.dismiss(); + if (result != null) { - MapActivity.this.runOnUiThread(new Runnable() + if (result.warning != null) { - @Override - public void run() - { - if (res.warning != null) - { - AccessibleToast.makeText(MapActivity.this, res.warning, Toast.LENGTH_LONG).show(); - } - else - { - callback.processResult(res); - } - } - }); + AccessibleToast.makeText(MapActivity.this, result.warning, Toast.LENGTH_LONG).show(); + } + else + { + getMyApplication().setGpxFileToDisplay(result, true); + } + } } - - }, "Loading gpx").start(); //$NON-NLS-1$ + }.execute(); } } From 933c2baabc6e6f8ee41e642a47f2742915230366 Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Tue, 22 Apr 2014 22:46:36 +0200 Subject: [PATCH 4/7] - move map to first waypoint of imported track --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 82db0cf491..332ab73a53 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -23,6 +23,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.BusyIndicator; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -713,6 +714,12 @@ public class MapActivity extends AccessibleActivity { else { getMyApplication().setGpxFileToDisplay(result, true); + final WptPt moveTo = result.findPointToShow(); + if (moveTo != null) + { + mapView.getAnimatedDraggingThread().startMoving(moveTo.lat, moveTo.lon, mapView.getZoom(), true); + } + mapView.refreshMap(); } } From 04ba81b1a11506ce439ea9e2eefa06266641fe7b Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Tue, 22 Apr 2014 22:46:36 +0200 Subject: [PATCH 5/7] - import reordering --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 332ab73a53..cd2298c6f7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -7,7 +7,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import android.os.AsyncTask; import net.osmand.Location; import net.osmand.StateChangedListener; import net.osmand.access.AccessibilityPlugin; From 9644e4b80d595edbfb3cf9ffcf56b1321e2ca1ff Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Tue, 22 Apr 2014 22:46:36 +0200 Subject: [PATCH 6/7] - improvements : import from dropbox ; ES-FileExplorer local&cloud --- OsmAnd/AndroidManifest.xml | 7 ++++++- .../net/osmand/plus/activities/MapActivity.java | 14 ++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 3944759dbb..cfc9607921 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -68,10 +68,15 @@ + + - + + + + diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index cd2298c6f7..ec24d1644d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -324,12 +324,18 @@ public class MapActivity extends AccessibleActivity { } final Intent intent = getIntent(); - if (intent != null && intent.getData() != null) + if (intent != null) { - final Uri data = intent.getData(); - if ("file".equalsIgnoreCase(data.getScheme())) + if (Intent.ACTION_VIEW.equals(intent.getAction())) { - showImportedGpx(data.getPath()); + if (intent.getData() != null) + { + final Uri data = intent.getData(); + if ("file".equalsIgnoreCase(data.getScheme())) + { + showImportedGpx(data.getPath()); + } + } } } From c5f142553d1efead7827cfab9b83de78917c41e3 Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Thu, 24 Apr 2014 08:34:06 +0200 Subject: [PATCH 7/7] Need to override onNewIntent otherwise old intent is returned since activity is declared singleTop --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index ec24d1644d..64827dc891 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -242,7 +242,11 @@ public class MapActivity extends AccessibleActivity { return l; } - + @Override + protected void onNewIntent(final Intent intent) + { + setIntent(intent); + } @Override protected void onResume() {