From 769f22768900d47a4e7478f335bac392ff753bc1 Mon Sep 17 00:00:00 2001 From: jens Date: Sat, 8 May 2021 15:14:31 +0200 Subject: [PATCH] Start app changed --- .../java/com/jens/automation2/Action.java | 2 +- .../java/com/jens/automation2/Actions.java | 175 ++++++++++-------- .../ActivityManageActionStartActivity.java | 58 ++++-- .../jens/automation2/XmlFileInterface.java | 16 ++ .../main/res/layout/action_start_activity.xml | 32 ++++ app/src/main/res/values/strings.xml | 3 + 6 files changed, 186 insertions(+), 100 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index 0f95701..814aee8 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -373,7 +373,7 @@ public class Action Actions.setDisplayRotation(context, getParameter1(), toggleActionIfPossible); break; case startOtherActivity: - Actions.startOtherActivity(getParameter2()); + Actions.startOtherActivity(getParameter1(), getParameter2()); break; case waitBeforeNextAction: Actions.waitBeforeNextAction(Long.parseLong(this.getParameter2())); diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index bef7ddb..eeb8ebe 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -568,36 +568,57 @@ public class Actions } } - public static void startOtherActivity(String param) + public static void startOtherActivity(boolean byActivity, String param) { Miscellaneous.logEvent("i", "StartOtherActivity", "Starting other Activity...", 4); - String packageName, className; - String params[] = param.split(";"); - packageName = params[0]; - className = params[1]; - try { - Miscellaneous.logEvent("i", "StartOtherApp", "Starting " + packageName + " " + className, 3); - Intent externalActivityIntent = new Intent(Intent.ACTION_MAIN); - externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER); + Intent externalActivityIntent; - if(packageName.equals("dummyPkg")) - externalActivityIntent.setAction(className); - else - externalActivityIntent.setClassName(packageName, className); + int paramsStartIndex; - if(Miscellaneous.doesActivityExist(externalActivityIntent, Miscellaneous.getAnyContext())) + if(byActivity) { - // has intent values to deliver - for (int i = 2; i < params.length; i++) - { - String[] singleParam = params[i].split("/"); - + // selected by activity + + String packageName, className; + + packageName = params[0]; + className = params[1]; + + Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3); + + paramsStartIndex = 2; + + externalActivityIntent = new Intent(Intent.ACTION_MAIN); + externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER); + +// if(packageName.equals("dummyPkg")) +// externalActivityIntent.setAction(className); +// else + externalActivityIntent.setClassName(packageName, className); + + if(!Miscellaneous.doesActivityExist(externalActivityIntent, Miscellaneous.getAnyContext())) + Miscellaneous.logEvent("w", "StartOtherApp", "Activity not found: " + className, 2); + } + else + { + // selected by action + Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by action: " + param, 3); + paramsStartIndex = 1; + externalActivityIntent = new Intent(param); + } + + externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + // Pack intents + for (int i = paramsStartIndex = 2; i < params.length; i++) + { + String[] singleParam = params[i].split("/"); + /*Class c = Class.forName(singleParam[0]); for(Method m : c.getMethods()) { @@ -608,68 +629,64 @@ public class Actions } }*/ - if (singleParam[0].equals("boolean")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], Boolean.parseBoolean(singleParam[2])); - } - else if (singleParam[0].equals("byte")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], Byte.parseByte(singleParam[2])); - } - else if (singleParam[0].equals("char")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], singleParam[2].charAt(0)); - } - else if (singleParam[0].equals("CharSequence")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], (CharSequence) singleParam[2]); - } - else if (singleParam[0].equals("double")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], Double.parseDouble(singleParam[2])); - } - else if (singleParam[0].equals("float")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], Float.parseFloat(singleParam[2])); - } - else if (singleParam[0].equals("int")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], Integer.parseInt(singleParam[2])); - } - else if (singleParam[0].equals("long")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], Long.parseLong(singleParam[2])); - } - else if (singleParam[0].equals("short")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], Short.parseShort(singleParam[2])); - } - else if (singleParam[0].equals("String")) - { - Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); - externalActivityIntent.putExtra(singleParam[1], singleParam[2]); - } - else - Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3); + if (singleParam[0].equals("boolean")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Boolean.parseBoolean(singleParam[2])); } + else if (singleParam[0].equals("byte")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Byte.parseByte(singleParam[2])); + } + else if (singleParam[0].equals("char")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], singleParam[2].charAt(0)); + } + else if (singleParam[0].equals("CharSequence")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], (CharSequence) singleParam[2]); + } + else if (singleParam[0].equals("double")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Double.parseDouble(singleParam[2])); + } + else if (singleParam[0].equals("float")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Float.parseFloat(singleParam[2])); + } + else if (singleParam[0].equals("int")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Integer.parseInt(singleParam[2])); + } + else if (singleParam[0].equals("long")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Long.parseLong(singleParam[2])); + } + else if (singleParam[0].equals("short")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Short.parseShort(singleParam[2])); + } + else if (singleParam[0].equals("String")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], singleParam[2]); + } + else + Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3); + } - autoMationServerRef.startActivity(externalActivityIntent); - } - else - { - Miscellaneous.logEvent("w", "StartOtherApp", "Activity not found: " + className, 2); - } +// autoMationServerRef.sendBroadcast(externalActivityIntent); + autoMationServerRef.startActivity(externalActivityIntent); } - catch(ActivityNotFoundException | SecurityException e) + catch(Exception e) { Miscellaneous.logEvent("e", "StartOtherApp", autoMationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + Log.getStackTraceString(e), 2); Toast.makeText(autoMationServerRef, autoMationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + e.getMessage(), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java index 0ca7f48..16d45fe 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java @@ -24,6 +24,7 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; +import android.widget.RadioButton; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -43,6 +44,7 @@ public class ActivityManageActionStartActivity extends Activity Spinner spinnerParameterType; boolean edit = false; ProgressDialog progressDialog = null; + RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction; private class CustomPackageInfo extends PackageInfo implements Comparable { @@ -289,6 +291,8 @@ public class ActivityManageActionStartActivity extends Activity bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity); spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType); etSelectedActivity = (EditText) findViewById(R.id.etSelectedApplication); + rbStartAppSelectByActivity = (RadioButton)findViewById(R.id.rbStartAppSelectByActivity); + rbStartAppSelectByAction = (RadioButton)findViewById(R.id.rbStartAppSelectByAction); intentTypeSpinnerAdapter = new ArrayAdapter(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes); spinnerParameterType.setAdapter(intentTypeSpinnerAdapter); @@ -407,25 +411,37 @@ public class ActivityManageActionStartActivity extends Activity private void loadValuesIntoGui() { - String[] params = resultingAction.getParameter2().split(";"); - if(params.length >= 2) - { - etSelectedActivity.setText(params[0] + ";" + params[1]); - - if(params.length > 2) - { - intentPairList.clear(); - - for(int i=2; i= 2) + startIndex = 2; + else if(!selectionByActivity && params.length >= 1) + startIndex = 1; + + if(startIndex > -1 && params.length > startIndex) + { + intentPairList.clear(); + + for(int i=startIndex; i + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 944ef59..19f3784 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -640,4 +640,7 @@ Cannot find sound file %1$s and therefore not play it. Add parameters Control tunnels of the wireguard app + Method to\nselect application + by activity + by action \ No newline at end of file