commit
6f45678ce3
7 changed files with 190 additions and 4 deletions
|
@ -1592,6 +1592,8 @@ public class GPXUtilities {
|
||||||
fis = new FileInputStream(f);
|
fis = new FileInputStream(f);
|
||||||
GPXFile file = loadGPXFile(fis);
|
GPXFile file = loadGPXFile(fis);
|
||||||
file.path = f.getAbsolutePath();
|
file.path = f.getAbsolutePath();
|
||||||
|
file.modifiedTime = f.lastModified();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fis.close();
|
fis.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
<string name="shared_string_swap">Swap</string>
|
<string name="shared_string_swap">Swap</string>
|
||||||
<string name="show_more">Show more</string>
|
<string name="show_more">Show more</string>
|
||||||
<string name="tracks_on_map">Tracks on the map</string>
|
<string name="tracks_on_map">Tracks on the map</string>
|
||||||
|
<string name="quick_action_show_hide_gpx_tracks">Show/Hide GPX Tracks</string>
|
||||||
|
<string name="quick_action_show_hide_gpx_tracks_descr">Tapping this action button shows or hides selected GPX tracks on map</string>
|
||||||
|
<string name="quick_action_gpx_tracks_hide">Hide GPX Tracks</string>
|
||||||
|
<string name="quick_action_gpx_tracks_show">Show GPX Tracks</string>
|
||||||
|
<string name="add_destination_query">Please add Destination first</string>
|
||||||
<string name="previous_route">Previous route</string>
|
<string name="previous_route">Previous route</string>
|
||||||
<string name="add_home">Add home</string>
|
<string name="add_home">Add home</string>
|
||||||
<string name="add_work">Add work</string>
|
<string name="add_work">Add work</string>
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package net.osmand.plus;
|
package net.osmand.plus;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
|
@ -24,6 +29,7 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -37,12 +43,17 @@ public class GpxSelectionHelper {
|
||||||
|
|
||||||
private static final String CURRENT_TRACK = "currentTrack";
|
private static final String CURRENT_TRACK = "currentTrack";
|
||||||
private static final String FILE = "file";
|
private static final String FILE = "file";
|
||||||
|
private static final String BACKUP = "backup";
|
||||||
|
private static final String BACKUPMODIFIEDTIME = "backupTime";
|
||||||
private static final String COLOR = "color";
|
private static final String COLOR = "color";
|
||||||
private static final String SELECTED_BY_USER = "selected_by_user";
|
private static final String SELECTED_BY_USER = "selected_by_user";
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
@NonNull
|
@NonNull
|
||||||
private List<SelectedGpxFile> selectedGPXFiles = new java.util.ArrayList<>();
|
private List<SelectedGpxFile> selectedGPXFiles = new java.util.ArrayList<>();
|
||||||
|
private Map<GPXFile, Long> selectedGpxFilesBackUp = new java.util.HashMap<>();
|
||||||
private SavingTrackHelper savingTrackHelper;
|
private SavingTrackHelper savingTrackHelper;
|
||||||
|
private final static Log LOG = PlatformUtil.getLog(GpxSelectionHelper.class);
|
||||||
|
|
||||||
|
|
||||||
public GpxSelectionHelper(OsmandApplication osmandApplication, SavingTrackHelper trackHelper) {
|
public GpxSelectionHelper(OsmandApplication osmandApplication, SavingTrackHelper trackHelper) {
|
||||||
this.app = osmandApplication;
|
this.app = osmandApplication;
|
||||||
|
@ -50,10 +61,53 @@ public class GpxSelectionHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearAllGpxFileToShow() {
|
public void clearAllGpxFileToShow() {
|
||||||
|
selectedGpxFilesBackUp.clear();
|
||||||
|
for(SelectedGpxFile s : selectedGPXFiles) {
|
||||||
|
selectedGpxFilesBackUp.put(s.gpxFile, s.modifiedTime);
|
||||||
|
}
|
||||||
selectedGPXFiles.clear();
|
selectedGPXFiles.clear();
|
||||||
saveCurrentSelections();
|
saveCurrentSelections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void restoreSelectedGpxFiles() {
|
||||||
|
for (Entry<GPXFile, Long> gpxEntry : selectedGpxFilesBackUp.entrySet()) {
|
||||||
|
if (!Algorithms.isEmpty(gpxEntry.getKey().path)) {
|
||||||
|
final File file = new File(gpxEntry.getKey().path);
|
||||||
|
if (file.exists() && !file.isDirectory()) {
|
||||||
|
if (file.lastModified() > gpxEntry.getValue()) {
|
||||||
|
new GpxFileLoaderTask(file, app).execute();
|
||||||
|
} else {
|
||||||
|
selectGpxFile(gpxEntry.getKey(), true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveCurrentSelections();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GpxFileLoaderTask extends AsyncTask<Void, Void, GPXFile> {
|
||||||
|
|
||||||
|
File fileToLoad;
|
||||||
|
GpxSelectionHelper helper;
|
||||||
|
|
||||||
|
GpxFileLoaderTask(File fileToLoad, OsmandApplication app) {
|
||||||
|
this.fileToLoad = fileToLoad;
|
||||||
|
this.helper = app.getSelectedGpxHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GPXFile doInBackground(Void... voids) {
|
||||||
|
return GPXUtilities.loadGPXFile(fileToLoad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(GPXFile gpxFile) {
|
||||||
|
if (gpxFile != null) {
|
||||||
|
helper.selectGpxFile(gpxFile, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isShowingAnyGpxFiles() {
|
public boolean isShowingAnyGpxFiles() {
|
||||||
return !selectedGPXFiles.isEmpty();
|
return !selectedGPXFiles.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +117,12 @@ public class GpxSelectionHelper {
|
||||||
return selectedGPXFiles;
|
return selectedGPXFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<GPXFile, Long> getSelectedGpxFilesBackUp() {
|
||||||
|
return selectedGpxFilesBackUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressLint({"StringFormatInvalid", "StringFormatMatches"})
|
||||||
public String getGpxDescription() {
|
public String getGpxDescription() {
|
||||||
if (selectedGPXFiles.size() == 1) {
|
if (selectedGPXFiles.size() == 1) {
|
||||||
GPXFile currentGPX = app.getSavingTrackHelper().getCurrentGpx();
|
GPXFile currentGPX = app.getSavingTrackHelper().getCurrentGpx();
|
||||||
|
@ -439,6 +499,8 @@ public class GpxSelectionHelper {
|
||||||
}
|
}
|
||||||
if (gpx.error != null) {
|
if (gpx.error != null) {
|
||||||
save = true;
|
save = true;
|
||||||
|
} else if(obj.has(BACKUP)) {
|
||||||
|
selectedGpxFilesBackUp.put(gpx, gpx.modifiedTime);
|
||||||
} else {
|
} else {
|
||||||
selectGpxFile(gpx, true, false, true, selectedByUser, false);
|
selectGpxFile(gpx, true, false, true, selectedByUser, false);
|
||||||
}
|
}
|
||||||
|
@ -480,6 +542,25 @@ public class GpxSelectionHelper {
|
||||||
ar.put(obj);
|
ar.put(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (Map.Entry<GPXFile, Long> s : selectedGpxFilesBackUp.entrySet()) {
|
||||||
|
if (s != null) {
|
||||||
|
try {
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
if(Algorithms.isEmpty(s.getKey().path)) {
|
||||||
|
obj.put(CURRENT_TRACK, true);
|
||||||
|
} else {
|
||||||
|
obj.put(FILE, s.getKey().path);
|
||||||
|
}
|
||||||
|
obj.put(SELECTED_BY_USER, true);
|
||||||
|
obj.put(BACKUP, true);
|
||||||
|
obj.put(BACKUPMODIFIEDTIME, s.getValue());
|
||||||
|
ar.put(obj);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
app.getSettings().SELECTED_GPX.set(ar.toString());
|
app.getSettings().SELECTED_GPX.set(ar.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,9 @@ import android.widget.ListView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.core.android.MapRendererContext;
|
import net.osmand.core.android.MapRendererContext;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
|
@ -154,10 +156,20 @@ public class ConfigureMapMenu {
|
||||||
private List<String> getAlreadySelectedGpx() {
|
private List<String> getAlreadySelectedGpx() {
|
||||||
GpxSelectionHelper selectedGpxHelper = ma.getMyApplication().getSelectedGpxHelper();
|
GpxSelectionHelper selectedGpxHelper = ma.getMyApplication().getSelectedGpxHelper();
|
||||||
List<GpxSelectionHelper.SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
|
List<GpxSelectionHelper.SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
|
||||||
|
|
||||||
List<String> files = new ArrayList<>();
|
List<String> files = new ArrayList<>();
|
||||||
for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) {
|
for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) {
|
||||||
files.add(file.getGpxFile().path);
|
files.add(file.getGpxFile().path);
|
||||||
}
|
}
|
||||||
|
Map<GPXUtilities.GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
|
||||||
|
for(Map.Entry<GPXUtilities.GPXFile, Long> f : fls.entrySet()) {
|
||||||
|
if(!Algorithms.isEmpty(f.getKey().path)) {
|
||||||
|
File file = new File(f.getKey().path);
|
||||||
|
if(file.exists() && !file.isDirectory()) {
|
||||||
|
files.add(f.getKey().path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +248,7 @@ public class ConfigureMapMenu {
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
OsmandApplication app = ma.getMyApplication();
|
OsmandApplication app = ma.getMyApplication();
|
||||||
boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
|
boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
|
||||||
item.setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles());
|
item.setSelected(selected);
|
||||||
item.setDescription(app.getSelectedGpxHelper().getGpxDescription());
|
item.setDescription(app.getSelectedGpxHelper().getGpxDescription());
|
||||||
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
|
|
|
@ -942,6 +942,7 @@ public class GpxUiHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
|
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
|
||||||
final File dir, final GPXFile currentFile, final String... filename) {
|
final File dir, final GPXFile currentFile, final String... filename) {
|
||||||
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""),
|
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""),
|
||||||
|
|
|
@ -33,6 +33,7 @@ import net.osmand.plus.quickaction.actions.NavStartStopAction;
|
||||||
import net.osmand.plus.quickaction.actions.NavVoiceAction;
|
import net.osmand.plus.quickaction.actions.NavVoiceAction;
|
||||||
import net.osmand.plus.quickaction.actions.NewAction;
|
import net.osmand.plus.quickaction.actions.NewAction;
|
||||||
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
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.ShowHideOSMBugAction;
|
||||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||||
import net.osmand.plus.quickaction.actions.DayNightModeAction;
|
import net.osmand.plus.quickaction.actions.DayNightModeAction;
|
||||||
|
@ -102,6 +103,9 @@ public class QuickActionFactory {
|
||||||
if (!favorites.hasInstanceInList(active)) {
|
if (!favorites.hasInstanceInList(active)) {
|
||||||
quickActions.add(favorites);
|
quickActions.add(favorites);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quickActions.add(new ShowHideGpxTracksAction());
|
||||||
|
|
||||||
quickActions.add(new ShowHidePoiAction());
|
quickActions.add(new ShowHidePoiAction());
|
||||||
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||||
QuickAction showHideOSMBugAction = new ShowHideOSMBugAction();
|
QuickAction showHideOSMBugAction = new ShowHideOSMBugAction();
|
||||||
|
@ -239,6 +243,9 @@ public class QuickActionFactory {
|
||||||
case DayNightModeAction.TYPE:
|
case DayNightModeAction.TYPE:
|
||||||
return new DayNightModeAction();
|
return new DayNightModeAction();
|
||||||
|
|
||||||
|
case ShowHideGpxTracksAction.TYPE:
|
||||||
|
return new ShowHideGpxTracksAction();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new QuickAction();
|
return new QuickAction();
|
||||||
}
|
}
|
||||||
|
@ -323,6 +330,9 @@ public class QuickActionFactory {
|
||||||
case DayNightModeAction.TYPE:
|
case DayNightModeAction.TYPE:
|
||||||
return new DayNightModeAction(quickAction);
|
return new DayNightModeAction(quickAction);
|
||||||
|
|
||||||
|
case ShowHideGpxTracksAction.TYPE:
|
||||||
|
return new ShowHideGpxTracksAction(quickAction);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return quickAction;
|
return quickAction;
|
||||||
}
|
}
|
||||||
|
@ -407,6 +417,9 @@ public class QuickActionFactory {
|
||||||
case DayNightModeAction.TYPE:
|
case DayNightModeAction.TYPE:
|
||||||
return R.drawable.ic_action_map_day;
|
return R.drawable.ic_action_map_day;
|
||||||
|
|
||||||
|
case ShowHideGpxTracksAction.TYPE:
|
||||||
|
return R.drawable.ic_gpx_track;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return R.drawable.ic_action_plus;
|
return R.drawable.ic_action_plus;
|
||||||
}
|
}
|
||||||
|
@ -491,6 +504,9 @@ public class QuickActionFactory {
|
||||||
case NavResumePauseAction.TYPE:
|
case NavResumePauseAction.TYPE:
|
||||||
return R.string.quick_action_resume_pause_navigation;
|
return R.string.quick_action_resume_pause_navigation;
|
||||||
|
|
||||||
|
case ShowHideGpxTracksAction.TYPE:
|
||||||
|
return R.string.quick_action_show_hide_gpx_tracks;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return R.string.quick_action_new_action;
|
return R.string.quick_action_new_action;
|
||||||
}
|
}
|
||||||
|
@ -517,6 +533,7 @@ public class QuickActionFactory {
|
||||||
case NavStartStopAction.TYPE:
|
case NavStartStopAction.TYPE:
|
||||||
case NavResumePauseAction.TYPE:
|
case NavResumePauseAction.TYPE:
|
||||||
case DayNightModeAction.TYPE:
|
case DayNightModeAction.TYPE:
|
||||||
|
case ShowHideGpxTracksAction.TYPE:
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue