1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-18 06:37:47 +01:00

Merge branch 'master' into fossil-q-hr

This commit is contained in:
cpfeiffer 2020-02-26 22:47:35 +01:00
commit 4d8ddb96cf
3 changed files with 22 additions and 22 deletions

View File

@ -66,12 +66,12 @@ public class Widget extends AppWidgetProvider {
return gbApp.getDeviceManager().getSelectedDevice(); return gbApp.getDeviceManager().getSelectedDevice();
} }
private int[] getSteps() { private long[] getSteps() {
Context context = GBApplication.getContext(); Context context = GBApplication.getContext();
Calendar day = GregorianCalendar.getInstance(); Calendar day = GregorianCalendar.getInstance();
if (!(context instanceof GBApplication)) { if (!(context instanceof GBApplication)) {
return new int[]{0, 0, 0}; return new long[]{0, 0, 0};
} }
DailyTotals ds = new DailyTotals(); DailyTotals ds = new DailyTotals();
return ds.getDailyTotalsForAllDevices(day); return ds.getDailyTotalsForAllDevices(day);
@ -114,10 +114,10 @@ public class Widget extends AppWidgetProvider {
} }
int[] DailyTotals = getSteps(); long[] dailyTotals = getSteps();
views.setTextViewText(R.id.todaywidget_steps, context.getString(R.string.widget_steps_label, (int) DailyTotals[0])); views.setTextViewText(R.id.todaywidget_steps, context.getString(R.string.widget_steps_label, dailyTotals[0]));
views.setTextViewText(R.id.todaywidget_sleep, context.getString(R.string.widget_sleep_label, getHM((long) DailyTotals[1]))); views.setTextViewText(R.id.todaywidget_sleep, context.getString(R.string.widget_sleep_label, getHM((dailyTotals[1])));
if (device != null) { if (device != null) {
String status = String.format("%1s", device.getStateString()); String status = String.format("%1s", device.getStateString());

View File

@ -40,11 +40,11 @@ public class DailyTotals {
private static final Logger LOG = LoggerFactory.getLogger(DailyTotals.class); private static final Logger LOG = LoggerFactory.getLogger(DailyTotals.class);
public int[] getDailyTotalsForAllDevices(Calendar day) { public long[] getDailyTotalsForAllDevices(Calendar day) {
Context context = GBApplication.getContext(); Context context = GBApplication.getContext();
//get today's steps for all devices in GB //get today's steps for all devices in GB
int all_steps = 0; long all_steps = 0;
int all_sleep = 0; long all_sleep = 0;
if (context instanceof GBApplication) { if (context instanceof GBApplication) {
@ -55,18 +55,18 @@ public class DailyTotals {
if (!coordinator.supportsActivityDataFetching()) { if (!coordinator.supportsActivityDataFetching()) {
continue; continue;
} }
int[] all_daily = getDailyTotalsForDevice(device, day); long[] all_daily = getDailyTotalsForDevice(device, day);
all_steps += all_daily[0]; all_steps += all_daily[0];
all_sleep += all_daily[1] + all_daily[2]; all_sleep += all_daily[1] + all_daily[2];
} }
} }
LOG.debug("gbwidget daily totals, all steps:" + all_steps); LOG.debug("gbwidget daily totals, all steps:" + all_steps);
LOG.debug("gbwidget daily totals, all sleep:" + all_sleep); LOG.debug("gbwidget daily totals, all sleep:" + all_sleep);
return new int[]{all_steps, all_sleep}; return new long[]{all_steps, all_sleep};
} }
public int[] getDailyTotalsForDevice(GBDevice device, Calendar day) { public long[] getDailyTotalsForDevice(GBDevice device, Calendar day) {
try (DBHandler handler = GBApplication.acquireDB()) { try (DBHandler handler = GBApplication.acquireDB()) {
ActivityAnalysis analysis = new ActivityAnalysis(); ActivityAnalysis analysis = new ActivityAnalysis();
@ -76,19 +76,19 @@ public class DailyTotals {
amountsSteps = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, 0, device)); amountsSteps = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, 0, device));
amountsSleep = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, -12, device)); amountsSleep = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, -12, device));
int[] Sleep = getTotalsSleepForActivityAmounts(amountsSleep); long[] sleep = getTotalsSleepForActivityAmounts(amountsSleep);
int Steps = getTotalsStepsForActivityAmounts(amountsSteps); long steps = getTotalsStepsForActivityAmounts(amountsSteps);
return new int[]{Steps, Sleep[0], Sleep[1]}; return new long[]{steps, sleep[0], sleep[1]};
} catch (Exception e) { } catch (Exception e) {
GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, e); GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, e);
return new int[]{0, 0, 0}; return new long[]{0, 0, 0};
} }
} }
private int[] getTotalsSleepForActivityAmounts(ActivityAmounts activityAmounts) { private long[] getTotalsSleepForActivityAmounts(ActivityAmounts activityAmounts) {
long totalSecondsDeepSleep = 0; long totalSecondsDeepSleep = 0;
long totalSecondsLightSleep = 0; long totalSecondsLightSleep = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) { for (ActivityAmount amount : activityAmounts.getAmounts()) {
@ -98,14 +98,14 @@ public class DailyTotals {
totalSecondsLightSleep += amount.getTotalSeconds(); totalSecondsLightSleep += amount.getTotalSeconds();
} }
} }
int totalMinutesDeepSleep = (int) (totalSecondsDeepSleep / 60); long totalMinutesDeepSleep = (totalSecondsDeepSleep / 60);
int totalMinutesLightSleep = (int) (totalSecondsLightSleep / 60); long totalMinutesLightSleep = (totalSecondsLightSleep / 60);
return new int[]{totalMinutesDeepSleep, totalMinutesLightSleep}; return new long[]{totalMinutesDeepSleep, totalMinutesLightSleep};
} }
private int getTotalsStepsForActivityAmounts(ActivityAmounts activityAmounts) { private long getTotalsStepsForActivityAmounts(ActivityAmounts activityAmounts) {
int totalSteps = 0; long totalSteps = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) { for (ActivityAmount amount : activityAmounts.getAmounts()) {
totalSteps += amount.getTotalSteps(); totalSteps += amount.getTotalSteps();

View File

@ -30,11 +30,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceIoThread;
public class CasioHandlerThread extends GBDeviceIoThread { public class CasioHandlerThread extends GBDeviceIoThread {
private static final Logger LOG = LoggerFactory.getLogger(CasioHandlerThread.class); private static final Logger LOG = LoggerFactory.getLogger(CasioHandlerThread.class);
private static final int TX_PERIOD = 60;
private boolean mQuit = false; private boolean mQuit = false;
private CasioGB6900DeviceSupport mDeviceSupport; private CasioGB6900DeviceSupport mDeviceSupport;
private final Object waitObject = new Object(); private final Object waitObject = new Object();
private int TX_PERIOD = 60;
private Calendar mTxTime = GregorianCalendar.getInstance(); private Calendar mTxTime = GregorianCalendar.getInstance();