Search in sources :

Example 71 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class BaseWatchFace method addToWatchSetTreats.

public void addToWatchSetTreats(DataMap dataMap, ArrayList<BgWatchData> dataList) {
    if (d)
        Log.d(TAG, "addToWatchSetTreats dataList.size()=" + (dataList != null ? dataList.size() : "0"));
    // necessary since treatments, bloodtest and calibrations can be deleted/invalidated
    dataList.clear();
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    if (entries != null) {
        if (d)
            Log.d(TAG, "addToWatchSetTreats entries.size()=" + entries.size() + " entries=" + entries);
        for (DataMap entry : entries) {
            addDataMapTreats(entry, dataList);
        }
    }
    if (d)
        Log.d(TAG, "addToWatchSetTreats dataList.size()=" + dataList.size());
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 72 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class CircleWatchface method addToWatchSet.

public void addToWatchSet(DataMap dataMap) {
    Log.d(TAG, "addToWatchSet bgDataList.size()=" + bgDataList.size());
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    if (entries != null) {
        Log.d(TAG, "addToWatchSet entries.size()=" + entries.size());
        for (DataMap entry : entries) {
            addDataMap(entry);
        }
    } else {
        addDataMap(dataMap);
    }
    for (int i = 0; i < bgDataList.size(); i++) {
        if (bgDataList.get(i).timestamp < (new Date().getTime() - (1000 * 60 * 60 * 5))) {
            // Get rid of anything more than 5 hours old
            bgDataList.remove(i);
            break;
        }
    }
    Collections.sort(bgDataList);
}
Also used : Point(android.graphics.Point) Paint(android.graphics.Paint) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Example 73 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class HeartRateService method dataMap.

// this is pretty inefficient - maybe eventually replace with protobuf
private static DataMap dataMap(HeartRate log) {
    final DataMap dataMap = new DataMap();
    final String json = log.toS();
    dataMap.putString("entry", json);
    return dataMap;
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 74 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class HeartRateService method getWearHeartSensorData.

public static synchronized DataMap getWearHeartSensorData(int count, long last_send_time, int min_count) {
    UserError.Log.d(TAG, "getWearHeartSensorData last_send_time:" + JoH.dateTimeText(last_send_time));
    if ((count != 0) || (JoH.ratelimit("heartrate-datamap", 5))) {
        HeartRate last_log = HeartRate.last();
        if (last_log != null) {
            UserError.Log.d(TAG, "getWearHeartSensorData last_log.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
        } else {
            UserError.Log.d(TAG, "getWearHeartSensorData HeartRate.last() = null:");
            return null;
        }
        if (last_log != null && last_send_time <= last_log.timestamp) {
            // startTime
            long last_send_success = last_send_time;
            UserError.Log.d(TAG, "getWearHeartSensorData last_send_time < last_bg.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
            List<HeartRate> logs = HeartRate.latestForGraph(count, last_send_time);
            if (!logs.isEmpty() && logs.size() > min_count) {
                DataMap entries = dataMap(last_log);
                final ArrayList<DataMap> dataMaps = new ArrayList<>(logs.size());
                for (HeartRate log : logs) {
                    dataMaps.add(dataMap(log));
                    last_send_success = (long) log.timestamp;
                }
                // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putLong("time", JoH.tsl());
                entries.putDataMapArrayList("entries", dataMaps);
                UserError.Log.i(TAG, "getWearHeartSensorData SYNCED up to " + JoH.dateTimeText(last_send_success) + " count = " + logs.size());
                return entries;
            } else
                UserError.Log.i(TAG, "getWearHeartSensorData SYNCED up to " + JoH.dateTimeText(last_send_success) + " count = 0");
        }
        return null;
    } else {
        UserError.Log.d(TAG, "Ratelimitted getWearHeartSensorData");
        return null;
    }
}
Also used : HeartRate(com.eveningoutpost.dexdrip.Models.HeartRate) ArrayList(java.util.ArrayList) DataMap(com.google.android.gms.wearable.DataMap)

Example 75 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class Simulation method Approve.

public void Approve(View myview) {
    if (watchkeypad) {
        // Treatments.create(carbs, insulin, thisnotes, new Date().getTime());
        DataMap dataMap = new DataMap();
        dataMap.putDouble("timeoffset", timeoffset);
        dataMap.putDouble("carbs", carbs);
        dataMap.putDouble("insulin", insulin);
        dataMap.putDouble("bloodtest", bloodtest);
        dataMap.putString("notes", thisnotes);
        // dataMap.putLong("timestamp", System.currentTimeMillis());
        ListenerService.createTreatment(dataMap, this);
    } else
        SendData(this, WEARABLE_APPROVE_TREATMENT, null);
    finish();
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Aggregations

DataMap (com.google.android.gms.wearable.DataMap)147 Date (java.util.Date)38 ArrayList (java.util.ArrayList)36 Gson (com.google.gson.Gson)18 Intent (android.content.Intent)17 GsonBuilder (com.google.gson.GsonBuilder)16 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)16 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)12 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)12 PendingIntent (android.app.PendingIntent)11 Context (android.content.Context)8 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)8 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)8 Bundle (android.os.Bundle)6 HeartRate (com.eveningoutpost.dexdrip.Models.HeartRate)6 Paint (android.graphics.Paint)5 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)5 BroadcastReceiver (android.content.BroadcastReceiver)4 SharedPreferences (android.content.SharedPreferences)4 Point (android.graphics.Point)4