From 0fbf6ea096bc816062e3eef3f72544a01264dbd4 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Mon, 10 Jul 2023 12:00:01 +0200 Subject: [PATCH 1/2] add a silent mode for app start --- .../btools/routingapp/BRouterActivity.java | 26 ++++++++++++++----- .../java/btools/routingapp/BRouterView.java | 14 +++++++--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java index 809b8fc..1dca201 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java @@ -77,6 +77,8 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat private String errorMessage; private String title; private int wpCount; + private boolean startSilent; + ActivityResultLauncher someActivityResultLauncher; /** @@ -115,9 +117,12 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); int memoryClass = am.getMemoryClass(); + Intent i = getIntent(); + if (i.hasExtra("runsilent")) startSilent = true; + // startQuiete = true; // instantiate our simulation view and set it as the activity's content mBRouterView = new BRouterView(this, memoryClass); - mBRouterView.init(); + mBRouterView.init(startSilent); setContentView(mBRouterView); } @@ -139,7 +144,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat case DIALOG_MAINACTION_ID: builder.setTitle("Select Main Action"); builder.setItems( - new String[] { "Download Manager", "BRouter App" }, + new String[]{"Download Manager", "BRouter App"}, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) @@ -238,7 +243,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String basedir = input.getText().toString(); - mBRouterView.startSetup(new File(basedir), true); + mBRouterView.startSetup(new File(basedir), true, false); } }); return builder.create(); @@ -254,7 +259,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (selectedBasedir < availableBasedirs.size()) { - mBRouterView.startSetup(availableBasedirs.get(selectedBasedir), true); + mBRouterView.startSetup(availableBasedirs.get(selectedBasedir), true, false); } else { showADialog(DIALOG_TEXTENTRY_ID); } @@ -530,7 +535,14 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat basedirOptions[bdidx] = "Enter path manually"; } - showADialog(DIALOG_SELECTBASEDIR_ID); + if (startSilent) { + mBRouterView.startSetup(availableBasedirs.get(0), true, startSilent); + Intent intent = new Intent(BRouterActivity.this, BInstallerActivity.class); + startActivity(intent); + finish(); + } else { + showADialog(DIALOG_SELECTBASEDIR_ID); + } } public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message) { @@ -650,9 +662,9 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - mBRouterView.startSetup(null, true); + mBRouterView.startSetup(null, true, false); } else { - mBRouterView.init(); + mBRouterView.init(false); } } } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java index 9655345..e2ea815 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java @@ -90,7 +90,7 @@ public class BRouterView extends View { if (cr != null) cr.terminate(); } - public void init() { + public void init(boolean silent) { try { // get base dir from private file File baseDir = ConfigHelper.getBaseDir(getContext()); @@ -107,7 +107,7 @@ public class BRouterView extends View { String version = "v" + getContext().getString(R.string.app_version); File vFile = new File(brd, "profiles2/" + version); if (vFile.exists()) { - startSetup(baseDir, false); + startSetup(baseDir, false, silent); return; } String message = "(previous basedir " + baseDir + " has to migrate )"; @@ -117,7 +117,7 @@ public class BRouterView extends View { waitingForMigration = true; oldMigrationPath = brd.getAbsolutePath(); } else { - startSetup(baseDir, false); + startSetup(baseDir, false, silent); } return; } @@ -137,7 +137,7 @@ public class BRouterView extends View { } } - public void startSetup(File baseDir, boolean storeBasedir) { + public void startSetup(File baseDir, boolean storeBasedir, boolean silent) { if (baseDir == null) { baseDir = retryBaseDir; retryBaseDir = null; @@ -239,6 +239,12 @@ public class BRouterView extends View { throw new IllegalArgumentException("The profile-directory " + profileDir + " contains no routing profiles (*.brf)." + " see brouter.de/brouter for setup instructions."); } + if (silent) { + Intent intent = new Intent(getContext(), BInstallerActivity.class); + getContext().startActivity(intent); + return; + }; + if (!RoutingHelper.hasDirectoryAnyDatafiles(segmentDir)) { ((BRouterActivity) getContext()).startDownloadManager(); waitingForSelection = true; From c02ebecf65b32bd816a92afda8a9f2a910535659 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Mon, 10 Jul 2023 12:12:03 +0200 Subject: [PATCH 2/2] add doc for silent mode --- docs/developers/android_service.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/developers/android_service.md b/docs/developers/android_service.md index 36da40c..49eab71 100644 --- a/docs/developers/android_service.md +++ b/docs/developers/android_service.md @@ -46,6 +46,19 @@ For the app it is a list of params concatenated by '&'. E.g. extraParams=avoidfe The server calls profile params by a prefix 'profile:'. E.g. ...&profile:avoidferry=1&profile:avoidsteps=0 +### silent app call + +The app can be started from other apps by using a call like this + +``` +Intent intent = new Intent(); +intent.setClassName("btools.routingapp", "btools.routingapp.BRouterActivity"); +intent.putExtra("runsilent", true); +startActivity(intent); +``` + +This suppress the first question after installation for the BRouter path, generates the BRouter folders in main space and starts the download dialog. + ## other routing engine modes in app ### get elevation