This commit is contained in:
jens 2021-12-08 17:22:18 +01:00
parent b88801500f
commit 89ac69fd4b
10 changed files with 74 additions and 38 deletions

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\jens\.android\avd\Android_11.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2021-12-04T01:10:17.133406Z" />
</component>
</project>

View File

@ -348,7 +348,7 @@ public class Rule implements Comparable<Rule>
public boolean getsGreenLight(Context context)
{
return isRuleActive() && applies(context) && (hasNotAppliedSinceLastExecution() || isActuallyToggable());
return applies(context) && hasNotAppliedSinceLastExecution();
}
public boolean applies(Context context)

View File

@ -342,6 +342,11 @@ public class Rule implements Comparable<Rule>
return false;
}
public boolean getsGreenLight(Context context)
{
return isRuleActive() && applies(context) && hasNotAppliedSinceLastExecution();
}
public boolean applies(Context context)
{
if(AutomationService.getInstance() == null)

View File

@ -346,6 +346,11 @@ public class Rule implements Comparable<Rule>
return false;
}
public boolean getsGreenLight(Context context)
{
return isRuleActive() && applies(context) && hasNotAppliedSinceLastExecution();
}
public boolean applies(Context context)
{
if(AutomationService.getInstance() == null)

View File

@ -1094,23 +1094,48 @@ public class Actions
@Override
public void run()
{
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock((WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "Automation:Wakelock");
wakeLock.acquire();
try
{
Thread.sleep(awakeTime);
}
catch (InterruptedException e)
{
Miscellaneous.logEvent("w", context.getResources().getString(R.string.wakeupDevice), "Error keeping device awake: " + Log.getStackTraceString(e), 4);
}
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock((WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "Automation:Wakelock");
wakeLock.acquire();
wakeLock.release();
try
{
Thread.sleep(awakeTime);
}
catch (InterruptedException e)
{
Miscellaneous.logEvent("w", context.getResources().getString(R.string.wakeupDevice), "Error keeping device awake: " + Log.getStackTraceString(e), 4);
}
wakeLock.release();
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "Wakeup device action", "Error while waking up device: " + Log.getStackTraceString(e), 1);
}
}
}
public void turnOnScreen()
{
// turn on screen
Log.v("ProximityActivity", "ON!");
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
wakeLock.acquire();
}
@TargetApi(21) //Suppress lint error for PROXIMITY_SCREEN_OFF_WAKE_LOCK
public void turnOffScreen(){
// turn off screen
Log.v("ProximityActivity", "OFF!");
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
wakeLock.acquire();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@SuppressLint("NewApi")
public static boolean setAirplaneMode(boolean desiredState, boolean toggleActionIfPossible)

View File

@ -1375,8 +1375,7 @@ public class ActivityManageRule extends Activity
{
Trigger editedTrigger = new Trigger();
editedTrigger.setTriggerType(Trigger_Enum.devicePosition);
// newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDevicePosition.vectorFieldName));
editedTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDevicePosition.vectorFieldName));
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
this.refreshTriggerList();
}

View File

@ -6,6 +6,7 @@ import android.graphics.Color;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -112,13 +113,21 @@ public class ActivityManageTriggerDevicePosition extends Activity
if(getIntent().hasExtra(vectorFieldName))
{
editMode = true;
String values[] = getIntent().getStringExtra(vectorFieldName).split(Trigger.triggerParameter2Split);
etDesiredAzimuth.setText(values[0]);
etDesiredAzimuthTolerance.setText(values[1]);
etDesiredPitch.setText(values[2]);
etDesiredPitchTolerance.setText(values[3]);
etDesiredRoll.setText(values[4]);
etDesiredRollTolerance.setText(values[5]);
try
{
String values[] = getIntent().getStringExtra(vectorFieldName).split(Trigger.triggerParameter2Split);
etDesiredAzimuth.setText(values[0]);
etDesiredAzimuthTolerance.setText(values[1]);
etDesiredPitch.setText(values[2]);
etDesiredPitchTolerance.setText(values[3]);
etDesiredRoll.setText(values[4]);
etDesiredRollTolerance.setText(values[5]);
}
catch(Exception e)
{
Toast.makeText(ActivityManageTriggerDevicePosition.this, getResources().getString(R.string.triggerWrong), Toast.LENGTH_SHORT).show();
Miscellaneous.logEvent("e", "DevicePositionTrigger", "There\'s something wrong with a device position trigger. Content: " + getIntent().getStringExtra(vectorFieldName) + ", " + Log.getStackTraceString(e), 1);
}
}
bApplyPositionValues.setOnClickListener(new View.OnClickListener()
@ -206,6 +215,8 @@ public class ActivityManageTriggerDevicePosition extends Activity
return false;
}
}
return true;
}
return false;

View File

@ -276,6 +276,7 @@ public class PointOfInterest implements Comparable<PointOfInterest>
ActivityMainScreen.updateMainScreen();
}
}
public void deactivate(AutomationService parentService)
{
if(this.isActivated())

View File

@ -290,6 +290,8 @@ public class Trigger
float currentRoll = DevicePositionListener.getInstance().getRoll();
if(
desiredAzimuthTolerance < 180
&&
!(
currentAzimuth <= desiredAzimuth + desiredAzimuthTolerance
&&
@ -302,6 +304,8 @@ public class Trigger
}
if(
desiredPitchTolerance < 180
&&
!(
currentPitch <= desiredPitch + desiredPitchTolerance
&&
@ -314,6 +318,8 @@ public class Trigger
}
if(
desiredRollTolerance < 180
&&
!(
currentRoll <= desiredRoll + desiredRollTolerance
&&

View File

@ -725,4 +725,5 @@
<string name="toleranceOf180OnlyAllowedIn2Fields">A tolerance of 180 is allowed for 2 tolerance fields only, not all 3. Otherwise the trigger would ALWAYS apply.</string>
<string name="unknown">unknown</string>
<string name="position">Position</string>
<string name="triggerWrong">" There's something wrong with this trigger. It could not be loaded correctly."</string>
</resources>