Share track via intent
This commit is contained in:
parent
bdecc2e1b9
commit
669ea28d1b
5 changed files with 106 additions and 53 deletions
|
@ -63,6 +63,7 @@ public class RoutingEngine extends Thread
|
||||||
private Object[] extract;
|
private Object[] extract;
|
||||||
|
|
||||||
private boolean directWeaving = !Boolean.getBoolean( "disableDirectWeaving" );
|
private boolean directWeaving = !Boolean.getBoolean( "disableDirectWeaving" );
|
||||||
|
private String outfile;
|
||||||
|
|
||||||
public RoutingEngine( String outfileBase, String logfileBase, File segmentDir,
|
public RoutingEngine( String outfileBase, String logfileBase, File segmentDir,
|
||||||
List<OsmNodeNamed> waypoints, RoutingContext rc )
|
List<OsmNodeNamed> waypoints, RoutingContext rc )
|
||||||
|
@ -185,6 +186,7 @@ public class RoutingEngine extends Thread
|
||||||
track.writeGpx( filename );
|
track.writeGpx( filename );
|
||||||
foundTrack = track;
|
foundTrack = track;
|
||||||
alternativeIndex = i;
|
alternativeIndex = i;
|
||||||
|
outfile = filename;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1369,4 +1371,7 @@ public class RoutingEngine extends Thread
|
||||||
return terminated;
|
return terminated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getOutfile() {
|
||||||
|
return outfile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,5 +91,15 @@
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:process=":brouter_service" />
|
android:process=":brouter_service" />
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="btools.routing.fileprovider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/filepaths" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -272,31 +272,49 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
|
||||||
});
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_SHOWRESULT_ID:
|
case DIALOG_SHOWRESULT_ID:
|
||||||
String leftLabel = wpCount < 0 ? (wpCount != -2 ? "Exit" : "Help") : (wpCount == 0 ? "Select from" : "Select to/via");
|
// -3: Repeated route calculation
|
||||||
String rightLabel = wpCount < 2 ? (wpCount == -3 ? "Help" : "Server-Mode") : "Calc Route";
|
// -2: No waypoints?
|
||||||
|
// -1: Route calculated
|
||||||
|
// other: Select waypoints for route calculation
|
||||||
|
builder.setTitle(title).setMessage(errorMessage);
|
||||||
|
|
||||||
builder.setTitle(title).setMessage(errorMessage).setPositiveButton(leftLabel, new DialogInterface.OnClickListener() {
|
// Neutral button
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
if (wpCount == 0) {
|
||||||
if (wpCount == -2) {
|
builder.setNeutralButton("Server-Mode", (dialog, which) -> {
|
||||||
showWaypointDatabaseHelp();
|
|
||||||
} else if (wpCount == -1 || wpCount == -3) {
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
mBRouterView.pickWaypoints();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).setNegativeButton(rightLabel, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
if (wpCount == -3) {
|
|
||||||
showRepeatTimeoutHelp();
|
|
||||||
} else if (wpCount < 2) {
|
|
||||||
mBRouterView.startConfigureService();
|
mBRouterView.startConfigureService();
|
||||||
} else {
|
});
|
||||||
|
} else if (wpCount == -3) {
|
||||||
|
builder.setNeutralButton("Info", (dialog, which) -> {
|
||||||
|
showRepeatTimeoutHelp();
|
||||||
|
});
|
||||||
|
} else if (wpCount == -2) {
|
||||||
|
builder.setNeutralButton("Help", (dialog, which) -> {
|
||||||
|
showWaypointDatabaseHelp();
|
||||||
|
});
|
||||||
|
} else if (wpCount >= 2) {
|
||||||
|
builder.setNeutralButton("Calc Route", (dialog, which) -> {
|
||||||
mBRouterView.finishWaypointSelection();
|
mBRouterView.finishWaypointSelection();
|
||||||
mBRouterView.startProcessing(selectedProfile);
|
mBRouterView.startProcessing(selectedProfile);
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Positive button
|
||||||
|
if (wpCount == -3 || wpCount == -1) {
|
||||||
|
builder.setPositiveButton("Share GPX", (dialog, which) -> {
|
||||||
|
mBRouterView.shareTrack();
|
||||||
|
});
|
||||||
|
} else if (wpCount >= 0) {
|
||||||
|
String selectLabel = wpCount == 0 ? "Select from" : "Select to/via";
|
||||||
|
builder.setPositiveButton(selectLabel, (dialog, which) -> {
|
||||||
|
mBRouterView.pickWaypoints();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Negative button
|
||||||
|
builder.setNegativeButton("Exit", (dialog, which) -> {
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
case DIALOG_MODECONFIGOVERVIEW_ID:
|
case DIALOG_MODECONFIGOVERVIEW_ID:
|
||||||
builder.setTitle("Success").setMessage(message).setPositiveButton("Exit", new DialogInterface.OnClickListener() {
|
builder.setTitle("Success").setMessage(message).setPositiveButton("Exit", new DialogInterface.OnClickListener() {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package btools.routingapp;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
@ -13,6 +14,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
@ -68,6 +70,7 @@ public class BRouterView extends View {
|
||||||
private boolean waitingForMigration = false;
|
private boolean waitingForMigration = false;
|
||||||
private String rawTrackPath;
|
private String rawTrackPath;
|
||||||
private String oldMigrationPath;
|
private String oldMigrationPath;
|
||||||
|
private String trackOutfile;
|
||||||
private boolean needsViaSelection;
|
private boolean needsViaSelection;
|
||||||
private boolean needsNogoSelection;
|
private boolean needsNogoSelection;
|
||||||
private boolean needsWaypointSelection;
|
private boolean needsWaypointSelection;
|
||||||
|
@ -283,21 +286,19 @@ public class BRouterView extends View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveFile(String inputPath, String inputFile, String outputPath) {
|
private void copyFile(String inputPath, String inputFile, String outputPath) {
|
||||||
|
|
||||||
InputStream in;
|
InputStream in;
|
||||||
OutputStream out;
|
OutputStream out;
|
||||||
try {
|
|
||||||
|
|
||||||
|
try {
|
||||||
//create output directory if it doesn't exist
|
//create output directory if it doesn't exist
|
||||||
File dir = new File(outputPath);
|
File dir = new File(outputPath);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in = new FileInputStream(new File(inputPath, inputFile));
|
||||||
in = new FileInputStream(inputPath + "/" + inputFile);
|
out = new FileOutputStream(new File(outputPath, inputFile));
|
||||||
out = new FileOutputStream(outputPath + "/" + inputFile);
|
|
||||||
|
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int read;
|
int read;
|
||||||
|
@ -310,16 +311,17 @@ public class BRouterView extends View {
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
// delete the original file
|
} catch (FileNotFoundException fileNotFoundException) {
|
||||||
new File(inputPath + "/" + inputFile).delete();
|
Log.e("tag", fileNotFoundException.getMessage());
|
||||||
|
|
||||||
|
|
||||||
} catch (FileNotFoundException fnfe1) {
|
|
||||||
Log.e("tag", fnfe1.getMessage());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("tag", e.getMessage());
|
Log.e("tag", e.getMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveFile(String inputPath, String inputFile, String outputPath) {
|
||||||
|
copyFile(inputPath, inputFile, outputPath);
|
||||||
|
// delete the original file
|
||||||
|
new File(inputPath, inputFile).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasUpToDateLookups() {
|
public boolean hasUpToDateLookups() {
|
||||||
|
@ -707,6 +709,7 @@ public class BRouterView extends View {
|
||||||
title += " / " + cr.getAlternativeIndex() + ". Alternative";
|
title += " / " + cr.getAlternativeIndex() + ". Alternative";
|
||||||
|
|
||||||
((BRouterActivity) getContext()).showResultMessage(title, result, rawTrackPath == null ? -1 : -3);
|
((BRouterActivity) getContext()).showResultMessage(title, result, rawTrackPath == null ? -1 : -3);
|
||||||
|
trackOutfile = cr.getOutfile();
|
||||||
}
|
}
|
||||||
cr = null;
|
cr = null;
|
||||||
waitingForSelection = true;
|
waitingForSelection = true;
|
||||||
|
@ -848,4 +851,16 @@ public class BRouterView extends View {
|
||||||
((BRouterActivity) getContext()).showModeConfigOverview(msg.toString());
|
((BRouterActivity) getContext()).showModeConfigOverview(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shareTrack() {
|
||||||
|
File track = new File(trackOutfile);
|
||||||
|
// Copy file to cache to ensure FileProvider allows sharing the file
|
||||||
|
File cacheDir = getContext().getCacheDir();
|
||||||
|
copyFile(track.getParent(), track.getName(), cacheDir.getAbsolutePath());
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setDataAndType(FileProvider.getUriForFile(getContext(), "btools.routing.fileprovider", new File(cacheDir, track.getName())),
|
||||||
|
"application/gpx+xml");
|
||||||
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
getContext().startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
5
brouter-routing-app/src/main/res/xml/filepaths.xml
Normal file
5
brouter-routing-app/src/main/res/xml/filepaths.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<paths>
|
||||||
|
<cache-path
|
||||||
|
name="cache"
|
||||||
|
path="." />
|
||||||
|
</paths>
|
Loading…
Reference in a new issue