use of nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample in project Gadgetbridge by Freeyourgadget.
the class PineTimeJFSupport method onReceiveStepsSample.
private void onReceiveStepsSample(int timeStamp, int steps) {
PineTimeActivitySample sample = new PineTimeActivitySample();
int dayStepCount = this.getStepsOnDay(timeStamp);
int diff = steps - dayStepCount;
if (diff > 0) {
LOG.debug("adding " + diff + " steps");
sample.setSteps(diff);
sample.setTimestamp(timeStamp);
// since it's a local timestamp, it should NOT be treated as Activity because it will spoil activity charts
sample.setRawKind(ActivityKind.TYPE_UNKNOWN);
this.addGBActivitySample(sample);
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES).putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample).putExtra(DeviceService.EXTRA_TIMESTAMP, sample.getTimestamp());
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
}
}
use of nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample in project Gadgetbridge by Freeyourgadget.
the class PineTimeJFSupport method getStepsOnDay.
/**
* @param timeStamp Time stamp (in seconds) at some point during the requested day.
*/
private int getStepsOnDay(int timeStamp) {
try (DBHandler dbHandler = GBApplication.acquireDB()) {
Calendar dayStart = new GregorianCalendar();
Calendar dayEnd = new GregorianCalendar();
this.getDayStartEnd(timeStamp, dayStart, dayEnd);
PineTimeActivitySampleProvider provider = new PineTimeActivitySampleProvider(this.getDevice(), dbHandler.getDaoSession());
List<PineTimeActivitySample> samples = provider.getAllActivitySamples((int) (dayStart.getTimeInMillis() / 1000L), (int) (dayEnd.getTimeInMillis() / 1000L));
int totalSteps = 0;
for (PineTimeActivitySample sample : samples) {
totalSteps += sample.getSteps();
}
return totalSteps;
} catch (Exception ex) {
LOG.error(ex.getMessage());
return 0;
}
}
use of nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample in project Gadgetbridge by Freeyourgadget.
the class PineTimeJFSupport method addGBActivitySamples.
private void addGBActivitySamples(PineTimeActivitySample[] samples) {
try (DBHandler dbHandler = GBApplication.acquireDB()) {
User user = DBHelper.getUser(dbHandler.getDaoSession());
Device device = DBHelper.getDevice(this.getDevice(), dbHandler.getDaoSession());
PineTimeActivitySampleProvider provider = new PineTimeActivitySampleProvider(this.getDevice(), dbHandler.getDaoSession());
for (PineTimeActivitySample sample : samples) {
sample.setDevice(device);
sample.setUser(user);
sample.setProvider(provider);
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
provider.addGBActivitySample(sample);
}
} catch (Exception ex) {
GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
LOG.error(ex.getMessage());
}
}
Aggregations