From 158dc5e54d3e94d0693730e960556b2cc245fa83 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Fri, 15 Dec 2023 14:01:13 +0100 Subject: [PATCH 1/3] do only compress gpx/json --- .../src/main/java/btools/routingapp/BRouterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java index 90b875c..3e4f55e 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java @@ -100,7 +100,7 @@ public class BRouterService extends Service { boolean canCompress = "true".equals(params.getString("acceptCompressedResult")); try { String gpxMessage = worker.getTrackFromParams(params); - if (canCompress) { + if (canCompress && (gpxMessage.startsWith("<") || gpxMessage.startsWith("{"))) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write("z64".getBytes(Charset.forName("UTF-8"))); // marker prefix From 9ef31e6d2c76663f0901ec724b8f9d09581de17b Mon Sep 17 00:00:00 2001 From: afischerdev Date: Fri, 15 Dec 2023 14:10:20 +0100 Subject: [PATCH 2/3] remove profile param when handled in app --- .../src/main/java/btools/routingapp/BRouterService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java index 3e4f55e..1f16947 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java @@ -96,6 +96,8 @@ public class BRouterService extends Service { if (errMsg != null) { return errMsg; } + // profile is already done + params.remove("profile"); boolean canCompress = "true".equals(params.getString("acceptCompressedResult")); try { From ec3461d8a237e8c3cddb8dc27d4a312fe1daccf4 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Fri, 15 Dec 2023 14:25:03 +0100 Subject: [PATCH 3/3] changed handle back pressed logic --- .../routingapp/RoutingParameterDialog.java | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/RoutingParameterDialog.java b/brouter-routing-app/src/main/java/btools/routingapp/RoutingParameterDialog.java index 8eb4365..356e2d3 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/RoutingParameterDialog.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/RoutingParameterDialog.java @@ -10,6 +10,7 @@ import android.os.Bundle; import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedDispatcher; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -168,41 +169,52 @@ public class RoutingParameterDialog extends AppCompatActivity { new OnBackInvokedCallback() { @Override public void onBackInvoked() { - StringBuilder sb = null; - if (sharedValues != null) { - // fill preference with used params - // for direct use in the BRouter interface "extraParams" - sb = new StringBuilder(); - for (Map.Entry entry : sharedValues.getAll().entrySet()) { - if (!entry.getKey().equals("params")) { - sb.append(sb.length() > 0 ? "&" : "") - .append(entry.getKey()) - .append("="); - String s = entry.getValue().toString(); - if (s.equals("true")) s = "1"; - else if (s.equals("false")) s = "0"; - sb.append(s); - } - } - } - // and return the array - // one should be enough - Intent i = new Intent(); - // i.putExtra("PARAMS", listParams); - i.putExtra("PROFILE", profile); - i.putExtra("PROFILE_HASH", profile_hash); - if (sb != null) i.putExtra("PARAMS_VALUES", sb.toString()); - - setResult(Activity.RESULT_OK, i); - finish(); + handleBackPressed(); } } ); - - + } else { + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + handleBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); } } + private void handleBackPressed() { + StringBuilder sb = null; + if (sharedValues != null) { + // fill preference with used params + // for direct use in the BRouter interface "extraParams" + sb = new StringBuilder(); + for (Map.Entry entry : sharedValues.getAll().entrySet()) { + if (!entry.getKey().equals("params")) { + sb.append(sb.length() > 0 ? "&" : "") + .append(entry.getKey()) + .append("="); + String s = entry.getValue().toString(); + if (s.equals("true")) s = "1"; + else if (s.equals("false")) s = "0"; + sb.append(s); + } + } + } + // and return the array + // one should be enough + Intent i = new Intent(); + // i.putExtra("PARAMS", listParams); + i.putExtra("PROFILE", profile); + i.putExtra("PROFILE_HASH", profile_hash); + if (sb != null) i.putExtra("PARAMS_VALUES", sb.toString()); + + setResult(Activity.RESULT_OK, i); + finish(); + + } + @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig);