Rework
This commit is contained in:
parent
c1139e1cb8
commit
d7e1cd44e8
@ -1119,36 +1119,55 @@ public class Actions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void turnOnScreen()
|
/*public static void turnOnScreen()
|
||||||
{
|
{
|
||||||
// turn on screen
|
// turn on screen
|
||||||
Miscellaneous.logEvent("i", "Actions", "Turning screen on.", 3);
|
Miscellaneous.logEvent("i", "Actions", "Turning screen on.", 3);
|
||||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
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, AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||||
wakeLock.acquire();
|
wakeLock.acquire();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@TargetApi(21) //Suppress lint error for PROXIMITY_SCREEN_OFF_WAKE_LOCK
|
@TargetApi(21) //Suppress lint error for PROXIMITY_SCREEN_OFF_WAKE_LOCK
|
||||||
public static void turnOffScreen()
|
public static void turnOffScreen()
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "Actions", "Turning screen off.", 3);
|
Miscellaneous.logEvent("i", "Actions", "Turning screen off.", 3);
|
||||||
|
|
||||||
DevicePolicyManager deviceManger = (DevicePolicyManager)Miscellaneous.getAnyContext().getSystemService(Context. DEVICE_POLICY_SERVICE);
|
|
||||||
deviceManger.lockNow();
|
|
||||||
|
|
||||||
/*params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
|
/*params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
|
||||||
params.screenBrightness = 0;
|
params.screenBrightness = 0;
|
||||||
getWindow().setAttributes(params);
|
getWindow().setAttributes(params);*/
|
||||||
|
|
||||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
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.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 wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||||
wakeLock.acquire();
|
wakeLock.acquire();
|
||||||
WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
|
|
||||||
|
// WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
|
||||||
// WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , "tag");
|
// WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , "tag");
|
||||||
wakeLock.acquire();*/
|
// wakeLock.acquire();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("w", context.getResources().getString(R.string.wakeupDevice), "Error keeping device awake: " + Log.getStackTraceString(e), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*public static void lockScreen()
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Actions", "Locking screen.", 3);
|
||||||
|
|
||||||
|
// Works, but requires Manifest.permission.BIND_DEVICE_ADMIN
|
||||||
|
// https://stackoverflow.com/questions/23898406/java-lang-securityexception-no-active-admin-owned-by-uid-10047-for-policy-4-on
|
||||||
|
DevicePolicyManager deviceManger = (DevicePolicyManager)Miscellaneous.getAnyContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
deviceManger.lockNow();
|
||||||
|
}*/
|
||||||
|
|
||||||
// using root
|
// using root
|
||||||
/*private void turnOffScreen()
|
/*private void turnOffScreen()
|
||||||
{
|
{
|
||||||
|
@ -50,6 +50,8 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
final static String activityDetectionClassPath = "com.jens.automation2.receivers.ActivityDetectionReceiver";
|
final static String activityDetectionClassPath = "com.jens.automation2.receivers.ActivityDetectionReceiver";
|
||||||
public final static String intentNameTriggerParameter1 = "triggerParameter1";
|
public final static String intentNameTriggerParameter1 = "triggerParameter1";
|
||||||
|
public final static String intentNameActionParameter1 = "actionParameter1";
|
||||||
|
public final static String intentNameActionParameter2 = "actionParameter2";
|
||||||
|
|
||||||
public Context context;
|
public Context context;
|
||||||
private Button cmdTriggerAdd, cmdActionAdd, cmdSaveRule;
|
private Button cmdTriggerAdd, cmdActionAdd, cmdSaveRule;
|
||||||
@ -96,8 +98,8 @@ public class ActivityManageRule extends Activity
|
|||||||
final static int requestCodeTriggerBluetoothEdit = 6001;
|
final static int requestCodeTriggerBluetoothEdit = 6001;
|
||||||
final static int requestCodeActionScreenBrightnessAdd = 401;
|
final static int requestCodeActionScreenBrightnessAdd = 401;
|
||||||
final static int requestCodeActionScreenBrightnessEdit = 402;
|
final static int requestCodeActionScreenBrightnessEdit = 402;
|
||||||
final static int requestCodeTriggerDevicePositionAdd = 301;
|
final static int requestCodeTriggerDeviceOrientationAdd = 301;
|
||||||
final static int requestCodeTriggerDevicePositionEdit = 302;
|
final static int requestCodeTriggerDeviceOrientationEdit = 302;
|
||||||
final static int requestCodeTriggerNotificationAdd = 8000;
|
final static int requestCodeTriggerNotificationAdd = 8000;
|
||||||
final static int requestCodeTriggerNfcNotificationEdit = 8001;
|
final static int requestCodeTriggerNfcNotificationEdit = 8001;
|
||||||
final static int requestCodeActionPlaySoundAdd = 501;
|
final static int requestCodeActionPlaySoundAdd = 501;
|
||||||
@ -268,7 +270,7 @@ public class ActivityManageRule extends Activity
|
|||||||
Intent devicePositionEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerDeviceOrientation.class);
|
Intent devicePositionEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerDeviceOrientation.class);
|
||||||
devicePositionEditor.putExtra(ActivityManageRule.intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
devicePositionEditor.putExtra(ActivityManageRule.intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||||
devicePositionEditor.putExtra(ActivityManageTriggerDeviceOrientation.vectorFieldName, selectedTrigger.getTriggerParameter2());
|
devicePositionEditor.putExtra(ActivityManageTriggerDeviceOrientation.vectorFieldName, selectedTrigger.getTriggerParameter2());
|
||||||
startActivityForResult(devicePositionEditor, requestCodeTriggerDevicePositionEdit);
|
startActivityForResult(devicePositionEditor, requestCodeTriggerDeviceOrientationEdit);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -341,8 +343,8 @@ public class ActivityManageRule extends Activity
|
|||||||
case playSound:
|
case playSound:
|
||||||
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
||||||
actionPlaySoundIntent.putExtra("edit", true);
|
actionPlaySoundIntent.putExtra("edit", true);
|
||||||
actionPlaySoundIntent.putExtra("actionParameter1", a.getParameter1());
|
actionPlaySoundIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||||
actionPlaySoundIntent.putExtra("actionParameter2", a.getParameter2());
|
actionPlaySoundIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||||
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundEdit);
|
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundEdit);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -559,7 +561,7 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
newTrigger.setTriggerType(Trigger_Enum.deviceOrientation);
|
newTrigger.setTriggerType(Trigger_Enum.deviceOrientation);
|
||||||
Intent devicePositionTriggerEditor = new Intent(myContext, ActivityManageTriggerDeviceOrientation.class);
|
Intent devicePositionTriggerEditor = new Intent(myContext, ActivityManageTriggerDeviceOrientation.class);
|
||||||
startActivityForResult(devicePositionTriggerEditor, requestCodeTriggerDevicePositionAdd);
|
startActivityForResult(devicePositionTriggerEditor, requestCodeTriggerDeviceOrientationAdd);
|
||||||
return;
|
return;
|
||||||
// booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
// booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
||||||
}
|
}
|
||||||
@ -1323,8 +1325,8 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
newAction.setParameter1(data.getBooleanExtra("actionParameter1", false));
|
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
newAction.setParameter2(data.getStringExtra("actionParameter2"));
|
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
ruleToEdit.getActionSet().add(newAction);
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
@ -1333,11 +1335,11 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
if(data.hasExtra("actionParameter1"))
|
if(data.hasExtra(intentNameActionParameter1))
|
||||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra("actionParameter1", false));
|
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||||
|
|
||||||
if(data.hasExtra("actionParameter2"))
|
if(data.hasExtra(intentNameActionParameter2))
|
||||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra("actionParameter2"));
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||||
|
|
||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
@ -1361,18 +1363,18 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(requestCode == requestCodeTriggerDevicePositionAdd)
|
else if(requestCode == requestCodeTriggerDeviceOrientationAdd)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
// newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
newTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||||
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDeviceOrientation.vectorFieldName));
|
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDeviceOrientation.vectorFieldName));
|
||||||
newTrigger.setParentRule(ruleToEdit);
|
newTrigger.setParentRule(ruleToEdit);
|
||||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||||
this.refreshTriggerList();
|
this.refreshTriggerList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(requestCode == requestCodeTriggerDevicePositionEdit)
|
else if(requestCode == requestCodeTriggerDeviceOrientationEdit)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
@ -1581,7 +1583,7 @@ public class ActivityManageRule extends Activity
|
|||||||
}
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendTextMessage.toString()))
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendTextMessage.toString()))
|
||||||
{
|
{
|
||||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, "android.permission.SEND_SMS"))
|
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
||||||
{
|
{
|
||||||
//launch other activity to enter parameters;
|
//launch other activity to enter parameters;
|
||||||
newAction.setAction(Action_Enum.sendTextMessage);
|
newAction.setAction(Action_Enum.sendTextMessage);
|
||||||
|
@ -14,6 +14,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
@ -544,6 +545,19 @@ public class Miscellaneous extends Service
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDarkModeEnabled(Context context)
|
||||||
|
{
|
||||||
|
switch(context.getResources().getConfiguration().uiMode)
|
||||||
|
{
|
||||||
|
case Configuration.UI_MODE_NIGHT_YES:
|
||||||
|
return true;
|
||||||
|
case Configuration.UI_MODE_NIGHT_NO:
|
||||||
|
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public static String replaceVariablesInText(String source, Context context) throws Exception
|
public static String replaceVariablesInText(String source, Context context) throws Exception
|
||||||
{
|
{
|
||||||
@ -1135,11 +1149,11 @@ public class Miscellaneous extends Service
|
|||||||
}
|
}
|
||||||
catch (IllegalAccessException e)
|
catch (IllegalAccessException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
Miscellaneous.logEvent("w", "runMethodReflective", Log.getStackTraceString(e),5 );
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e)
|
catch (InvocationTargetException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
Miscellaneous.logEvent("w", "runMethodReflective", Log.getStackTraceString(e),5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -175,10 +175,7 @@ public class ReceiverCoordinator
|
|||||||
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
||||||
//startActivityDetectionReceiver
|
//startActivityDetectionReceiver
|
||||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.activityDetection))
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.activityDetection))
|
||||||
{
|
|
||||||
Miscellaneous.runMethodReflective(activityDetectionClassPath, "startActivityDetectionReceiver", null);
|
Miscellaneous.runMethodReflective(activityDetectionClassPath, "startActivityDetectionReceiver", null);
|
||||||
// ActivityDetectionReceiver.startActivityDetectionReceiver();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(ClassNotFoundException e)
|
catch(ClassNotFoundException e)
|
||||||
{
|
{
|
||||||
@ -206,12 +203,12 @@ public class ReceiverCoordinator
|
|||||||
DateTimeListener.stopAlarmListener(AutomationService.getInstance());
|
DateTimeListener.stopAlarmListener(AutomationService.getInstance());
|
||||||
NoiseListener.stopNoiseListener();
|
NoiseListener.stopNoiseListener();
|
||||||
ProcessListener.stopProcessListener(AutomationService.getInstance());
|
ProcessListener.stopProcessListener(AutomationService.getInstance());
|
||||||
|
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
||||||
Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "stopActivityDetectionReceiver", null);
|
Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "stopActivityDetectionReceiver", null);
|
||||||
// ActivityDetectionReceiver.stopActivityDetectionReceiver();
|
|
||||||
}
|
}
|
||||||
catch(ClassNotFoundException e)
|
catch(ClassNotFoundException e)
|
||||||
{
|
{
|
||||||
|
@ -287,16 +287,18 @@ public class Trigger
|
|||||||
float currentRoll = DeviceOrientationListener.getInstance().getRoll();
|
float currentRoll = DeviceOrientationListener.getInstance().getRoll();
|
||||||
|
|
||||||
if(
|
if(
|
||||||
desiredAzimuthTolerance < 180
|
|
||||||
&&
|
|
||||||
!(
|
!(
|
||||||
currentAzimuth <= desiredAzimuth + desiredAzimuthTolerance
|
desiredAzimuthTolerance < 180
|
||||||
&&
|
&&
|
||||||
currentAzimuth >= desiredAzimuth - desiredAzimuthTolerance
|
(
|
||||||
|
Math.abs(currentAzimuth) <= Math.abs(desiredAzimuth - desiredAzimuthTolerance)
|
||||||
|
||
|
||||||
|
Math.abs(currentAzimuth) <= desiredAzimuth + desiredAzimuthTolerance
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "DeviceOrientation", "Trigger doesn\'t apply. Azimuth outside of tolerance area.", 5);
|
Miscellaneous.logEvent("i", "DeviceOrientation", "Azimuth outside of tolerance area.", 5);
|
||||||
if(getTriggerParameter())
|
if(getTriggerParameter())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
@ -304,16 +306,18 @@ public class Trigger
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(
|
if(
|
||||||
desiredPitchTolerance < 180
|
|
||||||
&&
|
|
||||||
!(
|
!(
|
||||||
currentPitch <= desiredPitch + desiredPitchTolerance
|
desiredPitchTolerance < 180
|
||||||
&&
|
&&
|
||||||
currentPitch >= desiredPitch - desiredPitchTolerance
|
(
|
||||||
|
Math.abs(currentPitch) <= Math.abs(desiredPitch - desiredPitchTolerance)
|
||||||
|
||
|
||||||
|
Math.abs(currentPitch) <= desiredPitch + desiredPitchTolerance
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "DeviceOrientation", "Trigger doesn\'t apply. Pitch outside of tolerance area.", 5);
|
Miscellaneous.logEvent("i", "DeviceOrientation", "Pitch outside of tolerance area.", 5);
|
||||||
if(getTriggerParameter())
|
if(getTriggerParameter())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
@ -321,16 +325,18 @@ public class Trigger
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(
|
if(
|
||||||
desiredRollTolerance < 180
|
|
||||||
&&
|
|
||||||
!(
|
!(
|
||||||
currentRoll <= desiredRoll + desiredRollTolerance
|
desiredRollTolerance < 180
|
||||||
&&
|
&&
|
||||||
currentRoll >= desiredRoll - desiredRollTolerance
|
(
|
||||||
|
Math.abs(currentRoll) <= Math.abs(desiredRoll - desiredRollTolerance)
|
||||||
|
||
|
||||||
|
Math.abs(currentRoll) <= desiredRoll + desiredRollTolerance
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "DeviceOrientation", "Trigger doesn\'t apply. Roll outside of tolerance area.", 5);
|
Miscellaneous.logEvent("i", "DeviceOrientation", "Roll outside of tolerance area.", 5);
|
||||||
if(getTriggerParameter())
|
if(getTriggerParameter())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
@ -31,6 +31,7 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
|
|||||||
|
|
||||||
Calendar now = null;
|
Calendar now = null;
|
||||||
static Calendar lastTimeSignalArrived = null;
|
static Calendar lastTimeSignalArrived = null;
|
||||||
|
static int sensorValueCounter = 0;
|
||||||
|
|
||||||
// Gravity rotational data
|
// Gravity rotational data
|
||||||
private float gravity[];
|
private float gravity[];
|
||||||
@ -148,23 +149,32 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
|
|||||||
if(activityManageTriggerDeviceOrientationInstance != null)
|
if(activityManageTriggerDeviceOrientationInstance != null)
|
||||||
activityManageTriggerDeviceOrientationInstance.updateFields(azimuth, pitch, roll);
|
activityManageTriggerDeviceOrientationInstance.updateFields(azimuth, pitch, roll);
|
||||||
|
|
||||||
now = Calendar.getInstance();
|
/*
|
||||||
if(lastTimeSignalArrived == null || now.getTimeInMillis() >= lastTimeSignalArrived.getTimeInMillis() + Settings.acceptDeviceOrientationSignalEveryX_MilliSeconds)
|
For some reason the first 3 values after starting the listener
|
||||||
|
are crap.
|
||||||
|
*/
|
||||||
|
if(sensorValueCounter > 3)
|
||||||
{
|
{
|
||||||
lastTimeSignalArrived = now;
|
now = Calendar.getInstance();
|
||||||
|
if (lastTimeSignalArrived == null || now.getTimeInMillis() >= lastTimeSignalArrived.getTimeInMillis() + Settings.acceptDeviceOrientationSignalEveryX_MilliSeconds)
|
||||||
Miscellaneous.logEvent("i", "DeviceOrientation", "Got device orientation update: azimuth: " + String.valueOf(azimuth) + ", pitch: " + String.valueOf(pitch) + ", roll: " + String.valueOf(pitch), 4);
|
|
||||||
|
|
||||||
if (AutomationService.isMyServiceRunning(Miscellaneous.getAnyContext()))
|
|
||||||
{
|
{
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.deviceOrientation);
|
lastTimeSignalArrived = now;
|
||||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
|
||||||
|
Miscellaneous.logEvent("i", "DeviceOrientation", "Got device orientation update: azimuth: " + String.valueOf(azimuth) + ", pitch: " + String.valueOf(pitch) + ", roll: " + String.valueOf(pitch), 4);
|
||||||
|
|
||||||
|
if (AutomationService.isMyServiceRunning(Miscellaneous.getAnyContext()))
|
||||||
{
|
{
|
||||||
if (ruleCandidates.get(i).getsGreenLight(Miscellaneous.getAnyContext()))
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.deviceOrientation);
|
||||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||||
|
{
|
||||||
|
if (ruleCandidates.get(i).getsGreenLight(Miscellaneous.getAnyContext()))
|
||||||
|
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
sensorValueCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -445,7 +445,7 @@
|
|||||||
<string name="headphoneMicrophone">Microphone</string>
|
<string name="headphoneMicrophone">Microphone</string>
|
||||||
<string name="headphoneAny">Either</string>
|
<string name="headphoneAny">Either</string>
|
||||||
<string name="headphoneSelectType">Select type of headphone</string>
|
<string name="headphoneSelectType">Select type of headphone</string>
|
||||||
<string name="ruleDoesntApplyWrongHeadphoneType" translatable="false">Rule doesn\'t apply. Wrong headphone type.</string>
|
<string name="ruleDoesntApplyWrongHeadphoneType" translatable="false">Rule %1$s doesn\'t apply. Wrong headphone type.</string>
|
||||||
<string name="ignoringActivityDetectionUpdateTooSoon" translatable="false">Ignoring activity detection update. Came in sooner that %1$s seconds.</string>
|
<string name="ignoringActivityDetectionUpdateTooSoon" translatable="false">Ignoring activity detection update. Came in sooner that %1$s seconds.</string>
|
||||||
<string name="whatsThis">What\'s this?</string>
|
<string name="whatsThis">What\'s this?</string>
|
||||||
<string name="atLeastRuleXisUsingY" translatable="false">At least rule \"%1$s\" is using a trigger of type \"%2$s\".</string>
|
<string name="atLeastRuleXisUsingY" translatable="false">At least rule \"%1$s\" is using a trigger of type \"%2$s\".</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user