forked from jens/Automation
Rework
This commit is contained in:
parent
359dd545c7
commit
0008642044
@ -36,6 +36,7 @@ public class Action
|
||||
startOtherActivity,
|
||||
waitBeforeNextAction,
|
||||
wakeupDevice,
|
||||
turnScreenOnOrOff,
|
||||
setAirplaneMode,
|
||||
setDataConnection,
|
||||
speakText,
|
||||
@ -91,6 +92,8 @@ public class Action
|
||||
return context.getResources().getString(R.string.waitBeforeNextAction);
|
||||
case wakeupDevice:
|
||||
return context.getResources().getString(R.string.wakeupDevice);
|
||||
case turnScreenOnOrOff:
|
||||
return context.getResources().getString(R.string.turnScreenOnOrOff);
|
||||
case vibrate:
|
||||
return context.getResources().getString(R.string.vibrate);
|
||||
case setAirplaneMode:
|
||||
@ -233,6 +236,13 @@ public class Action
|
||||
{
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.wakeupDevice));
|
||||
}
|
||||
else if(this.getAction().equals(Action_Enum.turnScreenOnOrOff))
|
||||
{
|
||||
if(getParameter1())
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.turnScreenOn));
|
||||
else
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.turnScreenOff));
|
||||
}
|
||||
else if(this.getAction().equals(Action_Enum.playSound))
|
||||
{
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.playSound));
|
||||
@ -416,6 +426,25 @@ public class Action
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case turnScreenOnOrOff:
|
||||
if(getParameter1())
|
||||
{
|
||||
Actions.wakeupDevice(Long.parseLong(this.getParameter2()));
|
||||
// wakeupDevice() will create a separate thread. That'll take some time, we wait 100ms.
|
||||
try
|
||||
{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Actions.turnOffScreen();
|
||||
}
|
||||
break;
|
||||
case setAirplaneMode:
|
||||
Actions.setAirplaneMode(this.getParameter1(), toggleActionIfPossible);
|
||||
break;
|
||||
|
@ -1097,7 +1097,7 @@ public class Actions
|
||||
try
|
||||
{
|
||||
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 wakeLock = pm.newWakeLock((PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "Automation:Wakelock");
|
||||
wakeLock.acquire();
|
||||
|
||||
try
|
||||
@ -1118,21 +1118,22 @@ public class Actions
|
||||
}
|
||||
}
|
||||
|
||||
public void turnOnScreen()
|
||||
public static void turnOnScreen()
|
||||
{
|
||||
// turn on screen
|
||||
Log.v("ProximityActivity", "ON!");
|
||||
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, "tag");
|
||||
wakeLock.acquire();
|
||||
}
|
||||
|
||||
@TargetApi(21) //Suppress lint error for PROXIMITY_SCREEN_OFF_WAKE_LOCK
|
||||
public void turnOffScreen(){
|
||||
// turn off screen
|
||||
Log.v("ProximityActivity", "OFF!");
|
||||
public static void turnOffScreen()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Actions", "Turning screen off.", 3);
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
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.acquire();
|
||||
}
|
||||
|
||||
|
@ -1409,6 +1409,8 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.plane));
|
||||
else if(types[i].toString().equals(Action_Enum.wakeupDevice.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.alarm));
|
||||
else if(types[i].toString().equals(Action_Enum.turnScreenOnOrOff.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.smartphone));
|
||||
else if(types[i].toString().equals(Action_Enum.changeSoundProfile.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.sound));
|
||||
else if(types[i].toString().equals(Action_Enum.triggerUrl.toString()))
|
||||
@ -1543,6 +1545,11 @@ public class ActivityManageRule extends Activity
|
||||
newAction.setAction(Action_Enum.wakeupDevice);
|
||||
getActionWakeupDeviceDialog(ActivityManageRule.this).show();
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.turnScreenOnOrOff.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.turnScreenOnOrOff);
|
||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setAirplaneMode.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.setAirplaneMode);
|
||||
|
@ -726,4 +726,7 @@
|
||||
<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>
|
||||
<string name="turnScreenOnOrOff">Turn screen on or off</string>
|
||||
<string name="turnScreenOn">turn screen on</string>
|
||||
<string name="turnScreenOff">turn screen off</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user