From fdb94ad33acc5dfb16b9dc5f5a974071460c9c90 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 28 Apr 2020 14:30:38 +0300 Subject: [PATCH 1/3] add native pt setting to dev plugin --- OsmAnd/res/values/strings.xml | 2 ++ OsmAnd/src/net/osmand/plus/AppInitializer.java | 2 ++ OsmAnd/src/net/osmand/plus/OsmandSettings.java | 2 +- .../plus/activities/SettingsGeneralActivity.java | 5 +++++ .../development/DevelopmentSettingsFragment.java | 13 +++++++++++++ .../development/SettingsDevelopmentActivity.java | 4 ++++ .../osmand/plus/routing/TransportRoutingHelper.java | 2 +- 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7012075c66..0c21c1b494 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Native PT routing development + Switch to Java (safe) Public Transport routing calculation Unsupported action %1$s Extra maps Payment will be charged to your Google Play account at the confirmation of purchase.\n\nSubscription automatically renews unless it is canceled before the renewal date. Your account will be charged for renewal period(month/three month/year) only on the renewal date.\n\nYou can manage and cancel your subscriptions by going to your Google Play settings. diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 457052796b..ecd4a25c08 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -859,10 +859,12 @@ public class AppInitializer implements IProgress { OsmandSettings osmandSettings = app.getSettings(); if (osmandSettings.NATIVE_RENDERING_FAILED.get()) { osmandSettings.SAFE_MODE.set(true); + osmandSettings.PT_SAFE_MODE.set(true); osmandSettings.NATIVE_RENDERING_FAILED.set(false); warnings.add(app.getString(R.string.native_library_not_supported)); } else { osmandSettings.SAFE_MODE.set(false); + osmandSettings.PT_SAFE_MODE.set(false); osmandSettings.NATIVE_RENDERING_FAILED.set(true); startTask(app.getString(R.string.init_native_library), -1); RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer(); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 462b61dc32..10f6bbf6df 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -3692,7 +3692,7 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference SAFE_MODE = new BooleanPreference("safe_mode", false).makeGlobal(); - + public final OsmandPreference PT_SAFE_MODE = new BooleanPreference("pt_safe_mode", false).makeGlobal(); public final OsmandPreference NATIVE_RENDERING_FAILED = new BooleanPreference("native_rendering_failed_init", false).makeGlobal(); public final OsmandPreference USE_OPENGL_RENDER = new BooleanPreference("use_opengl_render", diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 70e70efb15..470448a996 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -500,12 +500,17 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR misc.addPreference(applicationDir); CheckBoxPreference nativeCheckbox = createCheckBoxPreference(settings.SAFE_MODE, R.string.safe_mode, R.string.safe_mode_description); + CheckBoxPreference nativePTCheckbox = createCheckBoxPreference(settings.PT_SAFE_MODE, + R.string.pt_native_development, R.string.pt_native_development_descr); // disable the checkbox if the library cannot be used if ((NativeOsmandLibrary.isLoaded() && !NativeOsmandLibrary.isSupported()) || settings.NATIVE_RENDERING_FAILED.get()) { nativeCheckbox.setEnabled(false); nativeCheckbox.setChecked(true); + nativePTCheckbox.setEnabled(false); + nativePTCheckbox.setChecked(true); } misc.addPreference(nativeCheckbox); + misc.addPreference(nativePTCheckbox); int nav = getResources().getConfiguration().navigation; if (nav == Configuration.NAVIGATION_DPAD || nav == Configuration.NAVIGATION_TRACKBALL || diff --git a/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java b/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java index 549914ca09..f893d22050 100644 --- a/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java @@ -35,6 +35,7 @@ public class DevelopmentSettingsFragment extends BaseSettingsFragment { setupOpenglRenderPref(); setupSafeModePref(); + setupPTSafeMode(); setupDisableComplexRoutingPref(); setupFastRecalculationPref(); @@ -81,6 +82,18 @@ public class DevelopmentSettingsFragment extends BaseSettingsFragment { } } + private void setupPTSafeMode() { + SwitchPreferenceEx ptSafeMode = (SwitchPreferenceEx) findPreference(settings.PT_SAFE_MODE.getId()); + if (!Version.isBlackberry(app)) { + ptSafeMode.setDescription(getString(R.string.pt_native_development_descr)); + ptSafeMode.setIconSpaceReserved(false); + if ((NativeOsmandLibrary.isLoaded() && !NativeOsmandLibrary.isSupported()) || settings.NATIVE_RENDERING_FAILED.get()) { + ptSafeMode.setEnabled(false); + ptSafeMode.setChecked(true); + } + } + } + private void setupDisableComplexRoutingPref() { SwitchPreferenceEx disableComplexRouting = (SwitchPreferenceEx) findPreference(settings.DISABLE_COMPLEX_ROUTING.getId()); disableComplexRouting.setDescription(getString(R.string.disable_complex_routing_descr)); diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index af8c1969fb..0a8678700d 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -42,12 +42,16 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { if (!Version.isBlackberry(app)) { CheckBoxPreference nativeCheckbox = createCheckBoxPreference(settings.SAFE_MODE, R.string.safe_mode, R.string.safe_mode_description); + CheckBoxPreference nativePTCheckbox = createCheckBoxPreference(settings.PT_SAFE_MODE, R.string.pt_native_development, R.string.pt_native_development_descr); // disable the checkbox if the library cannot be used if ((NativeOsmandLibrary.isLoaded() && !NativeOsmandLibrary.isSupported()) || settings.NATIVE_RENDERING_FAILED.get()) { nativeCheckbox.setEnabled(false); nativeCheckbox.setChecked(true); + nativePTCheckbox.setEnabled(false); + nativePTCheckbox.setChecked(true); } cat.addPreference(nativeCheckbox); + cat.addPreference(nativePTCheckbox); } PreferenceCategory navigation = new PreferenceCategory(this); diff --git a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java index 8a4ff015c8..822f1dac85 100644 --- a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java @@ -494,7 +494,7 @@ public class TransportRoutingHelper { TransportRoutePlanner planner = new TransportRoutePlanner(); TransportRoutingContext ctx = new TransportRoutingContext(cfg, library, files); ctx.calculationProgress = params.calculationProgress; - if (ctx.library != null) { + if (ctx.library != null && !settings.PT_SAFE_MODE.get()) { NativeTransportRoutingResult[] nativeRes = library.runNativePTRouting( MapUtils.get31TileNumberX(params.start.getLongitude()), MapUtils.get31TileNumberY(params.start.getLatitude()), From dd9e9ec9f21066c63a7d06dfb4c9a9745478d700 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Tue, 28 Apr 2020 16:26:08 +0300 Subject: [PATCH 2/3] add native pt setting to dev plugin fix no result crash --- .../java/net/osmand/router/TransportRoutePlanner.java | 3 +++ OsmAnd/res/values/strings.xml | 2 -- OsmAnd/res/xml/development_settings.xml | 7 +++++++ OsmAnd/src/net/osmand/plus/AppInitializer.java | 1 - .../osmand/plus/activities/SettingsGeneralActivity.java | 5 ----- .../plus/development/DevelopmentSettingsFragment.java | 8 +++----- .../plus/development/SettingsDevelopmentActivity.java | 4 +--- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index 0f43079c89..d55a7e8087 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -972,6 +972,9 @@ public class TransportRoutePlanner { public static List convertToTransportRoutingResult(NativeTransportRoutingResult[] res, TransportRoutingConfiguration cfg) { + if (res.length == 0) { + return new ArrayList(); + } List convertedRes = new ArrayList(); for (NativeTransportRoutingResult ntrr : res) { TransportRouteResult trr = new TransportRouteResult(cfg); diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0c21c1b494..7012075c66 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,8 +11,6 @@ Thx - Hardy --> - Native PT routing development - Switch to Java (safe) Public Transport routing calculation Unsupported action %1$s Extra maps Payment will be charged to your Google Play account at the confirmation of purchase.\n\nSubscription automatically renews unless it is canceled before the renewal date. Your account will be charged for renewal period(month/three month/year) only on the renewal date.\n\nYou can manage and cancel your subscriptions by going to your Google Play settings. diff --git a/OsmAnd/res/xml/development_settings.xml b/OsmAnd/res/xml/development_settings.xml index 6382759667..d01a1f169d 100644 --- a/OsmAnd/res/xml/development_settings.xml +++ b/OsmAnd/res/xml/development_settings.xml @@ -25,6 +25,13 @@ android:summaryOn="@string/shared_string_enabled" android:title="@string/safe_mode" /> + + Date: Tue, 28 Apr 2020 15:29:15 +0200 Subject: [PATCH 3/3] Update AppInitializer.java --- OsmAnd/src/net/osmand/plus/AppInitializer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 4d8e243e1f..457052796b 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -863,7 +863,6 @@ public class AppInitializer implements IProgress { warnings.add(app.getString(R.string.native_library_not_supported)); } else { osmandSettings.SAFE_MODE.set(false); - osmandSettings.PT_SAFE_MODE.set(false); osmandSettings.NATIVE_RENDERING_FAILED.set(true); startTask(app.getString(R.string.init_native_library), -1); RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();