forked from jens/Automation
Rework
This commit is contained in:
@ -28,6 +28,8 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
|
||||
boolean editMode = false;
|
||||
|
||||
boolean messageDisplayed = false;
|
||||
|
||||
float desiredAzimuth, desiredPitch, desiredRoll, desiredAzimuthTolerance, desiredPitchTolerance, desiredRollTolerance;
|
||||
|
||||
public void updateFields(float azimuth, float pitch, float roll)
|
||||
@ -185,8 +187,28 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
float dp = Float.parseFloat(etDesiredPitch.getText().toString());
|
||||
float dr = Float.parseFloat(etDesiredRoll.getText().toString());
|
||||
|
||||
if(Math.abs(da) <= 180 || Math.abs(dp) <= 180 || Math.abs(dr) <= 180)
|
||||
return true;
|
||||
if(Math.abs(da) > 180 || Math.abs(dp) > 180 || Math.abs(dr) > 180)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!messageDisplayed)
|
||||
{
|
||||
float dat = Float.parseFloat(etDesiredAzimuthTolerance.getText().toString());
|
||||
float dpt = Float.parseFloat(etDesiredPitchTolerance.getText().toString());
|
||||
float drt = Float.parseFloat(etDesiredRollTolerance.getText().toString());
|
||||
|
||||
/*
|
||||
The user may enter a tolerance of 180° for two directions, but not all three.
|
||||
Otherwise this trigger would always apply.
|
||||
*/
|
||||
if (Math.abs(dat) >= 180 && Math.abs(dpt) >= 180 && Math.abs(drt) >= 180)
|
||||
{
|
||||
messageDisplayed = true;
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.toleranceOf180OnlyAllowedIn2Fields), ActivityManageTriggerDevicePosition.this).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -264,7 +264,7 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(parentService) && ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(parentService) && ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "POI", "Rule " + ruleCandidates.get(i).getName() + " applies for entering POI " + this.getName() + ".", 2);
|
||||
ruleCandidates.get(i).activate(parentService, false);
|
||||
@ -296,7 +296,7 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
Miscellaneous.logEvent("i", "POI", "POI " + this.getName() + " found in " + ruleCandidates.size() + " rule(s).", 2);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(parentService) && ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(parentService) && ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "POI", "Rule " + ruleCandidates.get(i).getName() + " applies for leaving POI " + this.getName() + ".", 2);
|
||||
ruleCandidates.get(i).activate(parentService, false);
|
||||
|
@ -201,7 +201,7 @@ public class LocationProvider
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesBySpeed();
|
||||
for (Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if (oneRule.applies(this.getParentService()) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
if ((oneRule.applies(this.getParentService()) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable())
|
||||
oneRule.activate(getParentService(), false);
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByWifiConnection();
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(automationServiceInstance) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
if((oneRule.applies(automationServiceInstance) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable())
|
||||
oneRule.activate(automationServiceInstance, false);
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(true);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
@ -219,7 +219,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByBatteryLevel();
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
@ -234,7 +234,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(false);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(true);
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
if((oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable())
|
||||
oneRule.activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(false);
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
if((oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable())
|
||||
oneRule.activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByBluetoothConnection();
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(AutomationService.getInstance()) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(AutomationService.getInstance()) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class ConnectivityReceiver extends BroadcastReceiver implements Automatio
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByAirplaneMode(isAirplaneMode);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(automationServiceRef) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(automationServiceRef) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ public class ConnectivityReceiver extends BroadcastReceiver implements Automatio
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByRoaming(isRoaming);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(automationServiceRef) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(automationServiceRef) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
ArrayList<Rule> allRulesWithNowInTimeFrame = Rule.findRuleCandidatesByTime(passTime);
|
||||
for(int i=0; i<allRulesWithNowInTimeFrame.size(); i++)
|
||||
{
|
||||
if(allRulesWithNowInTimeFrame.get(i).applies(context) && allRulesWithNowInTimeFrame.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((allRulesWithNowInTimeFrame.get(i).applies(context) && allRulesWithNowInTimeFrame.get(i).hasNotAppliedSinceLastExecution()) || allRulesWithNowInTimeFrame.get(i).isActuallyToggable())
|
||||
allRulesWithNowInTimeFrame.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,11 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
||||
private float pitch;
|
||||
private float roll;
|
||||
|
||||
boolean applies = false;
|
||||
boolean flipped = false;
|
||||
boolean toggable = false;
|
||||
|
||||
|
||||
public static DevicePositionListener getInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -144,15 +149,11 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.devicePosition);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
boolean applies = ruleCandidates.get(i).applies(Miscellaneous.getAnyContext());
|
||||
boolean flipped = ruleCandidates.get(i).hasNotAppliedSinceLastExecution();
|
||||
applies = ruleCandidates.get(i).applies(Miscellaneous.getAnyContext());
|
||||
flipped = ruleCandidates.get(i).hasNotAppliedSinceLastExecution();
|
||||
toggable = ruleCandidates.get(i).isActuallyToggable();
|
||||
|
||||
// if (
|
||||
// ruleCandidates.get(i).applies(Miscellaneous.getAnyContext())
|
||||
// &&
|
||||
// ruleCandidates.get(i).hasNotAppliedSinceLastExecution()
|
||||
// )
|
||||
if(applies && flipped)
|
||||
if((applies && flipped) || toggable)
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByHeadphoneJack(isHeadsetConnected());
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class NfcReceiver
|
||||
ArrayList<Rule> allRulesWithNfcTags = Rule.findRuleCandidatesByNfc();
|
||||
for(int i=0; i<allRulesWithNfcTags.size(); i++)
|
||||
{
|
||||
if(allRulesWithNfcTags.get(i).applies(asInstance) && allRulesWithNfcTags.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((allRulesWithNfcTags.get(i).applies(asInstance) && allRulesWithNfcTags.get(i).hasNotAppliedSinceLastExecution()) || allRulesWithNfcTags.get(i).isActuallyToggable())
|
||||
allRulesWithNfcTags.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class NoiseListener implements AutomationListenerInterface
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByNoiseLevel();
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(automationService) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
if((oneRule.applies(automationService) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable())
|
||||
oneRule.activate(automationService, false);
|
||||
}
|
||||
}
|
||||
|
@ -89,19 +89,12 @@ public class NotificationListener extends NotificationListenerService
|
||||
lastNotification.title = title;
|
||||
lastNotification.text = text;
|
||||
|
||||
// if(lastResponseToNotification == null || lastResponseToNotification.getTimeInMillis() < lastNotification.publishTime.getTimeInMillis())
|
||||
// {
|
||||
// lastResponseToNotification = Calendar.getInstance();
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
if (ruleCandidates.get(i).applies(NotificationListener.this) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// Miscellaneous.logEvent("e", "NotificationCheck", "Ignoring notification as it is old.", 5);
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
if ((ruleCandidates.get(i).applies(NotificationListener.this) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -114,7 +114,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if(asInstance != null)
|
||||
if(ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if (asInstance != null)
|
||||
if (ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if ((ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if(asInstance != null)
|
||||
if(ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
if((ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
|
@ -43,34 +43,27 @@ public class ProcessListener implements AutomationListenerInterface
|
||||
@Override
|
||||
public void handleMessage(Message msg)
|
||||
{
|
||||
// try
|
||||
// {
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.processMonitoring), automationService.getResources().getString(R.string.messageReceivedStatingProcessMonitoringIsComplete), 5);
|
||||
// This will take care of results delivered by the actual monitoring instance
|
||||
|
||||
for(String entry : getRunningApps())
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.runningApp), entry, 5);
|
||||
|
||||
// execute matching rules containing processes
|
||||
if(getRecentlyStartedApps().size()>0 | getRecentlyStoppedApps().size()>0)
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.processMonitoring), automationService.getResources().getString(R.string.messageReceivedStatingProcessMonitoringIsComplete), 5);
|
||||
// This will take care of results delivered by the actual monitoring instance
|
||||
|
||||
for(String entry : getRunningApps())
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.runningApp), entry, 5);
|
||||
|
||||
// execute matching rules containing processes
|
||||
if(getRecentlyStartedApps().size()>0 | getRecentlyStoppedApps().size()>0)
|
||||
{
|
||||
for(String entry : getRecentlyStartedApps())
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.appStarted), entry, 3);
|
||||
for(String entry : getRecentlyStoppedApps())
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.appStopped), entry, 3);
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByProcess();
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
for(String entry : getRecentlyStartedApps())
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.appStarted), entry, 3);
|
||||
for(String entry : getRecentlyStoppedApps())
|
||||
Miscellaneous.logEvent("i", automationService.getResources().getString(R.string.appStopped), entry, 3);
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByProcess();
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(automationService) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(automationService, false);
|
||||
}
|
||||
if((ruleCandidates.get(i).applies(automationService) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable())
|
||||
ruleCandidates.get(i).activate(automationService, false);
|
||||
}
|
||||
// }
|
||||
// catch(Exception e)
|
||||
// {
|
||||
// Miscellaneous.logEvent("e", "Noise level", "Error in workHandler->handleMessage(): " + e.getMessage());
|
||||
// }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -719,7 +719,8 @@
|
||||
<string name="orientationPitch">Pitch:</string>
|
||||
<string name="orientationRoll">Roll:</string>
|
||||
<string name="enterValidNumbersIntoAllFields">Enter valid numbers in all fields.</string>
|
||||
<string name="devicePositionExplanation">When you move your device the below numbers should update. What you can see there, is the current \"position\" of your device. If it is in the desired position, click the apply button to copy the current values to the desired fields.\nBecause you will probably not be able to reach this exact position ever again, enter a tolerance. The is amount to which the position can deviate in one direction or the other.</string>
|
||||
<string name="devicePositionExplanation">When you move your device the below numbers will update. What you can see there, is the current \"position\" of your device measured in degrees. If it is in the desired position, click the apply button to copy the current values to the desired fields.\nBecause reaching this exact position ever again is highly unlikely you must also enter a tolerance. The is amount of degrees to which the position can deviate in either direction. If you only care about one specific axis, specify a tolerance of 180° for the two other ones.</string>
|
||||
<string name="wouldCurrentlyApply">Would currently apply?</string>
|
||||
<string name="deviceIsInCertainPosition">the device is in a certain position</string>
|
||||
<string name="toleranceOf180OnlyAllowedIn2Fields">A tolerance of 180 is allowed for 2 tolerance fields only, not all 3. Otherwise the trigger would ALWAYS apply.</string>
|
||||
</resources>
|
Reference in New Issue
Block a user