diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 85c60ca52e..a388365c80 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -10,11 +10,15 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy
-->
+ Show/Hide GPX Tracks
+ Tapping this action button shows or hides selected GPX tracks on map
+ Hide GPX Tracks
+ Show GPX Tracks
Please add Destination first
Previous route
- Add home
- Add work
- Work
+ Add home
+ Add work
+ Work
m³
t
Сapacity
diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
index 5563363b54..138927bf07 100644
--- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
+++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
@@ -59,6 +59,7 @@ public class GpxSelectionHelper {
public void restoreSelectedGpxFiles() {
if (!selectedGpxFilesBackUp.isEmpty()) {
+ selectedGPXFiles.clear();
selectedGPXFiles.addAll(selectedGpxFilesBackUp);
}
}
@@ -71,7 +72,6 @@ public class GpxSelectionHelper {
return !selectedGPXFiles.isEmpty();
}
-
@NonNull
public List getSelectedGPXFiles() {
return selectedGPXFiles;
diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java
index 2644a92b74..021d39dd05 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java
@@ -930,6 +930,12 @@ public class GpxUiHelper {
}
}
+ public static void loadFileInDifferentThread(final Activity activity,
+ final CallbackWithObject callbackWithObject, final File dir,
+ final String... filename) {
+ loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, filename);
+ }
+
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject callbackWithObject,
final File dir, final GPXFile currentFile, final String... filename) {
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""),
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java
index 8620092f04..10b1bf1fc4 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java
@@ -33,6 +33,7 @@ import net.osmand.plus.quickaction.actions.NavStartStopAction;
import net.osmand.plus.quickaction.actions.NavVoiceAction;
import net.osmand.plus.quickaction.actions.NewAction;
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
+import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
import net.osmand.plus.quickaction.actions.DayNightModeAction;
@@ -102,6 +103,9 @@ public class QuickActionFactory {
if (!favorites.hasInstanceInList(active)) {
quickActions.add(favorites);
}
+
+ quickActions.add(new ShowHideGpxTracksAction());
+
quickActions.add(new ShowHidePoiAction());
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
QuickAction showHideOSMBugAction = new ShowHideOSMBugAction();
@@ -239,6 +243,9 @@ public class QuickActionFactory {
case DayNightModeAction.TYPE:
return new DayNightModeAction();
+ case ShowHideGpxTracksAction.TYPE:
+ return new ShowHideGpxTracksAction();
+
default:
return new QuickAction();
}
@@ -323,6 +330,9 @@ public class QuickActionFactory {
case DayNightModeAction.TYPE:
return new DayNightModeAction(quickAction);
+ case ShowHideGpxTracksAction.TYPE:
+ return new ShowHideGpxTracksAction(quickAction);
+
default:
return quickAction;
}
@@ -407,6 +417,9 @@ public class QuickActionFactory {
case DayNightModeAction.TYPE:
return R.drawable.ic_action_map_day;
+ case ShowHideGpxTracksAction.TYPE:
+ return R.drawable.ic_gpx_track;
+
default:
return R.drawable.ic_action_plus;
}
@@ -491,6 +504,9 @@ public class QuickActionFactory {
case NavResumePauseAction.TYPE:
return R.string.quick_action_resume_pause_navigation;
+ case ShowHideGpxTracksAction.TYPE:
+ return R.string.quick_action_show_hide_gpx_tracks;
+
default:
return R.string.quick_action_new_action;
}
@@ -517,6 +533,7 @@ public class QuickActionFactory {
case NavStartStopAction.TYPE:
case NavResumePauseAction.TYPE:
case DayNightModeAction.TYPE:
+ case ShowHideGpxTracksAction.TYPE:
return false;
default:
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGPXTracksAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGPXTracksAction.java
deleted file mode 100644
index f3415177a4..0000000000
--- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGPXTracksAction.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package net.osmand.plus.quickaction.actions;
-
-import net.osmand.plus.quickaction.QuickAction;
-
-public class ShowHideGPXTracksAction extends QuickAction {
-
-}
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGpxTracksAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGpxTracksAction.java
new file mode 100644
index 0000000000..5b73fd2b5a
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGpxTracksAction.java
@@ -0,0 +1,98 @@
+package net.osmand.plus.quickaction.actions;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import net.osmand.CallbackWithObject;
+import net.osmand.GPXUtilities.GPXFile;
+import net.osmand.IndexConstants;
+import net.osmand.plus.GpxSelectionHelper;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.OsmandSettings;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.helpers.GpxUiHelper;
+import net.osmand.plus.quickaction.QuickAction;
+
+public class ShowHideGpxTracksAction extends QuickAction {
+
+ public static final int TYPE = 28;
+
+ public ShowHideGpxTracksAction() {
+ super(TYPE);
+ }
+
+ public ShowHideGpxTracksAction(QuickAction quickAction) {
+ super(quickAction);
+ }
+
+ @Override
+ public void execute(final MapActivity activity) {
+ final GpxSelectionHelper selectedGpxHelper = activity.getMyApplication()
+ .getSelectedGpxHelper();
+ if (selectedGpxHelper.isShowingAnyGpxFiles()) {
+ selectedGpxHelper.clearAllGpxFileToShow();
+ } else {
+ selectedGpxHelper.restoreSelectedGpxFiles();
+
+ final OsmandSettings setting = activity.getMyApplication().getSettings();
+ final File dir = activity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
+ CallbackWithObject callbackWithObject = new CallbackWithObject() {
+ @Override
+ public boolean processResult(GPXFile[] result) {
+ for (GPXFile g : result) {
+ if (g.showCurrentTrack) {
+ if (!setting.SAVE_TRACK_TO_GPX.get()
+ && !setting.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
+ Toast.makeText(activity,
+ R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_LONG)
+ .show();
+ }
+ break;
+ }
+ }
+ return true;
+ }
+ };
+ selectedGpxHelper.restoreSelectedGpxFiles();
+ List selectedGpxFiles = selectedGpxHelper
+ .getSelectedGPXFiles();
+ List files = new ArrayList<>();
+ for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) {
+ files.add(file.getGpxFile().path);
+ }
+
+ GpxUiHelper.loadFileInDifferentThread(activity, callbackWithObject, dir,
+ files.toArray(new String[files.size()]));
+ }
+ }
+
+ @Override
+ public void drawUI(ViewGroup parent, MapActivity activity) {
+
+ View view = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.quick_action_with_text, parent, false);
+
+ ((TextView) view.findViewById(R.id.text))
+ .setText(R.string.quick_action_show_hide_gpx_tracks_descr);
+
+ parent.addView(view);
+ }
+
+ @Override
+ public String getActionText(OsmandApplication application) {
+ return application.getSelectedGpxHelper().isShowingAnyGpxFiles()
+ ? application.getString(R.string.quick_action_gpx_tracks_hide)
+ : application.getString(R.string.quick_action_gpx_tracks_show);
+ }
+
+ @Override
+ public boolean isActionWithSlash(OsmandApplication application) {
+ return application.getSelectedGpxHelper().isShowingAnyGpxFiles();
+ }
+}