diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index 12b4cd4837..37b64ce3a2 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -536,7 +536,7 @@ public class BinaryMapIndexReader { return r; } } - throw new IllegalArgumentException(name); + return null; } public List getCities(String region, SearchRequest resultMatcher, @@ -547,6 +547,9 @@ public class BinaryMapIndexReader { int cityType) throws IOException { List cities = new ArrayList(); AddressRegion r = getRegionByName(region); + if(r == null) { + return cities; + } for(CitiesBlock block : r.cities) { if(block.type == cityType) { codedIS.seek(block.filePointer); diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index 0560ef8f44..c22c5a4424 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -117,7 +117,13 @@ public class PointDescription { return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.northing) + " " + ((long) pnt.easting); } else { - return ctx.getString( sh? R.string.short_location_on_map : R.string.location_on_map, convert(lat, f), convert(lon, f)); + try { + return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, convert(lat, f), + convert(lon, f)); + } catch(RuntimeException e) { + e.printStackTrace(); + return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, 0, 0); + } } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 61a6e599a5..0c050a0efb 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -433,7 +433,7 @@ public class OsmandSettings { @Override protected boolean setValue(Object prefs, Integer val) { - return settingsAPI.edit( prefs).putInt(getId(), val).commit(); + return settingsAPI.edit(prefs).putInt(getId(), val).commit(); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index b00cc65813..ecbf20f467 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -46,6 +46,7 @@ import net.osmand.plus.views.PointNavigationLayer; import net.osmand.plus.views.RouteLayer; import net.osmand.plus.views.TransportInfoLayer; import net.osmand.plus.views.TransportStopsLayer; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; @@ -76,9 +77,15 @@ public class MapActivityLayers { private ContextMenuLayer contextMenuLayer; private MapControlsLayer mapControlsLayer; private DownloadedRegionsLayer downloadedRegionsLayer; - + private MapWidgetRegistry mapWidgetRegistry; + public MapActivityLayers(MapActivity activity) { this.activity = activity; + this.mapWidgetRegistry = new MapWidgetRegistry(activity.getMyApplication().getSettings()); + } + + public MapWidgetRegistry getMapWidgetRegistry() { + return mapWidgetRegistry; } public OsmandApplication getApplication(){ diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index e39fa62544..dd0fe8053a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -72,7 +72,6 @@ public class TrackActivity extends TabActivity { setViewPagerAdapter(mViewPager, new ArrayList()); mSlidingTabLayout.setViewPager(mViewPager); - new AsyncTask() { protected void onPreExecute() { @@ -114,6 +113,9 @@ public class TrackActivity extends TabActivity { } public List getResult() { + if(result == null) { + return new ArrayList(); + } if (result.modifiedTime != modifiedTime) { modifiedTime = result.modifiedTime; GpxSelectionHelper selectedGpxHelper = ((OsmandApplication) getApplication()).getSelectedGpxHelper(); @@ -171,11 +173,11 @@ public class TrackActivity extends TabActivity { } boolean isHavingWayPoints(){ - return getGpx().hasWptPt(); + return getGpx() != null && getGpx().hasWptPt(); } boolean isHavingRoutePoints(){ - return getGpx().hasRtePt(); + return getGpx() != null && getGpx().hasRtePt(); } public GPXFile getGpx() { diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java index 6c7b58e16c..f1092fe835 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java @@ -44,6 +44,7 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity listAdapter, OnItemClickListener listener) { this.listAdapter = listAdapter; this.listAdapterOnClickListener = listener; - if(this.listView != null) { + if (this.listView != null) { listView.setAdapter(listAdapter); if(!portrait) { listView.setOnItemClickListener(this.listAdapterOnClickListener); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java index 663f960602..5956a9e2ee 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java @@ -106,7 +106,7 @@ public class SelectedGPXFragment extends ListFragment { super.onResume(); updateContent(); updateEnable = true; - if(getGpx().showCurrentTrack && filterType() == GpxDisplayItemType.TRACK_POINTS) { + if(getGpx() != null && getGpx().showCurrentTrack && filterType() == GpxDisplayItemType.TRACK_POINTS) { startHandler(); } } @@ -121,8 +121,8 @@ public class SelectedGPXFragment extends ListFragment { protected List filterGroups(GpxDisplayItemType type) { - List result = ((TrackActivity)getActivity()).getResult(); - List groups = new ArrayList(); + List result = ((TrackActivity) getActivity()).getResult(); + List groups = new ArrayList(); for (GpxDisplayGroup group : result) { boolean add = group.getType() == type || type == null; if (isArgumentTrue(ARG_TO_FILTER_SHORT_TRACKS)) { @@ -238,7 +238,7 @@ public class SelectedGPXFragment extends ListFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); ((TrackActivity) getActivity()).getClearToolbar(false); - if (getGpx().path != null && !getGpx().showCurrentTrack) { + if (getGpx() != null && getGpx().path != null && !getGpx().showCurrentTrack) { MenuItem item = menu.add(R.string.shared_string_share).setIcon(R.drawable.ic_action_gshare_dark) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/osmo/DashOsMoFragment.java b/OsmAnd/src/net/osmand/plus/osmo/DashOsMoFragment.java index 5ea4e77129..b89f700d9c 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/DashOsMoFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmo/DashOsMoFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.osmo; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Iterator; import java.util.List; import net.osmand.Location; @@ -201,13 +202,16 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups } //remove all inactive devices - for (OsMoGroupsStorage.OsMoDevice device : devices) { - if (!device.isActive() && !device.isEnabled() && devices.size() > 2) { - devices.remove(device); - } + Iterator it = devices.iterator(); + while (it.hasNext()) { if (devices.size() < 4) { break; } + OsMoGroupsStorage.OsMoDevice device = it.next(); + if (!device.isActive() && !device.isEnabled() && devices.size() > 2) { + it.remove(); + } + } sortDevices(devices); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 67bc9b8486..957951152a 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -126,8 +126,10 @@ public class PoiFiltersHelper { AbstractPoiType tp = application.getPoiTypes().getAnyPoiTypeByKey(typeId); if(tp != null) { PoiLegacyFilter lf = new PoiLegacyFilter(tp, application); - cacheTopStandardFilters.add(lf); - sortListOfFilters(cacheTopStandardFilters); + ArrayList copy = new ArrayList(cacheTopStandardFilters); + copy.add(lf); + sortListOfFilters(copy); + cacheTopStandardFilters = copy; return lf; } } @@ -136,9 +138,9 @@ public class PoiFiltersHelper { public void reloadAllPoiFilters() { - cacheTopStandardFilters = null; showAllPOIFilter = null; getShowAllPOIFilter(); + cacheTopStandardFilters = null; getTopDefinedPoiFilters(); } @@ -168,15 +170,16 @@ public class PoiFiltersHelper { public List getTopDefinedPoiFilters() { if (cacheTopStandardFilters == null) { - cacheTopStandardFilters = new ArrayList(); + List top = new ArrayList(); // user defined - cacheTopStandardFilters.addAll(getUserDefinedPoiFilters()); + top.addAll(getUserDefinedPoiFilters()); // default MapPoiTypes poiTypes = application.getPoiTypes(); for (PoiFilter t : poiTypes.getTopVisibleFilters()) { - cacheTopStandardFilters.add(new PoiLegacyFilter(t, application)); + top.add(new PoiLegacyFilter(t, application)); } - sortListOfFilters(cacheTopStandardFilters); + sortListOfFilters(top); + cacheTopStandardFilters = top; } List result = new ArrayList(); if(OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) { @@ -205,7 +208,9 @@ public class PoiFiltersHelper { } boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter); if(res){ - cacheTopStandardFilters.remove(filter); + ArrayList copy = new ArrayList<>(cacheTopStandardFilters); + copy.remove(filter); + cacheTopStandardFilters = copy; } helper.close(); return res; @@ -225,8 +230,10 @@ public class PoiFiltersHelper { } res = helper.addFilter(filter, helper.getWritableDatabase(), false); if(res){ - cacheTopStandardFilters.add(filter); - sortListOfFilters(cacheTopStandardFilters); + ArrayList copy = new ArrayList<>(cacheTopStandardFilters); + copy.add(filter); + sortListOfFilters(copy); + cacheTopStandardFilters = copy; } helper.close(); return res; diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index fc7b5cad89..6b6f661d36 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -216,9 +216,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { }; adapter.item(R.string.layer_map).iconColor(R.drawable.ic_world_globe_dark) .listen(listener).position(3).reg(); - adapter.item(R.string.layer_overlay).selected(overlayLayer.getMap() != null ? 1 : 0). + adapter.item(R.string.layer_overlay).selected(overlayLayer != null && overlayLayer.getMap() != null ? 1 : 0). iconColor(R.drawable.ic_layer_top_dark).listen(listener).position(14).reg(); - adapter.item(R.string.layer_underlay).selected(underlayLayer.getMap() != null ? 1 : 0) + adapter.item(R.string.layer_underlay).selected(underlayLayer != null && underlayLayer.getMap() != null ? 1 : 0) .iconColor(R.drawable.ic_layer_bottom_dark).listen(listener).position(15).reg(); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index f79b766014..5677946baa 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -4,14 +4,10 @@ package net.osmand.plus.views; import java.lang.reflect.Field; import net.osmand.data.RotatedTileBox; -import net.osmand.plus.ApplicationMode; -import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; @@ -28,7 +24,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.view.View; import android.view.View.OnClickListener; -import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.LinearLayout; @@ -71,8 +66,7 @@ public class MapInfoLayer extends OsmandMapLayer { @Override public void initLayer(final OsmandMapTileView view) { this.view = view; - mapInfoControls = new MapWidgetRegistry(map.getMyApplication().getSettings()); - + mapInfoControls = map.getMapLayers().getMapWidgetRegistry() ; leftStack = (LinearLayout) map.findViewById(R.id.map_left_widgets_panel); rightStack = (LinearLayout) map.findViewById(R.id.map_right_widgets_panel); expand = (ImageButton) map.findViewById(R.id.map_collapse_button); @@ -307,32 +301,7 @@ public class MapInfoLayer extends OsmandMapLayer { - public ContextMenuAdapter getViewConfigureMenuAdapter() { - ContextMenuAdapter cm = new ContextMenuAdapter(view.getContext()); - cm.setDefaultLayoutId(R.layout.drawer_list_item); - cm.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg(); - cm.setChangeAppModeListener(new ConfigureMapMenu.OnClickListener() { - - @Override - public void onClick(boolean allModes) { - map.getDashboard().updateListAdapter(getViewConfigureMenuAdapter()); - } - }); - cm.item(R.string.map_widget_reset) - .iconColor(R.drawable.ic_action_reset_to_default_dark).listen(new OnContextMenuClick() { - - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - mapInfoControls.resetToDefault(); - recreateControls(); - adapter.notifyDataSetInvalidated(); - return false; - } - }).reg(); - final ApplicationMode mode = settings.getApplicationMode(); - mapInfoControls.addControls(this, cm, mode); - return cm; - } + diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 7ea4543601..3d57d4ef9d 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -14,6 +14,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import android.content.Context; @@ -214,21 +215,21 @@ public class MapWidgetRegistry { settings.CENTER_POSITION_ON_MAP.resetToDefault(); } - public void addControlsAppearance(final MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) { + public void addControlsAppearance(final MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) { // addControlId(mil, cm, R.string.map_widget_show_ruler, settings.SHOW_RULER); - addControlId(mil, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW); - addControlId(mil, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME); - addControlId(mil, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP); + addControlId(map, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW); + addControlId(map, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME); + addControlId(map, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP); if(mode != ApplicationMode.DEFAULT) { - addControlId(mil, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME); + addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME); } } - private void addControlId(final MapInfoLayer mil, ContextMenuAdapter cm, int stringId, OsmandPreference pref) { + private void addControlId(final MapActivity map, ContextMenuAdapter cm, int stringId, OsmandPreference pref) { cm.item(stringId).selected( pref.get() ? 1 : 0) // .icons(r.drawableDark, r.drawableLight) - .listen(new ApearanceOnContextMenuClick(pref, mil.getMapActivity())).reg(); + .listen(new ApearanceOnContextMenuClick(pref, map)).reg(); } class ApearanceOnContextMenuClick implements OnContextMenuClick { @@ -259,15 +260,15 @@ public class MapWidgetRegistry { } - public void addControls(MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) { + public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) { cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); - addControls(mil, cm, right, mode); + addControls(map, cm, right, mode); if(mode != ApplicationMode.DEFAULT) { cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); - addControls(mil, cm, left, mode); + addControls(map, cm, left, mode); } cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); - addControlsAppearance(mil, cm, mode); + addControlsAppearance(map, cm, mode); } public String getText(Context ctx, final ApplicationMode mode, final MapWidgetRegInfo r) { @@ -282,7 +283,7 @@ public class MapWidgetRegistry { return left; } - private void addControls(final MapInfoLayer mil, final ContextMenuAdapter adapter, Set top, final ApplicationMode mode) { + private void addControls(final MapActivity map, final ContextMenuAdapter adapter, Set top, final ApplicationMode mode) { for(final MapWidgetRegInfo r : top){ adapter.item(r.messageId).selected(r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0) .iconColor(r.drawableMenu).listen(new OnContextMenuClick() { @@ -290,14 +291,17 @@ public class MapWidgetRegistry { @Override public boolean onContextMenuClick(ArrayAdapter a, int itemId, int pos, boolean isChecked) { changeVisibility(r); - mil.recreateControls(); + MapInfoLayer mil = map.getMapLayers().getMapInfoLayer(); + if (mil != null) { + mil.recreateControls(); + } adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r)); adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0); a.notifyDataSetInvalidated(); return false; } }).reg(); - adapter.setItemName(adapter.length() - 1, getText(mil.getMapActivity(), mode, r)); + adapter.setItemName(adapter.length() - 1, getText(map, mode, r)); } } @@ -372,5 +376,35 @@ public class MapWidgetRegistry { return priorityOrder - another.priorityOrder; } } + + public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) { + ContextMenuAdapter cm = new ContextMenuAdapter(map); + cm.setDefaultLayoutId(R.layout.drawer_list_item); + cm.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg(); + cm.setChangeAppModeListener(new ConfigureMapMenu.OnClickListener() { + + @Override + public void onClick(boolean allModes) { + map.getDashboard().updateListAdapter(getViewConfigureMenuAdapter(map)); + } + }); + cm.item(R.string.map_widget_reset).iconColor(R.drawable.ic_action_reset_to_default_dark) + .listen(new OnContextMenuClick() { + + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { + resetToDefault(); + MapInfoLayer mil = map.getMapLayers().getMapInfoLayer(); + if (mil != null) { + mil.recreateControls(); + } + adapter.notifyDataSetInvalidated(); + return false; + } + }).reg(); + final ApplicationMode mode = settings.getApplicationMode(); + addControls(map, cm, mode); + return cm; + } }