Rework
This commit is contained in:
parent
cdf1a8baa8
commit
c34ec83425
11
.idea/deploymentTargetDropDown.xml
generated
11
.idea/deploymentTargetDropDown.xml
generated
@ -1,17 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="deploymentTargetDropDown">
|
<component name="deploymentTargetDropDown">
|
||||||
<runningDeviceTargetSelectedWithDropDown>
|
|
||||||
<Target>
|
|
||||||
<type value="RUNNING_DEVICE_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
|
||||||
<value value="C:\Users\jens\.android\avd\Android_11.avd" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</runningDeviceTargetSelectedWithDropDown>
|
|
||||||
<targetSelectedWithDropDown>
|
<targetSelectedWithDropDown>
|
||||||
<Target>
|
<Target>
|
||||||
<type value="QUICK_BOOT_TARGET" />
|
<type value="QUICK_BOOT_TARGET" />
|
||||||
|
@ -358,7 +358,24 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
for(Trigger oneTrigger : this.getTriggerSet())
|
for(Trigger oneTrigger : this.getTriggerSet())
|
||||||
{
|
{
|
||||||
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.activityDetection))
|
if (!oneTrigger.applies(null, context))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is actually a function of the class Trigger, but Rule is already distinguished by flavors, Trigger is not.
|
||||||
|
* Hence it is here.
|
||||||
|
* @param oneTrigger
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean checkActivityDetection(Trigger oneTrigger)
|
||||||
{
|
{
|
||||||
if (ActivityDetectionReceiver.getActivityDetectionLastResult() != null)
|
if (ActivityDetectionReceiver.getActivityDetectionLastResult() != null)
|
||||||
{
|
{
|
||||||
@ -371,7 +388,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleDoesntApplyActivityNotPresent), ActivityDetectionReceiver.getDescription(oneTrigger.getActivityDetectionType())), 3);
|
Miscellaneous.logEvent("i", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleDoesntApplyActivityNotPresent), ActivityDetectionReceiver.getDescription(oneTrigger.getActivityDetectionType())), 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -380,27 +397,16 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
if (oneDetectedActivity.getType() == oneTrigger.getActivityDetectionType() && oneDetectedActivity.getConfidence() < Settings.activityDetectionRequiredProbability)
|
if (oneDetectedActivity.getType() == oneTrigger.getActivityDetectionType() && oneDetectedActivity.getConfidence() < Settings.activityDetectionRequiredProbability)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleDoesntApplyActivityGivenButTooLowProbability), ActivityDetectionReceiver.getDescription(oneDetectedActivity.getType()), String.valueOf(oneDetectedActivity.getConfidence()), String.valueOf(Settings.activityDetectionRequiredProbability)), 3);
|
Miscellaneous.logEvent("i", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleDoesntApplyActivityGivenButTooLowProbability), ActivityDetectionReceiver.getDescription(oneDetectedActivity.getType()), String.valueOf(oneDetectedActivity.getConfidence()), String.valueOf(Settings.activityDetectionRequiredProbability)), 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!oneTrigger.applies(null, context))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ActivateRuleTask extends AsyncTask<Object, String, Void>
|
private class ActivateRuleTask extends AsyncTask<Object, String, Void>
|
||||||
{
|
{
|
||||||
boolean wasActivated = false;
|
boolean wasActivated = false;
|
||||||
@ -419,6 +425,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null)
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
|
|
||||||
|
setLastExecution(Calendar.getInstance());
|
||||||
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -443,7 +450,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
*/
|
*/
|
||||||
if(wasActivated)
|
if(wasActivated)
|
||||||
{
|
{
|
||||||
setLastExecution(Calendar.getInstance());
|
// setLastExecution(Calendar.getInstance());
|
||||||
AutomationService.updateNotification();
|
AutomationService.updateNotification();
|
||||||
ActivityMainScreen.updateMainScreen();
|
ActivityMainScreen.updateMainScreen();
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
@ -462,8 +469,8 @@ public class Rule implements Comparable<Rule>
|
|||||||
boolean doToggle = ruleToggle && isActuallyToggable;
|
boolean doToggle = ruleToggle && isActuallyToggable;
|
||||||
|
|
||||||
//if(notLastActive || force || doToggle)
|
//if(notLastActive || force || doToggle)
|
||||||
if(force || doToggle)
|
// if(force || doToggle)
|
||||||
{
|
// {
|
||||||
String message;
|
String message;
|
||||||
if(!doToggle)
|
if(!doToggle)
|
||||||
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName());
|
message = String.format(automationService.getResources().getString(R.string.ruleActivate), Rule.this.getName());
|
||||||
@ -492,6 +499,7 @@ public class Rule implements Comparable<Rule>
|
|||||||
{
|
{
|
||||||
Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization
|
Rule.ruleRunHistory.add(0, Rule.this); // add at beginning for better visualization
|
||||||
Rule.lastActivatedRuleActivationTime = new Date();
|
Rule.lastActivatedRuleActivationTime = new Date();
|
||||||
|
|
||||||
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize)
|
while(ruleRunHistory.size() > Settings.rulesThatHaveBeenRanHistorySize)
|
||||||
ruleRunHistory.remove(ruleRunHistory.size()-1);
|
ruleRunHistory.remove(ruleRunHistory.size()-1);
|
||||||
String history = "";
|
String history = "";
|
||||||
@ -507,12 +515,12 @@ public class Rule implements Comparable<Rule>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
|
Miscellaneous.logEvent("i", "Rule", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleActivationComplete), Rule.this.getName()), 2);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
Miscellaneous.logEvent("i", "Rule", "Request to activate rule " + Rule.this.getName() + ", but it is the last one that was activated. Won't do it again.", 3);
|
// Miscellaneous.logEvent("i", "Rule", "Request to activate rule " + Rule.this.getName() + ", but it is the last one that was activated. Won't do it again.", 3);
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import static android.content.Context.DEVICE_POLICY_SERVICE;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
@ -15,6 +18,7 @@ import com.jens.automation2.location.WifiBroadcastReceiver;
|
|||||||
import com.jens.automation2.receivers.BatteryReceiver;
|
import com.jens.automation2.receivers.BatteryReceiver;
|
||||||
import com.jens.automation2.receivers.BluetoothReceiver;
|
import com.jens.automation2.receivers.BluetoothReceiver;
|
||||||
import com.jens.automation2.receivers.ConnectivityReceiver;
|
import com.jens.automation2.receivers.ConnectivityReceiver;
|
||||||
|
import com.jens.automation2.receivers.DevicePositionListener;
|
||||||
import com.jens.automation2.receivers.HeadphoneJackListener;
|
import com.jens.automation2.receivers.HeadphoneJackListener;
|
||||||
import com.jens.automation2.receivers.NfcReceiver;
|
import com.jens.automation2.receivers.NfcReceiver;
|
||||||
import com.jens.automation2.receivers.NoiseListener;
|
import com.jens.automation2.receivers.NoiseListener;
|
||||||
@ -109,7 +113,13 @@ public class Trigger
|
|||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
case devicePosition:
|
case devicePosition:
|
||||||
and others
|
if(!checkDevicePosition())
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
case activityDetection:
|
||||||
|
if(!getParentRule().checkActivityDetection(this))
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -266,6 +276,55 @@ public class Trigger
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean checkDevicePosition()
|
||||||
|
{
|
||||||
|
String devicePositionPieces[] = getTriggerParameter2().split(Trigger.triggerParameter2Split);
|
||||||
|
float desiredAzimuth = Float.parseFloat(devicePositionPieces[0]);
|
||||||
|
float desiredAzimuthTolerance = Float.parseFloat(devicePositionPieces[1]);
|
||||||
|
float desiredPitch = Float.parseFloat(devicePositionPieces[2]);
|
||||||
|
float desiredPitchTolerance = Float.parseFloat(devicePositionPieces[3]);
|
||||||
|
float desiredRoll = Float.parseFloat(devicePositionPieces[4]);
|
||||||
|
float desiredRollTolerance = Float.parseFloat(devicePositionPieces[5]);
|
||||||
|
float currentAzimuth = DevicePositionListener.getInstance().getAzimuth();
|
||||||
|
float currentPitch = DevicePositionListener.getInstance().getPitch();
|
||||||
|
float currentRoll = DevicePositionListener.getInstance().getRoll();
|
||||||
|
|
||||||
|
if(
|
||||||
|
!(
|
||||||
|
currentAzimuth <= desiredAzimuth + desiredAzimuthTolerance
|
||||||
|
&&
|
||||||
|
currentAzimuth >= desiredAzimuth - desiredAzimuthTolerance
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
!(
|
||||||
|
currentPitch <= desiredPitch + desiredPitchTolerance
|
||||||
|
&&
|
||||||
|
currentPitch >= desiredPitch - desiredPitchTolerance
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
!(
|
||||||
|
currentRoll <= desiredRoll + desiredRollTolerance
|
||||||
|
&&
|
||||||
|
currentRoll >= desiredRoll - desiredRollTolerance
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
boolean checkHeadsetPlugged()
|
boolean checkHeadsetPlugged()
|
||||||
{
|
{
|
||||||
if(HeadphoneJackListener.isHeadsetConnected() != this.getTriggerParameter())
|
if(HeadphoneJackListener.isHeadsetConnected() != this.getTriggerParameter())
|
||||||
|
@ -49,6 +49,21 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getAzimuth()
|
||||||
|
{
|
||||||
|
return azimuth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPitch()
|
||||||
|
{
|
||||||
|
return pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRoll()
|
||||||
|
{
|
||||||
|
return roll;
|
||||||
|
}
|
||||||
|
|
||||||
public void startSensorFromConfigActivity(Context context, ActivityManageTriggerDevicePosition activityManageTriggerDevicePositionInstance)
|
public void startSensorFromConfigActivity(Context context, ActivityManageTriggerDevicePosition activityManageTriggerDevicePositionInstance)
|
||||||
{
|
{
|
||||||
this.activityManageTriggerDevicePositionInstance = activityManageTriggerDevicePositionInstance;
|
this.activityManageTriggerDevicePositionInstance = activityManageTriggerDevicePositionInstance;
|
||||||
@ -129,7 +144,15 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
|||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.devicePosition);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.devicePosition);
|
||||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||||
{
|
{
|
||||||
if (ruleCandidates.get(i).applies(Miscellaneous.getAnyContext()) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
boolean applies = ruleCandidates.get(i).applies(Miscellaneous.getAnyContext());
|
||||||
|
boolean flipped = ruleCandidates.get(i).hasNotAppliedSinceLastExecution();
|
||||||
|
|
||||||
|
// if (
|
||||||
|
// ruleCandidates.get(i).applies(Miscellaneous.getAnyContext())
|
||||||
|
// &&
|
||||||
|
// ruleCandidates.get(i).hasNotAppliedSinceLastExecution()
|
||||||
|
// )
|
||||||
|
if(applies && flipped)
|
||||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user