Merge pull request #6616 from osmandapp/open_GPX

Open gpx
This commit is contained in:
Alexey 2019-03-05 16:43:40 +03:00 committed by GitHub
commit f3666e6b80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View file

@ -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 = 2000000;
private static final Log LOG = PlatformUtil.getLog(GpxUiHelper.class);
public static String getDescription(OsmandApplication app, GPXFile result, File f, boolean html) {
@ -1639,6 +1640,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];

View file

@ -38,6 +38,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;
@ -58,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;
@ -558,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);
@ -665,12 +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);
if(Algorithms.isEmpty(warning)) {
showGpxInDetailsActivity(result);
} else {
Toast.makeText(activity, warning, Toast.LENGTH_LONG).show();
}
}
}
private MapActivity getMapActivity() {
@ -681,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);