From effffddd8dd8919fbb68fb0252ef6ba61a7097f6 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Thu, 1 Nov 2018 23:16:14 +0100 Subject: [PATCH] fixed lgtm warnings --- .../gadgetbridge/model/ActivityKind.java | 4 ++- .../service/devices/hplus/HPlusSupport.java | 4 +-- .../operations/FetchActivityOperation.java | 2 +- .../devices/pebble/PebbleIoThread.java | 2 +- .../devices/pebble/PebbleProtocol.java | 30 +++++++++---------- .../devices/pebble/webview/GBWebClient.java | 6 ++-- .../util/BengaliLanguageUtils.java | 6 ++-- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java index 774bde62d..744bd9b67 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java @@ -38,11 +38,13 @@ public class ActivityKind { public static final int TYPE_CYCLING = 128; public static final int TYPE_TREADMILL = 256; + private static final int TYPES_COUNT = 11; + public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP; public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN; public static int[] mapToDBActivityTypes(int types, SampleProvider provider) { - int[] result = new int[3]; + int[] result = new int[TYPES_COUNT]; int i = 0; if ((types & ActivityKind.TYPE_ACTIVITY) != 0) { result[i++] = provider.toRawActivityKind(TYPE_ACTIVITY); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java index fbb28c469..b89d738df 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java @@ -800,7 +800,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { private byte[] encodeStringToDevice(String s) { List outBytes = new ArrayList(); - Boolean unicode = HPlusCoordinator.getUnicodeSupport(this.gbDevice.getAddress()); + boolean unicode = HPlusCoordinator.getUnicodeSupport(this.gbDevice.getAddress()); LOG.info("Encode String: Unicode=" + unicode); for (int i = 0; i < s.length(); i++) { @@ -827,7 +827,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { outBytes.add(cs[j]); } - return ArrayUtils.toPrimitive(outBytes.toArray(new Byte[outBytes.size()])); + return ArrayUtils.toPrimitive(outBytes.toArray(new Byte[0])); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchActivityOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchActivityOperation.java index 131c333ef..4d7e8b27e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchActivityOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchActivityOperation.java @@ -196,7 +196,7 @@ public class FetchActivityOperation extends AbstractFetchOperation { } for (int i = 1; i < len; i+=4) { - MiBandActivitySample sample = createSample(value[i], value[i + 1], value[i + 2], value[i + 3]); + MiBandActivitySample sample = createSample(value[i], value[i + 1], value[i + 2], value[i + 3]); // lgtm [java/index-out-of-bounds] samples.add(sample); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index eb486ac9e..09bcceab9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -387,7 +387,7 @@ class PebbleIoThread extends GBDeviceIoThread { gbDevice.setState(GBDevice.State.WAITING_FOR_RECONNECT); gbDevice.sendDeviceUpdateIntent(getContext()); - int delaySeconds = 1; + long delaySeconds = 1; while (reconnectAttempts-- > 0 && !mQuit && !mIsConnected) { LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")"); mIsConnected = connect(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index 4157898e0..d33d8113d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -632,7 +632,7 @@ public class PebbleProtocol extends GBDeviceProtocol { for (String reply : cannedReplies) { replies_length += reply.getBytes().length + 1; } - actions_length += ACTION_LENGTH_MIN + reply_string.getBytes().length + replies_length + 3; // 3 = attribute id (byte) + length(short) + actions_length += (short) (ACTION_LENGTH_MIN + reply_string.getBytes().length + replies_length + 3); // 3 = attribute id (byte) + length(short) } byte attributes_count = 0; @@ -788,10 +788,10 @@ public class PebbleProtocol extends GBDeviceProtocol { buf.order(ByteOrder.LITTLE_ENDIAN); ActivityUser activityUser = new ActivityUser(); - Integer heightMm = activityUser.getHeightCm() * 10; - buf.putShort(heightMm.shortValue()); - Integer weigthDag = activityUser.getWeightKg() * 100; - buf.putShort(weigthDag.shortValue()); + int heightMm = activityUser.getHeightCm() * 10; + buf.putShort((short) heightMm); + int weigthDag = activityUser.getWeightKg() * 100; + buf.putShort((short) weigthDag); buf.put((byte) 0x01); //activate tracking buf.put((byte) 0x00); //activity Insights buf.put((byte) 0x00); //sleep Insights @@ -945,7 +945,7 @@ public class PebbleProtocol extends GBDeviceProtocol { int icon_id = notificationType.icon; // Calculate length first - byte actions_count = 0; + int actions_count = 0; short actions_length = 0; String dismiss_string; String open_string = "Open on phone"; @@ -979,8 +979,8 @@ public class PebbleProtocol extends GBDeviceProtocol { for (String reply : cannedReplies) { replies_length += reply.getBytes().length + 1; } - //similarly, only the replies lenght has to be added, the lenght for the bare action was already added above - actions_length += replies_length + 3; // 3 = attribute id (byte) + length(short) + //similarly, only the replies length has to be added, the length for the bare action was already added above + actions_length += (short) (replies_length + 3); // 3 = attribute id (byte) + length(short) } byte attributes_count = 2; // icon @@ -990,7 +990,7 @@ public class PebbleProtocol extends GBDeviceProtocol { continue; } attributes_count++; - attributes_length += (3 + s.getBytes().length); + attributes_length += (short) (3 + s.getBytes().length); } short pin_length = (short) (NOTIFICATION_PIN_LENGTH + attributes_length); @@ -1011,7 +1011,7 @@ public class PebbleProtocol extends GBDeviceProtocol { buf.put((byte) 0x04); // layout (0x04 = notification?) buf.putShort(attributes_length); // total length of all attributes and actions in bytes buf.put(attributes_count); - buf.put(actions_count); + buf.put((byte) actions_count); byte attribute_id = 0; // Encode Pascal-Style Strings @@ -1131,7 +1131,7 @@ public class PebbleProtocol extends GBDeviceProtocol { continue; } attributes_count++; - attributes_length += (3 + s.getBytes().length); + attributes_length += (short) (3 + s.getBytes().length); } UUID uuid = UUID.fromString("61b22bc8-1e29-460d-a236-3fe409a43901"); @@ -1264,7 +1264,7 @@ public class PebbleProtocol extends GBDeviceProtocol { if (s == null || s.equals("")) { continue; } - attributes_length += (2 + s.getBytes().length); + attributes_length += (short) (2 + s.getBytes().length); } short pin_length = (short) (WEATHER_FORECAST_LENGTH + attributes_length); @@ -1667,7 +1667,7 @@ public class PebbleProtocol extends GBDeviceProtocol { } if (type == PUTBYTES_TYPE_FILE && filename != null) { - length += filename.getBytes().length + 1; + length += (short) filename.getBytes().length + 1; } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length); @@ -2545,8 +2545,8 @@ public class PebbleProtocol extends GBDeviceProtocol { } else { appType = GBDeviceApp.Type.APP_GENERIC; } - Short appVersion = buf.getShort(); - appInfoCmd.apps[i] = new GBDeviceApp(tmpUUIDS.get(i), appName, appCreator, appVersion.toString(), appType); + short appVersion = buf.getShort(); + appInfoCmd.apps[i] = new GBDeviceApp(tmpUUIDS.get(i), appName, appCreator, String.valueOf(appVersion), appType); } for (int i = 0; i < slotCount; i++) { if (!slotInUse[i]) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java index c1b647599..3df79c9b6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java @@ -232,9 +232,9 @@ public class GBWebClient extends WebViewClient { main.put("temp_min", (int) main.get("temp_min") - 273); main.put("temp_max", (int) main.get("temp_max") - 273); } else if ("imperial".equals(units)) { //it's 2017... this is so sad - main.put("temp", ((int) (main.get("temp")) - 273.15f) * 1.8f + 32); - main.put("temp_min", ((int) (main.get("temp_min")) - 273.15f) * 1.8f + 32); - main.put("temp_max", ((int) (main.get("temp_max")) - 273.15f) * 1.8f + 32); + main.put("temp", ((int) (main.get("temp")) - 273.15f) * 1.8f + 32); // lgtm [java/integer-multiplication-cast-to-long] + main.put("temp_min", ((int) (main.get("temp_min")) - 273.15f) * 1.8f + 32); // lgtm [java/integer-multiplication-cast-to-long] + main.put("temp_max", ((int) (main.get("temp_max")) - 273.15f) * 1.8f + 32); // lgtm [java/integer-multiplication-cast-to-long] } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/BengaliLanguageUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/BengaliLanguageUtils.java index a59acfbe1..a67ec9845 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/BengaliLanguageUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/BengaliLanguageUtils.java @@ -254,9 +254,9 @@ public class BengaliLanguageUtils extends LanguageUtils { String kaarStr = letters.get(kaar); if (kaarStr != null) { appendableString = appendableString + kaarStr; - } - if (kaarStr.equals("i") || kaarStr.equals("ii") || kaarStr.equals("u") || kaarStr.equals("uu")) { - changePronounciation = true; + if (kaarStr.equals("i") || kaarStr.equals("ii") || kaarStr.equals("u") || kaarStr.equals("uu")) { + changePronounciation = true; + } } } String singleton = m.group(11);