Start app changed

This commit is contained in:
jens 2021-05-08 15:14:31 +02:00
parent 22533fcfee
commit 769f227689
6 changed files with 186 additions and 100 deletions

View File

@ -373,7 +373,7 @@ public class Action
Actions.setDisplayRotation(context, getParameter1(), toggleActionIfPossible); Actions.setDisplayRotation(context, getParameter1(), toggleActionIfPossible);
break; break;
case startOtherActivity: case startOtherActivity:
Actions.startOtherActivity(getParameter2()); Actions.startOtherActivity(getParameter1(), getParameter2());
break; break;
case waitBeforeNextAction: case waitBeforeNextAction:
Actions.waitBeforeNextAction(Long.parseLong(this.getParameter2())); Actions.waitBeforeNextAction(Long.parseLong(this.getParameter2()));

View File

@ -568,33 +568,54 @@ 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); Miscellaneous.logEvent("i", "StartOtherActivity", "Starting other Activity...", 4);
String packageName, className;
String params[] = param.split(";"); String params[] = param.split(";");
try
{
Intent externalActivityIntent;
int paramsStartIndex;
if(byActivity)
{
// selected by activity
String packageName, className;
packageName = params[0]; packageName = params[0];
className = params[1]; className = params[1];
try Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3);
{
Miscellaneous.logEvent("i", "StartOtherApp", "Starting " + packageName + " " + className, 3); paramsStartIndex = 2;
Intent externalActivityIntent = new Intent(Intent.ACTION_MAIN);
externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); externalActivityIntent = new Intent(Intent.ACTION_MAIN);
externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER); externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
if(packageName.equals("dummyPkg")) // if(packageName.equals("dummyPkg"))
externalActivityIntent.setAction(className); // externalActivityIntent.setAction(className);
else // else
externalActivityIntent.setClassName(packageName, className); externalActivityIntent.setClassName(packageName, className);
if(Miscellaneous.doesActivityExist(externalActivityIntent, Miscellaneous.getAnyContext())) if(!Miscellaneous.doesActivityExist(externalActivityIntent, Miscellaneous.getAnyContext()))
Miscellaneous.logEvent("w", "StartOtherApp", "Activity not found: " + className, 2);
}
else
{ {
// has intent values to deliver // selected by action
for (int i = 2; i < params.length; i++) 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("/"); String[] singleParam = params[i].split("/");
@ -662,14 +683,10 @@ public class Actions
Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3);
} }
// autoMationServerRef.sendBroadcast(externalActivityIntent);
autoMationServerRef.startActivity(externalActivityIntent); autoMationServerRef.startActivity(externalActivityIntent);
} }
else catch(Exception e)
{
Miscellaneous.logEvent("w", "StartOtherApp", "Activity not found: " + className, 2);
}
}
catch(ActivityNotFoundException | SecurityException e)
{ {
Miscellaneous.logEvent("e", "StartOtherApp", autoMationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + Log.getStackTraceString(e), 2); 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(); Toast.makeText(autoMationServerRef, autoMationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + e.getMessage(), Toast.LENGTH_LONG).show();

View File

@ -24,6 +24,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -43,6 +44,7 @@ public class ActivityManageActionStartActivity extends Activity
Spinner spinnerParameterType; Spinner spinnerParameterType;
boolean edit = false; boolean edit = false;
ProgressDialog progressDialog = null; ProgressDialog progressDialog = null;
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction;
private class CustomPackageInfo extends PackageInfo implements Comparable<CustomPackageInfo> private class CustomPackageInfo extends PackageInfo implements Comparable<CustomPackageInfo>
{ {
@ -289,6 +291,8 @@ public class ActivityManageActionStartActivity extends Activity
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity); bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType); spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType);
etSelectedActivity = (EditText) findViewById(R.id.etSelectedApplication); etSelectedActivity = (EditText) findViewById(R.id.etSelectedApplication);
rbStartAppSelectByActivity = (RadioButton)findViewById(R.id.rbStartAppSelectByActivity);
rbStartAppSelectByAction = (RadioButton)findViewById(R.id.rbStartAppSelectByAction);
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes); intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes);
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter); spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
@ -407,16 +411,29 @@ public class ActivityManageActionStartActivity extends Activity
private void loadValuesIntoGui() private void loadValuesIntoGui()
{ {
String[] params = resultingAction.getParameter2().split(";"); boolean selectionByActivity = resultingAction.getParameter1();
if(params.length >= 2) rbStartAppSelectByActivity.setChecked(selectionByActivity);
{ rbStartAppSelectByAction.setChecked(!selectionByActivity);
etSelectedActivity.setText(params[0] + ";" + params[1]);
if(params.length > 2) String[] params = resultingAction.getParameter2().split(";");
if(selectionByActivity)
etSelectedActivity.setText(params[0] + ";" + params[1]);
else
etSelectedActivity.setText(params[0]);
int startIndex = -1;
if(selectionByActivity && params.length >= 2)
startIndex = 2;
else if(!selectionByActivity && params.length >= 1)
startIndex = 1;
if(startIndex > -1 && params.length > startIndex)
{ {
intentPairList.clear(); intentPairList.clear();
for(int i=2; i<params.length; i++) for(int i=startIndex; i<params.length; i++)
{ {
if(lvIntentPairs.getVisibility() != View.VISIBLE) if(lvIntentPairs.getVisibility() != View.VISIBLE)
lvIntentPairs.setVisibility(View.VISIBLE); lvIntentPairs.setVisibility(View.VISIBLE);
@ -427,7 +444,6 @@ public class ActivityManageActionStartActivity extends Activity
updateIntentPairList(); updateIntentPairList();
} }
} }
}
private void updateIntentPairList() private void updateIntentPairList()
{ {
@ -464,14 +480,16 @@ public class ActivityManageActionStartActivity extends Activity
if(resultingAction == null) if(resultingAction == null)
resultingAction = new Action(); resultingAction = new Action();
resultingAction.setParameter1(rbStartAppSelectByActivity.isChecked());
resultingAction.setAction(Action_Enum.startOtherActivity); resultingAction.setAction(Action_Enum.startOtherActivity);
String parameter2; String parameter2;
if(etSelectedActivity.getText().toString().contains(";")) // if(etSelectedActivity.getText().toString().contains(";"))
parameter2 = etSelectedActivity.getText().toString(); parameter2 = etSelectedActivity.getText().toString();
else // else
parameter2 = "dummyPkg;" + etSelectedActivity.getText().toString(); // parameter2 = "dummyPkg;" + etSelectedActivity.getText().toString();
for(String s : intentPairList) for(String s : intentPairList)
parameter2 += ";" + s; parameter2 += ";" + s;

View File

@ -1225,6 +1225,22 @@ public class XmlFileInterface
} }
} }
} }
else if(newAction.getAction().equals(Action_Enum.startOtherActivity)) // read old entries where parameter1 was not in use, yet to distinguish between call by activity and call by action
{
String[] contents = tag.split(";");
if(contents.length == 1)
newAction.setParameter1(false);
else if(contents.length == 2)
{
if(contents[1].contains("/"))
newAction.setParameter1(false);
else
newAction.setParameter1(true);
}
newAction.setParameter2(tag);
}
else else
newAction.setParameter2(tag); newAction.setParameter2(tag);
} }

View File

@ -31,6 +31,38 @@
</TableRow> </TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="@string/startAppSelectionType" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rbStartAppSelectByActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/startAppByActivity" />
<RadioButton
android:id="@+id/rbStartAppSelectByAction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/startAppByAction" />
</RadioGroup>
</TableRow>
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">

View File

@ -640,4 +640,7 @@
<string name="cantFindSoundFile">Cannot find sound file %1$s and therefore not play it.</string> <string name="cantFindSoundFile">Cannot find sound file %1$s and therefore not play it.</string>
<string name="addParameters">Add parameters</string> <string name="addParameters">Add parameters</string>
<string name="com.wireguard.android.permission.CONTROL_TUNNELS">Control tunnels of the wireguard app</string> <string name="com.wireguard.android.permission.CONTROL_TUNNELS">Control tunnels of the wireguard app</string>
<string name="startAppSelectionType">Method to\nselect application</string>
<string name="startAppByActivity">by activity</string>
<string name="startAppByAction">by action</string>
</resources> </resources>