diff --git a/OsmAnd/res/layout/fragment_on_save_current_track.xml b/OsmAnd/res/layout/fragment_on_save_current_track.xml
new file mode 100644
index 0000000000..c4dc6ffd06
--- /dev/null
+++ b/OsmAnd/res/layout/fragment_on_save_current_track.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index afa42491fe..d138a38e96 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -11,6 +11,7 @@
Thx - Hardy
-->
+ saved
Wake on turn
Set the time for which the screen will turn on.
Use proximity sensor
diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java
index c8d4a562e5..11340e18a3 100644
--- a/OsmAnd/src/net/osmand/plus/AppInitializer.java
+++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java
@@ -743,7 +743,7 @@ public class AppInitializer implements IProgress {
if (System.currentTimeMillis() - timeUpdated >= 1000 * 60 * 30) {
startTask(app.getString(R.string.saving_gpx_tracks), -1);
try {
- warnings.addAll(app.savingTrackHelper.saveDataToGpx(app.getAppCustomization().getTracksDir()));
+ warnings.addAll(app.savingTrackHelper.saveDataToGpx(app.getAppCustomization().getTracksDir()).getWarnings());
} catch (RuntimeException e) {
warnings.add(e.getMessage());
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java
index 5d29aa5b1f..bda45dd53a 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java
@@ -188,10 +188,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
/**
- * @return warnings
+ * @return warnings, filenames
*/
- public synchronized List saveDataToGpx(File dir ) {
- List warnings = new ArrayList();
+ public synchronized SaveGpxResult saveDataToGpx(File dir) {
+ List warnings = new ArrayList<>();
+ List filenames = new ArrayList<>();
dir.mkdirs();
if (dir.getParentFile().canWrite()) {
if (dir.exists()) {
@@ -199,6 +200,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
// save file
for (final String f : data.keySet()) {
+ log.debug("Filename: " + f);
File fout = new File(dir, f + ".gpx"); //$NON-NLS-1$
if (!data.get(f).isEmpty()) {
WptPt pt = data.get(f).findPointToShow();
@@ -214,6 +216,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$
+ filenames.add(fileName);
fout = new File(targetDir, fileName + ".gpx"); //$NON-NLS-1$
int ind = 1;
while (fout.exists()) {
@@ -224,7 +227,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
Exception warn = GPXUtilities.writeGpxFile(fout, data.get(f));
if (warn != null) {
warnings.add(warn.getMessage());
- return warnings;
+ return new SaveGpxResult(warnings, new ArrayList());
}
GPXFile gpx = data.get(f);
@@ -257,7 +260,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
currentTrack.getModifiablePointsToDisplay().clear();
currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
prepareCurrentTrackForRecording();
- return warnings;
+ return new SaveGpxResult(warnings, filenames);
}
public Map collectRecordedData() {
@@ -685,5 +688,24 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public SelectedGpxFile getCurrentTrack() {
return currentTrack;
}
+
+ public class SaveGpxResult {
+
+ public SaveGpxResult(List warnings, List filenames) {
+ this.warnings = warnings;
+ this.filenames = filenames;
+ }
+
+ List warnings;
+ List filenames;
+
+ public List getWarnings() {
+ return warnings;
+ }
+
+ public List getFilenames() {
+ return filenames;
+ }
+ }
}
diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java
new file mode 100644
index 0000000000..6e9466fd61
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java
@@ -0,0 +1,88 @@
+package net.osmand.plus.monitoring;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.FragmentManager;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
+import android.text.style.StyleSpan;
+import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+import java.io.File;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
+import net.osmand.plus.base.BottomSheetDialogFragment;
+import net.osmand.plus.myplaces.AvailableGPXFragment;
+
+public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment {
+
+ public static final String TAG = "OnSaveCurrentTrackBottomSheetFragment";
+ public static final String SAVED_TRACK_KEY = "saved_track_filename";
+
+
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ final OsmandApplication app = getMyApplication();
+ Bundle args = getArguments();
+ String savedGpxName = "";
+ if (args != null && args.containsKey(SAVED_TRACK_KEY)) {
+ savedGpxName = args.getString(SAVED_TRACK_KEY, "");
+ } else {
+ dismiss();
+ }
+
+ final File f = new File (app.getAppCustomization().getTracksDir() +"/"+ savedGpxName + ".gpx");
+ final boolean nightMode = !app.getSettings().isLightContent();
+ final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
+ View mainView = View
+ .inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_on_save_current_track, container);
+ TextView tv = mainView.findViewById(R.id.saved_track_name_string);
+ Button openTrackBtn = mainView.findViewById(R.id.open_track_button);
+ Button showOnMapBtn = mainView.findViewById(R.id.show_on_map_button);
+
+ SpannableStringBuilder ssb = new SpannableStringBuilder();
+ ssb.append(app.getResources().getString(R.string.shared_string_gpx_track)).append(" ");
+ int startIndex = ssb.length();
+ ssb.append(savedGpxName).append(" ");
+ ssb.setSpan(new StyleSpan(Typeface.BOLD), startIndex, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ startIndex = ssb.length();
+ ssb.append(app.getResources().getString(R.string.shared_string_saved));
+ ssb.setSpan(new StyleSpan(Typeface.NORMAL), startIndex, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ tv.setText(ssb);
+
+ openTrackBtn.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ AvailableGPXFragment.openTrack(getActivity(), f);
+ dismiss();
+ }
+ });
+
+ showOnMapBtn.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ //show track on MapActivity
+ dismiss();
+ }
+ });
+ return mainView;
+ }
+
+ public static void showInstance(FragmentManager fragmentManager, String filename) {
+ OnSaveCurrentTrackFragment f = new OnSaveCurrentTrackFragment();
+ Bundle b = new Bundle();
+ b.putString(SAVED_TRACK_KEY, filename);
+ f.setArguments(b);
+ f.show(fragmentManager, TAG);
+ }
+
+}
diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java
index eb60ba548f..6bdaac8cce 100644
--- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java
@@ -31,6 +31,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
+import net.osmand.plus.activities.SavingTrackHelper.SaveGpxResult;
import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@@ -40,6 +41,7 @@ import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import java.util.List;
import gnu.trove.list.array.TIntArrayList;
+import net.osmand.util.Algorithms;
public class OsmandMonitoringPlugin extends OsmandPlugin {
public static final String ID = "osmand.monitoring";
@@ -288,7 +290,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
int which = holder[0];
int item = items.get(which);
if(item == R.string.save_current_track){
- saveCurrentTrack();
+ saveCurrentTrack(map);
} else if(item == R.string.gpx_monitoring_start) {
if (app.getLocationProvider().checkGPSEnabled(map)) {
startGPXMonitoring(map, showTrackSelection);
@@ -330,11 +332,20 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
public void saveCurrentTrack() {
- saveCurrentTrack(null);
+ saveCurrentTrack(null, null);
+ }
+
+ public void saveCurrentTrack(@Nullable final Runnable onComplete) {
+ saveCurrentTrack(onComplete, null);
}
- public void saveCurrentTrack(@Nullable final Runnable onComplete) {
- app.getTaskManager().runInBackground(new OsmAndTaskRunnable() {
+ public void saveCurrentTrack(@Nullable final Activity activity) {
+ saveCurrentTrack(null, activity);
+ }
+
+ public void saveCurrentTrack(@Nullable final Runnable onComplete, @Nullable final
+ Activity activity) {
+ app.getTaskManager().runInBackground(new OsmAndTaskRunnable() {
@Override
protected void onPreExecute() {
@@ -343,11 +354,12 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
@Override
- protected Void doInBackground(Void... params) {
+ protected SaveGpxResult doInBackground(Void... params) {
try {
SavingTrackHelper helper = app.getSavingTrackHelper();
- helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
+ SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
helper.close();
+ return result;
} catch (Exception e) {
e.printStackTrace();
}
@@ -355,10 +367,14 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
@Override
- protected void onPostExecute(Void aVoid) {
+ protected void onPostExecute(SaveGpxResult result) {
isSaving = false;
app.getNotificationHelper().refreshNotifications();
updateControl();
+ if (activity instanceof MapActivity && !Algorithms.isEmpty(result.getFilenames())) {
+ OnSaveCurrentTrackFragment.showInstance(((MapActivity) activity)
+ .getSupportFragmentManager(), result.getFilenames().get(0));
+ }
if (onComplete != null) {
onComplete.run();
}