variables as triggers and actions

This commit is contained in:
jens 2022-10-09 17:14:02 +02:00
parent 4abce042eb
commit c868d45896
21 changed files with 589 additions and 58 deletions

View File

@ -174,6 +174,9 @@
<activity android:name=".ActivityManageActionWakeLock" />
<activity android:name=".ActivityManageTriggerSubSystemState" />
<activity android:name=".ActivityManageActionMakePhoneCall" />
<activity android:name=".ActivityManageActionSetVariable" />
<activity android:name=".ActivityManageTriggerCheckVariable" />
<activity
android:name=".ActivityMainTabLayout"
android:launchMode="singleTask">

View File

@ -172,6 +172,8 @@
<activity android:name=".ActivityManageActionWakeLock" />
<activity android:name=".ActivityManageTriggerSubSystemState" />
<activity android:name=".ActivityManageMakePhoneCall" />
<activity android:name=".ActivityManageActionSetVariable" />
<activity android:name=".ActivityManageTriggerCheckVariable" />
<activity
android:name=".ActivityMainTabLayout"
android:launchMode="singleTask">

View File

@ -156,6 +156,8 @@
<activity android:name=".ActivityManageTriggerTethering" />
<activity android:name=".ActivityManageActionWakeLock" />
<activity android:name=".ActivityManageTriggerSubSystemState" />
<activity android:name=".ActivityManageActionSetVariable" />
<activity android:name=".ActivityManageTriggerCheckVariable" />
<activity
android:name=".ActivityMainTabLayout"
android:launchMode="singleTask">

View File

@ -52,6 +52,7 @@ public class Action
sendBroadcast,
runExecutable,
wakelock,
setVariable,
startPhoneCall,
stopPhoneCall,
sendTextMessage;
@ -130,6 +131,8 @@ public class Action
return context.getResources().getString(R.string.runExecutable);
case wakelock:
return context.getResources().getString(R.string.keepDeviceAwake);
case setVariable:
return context.getResources().getString(R.string.setVariable);
case startPhoneCall:
return context.getResources().getString(R.string.startPhoneCall);
case stopPhoneCall:
@ -283,6 +286,16 @@ public class Action
case wakelock:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.keepDeviceAwake) + " (" + String.valueOf(getParameter1()) + ")");
break;
case setVariable:
String[] variableParams = getParameter2().split(actionParameter2Split);
String addition;
if (variableParams.length >= 2)
addition = " (key: " + variableParams[0] + ", value: " + variableParams[1] + ")";
else
addition = " (delete key: " + variableParams[0] + ")";
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.setVariable) + addition);
break;
case startPhoneCall:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.startPhoneCall));
break;
@ -347,24 +360,24 @@ public class Action
if (parts.length > 4 && !StringUtils.isBlank(parts[4]))
returnString.append(", " + Miscellaneous.getAnyContext().getResources().getString(R.string.ifString) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.text) + " " + Trigger.getMatchString(parts[3]) + " " + parts[4]);
if(parts.length >= 6)
if (parts.length >= 6)
{
if(!parts[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
if (!parts[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
{
returnString.append(" " + String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.withButton), parts[5]));
}
}
}
else if(this.getAction().equals(Action_Enum.setWifi))
else if (this.getAction().equals(Action_Enum.setWifi))
{
if(!StringUtils.isEmpty(this.parameter2))
if (!StringUtils.isEmpty(this.parameter2))
{
boolean useRoot = Boolean.parseBoolean(this.parameter2);
if(useRoot)
if (useRoot)
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.usingRoot));
}
}
else if(this.getAction().equals(Action_Enum.controlMediaPlayback))
else if (this.getAction().equals(Action_Enum.controlMediaPlayback))
{
returnString.append(": ");
@ -392,10 +405,12 @@ public class Action
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.unknown));
}
}
else if(this.getAction().equals(Action_Enum.sendBroadcast))
else if (this.getAction().equals(Action_Enum.sendBroadcast))
{
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/"));
}
else if (this.getAction().equals(Action_Enum.setVariable))
; // it's completed further above already
else if (parameter2 != null && parameter2.length() > 0)
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; "));
}
@ -600,6 +615,9 @@ public class Action
else
Actions.wakeLockStop();
break;
case setVariable:
Actions.setVariable(this.getParameter2());
break;
case startPhoneCall:
Actions.startPhoneCall(context, this.getParameter2());
break;

View File

@ -66,6 +66,7 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -212,7 +213,35 @@ public class Actions
context.sendBroadcast(broadcastIntent);
}
public static class WifiStuff
public static void setVariable(String parameter2)
{
String[] parts = parameter2.split(Action.actionParameter2Split);
if(AutomationService.isMyServiceRunning(Miscellaneous.getAnyContext()))
{
Map<String,String> map = AutomationService.getInstance().getVariableMap();
if(parts.length > 1)
map.put(parts[0], parts[1]);
else
map.remove(parts[0]);
}
Miscellaneous.logEvent("i", "Variable", "Checking for applicable rules after variable has been set or deleted.", 2);
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.checkVariable);
for(int i=0; i<ruleCandidates.size(); i++)
{
if(ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).getsGreenLight(AutomationService.getInstance()))
{
Miscellaneous.logEvent("i", "Variable", "Rule " + ruleCandidates.get(i).getName() + " applies after variable has been set or deleted.", 2);
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
}
}
Miscellaneous.logEvent("i", "Variable", "Done checking for applicable rules after variable has been set or deleted.", 2);
}
public static class WifiStuff
{
public static Boolean setWifi(Context context, Boolean desiredState, String parameter2, boolean toggleActionIfPossible)
{

View File

@ -0,0 +1,64 @@
package com.jens.automation2;
import static com.jens.automation2.ActivityManageActionTriggerUrl.edit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.jens.automation2.Action.Action_Enum;
import org.apache.commons.lang3.StringUtils;
public class ActivityManageActionSetVariable extends Activity
{
private Button bSaveVariable;
private EditText etVariableSetKey, etVariableSetValue;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_manage_action_set_variable);
etVariableSetKey = (EditText)findViewById(R.id.etVariableSetKey);
etVariableSetValue = (EditText)findViewById(R.id.etVariableSetValue);
bSaveVariable = (Button)findViewById(R.id.bSaveVariable);
bSaveVariable.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(StringUtils.isEmpty(etVariableSetKey.getText().toString()))
{
Toast.makeText(ActivityManageActionSetVariable.this, getResources().getString(R.string.enterVariableKey), Toast.LENGTH_SHORT).show();
}
else
{
Intent response = new Intent();
if(StringUtils.isEmpty(etVariableSetValue.getText().toString()))
response.putExtra(ActivityManageRule.intentNameActionParameter2, etVariableSetKey.getText().toString());
else
response.putExtra(ActivityManageRule.intentNameActionParameter2, etVariableSetKey.getText().toString() + Action.actionParameter2Split + etVariableSetValue.getText().toString());
setResult(RESULT_OK, response);
finish();
}
}
});
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
{
String[] input = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
etVariableSetKey.setText(input[0]);
if(input.length > 1)
etVariableSetValue.setText(input[1]);
}
}
}

View File

@ -135,6 +135,10 @@ public class ActivityManageRule extends Activity
final static int requestCodeTriggerSubSystemStateEdit = 822;
final static int requestCodeActionMakePhoneCallAdd = 823;
final static int requestCodeActionMakePhoneCallEdit = 824;
final static int requestCodeActionSetVariableAdd = 825;
final static int requestCodeActionSetVariableEdit = 826;
final static int requestCodeTriggerCheckVariableAdd = 827;
final static int requestCodeTriggerCheckVariableEdit = 828;
public static ActivityManageRule getInstance()
{
@ -332,6 +336,12 @@ public class ActivityManageRule extends Activity
subSystemStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
startActivityForResult(subSystemStateEditor, requestCodeTriggerSubSystemStateEdit);
break;
case checkVariable:
Intent variableStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCheckVariable.class);
variableStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
variableStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
startActivityForResult(variableStateEditor, requestCodeTriggerCheckVariableEdit);
break;
default:
break;
}
@ -424,6 +434,11 @@ public class ActivityManageRule extends Activity
activityEditMakePhoneCallIntent.putExtra(intentNameActionParameter2, a.getParameter2());
startActivityForResult(activityEditMakePhoneCallIntent, requestCodeActionMakePhoneCallEdit);
break;
case setVariable:
Intent activityEditSetVariableIntent = new Intent(ActivityManageRule.this, ActivityManageActionSetVariable.class);
activityEditSetVariableIntent.putExtra(intentNameActionParameter2, a.getParameter2());
startActivityForResult(activityEditSetVariableIntent, requestCodeActionSetVariableEdit);
break;
case setWifi:
Intent activityEditSetWifiIntent = new Intent(ActivityManageRule.this, ActivityManageActionWifi.class);
activityEditSetWifiIntent.putExtra(intentNameActionParameter1, a.getParameter1());
@ -822,6 +837,13 @@ public class ActivityManageRule extends Activity
startActivityForResult(subSystemStateTriggerEditor, requestCodeTriggerSubSystemStateAdd);
return;
}
else if(triggerType == Trigger_Enum.checkVariable)
{
newTrigger.setTriggerType(Trigger_Enum.checkVariable);
Intent variableTriggerEditor = new Intent(myContext, ActivityManageTriggerCheckVariable.class);
startActivityForResult(variableTriggerEditor, requestCodeTriggerCheckVariableAdd);
return;
}
else
getTriggerParameterDialog(context, booleanChoices).show();
@ -1601,6 +1623,16 @@ public class ActivityManageRule extends Activity
this.refreshActionList();
}
}
else if(requestCode == requestCodeActionSetVariableAdd)
{
if(resultCode == RESULT_OK)
{
newAction.setParentRule(ruleToEdit);
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
ruleToEdit.getActionSet().add(newAction);
this.refreshActionList();
}
}
else if(requestCode == requestCodeActionWakeLockAdd)
{
if(resultCode == RESULT_OK)
@ -1726,6 +1758,20 @@ public class ActivityManageRule extends Activity
this.refreshActionList();
}
}
else if(requestCode == requestCodeActionSetVariableEdit)
{
if(resultCode == RESULT_OK)
{
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
if(data.hasExtra(intentNameActionParameter1) && data.hasExtra(intentNameActionParameter2))
{
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
}
this.refreshActionList();
}
}
else if(requestCode == requestCodeActionSetWifiEdit)
{
if(resultCode == RESULT_OK)
@ -1920,6 +1966,17 @@ public class ActivityManageRule extends Activity
this.refreshTriggerList();
}
}
else if(requestCode == requestCodeTriggerCheckVariableAdd)
{
if(resultCode == RESULT_OK)
{
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
newTrigger.setParentRule(ruleToEdit);
ruleToEdit.getTriggerSet().add(newTrigger);
this.refreshTriggerList();
}
}
else if(requestCode == requestCodeTriggerTetheringEdit)
{
if(resultCode == RESULT_OK)
@ -1946,6 +2003,19 @@ public class ActivityManageRule extends Activity
this.refreshTriggerList();
}
}
else if(requestCode == requestCodeTriggerCheckVariableEdit)
{
if(resultCode == RESULT_OK)
{
Trigger editedTrigger = new Trigger();
editedTrigger.setTriggerType(Trigger_Enum.checkVariable);
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
editedTrigger.setParentRule(ruleToEdit);
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
this.refreshTriggerList();
}
}
}
protected AlertDialog getActionTypeDialog()
@ -2192,6 +2262,12 @@ public class ActivityManageRule extends Activity
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionMakePhoneCall.class);
startActivityForResult(intent, requestCodeActionMakePhoneCallAdd);
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setVariable.toString()))
{
newAction.setAction(Action_Enum.setVariable);
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSetVariable.class);
startActivityForResult(intent, requestCodeActionSetVariableAdd);
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.stopPhoneCall.toString()))
{
newAction.setAction(Action_Enum.stopPhoneCall);

View File

@ -0,0 +1,56 @@
package com.jens.automation2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
public class ActivityManageTriggerCheckVariable extends Activity
{
EditText etVariableKeyTrigger, etVariableValueTrigger;
Button bTriggerVariableSave;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_trigger_check_variable);
etVariableKeyTrigger = (EditText) findViewById(R.id.etVariableKeyTrigger);
etVariableValueTrigger = (EditText) findViewById(R.id.etVariableValueTrigger);
bTriggerVariableSave = (Button) findViewById(R.id.bTriggerVariableSave);
Intent input = getIntent();
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
{
String[] conditions = input.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
etVariableKeyTrigger.setText(conditions[0]);
if(conditions.length > 1)
etVariableValueTrigger.setText(conditions[1]);
}
bTriggerVariableSave.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent response = new Intent();
// response.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbTetheringOn.isChecked());
if(StringUtils.isEmpty(etVariableValueTrigger.getText().toString()))
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, etVariableKeyTrigger.getText().toString());
else
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, etVariableKeyTrigger.getText().toString() + Trigger.triggerParameter2Split + etVariableValueTrigger.getText().toString());
setResult(RESULT_OK, response);
finish();
}
});
}
}

View File

@ -33,6 +33,8 @@ import com.jens.automation2.receivers.PackageReplacedReceiver;
import com.jens.automation2.receivers.PhoneStatusListener;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@SuppressLint("NewApi")
@ -63,6 +65,8 @@ public class AutomationService extends Service implements OnInitListener
protected Calendar lockSoundChangesEnd = null;
protected boolean isRunning;
Map<String,String> variableMap = new HashMap();
protected static AutomationService centralInstance = null;
public void nullLockSoundChangesEnd()
@ -457,6 +461,10 @@ public class AutomationService extends Service implements OnInitListener
private void stopRoutine()
{
Miscellaneous.logEvent("i", "Service", "Stopping service...", 3);
// Clear variables for trigger/action with same name
variableMap.clear();
try
{
myLocationProvider.stopLocationService();
@ -691,14 +699,19 @@ public class AutomationService extends Service implements OnInitListener
}
}
}
public static boolean isMainActivityRunning(Context context)
{
public Map<String, String> getVariableMap()
{
return variableMap;
}
public static boolean isMainActivityRunning(Context context)
{
if(ActivityMainScreen.getActivityMainScreenInstance() == null)
return false;
else
return true;
}
}
public static boolean isMyServiceRunning(Context context)
{

View File

@ -568,17 +568,17 @@ public class Profile implements Comparable<Profile>
}
finally
{
Miscellaneous.logEvent("i", "POI", "Checking for applicable rule after profile " + this.getName() + " has been activated.", 2);
Miscellaneous.logEvent("i", "Profile", "Checking for applicable rules after profile " + this.getName() + " has been activated.", 2);
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.profileActive);
for(int i=0; i<ruleCandidates.size(); i++)
{
if(ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).getsGreenLight(AutomationService.getInstance()))
{
Miscellaneous.logEvent("i", "POI", "Rule " + ruleCandidates.get(i).getName() + " applies after " + this.getName() + " has been activated.", 2);
Miscellaneous.logEvent("i", "Profile", "Rule " + ruleCandidates.get(i).getName() + " applies after " + this.getName() + " has been activated.", 2);
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
}
}
Miscellaneous.logEvent("i", "POI", "Done checking for applicable rule after profile " + this.getName() + " has been activated.", 2);
Miscellaneous.logEvent("i", "Profile", "Done checking for applicable rules after profile " + this.getName() + " has been activated.", 2);
}
}
else

View File

@ -31,6 +31,7 @@ import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
public class Trigger
{
@ -61,6 +62,7 @@ public class Trigger
broadcastReceived,
tethering,
subSystemState,
checkVariable,
phoneCall; //phoneCall always needs to be at the very end because of Google's shitty so called privacy
public String getFullName(Context context)
@ -119,6 +121,8 @@ public class Trigger
return context.getResources().getString(R.string.tetheringState);
case subSystemState:
return context.getResources().getString(R.string.subSystemState);
case checkVariable:
return context.getResources().getString(R.string.checkVariable);
default:
return "Unknown";
}
@ -244,6 +248,10 @@ public class Trigger
if(!checkSubSystemState())
result = false;
break;
case checkVariable:
if(!checkVariable())
result = false;
break;
default:
break;
}
@ -574,6 +582,33 @@ public class Trigger
return false;
}
boolean checkVariable()
{
try
{
Map<String,String> map = AutomationService.getInstance().getVariableMap();
String[] conditions = this.getTriggerParameter2().split(Trigger.triggerParameter2Split);
if(conditions.length == 1) // no real condition
return true;
else
{
if (map.containsKey(conditions[0]))
{
if (map.get(conditions[0]).equals(conditions[1]))
return true;
}
}
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "checkVariable()", Log.getStackTraceString(e), 1);
}
return false;
}
boolean checkBluetooth()
{
Miscellaneous.logEvent("i", Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), String.format("Checking for bluetooth...", this.getParentRule().getName()), 4);
@ -1418,7 +1453,7 @@ public class Trigger
switch(this.getTriggerType())
{
case charging:
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.starting) + " ");
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.stopping) + " ");
@ -1426,14 +1461,14 @@ public class Trigger
break;
case batteryLevel:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.batteryLevel));
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.exceeds) + " ");
else
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.dropsBelow) + " ");
returnString.append(String.valueOf(this.getBatteryLevel()) + " %");
break;
case usb_host_connection:
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.connecting) + " ");
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.disconnecting) + " ");
@ -1441,9 +1476,9 @@ public class Trigger
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.triggerUsb_host_connection));
break;
case pointOfInterest:
if(this.getPointOfInterest() != null)
if (this.getPointOfInterest() != null)
{
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.entering) + " ");
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.leaving) + " ");
@ -1452,33 +1487,33 @@ public class Trigger
}
else
{
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.leaving) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.anyLocation));
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.entering) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.anyLocation));
}
break;
case timeFrame:
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.entering) + " ");
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.leaving) + " ");
String repeat = ", " + Miscellaneous.getAnyContext().getResources().getString(R.string.noRepetition);
if(this.getTimeFrame().getRepetition() > 0)
if (this.getTimeFrame().getRepetition() > 0)
repeat = ", " + String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.repeatEveryXsecondsWithVariable), String.valueOf(this.getTimeFrame().getRepetition()));
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.triggerTimeFrame) + ": " + this.getTimeFrame().getTriggerTimeStart().toString() + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.until) + " " + this.getTimeFrame().getTriggerTimeStop().toString() + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.onDays) + " " + this.getTimeFrame().getDayList().toString() + repeat);
break;
case speed:
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.exceeding) + " ");
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.droppingBelow) + " ");
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.triggerSpeed) + ": " + String.valueOf(this.getSpeed()) + " km/h");
break;
case noiseLevel:
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.exceeding) + " ");
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.droppingBelow) + " ");
@ -1486,27 +1521,27 @@ public class Trigger
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.triggerNoiseLevel) + ": " + String.valueOf(this.getNoiseLevelDb()) + " dB");
break;
case wifiConnection:
String wifiDisplayName = "";
if(this.getTriggerParameter2().length() == 0)
String wifiDisplayName = "";
if (this.getTriggerParameter2().length() == 0)
wifiDisplayName += Miscellaneous.getAnyContext().getResources().getString(R.string.anyWifi);
else
wifiDisplayName += this.getTriggerParameter2();
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.connectedToWifi), wifiDisplayName));
else
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.disconnectedFromWifi), wifiDisplayName));
break;
case process_started_stopped:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.application) + " " + this.getProcessName() + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.is) + " ");
if(this.triggerParameter)
if (this.triggerParameter)
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.started));
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.stopped));
break;
case airplaneMode:
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.activated) + " ");
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.deactivated) + " ");
@ -1514,7 +1549,7 @@ public class Trigger
break;
case roaming:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.roaming));
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.activated));
else
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.deactivated));
@ -1526,27 +1561,27 @@ public class Trigger
returnString.append(" ");
if(elements[1].equals(triggerPhoneCallDirectionAny))
if (elements[1].equals(triggerPhoneCallDirectionAny))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.with));
else if(elements[1].equals(triggerPhoneCallDirectionIncoming))
else if (elements[1].equals(triggerPhoneCallDirectionIncoming))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.from));
else if(elements[1].equals(triggerPhoneCallDirectionOutgoing))
else if (elements[1].equals(triggerPhoneCallDirectionOutgoing))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.to));
returnString.append(" ");
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny))
if (elements[2].equals(Trigger.triggerPhoneCallNumberAny))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.any) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.number));
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.number) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.matching) + " " + elements[2]);
returnString.append(" ");
if(elements[0].equals(Trigger.triggerPhoneCallStateRinging))
if (elements[0].equals(Trigger.triggerPhoneCallStateRinging))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.ringing));
else if(elements[0].equals(Trigger.triggerPhoneCallStateStarted))
else if (elements[0].equals(Trigger.triggerPhoneCallStateStarted))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.started));
else if(elements[0].equals(Trigger.triggerPhoneCallStateStopped))
else if (elements[0].equals(Trigger.triggerPhoneCallStateStopped))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.stopped));
break;
@ -1566,18 +1601,18 @@ public class Trigger
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.featureNotInFdroidVersion));
}
catch(ClassNotFoundException e)
catch (ClassNotFoundException e)
{
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.featureNotInFdroidVersion));
}
break;
case bluetoothConnection:
String device = Miscellaneous.getAnyContext().getResources().getString(R.string.anyDevice);
if(bluetoothDeviceAddress.equals("<any>"))
if (bluetoothDeviceAddress.equals("<any>"))
{
device = Miscellaneous.getAnyContext().getResources().getString(R.string.any);
}
else if(bluetoothDeviceAddress.equals("<none>"))
else if (bluetoothDeviceAddress.equals("<none>"))
{
device = Miscellaneous.getAnyContext().getResources().getString(R.string.noDevice);
}
@ -1587,21 +1622,21 @@ public class Trigger
{
device = BluetoothReceiver.getDeviceByAddress(bluetoothDeviceAddress).getName() + " (" + this.bluetoothDeviceAddress + ")";
}
catch(NullPointerException e)
catch (NullPointerException e)
{
device = Miscellaneous.getAnyContext().getResources().getString(R.string.invalidDevice) + ": " + this.bluetoothDeviceAddress;
Miscellaneous.logEvent("w", "Trigger", device, 3);
}
}
if(bluetoothEvent.equals(BluetoothDevice.ACTION_ACL_CONNECTED) || bluetoothEvent.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED))
if (bluetoothEvent.equals(BluetoothDevice.ACTION_ACL_CONNECTED) || bluetoothEvent.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED))
{
if (this.triggerParameter)
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.bluetoothConnectionTo), device));
else
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.bluetoothDisconnectFrom), device));
}
else if(bluetoothEvent.equals(BluetoothDevice.ACTION_FOUND))
else if (bluetoothEvent.equals(BluetoothDevice.ACTION_FOUND))
{
if (this.triggerParameter)
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.bluetoothDeviceInRange), device));
@ -1611,7 +1646,7 @@ public class Trigger
break;
case headsetPlugged:
String type;
switch(headphoneType)
switch (headphoneType)
{
case 0:
type = Miscellaneous.getAnyContext().getResources().getString(R.string.headphoneSimple);
@ -1626,13 +1661,13 @@ public class Trigger
type = Miscellaneous.getAnyContext().getResources().getString(R.string.notSet);
break;
}
if(getTriggerParameter())
if (getTriggerParameter())
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.headsetConnected), type));
else
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.headsetDisconnected), type));
break;
case notification:
if(this.getTriggerParameter2().contains(triggerParameter2Split))
if (this.getTriggerParameter2().contains(triggerParameter2Split))
{
String[] params = getTriggerParameter2().split(triggerParameter2Split);
@ -1653,7 +1688,7 @@ public class Trigger
else
appString = "app " + app;
if(triggerParameter)
if (triggerParameter)
triggerBuilder.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.postsNotification), appString));
else
triggerBuilder.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.removedNotification), appString));
@ -1675,26 +1710,26 @@ public class Trigger
returnString.append(Miscellaneous.getAnyContext().getString(R.string.deviceIsInCertainOrientation));
break;
case profileActive:
if(triggerParameter)
if (triggerParameter)
returnString.append(String.format(Miscellaneous.getAnyContext().getString(R.string.profileActive), getTriggerParameter2().split(Trigger.triggerParameter2Split)[0]));
else
returnString.append(String.format(Miscellaneous.getAnyContext().getString(R.string.profileNotActive), getTriggerParameter2().split(Trigger.triggerParameter2Split)[0]));
break;
case musicPlaying:
if(triggerParameter)
if (triggerParameter)
returnString.append(Miscellaneous.getAnyContext().getString(R.string.musicIsPlaying));
else
returnString.append(Miscellaneous.getAnyContext().getString(R.string.musicIsNotPlaying));
break;
case screenState:
String state;
switch(triggerParameter2)
switch (triggerParameter2)
{
case "0":
state = Miscellaneous.getAnyContext().getString(R.string.off);
break;
case "1":
state = Miscellaneous.getAnyContext().getString(R.string.on);
state = Miscellaneous.getAnyContext().getString(R.string.on);
break;
case "2":
state = Miscellaneous.getAnyContext().getString(R.string.unlocked);
@ -1719,7 +1754,7 @@ public class Trigger
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.serviceIsStarting) + ": " + String.valueOf(triggerParameter));
break;
case broadcastReceived:
if(triggerParameter)
if (triggerParameter)
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.broadcastReceived));
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.broadcastNotReceived));
@ -1727,7 +1762,7 @@ public class Trigger
returnString.append(": " + triggerParameter2);
break;
case tethering:
if(triggerParameter)
if (triggerParameter)
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.tetheringActive));
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.tetheringNotActive));
@ -1736,7 +1771,7 @@ public class Trigger
break;
case subSystemState:
Trigger.subSystemStates desiredState = subSystemStates.valueOf(triggerParameter2);
switch(desiredState)
switch (desiredState)
{
case wifi:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.wifi));
@ -1748,11 +1783,20 @@ public class Trigger
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.is) + " ");
if(triggerParameter)
if (triggerParameter)
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.activated));
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.deactivated));
break;
case checkVariable:
if (triggerParameter2.contains(triggerParameter2Split))
{
String[] parts = triggerParameter2.split(triggerParameter2Split);
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.variableCheckString), parts[0], parts[1]));
}
else
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.variableCheckStringDeleted), triggerParameter2));
break;
default:
returnString.append("error");
break;

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setVariable"
android:textSize="25dp"
android:layout_marginBottom="@dimen/default_margin" />
<TableLayout
android:layout_marginLeft="@dimen/default_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="1" >
<TableRow>
<TextView
android:text="@string/VariableKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etVariableSetKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView
android:text="@string/variableValue"
android:layout_marginRight="@dimen/default_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etVariableSetValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/default_margin"
android:text="@string/setVariableExplanation" />
<Button
android:id="@+id/bSaveVariable"
android:layout_marginTop="@dimen/default_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save" />
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="@dimen/default_margin" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginBottom="@dimen/default_margin"
android:text="@string/checkVariable"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:stretchColumns="1"
android:shrinkColumns="1" >
<TableRow
android:layout_marginTop="@dimen/default_margin">
<TextView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/default_margin"
android:text="@string/VariableKey" />
<EditText
android:id="@+id/etVariableKeyTrigger"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_marginTop="@dimen/default_margin">
<TextView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/default_margin"
android:text="@string/variableValue" />
<EditText
android:id="@+id/etVariableValueTrigger"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:text="@string/checkVariableExplanation" />
<Button
android:id="@+id/bTriggerVariableSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:text="@string/save" />
</LinearLayout>
</ScrollView>

View File

@ -761,4 +761,14 @@
<string name="endPhoneCall">Telefonanruf beenden</string>
<string name="android.permission.ANSWER_PHONE_CALLS">Telefonanruf beenden</string>
<string name="settingsReferringToRestrictedFeaturesInGoogle">Ihre Einstellungen und/oder Regeln verweisen derzeit auf Funktionen, die in der Google Play-Version nicht bereitgestellt werden können. Dazu gehört unter anderem alles, was mit Telefonaten und Textnachrichten zu tun hat.</string>
<string name="setVariable">Variable festlegen</string>
<string name="deleteVariable">Variable löschen</string>
<string name="VariableKey">Variablenname</string>
<string name="variableValue">Variablenwert</string>
<string name="setVariableExplanation">Wenn Sie für eine Variable einen leeren Wert angeben, wird sie gelöscht.</string>
<string name="enterVariableKey">Geben Sie einen Namen für die Variable an.</string>
<string name="checkVariable">Variable prüfen</string>
<string name="checkVariableExplanation">Wenn Sie den Wert der Variablen leer lassen, darf sie nicht gesetzt sein, damit die Bedingung als erfüllt gilt.</string>
<string name="variableCheckString">wenn Variable %1$s den Wert %2$s hat</string>
<string name="variableCheckStringDeleted">wenn Variable %1$s nicht gesetzt ist</string>
</resources>

View File

@ -760,4 +760,14 @@
<string name="endPhoneCall">Terminar llamda de teléfono</string>
<string name="android.permission.ANSWER_PHONE_CALLS">Terminar llamda de teléfono</string>
<string name="settingsReferringToRestrictedFeaturesInGoogle">La configuración y/o las reglas hacen referencia a funciones que no se pueden proporcionar en la versión de Google Play. Entre otras cosas que incluye todo lo relacionado con llamadas telefónicas y mensajes de texto.</string>
<string name="variableCheckStringDeleted">Si la variable %1$s no está establecida</string>
<string name="variableCheckString">Si la variable %1$s es %2$s</string>
<string name="checkVariableExplanation">Si deja el valor vacío, no se debe establecer la variable para que la condición devuelva true.</string>
<string name="checkVariable">Comprobar variable</string>
<string name="enterVariableKey">Introduzca una clave para la variable.</string>
<string name="setVariableExplanation">Si establece una variable en un valor vacío, se eliminará.</string>
<string name="variableValue">Valor variable</string>
<string name="VariableKey">Clave variable</string>
<string name="deleteVariable">Eliminar variable</string>
<string name="setVariable">Establecer una variable</string>
</resources>

View File

@ -760,4 +760,14 @@
<string name="endPhoneCall">Mettre fin à l\'appel téléphonique</string>
<string name="android.permission.ANSWER_PHONE_CALLS">Mettre fin à l\'appel téléphonique</string>
<string name="settingsReferringToRestrictedFeaturesInGoogle">Vos paramètres et/ou règles font actuellement référence à des fonctionnalités qui ne peuvent pas être fournies dans la version Google Play. Entre autres choses, cela inclut tout ce qui concerne les appels téléphoniques et les messages texte.</string>
<string name="variableCheckStringDeleted">si la variable %1$s n\'est pas définie</string>
<string name="variableCheckString">si la variable %1$s est %2$s</string>
<string name="checkVariableExplanation">Si vous laissez la valeur vide, la variable ne doit pas être définie pour que la condition renvoie true.</string>
<string name="checkVariable">Vérifier la variable</string>
<string name="enterVariableKey">Entrez une clé pour la variable.</string>
<string name="setVariableExplanation">Si vous définissez une variable sur une valeur vide, elle sera supprimée.</string>
<string name="variableValue">Valeur variable</string>
<string name="VariableKey">Clé variable</string>
<string name="deleteVariable">Supprimer la variable</string>
<string name="setVariable">Définir une variable</string>
</resources>

View File

@ -761,4 +761,14 @@
<string name="android.permission.ANSWER_PHONE_CALLS">Termina telefonata</string>
<string name="endPhoneCall">Termina telefonata</string>
<string name="settingsReferringToRestrictedFeaturesInGoogle">Le tue impostazioni e/o regole fanno attualmente riferimento a funzioni che non possono essere fornite nella versione di Google Play. Tra le altre cose che include tutto ciò che riguarda le telefonate e i messaggi di testo.</string>
<string name="setVariable">Impostare una variabile</string>
<string name="deleteVariable">Elimina variabile</string>
<string name="VariableKey">Chiave variabile</string>
<string name="variableValue">Valore variabile</string>
<string name="setVariableExplanation">Se si imposta una variabile su un valore vuoto, questa verrà eliminata.</string>
<string name="enterVariableKey">Immettere una chiave per la variabile.</string>
<string name="checkVariable">Controlla variabile</string>
<string name="checkVariableExplanation">Se si lascia vuoto il valore, la variabile non deve essere impostata affinché la condizione restituisca true.</string>
<string name="variableCheckString">Se la variabile %1$s è %2$s</string>
<string name="variableCheckStringDeleted">Se la variabile %1$s non è impostata</string>
</resources>

View File

@ -759,5 +759,15 @@
<string name="android.permission.ANSWER_PHONE_CALLS">Telefoongesprek beëindigen</string>
<string name="endPhoneCall">Telefoongesprek beëindigen</string>
<string name="settingsReferringToRestrictedFeaturesInGoogle">Uw instellingen en/of regels verwijzen momenteel naar functies die niet kunnen worden geleverd in de Google Play-versie. Dat omvat onder andere alles wat te maken heeft met telefoontjes en sms-berichten.</string>
<string name="setVariable">Een variabele instellen</string>
<string name="deleteVariable">Variabele verwijderen</string>
<string name="VariableKey">Variabele sleutel</string>
<string name="variableValue">Variabele waarde</string>
<string name="setVariableExplanation">Als u een variabele instelt op een lege waarde, wordt deze verwijderd.</string>
<string name="enterVariableKey">Voer een sleutel in voor de variabele.</string>
<string name="checkVariable">Variabele controleren</string>
<string name="checkVariableExplanation">Als u de waarde leeg laat, mag de variabele niet worden ingesteld om de voorwaarde true te laten retourneren.</string>
<string name="variableCheckString">als variabele %1$s %2$s is</string>
<string name="variableCheckStringDeleted">als variabele %1$s niet is ingesteld</string>
</resources>

View File

@ -818,4 +818,14 @@
<string name="endPhoneCall">Завершение телефонного звонка</string>
<string name="android.permission.ANSWER_PHONE_CALLS">Завершение телефонного звонка</string>
<string name="settingsReferringToRestrictedFeaturesInGoogle">Ваши настройки и/или правила в настоящее время ссылаются на функции, которые не могут быть предоставлены в версии Google Play. Среди прочего, это включает в себя все, что связано с телефонными звонками и текстовыми сообщениями.</string>
<string name="setVariable">Задание переменной</string>
<string name="deleteVariable">Удалить переменную</string>
<string name="VariableKey">Клавиша переменной</string>
<string name="variableValue">Значение переменной</string>
<string name="setVariableExplanation">Если для переменной задано пустое значение, она будет удалена.</string>
<string name="enterVariableKey">Введите ключ для переменной.</string>
<string name="checkVariable">Проверить переменную</string>
<string name="checkVariableExplanation">Если оставить значение пустым, переменная не должна быть задана для того, чтобы условие возвращало значение true.</string>
<string name="variableCheckString">если переменная %1$s равно %2$s</string>
<string name="variableCheckStringDeleted">Если переменная %1$s не задана</string>
</resources>

View File

@ -858,4 +858,14 @@
<string name="makePhoneCallExplanation1">Here you can enter a phone number that will be called without further prompts. You may use this to make settings like making adjustments to call routing, etc.. Please search for the codes required for this on your own.</string>
<string name="endPhoneCall">End phone call</string>
<string name="android.permission.ANSWER_PHONE_CALLS">End phone call</string>
<string name="setVariable">Set a variable</string>
<string name="deleteVariable">Delete variable</string>
<string name="VariableKey">Variable key</string>
<string name="variableValue">Variable value</string>
<string name="setVariableExplanation">If you set a variable to an empty value it will be deleted.</string>
<string name="enterVariableKey">Enter a key for the variable.</string>
<string name="checkVariable">Check variable</string>
<string name="checkVariableExplanation">If you leave the value empty the variable must not be set for the condition to return true.</string>
<string name="variableCheckString">if variable %1$s is %2$s</string>
<string name="variableCheckStringDeleted">if variable %1$s is not set</string>
</resources>

View File

@ -1,3 +1,4 @@
* New: Confirmation dialog before deleting locations, rules and profile
* New action: Make phone call without further prompt
* New trigger/action: Set custom variables as actions and check for them in triggers
* Fixed: Battery receiver could trigger above 100% or below 0%