From dbfb379cc8a07a1f72f44535c80c6e80deb7d6a1 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 25 Jun 2020 22:21:19 +0300 Subject: [PATCH 01/16] Gpx width per file --- .../main/java/net/osmand/GPXUtilities.java | 12 + OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 8 +- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 60 ++- OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 6 + .../net/osmand/plus/GpxSelectionHelper.java | 10 + .../osmand/plus/dialogs/ConfigureMapMenu.java | 411 +----------------- .../plus/dialogs/GpxAppearanceAdapter.java | 214 +++++++++ .../plus/dialogs/MapLayerMenuListener.java | 229 ++++++++++ .../net/osmand/plus/helpers/GpxUiHelper.java | 12 +- .../TrackActivityFragmentAdapter.java | 136 +++--- .../src/net/osmand/plus/views/GPXLayer.java | 40 +- 11 files changed, 654 insertions(+), 484 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java create mode 100644 OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 6eb20d0f15..4b266588b8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -148,6 +148,18 @@ public class GPXUtilities { getExtensionsToWrite().remove("color"); } + public String getWidth(String defWidth) { + String widthValue = null; + if (extensions != null) { + widthValue = extensions.get("width"); + } + return widthValue != null ? widthValue : defWidth; + } + + public void setWidth(String width) { + getExtensionsToWrite().put("width", width); + } + public Map getExtensionsToWrite() { if (extensions == null) { extensions = new LinkedHashMap<>(); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 582d6972ee..96686c9956 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -43,6 +43,7 @@ import net.osmand.data.PointDescription; import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.InitEvents; +import net.osmand.plus.dialogs.GpxAppearanceAdapter; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; @@ -60,7 +61,6 @@ import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.settings.backend.SettingsHelper; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; -import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ExternalApiHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; @@ -1146,7 +1146,7 @@ public class OsmandAidlApi { @SuppressLint("StaticFieldLeak") private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) { - final int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor( + final int col = GpxAppearanceAdapter.parseTrackColor( app.getRendererRegistry().getCurrentSelectedRenderer(), color); if (!destinationExists) { GpxDataItem gpxDataItem = new GpxDataItem(destination, col); @@ -1390,7 +1390,7 @@ public class OsmandAidlApi { int color = dataItem.getColor(); String colorName = ""; if (color != 0) { - colorName = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color); + colorName = GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color); } net.osmand.aidlapi.gpx.AGpxFileDetails details = null; GPXTrackAnalysis analysis = dataItem.getAnalysis(); @@ -1431,7 +1431,7 @@ public class OsmandAidlApi { if (file.getName().equals(gpxFileName)) { int color = dataItem.getColor(); if (color != 0) { - return ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color); + return GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color); } } } diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 94b1a993b6..c1f1e220de 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -15,8 +15,9 @@ import java.util.List; public class GPXDatabase { + private static final int DB_VERSION = 11; private static final String DB_NAME = "gpx_database"; - private static final int DB_VERSION = 10; + private static final String GPX_TABLE_NAME = "gpxTable"; private static final String GPX_COL_NAME = "fileName"; private static final String GPX_COL_DIR = "fileDir"; @@ -56,6 +57,8 @@ public class GPXDatabase { private static final String GPX_COL_JOIN_SEGMENTS = "joinSegments"; + private static final String GPX_COL_WIDTH = "width"; + public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1; public static final int GPX_SPLIT_TYPE_DISTANCE = 1; public static final int GPX_SPLIT_TYPE_TIME = 2; @@ -89,7 +92,8 @@ public class GPXDatabase { GPX_COL_API_IMPORTED + " int, " + // 1 = true, 0 = false GPX_COL_WPT_CATEGORY_NAMES + " TEXT, " + GPX_COL_SHOW_AS_MARKERS + " int, " + // 1 = true, 0 = false - GPX_COL_JOIN_SEGMENTS + " int);"; // 1 = true, 0 = false + GPX_COL_JOIN_SEGMENTS + " int, " + // 1 = true, 0 = false + GPX_COL_WIDTH + " TEXT);"; private static final String GPX_TABLE_SELECT = "SELECT " + GPX_COL_NAME + ", " + @@ -117,7 +121,8 @@ public class GPXDatabase { GPX_COL_API_IMPORTED + ", " + GPX_COL_WPT_CATEGORY_NAMES + ", " + GPX_COL_SHOW_AS_MARKERS + ", " + - GPX_COL_JOIN_SEGMENTS + + GPX_COL_JOIN_SEGMENTS + ", " + + GPX_COL_WIDTH + " FROM " + GPX_TABLE_NAME; private static final String GPX_TABLE_UPDATE_ANALYSIS = "UPDATE " + @@ -144,12 +149,14 @@ public class GPXDatabase { private OsmandApplication context; public static class GpxDataItem { + private File file; private GPXTrackAnalysis analysis; + private String width; private int color; - private long fileLastModifiedTime; private int splitType; private double splitInterval; + private long fileLastModifiedTime; private boolean apiImported; private boolean showAsMarkers; private boolean joinSegments; @@ -177,6 +184,14 @@ public class GPXDatabase { return color; } + public String getWidth() { + return width; + } + + public void setWidth(String width) { + this.width = width; + } + public long getFileLastModifiedTime() { return fileLastModifiedTime; } @@ -341,6 +356,9 @@ public class GPXDatabase { " SET " + GPX_COL_JOIN_SEGMENTS + " = ? " + "WHERE " + GPX_COL_JOIN_SEGMENTS + " IS NULL", new Object[]{0}); } + if (oldVersion < 11) { + db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WIDTH + " TEXT"); + } db.execSQL("CREATE INDEX IF NOT EXISTS " + GPX_INDEX_NAME_DIR + " ON " + GPX_TABLE_NAME + " (" + GPX_COL_NAME + ", " + GPX_COL_DIR + ");"); } @@ -391,8 +409,7 @@ public class GPXDatabase { try { String fileName = getFileName(item.file); String fileDir = getFileDir(item.file); - db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + - GPX_COL_COLOR + " = ? " + + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_COLOR + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[] { (color == 0 ? "" : Algorithms.colorToString(color)), fileName, fileDir }); item.color = color; @@ -404,6 +421,24 @@ public class GPXDatabase { return false; } + public boolean updateWidth(GpxDataItem item, String width) { + SQLiteConnection db = openConnection(false); + if (db != null){ + try { + String fileName = getFileName(item.file); + String fileDir = getFileDir(item.file); + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_WIDTH + " = ? " + + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", + new Object[] { width, fileName, fileDir }); + item.width = width; + } finally { + db.close(); + } + return true; + } + return false; + } + public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -518,12 +553,12 @@ public class GPXDatabase { } if (a != null) { db.execSQL( - "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime, a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown, a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints, color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0, - Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0}); + Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, item.width}); } else { db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" + GPX_COL_NAME + ", " + @@ -534,9 +569,10 @@ public class GPXDatabase { GPX_COL_SPLIT_INTERVAL + ", " + GPX_COL_API_IMPORTED + ", " + GPX_COL_SHOW_AS_MARKERS + ", " + - GPX_COL_JOIN_SEGMENTS + - ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", - new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0}); + GPX_COL_JOIN_SEGMENTS + ", " + + GPX_COL_WIDTH + + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, item.width}); } } @@ -617,6 +653,7 @@ public class GPXDatabase { String wptCategoryNames = query.getString(23); boolean showAsMarkers = query.getInt(24) == 1; boolean joinSegments = query.getInt(25) == 1; + String width = query.getString(26); GPXTrackAnalysis a = new GPXTrackAnalysis(); a.totalDistance = totalDistance; @@ -658,6 +695,7 @@ public class GPXDatabase { item.apiImported = apiImported; item.showAsMarkers = showAsMarkers; item.joinSegments = joinSegments; + item.width = width; return item; } diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index 41f19a020b..6221e91f6f 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -77,6 +77,12 @@ public class GpxDbHelper { return res; } + public boolean updateWidth(GpxDataItem item, String width) { + boolean res = db.updateWidth(item, width); + putToCache(item); + return res; + } + public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) { boolean res = db.updateShowAsMarkers(item, showAsMarkers); putToCache(item); diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index f750056bd3..00a626ae6d 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -51,6 +51,7 @@ public class GpxSelectionHelper { private static final String BACKUP = "backup"; private static final String BACKUPMODIFIEDTIME = "backupTime"; private static final String COLOR = "color"; + private static final String WIDTH = "width"; private static final String SELECTED_BY_USER = "selected_by_user"; private OsmandApplication app; @@ -515,6 +516,9 @@ public class GpxSelectionHelper { int clr = Algorithms.parseColor(obj.getString(COLOR)); gpx.setColor(clr); } + if (obj.has(WIDTH)) { + gpx.setWidth(obj.getString(WIDTH)); + } if (gpx.error != null) { save = true; } else if (obj.has(BACKUP)) { @@ -554,6 +558,9 @@ public class GpxSelectionHelper { if (s.gpxFile.getColor(0) != 0) { obj.put(COLOR, Algorithms.colorToString(s.gpxFile.getColor(0))); } + if (s.gpxFile.getWidth(null) != null) { + obj.put(WIDTH, s.gpxFile.getWidth(null)); + } } obj.put(SELECTED_BY_USER, s.selectedByUser); } catch (JSONException e) { @@ -606,6 +613,9 @@ public class GpxSelectionHelper { if (dataItem.getColor() != 0) { gpx.setColor(dataItem.getColor()); } + if (dataItem.getWidth() != null) { + gpx.setWidth(dataItem.getWidth()); + } sf.setJoinSegments(dataItem.isJoinSegments()); } sf.setGpxFile(gpx, app); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index f6399cfa7d..46221ce063 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -2,9 +2,7 @@ package net.osmand.plus.dialogs; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.os.Build; -import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -25,8 +23,6 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; import net.osmand.AndroidUtils; -import net.osmand.CallbackWithObject; -import net.osmand.GPXUtilities; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.core.android.MapRendererContext; @@ -35,20 +31,14 @@ import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.DialogListItemAdapter; -import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.MapActivityLayers; -import net.osmand.plus.activities.PluginActivity; import net.osmand.plus.activities.SettingsActivity; -import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.inapp.InAppPurchaseHelper; -import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; -import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; @@ -58,7 +48,6 @@ import net.osmand.plus.transport.TransportLinesMenu; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.wikipedia.WikipediaPoiMenu; -import net.osmand.render.RenderingRule; import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRuleStorageProperties; import net.osmand.render.RenderingRulesStorage; @@ -67,7 +56,6 @@ import net.osmand.util.SunriseSunset; import org.apache.commons.logging.Log; -import java.io.File; import java.text.DateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -101,7 +89,6 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.ROUTES_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TEXT_SIZE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_ID; -import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID; import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction; import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_DENSITY_ATTR; import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_ATTR; @@ -181,188 +168,13 @@ public class ConfigureMapMenu { return customRules; } - private final class LayerMenuListener extends OnRowItemClick { - private MapActivity ma; - private ContextMenuAdapter cm; - - private LayerMenuListener(MapActivity ma, ContextMenuAdapter cm) { - this.ma = ma; - this.cm = cm; - } - - private List getAlreadySelectedGpx() { - GpxSelectionHelper selectedGpxHelper = ma.getMyApplication().getSelectedGpxHelper(); - List selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles(); - - List files = new ArrayList<>(); - for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) { - files.add(file.getGpxFile().path); - } - if (selectedGpxFiles.isEmpty()) { - Map fls = selectedGpxHelper.getSelectedGpxFilesBackUp(); - for(Map.Entry 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; - } - - @Override - public boolean onRowItemClick(final ArrayAdapter adapter, View view, int itemId, int pos) { - if (itemId == R.string.layer_poi) { - showPoiFilterDialog(adapter, adapter.getItem(pos)); - return false; - } else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) { - showGpxSelectionDialog(adapter, adapter.getItem(pos)); - return false; - } else if (itemId == R.string.rendering_category_transport) { - final ContextMenuItem item = adapter.getItem(pos); - TransportLinesMenu.showTransportsDialog(ma, new CallbackWithObject() { - @Override - public boolean processResult(Boolean result) { - if (item != null) { - item.setSelected(result); - item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - adapter.notifyDataSetChanged(); - } - return true; - } - }); - boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication()); - if (!selected && item != null) { - item.setSelected(true); - item.setColorRes(R.color.osmand_orange); - adapter.notifyDataSetChanged(); - } - return false; - } else { - CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item); - if (btn != null && btn.getVisibility() == View.VISIBLE) { - btn.setChecked(!btn.isChecked()); - cm.getItem(pos).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - adapter.notifyDataSetChanged(); - return false; - } else { - return onContextMenuClick(adapter, itemId, pos, false, null); - } - } - } - - @Override - public boolean onContextMenuClick(final ArrayAdapter adapter, int itemId, - final int pos, boolean isChecked, int[] viewCoordinates) { - final OsmandSettings settings = ma.getMyApplication().getSettings(); - final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters(); - final ContextMenuItem item = cm.getItem(pos); - if (item.getSelected() != null) { - item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - } - if (itemId == R.string.layer_poi) { - PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter(); - poiFiltersHelper.clearSelectedPoiFilters(wiki); - if (isChecked) { - showPoiFilterDialog(adapter, adapter.getItem(pos)); - } else { - adapter.getItem(pos).setDescription( - poiFiltersHelper.getSelectedPoiFiltersName(wiki)); - } - } else if (itemId == R.string.layer_amenity_label) { - settings.SHOW_POI_LABEL.set(isChecked); - } else if (itemId == R.string.shared_string_favorites) { - settings.SHOW_FAVORITES.set(isChecked); - } else if (itemId == R.string.layer_gpx_layer) { - final GpxSelectionHelper selectedGpxHelper = ma.getMyApplication().getSelectedGpxHelper(); - if (selectedGpxHelper.isShowingAnyGpxFiles()) { - selectedGpxHelper.clearAllGpxFilesToShow(true); - adapter.getItem(pos).setDescription(selectedGpxHelper.getGpxDescription()); - } else { - showGpxSelectionDialog(adapter, adapter.getItem(pos)); - } - } else if (itemId == R.string.rendering_category_transport) { - boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication()); - TransportLinesMenu.toggleTransportLines(ma, !selected, new CallbackWithObject() { - @Override - public boolean processResult(Boolean result) { - item.setSelected(result); - item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - adapter.notifyDataSetChanged(); - return true; - } - }); - } else if (itemId == R.string.map_markers) { - settings.SHOW_MAP_MARKERS.set(isChecked); - } else if (itemId == R.string.layer_map) { - if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) { - Intent intent = new Intent(ma, PluginActivity.class); - intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID); - ma.startActivity(intent); - } else { - ContextMenuItem it = adapter.getItem(pos); - ma.getMapLayers().selectMapLayer(ma.getMapView(), it, adapter); - } - } - adapter.notifyDataSetChanged(); - ma.getMapLayers().updateLayers(ma.getMapView()); - ma.getMapView().refreshMap(); - return false; - } - - private void showGpxSelectionDialog(final ArrayAdapter adapter, - final ContextMenuItem item) { - AlertDialog dialog = ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), - ma.getMapView()); - dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - OsmandApplication app = ma.getMyApplication(); - boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles(); - item.setSelected(selected); - item.setDescription(app.getSelectedGpxHelper().getGpxDescription()); - item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - adapter.notifyDataSetChanged(); - } - }); - } - - protected void showPoiFilterDialog(final ArrayAdapter adapter, - final ContextMenuItem item) { - final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters(); - final PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter(); - MapActivityLayers.DismissListener dismissListener = - new MapActivityLayers.DismissListener() { - @Override - public void dismiss() { - PoiFiltersHelper pf = ma.getMyApplication().getPoiFilters(); - boolean selected = pf.isShowingAnyPoi(wiki); - item.setSelected(selected); - item.setDescription(pf.getSelectedPoiFiltersName(wiki)); - item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - adapter.notifyDataSetChanged(); - } - }; - if (poiFiltersHelper.isShowingAnyPoi(wiki)) { - ma.getMapLayers().showMultichoicePoiFilterDialog(ma.getMapView(), - dismissListener); - } else { - ma.getMapLayers().showSingleChoicePoiFilterDialog(ma.getMapView(), - dismissListener); - } - } - } - private void createLayersItems(List customRules, ContextMenuAdapter adapter, final MapActivity activity, final int themeRes, final boolean nightMode) { final OsmandApplication app = activity.getMyApplication(); final OsmandSettings settings = app.getSettings(); final int selectedProfileColorRes = settings.getApplicationMode().getIconColorInfo().getColor(nightMode); final int selectedProfileColor = ContextCompat.getColor(app, selectedProfileColorRes); - LayerMenuListener l = new LayerMenuListener(activity, adapter); + MapLayerMenuListener l = new MapLayerMenuListener(activity, adapter); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(SHOW_CATEGORY_ID) .setTitleId(R.string.shared_string_show, activity) @@ -1299,230 +1111,35 @@ public class ConfigureMapMenu { } } - private class StringSpinnerArrayAdapter extends ArrayAdapter { + private static class StringSpinnerArrayAdapter extends ArrayAdapter { private boolean nightMode; public StringSpinnerArrayAdapter(Context context, boolean nightMode) { super(context, android.R.layout.simple_spinner_item); setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - OsmandApplication app = (OsmandApplication )getContext().getApplicationContext(); this.nightMode = nightMode; } - @Override - public View getView(int position, View convertView, ViewGroup parent) { - TextView label = (TextView) super.getView(position, convertView, parent); - - String text = getItem(position); - label.setText(text); - label.setTextColor(nightMode ? - ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_dark) : ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_light)); - return label; - } - - @Override - public View getDropDownView(int position, View convertView, ViewGroup parent) { - TextView label = (TextView) super.getDropDownView(position, convertView, parent); - - String text = getItem(position); - label.setText(text); - label.setTextColor(nightMode ? - ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_dark) : ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_light)); - - return label; - } - } - - public static class GpxAppearanceAdapter extends ArrayAdapter { - - private OsmandApplication app; - private int currentColor; - private GpxAppearanceAdapterType adapterType = GpxAppearanceAdapterType.TRACK_WIDTH_COLOR; - - public enum GpxAppearanceAdapterType { - TRACK_WIDTH, - TRACK_COLOR, - TRACK_WIDTH_COLOR - } - - public GpxAppearanceAdapter(Context context, String currentColorValue, GpxAppearanceAdapterType adapterType) { - super(context, R.layout.rendering_prop_menu_item); - this.app = (OsmandApplication) getContext().getApplicationContext(); - this.adapterType = adapterType; - RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); - this.currentColor = parseTrackColor(renderer, currentColorValue); - init(); - } - - public GpxAppearanceAdapter(Context context, int currentColor, GpxAppearanceAdapterType adapterType) { - super(context, R.layout.rendering_prop_menu_item); - this.app = (OsmandApplication) getContext().getApplicationContext(); - this.adapterType = adapterType; - this.currentColor = currentColor; - init(); - } - - public void init() { - RenderingRuleProperty trackWidthProp = null; - RenderingRuleProperty trackColorProp = null; - RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); - if (renderer != null) { - if (adapterType == GpxAppearanceAdapterType.TRACK_WIDTH || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) { - trackWidthProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_WIDTH_ATTR); - } - if (adapterType == GpxAppearanceAdapterType.TRACK_COLOR || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) { - trackColorProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_COLOR_ATTR); - } - } - - if (trackWidthProp != null) { - AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_WIDTH_ATTR, "", - SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getDefaultValueDescription())); - add(item); - for (int j = 0; j < trackWidthProp.getPossibleValues().length; j++) { - item = new AppearanceListItem(CURRENT_TRACK_WIDTH_ATTR, - trackWidthProp.getPossibleValues()[j], - SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getPossibleValues()[j])); - add(item); - } - item.setLastItem(true); - } - if (trackColorProp != null) { - AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_COLOR_ATTR, "", - SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getDefaultValueDescription()), - parseTrackColor(renderer, "")); - add(item); - for (int j = 0; j < trackColorProp.getPossibleValues().length; j++) { - item = new AppearanceListItem(CURRENT_TRACK_COLOR_ATTR, - trackColorProp.getPossibleValues()[j], - SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getPossibleValues()[j]), - parseTrackColor(renderer, trackColorProp.getPossibleValues()[j])); - add(item); - } - item.setLastItem(true); - } - } - - public static int parseTrackColor(RenderingRulesStorage renderer, String colorName) { - int defaultColor = -1; - RenderingRule gpxRule = null; - if (renderer != null) { - gpxRule = renderer.getRenderingAttributeRule("gpx"); - } - if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) { - List rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren(); - for (RenderingRule r : rules) { - String cName = r.getStringPropertyValue(CURRENT_TRACK_COLOR_ATTR); - if (!Algorithms.isEmpty(cName) && cName.equals(colorName)) { - return r.getIntPropertyValue(COLOR_ATTR); - } - if (cName == null && defaultColor == -1) { - defaultColor = r.getIntPropertyValue(COLOR_ATTR); - } - } - } - return defaultColor; - } - - public static String parseTrackColorName(RenderingRulesStorage renderer, int color) { - RenderingRule gpxRule = null; - if (renderer != null) { - gpxRule = renderer.getRenderingAttributeRule("gpx"); - } - if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) { - List rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren(); - for (RenderingRule r : rules) { - String cName = r.getStringPropertyValue(CURRENT_TRACK_COLOR_ATTR); - if (!Algorithms.isEmpty(cName) && color == r.getIntPropertyValue(COLOR_ATTR)) { - return cName; - } - } - } - return Algorithms.colorToString(color); - } - @NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { - AppearanceListItem item = getItem(position); - View v = convertView; - if (v == null) { - v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, null); - } - if (item != null) { - TextView textView = (TextView) v.findViewById(R.id.text1); - textView.setText(item.localizedValue); - if (item.attrName == CURRENT_TRACK_WIDTH_ATTR) { - int iconId; - if (item.value.equals("bold")) { - iconId = R.drawable.ic_action_gpx_width_bold; - } else if (item.value.equals("medium")) { - iconId = R.drawable.ic_action_gpx_width_medium; - } else { - iconId = R.drawable.ic_action_gpx_width_thin; - } - textView.setCompoundDrawablesWithIntrinsicBounds(null, null, - app.getUIUtilities().getPaintedIcon(iconId, currentColor), null); - } else { - if (item.color == -1) { - textView.setCompoundDrawablesWithIntrinsicBounds(null, null, - app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle), null); - } else { - textView.setCompoundDrawablesWithIntrinsicBounds(null, null, - app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, item.color), null); - } - } - textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f)); - v.findViewById(R.id.divider).setVisibility(item.lastItem - && position < getCount() - 1 ? View.VISIBLE : View.GONE); - } - return v; - } - } - - public static class AppearanceListItem { - private String attrName; - private String value; - private String localizedValue; - private int color; - private boolean lastItem; - - public AppearanceListItem(String attrName, String value, String localizedValue) { - this.attrName = attrName; - this.value = value; - this.localizedValue = localizedValue; + TextView label = (TextView) super.getView(position, convertView, parent); + setupLabel(label, getItem(position)); + return label; } - public AppearanceListItem(String attrName, String value, String localizedValue, int color) { - this.attrName = attrName; - this.value = value; - this.localizedValue = localizedValue; - this.color = color; + @Override + public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) { + TextView label = (TextView) super.getDropDownView(position, convertView, parent); + setupLabel(label, getItem(position)); + return label; } - public String getAttrName() { - return attrName; - } - - public String getValue() { - return value; - } - - public String getLocalizedValue() { - return localizedValue; - } - - public int getColor() { - return color; - } - - public boolean isLastItem() { - return lastItem; - } - - public void setLastItem(boolean lastItem) { - this.lastItem = lastItem; + private void setupLabel(TextView label, String text) { + int colorId = nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light; + label.setText(text); + label.setTextColor(ContextCompat.getColorStateList(getContext(), colorId)); } } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java b/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java new file mode 100644 index 0000000000..048461da55 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java @@ -0,0 +1,214 @@ +package net.osmand.plus.dialogs; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import net.osmand.AndroidUtils; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.SettingsActivity; +import net.osmand.render.RenderingRule; +import net.osmand.render.RenderingRuleProperty; +import net.osmand.render.RenderingRulesStorage; +import net.osmand.util.Algorithms; + +import java.util.List; + +public class GpxAppearanceAdapter extends ArrayAdapter { + + private OsmandApplication app; + private GpxAppearanceAdapterType adapterType; + private int currentColor; + + public enum GpxAppearanceAdapterType { + TRACK_WIDTH, + TRACK_COLOR, + TRACK_WIDTH_COLOR + } + + public GpxAppearanceAdapter(Context context, String currentColorValue, GpxAppearanceAdapterType adapterType) { + super(context, R.layout.rendering_prop_menu_item); + this.app = (OsmandApplication) context.getApplicationContext(); + this.adapterType = adapterType; + RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); + this.currentColor = parseTrackColor(renderer, currentColorValue); + init(); + } + + public GpxAppearanceAdapter(Context context, int currentColor, GpxAppearanceAdapterType adapterType) { + super(context, R.layout.rendering_prop_menu_item); + this.app = (OsmandApplication) context.getApplicationContext(); + this.adapterType = adapterType; + this.currentColor = currentColor; + init(); + } + + @NonNull + @Override + public View getView(int position, View convertView, @NonNull ViewGroup parent) { + AppearanceListItem item = getItem(position); + View v = convertView; + if (v == null) { + v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, null); + } + if (item != null) { + TextView textView = (TextView) v.findViewById(R.id.text1); + textView.setText(item.localizedValue); + if (ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR.equals(item.attrName)) { + int iconId; + if ("bold".equals(item.value)) { + iconId = R.drawable.ic_action_gpx_width_bold; + } else if ("medium".equals(item.value)) { + iconId = R.drawable.ic_action_gpx_width_medium; + } else { + iconId = R.drawable.ic_action_gpx_width_thin; + } + textView.setCompoundDrawablesWithIntrinsicBounds(null, null, + app.getUIUtilities().getPaintedIcon(iconId, currentColor), null); + } else { + if (item.color == -1) { + textView.setCompoundDrawablesWithIntrinsicBounds(null, null, + app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle), null); + } else { + textView.setCompoundDrawablesWithIntrinsicBounds(null, null, + app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, item.color), null); + } + } + textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f)); + v.findViewById(R.id.divider).setVisibility(item.lastItem + && position < getCount() - 1 ? View.VISIBLE : View.GONE); + } + return v; + } + + public void init() { + RenderingRuleProperty trackWidthProp = null; + RenderingRuleProperty trackColorProp = null; + RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); + if (renderer != null) { + if (adapterType == GpxAppearanceAdapterType.TRACK_WIDTH || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) { + trackWidthProp = renderer.PROPS.getCustomRule(ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR); + } + if (adapterType == GpxAppearanceAdapterType.TRACK_COLOR || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) { + trackColorProp = renderer.PROPS.getCustomRule(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR); + } + } + + if (trackWidthProp != null) { + AppearanceListItem item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR, "", + SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getDefaultValueDescription())); + add(item); + for (int j = 0; j < trackWidthProp.getPossibleValues().length; j++) { + item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR, + trackWidthProp.getPossibleValues()[j], + SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getPossibleValues()[j])); + add(item); + } + item.setLastItem(true); + } + if (trackColorProp != null) { + AppearanceListItem item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR, "", + SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getDefaultValueDescription()), + parseTrackColor(renderer, "")); + add(item); + for (int j = 0; j < trackColorProp.getPossibleValues().length; j++) { + item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR, + trackColorProp.getPossibleValues()[j], + SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getPossibleValues()[j]), + parseTrackColor(renderer, trackColorProp.getPossibleValues()[j])); + add(item); + } + item.setLastItem(true); + } + } + + public static int parseTrackColor(RenderingRulesStorage renderer, String colorName) { + int defaultColor = -1; + RenderingRule gpxRule = null; + if (renderer != null) { + gpxRule = renderer.getRenderingAttributeRule("gpx"); + } + if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) { + List rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren(); + for (RenderingRule r : rules) { + String cName = r.getStringPropertyValue(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR); + if (!Algorithms.isEmpty(cName) && cName.equals(colorName)) { + return r.getIntPropertyValue(ConfigureMapMenu.COLOR_ATTR); + } + if (cName == null && defaultColor == -1) { + defaultColor = r.getIntPropertyValue(ConfigureMapMenu.COLOR_ATTR); + } + } + } + return defaultColor; + } + + public static String parseTrackColorName(RenderingRulesStorage renderer, int color) { + RenderingRule gpxRule = null; + if (renderer != null) { + gpxRule = renderer.getRenderingAttributeRule("gpx"); + } + if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) { + List rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren(); + for (RenderingRule r : rules) { + String cName = r.getStringPropertyValue(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR); + if (!Algorithms.isEmpty(cName) && color == r.getIntPropertyValue(ConfigureMapMenu.COLOR_ATTR)) { + return cName; + } + } + } + return Algorithms.colorToString(color); + } + + public static class AppearanceListItem { + + private String attrName; + private String value; + private String localizedValue; + private int color; + private boolean lastItem; + + public AppearanceListItem(String attrName, String value, String localizedValue) { + this.attrName = attrName; + this.value = value; + this.localizedValue = localizedValue; + } + + public AppearanceListItem(String attrName, String value, String localizedValue, int color) { + this.attrName = attrName; + this.value = value; + this.localizedValue = localizedValue; + this.color = color; + } + + public String getAttrName() { + return attrName; + } + + public String getValue() { + return value; + } + + public String getLocalizedValue() { + return localizedValue; + } + + public int getColor() { + return color; + } + + public boolean isLastItem() { + return lastItem; + } + + public void setLastItem(boolean lastItem) { + this.lastItem = lastItem; + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java b/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java new file mode 100644 index 0000000000..d369ac0ea2 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java @@ -0,0 +1,229 @@ +package net.osmand.plus.dialogs; + +import android.content.DialogInterface; +import android.content.Intent; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; + +import androidx.appcompat.app.AlertDialog; + +import net.osmand.AndroidUtils; +import net.osmand.CallbackWithObject; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; +import net.osmand.plus.ContextMenuItem; +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +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.MapActivityLayers; +import net.osmand.plus.activities.PluginActivity; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.transport.TransportLinesMenu; +import net.osmand.plus.wikipedia.WikipediaPoiMenu; +import net.osmand.util.Algorithms; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +final class MapLayerMenuListener extends OnRowItemClick { + + private MapActivity mapActivity; + private ContextMenuAdapter menuAdapter; + + MapLayerMenuListener(MapActivity mapActivity, ContextMenuAdapter menuAdapter) { + this.mapActivity = mapActivity; + this.menuAdapter = menuAdapter; + } + + private List getAlreadySelectedGpx() { + GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper(); + List selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles(); + + List files = new ArrayList<>(); + for (SelectedGpxFile file : selectedGpxFiles) { + files.add(file.getGpxFile().path); + } + if (selectedGpxFiles.isEmpty()) { + Map fls = selectedGpxHelper.getSelectedGpxFilesBackUp(); + for (Map.Entry 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; + } + + @Override + public boolean onRowItemClick(final ArrayAdapter adapter, View view, int itemId, int pos) { + if (itemId == R.string.layer_poi) { + showPoiFilterDialog(adapter, adapter.getItem(pos)); + return false; + } else if (itemId == R.string.layer_gpx_layer && menuAdapter.getItem(pos).getSelected()) { + showGpxSelectionDialog(adapter, adapter.getItem(pos)); + return false; + } else if (itemId == R.string.shared_string_wikipedia) { + mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.WIKIPEDIA, + AndroidUtils.getCenterViewCoordinates(view)); + return false; + } else if (itemId == R.string.rendering_category_transport) { + final ContextMenuItem item = adapter.getItem(pos); + TransportLinesMenu.showTransportsDialog(mapActivity, new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + if (item != null) { + item.setSelected(result); + item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + } + return true; + } + }); + boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication()); + if (!selected && item != null) { + item.setSelected(true); + item.setColorRes(R.color.osmand_orange); + adapter.notifyDataSetChanged(); + } + return false; + } else { + CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item); + if (btn != null && btn.getVisibility() == View.VISIBLE) { + btn.setChecked(!btn.isChecked()); + menuAdapter.getItem(pos).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + return false; + } else { + return onContextMenuClick(adapter, itemId, pos, false, null); + } + } + } + + @Override + public boolean onContextMenuClick(final ArrayAdapter adapter, int itemId, + final int pos, boolean isChecked, int[] viewCoordinates) { + final OsmandSettings settings = mapActivity.getMyApplication().getSettings(); + final PoiFiltersHelper poiFiltersHelper = mapActivity.getMyApplication().getPoiFilters(); + final ContextMenuItem item = menuAdapter.getItem(pos); + if (item.getSelected() != null) { + item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + } + if (itemId == R.string.layer_poi) { + PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter(); + poiFiltersHelper.clearSelectedPoiFilters(wiki); + if (isChecked) { + showPoiFilterDialog(adapter, adapter.getItem(pos)); + } else { + adapter.getItem(pos).setDescription( + poiFiltersHelper.getSelectedPoiFiltersName(wiki)); + } + } else if (itemId == R.string.layer_amenity_label) { + settings.SHOW_POI_LABEL.set(isChecked); + } else if (itemId == R.string.shared_string_favorites) { + settings.SHOW_FAVORITES.set(isChecked); + } else if (itemId == R.string.layer_gpx_layer) { + final GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper(); + if (selectedGpxHelper.isShowingAnyGpxFiles()) { + selectedGpxHelper.clearAllGpxFilesToShow(true); + adapter.getItem(pos).setDescription(selectedGpxHelper.getGpxDescription()); + } else { + showGpxSelectionDialog(adapter, adapter.getItem(pos)); + } + } else if (itemId == R.string.shared_string_wikipedia) { + WikipediaPoiMenu.toggleWikipediaPoi(mapActivity, isChecked, new CallbackWithObject() { + @Override + public boolean processResult(Boolean selected) { + item.setSelected(selected); + item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + item.setDescription(selected ? + WikipediaPoiMenu.getLanguagesSummary(mapActivity.getMyApplication()) : null); + adapter.notifyDataSetChanged(); + return true; + } + }); + } else if (itemId == R.string.rendering_category_transport) { + boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication()); + TransportLinesMenu.toggleTransportLines(mapActivity, !selected, new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + item.setSelected(result); + item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + return true; + } + }); + } else if (itemId == R.string.map_markers) { + settings.SHOW_MAP_MARKERS.set(isChecked); + } else if (itemId == R.string.layer_map) { + if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) { + Intent intent = new Intent(mapActivity, PluginActivity.class); + intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID); + mapActivity.startActivity(intent); + } else { + ContextMenuItem it = adapter.getItem(pos); + mapActivity.getMapLayers().selectMapLayer(mapActivity.getMapView(), it, adapter); + } + } + adapter.notifyDataSetChanged(); + mapActivity.getMapLayers().updateLayers(mapActivity.getMapView()); + mapActivity.getMapView().refreshMap(); + return false; + } + + private void showGpxSelectionDialog(final ArrayAdapter adapter, + final ContextMenuItem item) { + AlertDialog dialog = mapActivity.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), + mapActivity.getMapView()); + dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + OsmandApplication app = mapActivity.getMyApplication(); + boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles(); + item.setSelected(selected); + item.setDescription(app.getSelectedGpxHelper().getGpxDescription()); + item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + } + }); + } + + protected void showPoiFilterDialog(final ArrayAdapter adapter, + final ContextMenuItem item) { + final PoiFiltersHelper poiFiltersHelper = mapActivity.getMyApplication().getPoiFilters(); + final PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter(); + MapActivityLayers.DismissListener dismissListener = + new MapActivityLayers.DismissListener() { + @Override + public void dismiss() { + PoiFiltersHelper pf = mapActivity.getMyApplication().getPoiFilters(); + boolean selected = pf.isShowingAnyPoi(wiki); + item.setSelected(selected); + item.setDescription(pf.getSelectedPoiFiltersName(wiki)); + item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + } + }; + if (poiFiltersHelper.isShowingAnyPoi(wiki)) { + mapActivity.getMapLayers().showMultichoicePoiFilterDialog(mapActivity.getMapView(), + dismissListener); + } else { + mapActivity.getMapLayers().showSingleChoicePoiFilterDialog(mapActivity.getMapView(), + dismissListener); + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 356f8c9870..c3dc6c2ae6 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -80,7 +80,6 @@ import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; @@ -90,10 +89,11 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.PluginActivity; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.dialogs.ConfigureMapMenu; -import net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem; -import net.osmand.plus.dialogs.ConfigureMapMenu.GpxAppearanceAdapter; +import net.osmand.plus.dialogs.GpxAppearanceAdapter; +import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RouteCalculationResult; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRulesStorage; import net.osmand.router.RouteStatisticsHelper; @@ -540,9 +540,9 @@ public class GpxUiHelper { public void onItemClick(AdapterView parent, View view, int position, long id) { AppearanceListItem item = gpxApprAdapter.getItem(position); if (item != null) { - if (item.getAttrName() == CURRENT_TRACK_WIDTH_ATTR) { + if (CURRENT_TRACK_WIDTH_ATTR.equals(item.getAttrName())) { gpxAppearanceParams.put(CURRENT_TRACK_WIDTH_ATTR, item.getValue()); - } else if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) { + } else if (CURRENT_TRACK_COLOR_ATTR.equals(item.getAttrName())) { gpxAppearanceParams.put(CURRENT_TRACK_COLOR_ATTR, item.getValue()); } } @@ -592,7 +592,7 @@ public class GpxUiHelper { } dialog.dismiss(); loadGPXFileInDifferentThread(activity, callbackWithObject, dir, currentGPX, - s.toArray(new String[s.size()])); + s.toArray(new String[0])); } }); builder.setNegativeButton(R.string.shared_string_cancel, null); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 25d9d7450a..61820c3f55 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -1,5 +1,6 @@ package net.osmand.plus.myplaces; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -14,8 +15,10 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.AbsListView; import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; +import android.widget.ListAdapter; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; @@ -49,19 +52,23 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; -import net.osmand.plus.dialogs.ConfigureMapMenu; +import net.osmand.plus.dialogs.GpxAppearanceAdapter; +import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; +import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType; import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.render.RenderingRulesStorage; +import net.osmand.util.Algorithms; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -71,6 +78,7 @@ import java.util.Map; import gnu.trove.list.array.TIntArrayList; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; +import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR; public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { @@ -356,50 +364,27 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { @Override public void onClick(View v) { TrackActivity activity = getTrackActivity(); - if (activity != null) { - colorListPopupWindow = new ListPopupWindow(activity); - colorListPopupWindow.setAnchorView(colorView); - colorListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f)); - colorListPopupWindow.setModal(true); - colorListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP); - colorListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f)); - colorListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f)); - GPXFile gpxFile = getGpx(); - final ConfigureMapMenu.GpxAppearanceAdapter gpxApprAdapter = new ConfigureMapMenu.GpxAppearanceAdapter(activity, - gpxFile.getColor(0), ConfigureMapMenu.GpxAppearanceAdapter.GpxAppearanceAdapterType.TRACK_COLOR); - colorListPopupWindow.setAdapter(gpxApprAdapter); - colorListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() { + final GPXFile gpxFile = getGpx(); + if (activity != null && gpxFile != null) { + final GpxAppearanceAdapter appearanceAdapter = new GpxAppearanceAdapter(activity, + gpxFile.getColor(0), GpxAppearanceAdapterType.TRACK_WIDTH_COLOR); + OnItemClickListener itemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - ConfigureMapMenu.AppearanceListItem item = gpxApprAdapter.getItem(position); + AppearanceListItem item = appearanceAdapter.getItem(position); if (item != null) { if (CURRENT_TRACK_COLOR_ATTR.equals(item.getAttrName())) { - GPXFile gpx = getGpx(); - int clr = item.getColor(); - if (vis.isChecked()) { - if (gpx != null) { - SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, vis.isChecked(), false); - if (clr != 0 && sf.getModifiableGpxFile() != null) { - sf.getModifiableGpxFile().setColor(clr); - if (getGpxDataItem() != null) { - app.getGpxDbHelper().updateColor(getGpxDataItem(), clr); - } - } - } - } else if (getGpxDataItem() != null) { - app.getGpxDbHelper().updateColor(getGpxDataItem(), clr); - } - if (gpx != null && gpx.showCurrentTrack) { - app.getSettings().CURRENT_TRACK_COLOR.set(clr); - } - refreshTrackBitmap(); + setGpxColor(item, gpxFile); + } else if (CURRENT_TRACK_WIDTH_ATTR.equals(item.getAttrName())) { + setGpxWidth(item, gpxFile); } } colorListPopupWindow.dismiss(); updateColorView(colorView); } - }); + }; + colorListPopupWindow = createPopupWindow(activity, splitIntervalView, appearanceAdapter, itemClickListener); colorListPopupWindow.show(); } } @@ -415,16 +400,8 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { public void onClick(View v) { TrackActivity activity = getTrackActivity(); if (activity != null) { - splitListPopupWindow = new ListPopupWindow(activity); - splitListPopupWindow.setAnchorView(splitIntervalView); - splitListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f)); - splitListPopupWindow.setModal(true); - splitListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP); - splitListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f)); - splitListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f)); - splitListPopupWindow.setAdapter(new ArrayAdapter<>(activity, - R.layout.popup_list_text_item, options)); - splitListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() { + ListAdapter adapter = new ArrayAdapter<>(activity, R.layout.popup_list_text_item, options); + OnItemClickListener itemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -433,7 +410,8 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { splitListPopupWindow.dismiss(); updateSplitIntervalView(splitIntervalView); } - }); + }; + splitListPopupWindow = createPopupWindow(activity, splitIntervalView, adapter, itemClickListener); splitListPopupWindow.show(); } } @@ -451,6 +429,55 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } } + private void setGpxColor(AppearanceListItem item, GPXFile gpxFile) { + int color = item.getColor(); + if (vis.isChecked()) { + SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false); + if (color != 0 && sf.getModifiableGpxFile() != null) { + sf.getModifiableGpxFile().setColor(color); + if (getGpxDataItem() != null) { + app.getGpxDbHelper().updateColor(getGpxDataItem(), color); + } + } + } else if (getGpxDataItem() != null) { + app.getGpxDbHelper().updateColor(getGpxDataItem(), color); + } + if (gpxFile.showCurrentTrack) { + app.getSettings().CURRENT_TRACK_COLOR.set(color); + } + refreshTrackBitmap(); + } + + private void setGpxWidth(AppearanceListItem item, GPXFile gpxFile) { + String width = item.getValue(); + if (vis.isChecked()) { + SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false); + if (!Algorithms.isEmpty(width) && sf.getModifiableGpxFile() != null) { + sf.getModifiableGpxFile().setWidth(width); + if (getGpxDataItem() != null) { + app.getGpxDbHelper().updateWidth(getGpxDataItem(), width); + } + } + } else if (getGpxDataItem() != null) { + app.getGpxDbHelper().updateWidth(getGpxDataItem(), width); + } + refreshTrackBitmap(); + } + + private ListPopupWindow createPopupWindow(Activity activity, View anchorView, ListAdapter adapter, OnItemClickListener itemClickListener) { + ListPopupWindow popupWindow = new ListPopupWindow(activity); + popupWindow.setAnchorView(anchorView); + popupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f)); + popupWindow.setModal(true); + popupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP); + popupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f)); + popupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f)); + popupWindow.setAdapter(adapter); + popupWindow.setOnItemClickListener(itemClickListener); + + return popupWindow; + } + @Nullable private View getDescriptionCardView(Context context) { GPXFile gpx = getGpx(); @@ -729,7 +756,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { text.setText(options.get(selectedSplitInterval)); } } - + private int getSelectedSplitInterval() { if (getGpxDataItem() == null) { return 0; @@ -737,14 +764,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { int splitType = getGpxDataItem().getSplitType(); double splitInterval = getGpxDataItem().getSplitInterval(); int position = 0; - + if (splitType == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { position = distanceSplit.indexOf(splitInterval); } else if (splitType == GPXDatabase.GPX_SPLIT_TYPE_TIME) { position = timeSplit.indexOf((int) splitInterval); } - - return position > 0 ? position : 0; + + return Math.max(position, 0); } private void updateColorView(View colorView) { @@ -759,10 +786,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } } if (color == 0) { - final RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); - final OsmandSettings.CommonPreference prefColor - = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR); - color = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get()); + RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); + CommonPreference prefColor = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR); + color = GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get()); } if (color == 0) { colorImageView.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle)); diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index fdc9ab950e..4adc2ef5ff 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -26,6 +26,7 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; import net.osmand.Location; +import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; @@ -55,6 +56,8 @@ import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -67,6 +70,7 @@ import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR; public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IMoveObjectProvider, MapTextProvider { + private static final Log log = PlatformUtil.getLog(GPXLayer.class); private static final double TOUCH_RADIUS_MULTIPLIER = 1.5; private static final int START_ZOOM = 7; @@ -81,6 +85,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private boolean isPaint_1; private int cachedHash; private int cachedColor; + private Map cachedWidth = new HashMap<>(); private Paint paintIcon; private int currentTrackColor; @@ -220,29 +225,30 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } - private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) { + private int updatePaints(int color, String width, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) { RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer(); final boolean isNight = nightMode != null && nightMode.isNightMode(); - int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom(), - currentTrackColorPref.get(), currentTrackWidthPref.get()); + int hsh = calculateHash(rrs, cachedWidth, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom(), + currentTrackColorPref.get(), currentTrackWidthPref.get()); + String widthKey = width; if (hsh != cachedHash) { + log.debug("updatePaints new HASH " + width); cachedHash = hsh; cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track); if (rrs != null) { RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight); - CommonPreference p = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR); - if (p != null && p.isSet()) { + if (currentTrackColorPref != null && currentTrackColorPref.isSet()) { RenderingRuleProperty ctColor = rrs.PROPS.get(CURRENT_TRACK_COLOR_ATTR); if (ctColor != null) { - req.setStringFilter(ctColor, p.get()); + req.setStringFilter(ctColor, currentTrackColorPref.get()); } } - CommonPreference p2 = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR); - if (p2 != null && p2.isSet()) { + if (currentTrackWidthPref != null && currentTrackWidthPref.isSet()) { RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR); if (ctWidth != null) { - req.setStringFilter(ctWidth, p2.get()); + widthKey = width == null ? currentTrackWidthPref.get() : width; + req.setStringFilter(ctWidth, widthKey); } } String additional = ""; @@ -261,6 +267,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM RenderingContext rc = new OsmandRenderer.RenderingContext(view.getContext()); rc.setDensityValue((float) tileBox.getMapDensity()); cachedColor = req.getIntPropertyValue(rrs.PROPS.R_COLOR); + + float widthF = rc.getComplexValue(req, req.ALL.R_STROKE_WIDTH); + cachedWidth.put(widthKey, widthF); + osmandRenderer.updatePaint(req, paint, 0, false, rc); isPaint2 = osmandRenderer.updatePaint(req, paint2, 1, false, rc); isPaint_1 = osmandRenderer.updatePaint(req, paint_1, -1, false, rc); @@ -279,6 +289,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } } paint.setColor(color == 0 ? cachedColor : color); + Float strikeWidth = cachedWidth.get(widthKey); + if (strikeWidth != null) { + paint.setStrokeWidth(strikeWidth); + } return cachedColor; } @@ -536,6 +550,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM RotatedTileBox tileBox, DrawSettings settings) { List segments = selectedGpxFile.getPointsToDisplay(); for (TrkSegment ts : segments) { + String width = selectedGpxFile.getGpxFile().getWidth(null); + if (!cachedWidth.containsKey(width)) { + cachedWidth.put(width, null); + } int color = selectedGpxFile.getGpxFile().getColor(0); if (currentTrack) { color = currentTrackColor; @@ -550,8 +568,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM ts.renderer = new Renderable.StandardTrack(ts.points, 17.2); } } - updatePaints(color, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox); - if(ts.renderer instanceof Renderable.RenderableSegment) { + updatePaints(color, width, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox); + if (ts.renderer instanceof Renderable.RenderableSegment) { ((Renderable.RenderableSegment) ts.renderer).drawSegment(view.getZoom(), paint, canvas, tileBox); } } From ddd66a9f84dce160f8e5fa1875b25cba5ea9d851 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 26 Jun 2020 11:09:33 +0300 Subject: [PATCH 02/16] Fix track width draw cache --- .../TrackActivityFragmentAdapter.java | 3 +- .../src/net/osmand/plus/views/GPXLayer.java | 116 ++++++++---------- 2 files changed, 50 insertions(+), 69 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 61820c3f55..0304618a7c 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -68,7 +68,6 @@ import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.render.RenderingRulesStorage; -import net.osmand.util.Algorithms; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -452,7 +451,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { String width = item.getValue(); if (vis.isChecked()) { SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false); - if (!Algorithms.isEmpty(width) && sf.getModifiableGpxFile() != null) { + if (width != null && sf.getModifiableGpxFile() != null) { sf.getModifiableGpxFile().setWidth(width); if (getGpxDataItem() != null) { app.getGpxDbHelper().updateWidth(getGpxDataItem(), width); diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 4adc2ef5ff..8646c6effb 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -2,7 +2,6 @@ package net.osmand.plus.views; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Paint.Style; @@ -26,7 +25,6 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; import net.osmand.Location; -import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; @@ -56,8 +54,6 @@ import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; -import org.apache.commons.logging.Log; - import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -70,22 +66,16 @@ import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR; public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IMoveObjectProvider, MapTextProvider { - private static final Log log = PlatformUtil.getLog(GPXLayer.class); private static final double TOUCH_RADIUS_MULTIPLIER = 1.5; private static final int START_ZOOM = 7; private OsmandMapTileView view; private Paint paint; - private Paint paint2; - private boolean isPaint2; private Paint shadowPaint; - private boolean isShadowPaint; - private Paint paint_1; - private boolean isPaint_1; private int cachedHash; private int cachedColor; - private Map cachedWidth = new HashMap<>(); + private Map cachedTrackWidth = new HashMap<>(); private Paint paintIcon; private int currentTrackColor; @@ -94,7 +84,6 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private GpxSelectionHelper selectedGpxHelper; private MapMarkersHelper mapMarkersHelper; - private Paint paintBmp; private List cache = new ArrayList<>(); private Map pointFileMap = new HashMap<>(); private MapTextLayer textLayer; @@ -139,26 +128,14 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM paint = new Paint(); paint.setStyle(Style.STROKE); paint.setAntiAlias(true); - paint2 = new Paint(); - paint2.setStyle(Style.STROKE); - paint2.setAntiAlias(true); shadowPaint = new Paint(); shadowPaint.setStyle(Style.STROKE); shadowPaint.setAntiAlias(true); - paint_1 = new Paint(); - paint_1.setStyle(Style.STROKE); - paint_1.setAntiAlias(true); - - paintBmp = new Paint(); - paintBmp.setAntiAlias(true); - paintBmp.setFilterBitmap(true); - paintBmp.setDither(true); paintTextIcon = new Paint(); paintTextIcon.setTextSize(10 * view.getDensity()); paintTextIcon.setTextAlign(Align.CENTER); paintTextIcon.setFakeBoldText(true); -// paintTextIcon.setColor(Color.WHITE); paintTextIcon.setAntiAlias(true); textLayer = view.getLayerByClass(MapTextLayer.class); @@ -169,17 +146,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM paintOuterRect = new Paint(); paintOuterRect.setStyle(Style.STROKE); paintOuterRect.setAntiAlias(true); -// paintOuterRect.setColor(Color.WHITE); paintOuterRect.setStrokeWidth(3); paintOuterRect.setAlpha(255); paintGridCircle = new Paint(); paintGridCircle.setStyle(Style.FILL_AND_STROKE); paintGridCircle.setAntiAlias(true); - paintGridOuterCircle = new Paint(); - paintGridOuterCircle.setStyle(Style.FILL_AND_STROKE); - paintGridOuterCircle.setAntiAlias(true); - paintGridOuterCircle.setColor(Color.WHITE); - paintGridOuterCircle.setAlpha(204); + paintGridOuterCircle = new Paint(); + paintGridOuterCircle.setStyle(Style.FILL_AND_STROKE); + paintGridOuterCircle.setAntiAlias(true); + paintGridOuterCircle.setColor(Color.WHITE); + paintGridOuterCircle.setAlpha(204); paintIcon = new Paint(); selectedPoint = (LayerDrawable) AppCompatResources.getDrawable(view.getContext(), R.drawable.map_location_default); @@ -225,19 +201,17 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } - private int updatePaints(int color, String width, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) { + private int updatePaints(int color, String width, boolean routePoints, boolean currentTrack, DrawSettings drawSettings, RotatedTileBox tileBox) { RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer(); - final boolean isNight = nightMode != null && nightMode.isNightMode(); - int hsh = calculateHash(rrs, cachedWidth, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom(), + boolean nightMode = drawSettings != null && drawSettings.isNightMode(); + int hash = calculateHash(rrs, cachedTrackWidth, routePoints, nightMode, tileBox.getMapDensity(), tileBox.getZoom(), currentTrackColorPref.get(), currentTrackWidthPref.get()); - String widthKey = width; - if (hsh != cachedHash) { - log.debug("updatePaints new HASH " + width); - cachedHash = hsh; + if (hash != cachedHash) { + cachedHash = hash; cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track); if (rrs != null) { RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); - req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight); + req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); if (currentTrackColorPref != null && currentTrackColorPref.isSet()) { RenderingRuleProperty ctColor = rrs.PROPS.get(CURRENT_TRACK_COLOR_ATTR); if (ctColor != null) { @@ -247,8 +221,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM if (currentTrackWidthPref != null && currentTrackWidthPref.isSet()) { RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR); if (ctWidth != null) { - widthKey = width == null ? currentTrackWidthPref.get() : width; - req.setStringFilter(ctWidth, widthKey); + req.setStringFilter(ctWidth, currentTrackWidthPref.get()); } } String additional = ""; @@ -267,20 +240,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM RenderingContext rc = new OsmandRenderer.RenderingContext(view.getContext()); rc.setDensityValue((float) tileBox.getMapDensity()); cachedColor = req.getIntPropertyValue(rrs.PROPS.R_COLOR); - - float widthF = rc.getComplexValue(req, req.ALL.R_STROKE_WIDTH); - cachedWidth.put(widthKey, widthF); - osmandRenderer.updatePaint(req, paint, 0, false, rc); - isPaint2 = osmandRenderer.updatePaint(req, paint2, 1, false, rc); - isPaint_1 = osmandRenderer.updatePaint(req, paint_1, -1, false, rc); - isShadowPaint = req.isSpecified(rrs.PROPS.R_SHADOW_RADIUS); - if (isShadowPaint) { - ColorFilter cf = new PorterDuffColorFilter(req.getIntPropertyValue(rrs.PROPS.R_SHADOW_COLOR), - Mode.SRC_IN); - shadowPaint.setColorFilter(cf); - shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 - * rc.getComplexValue(req, rrs.PROPS.R_SHADOW_RADIUS)); + + if (req.isSpecified(rrs.PROPS.R_SHADOW_RADIUS)) { + int shadowColor = req.getIntPropertyValue(rrs.PROPS.R_SHADOW_COLOR); + float shadowRadius = rc.getComplexValue(req, rrs.PROPS.R_SHADOW_RADIUS); + shadowPaint.setColorFilter(new PorterDuffColorFilter(shadowColor, Mode.SRC_IN)); + shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 * shadowRadius); + } + for (String key : cachedTrackWidth.keySet()) { + searchTrackWidth(key, rrs, req, rc); } } else { System.err.println("Rendering attribute gpx is not found !"); @@ -289,19 +258,30 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } } paint.setColor(color == 0 ? cachedColor : color); - Float strikeWidth = cachedWidth.get(widthKey); + Float strikeWidth = cachedTrackWidth.get(width); if (strikeWidth != null) { paint.setStrokeWidth(strikeWidth); } return cachedColor; } + private void searchTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) { + RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR); + if (ctWidth != null) { + req.setStringFilter(ctWidth, widthKey); + } + if (req.searchRenderingAttribute("gpx")) { + float widthF = rc.getComplexValue(req, req.ALL.R_STROKE_WIDTH); + cachedTrackWidth.put(widthKey, widthF); + } + } + private int calculateHash(Object... o) { return Arrays.hashCode(o); } private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List selectedGPXFiles, - DrawSettings settings) { + DrawSettings settings) { if (tileBox.getZoom() >= START_ZOOM) { // request to load for (SelectedGpxFile g : selectedGPXFiles) { @@ -368,11 +348,11 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM paintTextIcon.getTextBounds(nm, 0, nm.length(), bounds); int nmWidth = bounds.width(); int nmHeight = bounds.height(); - RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), - y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), - x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), - y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity())); - canvas.drawRoundRect(rect, 0, 0, paintInnerRect); + RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), + y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), + x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), + y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity())); + canvas.drawRoundRect(rect, 0, 0, paintInnerRect); canvas.drawRoundRect(rect, 0, 0, paintOuterRect); // canvas.drawRect(rect, paintInnerRect); // canvas.drawRect(rect, paintOuterRect); @@ -477,7 +457,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM trackChartPoints.setSegmentColor(color); } paintGridCircle.setColor(color); - paintGridCircle.setAlpha(255); + paintGridCircle.setAlpha(255); QuadRect latLonBounds = tileBox.getLatLonBounds(); float r = 3 * tileBox.getDensity(); List xAxisPoints = trackChartPoints.getXAxisPoints(); @@ -531,8 +511,13 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox, - List selectedGPXFiles, DrawSettings settings) { - + List selectedGPXFiles, DrawSettings settings) { + for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) { + String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get()); + if (!cachedTrackWidth.containsKey(width)) { + cachedTrackWidth.put(width, null); + } + } SelectedGpxFile currentTrack = null; for (SelectedGpxFile g : selectedGPXFiles) { if (g.isShowCurrentTrack()) { @@ -550,10 +535,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM RotatedTileBox tileBox, DrawSettings settings) { List segments = selectedGpxFile.getPointsToDisplay(); for (TrkSegment ts : segments) { - String width = selectedGpxFile.getGpxFile().getWidth(null); - if (!cachedWidth.containsKey(width)) { - cachedWidth.put(width, null); - } + String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get()); int color = selectedGpxFile.getGpxFile().getColor(0); if (currentTrack) { color = currentTrackColor; From 5dc3a5a484d313bee354d5621b4b6f6b048fd816 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 26 Jun 2020 18:44:49 +0300 Subject: [PATCH 03/16] Add support for custom gpx width --- .../src/net/osmand/plus/views/GPXLayer.java | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 8646c6effb..68e31dc4ca 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -20,11 +20,13 @@ import androidx.annotation.Nullable; import androidx.appcompat.content.res.AppCompatResources; import androidx.core.content.ContextCompat; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; import net.osmand.Location; +import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; @@ -54,6 +56,8 @@ import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -66,6 +70,8 @@ import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR; public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IMoveObjectProvider, MapTextProvider { + private static final Log log = PlatformUtil.getLog(GPXLayer.class); + private static final double TOUCH_RADIUS_MULTIPLIER = 1.5; private static final int START_ZOOM = 7; @@ -73,10 +79,11 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private Paint paint; private Paint shadowPaint; + private Paint paintIcon; private int cachedHash; private int cachedColor; + private float defaultTrackWidth; private Map cachedTrackWidth = new HashMap<>(); - private Paint paintIcon; private int currentTrackColor; private LayerDrawable selectedPoint; @@ -209,6 +216,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM if (hash != cachedHash) { cachedHash = hash; cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track); + defaultTrackWidth = 7 * view.getDensity(); if (rrs != null) { RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); @@ -252,8 +260,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM searchTrackWidth(key, rrs, req, rc); } } else { - System.err.println("Rendering attribute gpx is not found !"); - paint.setStrokeWidth(7 * view.getDensity()); + log.error("Rendering attribute gpx is not found !"); + for (String key : cachedTrackWidth.keySet()) { + cachedTrackWidth.put(key, defaultTrackWidth); + } } } } @@ -266,13 +276,24 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } private void searchTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) { - RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR); - if (ctWidth != null) { - req.setStringFilter(ctWidth, widthKey); - } - if (req.searchRenderingAttribute("gpx")) { - float widthF = rc.getComplexValue(req, req.ALL.R_STROKE_WIDTH); - cachedTrackWidth.put(widthKey, widthF); + if (!Algorithms.isEmpty(widthKey) && Algorithms.isInt(widthKey)) { + try { + int widthDp = Integer.parseInt(widthKey); + float widthF = AndroidUtils.dpToPx(view.getApplication(), widthDp); + cachedTrackWidth.put(widthKey, widthF); + } catch (NumberFormatException e) { + log.error(e.getMessage(), e); + cachedTrackWidth.put(widthKey, defaultTrackWidth); + } + } else { + RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR); + if (ctWidth != null) { + req.setStringFilter(ctWidth, widthKey); + } + if (req.searchRenderingAttribute("gpx")) { + float widthF = rc.getComplexValue(req, req.ALL.R_STROKE_WIDTH); + cachedTrackWidth.put(widthKey, widthF); + } } } From 08a8281a8ce84c34162f6bb6a9a310394b42778e Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 3 Jul 2020 14:10:20 +0300 Subject: [PATCH 04/16] Add show arrows and show start finish gpx params --- .../main/java/net/osmand/GPXUtilities.java | 24 +++++ OsmAnd/src/net/osmand/plus/GPXDatabase.java | 90 +++++++++++++++++-- OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 20 ++++- .../net/osmand/plus/GpxSelectionHelper.java | 14 +++ 4 files changed, 138 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 4b266588b8..ef54ed7edb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -160,6 +160,30 @@ public class GPXUtilities { getExtensionsToWrite().put("width", width); } + public boolean isShowArrows() { + String showArrows = null; + if (extensions != null) { + showArrows = extensions.get("showArrows"); + } + return Boolean.parseBoolean(showArrows); + } + + public void setShowArrows(boolean showArrows) { + getExtensionsToWrite().put("showArrows", String.valueOf(showArrows)); + } + + public boolean isShowStartFinish() { + String showStartFinish = null; + if (extensions != null) { + showStartFinish = extensions.get("showStartFinish"); + } + return Boolean.parseBoolean(showStartFinish); + } + + public void setShowStartFinish(boolean showStartFinish) { + getExtensionsToWrite().put("showStartFinish", String.valueOf(showStartFinish)); + } + public Map getExtensionsToWrite() { if (extensions == null) { extensions = new LinkedHashMap<>(); diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index c1f1e220de..1595e2b3b5 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -57,6 +57,10 @@ public class GPXDatabase { private static final String GPX_COL_JOIN_SEGMENTS = "joinSegments"; + private static final String GPX_COL_SHOW_ARROWS = "showArrows"; + + private static final String GPX_COL_SHOW_START_FINISH = "showStartFinish"; + private static final String GPX_COL_WIDTH = "width"; public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1; @@ -93,6 +97,8 @@ public class GPXDatabase { GPX_COL_WPT_CATEGORY_NAMES + " TEXT, " + GPX_COL_SHOW_AS_MARKERS + " int, " + // 1 = true, 0 = false GPX_COL_JOIN_SEGMENTS + " int, " + // 1 = true, 0 = false + GPX_COL_SHOW_ARROWS + " int, " + // 1 = true, 0 = false + GPX_COL_SHOW_START_FINISH + " int, " + // 1 = true, 0 = false GPX_COL_WIDTH + " TEXT);"; private static final String GPX_TABLE_SELECT = "SELECT " + @@ -122,6 +128,8 @@ public class GPXDatabase { GPX_COL_WPT_CATEGORY_NAMES + ", " + GPX_COL_SHOW_AS_MARKERS + ", " + GPX_COL_JOIN_SEGMENTS + ", " + + GPX_COL_SHOW_ARROWS + ", " + + GPX_COL_SHOW_START_FINISH + ", " + GPX_COL_WIDTH + " FROM " + GPX_TABLE_NAME; @@ -160,6 +168,8 @@ public class GPXDatabase { private boolean apiImported; private boolean showAsMarkers; private boolean joinSegments; + private boolean showArrows; + private boolean showStartFinish; public GpxDataItem(File file, GPXTrackAnalysis analysis) { this.file = file; @@ -228,6 +238,22 @@ public class GPXDatabase { this.joinSegments = joinSegments; } + public boolean isShowArrows() { + return showArrows; + } + + public void setShowArrows(boolean showArrows) { + this.showArrows = showArrows; + } + + public boolean isShowStartFinish() { + return showStartFinish; + } + + public void setShowStartFinish(boolean showStartFinish) { + this.showStartFinish = showStartFinish; + } + @Override public int hashCode() { return file != null ? file.hashCode() : 0; @@ -357,7 +383,14 @@ public class GPXDatabase { "WHERE " + GPX_COL_JOIN_SEGMENTS + " IS NULL", new Object[]{0}); } if (oldVersion < 11) { + db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SHOW_ARROWS + " int"); + db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SHOW_START_FINISH + " int"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WIDTH + " TEXT"); + + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " + + "WHERE " + GPX_COL_SHOW_ARROWS + " IS NULL", new Object[]{0}); + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " + + "WHERE " + GPX_COL_SHOW_START_FINISH + " IS NULL", new Object[]{0}); } db.execSQL("CREATE INDEX IF NOT EXISTS " + GPX_INDEX_NAME_DIR + " ON " + GPX_TABLE_NAME + " (" + GPX_COL_NAME + ", " + GPX_COL_DIR + ");"); } @@ -421,15 +454,51 @@ public class GPXDatabase { return false; } + public boolean updateShowArrows(GpxDataItem item, boolean showArrows) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + String fileName = getFileName(item.file); + String fileDir = getFileDir(item.file); + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " + + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", + new Object[] {showArrows ? 1 : 0, fileName, fileDir}); + item.setShowArrows(showArrows); + } finally { + db.close(); + } + return true; + } + return false; + } + + public boolean updateShowStartFinish(GpxDataItem item, boolean showStartFinish) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + String fileName = getFileName(item.file); + String fileDir = getFileDir(item.file); + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " + + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", + new Object[] {showStartFinish ? 1 : 0, fileName, fileDir}); + item.setShowStartFinish(showStartFinish); + } finally { + db.close(); + } + return true; + } + return false; + } + public boolean updateWidth(GpxDataItem item, String width) { SQLiteConnection db = openConnection(false); - if (db != null){ + if (db != null) { try { String fileName = getFileName(item.file); String fileDir = getFileDir(item.file); db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_WIDTH + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", - new Object[] { width, fileName, fileDir }); + new Object[] {width, fileName, fileDir}); item.width = width; } finally { db.close(); @@ -553,12 +622,13 @@ public class GPXDatabase { } if (a != null) { db.execSQL( - "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime, a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown, a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints, color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0, - Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, item.width}); + Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, + item.joinSegments ? 1 : 0, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width}); } else { db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" + GPX_COL_NAME + ", " + @@ -570,9 +640,13 @@ public class GPXDatabase { GPX_COL_API_IMPORTED + ", " + GPX_COL_SHOW_AS_MARKERS + ", " + GPX_COL_JOIN_SEGMENTS + ", " + + GPX_COL_SHOW_ARROWS + ", " + + GPX_COL_SHOW_START_FINISH + ", " + GPX_COL_WIDTH + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, item.width}); + new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, + item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, + item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width}); } } @@ -653,7 +727,9 @@ public class GPXDatabase { String wptCategoryNames = query.getString(23); boolean showAsMarkers = query.getInt(24) == 1; boolean joinSegments = query.getInt(25) == 1; - String width = query.getString(26); + boolean showArrows = query.getInt(26) == 1; + boolean showStartFinish = query.getInt(27) == 1; + String width = query.getString(28); GPXTrackAnalysis a = new GPXTrackAnalysis(); a.totalDistance = totalDistance; @@ -695,6 +771,8 @@ public class GPXDatabase { item.apiImported = apiImported; item.showAsMarkers = showAsMarkers; item.joinSegments = joinSegments; + item.showArrows = showArrows; + item.showStartFinish = showStartFinish; item.width = width; return item; } diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index 6221e91f6f..c929348297 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -77,14 +77,26 @@ public class GpxDbHelper { return res; } - public boolean updateWidth(GpxDataItem item, String width) { - boolean res = db.updateWidth(item, width); + public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) { + boolean res = db.updateShowAsMarkers(item, showAsMarkers); putToCache(item); return res; } - public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) { - boolean res = db.updateShowAsMarkers(item, showAsMarkers); + public boolean updateShowArrows(GpxDataItem item, boolean showArrows) { + boolean res = db.updateShowArrows(item, showArrows); + putToCache(item); + return res; + } + + public boolean updateShowStartFinish(GpxDataItem item, boolean showStartFinish) { + boolean res = db.updateShowStartFinish(item, showStartFinish); + putToCache(item); + return res; + } + + public boolean updateWidth(GpxDataItem item, String width) { + boolean res = db.updateWidth(item, width); putToCache(item); return res; } diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 00a626ae6d..31f4755803 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -53,6 +53,8 @@ public class GpxSelectionHelper { private static final String COLOR = "color"; private static final String WIDTH = "width"; private static final String SELECTED_BY_USER = "selected_by_user"; + private static final String SHOW_ARROWS = "showArrows"; + private static final String SHOW_START_FINISH = "showStartFinish"; private OsmandApplication app; @NonNull @@ -516,6 +518,14 @@ public class GpxSelectionHelper { int clr = Algorithms.parseColor(obj.getString(COLOR)); gpx.setColor(clr); } + if (obj.has(SHOW_ARROWS)) { + boolean showArrows = obj.optBoolean(SHOW_ARROWS, false); + gpx.setShowArrows(showArrows); + } + if (obj.has(SHOW_START_FINISH)) { + boolean showStartFinish = obj.optBoolean(SHOW_START_FINISH, false); + gpx.setShowStartFinish(showStartFinish); + } if (obj.has(WIDTH)) { gpx.setWidth(obj.getString(WIDTH)); } @@ -561,6 +571,8 @@ public class GpxSelectionHelper { if (s.gpxFile.getWidth(null) != null) { obj.put(WIDTH, s.gpxFile.getWidth(null)); } + obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows()); + obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish()); } obj.put(SELECTED_BY_USER, s.selectedByUser); } catch (JSONException e) { @@ -616,6 +628,8 @@ public class GpxSelectionHelper { if (dataItem.getWidth() != null) { gpx.setWidth(dataItem.getWidth()); } + gpx.setShowArrows(dataItem.isShowArrows()); + gpx.setShowStartFinish(dataItem.isShowStartFinish()); sf.setJoinSegments(dataItem.isJoinSegments()); } sf.setGpxFile(gpx, app); From 94919b25a5c51c583d8f0d19500b6018ad3d728c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 6 Jul 2020 11:41:18 +0300 Subject: [PATCH 05/16] Fix merge conflicts --- .../osmand/plus/dialogs/ConfigureMapMenu.java | 2 -- .../plus/dialogs/MapLayerMenuListener.java | 19 ------------------- 2 files changed, 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 46221ce063..726475cdc7 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -47,7 +47,6 @@ import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.transport.TransportLinesMenu; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.corenative.NativeCoreContext; -import net.osmand.plus.wikipedia.WikipediaPoiMenu; import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRuleStorageProperties; import net.osmand.render.RenderingRulesStorage; @@ -173,7 +172,6 @@ public class ConfigureMapMenu { final OsmandApplication app = activity.getMyApplication(); final OsmandSettings settings = app.getSettings(); final int selectedProfileColorRes = settings.getApplicationMode().getIconColorInfo().getColor(nightMode); - final int selectedProfileColor = ContextCompat.getColor(app, selectedProfileColorRes); MapLayerMenuListener l = new MapLayerMenuListener(activity, adapter); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(SHOW_CATEGORY_ID) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java b/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java index d369ac0ea2..91e55e1d73 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java @@ -8,7 +8,6 @@ import android.widget.CompoundButton; import androidx.appcompat.app.AlertDialog; -import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities.GPXFile; import net.osmand.plus.ContextMenuAdapter; @@ -22,13 +21,11 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.PluginActivity; -import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.transport.TransportLinesMenu; -import net.osmand.plus.wikipedia.WikipediaPoiMenu; import net.osmand.util.Algorithms; import java.io.File; @@ -77,10 +74,6 @@ final class MapLayerMenuListener extends OnRowItemClick { } else if (itemId == R.string.layer_gpx_layer && menuAdapter.getItem(pos).getSelected()) { showGpxSelectionDialog(adapter, adapter.getItem(pos)); return false; - } else if (itemId == R.string.shared_string_wikipedia) { - mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.WIKIPEDIA, - AndroidUtils.getCenterViewCoordinates(view)); - return false; } else if (itemId == R.string.rendering_category_transport) { final ContextMenuItem item = adapter.getItem(pos); TransportLinesMenu.showTransportsDialog(mapActivity, new CallbackWithObject() { @@ -144,18 +137,6 @@ final class MapLayerMenuListener extends OnRowItemClick { } else { showGpxSelectionDialog(adapter, adapter.getItem(pos)); } - } else if (itemId == R.string.shared_string_wikipedia) { - WikipediaPoiMenu.toggleWikipediaPoi(mapActivity, isChecked, new CallbackWithObject() { - @Override - public boolean processResult(Boolean selected) { - item.setSelected(selected); - item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - item.setDescription(selected ? - WikipediaPoiMenu.getLanguagesSummary(mapActivity.getMyApplication()) : null); - adapter.notifyDataSetChanged(); - return true; - } - }); } else if (itemId == R.string.rendering_category_transport) { boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication()); TransportLinesMenu.toggleTransportLines(mapActivity, !selected, new CallbackWithObject() { From a0c83cf8b527645ce98d562a276c1c0708649403 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 6 Jul 2020 12:30:55 +0300 Subject: [PATCH 06/16] Add track gradient scale types --- .../main/java/net/osmand/GPXUtilities.java | 118 +++++++++++------- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 83 +++++++++++- OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 9 +- .../net/osmand/plus/GpxSelectionHelper.java | 11 ++ 4 files changed, 171 insertions(+), 50 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index ef54ed7edb..077e249ac8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -42,7 +42,9 @@ import java.util.Stack; import java.util.TimeZone; public class GPXUtilities { + public final static Log log = PlatformUtil.getLog(GPXUtilities.class); + private static final String ICON_NAME_EXTENSION = "icon"; private static final String DEFAULT_ICON_NAME = "special_star"; private static final String BACKGROUND_TYPE_EXTENSION = "background"; @@ -115,6 +117,13 @@ public class GPXUtilities { return extensions; } + public Map getExtensionsToWrite() { + if (extensions == null) { + extensions = new LinkedHashMap<>(); + } + return extensions; + } + public GPXExtensionsWriter getExtensionsWriter() { return extensionsWriter; } @@ -148,50 +157,7 @@ public class GPXUtilities { getExtensionsToWrite().remove("color"); } - public String getWidth(String defWidth) { - String widthValue = null; - if (extensions != null) { - widthValue = extensions.get("width"); - } - return widthValue != null ? widthValue : defWidth; - } - - public void setWidth(String width) { - getExtensionsToWrite().put("width", width); - } - - public boolean isShowArrows() { - String showArrows = null; - if (extensions != null) { - showArrows = extensions.get("showArrows"); - } - return Boolean.parseBoolean(showArrows); - } - - public void setShowArrows(boolean showArrows) { - getExtensionsToWrite().put("showArrows", String.valueOf(showArrows)); - } - - public boolean isShowStartFinish() { - String showStartFinish = null; - if (extensions != null) { - showStartFinish = extensions.get("showStartFinish"); - } - return Boolean.parseBoolean(showStartFinish); - } - - public void setShowStartFinish(boolean showStartFinish) { - getExtensionsToWrite().put("showStartFinish", String.valueOf(showStartFinish)); - } - - public Map getExtensionsToWrite() { - if (extensions == null) { - extensions = new LinkedHashMap<>(); - } - return extensions; - } - - private int parseColor(String colorString, int defColor) { + protected int parseColor(String colorString, int defColor) { if (!Algorithms.isEmpty(colorString)) { if (colorString.charAt(0) == '#') { long color = Long.parseLong(colorString.substring(1), 16); @@ -1547,6 +1513,70 @@ public class GPXUtilities { } return new QuadRect(left, top, right, bottom); } + + public enum GradientScaleType { + SPEED("gradientSpeedColor"), + ALTITUDE("gradientAltitudeColor"), + SLOPE("gradientSlopeColor"); + + private String typeName; + + GradientScaleType(String typeName) { + this.typeName = typeName; + } + + public String getTypeName() { + return typeName; + } + } + + public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleSpeedColor) { + getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleSpeedColor)); + } + + public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) { + String clrValue = null; + if (extensions != null) { + clrValue = extensions.get(gradientScaleType.getTypeName()); + } + return parseColor(clrValue, defColor); + } + + public String getWidth(String defWidth) { + String widthValue = null; + if (extensions != null) { + widthValue = extensions.get("width"); + } + return widthValue != null ? widthValue : defWidth; + } + + public void setWidth(String width) { + getExtensionsToWrite().put("width", width); + } + + public boolean isShowArrows() { + String showArrows = null; + if (extensions != null) { + showArrows = extensions.get("showArrows"); + } + return Boolean.parseBoolean(showArrows); + } + + public void setShowArrows(boolean showArrows) { + getExtensionsToWrite().put("showArrows", String.valueOf(showArrows)); + } + + public boolean isShowStartFinish() { + String showStartFinish = null; + if (extensions != null) { + showStartFinish = extensions.get("showStartFinish"); + } + return Boolean.parseBoolean(showStartFinish); + } + + public void setShowStartFinish(boolean showStartFinish) { + getExtensionsToWrite().put("showStartFinish", String.valueOf(showStartFinish)); + } } public static String asString(GPXFile file) { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 1595e2b3b5..b45e5582a2 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -3,6 +3,7 @@ package net.osmand.plus; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; @@ -63,6 +64,12 @@ public class GPXDatabase { private static final String GPX_COL_WIDTH = "width"; + private static final String GPX_COL_GRADIENT_SPEED_COLOR = "gradientSpeedColor"; + + private static final String GPX_COL_GRADIENT_ALTITUDE_COLOR = "gradientAltitudeColor"; + + private static final String GPX_COL_GRADIENT_SLOPE_COLOR = "gradientSlopeColor"; + public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1; public static final int GPX_SPLIT_TYPE_DISTANCE = 1; public static final int GPX_SPLIT_TYPE_TIME = 2; @@ -99,7 +106,10 @@ public class GPXDatabase { GPX_COL_JOIN_SEGMENTS + " int, " + // 1 = true, 0 = false GPX_COL_SHOW_ARROWS + " int, " + // 1 = true, 0 = false GPX_COL_SHOW_START_FINISH + " int, " + // 1 = true, 0 = false - GPX_COL_WIDTH + " TEXT);"; + GPX_COL_WIDTH + " TEXT, " + + GPX_COL_GRADIENT_SPEED_COLOR + " TEXT, " + + GPX_COL_GRADIENT_ALTITUDE_COLOR + " TEXT, " + + GPX_COL_GRADIENT_SLOPE_COLOR + " TEXT);"; private static final String GPX_TABLE_SELECT = "SELECT " + GPX_COL_NAME + ", " + @@ -129,8 +139,10 @@ public class GPXDatabase { GPX_COL_SHOW_AS_MARKERS + ", " + GPX_COL_JOIN_SEGMENTS + ", " + GPX_COL_SHOW_ARROWS + ", " + - GPX_COL_SHOW_START_FINISH + ", " + - GPX_COL_WIDTH + + GPX_COL_WIDTH + ", " + + GPX_COL_GRADIENT_SPEED_COLOR + ", " + + GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " + + GPX_COL_GRADIENT_SLOPE_COLOR + " FROM " + GPX_TABLE_NAME; private static final String GPX_TABLE_UPDATE_ANALYSIS = "UPDATE " + @@ -162,6 +174,9 @@ public class GPXDatabase { private GPXTrackAnalysis analysis; private String width; private int color; + private int gradientSpeedColor; + private int gradientAltitudeColor; + private int gradientSlopeColor; private int splitType; private double splitInterval; private long fileLastModifiedTime; @@ -194,6 +209,30 @@ public class GPXDatabase { return color; } + public int getGradientSpeedColor() { + return gradientSpeedColor; + } + + public void setGradientSpeedColor(int gradientSpeedColor) { + this.gradientSpeedColor = gradientSpeedColor; + } + + public int getGradientAltitudeColor() { + return gradientAltitudeColor; + } + + public void setGradientAltitudeColor(int gradientAltitudeColor) { + this.gradientAltitudeColor = gradientAltitudeColor; + } + + public int getGradientSlopeColor() { + return gradientSlopeColor; + } + + public void setGradientSlopeColor(int gradientSlopeColor) { + this.gradientSlopeColor = gradientSlopeColor; + } + public String getWidth() { return width; } @@ -314,7 +353,7 @@ public class GPXDatabase { if (oldVersion < 3) { db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_FILE_LAST_MODIFIED_TIME + " long"); } - + if (oldVersion < 4) { db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double"); @@ -386,6 +425,9 @@ public class GPXDatabase { db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SHOW_ARROWS + " int"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SHOW_START_FINISH + " int"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WIDTH + " TEXT"); + db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SPEED_COLOR + " TEXT"); + db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_ALTITUDE_COLOR + " TEXT"); + db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SLOPE_COLOR + " TEXT"); db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " + "WHERE " + GPX_COL_SHOW_ARROWS + " IS NULL", new Object[]{0}); @@ -454,6 +496,34 @@ public class GPXDatabase { return false; } + public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int gradientScaleColor) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + String fileName = getFileName(item.file); + String fileDir = getFileDir(item.file); + String columnName = null; + if (GradientScaleType.SPEED == gradientScaleType) { + columnName = GPX_COL_GRADIENT_SPEED_COLOR; + item.gradientSpeedColor = gradientScaleColor; + } else if (GradientScaleType.ALTITUDE == gradientScaleType) { + columnName = GPX_COL_GRADIENT_ALTITUDE_COLOR; + item.gradientAltitudeColor = gradientScaleColor; + } else if (GradientScaleType.SLOPE == gradientScaleType) { + columnName = GPX_COL_GRADIENT_SLOPE_COLOR; + item.gradientSlopeColor = gradientScaleColor; + } + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + columnName + " = ? " + + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", + new Object[] {(gradientScaleColor == 0 ? "" : Algorithms.colorToString(gradientScaleColor)), fileName, fileDir}); + } finally { + db.close(); + } + return true; + } + return false; + } + public boolean updateShowArrows(GpxDataItem item, boolean showArrows) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -642,7 +712,10 @@ public class GPXDatabase { GPX_COL_JOIN_SEGMENTS + ", " + GPX_COL_SHOW_ARROWS + ", " + GPX_COL_SHOW_START_FINISH + ", " + - GPX_COL_WIDTH + + GPX_COL_WIDTH + ", " + + GPX_COL_GRADIENT_SPEED_COLOR + ", " + + GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " + + GPX_COL_GRADIENT_SLOPE_COLOR + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index c929348297..cb011336bb 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -8,6 +8,7 @@ import androidx.annotation.Nullable; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; @@ -77,6 +78,12 @@ public class GpxDbHelper { return res; } + public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int color) { + boolean res = db.updateGradientScaleColor(item, gradientScaleType, color); + putToCache(item); + return res; + } + public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) { boolean res = db.updateShowAsMarkers(item, showAsMarkers); putToCache(item); @@ -107,7 +114,7 @@ public class GpxDbHelper { return res; } - public boolean updateJoinSegments(@NonNull GpxDataItem item, boolean joinSegments) { + public boolean updateJoinSegments(@NonNull GpxDataItem item, boolean joinSegments) { boolean res = db.updateJoinSegments(item, joinSegments); putToCache(item); return res; diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 31f4755803..8d689978a1 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.Route; import net.osmand.GPXUtilities.Track; @@ -518,6 +519,7 @@ public class GpxSelectionHelper { int clr = Algorithms.parseColor(obj.getString(COLOR)); gpx.setColor(clr); } + loadGpxScaleTypes(obj, gpx); if (obj.has(SHOW_ARROWS)) { boolean showArrows = obj.optBoolean(SHOW_ARROWS, false); gpx.setShowArrows(showArrows); @@ -555,6 +557,15 @@ public class GpxSelectionHelper { } } + private void loadGpxScaleTypes(JSONObject obj, GPXFile gpx) throws JSONException { + for (GradientScaleType scaleType : GradientScaleType.values()) { + if (obj.has(scaleType.getTypeName())) { + int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName())); + gpx.setGradientScaleColor(scaleType, clr); + } + } + } + private void saveCurrentSelections() { JSONArray ar = new JSONArray(); for (SelectedGpxFile s : selectedGPXFiles) { From 15e26432f8a87f1dddff7e599d4916dba6af127c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 6 Jul 2020 15:01:47 +0300 Subject: [PATCH 07/16] Add selected gradient scale type for track --- .../main/java/net/osmand/GPXUtilities.java | 18 +++++ OsmAnd/src/net/osmand/plus/GPXDatabase.java | 80 ++++++++++++++++--- OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 6 ++ .../net/osmand/plus/GpxSelectionHelper.java | 36 ++++++--- 4 files changed, 115 insertions(+), 25 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 077e249ac8..c1ad5d5cef 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1542,6 +1542,24 @@ public class GPXUtilities { return parseColor(clrValue, defColor); } + public void setGradientScaleType(GradientScaleType gradientScaleType) { + getExtensionsToWrite().put("gradientScaleType", gradientScaleType != null ? gradientScaleType.name() : null); + } + + public GradientScaleType getGradientScaleType() { + if (extensions != null) { + String gradientScaleTypeName = extensions.get("gradientScaleType"); + if (!Algorithms.isEmpty(gradientScaleTypeName)) { + try { + return GradientScaleType.valueOf(gradientScaleTypeName); + } catch (IllegalArgumentException e) { + log.error("Error reading gradientScaleType", e); + } + } + } + return null; + } + public String getWidth(String defWidth) { String widthValue = null; if (extensions != null) { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index b45e5582a2..e5bd1c3ad0 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -70,6 +70,8 @@ public class GPXDatabase { private static final String GPX_COL_GRADIENT_SLOPE_COLOR = "gradientSlopeColor"; + private static final String GPX_COL_GRADIENT_SCALE_TYPE = "gradientScaleType"; + public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1; public static final int GPX_SPLIT_TYPE_DISTANCE = 1; public static final int GPX_SPLIT_TYPE_TIME = 2; @@ -109,7 +111,8 @@ public class GPXDatabase { GPX_COL_WIDTH + " TEXT, " + GPX_COL_GRADIENT_SPEED_COLOR + " TEXT, " + GPX_COL_GRADIENT_ALTITUDE_COLOR + " TEXT, " + - GPX_COL_GRADIENT_SLOPE_COLOR + " TEXT);"; + GPX_COL_GRADIENT_SLOPE_COLOR + " TEXT, " + + GPX_COL_GRADIENT_SCALE_TYPE+ " TEXT);"; private static final String GPX_TABLE_SELECT = "SELECT " + GPX_COL_NAME + ", " + @@ -142,8 +145,9 @@ public class GPXDatabase { GPX_COL_WIDTH + ", " + GPX_COL_GRADIENT_SPEED_COLOR + ", " + GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " + - GPX_COL_GRADIENT_SLOPE_COLOR + - " FROM " + GPX_TABLE_NAME; + GPX_COL_GRADIENT_SLOPE_COLOR + ", " + + GPX_COL_GRADIENT_SCALE_TYPE + + " FROM " + GPX_TABLE_NAME; private static final String GPX_TABLE_UPDATE_ANALYSIS = "UPDATE " + GPX_TABLE_NAME + " SET " + @@ -173,6 +177,7 @@ public class GPXDatabase { private File file; private GPXTrackAnalysis analysis; private String width; + private GradientScaleType gradientScaleType; private int color; private int gradientSpeedColor; private int gradientAltitudeColor; @@ -209,6 +214,14 @@ public class GPXDatabase { return color; } + public GradientScaleType getGradientScaleType() { + return gradientScaleType; + } + + public void setGradientScaleType(GradientScaleType gradientScaleType) { + this.gradientScaleType = gradientScaleType; + } + public int getGradientSpeedColor() { return gradientSpeedColor; } @@ -428,6 +441,7 @@ public class GPXDatabase { db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SPEED_COLOR + " TEXT"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_ALTITUDE_COLOR + " TEXT"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SLOPE_COLOR + " TEXT"); + db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SCALE_TYPE + " TEXT"); db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " + "WHERE " + GPX_COL_SHOW_ARROWS + " IS NULL", new Object[]{0}); @@ -524,6 +538,24 @@ public class GPXDatabase { return false; } + public boolean updateGradientScaleType(@NonNull GpxDataItem item, GradientScaleType gradientScaleType) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + String fileName = getFileName(item.file); + String fileDir = getFileDir(item.file); + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_GRADIENT_SCALE_TYPE + " = ? " + + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", + new Object[] {(gradientScaleType == null ? "" : gradientScaleType.name()), fileName, fileDir}); + item.gradientScaleType = gradientScaleType; + } finally { + db.close(); + } + return true; + } + return false; + } + public boolean updateShowArrows(GpxDataItem item, boolean showArrows) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -690,15 +722,17 @@ public class GPXDatabase { } else { color = Algorithms.colorToString(item.color); } + String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.name() : null; if (a != null) { db.execSQL( - "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime, a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown, a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints, color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0, Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, - item.joinSegments ? 1 : 0, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width}); + item.joinSegments ? 1 : 0, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width, + item.gradientSpeedColor, item.gradientAltitudeColor, item.gradientSlopeColor, gradientScaleType}); } else { db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" + GPX_COL_NAME + ", " + @@ -715,11 +749,13 @@ public class GPXDatabase { GPX_COL_WIDTH + ", " + GPX_COL_GRADIENT_SPEED_COLOR + ", " + GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " + - GPX_COL_GRADIENT_SLOPE_COLOR + - ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + GPX_COL_GRADIENT_SLOPE_COLOR + ", " + + GPX_COL_GRADIENT_SCALE_TYPE + + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, - item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width}); + item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width, + item.gradientSpeedColor, item.gradientAltitudeColor, item.gradientSlopeColor, gradientScaleType}); } } @@ -803,6 +839,10 @@ public class GPXDatabase { boolean showArrows = query.getInt(26) == 1; boolean showStartFinish = query.getInt(27) == 1; String width = query.getString(28); + String gradientSpeedColor = query.getString(29); + String gradientAltitudeColor = query.getString(30); + String gradientSlopeColor = query.getString(31); + String gradientScaleType = query.getString(32); GPXTrackAnalysis a = new GPXTrackAnalysis(); a.totalDistance = totalDistance; @@ -833,11 +873,7 @@ public class GPXDatabase { dir = context.getAppPath(IndexConstants.GPX_INDEX_DIR); } GpxDataItem item = new GpxDataItem(new File(dir, fileName), a); - try { - item.color = Algorithms.isEmpty(color) ? 0 : Algorithms.parseColor(color); - } catch (IllegalArgumentException e) { - item.color = 0; - } + item.color = parseColor(color); item.fileLastModifiedTime = fileLastModifiedTime; item.splitType = splitType; item.splitInterval = splitInterval; @@ -847,9 +883,27 @@ public class GPXDatabase { item.showArrows = showArrows; item.showStartFinish = showStartFinish; item.width = width; + item.gradientSpeedColor = parseColor(gradientSpeedColor); + item.gradientAltitudeColor = parseColor(gradientAltitudeColor); + item.gradientSlopeColor = parseColor(gradientSlopeColor); + + try { + item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType); + } catch (IllegalArgumentException e) { + item.gradientScaleType = null; + } + return item; } + private int parseColor(String color) { + try { + return Algorithms.isEmpty(color) ? 0 : Algorithms.parseColor(color); + } catch (IllegalArgumentException e) { + return 0; + } + } + @NonNull public List getItems() { List items = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index cb011336bb..0762982a33 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -84,6 +84,12 @@ public class GpxDbHelper { return res; } + public boolean updateGradientScaleType(@NonNull GpxDataItem item, @Nullable GradientScaleType gradientScaleType) { + boolean res = db.updateGradientScaleType(item, gradientScaleType); + putToCache(item); + return res; + } + public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) { boolean res = db.updateShowAsMarkers(item, showAsMarkers); putToCache(item); diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 8d689978a1..3959318853 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -55,6 +55,7 @@ public class GpxSelectionHelper { private static final String WIDTH = "width"; private static final String SELECTED_BY_USER = "selected_by_user"; private static final String SHOW_ARROWS = "showArrows"; + private static final String GRADIENT_SCALE_TYPE = "gradientScaleType"; private static final String SHOW_START_FINISH = "showStartFinish"; private OsmandApplication app; @@ -519,11 +520,22 @@ public class GpxSelectionHelper { int clr = Algorithms.parseColor(obj.getString(COLOR)); gpx.setColor(clr); } - loadGpxScaleTypes(obj, gpx); + for (GradientScaleType scaleType : GradientScaleType.values()) { + if (obj.has(scaleType.getTypeName())) { + int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName())); + gpx.setGradientScaleColor(scaleType, clr); + } + } if (obj.has(SHOW_ARROWS)) { boolean showArrows = obj.optBoolean(SHOW_ARROWS, false); gpx.setShowArrows(showArrows); } + if (obj.has(GRADIENT_SCALE_TYPE)) { + String gradientScaleTypeName = obj.optString(GRADIENT_SCALE_TYPE); + if (!Algorithms.isEmpty(gradientScaleTypeName)) { + gpx.setGradientScaleType(GradientScaleType.valueOf(gradientScaleTypeName)); + } + } if (obj.has(SHOW_START_FINISH)) { boolean showStartFinish = obj.optBoolean(SHOW_START_FINISH, false); gpx.setShowStartFinish(showStartFinish); @@ -557,15 +569,6 @@ public class GpxSelectionHelper { } } - private void loadGpxScaleTypes(JSONObject obj, GPXFile gpx) throws JSONException { - for (GradientScaleType scaleType : GradientScaleType.values()) { - if (obj.has(scaleType.getTypeName())) { - int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName())); - gpx.setGradientScaleColor(scaleType, clr); - } - } - } - private void saveCurrentSelections() { JSONArray ar = new JSONArray(); for (SelectedGpxFile s : selectedGPXFiles) { @@ -582,8 +585,17 @@ public class GpxSelectionHelper { if (s.gpxFile.getWidth(null) != null) { obj.put(WIDTH, s.gpxFile.getWidth(null)); } + if (s.gpxFile.getGradientScaleType() != null) { + obj.put(GRADIENT_SCALE_TYPE, s.gpxFile.getGradientScaleType()); + } obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows()); obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish()); + for (GradientScaleType scaleType : GradientScaleType.values()) { + int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType, 0); + if (gradientScaleColor != 0) { + obj.put(scaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor)); + } + } } obj.put(SELECTED_BY_USER, s.selectedByUser); } catch (JSONException e) { @@ -1059,13 +1071,13 @@ public class GpxSelectionHelper { @Override protected void onProgressUpdate(Void... values) { - gpxTaskListener.gpxSelectionInProgress(); + gpxTaskListener.gpxSelectionInProgress(); } @Override protected void onPreExecute() { collectSelectedItems(); - gpxTaskListener.gpxSelectionStarted(); + gpxTaskListener.gpxSelectionStarted(); } private void collectSelectedItems() { From 3bab88942a8d9fdb872e158c449b1fc1131a803d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 6 Jul 2020 17:02:25 +0300 Subject: [PATCH 08/16] Fix track gradient scale color --- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 1 + OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index e5bd1c3ad0..5633730e67 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -142,6 +142,7 @@ public class GPXDatabase { GPX_COL_SHOW_AS_MARKERS + ", " + GPX_COL_JOIN_SEGMENTS + ", " + GPX_COL_SHOW_ARROWS + ", " + + GPX_COL_SHOW_START_FINISH + ", " + GPX_COL_WIDTH + ", " + GPX_COL_GRADIENT_SPEED_COLOR + ", " + GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " + diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 3959318853..8a288d96b5 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -648,6 +648,18 @@ public class GpxSelectionHelper { if (dataItem.getColor() != 0) { gpx.setColor(dataItem.getColor()); } + if (dataItem.getGradientSpeedColor() != 0) { + gpx.setGradientScaleColor(GradientScaleType.SPEED, dataItem.getGradientSpeedColor()); + } + if (dataItem.getGradientAltitudeColor() != 0) { + gpx.setGradientScaleColor(GradientScaleType.ALTITUDE, dataItem.getGradientAltitudeColor()); + } + if (dataItem.getGradientSlopeColor() != 0) { + gpx.setGradientScaleColor(GradientScaleType.SLOPE, dataItem.getGradientSlopeColor()); + } + if (dataItem.getGradientScaleType() != null) { + gpx.setGradientScaleType(dataItem.getGradientScaleType()); + } if (dataItem.getWidth() != null) { gpx.setWidth(dataItem.getWidth()); } From 03951910fde453dad0873dc1a6821b3b631948a1 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 6 Jul 2020 21:07:48 +0300 Subject: [PATCH 09/16] Add track start and finish icons to map layer --- .../src/net/osmand/plus/views/GPXLayer.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 68e31dc4ca..4073194ea4 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -10,6 +10,7 @@ import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffColorFilter; import android.graphics.Rect; import android.graphics.RectF; +import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.os.AsyncTask; import android.util.Pair; @@ -41,6 +42,7 @@ import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; @@ -82,10 +84,12 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private Paint paintIcon; private int cachedHash; private int cachedColor; + private int currentTrackColor; private float defaultTrackWidth; private Map cachedTrackWidth = new HashMap<>(); - private int currentTrackColor; + private Drawable startPointIcon; + private Drawable finishPointIcon; private LayerDrawable selectedPoint; private TrackChartPoints trackChartPoints; @@ -167,6 +171,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM paintIcon = new Paint(); selectedPoint = (LayerDrawable) AppCompatResources.getDrawable(view.getContext(), R.drawable.map_location_default); + UiUtilities iconsCache = view.getApplication().getUIUtilities(); + startPointIcon = iconsCache.getIcon(R.drawable.map_track_point_start); + finishPointIcon = iconsCache.getIcon(R.drawable.map_track_point_finish); + contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class); visitedColor = ContextCompat.getColor(view.getApplication(), R.color.color_ok); @@ -201,6 +209,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } drawSelectedFilesSplits(canvas, tileBox, selectedGPXFiles, settings); drawSelectedFilesPoints(canvas, tileBox, selectedGPXFiles); + drawSelectedFilesStartEndPoints(canvas, tileBox, selectedGPXFiles); } if (textLayer != null && isTextVisible()) { textLayer.putData(this, cache); @@ -383,6 +392,34 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } } + private void drawSelectedFilesStartEndPoints(Canvas canvas, RotatedTileBox tileBox, List selectedGPXFiles) { + if (tileBox.getZoom() >= START_ZOOM) { + for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) { + if (selectedGpxFile.getGpxFile().isShowStartFinish()) { + List segments = selectedGpxFile.getPointsToDisplay(); + TrkSegment endSegment = segments.get(segments.size() - 1); + + WptPt start = segments.get(0).points.get(0); + WptPt end = endSegment.points.get(endSegment.points.size() - 1); + + drawPoint(canvas, tileBox, start, startPointIcon); + drawPoint(canvas, tileBox, end, finishPointIcon); + } + } + } + } + + private void drawPoint(Canvas canvas, RotatedTileBox tileBox, WptPt wptPt, Drawable icon) { + int pointX = (int) tileBox.getPixXFromLatLon(wptPt.lat, wptPt.lon); + int pointY = (int) tileBox.getPixYFromLatLon(wptPt.lat, wptPt.lon); + + icon.setBounds(pointX - icon.getIntrinsicWidth() / 2, + pointY - icon.getIntrinsicHeight() / 2, + pointX + icon.getIntrinsicWidth() / 2, + pointY + icon.getIntrinsicHeight() / 2); + icon.draw(canvas); + } + private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List selectedGPXFiles) { if (tileBox.getZoom() >= START_ZOOM) { float textScale = view.getSettings().TEXT_SCALE.get(); From 5f60f452c0678813699f4e1d72c26c0bbf4a5b09 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 7 Jul 2020 10:24:29 +0300 Subject: [PATCH 10/16] Change gradient parameters names --- .../src/main/java/net/osmand/GPXUtilities.java | 18 +++++++++--------- .../net/osmand/plus/GpxSelectionHelper.java | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index c1ad5d5cef..916e279160 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1515,9 +1515,9 @@ public class GPXUtilities { } public enum GradientScaleType { - SPEED("gradientSpeedColor"), - ALTITUDE("gradientAltitudeColor"), - SLOPE("gradientSlopeColor"); + SPEED("gradient_speed_color"), + ALTITUDE("gradient_altitude_color"), + SLOPE("gradient_slope_color"); private String typeName; @@ -1543,12 +1543,12 @@ public class GPXUtilities { } public void setGradientScaleType(GradientScaleType gradientScaleType) { - getExtensionsToWrite().put("gradientScaleType", gradientScaleType != null ? gradientScaleType.name() : null); + getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); } public GradientScaleType getGradientScaleType() { if (extensions != null) { - String gradientScaleTypeName = extensions.get("gradientScaleType"); + String gradientScaleTypeName = extensions.get("gradient_scale_type"); if (!Algorithms.isEmpty(gradientScaleTypeName)) { try { return GradientScaleType.valueOf(gradientScaleTypeName); @@ -1575,25 +1575,25 @@ public class GPXUtilities { public boolean isShowArrows() { String showArrows = null; if (extensions != null) { - showArrows = extensions.get("showArrows"); + showArrows = extensions.get("show_arrows"); } return Boolean.parseBoolean(showArrows); } public void setShowArrows(boolean showArrows) { - getExtensionsToWrite().put("showArrows", String.valueOf(showArrows)); + getExtensionsToWrite().put("show_arrows", String.valueOf(showArrows)); } public boolean isShowStartFinish() { String showStartFinish = null; if (extensions != null) { - showStartFinish = extensions.get("showStartFinish"); + showStartFinish = extensions.get("show_start_finish"); } return Boolean.parseBoolean(showStartFinish); } public void setShowStartFinish(boolean showStartFinish) { - getExtensionsToWrite().put("showStartFinish", String.valueOf(showStartFinish)); + getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish)); } } diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 8a288d96b5..07a183712d 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -54,9 +54,9 @@ public class GpxSelectionHelper { private static final String COLOR = "color"; private static final String WIDTH = "width"; private static final String SELECTED_BY_USER = "selected_by_user"; - private static final String SHOW_ARROWS = "showArrows"; - private static final String GRADIENT_SCALE_TYPE = "gradientScaleType"; - private static final String SHOW_START_FINISH = "showStartFinish"; + private static final String SHOW_ARROWS = "show_arrows"; + private static final String GRADIENT_SCALE_TYPE = "gradient_scale_type"; + private static final String SHOW_START_FINISH = "show_start_finish"; private OsmandApplication app; @NonNull From c18b5ba25c5b2ba9cf2b06d6db9c6571df42a844 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 7 Jul 2020 11:23:53 +0300 Subject: [PATCH 11/16] Fix gpx files import --- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 2 +- OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 5633730e67..58f8cdf27f 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -752,7 +752,7 @@ public class GPXDatabase { GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " + GPX_COL_GRADIENT_SLOPE_COLOR + ", " + GPX_COL_GRADIENT_SCALE_TYPE + - ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width, diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index fe33fa61d4..b5a9ee75e9 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -23,6 +23,7 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.WptPt; import net.osmand.IProgress; import net.osmand.IndexConstants; @@ -1018,6 +1019,13 @@ public class ImportHelper { File file = new File(gpxFile.path); if (!destinationExists) { GPXDatabase.GpxDataItem item = new GPXDatabase.GpxDataItem(file, gpxFile.getColor(0)); + item.setWidth(gpxFile.getWidth(null)); + item.setShowArrows(gpxFile.isShowArrows()); + item.setShowStartFinish(gpxFile.isShowStartFinish()); + item.setGradientScaleType(gpxFile.getGradientScaleType()); + item.setGradientSpeedColor(gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0)); + item.setGradientSlopeColor(gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0)); + item.setGradientAltitudeColor(gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0)); app.getGpxDbHelper().add(item); } else { GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file); From 2284de7055494e59606cb5e5eed1cf123bf3bcdd Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 7 Jul 2020 14:15:48 +0300 Subject: [PATCH 12/16] Load gpx split type from file --- .../main/java/net/osmand/GPXUtilities.java | 96 ++++++++++++++----- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 4 - OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 5 +- .../net/osmand/plus/GpxSelectionHelper.java | 7 +- .../net/osmand/plus/helpers/ImportHelper.java | 4 + .../TrackActivityFragmentAdapter.java | 16 ++-- 6 files changed, 93 insertions(+), 39 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 916e279160..762ed0deb8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1514,26 +1514,6 @@ public class GPXUtilities { return new QuadRect(left, top, right, bottom); } - public enum GradientScaleType { - SPEED("gradient_speed_color"), - ALTITUDE("gradient_altitude_color"), - SLOPE("gradient_slope_color"); - - private String typeName; - - GradientScaleType(String typeName) { - this.typeName = typeName; - } - - public String getTypeName() { - return typeName; - } - } - - public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleSpeedColor) { - getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleSpeedColor)); - } - public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) { String clrValue = null; if (extensions != null) { @@ -1542,8 +1522,8 @@ public class GPXUtilities { return parseColor(clrValue, defColor); } - public void setGradientScaleType(GradientScaleType gradientScaleType) { - getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); + public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleColor) { + getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor)); } public GradientScaleType getGradientScaleType() { @@ -1560,6 +1540,46 @@ public class GPXUtilities { return null; } + public void setGradientScaleType(GradientScaleType gradientScaleType) { + getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); + } + + public GpxSplitType getSplitType() { + if (extensions != null) { + String gradientScaleTypeName = extensions.get("split_type"); + if (!Algorithms.isEmpty(gradientScaleTypeName)) { + try { + return GpxSplitType.valueOf(gradientScaleTypeName); + } catch (IllegalArgumentException e) { + log.error("Error reading GpxSplitType", e); + } + } + } + return null; + } + + public void setSplitType(GpxSplitType gpxSplitType) { + getExtensionsToWrite().put("split_type", gpxSplitType != null ? gpxSplitType.name() : null); + } + + public double getSplitInterval() { + if (extensions != null) { + String splitIntervalStr = extensions.get("split_interval"); + if (!Algorithms.isEmpty(splitIntervalStr)) { + try { + return Double.parseDouble(splitIntervalStr); + } catch (NumberFormatException e) { + log.error("Error reading split_interval", e); + } + } + } + return 0; + } + + public void setSplitInterval(double splitInterval) { + getExtensionsToWrite().put("split_interval", String.valueOf(splitInterval)); + } + public String getWidth(String defWidth) { String widthValue = null; if (extensions != null) { @@ -1595,6 +1615,38 @@ public class GPXUtilities { public void setShowStartFinish(boolean showStartFinish) { getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish)); } + + public enum GradientScaleType { + SPEED("gradient_speed_color"), + ALTITUDE("gradient_altitude_color"), + SLOPE("gradient_slope_color"); + + private String typeName; + + GradientScaleType(String typeName) { + this.typeName = typeName; + } + + public String getTypeName() { + return typeName; + } + } + + public enum GpxSplitType { + NO_SPLIT(-1), + DISTANCE(1), + TIME(2); + + private int type; + + GpxSplitType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + } } public static String asString(GPXFile file) { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 58f8cdf27f..dd573eba54 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -72,10 +72,6 @@ public class GPXDatabase { private static final String GPX_COL_GRADIENT_SCALE_TYPE = "gradientScaleType"; - public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1; - public static final int GPX_SPLIT_TYPE_DISTANCE = 1; - public static final int GPX_SPLIT_TYPE_TIME = 2; - private static final String GPX_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GPX_TABLE_NAME + " (" + GPX_COL_NAME + " TEXT, " + GPX_COL_DIR + " TEXT, " + diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index 0762982a33..4f4c12c9a4 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -8,6 +8,7 @@ import androidx.annotation.Nullable; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GpxSplitType; import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXDatabase.GpxDataItem; @@ -114,8 +115,8 @@ public class GpxDbHelper { return res; } - public boolean updateSplit(@NonNull GpxDataItem item, int splitType, double splitInterval) { - boolean res = db.updateSplit(item, splitType, splitInterval); + public boolean updateSplit(@NonNull GpxDataItem item, @NonNull GpxSplitType splitType, double splitInterval) { + boolean res = db.updateSplit(item, splitType.getType(), splitInterval); putToCache(item); return res; } diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 07a183712d..6f239e2286 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GpxSplitType; import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.Route; @@ -172,17 +173,17 @@ public class GpxSelectionHelper { if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) { GPXFile gpxFile = selectedGpxFile.getGpxFile(); List groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); - if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT) { + if (dataItem.getSplitType() == GpxSplitType.NO_SPLIT.getType()) { for (GpxDisplayGroup model : groups) { model.noSplit(app); } selectedGpxFile.setDisplayGroups(groups, app); - } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { + } else if (dataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { for (GpxDisplayGroup model : groups) { model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments()); } selectedGpxFile.setDisplayGroups(groups, app); - } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) { + } else if (dataItem.getSplitType() == GpxSplitType.TIME.getType()) { for (GpxDisplayGroup model : groups) { model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments()); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index b5a9ee75e9..7bf86aff9e 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -1027,6 +1027,10 @@ public class ImportHelper { item.setGradientSlopeColor(gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0)); item.setGradientAltitudeColor(gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0)); app.getGpxDbHelper().add(item); + + if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) { + app.getGpxDbHelper().updateSplit(item, gpxFile.getSplitType(), gpxFile.getSplitInterval()); + } } else { GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file); if (item != null) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 0304618a7c..260d7fccda 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -39,12 +39,12 @@ import com.squareup.picasso.RequestCreator; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GpxSplitType; import net.osmand.GPXUtilities.WptPt; import net.osmand.PicassoUtils; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; -import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; @@ -764,9 +764,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { double splitInterval = getGpxDataItem().getSplitInterval(); int position = 0; - if (splitType == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { + if (splitType == GpxSplitType.DISTANCE.getType()) { position = distanceSplit.indexOf(splitInterval); - } else if (splitType == GPXDatabase.GPX_SPLIT_TYPE_TIME) { + } else if (splitType == GpxSplitType.TIME.getType()) { position = timeSplit.indexOf((int) splitInterval); } @@ -877,20 +877,20 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } private void updateSplitInDatabase() { - int splitType = 0; double splitInterval = 0; + GpxSplitType splitType = null; if (selectedSplitInterval == 0) { - splitType = GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT; + splitType = GpxSplitType.NO_SPLIT; splitInterval = 0; } else if (distanceSplit.get(selectedSplitInterval) > 0) { - splitType = GPXDatabase.GPX_SPLIT_TYPE_DISTANCE; + splitType = GpxSplitType.DISTANCE; splitInterval = distanceSplit.get(selectedSplitInterval); } else if (timeSplit.get(selectedSplitInterval) > 0) { - splitType = GPXDatabase.GPX_SPLIT_TYPE_TIME; + splitType = GpxSplitType.TIME; splitInterval = timeSplit.get(selectedSplitInterval); } GpxDataItem item = getGpxDataItem(); - if (item != null) { + if (item != null && splitType != null) { app.getGpxDbHelper().updateSplit(item, splitType, splitInterval); } } From 4eabba3489cecc6129d35829114a294c2be66052 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 8 Jul 2020 13:03:28 +0300 Subject: [PATCH 13/16] Show track start finish icons by default --- OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java | 7 +++---- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 762ed0deb8..b3c3e18e8a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1605,11 +1605,10 @@ public class GPXUtilities { } public boolean isShowStartFinish() { - String showStartFinish = null; - if (extensions != null) { - showStartFinish = extensions.get("show_start_finish"); + if (extensions != null && extensions.containsKey("show_start_finish")) { + return Boolean.parseBoolean(extensions.get("show_start_finish")); } - return Boolean.parseBoolean(showStartFinish); + return true; } public void setShowStartFinish(boolean showStartFinish) { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index dd573eba54..16f480df10 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -443,7 +443,7 @@ public class GPXDatabase { db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " + "WHERE " + GPX_COL_SHOW_ARROWS + " IS NULL", new Object[]{0}); db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " + - "WHERE " + GPX_COL_SHOW_START_FINISH + " IS NULL", new Object[]{0}); + "WHERE " + GPX_COL_SHOW_START_FINISH + " IS NULL", new Object[]{1}); } db.execSQL("CREATE INDEX IF NOT EXISTS " + GPX_INDEX_NAME_DIR + " ON " + GPX_TABLE_NAME + " (" + GPX_COL_NAME + ", " + GPX_COL_DIR + ");"); } From b7c1fe6ba792e690db92e18fcf4dac68666865e8 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 13 Jul 2020 12:03:20 +0300 Subject: [PATCH 14/16] Remove unnecessary setters from GpxDataItem --- .../main/java/net/osmand/GPXUtilities.java | 10 ++-- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 54 +++++++------------ OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 2 +- .../net/osmand/plus/helpers/ImportHelper.java | 18 ++----- .../src/net/osmand/plus/views/GPXLayer.java | 4 +- 5 files changed, 32 insertions(+), 56 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index b3c3e18e8a..200dca61dc 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1,6 +1,8 @@ package net.osmand; +import com.sun.istack.internal.NotNull; + import net.osmand.data.QuadRect; import net.osmand.util.Algorithms; @@ -1540,8 +1542,8 @@ public class GPXUtilities { return null; } - public void setGradientScaleType(GradientScaleType gradientScaleType) { - getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); + public void setGradientScaleType(@NotNull GradientScaleType gradientScaleType) { + getExtensionsToWrite().put("gradient_scale_type", gradientScaleType.name()); } public GpxSplitType getSplitType() { @@ -1558,8 +1560,8 @@ public class GPXUtilities { return null; } - public void setSplitType(GpxSplitType gpxSplitType) { - getExtensionsToWrite().put("split_type", gpxSplitType != null ? gpxSplitType.name() : null); + public void setSplitType(@NotNull GpxSplitType gpxSplitType) { + getExtensionsToWrite().put("split_type", gpxSplitType.name()); } public double getSplitInterval() { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 16f480df10..b25bc4aefd 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -3,6 +3,7 @@ package net.osmand.plus; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; @@ -198,6 +199,22 @@ public class GPXDatabase { this.color = color; } + public GpxDataItem(File file, @NonNull GPXUtilities.GPXFile gpxFile) { + this.file = file; + color = gpxFile.getColor(0); + width = gpxFile.getWidth(null); + showArrows = gpxFile.isShowArrows(); + showStartFinish = gpxFile.isShowStartFinish(); + gradientScaleType = gpxFile.getGradientScaleType(); + gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0); + gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0); + gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0); + if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) { + splitType = gpxFile.getSplitType().getType(); + splitInterval = gpxFile.getSplitInterval(); + } + } + public File getFile() { return file; } @@ -215,41 +232,22 @@ public class GPXDatabase { return gradientScaleType; } - public void setGradientScaleType(GradientScaleType gradientScaleType) { - this.gradientScaleType = gradientScaleType; - } - public int getGradientSpeedColor() { return gradientSpeedColor; } - public void setGradientSpeedColor(int gradientSpeedColor) { - this.gradientSpeedColor = gradientSpeedColor; - } - public int getGradientAltitudeColor() { return gradientAltitudeColor; } - public void setGradientAltitudeColor(int gradientAltitudeColor) { - this.gradientAltitudeColor = gradientAltitudeColor; - } - public int getGradientSlopeColor() { return gradientSlopeColor; } - public void setGradientSlopeColor(int gradientSlopeColor) { - this.gradientSlopeColor = gradientSlopeColor; - } - public String getWidth() { return width; } - public void setWidth(String width) { - this.width = width; - } public long getFileLastModifiedTime() { return fileLastModifiedTime; @@ -283,26 +281,14 @@ public class GPXDatabase { return joinSegments; } - public void setJoinSegments(boolean joinSegments) { - this.joinSegments = joinSegments; - } - public boolean isShowArrows() { return showArrows; } - public void setShowArrows(boolean showArrows) { - this.showArrows = showArrows; - } - public boolean isShowStartFinish() { return showStartFinish; } - public void setShowStartFinish(boolean showStartFinish) { - this.showStartFinish = showStartFinish; - } - @Override public int hashCode() { return file != null ? file.hashCode() : 0; @@ -562,7 +548,7 @@ public class GPXDatabase { db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[] {showArrows ? 1 : 0, fileName, fileDir}); - item.setShowArrows(showArrows); + item.showArrows = showArrows; } finally { db.close(); } @@ -580,7 +566,7 @@ public class GPXDatabase { db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[] {showStartFinish ? 1 : 0, fileName, fileDir}); - item.setShowStartFinish(showStartFinish); + item.showStartFinish = showStartFinish; } finally { db.close(); } @@ -636,7 +622,7 @@ public class GPXDatabase { GPX_COL_JOIN_SEGMENTS + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[]{joinSegments ? 1 : 0, fileName, fileDir}); - item.setJoinSegments(joinSegments); + item.joinSegments = joinSegments; } finally { db.close(); } diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index 4f4c12c9a4..fc0ffb636e 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -189,7 +189,7 @@ public class GpxDbHelper { } private void readGpxItem(@NonNull File gpxFile, @Nullable GpxDataItem item, @Nullable GpxDataItemCallback callback) { - readingItemsMap.put(gpxFile, item != null ? item : new GpxDataItem(null, null)); + readingItemsMap.put(gpxFile, item != null ? item : new GpxDataItem(null, (GPXTrackAnalysis) null)); if (callback != null) { readingItemsCallbacks.put(gpxFile, callback); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 7bf86aff9e..36d5b9ab92 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -23,7 +23,6 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.WptPt; import net.osmand.IProgress; import net.osmand.IndexConstants; @@ -33,7 +32,7 @@ import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.plus.AppInitializer; import net.osmand.plus.CustomOsmandPlugin; import net.osmand.plus.FavouritesDbHelper; -import net.osmand.plus.GPXDatabase; +import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -1018,21 +1017,10 @@ public class ImportHelper { gpxFile.path = toWrite.getAbsolutePath(); File file = new File(gpxFile.path); if (!destinationExists) { - GPXDatabase.GpxDataItem item = new GPXDatabase.GpxDataItem(file, gpxFile.getColor(0)); - item.setWidth(gpxFile.getWidth(null)); - item.setShowArrows(gpxFile.isShowArrows()); - item.setShowStartFinish(gpxFile.isShowStartFinish()); - item.setGradientScaleType(gpxFile.getGradientScaleType()); - item.setGradientSpeedColor(gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0)); - item.setGradientSlopeColor(gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0)); - item.setGradientAltitudeColor(gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0)); + GpxDataItem item = new GpxDataItem(file, gpxFile); app.getGpxDbHelper().add(item); - - if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) { - app.getGpxDbHelper().updateSplit(item, gpxFile.getSplitType(), gpxFile.getSplitInterval()); - } } else { - GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file); + GpxDataItem item = app.getGpxDbHelper().getItem(file); if (item != null) { app.getGpxDbHelper().clearAnalysis(item); } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 4073194ea4..c9ee1b2433 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -266,7 +266,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 * shadowRadius); } for (String key : cachedTrackWidth.keySet()) { - searchTrackWidth(key, rrs, req, rc); + acquireTrackWidth(key, rrs, req, rc); } } else { log.error("Rendering attribute gpx is not found !"); @@ -284,7 +284,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM return cachedColor; } - private void searchTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) { + private void acquireTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) { if (!Algorithms.isEmpty(widthKey) && Algorithms.isInt(widthKey)) { try { int widthDp = Integer.parseInt(widthKey); From 4d81d797dbaca42228bcffa8badf00d4bd1a41f9 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 13 Jul 2020 12:11:10 +0300 Subject: [PATCH 15/16] Add constant for default width multiplier --- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 4 ++-- OsmAnd/src/net/osmand/plus/views/GPXLayer.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index b25bc4aefd..d0a19e80b9 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -3,7 +3,7 @@ package net.osmand.plus; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; @@ -199,7 +199,7 @@ public class GPXDatabase { this.color = color; } - public GpxDataItem(File file, @NonNull GPXUtilities.GPXFile gpxFile) { + public GpxDataItem(File file, @NonNull GPXFile gpxFile) { this.file = file; color = gpxFile.getColor(0); width = gpxFile.getWidth(null); diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index c9ee1b2433..7cc2e97f63 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -75,6 +75,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private static final Log log = PlatformUtil.getLog(GPXLayer.class); private static final double TOUCH_RADIUS_MULTIPLIER = 1.5; + private static final int DEFAULT_WIDTH_MULTIPLIER = 7; private static final int START_ZOOM = 7; private OsmandMapTileView view; @@ -225,7 +226,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM if (hash != cachedHash) { cachedHash = hash; cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track); - defaultTrackWidth = 7 * view.getDensity(); + defaultTrackWidth = DEFAULT_WIDTH_MULTIPLIER * view.getDensity(); if (rrs != null) { RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); From 7a18f2e5cada96d5e3819a5437bbdb3c673d5707 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 13 Jul 2020 12:29:56 +0300 Subject: [PATCH 16/16] Remove unnecessary annotations --- OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 4cd237fc66..3498450ab4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1,7 +1,6 @@ package net.osmand; -import com.sun.istack.internal.NotNull; import net.osmand.data.QuadRect; import net.osmand.util.Algorithms; @@ -1541,7 +1540,7 @@ public class GPXUtilities { return null; } - public void setGradientScaleType(@NotNull GradientScaleType gradientScaleType) { + public void setGradientScaleType(GradientScaleType gradientScaleType) { getExtensionsToWrite().put("gradient_scale_type", gradientScaleType.name()); } @@ -1559,7 +1558,7 @@ public class GPXUtilities { return null; } - public void setSplitType(@NotNull GpxSplitType gpxSplitType) { + public void setSplitType(GpxSplitType gpxSplitType) { getExtensionsToWrite().put("split_type", gpxSplitType.name()); }