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);
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
{
try
{
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)
try

View File

@ -2,7 +2,9 @@ package com.jens.automation2;
import android.content.Context;
import android.os.AsyncTask;
import android.text.style.TabStopSpan;
import android.util.Log;
import android.widget.Toast;
import org.apache.http.client.methods.HttpGet;
@ -329,6 +331,8 @@ public class Action
}
public void run(Context context, boolean toggleActionIfPossible)
{
try
{
switch(this.getAction())
{
@ -346,7 +350,7 @@ public class Action
// else
// {
Profile p = Profile.getByName(this.getParameter2());
if(p != null)
if (p != null)
p.activate(context);
// }
break;
@ -412,6 +416,12 @@ public class Action
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)
{

View File

@ -36,6 +36,7 @@ import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.util.InetAddressUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetAddress;
@ -475,6 +476,9 @@ public class Actions
{
MediaPlayer mp = new MediaPlayer();
try
{
File file = new File(soundFileLocation);
if(file.exists())
{
Uri fileUri = Uri.parse(soundFileLocation);
mp.setLooping(false);
@ -490,6 +494,12 @@ public class Actions
mp.prepare();
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)
{
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);
String packageName, className;
String params[] = param.split(";");
packageName = params[0];
className = params[1];
@ -571,6 +583,10 @@ public class Actions
Intent externalActivityIntent = new Intent(Intent.ACTION_MAIN);
externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
if(packageName.equals("dummyPkg"))
externalActivityIntent.setAction(className);
else
externalActivityIntent.setClassName(packageName, className);
// has intent values to deliver

View File

@ -38,10 +38,9 @@ import java.util.List;
public class ActivityManageActionStartActivity extends Activity
{
ListView lvIntentPairs;
EditText etParameterName, etParameterValue;
EditText etParameterName, etParameterValue, etSelectedActivity;
Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity;
Spinner spinnerParameterType;
TextView tvSelectedActivity;
boolean edit = false;
ProgressDialog progressDialog = null;
@ -268,7 +267,7 @@ public class ActivityManageActionStartActivity extends Activity
public void onClick(DialogInterface dialog, int which)
{
ActivityInfo ai = ActivityManageActionStartActivity.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]);
tvSelectedActivity.setText(ai.packageName + ";" + ai.name);
etSelectedActivity.setText(ai.packageName + ";" + ai.name);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
@ -289,13 +288,13 @@ public class ActivityManageActionStartActivity extends Activity
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
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);
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
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()
{
@ -408,7 +407,7 @@ public class ActivityManageActionStartActivity extends Activity
String[] params = resultingAction.getParameter2().split(";");
if(params.length >= 2)
{
tvSelectedActivity.setText(params[0] + ";" + params[1]);
etSelectedActivity.setText(params[0] + ";" + params[1]);
if(params.length > 2)
{
@ -434,13 +433,23 @@ public class ActivityManageActionStartActivity extends Activity
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();
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();
return false;
@ -451,7 +460,13 @@ public class ActivityManageActionStartActivity extends Activity
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)
parameter2 += ";" + s;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<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:textSize="20sp">

View File

@ -635,4 +635,7 @@
<string name="noFileManageInstalled">No file manager installed.</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="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>