From f2dc4cdc4d63dbb3da936d2d1d28384544e4d4ed Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 22 May 2020 14:29:11 +0300 Subject: [PATCH 1/4] Check activity state before showing dialog --- .../osmand/plus/dialogs/ConfigureMapMenu.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 4c3378c77e..0ab07cc75b 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -37,9 +37,6 @@ import net.osmand.plus.DialogListItemAdapter; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; -import net.osmand.plus.settings.backend.OsmandSettings.ListStringPreference; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -51,6 +48,9 @@ import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.poi.PoiFiltersHelper; 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; +import net.osmand.plus.settings.backend.OsmandSettings.ListStringPreference; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.transport.TransportLinesMenu; import net.osmand.plus.views.OsmandMapTileView; @@ -529,6 +529,9 @@ public class ConfigureMapMenu { @Override public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) { + if (!AndroidUtils.isActivityNotDestroyed(activity)) { + return false; + } final OsmandMapTileView view = activity.getMapView(); AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes)); bld.setTitle(R.string.daynight); @@ -570,6 +573,9 @@ public class ConfigureMapMenu { @Override public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) { + if (!AndroidUtils.isActivityNotDestroyed(activity)) { + return false; + } final OsmandMapTileView view = activity.getMapView(); final OsmandSettings.OsmandPreference mapDensity = view.getSettings().MAP_DENSITY; AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes)); @@ -638,6 +644,9 @@ public class ConfigureMapMenu { @Override public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) { + if (!AndroidUtils.isActivityNotDestroyed(activity)) { + return false; + } final OsmandMapTileView view = activity.getMapView(); AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes)); // test old descr as title @@ -682,6 +691,9 @@ public class ConfigureMapMenu { @Override public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) { + if (!AndroidUtils.isActivityNotDestroyed(activity)) { + return false; + } final OsmandMapTileView view = activity.getMapView(); AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes)); @@ -991,7 +1003,9 @@ public class ConfigureMapMenu { final int themeRes, final boolean nightMode, @ColorInt final int selectedProfileColor) { - + if (!AndroidUtils.isActivityNotDestroyed(activity)) { + return; + } AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes)); boolean[] checkedItems = new boolean[prefs.size()]; final boolean[] tempPrefs = new boolean[prefs.size()]; @@ -1245,7 +1259,10 @@ public class ConfigureMapMenu { @Override public boolean onContextMenuClick(final ArrayAdapter ad, - final int itemId, final int pos, boolean isChecked, int[] viewCoordinates) { + final int itemId, final int pos, boolean isChecked, int[] viewCoordinates) { + if (!AndroidUtils.isActivityNotDestroyed(activity)) { + return false; + } AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes)); // test old descr as title b.setTitle(propertyDescr); From 8a63a0ce53651ed05cb7bed0258006a9ece35a81 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 22 May 2020 14:50:14 +0300 Subject: [PATCH 2/4] Fix dashboard back button --- OsmAnd/res/layout/dashboard_toolbar.xml | 22 ++++++++++--------- .../osmand/plus/dashboard/DashboardOnMap.java | 7 +++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/layout/dashboard_toolbar.xml b/OsmAnd/res/layout/dashboard_toolbar.xml index 24cff7957f..361dfc190f 100644 --- a/OsmAnd/res/layout/dashboard_toolbar.xml +++ b/OsmAnd/res/layout/dashboard_toolbar.xml @@ -7,8 +7,8 @@ android:layout_width="fill_parent" android:layout_height="@dimen/dashboard_map_toolbar" android:background="@color/app_bar_color_light" - app:contentInsetLeft="4dp" - app:contentInsetStart="4dp" + app:contentInsetLeft="0dp" + app:contentInsetStart="0dp" app:contentInsetRight="0dp" app:contentInsetEnd="0dp"> @@ -25,17 +25,18 @@ android:gravity="start" android:orientation="horizontal"> - + tools:visibility="visible" /> Date: Fri, 22 May 2020 15:01:42 +0300 Subject: [PATCH 3/4] Fix possible npe --- OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 55adfc9eaf..843a9576b7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -393,7 +393,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight()); contextMarker.draw(canvas); } - if (this.nightMode != nightMode) { + if (this.nightMode != nightMode && currentWidgetState != null) { this.nightMode = nightMode; updateQuickActionButton(currentWidgetState); } From 88a6d620803e19538e39cf24023c3c941a8dc307 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 22 May 2020 14:57:55 +0200 Subject: [PATCH 4/4] Fix map poi types --- .../main/java/net/osmand/osm/MapPoiTypes.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 330a21c156..4199abee89 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -29,6 +29,7 @@ import java.util.TreeSet; public class MapPoiTypes { + private static final String OTHER_MAP_CATEGORY = "Other"; private static MapPoiTypes DEFAULT_INSTANCE = null; private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class); private String resourceName; @@ -96,7 +97,7 @@ public class MapPoiTypes { public PoiCategory getOtherMapCategory() { if (otherMapCategory == null) { - otherMapCategory = getPoiCategoryByName("Other", true); + otherMapCategory = getPoiCategoryByName(OTHER_MAP_CATEGORY, true); } return otherMapCategory; } @@ -111,7 +112,8 @@ public class MapPoiTypes { public List getTopVisibleFilters() { List lf = new ArrayList(); - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (pc.isTopVisible()) { lf.add(pc); } @@ -131,7 +133,8 @@ public class MapPoiTypes { } public PoiCategory getOsmwiki() { - for (PoiCategory category : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory category = categories.get(i); if (category.isWiki()) { return category; } @@ -167,7 +170,8 @@ public class MapPoiTypes { } public PoiType getPoiTypeByKey(String name) { - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); PoiType pt = pc.getPoiTypeByKeyName(name); if (pt != null && !pt.isReference()) { return pt; @@ -184,7 +188,8 @@ public class MapPoiTypes { } public AbstractPoiType getAnyPoiTypeByKey(String name) { - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (pc.getKeyName().equals(name)) { return pc; } @@ -203,7 +208,8 @@ public class MapPoiTypes { public Map getAllTranslatedNames(boolean skipNonEditable) { Map translation = new HashMap(); - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (skipNonEditable && pc.isNotEditableOsm()) { continue; } @@ -231,7 +237,8 @@ public class MapPoiTypes { public List getAllTypesTranslatedNames(StringMatcher matcher) { List tm = new ArrayList(); - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); if (pc == otherMapCategory) { continue; } @@ -294,7 +301,7 @@ public class MapPoiTypes { } if (create) { PoiCategory lastCategory = new PoiCategory(this, name, categories.size()); - if (!lastCategory.getKeyName().equals("Other")) { + if (!lastCategory.getKeyName().equals(OTHER_MAP_CATEGORY)) { lastCategory.setTopVisible(true); } addCategory(lastCategory); @@ -365,6 +372,8 @@ public class MapPoiTypes { PoiType lastType = null; Set lastTypePoiAdditionalsCategories = new TreeSet(); String lastPoiAdditionalCategory = null; + PoiCategory localOtherMapCategory = new PoiCategory(this, OTHER_MAP_CATEGORY, categoriesList.size()); + categoriesList.add(localOtherMapCategory); while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { if (tok == XmlPullParser.START_TAG) { String name = parser.getName(); @@ -404,7 +413,7 @@ public class MapPoiTypes { lastCategory.addPoiType(tp); } else if (name.equals("poi_additional")) { if (lastCategory == null) { - lastCategory = getOtherMapCategory(); + lastCategory = localOtherMapCategory; } PoiType baseType = parsePoiAdditional(parser, lastCategory, lastFilter, lastType, null, null, lastPoiAdditionalCategory); if ("true".equals(parser.getAttributeValue("", "lang"))) { @@ -433,7 +442,7 @@ public class MapPoiTypes { } else if (name.equals("poi_type")) { if (lastCategory == null) { - lastCategory = getOtherMapCategory(); + lastCategory = localOtherMapCategory; } if(!Algorithms.isEmpty(parser.getAttributeValue("", "deprecated_of"))){ String vl = parser.getAttributeValue("", "name"); @@ -705,7 +714,8 @@ public class MapPoiTypes { public AbstractPoiType getAnyPoiAdditionalTypeByKey(String name) { PoiType add = null; - for (PoiCategory pc : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory pc = categories.get(i); add = getPoiAdditionalByKey(pc, name); if (add != null) { return add; @@ -811,7 +821,8 @@ public class MapPoiTypes { if (!poiTypesByTag.isEmpty()) { return; } - for (PoiCategory poic : categories) { + for (int i = 0; i < categories.size(); i++) { + PoiCategory poic = categories.get(i); for (PoiType p : poic.getPoiTypes()) { initPoiType(p); for (PoiType pts : p.getPoiAdditionals()) {