1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-28 19:45:50 +01:00

Fix some static analysis warnings

This commit is contained in:
cpfeiffer 2018-09-16 13:37:08 +02:00
parent 08dfa2a47d
commit 5028458fe8
5 changed files with 63 additions and 76 deletions

View File

@ -108,7 +108,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
List<BarEntry> entries = new ArrayList<>();
ArrayList<String> labels = new ArrayList<String>();
int balance = 0;
long balance = 0;
for (int counter = 0; counter < TOTAL_DAYS; counter++) {
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
@ -171,7 +171,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
set.setValueFormatter(getPieValueFormatter());
}
return new DayData(data, formatPieValue((int) totalValue));
return new DayData(data, formatPieValue((long) totalValue));
}
@Override
@ -321,7 +321,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts);
abstract String formatPieValue(int value);
abstract String formatPieValue(long value);
abstract String[] getPieLabels();
@ -335,9 +335,9 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract String getPieDescription(int targetValue);
protected abstract int calculateBalance(ActivityAmounts amounts);
protected abstract long calculateBalance(ActivityAmounts amounts);
protected abstract String getBalanceMessage(int balance, int targetValue);
protected abstract String getBalanceMessage(long balance, int targetValue);
private class WeekChartsData<T extends ChartData<?>> extends DefaultChartsData<T> {
private final String balanceMessage;

View File

@ -60,7 +60,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
@Override
protected int calculateBalance(ActivityAmounts activityAmounts) {
protected long calculateBalance(ActivityAmounts activityAmounts) {
long balance = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) {
@ -72,13 +72,13 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
}
@Override
protected String getBalanceMessage(int balance, int targetValue) {
protected String getBalanceMessage(long balance, int targetValue) {
if (balance > 0) {
final long totalBalance = balance - (targetValue * TOTAL_DAYS);
if (totalBalance > 0)
return getString(R.string.overslept, getHM((int) totalBalance));
return getString(R.string.overslept, getHM(totalBalance));
else
return getString(R.string.lack_of_sleep, getHM((int) Math.abs(totalBalance)));
return getString(R.string.lack_of_sleep, getHM(Math.abs(totalBalance)));
} else
return getString(R.string.no_data);
}
@ -100,8 +100,8 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
}
@Override
protected String formatPieValue(int value) {
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.MINUTES);
protected String formatPieValue(long value) {
return DateTimeUtils.formatDurationHoursMinutes(value, TimeUnit.MINUTES);
}
@Override
@ -114,7 +114,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
return new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return formatPieValue((int) value);
return formatPieValue((long) value);
}
};
}
@ -164,7 +164,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
chart.getLegend().setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
}
private String getHM(int value) {
private String getHM(long value) {
return DateTimeUtils.formatDurationHoursMinutes(value, TimeUnit.MINUTES);
}
}

View File

@ -50,7 +50,7 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
@Override
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
int totalSteps = 0;
long totalSteps = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) {
totalSteps += amount.getTotalSteps();
}
@ -58,8 +58,8 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
}
@Override
protected int calculateBalance(ActivityAmounts activityAmounts) {
int balance = 0;
protected long calculateBalance(ActivityAmounts activityAmounts) {
long balance = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) {
balance += amount.getTotalSteps();
}
@ -67,7 +67,7 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
}
@Override
protected String formatPieValue(int value) {
protected String formatPieValue(long value) {
return String.valueOf(value);
}
@ -103,13 +103,13 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
}
@Override
protected String getBalanceMessage(int balance, int targetValue) {
protected String getBalanceMessage(long balance, int targetValue) {
if (balance > 0) {
final long totalBalance = balance - (targetValue * TOTAL_DAYS);
if (totalBalance > 0)
return getString(R.string.overstep, (int) Math.abs(totalBalance));
return getString(R.string.overstep, Math.abs(totalBalance));
else
return getString(R.string.lack_of_step, (int) Math.abs(totalBalance));
return getString(R.string.lack_of_step, Math.abs(totalBalance));
} else
return getString(R.string.no_data);
}

View File

@ -548,9 +548,9 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport {
int yearInt, monthInt, dayInt, hoursMinutesInt = 0;
int hours, minutes = 0;
yearInt = Integer.valueOf(String.format("%02x", year, 16));
monthInt = Integer.valueOf(String.format("%02x", month, 16));
dayInt = Integer.valueOf(String.format("%02x", day, 16));
yearInt = Integer.valueOf(String.format("%02x", year), 16);
monthInt = Integer.valueOf(String.format("%02x", month), 16);
dayInt = Integer.valueOf(String.format("%02x", day), 16);
hoursMinutesInt = Integer.valueOf(String.format("%02x", hoursminutes), 16);
minutes = hoursMinutesInt % 4;

View File

@ -200,7 +200,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
music[5] = musicState;
System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, music, 6, songtitle.getBytes(StandardCharsets.UTF_8).length);
music[music.length - 1] = ZeTimeConstants.CMD_END;
if (music != null) {
try {
TransactionBuilder builder = performInitialized("setMusicStateInfo");
replyMsgToWatch(builder, music);
@ -210,7 +209,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
}
}
}
}
@Override
public void onSetCallState(CallSpec callSpec) {
@ -345,7 +343,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
}
System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, music, 6, songtitle.getBytes(StandardCharsets.UTF_8).length);
music[music.length - 1] = ZeTimeConstants.CMD_END;
if (music != null) {
try {
TransactionBuilder builder = performInitialized("setMusicStateInfo");
replyMsgToWatch(builder, music);
@ -355,7 +352,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
}
}
}
}
@Override
public void onAddCalendarEvent(CalendarEventSpec calendarEventSpec) {
@ -379,8 +375,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
CalendarEvent[14] = (byte) calendarEventSpec.title.getBytes(StandardCharsets.UTF_8).length;
System.arraycopy(calendarEventSpec.title.getBytes(StandardCharsets.UTF_8), 0, CalendarEvent, 15, calendarEventSpec.title.getBytes(StandardCharsets.UTF_8).length);
CalendarEvent[CalendarEvent.length-1] = ZeTimeConstants.CMD_END;
if(CalendarEvent != null)
{
try {
TransactionBuilder builder = performInitialized("sendCalendarEvenr");
sendMsgToWatch(builder, CalendarEvent);
@ -389,7 +383,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
GB.toast(getContext(), "Error sending calendar event: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
}
@Override
public void onSetTime() {
@ -449,8 +442,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
}
System.arraycopy(weatherSpec.location.getBytes(StandardCharsets.UTF_8), 0, weather, 25, weatherSpec.location.getBytes(StandardCharsets.UTF_8).length);
weather[weather.length-1] = ZeTimeConstants.CMD_END;
if(weather != null)
{
try {
TransactionBuilder builder = performInitialized("sendWeahter");
sendMsgToWatch(builder, weather);
@ -459,7 +450,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
GB.toast(getContext(), "Error sending weather: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
}
@Override
public void onAppReorder(UUID[] uuids) {
@ -620,8 +610,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
notification[5] = ZeTimeConstants.NOTIFICATION_SOCIAL;
break;
}
if(notification != null)
{
try {
TransactionBuilder builder = performInitialized("sendNotification");
sendMsgToWatch(builder, notification);
@ -630,7 +618,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
GB.toast(getContext(), "Error sending notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
}
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt,