Compare commits
No commits in common. "5ae193847e0273f0661f394bfffff467153b0f4f" and "fa578b175d64c93258eb1bb94059e3d369693921" have entirely different histories.
5ae193847e
...
fa578b175d
@ -348,24 +348,14 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
public boolean getsGreenLight(Context context)
|
||||
{
|
||||
if(applies(context))
|
||||
{
|
||||
if(hasNotAppliedSinceLastExecution())
|
||||
return true;
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " does not apply.", 4);
|
||||
|
||||
return false;
|
||||
return applies(context) && hasNotAppliedSinceLastExecution();
|
||||
}
|
||||
|
||||
public boolean applies(Context context)
|
||||
{
|
||||
if(AutomationService.getInstance() == null)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule " + getName() + " cannot apply.", 3);
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule cannot apply.", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -403,7 +393,7 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
if (!found)
|
||||
{
|
||||
Miscellaneous.logEvent("i", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleDoesntApplyActivityNotPresent), getName(), 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;
|
||||
}
|
||||
else
|
||||
@ -412,7 +402,7 @@ public class Rule implements Comparable<Rule>
|
||||
{
|
||||
if (oneDetectedActivity.getType() == oneTrigger.getActivityDetectionType() && oneDetectedActivity.getConfidence() < Settings.activityDetectionRequiredProbability)
|
||||
{
|
||||
Miscellaneous.logEvent("i", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleDoesntApplyActivityGivenButTooLowProbability), getName(), 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;
|
||||
}
|
||||
}
|
||||
@ -544,7 +534,15 @@ public class Rule implements Comparable<Rule>
|
||||
public void activate(AutomationService automationService, boolean force)
|
||||
{
|
||||
ActivateRuleTask task = new ActivateRuleTask();
|
||||
|
||||
// if(Settings.startNewThreadForRuleActivation)
|
||||
task.execute(automationService, force);
|
||||
// else
|
||||
// {
|
||||
// task.activateInternally(automationService, force);
|
||||
// AutomationService.updateNotification();
|
||||
// ActivityMainScreen.updateMainScreen();
|
||||
// }
|
||||
}
|
||||
|
||||
public static ArrayList<Rule> findRuleCandidatesByPoi(PointOfInterest searchPoi, boolean triggerParameter)
|
||||
@ -629,7 +627,7 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Timeframe search", "Rule (" + oneRule.getName() + ") stretches over midnight.", 5);
|
||||
Miscellaneous.logEvent("i", "Timeframe search", "Rule goes over midnight.", 5);
|
||||
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() || searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay
|
||||
{
|
||||
ruleCandidates.add(oneRule);
|
||||
@ -638,7 +636,7 @@ public class Rule implements Comparable<Rule>
|
||||
}
|
||||
else if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() && searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay
|
||||
{
|
||||
Miscellaneous.logEvent("i", "RuleSearch", "Rule found (" + oneRule.getName() + ") with TimeFrame with time " + searchTime.toString(), 3);
|
||||
Miscellaneous.logEvent("i", "RuleSearch", "Rule found with TimeFrame with time " + searchTime.toString(), 3);
|
||||
ruleCandidates.add(oneRule);
|
||||
break innerloop; //if the poi is found we don't need to search the other triggers in the same rule
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -430,10 +429,7 @@ public class Action
|
||||
case turnScreenOnOrOff:
|
||||
if(getParameter1())
|
||||
{
|
||||
if(StringUtils.isNumeric(this.getParameter2()))
|
||||
Actions.wakeupDevice(Long.parseLong(this.getParameter2()));
|
||||
else
|
||||
Actions.wakeupDevice((long)1000);
|
||||
// wakeupDevice() will create a separate thread. That'll take some time, we wait 100ms.
|
||||
try
|
||||
{
|
||||
|
@ -1124,7 +1124,7 @@ public class Actions
|
||||
// turn on screen
|
||||
Miscellaneous.logEvent("i", "Actions", "Turning screen on.", 3);
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||
WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
|
||||
wakeLock.acquire();
|
||||
}
|
||||
|
||||
@ -1141,9 +1141,6 @@ public class Actions
|
||||
getWindow().setAttributes(params);
|
||||
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||
// WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||
wakeLock.acquire();
|
||||
WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
|
||||
// WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , "tag");
|
||||
wakeLock.acquire();*/
|
||||
|
@ -49,7 +49,6 @@ import java.util.Collections;
|
||||
public class ActivityManageRule extends Activity
|
||||
{
|
||||
final static String activityDetectionClassPath = "com.jens.automation2.receivers.ActivityDetectionReceiver";
|
||||
public final static String intentNameTriggerParameter1 = "triggerParameter1";
|
||||
|
||||
public Context context;
|
||||
private Button cmdTriggerAdd, cmdActionAdd, cmdSaveRule;
|
||||
@ -266,7 +265,6 @@ public class ActivityManageRule extends Activity
|
||||
break;
|
||||
case devicePosition:
|
||||
Intent devicePositionEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerDevicePosition.class);
|
||||
devicePositionEditor.putExtra(ActivityManageRule.intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
devicePositionEditor.putExtra(ActivityManageTriggerDevicePosition.vectorFieldName, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(devicePositionEditor, requestCodeTriggerDevicePositionEdit);
|
||||
break;
|
||||
@ -1367,7 +1365,6 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
// newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDevicePosition.vectorFieldName));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
@ -1378,9 +1375,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.devicePosition);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDevicePosition.vectorFieldName));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -25,7 +24,6 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
TextView currentAzimuth, currentPitch, currentRoll, tvAppliesAzimuth, tvAppliesPitch, tvAppliesRoll;
|
||||
Button bApplyPositionValues, bSavePositionValues;
|
||||
EditText etDesiredAzimuth, etDesiredAzimuthTolerance, etDesiredPitch, etDesiredPitchTolerance, etDesiredRoll, etDesiredRollTolerance;
|
||||
CheckBox chkDevicePositionApplies;
|
||||
|
||||
public static String vectorFieldName = "deviceVector";
|
||||
|
||||
@ -39,7 +37,7 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
currentPitch.setText(Float.toString(pitch));
|
||||
currentRoll.setText(Float.toString(roll));
|
||||
|
||||
try
|
||||
if(checkInputs(false))
|
||||
{
|
||||
desiredAzimuth = Float.parseFloat(etDesiredAzimuth.getText().toString());
|
||||
desiredAzimuthTolerance = Float.parseFloat(etDesiredAzimuthTolerance.getText().toString());
|
||||
@ -53,14 +51,7 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
tvAppliesAzimuth.setText(getResources().getString(R.string.no));
|
||||
tvAppliesAzimuth.setTextColor(Color.RED);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
tvAppliesAzimuth.setText("");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
desiredPitch = Float.parseFloat(etDesiredPitch.getText().toString());
|
||||
desiredPitchTolerance = Float.parseFloat(etDesiredPitchTolerance.getText().toString());
|
||||
if(Math.abs(pitch) <= Math.abs(desiredPitch - desiredPitchTolerance) || Math.abs(pitch) <= desiredPitch + desiredPitchTolerance)
|
||||
@ -73,14 +64,7 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
tvAppliesPitch.setText(getResources().getString(R.string.no));
|
||||
tvAppliesPitch.setTextColor(Color.RED);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
tvAppliesPitch.setText("");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
desiredRoll = Float.parseFloat(etDesiredRoll.getText().toString());
|
||||
desiredRollTolerance = Float.parseFloat(etDesiredRollTolerance.getText().toString());
|
||||
if(Math.abs(roll) <= Math.abs(desiredRoll - desiredRollTolerance) || Math.abs(roll) <= desiredRoll + desiredRollTolerance)
|
||||
@ -94,10 +78,6 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
tvAppliesRoll.setTextColor(Color.RED);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
tvAppliesRoll.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,8 +103,6 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
etDesiredRoll = (EditText) findViewById(R.id.etDesiredRoll);
|
||||
etDesiredRollTolerance = (EditText) findViewById(R.id.etDesiredRollTolerance);
|
||||
|
||||
chkDevicePositionApplies = (CheckBox)findViewById(R.id.chkDevicePositionApplies);
|
||||
|
||||
// etDesiredAzimuth.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)});
|
||||
// etDesiredPitch.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)});
|
||||
// etDesiredRoll.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)});
|
||||
@ -137,8 +115,6 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
editMode = true;
|
||||
try
|
||||
{
|
||||
boolean chkValue = getIntent().getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true);
|
||||
chkDevicePositionApplies.setChecked(chkValue);
|
||||
String values[] = getIntent().getStringExtra(vectorFieldName).split(Trigger.triggerParameter2Split);
|
||||
etDesiredAzimuth.setText(values[0]);
|
||||
etDesiredAzimuthTolerance.setText(values[1]);
|
||||
@ -183,7 +159,6 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
{
|
||||
// Save
|
||||
Intent returnData = new Intent();
|
||||
returnData.putExtra(ActivityManageRule.intentNameTriggerParameter1, chkDevicePositionApplies.isChecked());
|
||||
returnData.putExtra(vectorFieldName,
|
||||
etDesiredAzimuth.getText().toString() + Trigger.triggerParameter2Split +
|
||||
etDesiredAzimuthTolerance.getText().toString() + Trigger.triggerParameter2Split +
|
||||
|
@ -360,7 +360,7 @@ public class ReceiverCoordinator
|
||||
if(!DevicePositionListener.getInstance().isListenerRunning())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "DevicePositionListener", "Starting DevicePositionListener because used in a new/changed rule.", 4);
|
||||
// if(DevicePositionListener.getInstance().haveAllPermission())
|
||||
if(HeadphoneJackListener.getInstance().haveAllPermission())
|
||||
DevicePositionListener.getInstance().startListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
|
@ -300,10 +300,7 @@ public class Trigger
|
||||
)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "DevicePosition", "Trigger doesn\'t apply. Azimuth outside of tolerance area.", 5);
|
||||
if(getTriggerParameter())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
if(
|
||||
@ -317,10 +314,7 @@ public class Trigger
|
||||
)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "DevicePosition", "Trigger doesn\'t apply. Pitch outside of tolerance area.", 5);
|
||||
if(getTriggerParameter())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
if(
|
||||
@ -334,16 +328,10 @@ public class Trigger
|
||||
)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "DevicePosition", "Trigger doesn\'t apply. Roll outside of tolerance area.", 5);
|
||||
if(getTriggerParameter())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
if(getTriggerParameter())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean checkHeadsetPlugged()
|
||||
@ -1395,6 +1383,8 @@ public class Trigger
|
||||
break;
|
||||
case bluetoothConnection:
|
||||
String device = Miscellaneous.getAnyContext().getResources().getString(R.string.anyDevice);
|
||||
// if(this.bluetoothDeviceAddress != null)
|
||||
// {
|
||||
if(bluetoothDeviceAddress.equals("<any>"))
|
||||
{
|
||||
device = Miscellaneous.getAnyContext().getResources().getString(R.string.any);
|
||||
@ -1411,8 +1401,8 @@ public class Trigger
|
||||
}
|
||||
catch(NullPointerException e)
|
||||
{
|
||||
device = Miscellaneous.getAnyContext().getResources().getString(R.string.invalidDevice) + ": " + this.bluetoothDeviceAddress;
|
||||
Miscellaneous.logEvent("w", "Trigger", device, 3);
|
||||
device = Miscellaneous.getAnyContext().getResources().getString(R.string.invalidDevice) + ": " + device;
|
||||
Miscellaneous.logEvent("w", "Trigger", Miscellaneous.getAnyContext().getResources().getString(R.string.invalidDevice) + ": " + device, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1430,6 +1420,7 @@ public class Trigger
|
||||
else
|
||||
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.bluetoothDeviceOutOfRange), device));
|
||||
}
|
||||
// }
|
||||
break;
|
||||
case headsetPlugged:
|
||||
String type;
|
||||
|
@ -100,7 +100,7 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
||||
{
|
||||
//unregister the sensor listener
|
||||
sManager.unregisterListener(this);
|
||||
isRunning = false;
|
||||
isRunning = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,7 +184,7 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
||||
{
|
||||
//unregister the sensor listener
|
||||
sManager.unregisterListener(this);
|
||||
isRunning = false;
|
||||
isRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -134,7 +133,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
|
||||
public static boolean haveAllPermission()
|
||||
{
|
||||
return ActivityPermissions.havePermission(Manifest.permission.READ_PHONE_STATE, Miscellaneous.getAnyContext());
|
||||
return ActivityPermissions.havePermission("android.permission.READ_PHONE_STATE", Miscellaneous.getAnyContext());
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,18 +224,6 @@
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/chkDevicePositionApplies"
|
||||
android:checked="true"
|
||||
android:text="@string/mustApply"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/explanationDevicePositionDirection" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bSavePositionValues"
|
||||
android:text="@string/save"
|
||||
|
@ -404,8 +404,8 @@
|
||||
<string name="detectedActivityWalking">Walking</string>
|
||||
<string name="detectedActivityRunning">Running</string>
|
||||
<string name="detectedActivityInvalidStatus">Invalid activity</string>
|
||||
<string name="ruleDoesntApplyActivityGivenButTooLowProbability" translatable="false">Rule %1$s doesn\'t apply. Detected activity %2$s given, but too low probability (%3$s %%), required %4$s %%.</string>
|
||||
<string name="ruleDoesntApplyActivityNotPresent" translatable="false">Rule %1$s doesn\'t apply. Required activity %2$s not present.</string>
|
||||
<string name="ruleDoesntApplyActivityGivenButTooLowProbability" translatable="false">Rule doesn\'t apply. Detected activity %1$s given, but too low probability (%2$s %%), required %3$s %%.</string>
|
||||
<string name="ruleDoesntApplyActivityNotPresent" translatable="false">Rule doesn\'t apply. Required activity %1$s not present.</string>
|
||||
<string name="selectTypeOfActivity">Select type of activity</string>
|
||||
<string name="triggerOnlyAvailableIfPlayServicesInstalled">This trigger is only available if Google Play Services is installed.</string>
|
||||
<string name="activityDetectionFrequencyTitle">Activity detection frequency [sec]</string>
|
||||
@ -729,6 +729,4 @@
|
||||
<string name="turnScreenOnOrOff">Turn screen on or off</string>
|
||||
<string name="turnScreenOn">turn screen on</string>
|
||||
<string name="turnScreenOff">turn screen off</string>
|
||||
<string name="mustApply">Must apply</string>
|
||||
<string name="explanationDevicePositionDirection">If the checkbox is checked that means the device has to be in the position you specify. If it\'s not checked, any position that does NOT match your criteria will do.</string>
|
||||
</resources>
|
@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.0.4'
|
||||
classpath 'com.android.tools.build:gradle:7.0.3'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
Loading…
Reference in New Issue
Block a user