1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-16 12:47:32 +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<>(); List<BarEntry> entries = new ArrayList<>();
ArrayList<String> labels = new ArrayList<String>(); ArrayList<String> labels = new ArrayList<String>();
int balance = 0; long balance = 0;
for (int counter = 0; counter < TOTAL_DAYS; counter++) { for (int counter = 0; counter < TOTAL_DAYS; counter++) {
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device); ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
@ -171,7 +171,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
set.setValueFormatter(getPieValueFormatter()); set.setValueFormatter(getPieValueFormatter());
} }
return new DayData(data, formatPieValue((int) totalValue)); return new DayData(data, formatPieValue((long) totalValue));
} }
@Override @Override
@ -321,7 +321,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts); abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts);
abstract String formatPieValue(int value); abstract String formatPieValue(long value);
abstract String[] getPieLabels(); abstract String[] getPieLabels();
@ -335,9 +335,9 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract String getPieDescription(int targetValue); 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 class WeekChartsData<T extends ChartData<?>> extends DefaultChartsData<T> {
private final String balanceMessage; private final String balanceMessage;

View File

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

View File

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

View File

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

View File

@ -200,14 +200,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
music[5] = musicState; music[5] = musicState;
System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, music, 6, songtitle.getBytes(StandardCharsets.UTF_8).length); System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, music, 6, songtitle.getBytes(StandardCharsets.UTF_8).length);
music[music.length - 1] = ZeTimeConstants.CMD_END; music[music.length - 1] = ZeTimeConstants.CMD_END;
if (music != null) { try {
try { TransactionBuilder builder = performInitialized("setMusicStateInfo");
TransactionBuilder builder = performInitialized("setMusicStateInfo"); replyMsgToWatch(builder, music);
replyMsgToWatch(builder, music); builder.queue(getQueue());
builder.queue(getQueue()); } catch (IOException e) {
} catch (IOException e) { GB.toast(getContext(), "Error setting music state and info: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.toast(getContext(), "Error setting music state and info: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
} }
} }
} }
@ -345,14 +343,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
} }
System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, music, 6, songtitle.getBytes(StandardCharsets.UTF_8).length); System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, music, 6, songtitle.getBytes(StandardCharsets.UTF_8).length);
music[music.length - 1] = ZeTimeConstants.CMD_END; music[music.length - 1] = ZeTimeConstants.CMD_END;
if (music != null) { try {
try { TransactionBuilder builder = performInitialized("setMusicStateInfo");
TransactionBuilder builder = performInitialized("setMusicStateInfo"); replyMsgToWatch(builder, music);
replyMsgToWatch(builder, music); builder.queue(getQueue());
builder.queue(getQueue()); } catch (IOException e) {
} catch (IOException e) { GB.toast(getContext(), "Error setting music state and info: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.toast(getContext(), "Error setting music state and info: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
} }
} }
} }
@ -379,15 +375,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
CalendarEvent[14] = (byte) calendarEventSpec.title.getBytes(StandardCharsets.UTF_8).length; 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); 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; CalendarEvent[CalendarEvent.length-1] = ZeTimeConstants.CMD_END;
if(CalendarEvent != null) try {
{ TransactionBuilder builder = performInitialized("sendCalendarEvenr");
try { sendMsgToWatch(builder, CalendarEvent);
TransactionBuilder builder = performInitialized("sendCalendarEvenr"); builder.queue(getQueue());
sendMsgToWatch(builder, CalendarEvent); } catch (IOException e) {
builder.queue(getQueue()); GB.toast(getContext(), "Error sending calendar event: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} catch (IOException e) {
GB.toast(getContext(), "Error sending calendar event: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
} }
} }
@ -449,15 +442,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
} }
System.arraycopy(weatherSpec.location.getBytes(StandardCharsets.UTF_8), 0, weather, 25, weatherSpec.location.getBytes(StandardCharsets.UTF_8).length); 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; weather[weather.length-1] = ZeTimeConstants.CMD_END;
if(weather != null) try {
{ TransactionBuilder builder = performInitialized("sendWeahter");
try { sendMsgToWatch(builder, weather);
TransactionBuilder builder = performInitialized("sendWeahter"); builder.queue(getQueue());
sendMsgToWatch(builder, weather); } catch (IOException e) {
builder.queue(getQueue()); GB.toast(getContext(), "Error sending weather: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} catch (IOException e) {
GB.toast(getContext(), "Error sending weather: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
} }
} }
@ -620,8 +610,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
notification[5] = ZeTimeConstants.NOTIFICATION_SOCIAL; notification[5] = ZeTimeConstants.NOTIFICATION_SOCIAL;
break; break;
} }
if(notification != null)
{
try { try {
TransactionBuilder builder = performInitialized("sendNotification"); TransactionBuilder builder = performInitialized("sendNotification");
sendMsgToWatch(builder, notification); sendMsgToWatch(builder, notification);
@ -629,7 +617,6 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error sending notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error sending notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} }
}
} }
@Override @Override