forked from jens/Automation
variables as triggers and actions
This commit is contained in:
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user