StartAppChanges

This commit is contained in:
jens 2021-04-09 17:39:59 +02:00
parent 13bcb02ffc
commit ee43e109da
11 changed files with 279 additions and 207 deletions

View File

@ -930,7 +930,16 @@ public class Rule implements Comparable<Rule>
publishProgress(message); publishProgress(message);
for(int i = 0; i< Rule.this.getActionSet().size(); i++) for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try
{
Rule.this.getActionSet().get(i).run(automationService, doToggle); Rule.this.getActionSet().get(i).run(automationService, doToggle);
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "RuleExecution", "Error running action of rule " + Rule.this.getName() + ": " + Log.getStackTraceString(e), 1);
}
}
// Keep log of last x rule activations (Settings) // Keep log of last x rule activations (Settings)
try try

View File

@ -2,7 +2,9 @@ package com.jens.automation2;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.text.style.TabStopSpan;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
@ -329,6 +331,8 @@ public class Action
} }
public void run(Context context, boolean toggleActionIfPossible) public void run(Context context, boolean toggleActionIfPossible)
{
try
{ {
switch(this.getAction()) switch(this.getAction())
{ {
@ -412,6 +416,12 @@ public class Action
break; break;
} }
} }
catch(Exception e)
{
Miscellaneous.logEvent("e", "ActionExecution", Log.getStackTraceString(e), 1);
Toast.makeText(context, context.getResources().getString(R.string.errorRunningRule), Toast.LENGTH_LONG).show();
}
}
private void triggerUrl(Context context) private void triggerUrl(Context context)
{ {

View File

@ -36,6 +36,7 @@ import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.util.InetAddressUtils; import org.apache.http.conn.util.InetAddressUtils;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetAddress; import java.net.InetAddress;
@ -475,6 +476,9 @@ public class Actions
{ {
MediaPlayer mp = new MediaPlayer(); MediaPlayer mp = new MediaPlayer();
try try
{
File file = new File(soundFileLocation);
if(file.exists())
{ {
Uri fileUri = Uri.parse(soundFileLocation); Uri fileUri = Uri.parse(soundFileLocation);
mp.setLooping(false); mp.setLooping(false);
@ -490,6 +494,12 @@ public class Actions
mp.prepare(); mp.prepare();
mp.start(); mp.start();
} }
else
{
Miscellaneous.logEvent("w", "Play sound file", "Sound file " + soundFileLocation + " does not exist. Can't play it.", 2);
Toast.makeText(context, String.format(context.getResources().getString(R.string.cantFindSoundFile), soundFileLocation), Toast.LENGTH_SHORT).show();
}
}
catch (Exception e) catch (Exception e)
{ {
Miscellaneous.logEvent("e", "Play sound file", "Error playing sound: " + Log.getStackTraceString(e), 2); Miscellaneous.logEvent("e", "Play sound file", "Error playing sound: " + Log.getStackTraceString(e), 2);
@ -561,7 +571,9 @@ public class Actions
Miscellaneous.logEvent("i", "StartOtherActivity", "Starting other Activity...", 4); Miscellaneous.logEvent("i", "StartOtherActivity", "Starting other Activity...", 4);
String packageName, className; String packageName, className;
String params[] = param.split(";"); String params[] = param.split(";");
packageName = params[0]; packageName = params[0];
className = params[1]; className = params[1];
@ -571,6 +583,10 @@ public class Actions
Intent externalActivityIntent = new Intent(Intent.ACTION_MAIN); Intent externalActivityIntent = new Intent(Intent.ACTION_MAIN);
externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER); externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
if(packageName.equals("dummyPkg"))
externalActivityIntent.setAction(className);
else
externalActivityIntent.setClassName(packageName, className); externalActivityIntent.setClassName(packageName, className);
// has intent values to deliver // has intent values to deliver

View File

@ -38,10 +38,9 @@ import java.util.List;
public class ActivityManageActionStartActivity extends Activity public class ActivityManageActionStartActivity extends Activity
{ {
ListView lvIntentPairs; ListView lvIntentPairs;
EditText etParameterName, etParameterValue; EditText etParameterName, etParameterValue, etSelectedActivity;
Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity; Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity;
Spinner spinnerParameterType; Spinner spinnerParameterType;
TextView tvSelectedActivity;
boolean edit = false; boolean edit = false;
ProgressDialog progressDialog = null; ProgressDialog progressDialog = null;
@ -268,7 +267,7 @@ public class ActivityManageActionStartActivity extends Activity
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
ActivityInfo ai = ActivityManageActionStartActivity.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]); ActivityInfo ai = ActivityManageActionStartActivity.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]);
tvSelectedActivity.setText(ai.packageName + ";" + ai.name); etSelectedActivity.setText(ai.packageName + ";" + ai.name);
} }
}); });
AlertDialog alertDialog = alertDialogBuilder.create(); AlertDialog alertDialog = alertDialogBuilder.create();
@ -289,13 +288,13 @@ public class ActivityManageActionStartActivity extends Activity
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair); bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity); bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType); spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType);
tvSelectedActivity = (TextView)findViewById(R.id.tvSelectedApplication); etSelectedActivity = (EditText) findViewById(R.id.etSelectedApplication);
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);
intentTypeSpinnerAdapter.notifyDataSetChanged(); intentTypeSpinnerAdapter.notifyDataSetChanged();
intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_smalltextsize, intentPairList); intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, intentPairList);
bSelectApp.setOnClickListener(new OnClickListener() bSelectApp.setOnClickListener(new OnClickListener()
{ {
@ -408,7 +407,7 @@ public class ActivityManageActionStartActivity extends Activity
String[] params = resultingAction.getParameter2().split(";"); String[] params = resultingAction.getParameter2().split(";");
if(params.length >= 2) if(params.length >= 2)
{ {
tvSelectedActivity.setText(params[0] + ";" + params[1]); etSelectedActivity.setText(params[0] + ";" + params[1]);
if(params.length > 2) if(params.length > 2)
{ {
@ -434,13 +433,23 @@ public class ActivityManageActionStartActivity extends Activity
private boolean saveAction() private boolean saveAction()
{ {
if(tvSelectedActivity.getText().toString().length() == 0) if(etSelectedActivity.getText().toString().length() == 0)
{ {
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show(); Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show();
return false; return false;
} }
// else
// {
// Intent testIntent = new Intent(ActivityManageActionStartActivity.this, etSelectedActivity);
// Intent externalActivityIntent = new Intent(Intent.ACTION_MAIN);
// externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// externalActivityIntent.setClassName(packageName, className);
//
// boolean activityExists = externalActivityIntent.resolveActivityInfo(getPackageManager(), 0) != null;
// }
if(tvSelectedActivity.getText().toString().equals(getResources().getString(R.string.selectApplication))) if(etSelectedActivity.getText().toString().equals(getResources().getString(R.string.selectApplication)))
{ {
Toast.makeText(this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show(); Toast.makeText(this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show();
return false; return false;
@ -451,7 +460,13 @@ public class ActivityManageActionStartActivity extends Activity
resultingAction.setAction(Action_Enum.startOtherActivity); resultingAction.setAction(Action_Enum.startOtherActivity);
String parameter2 = tvSelectedActivity.getText().toString(); String parameter2;
if(etSelectedActivity.getText().toString().contains(";"))
parameter2 = etSelectedActivity.getText().toString();
else
parameter2 = "dummyPkg;" + etSelectedActivity.getText().toString();
for(String s : intentPairList) for(String s : intentPairList)
parameter2 += ";" + s; parameter2 += ";" + s;

View File

@ -22,8 +22,6 @@ import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.jens.automation2.Action.Action_Enum;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -260,7 +258,7 @@ public class ActivityManageTriggerNotification extends Activity
bSaveTriggerNotification = (Button)findViewById(R.id.bSaveTriggerNotification); bSaveTriggerNotification = (Button)findViewById(R.id.bSaveTriggerNotification);
spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection); spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection);
spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection); spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection);
tvSelectedApplication = (TextView)findViewById(R.id.tvSelectedApplication); tvSelectedApplication = (TextView)findViewById(R.id.etSelectedApplication);
chkNotificationDirection = (CheckBox)findViewById(R.id.chkNotificationDirection); chkNotificationDirection = (CheckBox)findViewById(R.id.chkNotificationDirection);
directions = new String[] { directions = new String[] {

View File

@ -403,7 +403,7 @@ public class ActivityPermissions extends Activity
addToArrayListUnique("android.permission.ACCESS_NETWORK_STATE", requiredPermissions); addToArrayListUnique("android.permission.ACCESS_NETWORK_STATE", requiredPermissions);
break; break;
case batteryLevel: case batteryLevel:
addToArrayListUnique("android.permission.READ_PHONE_STATE", requiredPermissions); // addToArrayListUnique("android.permission.READ_PHONE_STATE", requiredPermissions);
// addToArrayListUnique("android.permission.BATTERY_STATS", requiredPermissions); // addToArrayListUnique("android.permission.BATTERY_STATS", requiredPermissions);
break; break;
case bluetoothConnection: case bluetoothConnection:

View File

@ -2,15 +2,21 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" > android:layout_margin="@dimen/default_margin" >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <TableLayout
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:stretchColumns="1"
android:shrinkColumns="1" >
<TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -20,42 +26,56 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/selectApplication" /> android:text="@string/selectApplication" />
<TextView <EditText
android:id="@+id/tvSelectedApplication" android:id="@+id/etSelectedApplication"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:text="" android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout> </TableRow>
<ImageView <TableRow
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="#aa000000" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="#aa000000"
android:visibility="invisible" />
<TextView <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/parameterType" android:inputType="textMultiLine"
android:layout_gravity="center_vertical"/> android:text="@string/startAppChoiceNote" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/parameterType" />
<Spinner <Spinner
android:id="@+id/spinnerParameterType" android:id="@+id/spinnerParameterType"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout </TableRow>
android:orientation="horizontal"
<TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/tvCurrentNfcIdValue" android:id="@+id/tvCurrentNfcIdValue"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -64,18 +84,15 @@
<EditText <EditText
android:id="@+id/etParameterName" android:id="@+id/etParameterName"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
android:ems="10" >
<requestFocus /> </TableRow>
</EditText>
</LinearLayout>
<LinearLayout <TableRow
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -84,10 +101,12 @@
<EditText <EditText
android:id="@+id/etParameterValue" android:id="@+id/etParameterValue"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
android:ems="10" />
</LinearLayout> </TableRow>
</TableLayout>
<Button <Button
android:id="@+id/bAddIntentPair" android:id="@+id/bAddIntentPair"
@ -109,9 +128,11 @@
<Button <Button
android:id="@+id/bSaveActionStartOtherActivity" android:id="@+id/bSaveActionStartOtherActivity"
android:layout_marginTop="@dimen/default_margin"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/save" /> android:text="@string/save" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -17,7 +17,7 @@
android:background="@color/barBackgroundColor" > android:background="@color/barBackgroundColor" >
<TextView <TextView
android:id="@+id/tvSelectedApplication" android:id="@+id/etSelectedApplication"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/general" android:text="@string/general"

View File

@ -59,7 +59,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/tvSelectedApplication" android:id="@+id/etSelectedApplication"
android:layout_marginHorizontal="@dimen/default_margin" android:layout_marginHorizontal="@dimen/default_margin"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="20sp"> android:textSize="20sp">

View File

@ -635,4 +635,7 @@
<string name="noFileManageInstalled">No file manager installed.</string> <string name="noFileManageInstalled">No file manager installed.</string>
<string name="shareConfigAndLogFilesWithDev">Share config and log files with developer (via email).</string> <string name="shareConfigAndLogFilesWithDev">Share config and log files with developer (via email).</string>
<string name="shareConfigAndLogExplanation">This will start a new email with your config and log files attached as zip file. It will not be sent automatically, you still need to hit \"send\". You can also change the recipient to yourself for example.</string> <string name="shareConfigAndLogExplanation">This will start a new email with your config and log files attached as zip file. It will not be sent automatically, you still need to hit \"send\". You can also change the recipient to yourself for example.</string>
<string name="startAppChoiceNote">You can enter an activity path manually, but it\'s recommended to use the \"Select\" button.\nIf you choose to enter something manually keep in mind no variables will be resolved. If you want to start the camera for example \"MediaStore.ACTION_IMAGE_CAPTURE\" will not work. You have to look at the Android documentation and use its value instead which would be \"android.media.action.IMAGE_CAPTURE\".</string>
<string name="errorRunningRule">There was an error running a rule.</string>
<string name="cantFindSoundFile">Cannot find sound file %1$s and therefore not play it.</string>
</resources> </resources>