From 3e973f1638310e8f24d558ecaf706244063e0afe Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 4 Mar 2019 12:30:28 +0200 Subject: [PATCH 1/8] Open imported GPX files in TrackActivity --- .../net/osmand/plus/helpers/ImportHelper.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 88b20d870c..44d7b0d182 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -20,9 +20,11 @@ import android.support.v7.app.AppCompatActivity; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; +import android.view.MenuItem; import android.view.View; import android.widget.Toast; +import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.WptPt; import net.osmand.IProgress; import net.osmand.IndexConstants; @@ -38,6 +40,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; @@ -666,9 +669,10 @@ public class ImportHelper { @Override protected void onPostExecute(final String warning) { final String msg = warning == null ? MessageFormat.format(app.getString(R.string.gpx_saved_sucessfully), result.path) : warning; - Toast.makeText(activity, msg, Toast.LENGTH_LONG).show(); + //Toast.makeText(activity, msg, Toast.LENGTH_LONG).show(); - showGpxOnMap(result); + //showGpxOnMap(result); + showGpxDetailsActivity(result); } } @@ -695,6 +699,15 @@ public class ImportHelper { } } + private void showGpxDetailsActivity(final GPXFile gpxFile) { + if (gpxFile.path != null) { + Intent newIntent = new Intent(activity, app.getAppCustomization().getTrackActivity()); + newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxFile.path); + newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + activity.startActivity(newIntent); + } + } + private void importFavourites(final GPXFile gpxFile, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) { if (gpxFile == null || gpxFile.isPointsEmpty()) { From 62848ac1d68829a3907f89df06951d06d1c48ec4 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 4 Mar 2019 14:58:46 +0200 Subject: [PATCH 2/8] Fix crash from calculating GPX Slope dataset for large tracks (>2000km) --- OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 357515c33e..743ee85cfc 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -125,6 +125,7 @@ import static net.osmand.plus.download.DownloadActivity.formatMb; public class GpxUiHelper { private static final int OPEN_GPX_DOCUMENT_REQUEST = 1005; + private static final int DEFAULT_DISTANCE_FOR_SLOPE_DATA = 2_000_000; private static final Log LOG = PlatformUtil.getLog(GpxUiHelper.class); public static String getDescription(OsmandApplication app, GPXFile result, File f, boolean html) { @@ -1635,6 +1636,9 @@ public class GpxUiHelper { int lastIndex = values.size() - 1; double STEP = 5; + if (totalDistance > DEFAULT_DISTANCE_FOR_SLOPE_DATA) { + STEP = STEP * (totalDistance / DEFAULT_DISTANCE_FOR_SLOPE_DATA); + } double[] calculatedDist = new double[(int) (totalDistance / STEP) + 1]; double[] calculatedH = new double[(int) (totalDistance / STEP) + 1]; From 63f933a9a3913575b8221b0c0178cd398857106e Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Tue, 5 Mar 2019 10:56:40 +0200 Subject: [PATCH 3/8] Add check for import error --- .../net/osmand/plus/helpers/ImportHelper.java | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 44d7b0d182..d0ed52a6c4 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -20,11 +20,9 @@ import android.support.v7.app.AppCompatActivity; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; -import android.view.MenuItem; import android.view.View; import android.widget.Toast; -import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.WptPt; import net.osmand.IProgress; import net.osmand.IndexConstants; @@ -40,7 +38,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; @@ -668,13 +665,12 @@ public class ImportHelper { @Override protected void onPostExecute(final String warning) { - final String msg = warning == null ? MessageFormat.format(app.getString(R.string.gpx_saved_sucessfully), result.path) : warning; - //Toast.makeText(activity, msg, Toast.LENGTH_LONG).show(); - - //showGpxOnMap(result); - showGpxDetailsActivity(result); + if(Algorithms.isEmpty(warning)) { + showGpxOnMap(result); + } else { + Toast.makeText(activity, warning, Toast.LENGTH_LONG).show(); + } } - } private MapActivity getMapActivity() { @@ -699,15 +695,6 @@ public class ImportHelper { } } - private void showGpxDetailsActivity(final GPXFile gpxFile) { - if (gpxFile.path != null) { - Intent newIntent = new Intent(activity, app.getAppCustomization().getTrackActivity()); - newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxFile.path); - newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - activity.startActivity(newIntent); - } - } - private void importFavourites(final GPXFile gpxFile, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) { if (gpxFile == null || gpxFile.isPointsEmpty()) { From d299c0d93d3d3517c23fe6aba25239b8d355a445 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Tue, 5 Mar 2019 10:56:40 +0200 Subject: [PATCH 4/8] Add check for import error --- .../net/osmand/plus/helpers/ImportHelper.java | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 44d7b0d182..590de74cb1 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -20,11 +20,9 @@ import android.support.v7.app.AppCompatActivity; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; -import android.view.MenuItem; import android.view.View; import android.widget.Toast; -import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.WptPt; import net.osmand.IProgress; import net.osmand.IndexConstants; @@ -61,7 +59,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; -import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -561,7 +558,7 @@ public class ImportHelper { if (save) { new SaveAsyncTask(result, name, useImportDir).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { - showGpxOnMap(result); + showGpxInDetailsActivity(result); } if (gpxImportCompleteListener != null) { gpxImportCompleteListener.onComplete(true); @@ -668,13 +665,12 @@ public class ImportHelper { @Override protected void onPostExecute(final String warning) { - final String msg = warning == null ? MessageFormat.format(app.getString(R.string.gpx_saved_sucessfully), result.path) : warning; - //Toast.makeText(activity, msg, Toast.LENGTH_LONG).show(); - - //showGpxOnMap(result); - showGpxDetailsActivity(result); + if(Algorithms.isEmpty(warning)) { + showGpxInDetailsActivity(result); + } else { + Toast.makeText(activity, warning, Toast.LENGTH_LONG).show(); + } } - } private MapActivity getMapActivity() { @@ -685,6 +681,15 @@ public class ImportHelper { } } + private void showGpxInDetailsActivity(final GPXFile gpxFile) { + if (gpxFile.path != null) { + Intent newIntent = new Intent(activity, app.getAppCustomization().getTrackActivity()); + newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxFile.path); + newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + activity.startActivity(newIntent); + } + } + private void showGpxOnMap(final GPXFile result) { if (mapView != null && getMapActivity() != null) { app.getSelectedGpxHelper().setGpxFileToDisplay(result); @@ -699,15 +704,6 @@ public class ImportHelper { } } - private void showGpxDetailsActivity(final GPXFile gpxFile) { - if (gpxFile.path != null) { - Intent newIntent = new Intent(activity, app.getAppCustomization().getTrackActivity()); - newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxFile.path); - newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - activity.startActivity(newIntent); - } - } - private void importFavourites(final GPXFile gpxFile, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) { if (gpxFile == null || gpxFile.isPointsEmpty()) { From 763a139ea9f8afea632be50222b51ac487ea03a0 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Tue, 5 Mar 2019 12:14:05 +0200 Subject: [PATCH 5/8] Remove final so that intent could be cleared --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 6d9da435c9..6b1201b977 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -727,7 +727,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven OsmandPlugin.onMapActivityResume(this); - final Intent intent = getIntent(); + Intent intent = getIntent(); if (intent != null) { if (Intent.ACTION_VIEW.equals(intent.getAction())) { if (intent.getData() != null) { From 2197daa7272b43c8c7c1d1d5f76ef61ec1d1a292 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Tue, 5 Mar 2019 13:18:09 +0200 Subject: [PATCH 6/8] Change int syntax of DEFAULT_DISTANCE_FOR_SLOPE_DATA const --- OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 743ee85cfc..a3e667dafb 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -125,7 +125,7 @@ import static net.osmand.plus.download.DownloadActivity.formatMb; public class GpxUiHelper { private static final int OPEN_GPX_DOCUMENT_REQUEST = 1005; - private static final int DEFAULT_DISTANCE_FOR_SLOPE_DATA = 2_000_000; + private static final int DEFAULT_DISTANCE_FOR_SLOPE_DATA = 2000000; private static final Log LOG = PlatformUtil.getLog(GpxUiHelper.class); public static String getDescription(OsmandApplication app, GPXFile result, File f, boolean html) { From aaec7c1e331cf0fd701fbb09500e75df5abf290d Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Tue, 5 Mar 2019 13:56:23 +0200 Subject: [PATCH 7/8] clear intent's action after executing gpx import --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 6b1201b977..2af2617440 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -727,9 +727,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven OsmandPlugin.onMapActivityResume(this); - Intent intent = getIntent(); + final Intent intent = getIntent(); if (intent != null) { if (Intent.ACTION_VIEW.equals(intent.getAction())) { + getIntent().setAction(""); if (intent.getData() != null) { final Uri data = intent.getData(); final String scheme = data.getScheme(); From 8aa51a0cc4e0968f2b82997b9cb632d92097a3a9 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Tue, 5 Mar 2019 15:32:34 +0200 Subject: [PATCH 8/8] clear intent's action after executing gpx import - reverted --- 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 2af2617440..6d9da435c9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -730,7 +730,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven final Intent intent = getIntent(); if (intent != null) { if (Intent.ACTION_VIEW.equals(intent.getAction())) { - getIntent().setAction(""); if (intent.getData() != null) { final Uri data = intent.getData(); final String scheme = data.getScheme();