Use Java lambdas where possible

This commit is contained in:
Romain Vimont 2023-01-27 22:16:36 +01:00
parent 234ad7ee78
commit bdba554118
2 changed files with 20 additions and 42 deletions

View file

@ -258,12 +258,9 @@ public class Controller {
* Schedule a call to set power mode to off after a small delay. * Schedule a call to set power mode to off after a small delay.
*/ */
private static void schedulePowerModeOff() { private static void schedulePowerModeOff() {
EXECUTOR.schedule(new Runnable() { EXECUTOR.schedule(() -> {
@Override
public void run() {
Ln.i("Forcing screen off"); Ln.i("Forcing screen off");
Device.setScreenPowerMode(Device.POWER_MODE_OFF); Device.setScreenPowerMode(Device.POWER_MODE_OFF);
}
}, 200, TimeUnit.MILLISECONDS); }, 200, TimeUnit.MILLISECONDS);
} }

View file

@ -88,12 +88,7 @@ public final class Server {
controllerThread = startController(controller); controllerThread = startController(controller);
deviceMessageSenderThread = startDeviceMessageSender(controller.getSender()); deviceMessageSenderThread = startDeviceMessageSender(controller.getSender());
device.setClipboardListener(new Device.ClipboardListener() { device.setClipboardListener(text -> controller.getSender().pushClipboardText(text));
@Override
public void onClipboardTextChanged(String text) {
controller.getSender().pushClipboardText(text);
}
});
} }
try { try {
@ -115,43 +110,32 @@ public final class Server {
} }
private static Thread startInitThread(final Options options) { private static Thread startInitThread(final Options options) {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(() -> initAndCleanUp(options));
@Override
public void run() {
initAndCleanUp(options);
}
});
thread.start(); thread.start();
return thread; return thread;
} }
private static Thread startController(final Controller controller) { private static Thread startController(final Controller controller) {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(() -> {
@Override
public void run() {
try { try {
controller.control(); controller.control();
} catch (IOException e) { } catch (IOException e) {
// this is expected on close // this is expected on close
Ln.d("Controller stopped"); Ln.d("Controller stopped");
} }
}
}); });
thread.start(); thread.start();
return thread; return thread;
} }
private static Thread startDeviceMessageSender(final DeviceMessageSender sender) { private static Thread startDeviceMessageSender(final DeviceMessageSender sender) {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(() -> {
@Override
public void run() {
try { try {
sender.loop(); sender.loop();
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
// this is expected on close // this is expected on close
Ln.d("Device message sender stopped"); Ln.d("Device message sender stopped");
} }
}
}); });
thread.start(); thread.start();
return thread; return thread;
@ -327,12 +311,9 @@ public final class Server {
} }
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
@Override
public void uncaughtException(Thread t, Throwable e) {
Ln.e("Exception on thread " + t, e); Ln.e("Exception on thread " + t, e);
suggestFix(e); suggestFix(e);
}
}); });
Options options = createOptions(args); Options options = createOptions(args);