From 30eac3412f9aff9204bd9addfa362f6a987114ce Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 25 May 2020 15:45:36 +0300 Subject: [PATCH 1/4] Fix several possible exceptions --- .../src/net/osmand/plus/AppInitializer.java | 3 +- .../OsmandInAppPurchaseActivity.java | 7 ++-- .../SettingsDevelopmentActivity.java | 2 +- .../osmand/plus/dialogs/ConfigureMapMenu.java | 2 +- .../download/ui/LocalIndexesFragment.java | 16 +++---- .../osmand/plus/helpers/WaypointHelper.java | 25 +++++------ .../monitoring/OsmandMonitoringPlugin.java | 42 ++++++++++--------- .../fragments/VehicleParametersFragment.java | 7 ++-- .../plus/srtmplugin/TerrainFragment.java | 28 ++++++------- .../wikipedia/WikipediaWebViewClient.java | 5 ++- .../wikivoyage/WikivoyageWebViewClient.java | 7 +++- 11 files changed, 80 insertions(+), 64 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 3338594403..f09785122e 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -553,7 +553,8 @@ public class AppInitializer implements IProgress { customConfigs.put(fileName, builder); } catch (XmlPullParserException | IOException e) { - throw new IllegalStateException(e); + Algorithms.removeAllFiles(f); + LOG.error(e); } } } diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java index 76293f870d..cb91f7d167 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java @@ -166,17 +166,18 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In @Override public void onItemPurchased(String sku, boolean active) { + FragmentManager fragmentManager = getSupportFragmentManager(); if (purchaseHelper != null && purchaseHelper.getLiveUpdates().containsSku(sku)) { getMyApplication().logEvent("live_osm_subscription_purchased"); - if (!active) { + if (!active && !fragmentManager.isStateSaved()) { OsmLiveRestartBottomSheetDialogFragment fragment = new OsmLiveRestartBottomSheetDialogFragment(); fragment.setUsedOnMap(this instanceof MapActivity); - fragment.show(getSupportFragmentManager(), OsmLiveRestartBottomSheetDialogFragment.TAG); + fragment.show(fragmentManager, OsmLiveRestartBottomSheetDialogFragment.TAG); } } onInAppPurchaseItemPurchased(sku); - fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku, active); + fireInAppPurchaseItemPurchasedOnFragments(fragmentManager, sku, active); } public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager, diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 3cfd370057..b5ea815bed 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -215,7 +215,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { SunriseSunset sunriseSunset = getMyApplication().getDaynightHelper().getSunriseSunset(); pref = new Preference(this); pref.setTitle(R.string.day_night_info); - if (sunriseSunset != null) { + if (sunriseSunset != null && sunriseSunset.getSunrise() != null && sunriseSunset.getSunset() != null) { SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd HH:mm"); pref.setSummary(getString(R.string.day_night_info_description, prt.format(sunriseSunset.getSunrise()), prt.format(sunriseSunset.getSunset()))); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 0ab07cc75b..b3e11e54b6 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -504,7 +504,7 @@ public class ConfigureMapMenu { String description = ""; SunriseSunset sunriseSunset = activity.getMyApplication().getDaynightHelper().getSunriseSunset(); - if (sunriseSunset != null) { + if (sunriseSunset != null && sunriseSunset.getSunrise() != null && sunriseSunset.getSunset() != null) { DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); String sunriseTime = dateFormat.format(sunriseSunset.getSunrise()); String sunsetTime = dateFormat.format(sunriseSunset.getSunset()); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index bbb0f694e9..b4441a2ed6 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -768,13 +768,15 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - for (int i = 0; i < optionsMenuAdapter.length(); i++) { - ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i); - if (itemId == contextMenuItem.getTitleId()) { - contextMenuItem.getItemClickListener().onContextMenuClick(null, itemId, i, false, null); - return true; + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (optionsMenuAdapter != null) { + int itemId = item.getItemId(); + for (int i = 0; i < optionsMenuAdapter.length(); i++) { + ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i); + if (itemId == contextMenuItem.getTitleId()) { + contextMenuItem.getItemClickListener().onContextMenuClick(null, itemId, i, false, null); + return true; + } } } return super.onOptionsItemSelected(item); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 239715e192..5cd0ce4b39 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -17,11 +17,8 @@ import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; import net.osmand.data.WptLocationPoint; import net.osmand.osm.PoiType; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.UiUtilities; @@ -33,6 +30,9 @@ import net.osmand.plus.routing.AlarmInfo; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.VoiceRouter; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants; import net.osmand.util.MapUtils; import java.util.ArrayList; @@ -627,20 +627,21 @@ public class WaypointHelper { amenities.addAll(pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius)); } for (Amenity a : amenities) { - AmenityRoutePoint rp = a.getRoutePoint(); - int i = locs.indexOf(rp.pointA); - if (i >= 0) { - LocationPointWrapper lwp = new LocationPointWrapper(route, POI, new AmenityLocationPoint(a), - (float) rp.deviateDistance, i); - lwp.deviationDirectionRight = rp.deviationDirectionRight; - lwp.setAnnounce(announcePOI); - locationPoints.add(lwp); + AmenityRoutePoint routePoint = a.getRoutePoint(); + if (routePoint != null) { + int i = locs.indexOf(routePoint.pointA); + if (i >= 0) { + LocationPointWrapper lwp = new LocationPointWrapper(route, POI, new AmenityLocationPoint(a), + (float) routePoint.deviateDistance, i); + lwp.deviationDirectionRight = routePoint.deviationDirectionRight; + lwp.setAnnounce(announcePOI); + locationPoints.add(lwp); + } } } } } - private void calculateAlarms(RouteCalculationResult route, List array, ApplicationMode mode) { AlarmInfo prevSpeedCam = null; for (AlarmInfo i : route.getAlarmInfo()) { diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 9ae44d87b1..b869ea992c 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -25,19 +25,19 @@ import com.google.android.material.slider.Slider; import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.ValueHolder; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.NavigationService; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable; 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.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper.SaveGpxResult; import net.osmand.plus.dashboard.tools.DashFragmentData; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; @@ -333,18 +333,20 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { startGPXMonitoring(activity, showTrackSelection); } } else if (item == R.string.clear_recorded_data) { - AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode)); - builder.setTitle(R.string.clear_recorded_data); - builder.setMessage(R.string.are_you_sure); - builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton( - R.string.shared_string_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - app.getSavingTrackHelper().clearRecordedData(true); - app.getNotificationHelper().refreshNotifications(); - } - }); - builder.show(); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode)); + builder.setTitle(R.string.clear_recorded_data); + builder.setMessage(R.string.are_you_sure); + builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton( + R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + app.getSavingTrackHelper().clearRecordedData(true); + app.getNotificationHelper().refreshNotifications(); + } + }); + builder.show(); + } } else if(item == R.string.gpx_monitoring_stop) { stopRecording(); } else if(item == R.string.gpx_start_new_segment) { @@ -481,19 +483,21 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { } } - - public static void showIntervalChooseDialog(final Context uiCtx, final String patternMsg, + public static void showIntervalChooseDialog(final Activity activity, final String patternMsg, String title, final int[] seconds, final int[] minutes, final ValueHolder choice, final ValueHolder v, final boolean showTrackSelection, OnClickListener onclick) { - final OsmandApplication app = (OsmandApplication) uiCtx.getApplicationContext(); + if (!AndroidUtils.isActivityNotDestroyed(activity)) { + return; + } + final OsmandApplication app = (OsmandApplication) activity.getApplicationContext(); boolean nightMode; - if (uiCtx instanceof MapActivity) { + if (activity instanceof MapActivity) { nightMode = app.getDaynightHelper().isNightModeForMapControls(); } else { nightMode = !app.getSettings().isLightContent(); } - Context themedContext = UiUtilities.getThemedContext(uiCtx, nightMode); + Context themedContext = UiUtilities.getThemedContext(activity, nightMode); AlertDialog.Builder dlg = new AlertDialog.Builder(themedContext); dlg.setTitle(title); LinearLayout ll = createIntervalChooseLayout(app, themedContext, patternMsg, seconds, minutes, choice, v, showTrackSelection, nightMode); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java index 590be355fa..14ff53106b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java @@ -7,13 +7,13 @@ import android.widget.ImageView; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.router.GeneralRouter; @@ -123,7 +123,8 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O public boolean onPreferenceClick(Preference preference) { if (preference.getKey().equals(GeneralRouter.DEFAULT_SPEED)) { RouteService routeService = getSelectedAppMode().getRouteService(); - showSeekbarSettingsDialog(getActivity(), routeService == RouteService.STRAIGHT, getSelectedAppMode()); + boolean defaultSpeedOnly = routeService == RouteService.STRAIGHT || routeService == RouteService.DIRECT_TO; + showSeekbarSettingsDialog(getActivity(), defaultSpeedOnly, getSelectedAppMode()); return true; } return super.onPreferenceClick(preference); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java index bdd4b1a8b1..75bd4ed3db 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java @@ -35,8 +35,6 @@ import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.TerrainMode; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -46,6 +44,8 @@ import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.TerrainMode; import net.osmand.plus.widgets.style.CustomTypefaceSpan; import org.apache.commons.logging.Log; @@ -53,10 +53,10 @@ import org.apache.commons.logging.Log; import java.io.IOException; import java.util.List; -import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.HILLSHADE; -import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.SLOPE; import static net.osmand.plus.download.DownloadActivityType.HILLSHADE_FILE; import static net.osmand.plus.download.DownloadActivityType.SLOPE_FILE; +import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.HILLSHADE; +import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.SLOPE; import static net.osmand.plus.srtmplugin.SRTMPlugin.TERRAIN_MAX_ZOOM; import static net.osmand.plus.srtmplugin.SRTMPlugin.TERRAIN_MIN_ZOOM; @@ -527,18 +527,18 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL @Override public void downloadInProgress() { DownloadIndexesThread downloadThread = app.getDownloadThread(); - IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem(); - if (downloadIndexItem != null) { - int downloadProgress = downloadThread.getCurrentDownloadingItemProgress(); - ArrayAdapter adapter = (ArrayAdapter) listAdapter; - for (int i = 0; i < adapter.getCount(); i++) { - ContextMenuItem item = adapter.getItem(i); - if (item != null && item.getProgressListener() != null) { - item.getProgressListener().onProgressChanged( - downloadIndexItem, downloadProgress, adapter, (int) adapter.getItemId(i), i); - } + IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem(); + if (downloadIndexItem != null && listAdapter != null) { + int downloadProgress = downloadThread.getCurrentDownloadingItemProgress(); + ArrayAdapter adapter = (ArrayAdapter) listAdapter; + for (int i = 0; i < adapter.getCount(); i++) { + ContextMenuItem item = adapter.getItem(i); + if (item != null && item.getProgressListener() != null) { + item.getProgressListener().onProgressChanged( + downloadIndexItem, downloadProgress, adapter, (int) adapter.getItemId(i), i); } } + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaWebViewClient.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaWebViewClient.java index ccc40c5ad4..d2830e4b62 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaWebViewClient.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaWebViewClient.java @@ -8,6 +8,7 @@ import android.webkit.WebViewClient; import androidx.fragment.app.FragmentActivity; +import net.osmand.AndroidUtils; import net.osmand.data.Amenity; import static net.osmand.plus.wikipedia.WikiArticleHelper.WIKI_DOMAIN; @@ -41,7 +42,9 @@ public class WikipediaWebViewClient extends WebViewClient { WikiArticleHelper.warnAboutExternalLoad(url, context, nightMode); } else { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - context.startActivity(i); + if (AndroidUtils.isIntentSafe(context, i)) { + context.startActivity(i); + } } return true; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java index b9fb48a1c3..fe47a8f370 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java @@ -12,12 +12,13 @@ import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.data.TravelArticle; @@ -124,7 +125,9 @@ public class WikivoyageWebViewClient extends WebViewClient { } } else { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - activity.startActivity(i); + if (AndroidUtils.isIntentSafe(activity, i)) { + activity.startActivity(i); + } } return true; } From 26805c4ae8002af5a35b941153070f14b3c0445c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 25 May 2020 16:01:55 +0300 Subject: [PATCH 2/4] Fix possible IndexOutOfBoundsException --- OsmAnd/res/values/strings.xml | 1 + .../osmand/plus/OsmAndLocationSimulation.java | 2 +- .../plus/activities/MapActivityActions.java | 2 +- .../RoutingOptionsHelper.java | 2 +- .../osmand/plus/routing/RouteProvider.java | 23 ++++++++++--------- .../osmand/plus/routing/RoutingHelper.java | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 65a1231387..1579d4c11e 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + OsmAnd GPX is not well formed, please contact support team to investigate further Unsupported type World overview map (detailed) Could not find any such profiles. diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java index 8e4ae960c2..0b2683fcc6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java @@ -79,7 +79,7 @@ public class OsmAndLocationSimulation { @Override public boolean processResult(GPXUtilities.GPXFile[] result) { GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result[0], app.getSettings()); - startAnimationThread(app, builder.getPoints(), true, speedup.getValue() + 1); + startAnimationThread(app, builder.getPoints(app), true, speedup.getValue() + 1); if (runnable != null) { runnable.run(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index c5ad4ec536..071b50dd5b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -514,7 +514,7 @@ public class MapActivityActions implements DialogProvider { params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()); params.setUseIntermediatePointsRTE(settings.GPX_CALCULATE_RTEPT.get()); params.setCalculateOsmAndRoute(settings.GPX_ROUTE_CALC.get()); - List ps = params.getPoints(); + List ps = params.getPoints(settings.getContext()); mapActivity.getRoutingHelper().setGpxParams(params); settings.FOLLOW_THE_GPX_ROUTE.set(result.path); if (!ps.isEmpty()) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 0ba3112d26..80359f7dca 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -237,7 +237,7 @@ public class RoutingOptionsHelper { if (gpxParam.id == R.string.gpx_option_reverse_route) { rp.setReverse(selected); TargetPointsHelper tg = app.getTargetPointsHelper(); - List ps = rp.getPoints(); + List ps = rp.getPoints(app); if (ps.size() > 0) { Location first = ps.get(0); Location end = ps.get(ps.size() - 1); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 2605e8a6c9..34fd072c85 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -19,15 +19,15 @@ import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.WptLocationPoint; import net.osmand.osm.io.NetworkUtils; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.Version; import net.osmand.plus.render.NativeOsmandLibrary; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameterType; @@ -173,12 +173,14 @@ public class RouteProvider { return passWholeRoute; } - public GPXRouteParams build(Location start, OsmandSettings settings) { + public GPXRouteParams build(OsmandApplication app) { GPXRouteParams res = new GPXRouteParams(); - res.prepareGPXFile(this); -// if (passWholeRoute && start != null) { -// res.points.add(0, start); -// } + try { + res.prepareGPXFile(this); + } catch (Exception e) { + log.error(e); + app.showShortToastMessage(app.getString(R.string.gpx_parse_error)); + } return res; } @@ -190,9 +192,8 @@ public class RouteProvider { return file; } - public List getPoints() { - GPXRouteParams copy = new GPXRouteParams(); - copy.prepareGPXFile(this); + public List getPoints(OsmandApplication app) { + GPXRouteParams copy = build(app); return copy.getPoints(); } } diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index f60e4f7ea9..9a4fb32f83 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -1172,7 +1172,7 @@ public class RoutingHelper { params.start = start; params.end = end; params.intermediates = intermediates; - params.gpxRoute = gpxRoute == null ? null : gpxRoute.build(start, settings); + params.gpxRoute = gpxRoute == null ? null : gpxRoute.build(app); params.onlyStartPointChanged = onlyStartPointChanged; if (recalculateCountInInterval < RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE || (gpxRoute != null && gpxRoute.isPassWholeRoute() && isDeviatedFromRoute)) { From d1e479e9be77f7d4d968d055ebb4ca6c6da3a978 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 26 May 2020 11:25:08 +0200 Subject: [PATCH 3/4] Update RouteProvider.java --- OsmAnd/src/net/osmand/plus/routing/RouteProvider.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 34fd072c85..febfa7aa0b 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -177,9 +177,9 @@ public class RouteProvider { GPXRouteParams res = new GPXRouteParams(); try { res.prepareGPXFile(this); - } catch (Exception e) { - log.error(e); - app.showShortToastMessage(app.getString(R.string.gpx_parse_error)); + } catch (RuntimeException e) { + log.error(e.getMessage(), e); + app.showShortToastMessage(app.getString(R.string.gpx_parse_error) + " " + e.getMessage()); } return res; } From 6f5a4d5bba7e627d7978a3f9baac19300479beaa Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 26 May 2020 12:27:27 +0300 Subject: [PATCH 4/4] Fix possible npe --- OsmAnd/src/net/osmand/plus/AppInitializer.java | 2 +- .../src/net/osmand/plus/views/MapQuickActionLayer.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index f09785122e..c39fe3a9d5 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -554,7 +554,7 @@ public class AppInitializer implements IProgress { customConfigs.put(fileName, builder); } catch (XmlPullParserException | IOException e) { Algorithms.removeAllFiles(f); - LOG.error(e); + LOG.error(e.getMessage(), e); } } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 33344bcf3a..c425e1774d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -394,9 +394,13 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe contextMarker.draw(canvas); } if (this.nightMode != nightMode) { - this.nightMode = nightMode; - updateQuickActionButton(currentWidgetState != null && currentWidgetState); - } + this.nightMode = nightMode; + boolean widgetVisible = false; + if (currentWidgetState != null) { + widgetVisible = currentWidgetState; + } + updateQuickActionButton(widgetVisible); + } setupQuickActionBtnVisibility(); }