Search in sources :

Example 1 with PineTimeActivitySample

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);
    }
}
Also used : Intent(android.content.Intent) PineTimeActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample)

Example 2 with PineTimeActivitySample

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;
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) PineTimeActivitySampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) PineTimeActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample)

Example 3 with PineTimeActivitySample

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());
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) PineTimeActivitySampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider) User(nodomain.freeyourgadget.gadgetbridge.entities.User) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) PineTimeActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample)

Aggregations

PineTimeActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample)3 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)2 PineTimeActivitySampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider)2 Intent (android.content.Intent)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1