Skip to content

Commit 41e7171

Browse files
committed
fix codacy issues
1 parent 0e92b6f commit 41e7171

File tree

12 files changed

+75
-41
lines changed

12 files changed

+75
-41
lines changed

src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/CommandExecutionException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.github.xsavikx.androidscreencast.api.command.exception;
22

3-
public class CommandExecutionException extends RuntimeException {
3+
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
4+
5+
public class CommandExecutionException extends AndroidScreenCastRuntimeException {
46

57
private static final long serialVersionUID = 8676432388325401069L;
68

src/main/java/com/github/xsavikx/androidscreencast/api/image/AbstractRawImageColorModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public AbstractRawImageColorModel() {
2525

2626
protected abstract int getPixel(byte[] data);
2727

28-
int getPixel(Object inData) {
28+
protected int getPixel(Object inData) {
2929
return getPixel((byte[]) inData);
3030
}
3131

32-
int getMask(int length) {
32+
protected int getMask(int length) {
3333
int res = 0;
3434
for (int i = 0; i < length; i++) {
3535
res = (res << 1) + 1;

src/main/java/com/github/xsavikx/androidscreencast/api/image/ImageUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public static BufferedImage convertImage(RawImage rawImage) {
3232
return rawImage16toARGB(rawImage);
3333
case THIRTY_TWO_BIT_IMAGE:
3434
return rawImage32toARGB(rawImage);
35+
default:
36+
throw new IllegalStateException("Raw image contain wrong bpp: " + rawImage.bpp);
3537
}
36-
throw new IllegalArgumentException("Raw image contain wrong bpp: " + rawImage.bpp);
3738
}
3839

3940
private static BufferedImage rawImage32toARGB(RawImage rawImage) {

src/main/java/com/github/xsavikx/androidscreencast/api/injector/Injector.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,11 @@ public Injector(ScreenCaptureRunnable screenCaptureRunnable) {
1919
}
2020

2121
public void stop() {
22-
LOGGER.debug("stop() - start");
2322
screenCaptureRunnable.stop();
24-
LOGGER.debug("stop() - end");
2523
}
2624

2725
public void start() {
28-
LOGGER.debug("start() - start");
29-
3026
screenCaptureThread.start();
31-
32-
LOGGER.debug("start() - end");
3327
}
3428

3529
public void setScreenCaptureListener(ScreenCaptureRunnable.ScreenCaptureListener listener) {

src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static int getKeyCode(KeyEvent e) {
1616
if (inputKeyEvent != null) {
1717
code = inputKeyEvent.getCode();
1818
}
19-
LOGGER.debug("getKeyCode(KeyEvent e=" + e + ") - end");
19+
LOGGER.debug(String.format("Received KeyEvent=%s. Produced KeyCode=%d", String.valueOf(e), code));
2020
return code;
2121
}
2222

src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.xsavikx.androidscreencast.api.injector;
22

33
import com.android.ddmlib.IShellOutputReceiver;
4+
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
45

56
import java.io.IOException;
67
import java.io.OutputStream;
@@ -17,8 +18,8 @@ public OutputStreamShellOutputReceiver(OutputStream os) {
1718
public void addOutput(byte[] buf, int off, int len) {
1819
try {
1920
os.write(buf, off, len);
20-
} catch (IOException ex) {
21-
throw new RuntimeException(ex);
21+
} catch (IOException e) {
22+
throw new IORuntimeException(e);
2223
}
2324
}
2425

@@ -27,7 +28,7 @@ public void flush() {
2728
try {
2829
os.flush();
2930
} catch (IOException e) {
30-
e.printStackTrace();
31+
throw new IORuntimeException(e);
3132
}
3233
}
3334

src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.android.ddmlib.TimeoutException;
77
import com.github.xsavikx.androidscreencast.api.image.ImageUtils;
88
import com.github.xsavikx.androidscreencast.api.recording.QuickTimeOutputStream;
9+
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
910
import org.apache.log4j.Logger;
1011
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.beans.factory.annotation.Value;
@@ -22,6 +23,10 @@
2223
@Component
2324
public class ScreenCaptureRunnable implements Runnable {
2425
private static final Logger LOGGER = Logger.getLogger(ScreenCaptureRunnable.class);
26+
private static final String MOV_FILE_TYPE = ".mov";
27+
private static final int MOV_FPS = 30;
28+
private static final float MOV_COMPRESSION_RATE = 1f;
29+
private static final int FRAME_DURATION = 10;
2530
private final IDevice device;
2631
private Dimension size;
2732
private QuickTimeOutputStream qos = null;
@@ -93,7 +98,7 @@ private void display(RawImage rawImage) {
9398
if (qos != null) {
9499
SwingUtilities.invokeLater(() -> {
95100
try {
96-
qos.writeFrame(image, 10);
101+
qos.writeFrame(image, FRAME_DURATION);
97102
} catch (IOException e) {
98103
LOGGER.error(e);
99104
}
@@ -106,16 +111,17 @@ public void setListener(ScreenCaptureListener listener) {
106111
}
107112

108113

109-
public void startRecording(File f) {
114+
public void startRecording(File file) {
110115
try {
111-
if (!f.getName().toLowerCase().endsWith(".mov"))
112-
f = new File(f.getAbsolutePath() + ".mov");
113-
qos = new QuickTimeOutputStream(f, QuickTimeOutputStream.VideoFormat.JPG);
116+
File outputFile = file;
117+
if (!outputFile.getName().toLowerCase().endsWith(MOV_FILE_TYPE))
118+
outputFile = new File(file.getAbsolutePath() + MOV_FILE_TYPE);
119+
qos = new QuickTimeOutputStream(outputFile, QuickTimeOutputStream.VideoFormat.JPG);
114120
} catch (IOException e) {
115-
throw new RuntimeException(e);
121+
throw new IORuntimeException(e);
116122
}
117-
qos.setVideoCompressionQuality(1f);
118-
qos.setTimeScale(30); // 30 fps
123+
qos.setVideoCompressionQuality(MOV_COMPRESSION_RATE);
124+
qos.setTimeScale(MOV_FPS);
119125
}
120126

121127
public void stopRecording() {
@@ -124,7 +130,7 @@ public void stopRecording() {
124130
qos = null;
125131
o.close();
126132
} catch (IOException e) {
127-
throw new RuntimeException(e);
133+
throw new IORuntimeException(e);
128134
}
129135
}
130136

src/main/java/com/github/xsavikx/androidscreencast/api/recording/QuickTimeOutputStream.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,8 @@ private void writeEpilog() throws IOException {
949949

950950
break;
951951
}
952+
default:
953+
throw new IllegalStateException("Such video format is not supported: " + videoFormat);
952954
}
953955

954956
/* Time to Sample atom ---- */
@@ -1202,9 +1204,10 @@ public void writeFrame(BufferedImage image, int duration) throws IOException {
12021204
byte[] bytes = new byte[imgWidth * 3]; // holds a scanline of raw
12031205
// image data with 3
12041206
// channels of 8 bit data
1207+
int n = imgWidth * 3;
12051208
for (int y = 0; y < imgHeight; y++) {
12061209
raster.getPixels(0, y, imgWidth, 1, raw);
1207-
for (int k = 0, n = imgWidth * 3; k < n; k++) {
1210+
for (int k = 0; k < n; k++) {
12081211
bytes[k] = (byte) raw[k];
12091212
}
12101213
mdatAtom.getOutputStream().write(bytes);
@@ -1336,15 +1339,15 @@ private static class Sample {
13361339
/**
13371340
* Offset of the sample relative to the start of the QuickTime file.
13381341
*/
1339-
long offset;
1342+
private long offset;
13401343
/**
13411344
* Data length of the sample.
13421345
*/
1343-
long length;
1346+
private long length;
13441347
/**
13451348
* The duration of the sample in time scale units.
13461349
*/
1347-
int duration;
1350+
private int duration;
13481351

13491352
/**
13501353
* Creates a new sample.

src/main/java/com/github/xsavikx/androidscreencast/app/SwingApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.xsavikx.androidscreencast.app;
22

3+
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
34
import com.github.xsavikx.androidscreencast.ui.JDialogError;
45
import org.springframework.beans.factory.annotation.Value;
56

@@ -22,7 +23,7 @@ public void init() {
2223
if (useNativeLook())
2324
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
2425
} catch (Exception ex) {
25-
throw new RuntimeException(ex);
26+
throw new AndroidScreenCastRuntimeException(ex);
2627
}
2728
}
2829

@@ -38,7 +39,7 @@ public void handleException(Thread thread, Throwable ex) {
3839
return;
3940
jd = new JDialogError(ex);
4041
SwingUtilities.invokeLater(() -> jd.setVisible(true));
41-
} catch (Exception ex2) {
42+
} catch (Exception ignored) {
4243
// ignored
4344
}
4445
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.xsavikx.androidscreencast.exception;
2+
3+
import java.io.IOException;
4+
5+
/**
6+
* Runtime Exception wrapper for {@link IOException}
7+
*/
8+
public class IORuntimeException extends AndroidScreenCastRuntimeException {
9+
10+
public IORuntimeException(String message, IOException cause) {
11+
super(message, cause);
12+
}
13+
14+
public IORuntimeException(IOException cause) {
15+
super(cause);
16+
}
17+
18+
public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
19+
super(message, cause, enableSuppression, writableStackTrace);
20+
}
21+
}

0 commit comments

Comments
 (0)