More efficient version recycling the scheduling thread

This commit is contained in:
brunoais 2020-07-09 19:00:24 +01:00
commit 22cdab6bfb

View file

@ -28,6 +28,8 @@ public class Controller {
private final MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[PointersState.MAX_POINTERS];
private final MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[PointersState.MAX_POINTERS];
private final Timer keepScreenOffTimer = new Timer("KeepScreenOff", true);
public Controller(Device device, DesktopConnection connection) {
this.device = device;
this.connection = connection;
@ -240,14 +242,12 @@ public class Controller {
*/
public void scheduleScreenOff() {
if (screenStayOff) {
final Timer timing = new Timer("KeepScreenOn", true);
timing.schedule(new TimerTask() {
keepScreenOffTimer.schedule(
new TimerTask() {
@Override
public void run() {
Ln.i("Forcing screen back off");
if (Device.setScreenPowerMode(Device.POWER_MODE_OFF)) {
timing.cancel();
}
Device.setScreenPowerMode(Device.POWER_MODE_OFF);
}
},
100);