From e39f0c24979f0d3a7db953243df9519594af643b Mon Sep 17 00:00:00 2001 From: jens Date: Tue, 11 May 2021 20:00:50 +0200 Subject: [PATCH] startApp changes --- .../java/com/jens/automation2/Action.java | 5 +++ .../java/com/jens/automation2/Actions.java | 17 ++++++- .../ActivityManageActionStartActivity.java | 28 ++++++++++-- .../jens/automation2/XmlFileInterface.java | 7 +++ .../main/res/layout/activity_maintenance.xml | 44 ++++++++++++++++--- ...activity_manage_action_start_activity.xml} | 13 +++++- ...t_view_for_poi_listview_mediumtextsize.xml | 2 +- app/src/main/res/values/strings.xml | 3 ++ 8 files changed, 106 insertions(+), 13 deletions(-) rename app/src/main/res/layout/{action_start_activity.xml => activity_manage_action_start_activity.xml} (95%) diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index 814aee8a..98b07843 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -15,6 +15,7 @@ import java.util.Locale; public class Action { public static final String actionParameter2Split = "ap2split"; + public static final String intentPairSeperator = "intPairSplit"; public enum Action_Enum { setWifi, @@ -237,6 +238,10 @@ public class Action else returnString.append(": " + components[0]); } + else if(this.getAction().equals(Action_Enum.startOtherActivity)) + { + returnString.append(": " + parameter2.replace(Action.intentPairSeperator, "/")); + } else if(this.getAction().equals(Action_Enum.sendTextMessage)) { String[] components = parameter2.split(Actions.smsSeparator); diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index 0249eaab..a4ec06bb 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -611,7 +611,7 @@ public class Actions externalActivityIntent = new Intent(); - if(params.length > 1 && !params[1].contains("/")) + if(params.length > 1 && !params[1].contains(Action.intentPairSeperator)) { externalActivityIntent.setPackage(params[0]); externalActivityIntent.setAction(params[1]); @@ -629,7 +629,7 @@ public class Actions // Pack intents for (int i = paramsStartIndex; i < params.length; i++) { - String[] singleParam = params[i].split("/"); + String[] singleParam = params[i].split(Action.intentPairSeperator); /*Class c = Class.forName(singleParam[0]); for(Method m : c.getMethods()) @@ -686,6 +686,19 @@ public class Actions 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("Uri")) + { + if(singleParam[1].equalsIgnoreCase("IntentData")) + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with value " + singleParam[2] + " as standard data parameter.", 3); + externalActivityIntent.setData(Uri.parse(singleParam[2])); + } + else + { + Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); + externalActivityIntent.putExtra(singleParam[1], Uri.parse(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); diff --git a/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java index da12ac2c..2439dbc4 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java @@ -73,7 +73,7 @@ public class ActivityManageActionStartActivity extends Activity private static List pInfos = null; public static Action resultingAction; - private static final String[] supportedIntentTypes = { "boolean", "byte", "char", "double", "float", "int", "long", "short", "String" }; + private static final String[] supportedIntentTypes = { "boolean", "byte", "char", "double", "float", "int", "long", "short", "String", "Uri" }; private ArrayList intentPairList = new ArrayList(); ArrayAdapter intentTypeSpinnerAdapter, intentPairAdapter; @@ -281,7 +281,7 @@ public class ActivityManageActionStartActivity extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.action_start_activity); + setContentView(R.layout.activity_manage_action_start_activity); lvIntentPairs = (ListView)findViewById(R.id.lvIntentPairs); etParameterName = (EditText)findViewById(R.id.etParameterName); @@ -329,14 +329,34 @@ public class ActivityManageActionStartActivity extends Activity Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterNameForIntentPair), Toast.LENGTH_LONG).show(); return; } + else if(etParameterName.getText().toString().contains(Action.intentPairSeperator)) + { + Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeperator), Toast.LENGTH_LONG).show(); + return; + } + else if(etParameterName.getText().toString().contains(";")) + { + Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show(); + return; + } if(etParameterValue.getText().toString().length() == 0) { Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterValueForIntentPair), Toast.LENGTH_LONG).show(); return; } + else if(etParameterValue.getText().toString().contains(Action.intentPairSeperator)) + { + Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeperator), Toast.LENGTH_LONG).show(); + return; + } + else if(etParameterValue.getText().toString().contains(";")) + { + Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show(); + return; + } - String param = supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()] + "/" + etParameterName.getText().toString() + "/" + etParameterValue.getText().toString(); + String param = supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()] + Action.intentPairSeperator + etParameterName.getText().toString() + Action.intentPairSeperator + etParameterValue.getText().toString(); intentPairList.add(param); spinnerParameterType.setSelection(0); @@ -455,7 +475,7 @@ public class ActivityManageActionStartActivity extends Activity { if(params.length > 1) // should not occur, have fault tollerance { - if(params[1].contains("/")) + if(params[1].contains(Action.intentPairSeperator)) { etActivityOrActionPath.setText(params[0]); startIndex = 1; diff --git a/app/src/main/java/com/jens/automation2/XmlFileInterface.java b/app/src/main/java/com/jens/automation2/XmlFileInterface.java index ceb2c439..ad35eb73 100644 --- a/app/src/main/java/com/jens/automation2/XmlFileInterface.java +++ b/app/src/main/java/com/jens/automation2/XmlFileInterface.java @@ -1158,6 +1158,13 @@ public class XmlFileInterface } } } + else if(newAction.getAction().equals(Action_Enum.startOtherActivity)) // separator has been changed, convert in old files + { + if(tag.contains(Action.intentPairSeperator)) // already has new format + newAction.setParameter2(tag); + else + newAction.setParameter2(tag.replace("/", Action.intentPairSeperator)); + } else newAction.setParameter2(tag); } diff --git a/app/src/main/res/layout/activity_maintenance.xml b/app/src/main/res/layout/activity_maintenance.xml index 4882733c..ae9719a8 100644 --- a/app/src/main/res/layout/activity_maintenance.xml +++ b/app/src/main/res/layout/activity_maintenance.xml @@ -10,7 +10,26 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.AppCompat.Headline" - android:text="@string/settings" /> + android:text="@string/settings" + android:layout_marginBottom="@dimen/default_margin"/> + +