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); } }