Use Java lambdas where possible

refactor-encoder
Romain Vimont 1 year ago
parent 234ad7ee78
commit bdba554118

@ -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 Ln.i("Forcing screen off");
public void run() { Device.setScreenPowerMode(Device.POWER_MODE_OFF);
Ln.i("Forcing screen off");
Device.setScreenPowerMode(Device.POWER_MODE_OFF);
}
}, 200, TimeUnit.MILLISECONDS); }, 200, TimeUnit.MILLISECONDS);
} }

@ -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,26 +110,18 @@ 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 try {
public void run() { controller.control();
try { } catch (IOException e) {
controller.control(); // this is expected on close
} catch (IOException e) { Ln.d("Controller stopped");
// this is expected on close
Ln.d("Controller stopped");
}
} }
}); });
thread.start(); thread.start();
@ -142,15 +129,12 @@ public final class Server {
} }
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 try {
public void run() { sender.loop();
try { } catch (IOException | InterruptedException e) {
sender.loop(); // this is expected on close
} catch (IOException | InterruptedException e) { Ln.d("Device message sender stopped");
// this is expected on close
Ln.d("Device message sender stopped");
}
} }
}); });
thread.start(); thread.start();
@ -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 Ln.e("Exception on thread " + t, e);
public void uncaughtException(Thread t, Throwable e) { suggestFix(e);
Ln.e("Exception on thread " + t, e);
suggestFix(e);
}
}); });
Options options = createOptions(args); Options options = createOptions(args);

Loading…
Cancel
Save