From 0664cd69765705bdef26353709a7e44851fd85d2 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sat, 11 Feb 2017 22:37:27 +0200 Subject: [PATCH 01/20] Ensure travis is building all branches --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e040132..1e6f6ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,5 @@ language: java -branches: - only: - - master before_install: - chmod +x mvnw jdk: From 19b749d492c668090aed0bdd3b2a25e4d6eaf89d Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sun, 12 Feb 2017 18:12:18 +0200 Subject: [PATCH 02/20] update jnlp version to 0.0.9s --- docs/jnlp/androidscreencast.jnlp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/jnlp/androidscreencast.jnlp b/docs/jnlp/androidscreencast.jnlp index c3ac0d2..06d6d3a 100644 --- a/docs/jnlp/androidscreencast.jnlp +++ b/docs/jnlp/androidscreencast.jnlp @@ -1,7 +1,7 @@ + version="0.0.9s"> Android Screencast Iurii Sergiichuk @@ -16,7 +16,7 @@ + href="https://github.com/xSAVIKx/AndroidScreencast/releases/download/0.0.9s/androidscreencast-0.0.9s-executable.jar"/> From 74e21f9b864ef773d9fc917d6ff0b6750bb62596 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sun, 12 Feb 2017 18:16:31 +0200 Subject: [PATCH 03/20] updated dev version to 0.0.10s-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1802285..810f8c1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.github.xsavikx androidscreencast - 0.0.9s + 0.0.10s-SNAPSHOT Android Screencast 4.3.5.RELEASE From 3cc19720c9d1f5a3c5ff81c5085b2bcaa53b8a64 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sun, 12 Feb 2017 21:31:52 +0200 Subject: [PATCH 04/20] update logging to slf4j+logback updated dependencies and removed log4j logging --- pom.xml | 29 ++++++++++++------- .../xsavikx/androidscreencast/Main.java | 5 ++-- .../api/AndroidDeviceImpl.java | 5 ++-- .../executor/ShellCommandExecutor.java | 5 ++-- .../factory/AdbInputCommandFactory.java | 19 ++++++------ .../api/injector/KeyCodeConverter.java | 5 ++-- .../api/injector/ScreenCaptureRunnable.java | 13 +++++---- .../app/AndroidScreencastApplication.java | 5 ++-- .../app/DeviceChooserApplication.java | 5 ++-- src/main/resources/log4j.properties | 17 ----------- src/main/resources/logback-test.xml | 28 ++++++++++++++++++ src/main/resources/logback.xml | 28 ++++++++++++++++++ 12 files changed, 109 insertions(+), 55 deletions(-) delete mode 100644 src/main/resources/log4j.properties create mode 100644 src/main/resources/logback-test.xml create mode 100644 src/main/resources/logback.xml diff --git a/pom.xml b/pom.xml index 810f8c1..5517c3a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,9 +6,10 @@ 0.0.10s-SNAPSHOT Android Screencast - 4.3.5.RELEASE + 4.3.6.RELEASE 25.2.0 - 1.2.17 + 1.7.22 + 1.2.1 21.0 com.github.xsavikx.androidscreencast.Main 1.8 @@ -25,24 +26,30 @@ ${ddmlib.version} - log4j - log4j - ${log4j.version} + org.slf4j + slf4j-api + ${slf4j.version} - org.springframework - spring-core - ${spring.version} + ch.qos.logback + logback-classic + ${logback-classic.version} - org.springframework - spring-beans - ${spring.version} + org.slf4j + jcl-over-slf4j + ${slf4j.version} org.springframework spring-context ${spring.version} + + + commons-logging + commons-logging + + com.google.guava diff --git a/src/main/java/com/github/xsavikx/androidscreencast/Main.java b/src/main/java/com/github/xsavikx/androidscreencast/Main.java index 32a10bb..a8789fc 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/Main.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/Main.java @@ -3,12 +3,13 @@ import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication; import com.github.xsavikx.androidscreencast.app.Application; import com.github.xsavikx.androidscreencast.spring.config.ApplicationContextProvider; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Arrays; public class Main { - private static final Logger LOGGER = Logger.getLogger(Main.class); + private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); public static void main(String args[]) { LOGGER.debug("main(String[] args=" + Arrays.toString(args) + ") - start"); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java b/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java index f19ac15..cdf196c 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java @@ -7,7 +7,8 @@ import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver; import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException; import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -19,7 +20,7 @@ @Component public class AndroidDeviceImpl implements AndroidDevice { - private static final Logger logger = Logger.getLogger(AndroidDeviceImpl.class); + private static final Logger logger = LoggerFactory.getLogger(AndroidDeviceImpl.class); private final IDevice device; @Autowired diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java index 1327533..1448817 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java @@ -7,7 +7,8 @@ import com.github.xsavikx.androidscreencast.api.command.Command; import com.github.xsavikx.androidscreencast.api.command.exception.AdbShellCommandExecutionException; import com.github.xsavikx.androidscreencast.api.injector.MultiLineReceiverPrinter; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -17,7 +18,7 @@ @Service public class ShellCommandExecutor implements CommandExecutor { - private static final Logger LOGGER = Logger.getLogger(ShellCommandExecutor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ShellCommandExecutor.class); private final IDevice device; private final MultiLineReceiverPrinter multiLineReceiverPrinter; @Value("${adb.command.timeout:5}") diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java index 6682e3c..5c33f6e 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java @@ -4,53 +4,54 @@ import com.github.xsavikx.androidscreencast.api.command.SwipeCommand; import com.github.xsavikx.androidscreencast.api.command.TapCommand; import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @Service public final class AdbInputCommandFactory { - private static final Logger LOGGER = Logger.getLogger(AdbInputCommandFactory.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AdbInputCommandFactory.class); public static KeyCommand getKeyCommand(int keyCode) { KeyCommand returnKeyCommand = new KeyCommand(keyCode); - LOGGER.debug(returnKeyCommand); + LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } public static KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent) { KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent); - LOGGER.debug(returnKeyCommand); + LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } public static KeyCommand getKeyCommand(int keyCode, boolean longpress) { KeyCommand returnKeyCommand = new KeyCommand(keyCode, longpress); - LOGGER.debug(returnKeyCommand); + LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } public static KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) { KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent, longpress); - LOGGER.debug(returnKeyCommand); + LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } public static SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration) { SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2, duration); - LOGGER.debug(returnSwipeCommand); + LOGGER.debug(String.valueOf(returnSwipeCommand)); return returnSwipeCommand; } public static SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2) { SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2); - LOGGER.debug(returnSwipeCommand); + LOGGER.debug(String.valueOf(returnSwipeCommand)); return returnSwipeCommand; } public static TapCommand getTapCommand(int x, int y) { TapCommand returnTapCommand = new TapCommand(x, y); - LOGGER.debug(returnTapCommand); + LOGGER.debug(String.valueOf(returnTapCommand)); return returnTapCommand; } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java index b9d8bd6..244c413 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java @@ -1,11 +1,12 @@ package com.github.xsavikx.androidscreencast.api.injector; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.awt.event.KeyEvent; public class KeyCodeConverter { - private static final Logger LOGGER = Logger.getLogger(KeyCodeConverter.class); + private static final Logger LOGGER = LoggerFactory.getLogger(KeyCodeConverter.class); public static int getKeyCode(KeyEvent e) { LOGGER.debug("getKeyCode(KeyEvent e=" + e + ") - start"); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java index 7d2a16f..9b99779 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java @@ -7,7 +7,8 @@ import com.github.xsavikx.androidscreencast.api.image.ImageUtils; import com.github.xsavikx.androidscreencast.api.recording.QuickTimeOutputStream; import com.github.xsavikx.androidscreencast.exception.IORuntimeException; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -22,7 +23,7 @@ @Component public class ScreenCaptureRunnable implements Runnable { - private static final Logger LOGGER = Logger.getLogger(ScreenCaptureRunnable.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ScreenCaptureRunnable.class); private static final int MOV_FPS = 30; private static final float MOV_COMPRESSION_RATE = 1f; private static final int FRAME_DURATION = 10; @@ -45,14 +46,14 @@ public ScreenCaptureRunnable(IDevice device) { @Override public void run() { - LOGGER.info("Starting ScreenCaptureRunnable"); + LOGGER.info("Starting screen capturing"); while (!isStopped) { try { RawImage screenshot = getScreenshot(); if (screenshot != null) { display(screenshot); } else { - LOGGER.info("Failed to get device screenshot."); + LOGGER.info("Failed to get device screenshot"); } } catch (ClosedByInterruptException e) { LOGGER.error("ADB Channel closed due to interrupted exception", e); @@ -62,7 +63,7 @@ public void run() { break; } } - LOGGER.info("ScreenCaptureRunnable is stopped."); + LOGGER.info("Stopping screen capturing"); } private RawImage getScreenshot() throws InterruptedException, ClosedByInterruptException { @@ -99,7 +100,7 @@ private void display(RawImage rawImage) { try { qos.writeFrame(image, FRAME_DURATION); } catch (IORuntimeException e) { - LOGGER.error(e); + LOGGER.error("IO exception during writing video frame happened", e); } }); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java index c5c73ea..0e31f2e 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java @@ -4,7 +4,8 @@ import com.android.ddmlib.IDevice; import com.github.xsavikx.androidscreencast.api.injector.Injector; import com.github.xsavikx.androidscreencast.ui.JFrameMain; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -15,7 +16,7 @@ @Component public class AndroidScreencastApplication extends SwingApplication { - private static final Logger LOGGER = Logger.getLogger(AndroidScreencastApplication.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AndroidScreencastApplication.class); private final JFrameMain jFrameMain; private final Injector injector; private final IDevice iDevice; diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java index 1a34925..734e232 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java @@ -5,14 +5,15 @@ import com.github.xsavikx.androidscreencast.exception.NoDeviceChosenException; import com.github.xsavikx.androidscreencast.exception.WaitDeviceListTimeoutException; import com.github.xsavikx.androidscreencast.ui.JDialogDeviceList; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class DeviceChooserApplication extends SwingApplication { - private static final Logger LOGGER = Logger.getLogger(DeviceChooserApplication.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DeviceChooserApplication.class); private static final long WAIT_TIMEOUT = 100; private final AndroidDebugBridge bridge; private final long adbWaitSleepCyclesAmount; diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties deleted file mode 100644 index d0af363..0000000 --- a/src/main/resources/log4j.properties +++ /dev/null @@ -1,17 +0,0 @@ -# Root logger option -log4j.rootLogger=TRACE, stdout, file -# Direct log messages to a log file -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=AndroidScreencast.log -log4j.appender.file.MaxFileSize=1MB -log4j.appender.file.MaxBackupIndex=1 -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%-5p] [%C{1}:%L] - %m%n -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} [%-5p] [%C{1}] - %m%n -# Set levels for appenders -log4j.appender.file.Threshold=DEBUG -log4j.appender.stdout.Threshold=INFO diff --git a/src/main/resources/logback-test.xml b/src/main/resources/logback-test.xml new file mode 100644 index 0000000..633cd4c --- /dev/null +++ b/src/main/resources/logback-test.xml @@ -0,0 +1,28 @@ + + + + + %-30(%date{HH:mm:ss} [%thread]) %highlight(%-5level) %logger{0} - %msg%n + + + + AndroidScreencast.log + + %-45(%date{ISO8601} [%thread]) %highlight(%-5level) %logger - %msg%n [%file:%line] + + + 10 + AndroidScreencast.%i.log + + + 1MB + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..633cd4c --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,28 @@ + + + + + %-30(%date{HH:mm:ss} [%thread]) %highlight(%-5level) %logger{0} - %msg%n + + + + AndroidScreencast.log + + %-45(%date{ISO8601} [%thread]) %highlight(%-5level) %logger - %msg%n [%file:%line] + + + 10 + AndroidScreencast.%i.log + + + 1MB + + + + + + + + + + \ No newline at end of file From 5952c29a97bc80cc0e4d997b8b77d6100ca8b12a Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sun, 12 Feb 2017 21:47:43 +0200 Subject: [PATCH 05/20] enhanced apps logging messages --- .../app/AndroidScreencastApplication.java | 40 ++++++-------- .../app/DeviceChooserApplication.java | 53 ++++++++----------- 2 files changed, 40 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java index 0e31f2e..c2ab629 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java @@ -33,35 +33,30 @@ public AndroidScreencastApplication(Injector injector, IDevice iDevice, JFrameMa @Override public void stop() { - try { - LOGGER.debug("stop() - start"); - if (isStopped) { - LOGGER.debug("Application is already stopped."); - return; - } - if (injector != null) - injector.stop(); + LOGGER.info("Stopping application"); + if (isStopped) { + LOGGER.debug("Application is already stopped."); + return; + } + if (injector != null) + injector.stop(); - if (iDevice != null) { - synchronized (iDevice) { - if (hasFilledAdbPath()) - AndroidDebugBridge.disconnectBridge(); - AndroidDebugBridge.terminate(); - } - } - for (Frame frame : Frame.getFrames()) { - frame.dispose(); + if (iDevice != null) { + synchronized (iDevice) { + if (hasFilledAdbPath()) + AndroidDebugBridge.disconnectBridge(); + AndroidDebugBridge.terminate(); } - isStopped = true; - } finally { - LOGGER.debug("stop() - end"); } - + for (Frame frame : Frame.getFrames()) { + frame.dispose(); + } + isStopped = true; } @Override public void start() { - LOGGER.debug("start() - start"); + LOGGER.info("Starting application"); if (iDevice == null) { LOGGER.warn("No valid device was chosen. Please try to chose correct one."); stop(); @@ -75,7 +70,6 @@ public void start() { jFrameMain.launchInjector(); }); - LOGGER.debug("start() - end"); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java index 734e232..ef2e910 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java @@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import static java.lang.String.format; + @Component public class DeviceChooserApplication extends SwingApplication { private static final Logger LOGGER = LoggerFactory.getLogger(DeviceChooserApplication.class); @@ -34,9 +36,27 @@ public void stop() { @Override public void start() { - LOGGER.debug("start() - start"); - initialize(); - LOGGER.debug("start() - end"); + LOGGER.info("Starting application"); + + waitDeviceList(bridge); + + IDevice devices[] = bridge.getDevices(); + + // Let the user choose the device + if (devices.length == 1) { + device = devices[0]; + LOGGER.info("1 device was found by ADB"); + } else { + JDialogDeviceList jd = new JDialogDeviceList(devices); + jd.setVisible(true); + device = jd.getDevice(); + LOGGER.info(format("%d devices were found by ADB", devices.length)); + } + + if (device == null) { + throw new NoDeviceChosenException(); + } + LOGGER.info(format("%s was chosen", device.getName())); } private void waitDeviceList(AndroidDebugBridge bridge) { @@ -51,40 +71,13 @@ private void waitDeviceList(AndroidDebugBridge bridge) { LOGGER.warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e); } - if (count > adbWaitSleepCyclesAmount) { throw new WaitDeviceListTimeoutException(); } } - LOGGER.debug("waitDeviceList(AndroidDebugBridge bridge=" + bridge + ") - end"); } - private void initialize() { - LOGGER.debug("initialize() - start"); - - waitDeviceList(bridge); - - IDevice devices[] = bridge.getDevices(); - // Let the user choose the device - if (devices.length == 1) { - device = devices[0]; - } else { - JDialogDeviceList jd = new JDialogDeviceList(devices); - jd.setVisible(true); - - device = jd.getDevice(); - if (device == null) { - return; - } - } - - if (device == null) { - throw new NoDeviceChosenException(); - } - LOGGER.debug("initialize() - end"); - } - public IDevice getDevice() { return device; } From d3b21721d66954b1526c12749a6dc8ef52c1c3b0 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Wed, 15 Feb 2017 21:20:42 +0200 Subject: [PATCH 06/20] ensure application could be run if adb path is not presented --- .../androidscreencast/app/AndroidScreencastApplication.java | 2 +- .../spring/config/ApplicationConfiguration.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java index c2ab629..e2c70e8 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java @@ -20,7 +20,7 @@ public class AndroidScreencastApplication extends SwingApplication { private final JFrameMain jFrameMain; private final Injector injector; private final IDevice iDevice; - @Value("${adb.path}") + @Value("${adb.path:}") private String adbPath; private transient boolean isStopped = false; diff --git a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java index 27d4f62..695f995 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java @@ -17,7 +17,7 @@ @PropertySource(value = "file:${user.dir}/app.properties", ignoreResourceNotFound = true) }) public class ApplicationConfiguration { - @Value("${adb.path}") + @Value("${adb.path:}") private String adbPath; @Bean From 7be10ae0aa1187f29b6ef37a05f5128b97f35d1a Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Fri, 17 Feb 2017 20:50:43 +0200 Subject: [PATCH 07/20] ensure application won't hang if ADB is misconfigured. also remove String.format from logger calls --- app.properties | 2 +- .../xsavikx/androidscreencast/Main.java | 4 +- .../api/AndroidDeviceImpl.java | 52 ++++++++-------- .../api/adb/AndroidDebugBridgeWrapper.java | 62 +++++++++++++++++++ .../executor/ShellCommandExecutor.java | 6 +- .../api/injector/KeyCodeConverter.java | 4 +- .../api/injector/ScreenCaptureRunnable.java | 2 +- .../api/recording/atom/DataAtom.java | 5 +- .../app/AndroidScreencastApplication.java | 9 --- .../app/DeviceChooserApplication.java | 18 ++---- .../app/SwingApplication.java | 5 +- .../IllegalAdbConfigurationException.java | 10 +++ .../config/ApplicationConfiguration.java | 19 ------ .../androidscreencast/ui/JDialogError.java | 10 ++- 14 files changed, 128 insertions(+), 80 deletions(-) create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java diff --git a/app.properties b/app.properties index 2d7c1f7..1175efc 100644 --- a/app.properties +++ b/app.properties @@ -1,3 +1,3 @@ -adb.path=adb/windows/adb.exe +adb.path=adb/windows/adb2.exe default.window.width=1024 default.window.height=768 \ No newline at end of file diff --git a/src/main/java/com/github/xsavikx/androidscreencast/Main.java b/src/main/java/com/github/xsavikx/androidscreencast/Main.java index a8789fc..4863259 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/Main.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/Main.java @@ -12,14 +12,14 @@ public class Main { private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); public static void main(String args[]) { - LOGGER.debug("main(String[] args=" + Arrays.toString(args) + ") - start"); + LOGGER.debug("main(String[] args={}) - start", Arrays.toString(args)); Application application; try { application = ApplicationContextProvider.getBean(AndroidScreencastApplication.class); application.init(); application.start(); } finally { - LOGGER.debug("main(String[] args=" + Arrays.toString(args) + ") - end"); + LOGGER.debug("main(String[] args={}) - end", Arrays.toString(args)); } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java b/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java index cdf196c..8d0d175 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java @@ -20,7 +20,7 @@ @Component public class AndroidDeviceImpl implements AndroidDevice { - private static final Logger logger = LoggerFactory.getLogger(AndroidDeviceImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AndroidDeviceImpl.class); private final IDevice device; @Autowired @@ -30,26 +30,26 @@ public AndroidDeviceImpl(IDevice device) { @Override public String executeCommand(String cmd) { - if (logger.isDebugEnabled()) { - logger.debug("executeCommand(String) - start"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("executeCommand(String) - start"); } try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) { device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos)); String returnString = new String(bos.toByteArray(), "UTF-8"); - if (logger.isDebugEnabled()) { - logger.debug("executeCommand(String) - end"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("executeCommand(String) - end"); } return returnString; } catch (Exception ex) { - logger.error("executeCommand(String)", ex); + LOGGER.error("executeCommand(String)", ex); throw new ExecuteCommandException(cmd); } } @Override public List list(String path) { - if (logger.isDebugEnabled()) { - logger.debug("list(String) - start"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("list(String) - start"); } try { @@ -74,59 +74,59 @@ public List list(String path) { fileInfos.add(fi); } - if (logger.isDebugEnabled()) { - logger.debug("list(String) - end"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("list(String) - end"); } return fileInfos; } catch (Exception ex) { - logger.error("list(String)", ex); + LOGGER.error("list(String)", ex); throw new AndroidScreenCastRuntimeException(ex); } } @Override public void openUrl(String url) { - if (logger.isDebugEnabled()) { - logger.debug("openUrl(String) - start"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("openUrl(String) - start"); } executeCommand("am start " + url); - if (logger.isDebugEnabled()) { - logger.debug("openUrl(String) - end"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("openUrl(String) - end"); } } @Override public void pullFile(String removeFrom, File localTo) { - if (logger.isDebugEnabled()) { - logger.debug("pullFile(String, File) - start"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("pullFile(String, File) - start"); } // ugly hack to call the method without FileEntry try { if (device.getSyncService() == null) - throw new RuntimeException("SyncService is null, ADB crashed ?"); + throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?"); Method m = device.getSyncService().getClass().getDeclaredMethod("doPullFile", String.class, String.class, ISyncProgressMonitor.class); m.setAccessible(true); device.getSyncService(); m.invoke(device.getSyncService(), removeFrom, localTo.getAbsolutePath(), SyncService.getNullProgressMonitor()); } catch (Exception ex) { - logger.error("pullFile(String, File)", ex); + LOGGER.error("pullFile(String, File)", ex); throw new AndroidScreenCastRuntimeException(ex); } - if (logger.isDebugEnabled()) { - logger.debug("pullFile(String, File) - end"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("pullFile(String, File) - end"); } } @Override public void pushFile(File localFrom, String remoteTo) { - if (logger.isDebugEnabled()) { - logger.debug("pushFile(File, String) - start"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("pushFile(File, String) - start"); } try { @@ -136,13 +136,13 @@ public void pushFile(File localFrom, String remoteTo) { device.getSyncService().pushFile(localFrom.getAbsolutePath(), remoteTo, SyncService.getNullProgressMonitor()); } catch (Exception ex) { - logger.error("pushFile(File, String)", ex); + LOGGER.error("pushFile(File, String)", ex); throw new AndroidScreenCastRuntimeException(ex); } - if (logger.isDebugEnabled()) { - logger.debug("pushFile(File, String) - end"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("pushFile(File, String) - end"); } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java b/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java new file mode 100644 index 0000000..a1daa69 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java @@ -0,0 +1,62 @@ +package com.github.xsavikx.androidscreencast.api.adb; + +import com.android.ddmlib.AndroidDebugBridge; +import com.android.ddmlib.IDevice; +import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.PreDestroy; +import java.io.IOException; + +@Service +public class AndroidDebugBridgeWrapper { + @Value("${adb.path:}") + private String adbPath; + private AndroidDebugBridge adb; + + public IDevice[] getDevices() { + init(); + return adb.getDevices(); + } + + public boolean hasInitialDeviceList() { + init(); + return adb.hasInitialDeviceList(); + } + + + @PreDestroy + private void cleanUp() { + AndroidDebugBridge.disconnectBridge(); + AndroidDebugBridge.terminate(); + } + + private void init() { + if (adb != null) { + return; + } + try { + AndroidDebugBridge.initIfNeeded(false); + if (!StringUtils.isEmpty(adbPath)) { + adb = AndroidDebugBridge.createBridge(adbPath, false); + } else { + adb = AndroidDebugBridge.createBridge(); + } + } catch (IllegalArgumentException e) { + if (hasAdbProcFailed(e)) { + throw new IllegalAdbConfigurationException(adbPath); + } + throw e; + } + } + + private boolean hasAdbProcFailed(IllegalArgumentException e) { + return e.getCause() != null + && e.getCause() instanceof IOException + && e.getCause().getMessage().contains("Cannot run program") + && e.getCause().getMessage().contains("adb"); + + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java index 1448817..047702a 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java @@ -32,17 +32,17 @@ public ShellCommandExecutor(IDevice device, MultiLineReceiverPrinter multiLineRe @Override public void execute(Command command) { - LOGGER.debug("execute(Command command=" + command + ") - start"); + LOGGER.debug("execute(Command command={}) - start", command); try { device.executeShellCommand(command.getFormattedCommand(), multiLineReceiverPrinter, adbCommandTimeout, TimeUnit.SECONDS); } catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e) { - LOGGER.error("execute(Command)", e); + LOGGER.error("execute(Command command={})", command, e); throw new AdbShellCommandExecutionException(command, e); } - LOGGER.debug("execute(Command command=" + command + ") - end"); + LOGGER.debug("execute(Command command={}) - end", command); } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java index 244c413..153b537 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java @@ -9,7 +9,7 @@ public class KeyCodeConverter { private static final Logger LOGGER = LoggerFactory.getLogger(KeyCodeConverter.class); public static int getKeyCode(KeyEvent e) { - LOGGER.debug("getKeyCode(KeyEvent e=" + e + ") - start"); + LOGGER.debug("getKeyCode(KeyEvent e={}) - start", e); int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode(); char c = e.getKeyChar(); int keyCode = e.getKeyCode(); @@ -17,7 +17,7 @@ public static int getKeyCode(KeyEvent e) { if (inputKeyEvent != null) { code = inputKeyEvent.getCode(); } - LOGGER.debug(String.format("Received KeyEvent=%s. Produced KeyCode=%d", String.valueOf(e), code)); + LOGGER.debug("Received KeyEvent={}. Produced KeyCode={}", String.valueOf(e), code); return code; } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java index 9b99779..aa30be8 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java @@ -75,7 +75,7 @@ private RawImage getScreenshot() throws InterruptedException, ClosedByInterruptE currentAdbCommandTimeout = defaultAdbCommandTimeout; } catch (TimeoutException e) { currentAdbCommandTimeout++; - LOGGER.warn(String.format("Adb command timeout happened. Timeout would be set to %d for the next try.", currentAdbCommandTimeout), e); + LOGGER.warn("Adb command timeout happened. Timeout would be set to {} for the next try.", currentAdbCommandTimeout, e); } catch (AdbCommandRejectedException e) { LOGGER.warn("ADB Command was rejected. Will try again in 100 ms."); Thread.sleep(100); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/DataAtom.java b/src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/DataAtom.java index f4927b2..759f3d8 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/DataAtom.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/DataAtom.java @@ -5,6 +5,8 @@ import com.github.xsavikx.androidscreencast.api.recording.exception.MaximumAtomSizeExeededException; import com.github.xsavikx.androidscreencast.exception.IORuntimeException; import com.google.common.base.Preconditions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.imageio.stream.ImageOutputStream; import java.io.IOException; @@ -13,6 +15,7 @@ * Data Atom. */ public class DataAtom extends CommonAtom { + private static final Logger LOGGER = LoggerFactory.getLogger(DataAtom.class); private static final int HEADER_SIZE = 1; protected final DataAtomOutputStream data; @@ -49,7 +52,7 @@ public void finish() { finished = true; long sizeAfter = size(); if (sizeBefore != sizeAfter) { - System.err.println("size mismatch " + sizeBefore + ".." + sizeAfter); + LOGGER.warn("Size mismatch. sizeBefore={}, sizeAfter={}.", sizeBefore, sizeAfter); } } } catch (IOException e) { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java index e2c70e8..d7d71c8 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java @@ -1,6 +1,5 @@ package com.github.xsavikx.androidscreencast.app; -import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.IDevice; import com.github.xsavikx.androidscreencast.api.injector.Injector; import com.github.xsavikx.androidscreencast.ui.JFrameMain; @@ -40,14 +39,6 @@ public void stop() { } if (injector != null) injector.stop(); - - if (iDevice != null) { - synchronized (iDevice) { - if (hasFilledAdbPath()) - AndroidDebugBridge.disconnectBridge(); - AndroidDebugBridge.terminate(); - } - } for (Frame frame : Frame.getFrames()) { frame.dispose(); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java index ef2e910..2b4ac49 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java @@ -1,7 +1,7 @@ package com.github.xsavikx.androidscreencast.app; -import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.IDevice; +import com.github.xsavikx.androidscreencast.api.adb.AndroidDebugBridgeWrapper; import com.github.xsavikx.androidscreencast.exception.NoDeviceChosenException; import com.github.xsavikx.androidscreencast.exception.WaitDeviceListTimeoutException; import com.github.xsavikx.androidscreencast.ui.JDialogDeviceList; @@ -11,20 +11,18 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import static java.lang.String.format; - @Component public class DeviceChooserApplication extends SwingApplication { private static final Logger LOGGER = LoggerFactory.getLogger(DeviceChooserApplication.class); private static final long WAIT_TIMEOUT = 100; - private final AndroidDebugBridge bridge; + private final AndroidDebugBridgeWrapper bridge; private final long adbWaitSleepCyclesAmount; @Value("${adb.device.timeout:30}") private long adbDeviceTimeout; private IDevice device; @Autowired - public DeviceChooserApplication(AndroidDebugBridge bridge) { + public DeviceChooserApplication(AndroidDebugBridgeWrapper bridge) { this.bridge = bridge; this.adbWaitSleepCyclesAmount = adbDeviceTimeout * 10; } @@ -50,18 +48,16 @@ public void start() { JDialogDeviceList jd = new JDialogDeviceList(devices); jd.setVisible(true); device = jd.getDevice(); - LOGGER.info(format("%d devices were found by ADB", devices.length)); + LOGGER.info("{} devices were found by ADB", devices.length); } if (device == null) { throw new NoDeviceChosenException(); } - LOGGER.info(format("%s was chosen", device.getName())); + LOGGER.info("{} was chosen", device.getName()); } - private void waitDeviceList(AndroidDebugBridge bridge) { - LOGGER.debug("waitDeviceList(AndroidDebugBridge bridge=" + bridge + ") - start"); - + private void waitDeviceList(AndroidDebugBridgeWrapper bridge) { int count = 0; while (!bridge.hasInitialDeviceList()) { try { @@ -69,13 +65,11 @@ private void waitDeviceList(AndroidDebugBridge bridge) { count++; } catch (InterruptedException e) { LOGGER.warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e); - } if (count > adbWaitSleepCyclesAmount) { throw new WaitDeviceListTimeoutException(); } } - LOGGER.debug("waitDeviceList(AndroidDebugBridge bridge=" + bridge + ") - end"); } public IDevice getDevice() { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java index 1a19362..0732b80 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java @@ -2,6 +2,8 @@ import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException; import com.github.xsavikx.androidscreencast.ui.JDialogError; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import javax.swing.*; @@ -9,6 +11,7 @@ import java.io.StringWriter; public abstract class SwingApplication extends GUIApplication { + private static final Logger LOGGER = LoggerFactory.getLogger(DeviceChooserApplication.class); private JDialogError jd = null; @Value("${app.native.look:true}") private boolean nativeLook; @@ -34,7 +37,7 @@ public void handleException(Thread thread, Throwable ex) { ex.printStackTrace(new PrintWriter(sw)); if (sw.toString().contains("SynthTreeUI")) return; - ex.printStackTrace(System.err); + LOGGER.error(ex.getClass().getSimpleName(), ex); if (jd != null && jd.isVisible()) return; jd = new JDialogError(ex); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java b/src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java new file mode 100644 index 0000000..7c13535 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java @@ -0,0 +1,10 @@ +package com.github.xsavikx.androidscreencast.exception; + +/** + * Created by User on 16.02.2017. + */ +public class IllegalAdbConfigurationException extends AndroidScreenCastRuntimeException { + public IllegalAdbConfigurationException(String adbPath) { + super(String.format("Exception happened during running your ADB instance. Probably ADB path is misconfigured. ADB path='%s'", adbPath)); + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java index 695f995..50ebc06 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java @@ -1,15 +1,11 @@ package com.github.xsavikx.androidscreencast.spring.config; -import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.IDevice; import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.annotation.*; -import org.springframework.util.StringUtils; - -import javax.annotation.PreDestroy; @Configuration @ComponentScan(basePackages = "com.github.xsavikx.androidscreencast") @@ -20,21 +16,6 @@ public class ApplicationConfiguration { @Value("${adb.path:}") private String adbPath; - @Bean - public AndroidDebugBridge initAndroidDebugBridge() { - AndroidDebugBridge.initIfNeeded(false); - if (!StringUtils.isEmpty(adbPath)) { - return AndroidDebugBridge.createBridge(adbPath, false); - } - return AndroidDebugBridge.createBridge(); - } - - @PreDestroy - public void preDestroy() { - AndroidDebugBridge.disconnectBridge(); - AndroidDebugBridge.terminate(); - } - @Bean public DefaultListableBeanFactory initBeanFactory() { return new DefaultListableBeanFactory(); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java index 171518c..4e7bcb4 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java @@ -2,6 +2,7 @@ import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException; import com.github.xsavikx.androidscreencast.exception.IORuntimeException; +import org.springframework.util.StringUtils; import javax.swing.*; import java.awt.*; @@ -53,10 +54,13 @@ private void setErrorDetails(Throwable e) { AndroidScreenCastRuntimeException realCause = getCause(ex); if (realCause != null) { errorDialogLabel.setText(realCause.getClass().getSimpleName()); - stringWriter.append(realCause.getMessage()).append('\n').append('\n'); - stringWriter.append(realCause.getAdditionalInformation()); + if (!StringUtils.isEmpty(realCause.getMessage())) + stringWriter.append(realCause.getMessage()).append('\n').append('\n'); + if (!StringUtils.isEmpty(realCause.getAdditionalInformation())) + stringWriter.append(realCause.getAdditionalInformation()); } else { - stringWriter.append(ex.getMessage()).append('\n').append('\n'); + if (!StringUtils.isEmpty(ex.getMessage())) + stringWriter.append(ex.getMessage()).append('\n').append('\n'); ex.printStackTrace(new PrintWriter(stringWriter)); } errorDescription.setText(stringWriter.toString()); From 4cc6fbb6602c3b60cb0b48031d9caf094d21c19b Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Fri, 17 Feb 2017 21:04:52 +0200 Subject: [PATCH 08/20] added License badge and formatted badges markup --- README.md | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 94655bc..ee12fba 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,11 @@ AndroidScreencast ================= -[![Build Status Travis-CI][travis_badge]][travis] [![Dependency Status][versioneye_badge]][versioneye] [![Codacy Badge][codacy_badge]][codacy] [![Join the chat at https://gitter.im/AndroidScreencast/Lobby][gitter_badge]][gitter] - -[travis_badge]: https://travis-ci.org/xSAVIKx/AndroidScreencast.svg?branch=master -[travis]: https://travis-ci.org/xSAVIKx/AndroidScreencast - -[versioneye_badge]: https://www.versioneye.com/user/projects/588988221618a700318eafb5/badge.svg -[versioneye]: https://www.versioneye.com/user/projects/588988221618a700318eafb5 - -[codacy_badge]: https://api.codacy.com/project/badge/Grade/064bbd2582b544bb9659a01a2872317c -[codacy]: https://www.codacy.com/app/xSAVIKx/AndroidScreencast?utm_source=github.com&utm_medium=referral&utm_content=xSAVIKx/AndroidScreencast&utm_campaign=badger - - - -[gitter_badge]: https://badges.gitter.im/AndroidScreencast/Lobby.svg -[gitter]: https://gitter.im/AndroidScreencast/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge +[![Build Status Travis-CI][travis_badge]][travis]  +[![Dependency Status][versioneye_badge]][versioneye]  +[![Codacy Badge][codacy_badge]][codacy]  +[![Join the chat at https://gitter.im/AndroidScreencast/Lobby][gitter_badge]][gitter]  +[![Apache License][license_badge]][license] # Description @@ -83,3 +73,19 @@ So, right now AndroidScreencast support all Android versions equal or greater th Also, to run AndroidScreencast you will need *adb* installed (or you can use bundled in OS bundles adb). [Android_4_1_1_Input]: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/com/android/commands/input/Input.java#Input + + +[travis_badge]: https://travis-ci.org/xSAVIKx/AndroidScreencast.svg?branch=master +[travis]: https://travis-ci.org/xSAVIKx/AndroidScreencast + +[versioneye_badge]: https://www.versioneye.com/user/projects/588988221618a700318eafb5/badge.svg +[versioneye]: https://www.versioneye.com/user/projects/588988221618a700318eafb5 + +[codacy_badge]: https://api.codacy.com/project/badge/Grade/064bbd2582b544bb9659a01a2872317c +[codacy]: https://www.codacy.com/app/xSAVIKx/AndroidScreencast?utm_source=github.com&utm_medium=referral&utm_content=xSAVIKx/AndroidScreencast&utm_campaign=badger + +[license_badge]: https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat +[license]: http://www.apache.org/licenses/LICENSE-2.0 + +[gitter_badge]: https://badges.gitter.im/AndroidScreencast/Lobby.svg +[gitter]: https://gitter.im/AndroidScreencast/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge \ No newline at end of file From 60f8aea33f7bb291ac64b32ec3c7aa94dffac7b5 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Fri, 17 Feb 2017 21:10:19 +0200 Subject: [PATCH 09/20] update versioneye badge to point develop branch. update gitter badge style --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ee12fba..9ced855 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,8 @@ Also, to run AndroidScreencast you will need *adb* installed (or you can use bun [travis_badge]: https://travis-ci.org/xSAVIKx/AndroidScreencast.svg?branch=master [travis]: https://travis-ci.org/xSAVIKx/AndroidScreencast -[versioneye_badge]: https://www.versioneye.com/user/projects/588988221618a700318eafb5/badge.svg -[versioneye]: https://www.versioneye.com/user/projects/588988221618a700318eafb5 +[versioneye_badge]: https://www.versioneye.com/user/projects/58a746d8b4d2a20055fcb887/badge.svg?style=flat +[versioneye]: https://www.versioneye.com/user/projects/58a746d8b4d2a20055fcb887 [codacy_badge]: https://api.codacy.com/project/badge/Grade/064bbd2582b544bb9659a01a2872317c [codacy]: https://www.codacy.com/app/xSAVIKx/AndroidScreencast?utm_source=github.com&utm_medium=referral&utm_content=xSAVIKx/AndroidScreencast&utm_campaign=badger @@ -87,5 +87,5 @@ Also, to run AndroidScreencast you will need *adb* installed (or you can use bun [license_badge]: https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat [license]: http://www.apache.org/licenses/LICENSE-2.0 -[gitter_badge]: https://badges.gitter.im/AndroidScreencast/Lobby.svg +[gitter_badge]: https://badges.gitter.im/AndroidScreencast/Lobby.svg?style=flat [gitter]: https://gitter.im/AndroidScreencast/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge \ No newline at end of file From ad17b5eadb52c43fc755c4f4f0d3b57dc9ea9e54 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sun, 19 Feb 2017 22:12:52 +0200 Subject: [PATCH 10/20] fix codacy issues --- .../api/adb/AndroidDebugBridgeWrapper.java | 2 +- .../app/AndroidScreencastApplication.java | 9 --------- .../spring/config/ApplicationConfiguration.java | 3 --- .../xsavikx/androidscreencast/ui/worker/SwingWorker.java | 2 ++ 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java b/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java index a1daa69..fff2062 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java @@ -28,7 +28,7 @@ public boolean hasInitialDeviceList() { @PreDestroy - private void cleanUp() { + void cleanUp() { AndroidDebugBridge.disconnectBridge(); AndroidDebugBridge.terminate(); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java index d7d71c8..1025c1c 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java @@ -6,9 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; import javax.swing.*; import java.awt.*; @@ -19,8 +17,6 @@ public class AndroidScreencastApplication extends SwingApplication { private final JFrameMain jFrameMain; private final Injector injector; private final IDevice iDevice; - @Value("${adb.path:}") - private String adbPath; private transient boolean isStopped = false; @Autowired @@ -62,9 +58,4 @@ public void start() { jFrameMain.launchInjector(); }); } - - - private boolean hasFilledAdbPath() { - return !StringUtils.isEmpty(adbPath); - } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java index 50ebc06..e8d11a7 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java @@ -3,7 +3,6 @@ import com.android.ddmlib.IDevice; import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.annotation.*; @@ -13,8 +12,6 @@ @PropertySource(value = "file:${user.dir}/app.properties", ignoreResourceNotFound = true) }) public class ApplicationConfiguration { - @Value("${adb.path:}") - private String adbPath; @Bean public DefaultListableBeanFactory initBeanFactory() { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/worker/SwingWorker.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/worker/SwingWorker.java index 736bca8..b83a5c5 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/worker/SwingWorker.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/worker/SwingWorker.java @@ -372,6 +372,7 @@ public final boolean cancel(boolean mayInterruptIfRunning) { * @see #get */ protected void done() { + // } // Future methods START @@ -605,6 +606,7 @@ public final boolean isDone() { * @see #publish */ protected void process(List chunks) { + // } // PropertyChangeSupports methods END From 9cce19de7a2b58431cc7319d156873052e4fb19b Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sat, 25 Feb 2017 20:25:15 +0200 Subject: [PATCH 11/20] added similar projects section --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ced855..7ace09f 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,15 @@ So, right now AndroidScreencast support all Android versions equal or greater th Also, to run AndroidScreencast you will need *adb* installed (or you can use bundled in OS bundles adb). -[Android_4_1_1_Input]: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/com/android/commands/input/Input.java#Input +# Similar Projects + +* [Seven Square][seven_square] - QT implementation of Android Screencast (actively developed) +* [Droid@Screen][droid_at_screen] - implementation of Android Screencast in Java (fancy one, last release in 2013) +* [Android Screen Monitor][android_screen_monitor] - implementation of Android Screencast in Java (latest release in 2013) +[Android_4_1_1_Input]: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/com/android/commands/input/Input.java#Input +[seven_square]: https://github.com/yangh/sevensquare +[droid_at_screen]: http://droid-at-screen.org/droid-at-screen/ [travis_badge]: https://travis-ci.org/xSAVIKx/AndroidScreencast.svg?branch=master [travis]: https://travis-ci.org/xSAVIKx/AndroidScreencast @@ -88,4 +95,4 @@ Also, to run AndroidScreencast you will need *adb* installed (or you can use bun [license]: http://www.apache.org/licenses/LICENSE-2.0 [gitter_badge]: https://badges.gitter.im/AndroidScreencast/Lobby.svg?style=flat -[gitter]: https://gitter.im/AndroidScreencast/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge \ No newline at end of file +[gitter]: https://gitter.im/AndroidScreencast/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge From fe873064c9efcdb3e43ae08f357b0fa68d9dead4 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Sun, 26 Feb 2017 00:59:38 +0200 Subject: [PATCH 12/20] introduced Dagger2 as new DI framework --- pom.xml | 21 +++---- .../xsavikx/androidscreencast/Main.java | 6 +- .../api/AndroidDeviceImpl.java | 44 +++++++------- .../api/adb/AndroidDebugBridgeWrapper.java | 39 +++++++----- .../executor/ShellCommandExecutor.java | 20 ++++--- .../factory/AdbInputCommandFactory.java | 2 - .../androidscreencast/api/file/FileInfo.java | 10 +++- .../api/injector/Injector.java | 16 ++--- .../api/injector/InputKeyEvent.java | 2 - .../injector/MultiLineReceiverPrinter.java | 10 +++- .../api/injector/ScreenCaptureRunnable.java | 44 +++++++------- .../app/AndroidScreencastApplication.java | 26 ++++---- .../app/DeviceChooserApplication.java | 60 +++++++++++-------- .../androidscreencast/app/GUIApplication.java | 13 ++-- .../app/SwingApplication.java | 28 +++++---- .../ApplicationConfiguration.java | 43 +++++++++++++ .../ApplicationConfigurationProperty.java | 27 +++++++++ .../ApplicationConfigurationPropertyKeys.java | 14 +++++ .../androidscreencast/constant/Constants.java | 11 ---- .../androidscreencast/dagger/ApiModule.java | 51 ++++++++++++++++ .../androidscreencast/dagger/AppModule.java | 29 +++++++++ .../dagger/MainComponent.java | 15 +++++ .../dagger/MainComponentProvider.java | 16 +++++ .../androidscreencast/dagger/UiModule.java | 29 +++++++++ .../config/ApplicationConfiguration.java | 30 ---------- .../config/ApplicationContextProvider.java | 30 ---------- .../androidscreencast/ui/JDialogError.java | 8 +-- .../ui/JDialogExecuteKeyEvent.java | 6 +- .../androidscreencast/ui/JFrameMain.java | 58 +++++++++--------- .../androidscreencast/ui/JPanelScreen.java | 21 +++---- .../ui/explorer/JFrameExplorer.java | 6 +- .../interaction/KeyEventDispatcherImpl.java | 4 +- .../interaction/KeyboardActionListener.java | 4 +- .../ui/interaction/MouseActionAdapter.java | 6 +- .../androidscreencast/util/StringUtils.java | 11 ++++ 35 files changed, 484 insertions(+), 276 deletions(-) create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfiguration.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationProperty.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java delete mode 100644 src/main/java/com/github/xsavikx/androidscreencast/constant/Constants.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java delete mode 100644 src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java delete mode 100644 src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationContextProvider.java create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java diff --git a/pom.xml b/pom.xml index 5517c3a..16fa716 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 0.0.10s-SNAPSHOT Android Screencast - 4.3.6.RELEASE + 2.9 25.2.0 1.7.22 1.2.1 @@ -41,15 +41,16 @@ ${slf4j.version} - org.springframework - spring-context - ${spring.version} - - - commons-logging - commons-logging - - + com.google.dagger + dagger + ${dagger2.version} + + + com.google.dagger + dagger-compiler + ${dagger2.version} + true + provided com.google.guava diff --git a/src/main/java/com/github/xsavikx/androidscreencast/Main.java b/src/main/java/com/github/xsavikx/androidscreencast/Main.java index 4863259..cb5e810 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/Main.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/Main.java @@ -1,8 +1,7 @@ package com.github.xsavikx.androidscreencast; -import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication; import com.github.xsavikx.androidscreencast.app.Application; -import com.github.xsavikx.androidscreencast.spring.config.ApplicationContextProvider; +import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,9 +12,8 @@ public class Main { public static void main(String args[]) { LOGGER.debug("main(String[] args={}) - start", Arrays.toString(args)); - Application application; try { - application = ApplicationContextProvider.getBean(AndroidScreencastApplication.class); + Application application = MainComponentProvider.mainComponent().application(); application.init(); application.start(); } finally { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java b/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java index 8d0d175..295d671 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java @@ -9,54 +9,54 @@ import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import javax.inject.Inject; +import javax.inject.Singleton; import java.io.ByteArrayOutputStream; import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -@Component +@Singleton public class AndroidDeviceImpl implements AndroidDevice { private static final Logger LOGGER = LoggerFactory.getLogger(AndroidDeviceImpl.class); private final IDevice device; - @Autowired - public AndroidDeviceImpl(IDevice device) { + @Inject + public AndroidDeviceImpl(final IDevice device) { this.device = device; } @Override - public String executeCommand(String cmd) { + public String executeCommand(final String cmd) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("executeCommand(String) - start"); } - try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) { + try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();) { device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos)); - String returnString = new String(bos.toByteArray(), "UTF-8"); + final String returnString = new String(bos.toByteArray(), "UTF-8"); if (LOGGER.isDebugEnabled()) { LOGGER.debug("executeCommand(String) - end"); } return returnString; - } catch (Exception ex) { + } catch (final Exception ex) { LOGGER.error("executeCommand(String)", ex); throw new ExecuteCommandException(cmd); } } @Override - public List list(String path) { + public List list(final String path) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("list(String) - start"); } try { - String s = executeCommand("ls -l " + path); - String[] entries = s.split("\r\n"); - List fileInfos = new ArrayList<>(); - for (String entry : entries) { + final String s = executeCommand("ls -l " + path); + final String[] entries = s.split("\r\n"); + final List fileInfos = new ArrayList<>(); + for (final String entry : entries) { String[] data = entry.split(" "); if (data.length < 4) continue; @@ -64,7 +64,7 @@ public List list(String path) { boolean directory = attributes.charAt(0) == 'd'; String name = data[data.length - 1]; - FileInfo fi = new FileInfo(); + final FileInfo fi = new FileInfo(); fi.attribs = attributes; fi.directory = directory; fi.name = name; @@ -78,14 +78,14 @@ public List list(String path) { LOGGER.debug("list(String) - end"); } return fileInfos; - } catch (Exception ex) { + } catch (final Exception ex) { LOGGER.error("list(String)", ex); throw new AndroidScreenCastRuntimeException(ex); } } @Override - public void openUrl(String url) { + public void openUrl(final String url) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("openUrl(String) - start"); } @@ -98,7 +98,7 @@ public void openUrl(String url) { } @Override - public void pullFile(String removeFrom, File localTo) { + public void pullFile(final String removeFrom, final File localTo) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("pullFile(String, File) - start"); } @@ -107,12 +107,12 @@ public void pullFile(String removeFrom, File localTo) { try { if (device.getSyncService() == null) throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?"); - Method m = device.getSyncService().getClass().getDeclaredMethod("doPullFile", String.class, String.class, + final Method m = device.getSyncService().getClass().getDeclaredMethod("doPullFile", String.class, String.class, ISyncProgressMonitor.class); m.setAccessible(true); device.getSyncService(); m.invoke(device.getSyncService(), removeFrom, localTo.getAbsolutePath(), SyncService.getNullProgressMonitor()); - } catch (Exception ex) { + } catch (final Exception ex) { LOGGER.error("pullFile(String, File)", ex); throw new AndroidScreenCastRuntimeException(ex); @@ -124,7 +124,7 @@ public void pullFile(String removeFrom, File localTo) { } @Override - public void pushFile(File localFrom, String remoteTo) { + public void pushFile(final File localFrom, final String remoteTo) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("pushFile(File, String) - start"); } @@ -135,7 +135,7 @@ public void pushFile(File localFrom, String remoteTo) { device.getSyncService().pushFile(localFrom.getAbsolutePath(), remoteTo, SyncService.getNullProgressMonitor()); - } catch (Exception ex) { + } catch (final Exception ex) { LOGGER.error("pushFile(File, String)", ex); throw new AndroidScreenCastRuntimeException(ex); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java b/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java index fff2062..d9e9a90 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java @@ -3,43 +3,52 @@ import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.IDevice; import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; +import com.github.xsavikx.androidscreencast.util.StringUtils; -import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; import java.io.IOException; -@Service +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY; + +@Singleton public class AndroidDebugBridgeWrapper { - @Value("${adb.path:}") - private String adbPath; + private final String adbPath; private AndroidDebugBridge adb; + @Inject + public AndroidDebugBridgeWrapper(@Named(ADB_PATH_KEY) String adbPath) { + this.adbPath = adbPath; + } + public IDevice[] getDevices() { - init(); - return adb.getDevices(); + return getAdb().getDevices(); } public boolean hasInitialDeviceList() { - init(); - return adb.hasInitialDeviceList(); + return getAdb().hasInitialDeviceList(); } - - @PreDestroy - void cleanUp() { + public void stop() { AndroidDebugBridge.disconnectBridge(); AndroidDebugBridge.terminate(); } + private AndroidDebugBridge getAdb() { + if (adb == null) { + init(); + } + return adb; + } + private void init() { if (adb != null) { return; } try { AndroidDebugBridge.initIfNeeded(false); - if (!StringUtils.isEmpty(adbPath)) { + if (StringUtils.isNotEmpty(adbPath)) { adb = AndroidDebugBridge.createBridge(adbPath, false); } else { adb = AndroidDebugBridge.createBridge(); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java index 047702a..41a3830 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java @@ -9,25 +9,29 @@ import com.github.xsavikx.androidscreencast.api.injector.MultiLineReceiverPrinter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; import java.io.IOException; import java.util.concurrent.TimeUnit; -@Service +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY; + +@Singleton public class ShellCommandExecutor implements CommandExecutor { private static final Logger LOGGER = LoggerFactory.getLogger(ShellCommandExecutor.class); private final IDevice device; private final MultiLineReceiverPrinter multiLineReceiverPrinter; - @Value("${adb.command.timeout:5}") - private long adbCommandTimeout; + private final long adbCommandTimeout; - @Autowired - public ShellCommandExecutor(IDevice device, MultiLineReceiverPrinter multiLineReceiverPrinter) { + @Inject + public ShellCommandExecutor(final IDevice device, + final MultiLineReceiverPrinter multiLineReceiverPrinter, + @Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) { this.device = device; this.multiLineReceiverPrinter = multiLineReceiverPrinter; + this.adbCommandTimeout = adbCommandTimeout; } @Override diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java index 5c33f6e..86b9f3a 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java @@ -6,9 +6,7 @@ import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; -@Service public final class AdbInputCommandFactory { private static final Logger LOGGER = LoggerFactory.getLogger(AdbInputCommandFactory.class); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java b/src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java index 007de7f..a49804c 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java @@ -2,12 +2,13 @@ import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl; import com.github.xsavikx.androidscreencast.exception.IORuntimeException; -import org.springframework.stereotype.Component; +import javax.inject.Inject; +import javax.inject.Singleton; import java.io.File; import java.io.IOException; -@Component +@Singleton public class FileInfo { public AndroidDeviceImpl device; public String path; @@ -15,6 +16,11 @@ public class FileInfo { public boolean directory; public String name; + @Inject + public FileInfo() { + + } + public File downloadTemporary() { try { File tempFile = File.createTempFile("android", name); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/Injector.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/Injector.java index eed9306..13fde3b 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/Injector.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/Injector.java @@ -1,19 +1,19 @@ package com.github.xsavikx.androidscreencast.api.injector; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - +import javax.inject.Inject; +import javax.inject.Singleton; import java.io.File; -@Service +@Singleton public class Injector { private final ScreenCaptureRunnable screenCaptureRunnable; private final Thread screenCaptureThread; - @Autowired - public Injector(ScreenCaptureRunnable screenCaptureRunnable) { + @Inject + public Injector(final ScreenCaptureRunnable screenCaptureRunnable) { this.screenCaptureRunnable = screenCaptureRunnable; this.screenCaptureThread = new Thread(screenCaptureRunnable, "Screen Capturer"); + this.screenCaptureThread.setDaemon(true); } public void stop() { @@ -24,11 +24,11 @@ public void start() { screenCaptureThread.start(); } - public void setScreenCaptureListener(ScreenCaptureRunnable.ScreenCaptureListener listener) { + public void setScreenCaptureListener(final ScreenCaptureRunnable.ScreenCaptureListener listener) { this.screenCaptureRunnable.setListener(listener); } - public void startRecording(File file) { + public void startRecording(final File file) { screenCaptureRunnable.startRecording(file); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/InputKeyEvent.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/InputKeyEvent.java index ddaa0f6..ddf8ceb 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/InputKeyEvent.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/InputKeyEvent.java @@ -1,12 +1,10 @@ //@formatter:off package com.github.xsavikx.androidscreencast.api.injector; -import javax.annotation.Resource; import java.awt.event.KeyEvent; import java.util.EnumSet; import java.util.Set; -@Resource public enum InputKeyEvent { KEYCODE_UNKNOWN(0, "Key code constant: Unknown key code."), KEYCODE_SOFT_LEFT(1, "Key code constant: Soft Left key. Usually situated below the display on phones and used as a multi-function feature key for selecting a software defined function shown on the bottom left of the display."), diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/MultiLineReceiverPrinter.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/MultiLineReceiverPrinter.java index d33a9ce..0233842 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/MultiLineReceiverPrinter.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/MultiLineReceiverPrinter.java @@ -1,10 +1,16 @@ package com.github.xsavikx.androidscreencast.api.injector; import com.android.ddmlib.MultiLineReceiver; -import org.springframework.stereotype.Component; -@Component +import javax.inject.Inject; +import javax.inject.Singleton; + +@Singleton public class MultiLineReceiverPrinter extends MultiLineReceiver { + @Inject + public MultiLineReceiverPrinter() { + + } @Override public boolean isCancelled() { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java index aa30be8..2fa4169 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java @@ -9,10 +9,10 @@ import com.github.xsavikx.androidscreencast.exception.IORuntimeException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; @@ -21,27 +21,29 @@ import java.nio.channels.ClosedByInterruptException; import java.util.concurrent.TimeUnit; -@Component +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY; + +@Singleton public class ScreenCaptureRunnable implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(ScreenCaptureRunnable.class); private static final int MOV_FPS = 30; private static final float MOV_COMPRESSION_RATE = 1f; private static final int FRAME_DURATION = 10; private final IDevice device; + private final long defaultAdbCommandTimeout; private Dimension size; private QuickTimeOutputStream qos = null; private boolean landscape = false; private ScreenCaptureListener listener = null; - @Value("${adb.command.timeout:5}") - private long defaultAdbCommandTimeout; - @Value("${adb.command.timeout:5}") private long currentAdbCommandTimeout; private boolean isStopped = false; - @Autowired - public ScreenCaptureRunnable(IDevice device) { - size = new Dimension(); + @Inject + public ScreenCaptureRunnable(final IDevice device, @Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) { + this.size = new Dimension(); this.device = device; + this.defaultAdbCommandTimeout = adbCommandTimeout; + this.currentAdbCommandTimeout = defaultAdbCommandTimeout; } @Override @@ -49,16 +51,16 @@ public void run() { LOGGER.info("Starting screen capturing"); while (!isStopped) { try { - RawImage screenshot = getScreenshot(); + final RawImage screenshot = getScreenshot(); if (screenshot != null) { display(screenshot); } else { LOGGER.info("Failed to get device screenshot"); } - } catch (ClosedByInterruptException e) { + } catch (final ClosedByInterruptException e) { LOGGER.error("ADB Channel closed due to interrupted exception", e); break; - } catch (InterruptedException e) { + } catch (final InterruptedException e) { LOGGER.error("Execution of thread was interrupted. Shutting down thread.", e); break; } @@ -88,9 +90,9 @@ private RawImage getScreenshot() throws InterruptedException, ClosedByInterruptE return rawImage; } - private void display(RawImage rawImage) { - RawImage imageToProcess = landscape ? rawImage.getRotated() : rawImage; - BufferedImage image = ImageUtils.convertImage(imageToProcess); + private void display(final RawImage rawImage) { + final RawImage imageToProcess = landscape ? rawImage.getRotated() : rawImage; + final BufferedImage image = ImageUtils.convertImage(imageToProcess); size.setSize(image.getWidth(), image.getHeight()); if (listener != null) { SwingUtilities.invokeLater(() -> listener.handleNewImage(size, image, landscape)); @@ -106,19 +108,19 @@ private void display(RawImage rawImage) { } } - public void setListener(ScreenCaptureListener listener) { + public void setListener(final ScreenCaptureListener listener) { this.listener = listener; } - public void startRecording(File file) { + public void startRecording(final File file) { try { qos = new QuickTimeOutputStream(file, QuickTimeOutputStream.VideoFormat.JPG); - } catch (IOException e) { + qos.setVideoCompressionQuality(MOV_COMPRESSION_RATE); + qos.setTimeScale(MOV_FPS); + } catch (final IOException e) { throw new IORuntimeException(e); } - qos.setVideoCompressionQuality(MOV_COMPRESSION_RATE); - qos.setTimeScale(MOV_FPS); } public void stopRecording() { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java index 1025c1c..306b468 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java @@ -1,29 +1,35 @@ package com.github.xsavikx.androidscreencast.app; import com.android.ddmlib.IDevice; +import com.github.xsavikx.androidscreencast.api.adb.AndroidDebugBridgeWrapper; import com.github.xsavikx.androidscreencast.api.injector.Injector; +import com.github.xsavikx.androidscreencast.configuration.ApplicationConfiguration; import com.github.xsavikx.androidscreencast.ui.JFrameMain; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import javax.inject.Inject; +import javax.inject.Singleton; import javax.swing.*; import java.awt.*; -@Component +@Singleton public class AndroidScreencastApplication extends SwingApplication { private static final Logger LOGGER = LoggerFactory.getLogger(AndroidScreencastApplication.class); private final JFrameMain jFrameMain; private final Injector injector; private final IDevice iDevice; + private final AndroidDebugBridgeWrapper wrapper; private transient boolean isStopped = false; - @Autowired - public AndroidScreencastApplication(Injector injector, IDevice iDevice, JFrameMain jFrameMain) { + @Inject + public AndroidScreencastApplication(final Injector injector, final IDevice iDevice, final JFrameMain jFrameMain, + final ApplicationConfiguration applicationConfiguration, AndroidDebugBridgeWrapper wrapper) { + super(applicationConfiguration); this.injector = injector; this.iDevice = iDevice; this.jFrameMain = jFrameMain; + this.wrapper = wrapper; } @Override @@ -33,9 +39,9 @@ public void stop() { LOGGER.debug("Application is already stopped."); return; } - if (injector != null) - injector.stop(); - for (Frame frame : Frame.getFrames()) { + injector.stop(); + wrapper.stop(); + for (final Frame frame : Frame.getFrames()) { frame.dispose(); } isStopped = true; @@ -49,9 +55,9 @@ public void start() { stop(); } SwingUtilities.invokeLater(() -> { + jFrameMain.initialize(); // Start showing the iDevice screen - jFrameMain.setTitle("" + iDevice); - + jFrameMain.setTitle(iDevice.getSerialNumber()); // Show window jFrameMain.setVisible(true); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java index 2b4ac49..cd43d20 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java @@ -2,29 +2,36 @@ import com.android.ddmlib.IDevice; import com.github.xsavikx.androidscreencast.api.adb.AndroidDebugBridgeWrapper; +import com.github.xsavikx.androidscreencast.configuration.ApplicationConfiguration; import com.github.xsavikx.androidscreencast.exception.NoDeviceChosenException; import com.github.xsavikx.androidscreencast.exception.WaitDeviceListTimeoutException; import com.github.xsavikx.androidscreencast.ui.JDialogDeviceList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -@Component +import javax.inject.Inject; +import javax.inject.Singleton; + +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationProperty.ADB_DEVICE_TIMEOUT; + +@Singleton public class DeviceChooserApplication extends SwingApplication { private static final Logger LOGGER = LoggerFactory.getLogger(DeviceChooserApplication.class); private static final long WAIT_TIMEOUT = 100; private final AndroidDebugBridgeWrapper bridge; private final long adbWaitSleepCyclesAmount; - @Value("${adb.device.timeout:30}") - private long adbDeviceTimeout; private IDevice device; - @Autowired - public DeviceChooserApplication(AndroidDebugBridgeWrapper bridge) { + @Inject + public DeviceChooserApplication(final AndroidDebugBridgeWrapper bridge, + final ApplicationConfiguration applicationConfiguration) { + super(applicationConfiguration); this.bridge = bridge; - this.adbWaitSleepCyclesAmount = adbDeviceTimeout * 10; + this.adbWaitSleepCyclesAmount = getAdbDeviceTimeout() * 10; + } + + private long getAdbDeviceTimeout() { + return Long.valueOf(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT)); } @Override @@ -35,29 +42,34 @@ public void stop() { @Override public void start() { LOGGER.info("Starting application"); + try { - waitDeviceList(bridge); + waitDeviceList(bridge); - IDevice devices[] = bridge.getDevices(); + final IDevice devices[] = bridge.getDevices(); - // Let the user choose the device - if (devices.length == 1) { - device = devices[0]; - LOGGER.info("1 device was found by ADB"); - } else { - JDialogDeviceList jd = new JDialogDeviceList(devices); - jd.setVisible(true); - device = jd.getDevice(); - LOGGER.info("{} devices were found by ADB", devices.length); - } + // Let the user choose the device + if (devices.length == 1) { + device = devices[0]; + LOGGER.info("1 device was found by ADB"); + } else { + final JDialogDeviceList jd = new JDialogDeviceList(devices); + jd.setVisible(true); + device = jd.getDevice(); + LOGGER.info("{} devices were found by ADB", devices.length); + } - if (device == null) { - throw new NoDeviceChosenException(); + if (device == null) { + throw new NoDeviceChosenException(); + } + } catch (final Throwable e) { + bridge.stop(); + throw e; } LOGGER.info("{} was chosen", device.getName()); } - private void waitDeviceList(AndroidDebugBridgeWrapper bridge) { + private void waitDeviceList(final AndroidDebugBridgeWrapper bridge) { int count = 0; while (!bridge.hasInitialDeviceList()) { try { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java index 19e6fc7..417499d 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java @@ -1,15 +1,18 @@ package com.github.xsavikx.androidscreencast.app; -public abstract class GUIApplication implements Application { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - public GUIApplication() { +abstract class GUIApplication implements Application { + private static final Logger LOGGER = LoggerFactory.getLogger(GUIApplication.class); + + GUIApplication() { Runtime.getRuntime().addShutdownHook(new Thread(GUIApplication.this::stop)); Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> { try { handleException(thread, ex); - } catch (Exception ex2) { - // ignored - ex2.printStackTrace(); + } catch (final Exception ex2) { + LOGGER.error("Error occurred during exception handling.", ex2); } }); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java index 0732b80..d3d80a3 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java @@ -1,23 +1,29 @@ package com.github.xsavikx.androidscreencast.app; +import com.github.xsavikx.androidscreencast.configuration.ApplicationConfiguration; import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException; import com.github.xsavikx.androidscreencast.ui.JDialogError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import javax.swing.*; import java.io.PrintWriter; import java.io.StringWriter; +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationProperty.APP_NATIVE_LOOK; + public abstract class SwingApplication extends GUIApplication { private static final Logger LOGGER = LoggerFactory.getLogger(DeviceChooserApplication.class); + private static final String SYNC_TREE_UI = "SynthTreeUI"; + protected final ApplicationConfiguration applicationConfiguration; private JDialogError jd = null; - @Value("${app.native.look:true}") - private boolean nativeLook; + + protected SwingApplication(final ApplicationConfiguration applicationConfiguration) { + this.applicationConfiguration = applicationConfiguration; + } private boolean useNativeLook() { - return nativeLook; + return Boolean.valueOf(applicationConfiguration.getProperty(APP_NATIVE_LOOK)); } @Override @@ -31,19 +37,21 @@ public void init() { } @Override - public void handleException(Thread thread, Throwable ex) { + public void handleException(final Thread thread, final Throwable ex) { try { - StringWriter sw = new StringWriter(); + final StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); - if (sw.toString().contains("SynthTreeUI")) + if (sw.toString().contains(SYNC_TREE_UI)) return; LOGGER.error(ex.getClass().getSimpleName(), ex); if (jd != null && jd.isVisible()) return; jd = new JDialogError(ex); - SwingUtilities.invokeLater(() -> jd.setVisible(true)); - } catch (Exception ignored) { - // ignored + SwingUtilities.invokeLater(() -> { + jd.setVisible(true); + }); + } catch (Exception e) { + LOGGER.warn("Exception occurred during exception handling.", e); } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfiguration.java b/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfiguration.java new file mode 100644 index 0000000..5449143 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfiguration.java @@ -0,0 +1,43 @@ +package com.github.xsavikx.androidscreencast.configuration; + +import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +@Singleton +public class ApplicationConfiguration { + private static final String PROPERTIES_LOCATION = "./app.properties"; + private final Properties properties; + + @Inject + public ApplicationConfiguration() { + properties = initProperties(); + } + + private Properties initProperties() { + final Properties properties = new Properties(); + loadProperties(properties, PROPERTIES_LOCATION); + return properties; + } + + private void loadProperties(final Properties properties, final String propertiesLocation) { + final File propertiesFile = new File(propertiesLocation); + if (propertiesFile.exists()) { + try (final FileInputStream fis = new FileInputStream(propertiesFile)) { + properties.load(fis); + } catch (final IOException e) { + throw new AndroidScreenCastRuntimeException(e); + } + } + } + + public String getProperty(final ApplicationConfigurationProperty configurationProperty) { + final String property = properties.getProperty(configurationProperty.getPropertyKey(), configurationProperty.getDefaultValue()); + return property; + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationProperty.java b/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationProperty.java new file mode 100644 index 0000000..25e1fa1 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationProperty.java @@ -0,0 +1,27 @@ +package com.github.xsavikx.androidscreencast.configuration; + +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.*; + +public enum ApplicationConfigurationProperty { + ADB_PATH(ADB_PATH_KEY, ""), + ADB_DEVICE_TIMEOUT(ADB_DEVICE_TIMEOUT_KEY, "30"), + ADB_COMMAND_TIMEOUT(ADB_COMMAND_TIMEOUT_KEY, "5"), + APP_WINDOW_WIDTH(APP_WINDOW_WIDTH_KEY, "1024"), + APP_WINDOW_HEIGHT(APP_WINDOW_HEIGHT_KEY, "768"), + APP_NATIVE_LOOK(APP_NATIVE_LOOK_KEY, "true"); + private final String propertyKey; + private final String defaultValue; + + ApplicationConfigurationProperty(final String propertyKey, String defaultValue) { + this.propertyKey = propertyKey; + this.defaultValue = defaultValue; + } + + public String getPropertyKey() { + return propertyKey; + } + + public String getDefaultValue() { + return defaultValue; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java b/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java new file mode 100644 index 0000000..32c489c --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java @@ -0,0 +1,14 @@ +package com.github.xsavikx.androidscreencast.configuration; + +public final class ApplicationConfigurationPropertyKeys { + public static final String ADB_PATH_KEY = "adb.path"; + public static final String ADB_DEVICE_TIMEOUT_KEY = "adb.device.timeout"; + public static final String ADB_COMMAND_TIMEOUT_KEY = "adb.command.timeout"; + public static final String APP_WINDOW_WIDTH_KEY = "app.window.width"; + public static final String APP_WINDOW_HEIGHT_KEY = "app.window.height"; + public static final String APP_NATIVE_LOOK_KEY = "app.native.look"; + + private ApplicationConfigurationPropertyKeys() { + // + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/constant/Constants.java b/src/main/java/com/github/xsavikx/androidscreencast/constant/Constants.java deleted file mode 100644 index 99f06d3..0000000 --- a/src/main/java/com/github/xsavikx/androidscreencast/constant/Constants.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.xsavikx.androidscreencast.constant; - -import javax.annotation.Resource; - -@Resource -public final class Constants { - public static final String APP_NATIVE_LOOK_PROPERTY = "app.native.look"; - public static final String ADB_PATH_PROPERTY = "adb.path"; - public static final String DEFAULT_WINDOW_WIDTH = "default.window.width"; - public static final String DEFAULT_WINDOW_HEIGHT = "default.window.height"; -} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java new file mode 100644 index 0000000..cc2dca3 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java @@ -0,0 +1,51 @@ +package com.github.xsavikx.androidscreencast.dagger; + +import com.github.xsavikx.androidscreencast.api.AndroidDevice; +import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl; +import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; +import com.github.xsavikx.androidscreencast.api.command.executor.ShellCommandExecutor; +import com.github.xsavikx.androidscreencast.configuration.ApplicationConfiguration; +import dagger.Module; +import dagger.Provides; + +import javax.inject.Named; +import javax.inject.Singleton; + +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationProperty.*; +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.*; + +@Module +public class ApiModule { + @Singleton + @Named(ADB_COMMAND_TIMEOUT_KEY) + @Provides + public static long adbCommandTimeout(ApplicationConfiguration applicationConfiguration) { + return Long.valueOf(applicationConfiguration.getProperty(ADB_COMMAND_TIMEOUT)); + } + + @Singleton + @Named(ADB_DEVICE_TIMEOUT_KEY) + @Provides + public static long adbDeviceTimeout(ApplicationConfiguration applicationConfiguration) { + return Long.valueOf(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT)); + } + + @Singleton + @Named(ADB_PATH_KEY) + @Provides + public static String adbPath(ApplicationConfiguration applicationConfiguration) { + return applicationConfiguration.getProperty(ADB_PATH); + } + + @Singleton + @Provides + public CommandExecutor commandExecutor(ShellCommandExecutor shellCommandExecutor) { + return shellCommandExecutor; + } + + @Singleton + @Provides + public AndroidDevice androidDevice(AndroidDeviceImpl androidDevice) { + return androidDevice; + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java new file mode 100644 index 0000000..a334b0b --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java @@ -0,0 +1,29 @@ +package com.github.xsavikx.androidscreencast.dagger; + +import com.android.ddmlib.IDevice; +import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication; +import com.github.xsavikx.androidscreencast.app.Application; +import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication; +import dagger.Module; +import dagger.Provides; + +import javax.inject.Singleton; + +@Module +public class AppModule { + @Singleton + @Provides + public static Application application(AndroidScreencastApplication application) { + return application; + } + + @Singleton + @Provides + public static IDevice iDevice(final DeviceChooserApplication application) { + application.init(); + application.start(); + application.stop(); + IDevice device = application.getDevice(); + return device; + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java new file mode 100644 index 0000000..0bd685a --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java @@ -0,0 +1,15 @@ +package com.github.xsavikx.androidscreencast.dagger; + +import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; +import com.github.xsavikx.androidscreencast.app.Application; +import dagger.Component; + +import javax.inject.Singleton; + +@Singleton +@Component(modules = {ApiModule.class, AppModule.class, UiModule.class}) +public interface MainComponent { + Application application(); + + CommandExecutor commandExecutor(); +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java new file mode 100644 index 0000000..27f42f1 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java @@ -0,0 +1,16 @@ +package com.github.xsavikx.androidscreencast.dagger; + +public final class MainComponentProvider { + private static MainComponent INSTANCE; + + private MainComponentProvider() { + + } + + public static MainComponent mainComponent() { + if (INSTANCE == null) { + INSTANCE = DaggerMainComponent.create(); + } + return INSTANCE; + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java new file mode 100644 index 0000000..ab5c33b --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java @@ -0,0 +1,29 @@ +package com.github.xsavikx.androidscreencast.dagger; + +import com.github.xsavikx.androidscreencast.configuration.ApplicationConfiguration; +import com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationProperty; +import dagger.Module; +import dagger.Provides; + +import javax.inject.Named; +import javax.inject.Singleton; + +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.APP_WINDOW_HEIGHT_KEY; +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.APP_WINDOW_WIDTH_KEY; + +@Module +public class UiModule { + @Singleton + @Named(APP_WINDOW_WIDTH_KEY) + @Provides + public static int appWindowHeight(final ApplicationConfiguration applicationConfiguration) { + return Integer.valueOf(applicationConfiguration.getProperty(ApplicationConfigurationProperty.APP_WINDOW_HEIGHT)); + } + + @Singleton + @Named(APP_WINDOW_HEIGHT_KEY) + @Provides + public static int appWindowWidth(final ApplicationConfiguration applicationConfiguration) { + return Integer.valueOf(applicationConfiguration.getProperty(ApplicationConfigurationProperty.APP_WINDOW_WIDTH)); + } +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java deleted file mode 100644 index e8d11a7..0000000 --- a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationConfiguration.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.xsavikx.androidscreencast.spring.config; - -import com.android.ddmlib.IDevice; -import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.context.annotation.*; - -@Configuration -@ComponentScan(basePackages = "com.github.xsavikx.androidscreencast") -@PropertySources(value = { - @PropertySource(value = "file:${user.dir}/app.properties", ignoreResourceNotFound = true) -}) -public class ApplicationConfiguration { - - @Bean - public DefaultListableBeanFactory initBeanFactory() { - return new DefaultListableBeanFactory(); - } - - @Bean - @Autowired - public IDevice initDevice(DeviceChooserApplication application) { - application.init(); - application.start(); - application.stop(); - return application.getDevice(); - } - -} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationContextProvider.java b/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationContextProvider.java deleted file mode 100644 index 68c0c1c..0000000 --- a/src/main/java/com/github/xsavikx/androidscreencast/spring/config/ApplicationContextProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.xsavikx.androidscreencast.spring.config; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -public class ApplicationContextProvider implements ApplicationContextAware { - private static ApplicationContext applicationContext; - - private ApplicationContextProvider() { - // - } - - public static ApplicationContext getApplicationContext() { - if (applicationContext == null) - applicationContext = new AnnotationConfigApplicationContext(ApplicationConfiguration.class); - return applicationContext; - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - ApplicationContextProvider.applicationContext = applicationContext; - } - - public static T getBean(Class clazz) throws BeansException { - return getApplicationContext().getBean(clazz); - } - -} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java index 4e7bcb4..8d5435a 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java @@ -2,7 +2,7 @@ import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException; import com.github.xsavikx.androidscreencast.exception.IORuntimeException; -import org.springframework.util.StringUtils; +import com.github.xsavikx.androidscreencast.util.StringUtils; import javax.swing.*; import java.awt.*; @@ -54,12 +54,12 @@ private void setErrorDetails(Throwable e) { AndroidScreenCastRuntimeException realCause = getCause(ex); if (realCause != null) { errorDialogLabel.setText(realCause.getClass().getSimpleName()); - if (!StringUtils.isEmpty(realCause.getMessage())) + if (StringUtils.isNotEmpty(realCause.getMessage())) stringWriter.append(realCause.getMessage()).append('\n').append('\n'); - if (!StringUtils.isEmpty(realCause.getAdditionalInformation())) + if (StringUtils.isNotEmpty(realCause.getAdditionalInformation())) stringWriter.append(realCause.getAdditionalInformation()); } else { - if (!StringUtils.isEmpty(ex.getMessage())) + if (StringUtils.isNotEmpty(ex.getMessage())) stringWriter.append(ex.getMessage()).append('\n').append('\n'); ex.printStackTrace(new PrintWriter(stringWriter)); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java index d4eb5c5..613078d 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java @@ -5,15 +5,13 @@ import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; import com.github.xsavikx.androidscreencast.ui.model.InputKeyEventTable; import com.github.xsavikx.androidscreencast.ui.model.InputKeyEventTableModel; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; +import javax.inject.Inject; import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.*; -@Component public class JDialogExecuteKeyEvent extends JDialog { private static final long serialVersionUID = -4152020879675916776L; private static final int HEIGHT = 600; @@ -32,7 +30,7 @@ public class JDialogExecuteKeyEvent extends JDialog { private final CommandExecutor commandExecutor; - @Autowired + @Inject public JDialogExecuteKeyEvent(CommandExecutor commandExecutor) { this.commandExecutor = commandExecutor; } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java index 4672886..bab70fe 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java @@ -2,36 +2,38 @@ import com.github.xsavikx.androidscreencast.api.injector.Injector; import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; -import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication; -import com.github.xsavikx.androidscreencast.constant.Constants; +import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider; import com.github.xsavikx.androidscreencast.exception.IORuntimeException; -import com.github.xsavikx.androidscreencast.spring.config.ApplicationContextProvider; import com.github.xsavikx.androidscreencast.ui.explorer.JFrameExplorer; import com.github.xsavikx.androidscreencast.ui.interaction.KeyEventDispatcherFactory; import com.github.xsavikx.androidscreencast.ui.interaction.KeyboardActionListenerFactory; +import com.github.xsavikx.androidscreencast.ui.interaction.MouseActionAdapter; import com.google.common.io.Files; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; import java.io.File; import java.io.IOException; import java.nio.file.Path; -@Component +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.APP_WINDOW_HEIGHT_KEY; +import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.APP_WINDOW_WIDTH_KEY; + +@Singleton public class JFrameMain extends JFrame { private static final long serialVersionUID = -2085909236767692371L; private final JPanelScreen jp; - private final MouseAdapter ma; + private final MouseActionAdapter ma; private final Injector injector; - private final Environment env; + private final Dimension windowSize; + private final JFrameExplorer frameExplorer; + private final JDialogExecuteKeyEvent dialogExecuteKeyEvent; private transient boolean isDisposed = false; private JToolBar jtb = new JToolBar(); private JToolBar jtbHardkeys = new JToolBar(); @@ -47,22 +49,16 @@ public class JFrameMain extends JFrame { private JButton jbRecord = new JButton("Start record"); private Dimension oldImageDimension; - @Autowired - public JFrameMain(JPanelScreen jp, Environment env, Injector injector, MouseAdapter ma) { + @Inject + public JFrameMain(JPanelScreen jp, Injector injector, MouseActionAdapter ma, + JFrameExplorer frameExplorer, JDialogExecuteKeyEvent dialogExecuteKeyEvent, @Named(APP_WINDOW_WIDTH_KEY) int width, + @Named(APP_WINDOW_HEIGHT_KEY) int height) { this.jp = jp; this.injector = injector; - this.env = env; this.ma = ma; - } - - private void setPreferredWindowSize() { - if (env.containsProperty(Constants.DEFAULT_WINDOW_HEIGHT) && env.containsProperty(Constants.DEFAULT_WINDOW_WIDTH)) { - Integer height = env.getProperty(Constants.DEFAULT_WINDOW_HEIGHT, Integer.class); - Integer width = env.getProperty(Constants.DEFAULT_WINDOW_WIDTH, Integer.class); - if (height != null && width != null) - getContentPane().setPreferredSize(new Dimension(width, height)); - } - pack(); + this.frameExplorer = frameExplorer; + this.dialogExecuteKeyEvent = dialogExecuteKeyEvent; + this.windowSize = new Dimension(width, height); } @Override @@ -72,10 +68,9 @@ public void dispose() { } isDisposed = true; super.dispose(); - ApplicationContextProvider.getBean(AndroidScreencastApplication.class).stop(); + MainComponentProvider.mainComponent().application().stop(); } - @PostConstruct public void initialize() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); KeyboardFocusManager.getCurrentKeyboardFocusManager() @@ -123,7 +118,7 @@ public void initialize() { jp.addMouseWheelListener(ma); jbExplorer.addActionListener(actionEvent -> { - JFrameExplorer jf = ApplicationContextProvider.getBean(JFrameExplorer.class); + JFrameExplorer jf = frameExplorer; jf.setIconImage(getIconImage()); jf.launch(); jf.setVisible(true); @@ -131,15 +126,18 @@ public void initialize() { jtb.add(jbExplorer); jbExecuteKeyEvent.addActionListener(actionEvent -> { - JDialogExecuteKeyEvent jdExecuteKeyEvent = ApplicationContextProvider - .getBean(JDialogExecuteKeyEvent.class); - jdExecuteKeyEvent.setVisible(true); + dialogExecuteKeyEvent.setVisible(true); }); jtb.add(jbExecuteKeyEvent); jtb.add(jbRecord); } + private void setPreferredWindowSize() { + getContentPane().setPreferredSize(windowSize); + pack(); + } + private ActionListener createRecordActionListener() { return new ActionListener() { private final Path tmpDir = Files.createTempDir().toPath(); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java index d6362a6..41d809c 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java @@ -1,12 +1,10 @@ package com.github.xsavikx.androidscreencast.ui; -import org.springframework.stereotype.Component; - +import javax.inject.Inject; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; -@Component public class JPanelScreen extends JPanel { private static final long serialVersionUID = -2034873107028503004L; private float coef = 1; @@ -15,28 +13,27 @@ public class JPanelScreen extends JPanel { private Dimension size = null; private BufferedImage image = null; + @Inject public JPanelScreen() { this.setFocusable(true); } - public Point getRawPoint(Point p1) { - Point p2 = new Point(); + public Point getRawPoint(final Point p1) { + final Point p2 = new Point(); p2.x = (int) ((p1.x - origX) / coef); p2.y = (int) ((p1.y - origY) / coef); return p2; } - public void handleNewImage(Dimension size, BufferedImage image) { + public void handleNewImage(final Dimension size, final BufferedImage image) { this.size = size; this.image = image; repaint(); } @Override - protected void paintComponent(Graphics g) { - if (size == null) - return; - if (size.height == 0) + protected void paintComponent(final Graphics g) { + if (isNotInitialized()) return; Graphics2D g2 = (Graphics2D) g; g2.clearRect(0, 0, getWidth(), getHeight()); @@ -48,4 +45,8 @@ protected void paintComponent(Graphics g) { g2.drawImage(image, (int) origX, (int) origY, (int) width, (int) height, this); } + private boolean isNotInitialized() { + return size == null || size.height == 0 || size.width == 0; + } + } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java index 41a7f0f..f40b571 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java @@ -3,9 +3,8 @@ import com.github.xsavikx.androidscreencast.api.AndroidDevice; import com.github.xsavikx.androidscreencast.api.file.FileInfo; import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import javax.inject.Inject; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; @@ -19,7 +18,6 @@ import java.util.List; import java.util.Map; -@Component public class JFrameExplorer extends JFrame { private static final long serialVersionUID = -5209265873286028854L; @@ -28,7 +26,7 @@ public class JFrameExplorer extends JFrame { private JList jListFichiers; private Map> cache = new LinkedHashMap<>(); - @Autowired + @Inject public JFrameExplorer(AndroidDevice androidDevice) { setTitle("Explorer"); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java index 48f0f07..e140b21 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java @@ -3,7 +3,7 @@ import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter; -import com.github.xsavikx.androidscreencast.spring.config.ApplicationContextProvider; +import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider; import javax.swing.*; import java.awt.*; @@ -31,7 +31,7 @@ public boolean dispatchKeyEvent(KeyEvent e) { private CommandExecutor getCommandExecutor() { if (commandExecutor == null) { - commandExecutor = ApplicationContextProvider.getBean(CommandExecutor.class); + commandExecutor = MainComponentProvider.mainComponent().commandExecutor(); } return commandExecutor; } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java index 401cafa..76e7f54 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java @@ -2,7 +2,7 @@ import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; -import com.github.xsavikx.androidscreencast.spring.config.ApplicationContextProvider; +import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider; import javax.swing.*; import java.awt.event.ActionEvent; @@ -23,7 +23,7 @@ public void actionPerformed(ActionEvent e) { private CommandExecutor getCommandExecutor() { if (commandExecutor == null) { - commandExecutor = ApplicationContextProvider.getBean(CommandExecutor.class); + commandExecutor = MainComponentProvider.mainComponent().commandExecutor(); } return commandExecutor; } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java index c97a1cb..0b4c87c 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java @@ -4,16 +4,14 @@ import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; import com.github.xsavikx.androidscreencast.api.injector.Injector; import com.github.xsavikx.androidscreencast.ui.JPanelScreen; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import javax.inject.Inject; import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; -@Component public class MouseActionAdapter extends MouseAdapter { private final static long ONE_SECOND = 1000L; private final JPanelScreen jp; @@ -23,7 +21,7 @@ public class MouseActionAdapter extends MouseAdapter { private int dragFromY = -1; private long timeFromPress = -1; - @Autowired + @Inject public MouseActionAdapter(JPanelScreen jp, CommandExecutor commandExecutor, Injector injector) { this.jp = jp; this.commandExecutor = commandExecutor; diff --git a/src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java b/src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java new file mode 100644 index 0000000..858f477 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java @@ -0,0 +1,11 @@ +package com.github.xsavikx.androidscreencast.util; + +public class StringUtils { + private StringUtils() { + // + } + + public static boolean isNotEmpty(final CharSequence charSequence) { + return charSequence != null && charSequence.length() > 0; + } +} From 734cc89b2540a4e89bd687998fec158124e4e2fa Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Tue, 28 Feb 2017 21:01:22 +0200 Subject: [PATCH 13/20] fixed Execute Key Code functionality functionality didn't work due to @PostConstruct annotation on init method from Spring, that was never called, cause Spring is not used anymore. --- .../androidscreencast/dagger/UiModule.java | 7 +++++ .../ui/JDialogExecuteKeyEvent.java | 27 +++++++++++-------- .../androidscreencast/ui/JFrameMain.java | 12 +++++---- .../interaction/KeyEventDispatcherImpl.java | 1 - .../ui/model/InputKeyEventTable.java | 6 ++++- .../ui/model/InputKeyEventTableModel.java | 9 +++++-- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java index ab5c33b..94c0e77 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java @@ -1,5 +1,6 @@ package com.github.xsavikx.androidscreencast.dagger; +import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; import com.github.xsavikx.androidscreencast.configuration.ApplicationConfiguration; import com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationProperty; import dagger.Module; @@ -26,4 +27,10 @@ public static int appWindowHeight(final ApplicationConfiguration applicationConf public static int appWindowWidth(final ApplicationConfiguration applicationConfiguration) { return Integer.valueOf(applicationConfiguration.getProperty(ApplicationConfigurationProperty.APP_WINDOW_WIDTH)); } + + @Singleton + @Provides + public static InputKeyEvent[] initialData() { + return InputKeyEvent.values(); + } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java index 613078d..a12c70c 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java @@ -4,14 +4,14 @@ import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; import com.github.xsavikx.androidscreencast.ui.model.InputKeyEventTable; -import com.github.xsavikx.androidscreencast.ui.model.InputKeyEventTableModel; -import javax.annotation.PostConstruct; import javax.inject.Inject; +import javax.inject.Singleton; import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.*; +@Singleton public class JDialogExecuteKeyEvent extends JDialog { private static final long serialVersionUID = -4152020879675916776L; private static final int HEIGHT = 600; @@ -20,7 +20,7 @@ public class JDialogExecuteKeyEvent extends JDialog { private static final int BUTTON_WIDTH = WIDTH >> 1 - 5; private static final int TITLE_COLUMN_INDEX = 1; - + private static final String TITLE = "Execute key event"; private static final String EXECUTE_BUTTON_TEXT = "Execute"; private static final String USE_LONG_PRESS_BUTTON_TEXT = "Long press"; private static final String CANCEL_BUTTON_TEXT = "Cancel"; @@ -29,20 +29,24 @@ public class JDialogExecuteKeyEvent extends JDialog { private static final String NO_COMMAND_CHOSEN_WARNING_DIALOG_TITLE = "Warning"; private final CommandExecutor commandExecutor; + private final InputKeyEventTable commandListTable; @Inject - public JDialogExecuteKeyEvent(CommandExecutor commandExecutor) { + public JDialogExecuteKeyEvent(CommandExecutor commandExecutor, InputKeyEventTable commandListTable) { this.commandExecutor = commandExecutor; + this.commandListTable = commandListTable; + init(); } + public void open() { + setVisible(true); + } - @PostConstruct - private void initialize() { - setResizable(false); - setTitle("Execute key event"); + private void init() { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - final InputKeyEventTableModel commandList = new InputKeyEventTableModel(InputKeyEvent.values()); - final InputKeyEventTable commandListTable = new InputKeyEventTable(commandList); + setResizable(false); + setTitle(TITLE); + setAlwaysOnTop(true); final JCheckBoxMenuItem useLongPress = new JCheckBoxMenuItem(USE_LONG_PRESS_BUTTON_TEXT, false); JButton executeCommandButton = new JButton(EXECUTE_BUTTON_TEXT); @@ -50,7 +54,8 @@ private void initialize() { executeCommandButton.addActionListener(actionEvent -> { int rowIndex = commandListTable.getSelectedRow(); if (rowIndex > 0) { - final String title = (String) commandList.getValueAt(rowIndex, TITLE_COLUMN_INDEX); + + final String title = (String) commandListTable.getModel().getValueAt(rowIndex, TITLE_COLUMN_INDEX); SwingUtilities.invokeLater(() -> commandExecutor.execute(AdbInputCommandFactory.getKeyCommand(InputKeyEvent.valueOf(title), useLongPress.getState()))); closeDialog(); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java index bab70fe..189aaf3 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java @@ -118,15 +118,17 @@ public void initialize() { jp.addMouseWheelListener(ma); jbExplorer.addActionListener(actionEvent -> { - JFrameExplorer jf = frameExplorer; - jf.setIconImage(getIconImage()); - jf.launch(); - jf.setVisible(true); + SwingUtilities.invokeLater(() -> { + JFrameExplorer jf = frameExplorer; + jf.setIconImage(getIconImage()); + jf.launch(); + jf.setVisible(true); + }); }); jtb.add(jbExplorer); jbExecuteKeyEvent.addActionListener(actionEvent -> { - dialogExecuteKeyEvent.setVisible(true); + SwingUtilities.invokeLater(dialogExecuteKeyEvent::open); }); jtb.add(jbExecuteKeyEvent); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java index e140b21..39462c6 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java @@ -24,7 +24,6 @@ public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_TYPED) { final int code = KeyCodeConverter.getKeyCode(e); SwingUtilities.invokeLater(() -> getCommandExecutor().execute(AdbInputCommandFactory.getKeyCommand(code))); - } return false; } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTable.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTable.java index 10cb824..eaa0155 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTable.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTable.java @@ -1,19 +1,23 @@ package com.github.xsavikx.androidscreencast.ui.model; +import javax.inject.Inject; +import javax.inject.Singleton; import javax.swing.*; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import java.awt.*; +@Singleton public class InputKeyEventTable extends JTable { private static final long serialVersionUID = 3978642864003531967L; private final static int MIN_COLUMN_WIDTH = 20; + @Inject public InputKeyEventTable(InputKeyEventTableModel tableModel) { super(tableModel); - setTableColumnsNames(tableModel.columnNames); + setTableColumnsNames(InputKeyEventTableModel.COLUMN_NAMES); setAutoResizeMode(JTable.AUTO_RESIZE_OFF); setTableColumnsPreferredSize(); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTableModel.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTableModel.java index 6d0098a..a8adc5d 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTableModel.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/model/InputKeyEventTableModel.java @@ -2,21 +2,26 @@ import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; +import javax.inject.Inject; +import javax.inject.Singleton; import javax.swing.table.AbstractTableModel; import java.util.ArrayList; import java.util.List; +@Singleton public class InputKeyEventTableModel extends AbstractTableModel { private static final long serialVersionUID = 1553313932570896541L; private final static String INDEX_COLUMN_NAME = "#"; private final static String TITLE_COLUMN_NAME = "title"; private final static String DESCRIPTION_COLUMN_NAME = "description"; - public final String[] columnNames = { + public static final String[] COLUMN_NAMES = { INDEX_COLUMN_NAME, TITLE_COLUMN_NAME, DESCRIPTION_COLUMN_NAME }; + private List> data = new ArrayList<>(); private int rowCount = 0; + @Inject public InputKeyEventTableModel(InputKeyEvent[] initialData) { initData(initialData); } @@ -42,7 +47,7 @@ public int getRowCount() { @Override public int getColumnCount() { - return columnNames.length; + return COLUMN_NAMES.length; } @Override From 07b8959d2dc0853897b485d8cdf27f5aa9b5dbed Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Tue, 28 Feb 2017 22:09:52 +0200 Subject: [PATCH 14/20] fixed problem with wrong x-y coordinates for tap and swipe Problem occured due to mis-configured Dagger scope. JPanelScreen was scoped as Repeated, so JFrameMain and MouseActionAdapter received two different copies of this class. Because of that - MouseActionAdapter could not figure out x-y coordinates properly, as its copy of JPanelScreen did not receive new images to draw. --- .../app/DeviceChooserApplication.java | 35 ++++++++----------- .../androidscreencast/app/GUIApplication.java | 2 +- .../androidscreencast/dagger/ApiModule.java | 1 + .../androidscreencast/dagger/AppModule.java | 15 +++++--- .../androidscreencast/dagger/UiModule.java | 1 + .../androidscreencast/ui/JFrameMain.java | 1 - .../androidscreencast/ui/JPanelScreen.java | 10 +++--- .../ui/interaction/MouseActionAdapter.java | 2 ++ 8 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java index cd43d20..f2b89a9 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java @@ -36,35 +36,30 @@ private long getAdbDeviceTimeout() { @Override public void stop() { - // ignore + bridge.stop(); } @Override public void start() { LOGGER.info("Starting application"); - try { - waitDeviceList(bridge); + waitDeviceList(bridge); - final IDevice devices[] = bridge.getDevices(); + final IDevice devices[] = bridge.getDevices(); - // Let the user choose the device - if (devices.length == 1) { - device = devices[0]; - LOGGER.info("1 device was found by ADB"); - } else { - final JDialogDeviceList jd = new JDialogDeviceList(devices); - jd.setVisible(true); - device = jd.getDevice(); - LOGGER.info("{} devices were found by ADB", devices.length); - } + // Let the user choose the device + if (devices.length == 1) { + device = devices[0]; + LOGGER.info("1 device was found by ADB"); + } else { + final JDialogDeviceList jd = new JDialogDeviceList(devices); + jd.setVisible(true); + device = jd.getDevice(); + LOGGER.info("{} devices were found by ADB", devices.length); + } - if (device == null) { - throw new NoDeviceChosenException(); - } - } catch (final Throwable e) { - bridge.stop(); - throw e; + if (device == null) { + throw new NoDeviceChosenException(); } LOGGER.info("{} was chosen", device.getName()); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java b/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java index 417499d..52d24cf 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/app/GUIApplication.java @@ -7,7 +7,7 @@ abstract class GUIApplication implements Application { private static final Logger LOGGER = LoggerFactory.getLogger(GUIApplication.class); GUIApplication() { - Runtime.getRuntime().addShutdownHook(new Thread(GUIApplication.this::stop)); + Runtime.getRuntime().addShutdownHook(new Thread(this::stop)); Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> { try { handleException(thread, ex); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java index cc2dca3..cf9f1c7 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java @@ -14,6 +14,7 @@ import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationProperty.*; import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.*; +@Singleton @Module public class ApiModule { @Singleton diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java index a334b0b..0672b8d 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java @@ -9,6 +9,7 @@ import javax.inject.Singleton; +@Singleton @Module public class AppModule { @Singleton @@ -20,10 +21,14 @@ public static Application application(AndroidScreencastApplication application) @Singleton @Provides public static IDevice iDevice(final DeviceChooserApplication application) { - application.init(); - application.start(); - application.stop(); - IDevice device = application.getDevice(); - return device; + try { + application.init(); + application.start(); + IDevice device = application.getDevice(); + return device; + } catch (Throwable e) { + application.stop(); + throw e; + } } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java index 94c0e77..f3f460b 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/UiModule.java @@ -12,6 +12,7 @@ import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.APP_WINDOW_HEIGHT_KEY; import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.APP_WINDOW_WIDTH_KEY; +@Singleton @Module public class UiModule { @Singleton diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java index 189aaf3..768fd26 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JFrameMain.java @@ -102,7 +102,6 @@ public void initialize() { jtbHardkeys.add(jbKbPhoneOn); jtbHardkeys.add(jbKbPhoneOff); - setDefaultCloseOperation(DISPOSE_ON_CLOSE); setLayout(new BorderLayout()); add(jtb, BorderLayout.NORTH); add(jtbHardkeys, BorderLayout.SOUTH); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java index 41d809c..3006250 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JPanelScreen.java @@ -1,10 +1,12 @@ package com.github.xsavikx.androidscreencast.ui; import javax.inject.Inject; +import javax.inject.Singleton; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; +@Singleton public class JPanelScreen extends JPanel { private static final long serialVersionUID = -2034873107028503004L; private float coef = 1; @@ -15,7 +17,7 @@ public class JPanelScreen extends JPanel { @Inject public JPanelScreen() { - this.setFocusable(true); + setFocusable(true); } public Point getRawPoint(final Point p1) { @@ -35,11 +37,11 @@ public void handleNewImage(final Dimension size, final BufferedImage image) { protected void paintComponent(final Graphics g) { if (isNotInitialized()) return; - Graphics2D g2 = (Graphics2D) g; + final Graphics2D g2 = (Graphics2D) g; g2.clearRect(0, 0, getWidth(), getHeight()); - double width = Math.min(getWidth(), size.width * getHeight() / size.height); + final double width = Math.min(getWidth(), size.width * getHeight() / size.height); coef = (float) width / size.width; - double height = width * size.height / size.width; + final double height = width * size.height / size.width; origX = (getWidth() - width) / 2; origY = (getHeight() - height) / 2; g2.drawImage(image, (int) origX, (int) origY, (int) width, (int) height, this); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java index 0b4c87c..fe63c79 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java @@ -6,12 +6,14 @@ import com.github.xsavikx.androidscreencast.ui.JPanelScreen; import javax.inject.Inject; +import javax.inject.Singleton; import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; +@Singleton public class MouseActionAdapter extends MouseAdapter { private final static long ONE_SECOND = 1000L; private final JPanelScreen jp; From f3d58a581456d18987afac3b769cd182092e97e1 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Tue, 28 Feb 2017 22:27:49 +0200 Subject: [PATCH 15/20] update dependencies and plugins version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 16fa716..2027289 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 2.9 25.2.0 - 1.7.22 + 1.7.24 1.2.1 21.0 com.github.xsavikx.androidscreencast.Main @@ -83,7 +83,7 @@ org.apache.maven.plugins maven-shade-plugin - 2.4.3 + 3.0.0 package From abae8b9084ff023c58ebb8a6bf2795c36e738cae Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Tue, 28 Feb 2017 23:23:12 +0200 Subject: [PATCH 16/20] extracted InputCommandFactory interface and removed usage of AdbInputCommandFactory static methods. --- .../factory/AdbInputCommandFactory.java | 48 ++++++++++++------- .../command/factory/InputCommandFactory.java | 22 +++++++++ .../androidscreencast/dagger/ApiModule.java | 12 ++++- .../dagger/MainComponent.java | 3 ++ .../ui/JDialogExecuteKeyEvent.java | 15 ++++-- .../interaction/KeyEventDispatcherImpl.java | 20 ++++++-- .../interaction/KeyboardActionListener.java | 20 ++++++-- .../ui/interaction/MouseActionAdapter.java | 39 ++++++++++----- 8 files changed, 138 insertions(+), 41 deletions(-) create mode 100644 src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java index 86b9f3a..0fb6f97 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java @@ -7,49 +7,65 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class AdbInputCommandFactory { +import javax.inject.Inject; +import javax.inject.Singleton; + +@Singleton +public class AdbInputCommandFactory implements InputCommandFactory { private static final Logger LOGGER = LoggerFactory.getLogger(AdbInputCommandFactory.class); - public static KeyCommand getKeyCommand(int keyCode) { - KeyCommand returnKeyCommand = new KeyCommand(keyCode); + @Inject + public AdbInputCommandFactory() { + + } + + @Override + public KeyCommand getKeyCommand(final int keyCode) { + final KeyCommand returnKeyCommand = new KeyCommand(keyCode); LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } - public static KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent) { - KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent); + @Override + public KeyCommand getKeyCommand(final InputKeyEvent inputKeyEvent) { + final KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent); LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } - - public static KeyCommand getKeyCommand(int keyCode, boolean longpress) { - KeyCommand returnKeyCommand = new KeyCommand(keyCode, longpress); + @Override + public KeyCommand getKeyCommand(final int keyCode, final boolean longpress) { + final KeyCommand returnKeyCommand = new KeyCommand(keyCode, longpress); LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } - public static KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) { - KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent, longpress); + @Override + public KeyCommand getKeyCommand(final InputKeyEvent inputKeyEvent, final boolean longpress) { + final KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent, longpress); LOGGER.debug(String.valueOf(returnKeyCommand)); return returnKeyCommand; } - public static SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration) { - SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2, duration); + @Override + public SwipeCommand getSwipeCommand(final int x1, final int y1, final int x2, final int y2, final long duration) { + final SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2, duration); LOGGER.debug(String.valueOf(returnSwipeCommand)); return returnSwipeCommand; } - public static SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2) { - SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2); + @Override + public SwipeCommand getSwipeCommand(final int x1, final int y1, final int x2, final int y2) { + final SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2); LOGGER.debug(String.valueOf(returnSwipeCommand)); return returnSwipeCommand; } - public static TapCommand getTapCommand(int x, int y) { - TapCommand returnTapCommand = new TapCommand(x, y); + @Override + public TapCommand getTapCommand(final int x, final int y) { + final TapCommand returnTapCommand = new TapCommand(x, y); LOGGER.debug(String.valueOf(returnTapCommand)); return returnTapCommand; } + } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java new file mode 100644 index 0000000..73f2062 --- /dev/null +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java @@ -0,0 +1,22 @@ +package com.github.xsavikx.androidscreencast.api.command.factory; + +import com.github.xsavikx.androidscreencast.api.command.KeyCommand; +import com.github.xsavikx.androidscreencast.api.command.SwipeCommand; +import com.github.xsavikx.androidscreencast.api.command.TapCommand; +import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; + +public interface InputCommandFactory { + KeyCommand getKeyCommand(int keyCode); + + KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent); + + KeyCommand getKeyCommand(int keyCode, boolean longpress); + + KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress); + + SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration); + + SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2); + + TapCommand getTapCommand(int x, int y); +} diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java index cf9f1c7..4e88110 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/ApiModule.java @@ -4,6 +4,8 @@ import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl; import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; import com.github.xsavikx.androidscreencast.api.command.executor.ShellCommandExecutor; +import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; +import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory; import com.github.xsavikx.androidscreencast.configuration.ApplicationConfiguration; import dagger.Module; import dagger.Provides; @@ -40,13 +42,19 @@ public static String adbPath(ApplicationConfiguration applicationConfiguration) @Singleton @Provides - public CommandExecutor commandExecutor(ShellCommandExecutor shellCommandExecutor) { + public static CommandExecutor commandExecutor(ShellCommandExecutor shellCommandExecutor) { return shellCommandExecutor; } @Singleton @Provides - public AndroidDevice androidDevice(AndroidDeviceImpl androidDevice) { + public static AndroidDevice androidDevice(AndroidDeviceImpl androidDevice) { return androidDevice; } + + @Singleton + @Provides + public static InputCommandFactory inputCommandFactory(AdbInputCommandFactory adbInputCommandFactory) { + return adbInputCommandFactory; + } } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java b/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java index 0bd685a..b5ad021 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java @@ -1,6 +1,7 @@ package com.github.xsavikx.androidscreencast.dagger; import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; +import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory; import com.github.xsavikx.androidscreencast.app.Application; import dagger.Component; @@ -12,4 +13,6 @@ public interface MainComponent { Application application(); CommandExecutor commandExecutor(); + + InputCommandFactory inputCommandFactory(); } diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java index a12c70c..80e348d 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogExecuteKeyEvent.java @@ -1,7 +1,8 @@ package com.github.xsavikx.androidscreencast.ui; +import com.github.xsavikx.androidscreencast.api.command.KeyCommand; import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; -import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; +import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory; import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent; import com.github.xsavikx.androidscreencast.ui.model.InputKeyEventTable; @@ -30,11 +31,13 @@ public class JDialogExecuteKeyEvent extends JDialog { private final CommandExecutor commandExecutor; private final InputKeyEventTable commandListTable; + private final InputCommandFactory inputCommandFactory; @Inject - public JDialogExecuteKeyEvent(CommandExecutor commandExecutor, InputKeyEventTable commandListTable) { + public JDialogExecuteKeyEvent(CommandExecutor commandExecutor, InputKeyEventTable commandListTable, InputCommandFactory inputCommandFactory) { this.commandExecutor = commandExecutor; this.commandListTable = commandListTable; + this.inputCommandFactory = inputCommandFactory; init(); } @@ -56,8 +59,12 @@ private void init() { if (rowIndex > 0) { final String title = (String) commandListTable.getModel().getValueAt(rowIndex, TITLE_COLUMN_INDEX); - SwingUtilities.invokeLater(() -> commandExecutor.execute(AdbInputCommandFactory.getKeyCommand(InputKeyEvent.valueOf(title), - useLongPress.getState()))); + SwingUtilities.invokeLater(() -> { + final InputKeyEvent inputKeyEvent = InputKeyEvent.valueOf(title); + final boolean longPress = useLongPress.getState(); + final KeyCommand keyCommand = inputCommandFactory.getKeyCommand(inputKeyEvent, longPress); + commandExecutor.execute(keyCommand); + }); closeDialog(); } else { JOptionPane.showMessageDialog(null, NO_COMMAND_CHOSEN_WARNING_MESSAGE, NO_COMMAND_CHOSEN_WARNING_DIALOG_TITLE, diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java index 39462c6..d22443a 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java @@ -1,7 +1,8 @@ package com.github.xsavikx.androidscreencast.ui.interaction; +import com.github.xsavikx.androidscreencast.api.command.KeyCommand; import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; -import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; +import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory; import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter; import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider; @@ -10,24 +11,35 @@ import java.awt.event.KeyEvent; public class KeyEventDispatcherImpl implements KeyEventDispatcher { + private final Window window; private CommandExecutor commandExecutor; - private Window window; + private InputCommandFactory inputCommandFactory; public KeyEventDispatcherImpl(Window frame) { this.window = frame; } @Override - public boolean dispatchKeyEvent(KeyEvent e) { + public boolean dispatchKeyEvent(final KeyEvent e) { if (!window.isActive()) return false; if (e.getID() == KeyEvent.KEY_TYPED) { final int code = KeyCodeConverter.getKeyCode(e); - SwingUtilities.invokeLater(() -> getCommandExecutor().execute(AdbInputCommandFactory.getKeyCommand(code))); + SwingUtilities.invokeLater(() -> { + final KeyCommand command = getInputCommandFactory().getKeyCommand(code); + getCommandExecutor().execute(command); + }); } return false; } + private InputCommandFactory getInputCommandFactory() { + if (inputCommandFactory == null) { + inputCommandFactory = MainComponentProvider.mainComponent().inputCommandFactory(); + } + return inputCommandFactory; + } + private CommandExecutor getCommandExecutor() { if (commandExecutor == null) { commandExecutor = MainComponentProvider.mainComponent().commandExecutor(); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java index 76e7f54..039657d 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java @@ -1,7 +1,8 @@ package com.github.xsavikx.androidscreencast.ui.interaction; +import com.github.xsavikx.androidscreencast.api.command.KeyCommand; import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; -import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; +import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory; import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider; import javax.swing.*; @@ -9,16 +10,27 @@ import java.awt.event.ActionListener; public class KeyboardActionListener implements ActionListener { + private final int key; private CommandExecutor commandExecutor; - private int key; + private InputCommandFactory inputCommandFactory; public KeyboardActionListener(int key) { this.key = key; } @Override - public void actionPerformed(ActionEvent e) { - SwingUtilities.invokeLater(() -> getCommandExecutor().execute(AdbInputCommandFactory.getKeyCommand(key))); + public void actionPerformed(final ActionEvent e) { + SwingUtilities.invokeLater(() -> { + final KeyCommand command = getInputCommandFactory().getKeyCommand(key); + getCommandExecutor().execute(command); + }); + } + + private InputCommandFactory getInputCommandFactory() { + if (inputCommandFactory == null) { + inputCommandFactory = MainComponentProvider.mainComponent().inputCommandFactory(); + } + return inputCommandFactory; } private CommandExecutor getCommandExecutor() { diff --git a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java index fe63c79..4d6f663 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/MouseActionAdapter.java @@ -1,7 +1,9 @@ package com.github.xsavikx.androidscreencast.ui.interaction; +import com.github.xsavikx.androidscreencast.api.command.SwipeCommand; +import com.github.xsavikx.androidscreencast.api.command.TapCommand; import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor; -import com.github.xsavikx.androidscreencast.api.command.factory.AdbInputCommandFactory; +import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory; import com.github.xsavikx.androidscreencast.api.injector.Injector; import com.github.xsavikx.androidscreencast.ui.JPanelScreen; @@ -18,21 +20,26 @@ public class MouseActionAdapter extends MouseAdapter { private final static long ONE_SECOND = 1000L; private final JPanelScreen jp; private final CommandExecutor commandExecutor; + private final InputCommandFactory inputCommandFactory; private final Injector injector; private int dragFromX = -1; private int dragFromY = -1; private long timeFromPress = -1; @Inject - public MouseActionAdapter(JPanelScreen jp, CommandExecutor commandExecutor, Injector injector) { + public MouseActionAdapter(final JPanelScreen jp, + final CommandExecutor commandExecutor, + final InputCommandFactory inputCommandFactory, + final Injector injector) { this.jp = jp; this.commandExecutor = commandExecutor; + this.inputCommandFactory = inputCommandFactory; this.injector = injector; } @Override - public void mouseClicked(MouseEvent e) { + public void mouseClicked(final MouseEvent e) { if (injector != null && e.getButton() == MouseEvent.BUTTON3) { injector.toggleOrientation(); e.consume(); @@ -40,14 +47,17 @@ public void mouseClicked(MouseEvent e) { } final Point p2 = jp.getRawPoint(e.getPoint()); if (p2.x > 0 && p2.y > 0) { - SwingUtilities.invokeLater(() -> commandExecutor.execute(AdbInputCommandFactory.getTapCommand(p2.x, p2.y))); + SwingUtilities.invokeLater(() -> { + final TapCommand command = inputCommandFactory.getTapCommand(p2.x, p2.y); + commandExecutor.execute(command); + }); } } @Override - public void mouseDragged(MouseEvent e) { + public void mouseDragged(final MouseEvent e) { if (dragFromX == -1 && dragFromY == -1) { - Point p2 = jp.getRawPoint(e.getPoint()); + final Point p2 = jp.getRawPoint(e.getPoint()); dragFromX = p2.x; dragFromY = p2.y; timeFromPress = System.currentTimeMillis(); @@ -62,15 +72,22 @@ public void mouseReleased(MouseEvent e) { final int yFrom = dragFromY; final int xTo = p2.x; final int yTo = p2.y; - SwingUtilities.invokeLater(() -> commandExecutor.execute(AdbInputCommandFactory.getSwipeCommand(xFrom, yFrom, xTo, yTo, timeFromPress))); - dragFromX = -1; - dragFromY = -1; - timeFromPress = -1; + SwingUtilities.invokeLater(() -> { + final SwipeCommand command = inputCommandFactory.getSwipeCommand(xFrom, yFrom, xTo, yTo, timeFromPress); + commandExecutor.execute(command); + }); + clearState(); } } + private void clearState() { + dragFromX = -1; + dragFromY = -1; + timeFromPress = -1; + } + @Override - public void mouseWheelMoved(MouseWheelEvent arg0) { + public void mouseWheelMoved(final MouseWheelEvent arg0) { // if (JFrameMain.this.injector == null) // return; // JFrameMain.this.injector.injectTrackball(arg0.getWheelRotation() < 0 ? From 5a61f740317e903c12abc8804c47b1ac023a1be3 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Tue, 28 Feb 2017 23:23:38 +0200 Subject: [PATCH 17/20] removed unused methods --- .../factory/AdbInputCommandFactory.java | 21 ------------------- .../command/factory/InputCommandFactory.java | 6 ------ 2 files changed, 27 deletions(-) diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java index 0fb6f97..0fe03aa 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java @@ -26,20 +26,6 @@ public KeyCommand getKeyCommand(final int keyCode) { return returnKeyCommand; } - @Override - public KeyCommand getKeyCommand(final InputKeyEvent inputKeyEvent) { - final KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent); - LOGGER.debug(String.valueOf(returnKeyCommand)); - return returnKeyCommand; - } - - @Override - public KeyCommand getKeyCommand(final int keyCode, final boolean longpress) { - final KeyCommand returnKeyCommand = new KeyCommand(keyCode, longpress); - LOGGER.debug(String.valueOf(returnKeyCommand)); - return returnKeyCommand; - } - @Override public KeyCommand getKeyCommand(final InputKeyEvent inputKeyEvent, final boolean longpress) { final KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent, longpress); @@ -54,13 +40,6 @@ public SwipeCommand getSwipeCommand(final int x1, final int y1, final int x2, fi return returnSwipeCommand; } - @Override - public SwipeCommand getSwipeCommand(final int x1, final int y1, final int x2, final int y2) { - final SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2); - LOGGER.debug(String.valueOf(returnSwipeCommand)); - return returnSwipeCommand; - } - @Override public TapCommand getTapCommand(final int x, final int y) { final TapCommand returnTapCommand = new TapCommand(x, y); diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java index 73f2062..a8953d1 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java @@ -8,15 +8,9 @@ public interface InputCommandFactory { KeyCommand getKeyCommand(int keyCode); - KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent); - - KeyCommand getKeyCommand(int keyCode, boolean longpress); - KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress); SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration); - SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2); - TapCommand getTapCommand(int x, int y); } From b9ae0c809ea666cdc05a4410cbd65edcc9a5a051 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Fri, 3 Mar 2017 23:26:31 +0200 Subject: [PATCH 18/20] update version to release 0.0.10s --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2027289..dc3501e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.github.xsavikx androidscreencast - 0.0.10s-SNAPSHOT + 0.0.10s Android Screencast 2.9 From 2c0f577ad25cd05b79126c22bc7d2b06de9a251f Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Fri, 3 Mar 2017 23:30:18 +0200 Subject: [PATCH 19/20] updage jnlp version --- docs/jnlp/androidscreencast.jnlp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/jnlp/androidscreencast.jnlp b/docs/jnlp/androidscreencast.jnlp index 06d6d3a..d3c68dd 100644 --- a/docs/jnlp/androidscreencast.jnlp +++ b/docs/jnlp/androidscreencast.jnlp @@ -1,7 +1,7 @@ + version="0.0.10s"> Android Screencast Iurii Sergiichuk @@ -16,7 +16,7 @@ + href="https://github.com/xSAVIKx/AndroidScreencast/releases/download/0.0.10s/androidscreencast-0.0.10s-executable.jar"/> From 9914794fcabbeb7956a37b2ef16097ab9d01b3b0 Mon Sep 17 00:00:00 2001 From: Iurii Sergiichuk Date: Fri, 3 Mar 2017 23:30:48 +0200 Subject: [PATCH 20/20] update version in README and ensure packaging is defined in pom.xml --- README.md | 2 +- pom.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ace09f..550960a 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ The resulting artifacts will be created in the `target` subdirectory. You can run the executable jar via `java -jar target/androidscreencast-VERSION-executable.jar`, replacing VERSION with the current version. -For example, `java -jar target/androidscreencast-0.0.9s-executable.jar`. +For example, `java -jar target/androidscreencast-0.0.10s-executable.jar`. Additionally OS-packages would be created with ADB executables bundled: * `androidscreencast-VERSION-windows.zip` diff --git a/pom.xml b/pom.xml index dc3501e..a004b8e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,6 +5,7 @@ androidscreencast 0.0.10s Android Screencast + jar 2.9 25.2.0