1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-04 12:02:06 +02:00

fixed lgtm warnings

This commit is contained in:
cpfeiffer 2018-11-01 23:16:14 +01:00
parent 7ddd2a045a
commit effffddd8d
7 changed files with 28 additions and 26 deletions

View File

@ -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);

View File

@ -800,7 +800,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private byte[] encodeStringToDevice(String s) {
List<Byte> outBytes = new ArrayList<Byte>();
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

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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]) {

View File

@ -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]
}
}

View File

@ -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);