From c237970b3ad78686ed292bfcfa32bef68f17f8a1 Mon Sep 17 00:00:00 2001 From: 251309-lirui Date: Tue, 6 Jul 2021 19:06:53 +0800 Subject: [PATCH] =?UTF-8?q?findbugs=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/build.gradle | 3 +- .../Text/ImageSteganography.java | 6 --- .../Utils/ResUtils.java | 38 +++++++++---------- .../Utils/Utility.java | 6 --- .../view/CircleView.java | 18 ++++----- .../view/ProgressDialog.java | 4 +- 6 files changed, 31 insertions(+), 44 deletions(-) diff --git a/entry/build.gradle b/entry/build.gradle index 6f8ec3f..e7307fa 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -20,7 +20,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testImplementation 'junit:junit:4.13' ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' - implementation 'com.gitee.chinasoft_ohos:imagesteganographylibrary:0.0.2-SNAPSHOT' + implementation 'com.gitee.chinasoft_ohos:imagesteganographylibrary:0.0.2-SNAPSHOT' + //implementation project(path: ':imagesteganographylibrary') } decc { supportType = ['html', 'xml'] diff --git a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Text/ImageSteganography.java b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Text/ImageSteganography.java index 7ba2926..e838aaf 100644 --- a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Text/ImageSteganography.java +++ b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Text/ImageSteganography.java @@ -18,12 +18,9 @@ public class ImageSteganography { private String encrypted_message; private PixelMap image; private PixelMap encoded_image; - private byte[] encrypted_zip; private Boolean encoded; private Boolean decoded; private Boolean secretKeyWrong; - private PixelMap encoded_imax; - public ImageSteganography() { PixelMap.InitializationOptions options = new PixelMap.InitializationOptions(); @@ -37,7 +34,6 @@ public class ImageSteganography { this.encrypted_message = ""; this.image = PixelMap.create(options); this.encoded_image = PixelMap.create(options); - this.encrypted_zip = new byte[0]; } public ImageSteganography(String message, String secret_key, PixelMap image) { @@ -47,7 +43,6 @@ public class ImageSteganography { this.message = message; this.secret_key = convertKeyTo128bit(secret_key); this.image = image; - this.encrypted_zip = message.getBytes(); this.encrypted_message = encryptMessage(message, this.secret_key); this.encoded = false; this.decoded = false; @@ -72,7 +67,6 @@ public class ImageSteganography { this.message = ""; this.encrypted_message = ""; this.encoded_image = PixelMap.create(opts1); - this.encrypted_zip = new byte[0]; } private static String encryptMessage(String message, String secret_key) { diff --git a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/ResUtils.java b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/ResUtils.java index 17e001f..9498f7f 100644 --- a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/ResUtils.java +++ b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/ResUtils.java @@ -32,7 +32,7 @@ import java.io.IOException; * @since 2021-04-25 */ public class ResUtils { - private static final String TAG = "ResUtil"; + private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, "ResUtils"); private static final int CONSTANT = 160; private ResUtils() { @@ -46,7 +46,7 @@ public class ResUtils { * @return px */ public static int vpToPx(Context context, float vp) { - return (int) (context.getResourceManager().getDeviceCapability().screenDensity / CONSTANT * vp); + return (context.getResourceManager().getDeviceCapability().screenDensity / CONSTANT * Math.round(vp)); } /** @@ -57,7 +57,7 @@ public class ResUtils { * @return vp */ public static int pxTovp(Context context, float px) { - return (int) (px / (context.getResourceManager().getDeviceCapability().screenDensity / CONSTANT)); + return (Math.round(px) / (context.getResourceManager().getDeviceCapability().screenDensity / CONSTANT)); } /** @@ -90,26 +90,24 @@ public class ResUtils { public static String getString(Context context, int id) { String result = ""; if (context == null) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, - new ResUtils().getClass().getName()), "getString -> get null context"); + HiLog.error(LABEL_LOG, "getString -> get null context"); return result; } ResourceManager manager = context.getResourceManager(); if (manager == null) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, - new ResUtils().getClass().getName()), "getString -> get null ResourceManager"); + HiLog.error(LABEL_LOG, "getString -> get null ResourceManager"); return result; } try { result = manager.getElement(id).getString(); } catch (IOException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getString -> IOException"); } catch (NotExistException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getString -> NotExistException"); } catch (WrongTypeException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getString -> WrongTypeException"); } return result; @@ -125,26 +123,26 @@ public class ResUtils { public static String[] getStringArray(Context context, int id) { String[] result = null; if (context == null) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getStringArray -> get null context"); return result; } ResourceManager manager = context.getResourceManager(); if (manager == null) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getStringArray -> get null ResourceManager"); return result; } try { result = manager.getElement(id).getStringArray(); } catch (IOException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getStringArray -> IOException"); } catch (NotExistException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getStringArray -> NotExistException"); } catch (WrongTypeException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getStringArray -> WrongTypeException"); } return result; @@ -160,26 +158,26 @@ public class ResUtils { public static int getInt(Context context, int id) { int result = 0; if (context == null) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getInt -> get null context"); return result; } ResourceManager manager = context.getResourceManager(); if (manager == null) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getInt -> get null ResourceManager"); return result; } try { result = manager.getElement(id).getInteger(); } catch (IOException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getInt -> IOException"); } catch (NotExistException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getInt -> NotExistException"); } catch (WrongTypeException e) { - HiLog.error(new HiLogLabel(HiLog.LOG_APP, 0, new ResUtils().getClass().getName()), + HiLog.error(LABEL_LOG, "getInt -> WrongTypeException"); } return result; diff --git a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/Utility.java b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/Utility.java index c7f3d2e..8647fad 100644 --- a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/Utility.java +++ b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/Utils/Utility.java @@ -97,13 +97,8 @@ public class Utility { public static PixelMap mergeImage(List pixelMaps, int original_height, int original_width) { //Calculating number of Rows and columns of that matrix - int rows = original_height / SQUARE_BLOCK_SIZE; int cols = original_width / SQUARE_BLOCK_SIZE; - int chunk_height_mod = original_height % SQUARE_BLOCK_SIZE; int chunk_width_mod = original_width % SQUARE_BLOCK_SIZE; - - if (chunk_height_mod > 0) - rows++; if (chunk_width_mod > 0) cols++; PixelMap.InitializationOptions options = new PixelMap.InitializationOptions(); @@ -124,7 +119,6 @@ public class Utility { int size = b.length / 3; System.runFinalization(); //Garbage collection - System.gc(); int[] result = new int[size]; int offset = 0; int index = 0; diff --git a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/CircleView.java b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/CircleView.java index 652167b..9757612 100644 --- a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/CircleView.java +++ b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/CircleView.java @@ -45,15 +45,15 @@ public class CircleView extends Component implements Component.EstimateSizeListe */ public static final int INFINITE = -1; RectFloat rectF = new RectFloat(); - private final int strokeWidth = 12; - private final int rgbAlpha = 200; - private final int rgbRed = 255; - private final int rgbGreen = 20; - private final int rgbBlue = 147; - private final int drawCircle = 2; - private final float sweepAngle = 100; - private final float padding = 5; - private final int angle = 360; + private static final int strokeWidth = 12; + private static final int rgbAlpha = 200; + private static final int rgbRed = 255; + private static final int rgbGreen = 20; + private static final int rgbBlue = 147; + private static final int drawCircle = 2; + private static final float sweepAngle = 100; + private static final float padding = 5; + private static final int angle = 360; /** * valueAnimator */ diff --git a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/ProgressDialog.java b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/ProgressDialog.java index f6d0b3a..f5f60a4 100644 --- a/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/ProgressDialog.java +++ b/imagesteganographylibrary/src/main/java/com/example/imagesteganographylibrary/view/ProgressDialog.java @@ -36,8 +36,8 @@ import ohos.app.Context; * @since 2021-05-07 */ public class ProgressDialog extends CommonDialog { - private final int animTime = 500; - private final double widths = 0.9; + private static final int animTime = 500; + private static final double widths = 0.9; private Text tvIndex; private Text tvTitle; -- Gitee