Search in sources :

Example 96 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method sendActiveBtDeviceData.

private void sendActiveBtDeviceData() {
    // KS
    if (is_using_bt) {
        // only required for Collector running on watch
        forceGoogleApiConnect();
        ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice != null) {
            if (wear_integration) {
                DataMap dataMap = new DataMap();
                Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected);
                // MOST IMPORTANT LINE FOR TIMESTAMP
                dataMap.putLong("time", new Date().getTime());
                dataMap.putString("name", btDevice.name);
                dataMap.putString("address", btDevice.address);
                dataMap.putBoolean("connected", btDevice.connected);
                new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
            }
        }
    } else {
        Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt");
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Example 97 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method sendWearBloodTestData.

public static boolean sendWearBloodTestData(Integer count, long startTime, List<BloodTest> list) {
    // DataMap
    try {
        if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
            googleApiClient.connect();
        }
        if (googleApiClient != null) {
            BloodTest last = list != null && list.size() > 0 ? list.get(0) : BloodTest.last();
            if (last != null) {
                Log.d(TAG, "sendWearBloodTestData last.timestamp:" + JoH.dateTimeText(last.timestamp));
            } else {
                Log.d(TAG, "sendWearBloodTestData no BloodTest exist");
                return true;
            }
            List<BloodTest> graph;
            if (list != null)
                graph = list;
            else if (startTime == 0)
                graph = BloodTest.last(count);
            else
                graph = BloodTest.latestForGraph(count, startTime);
            if (!graph.isEmpty()) {
                Log.d(TAG, "sendWearBloodTestData graph size=" + graph.size());
                final ArrayList<DataMap> dataMaps = new ArrayList<>(graph.size());
                DataMap entries = dataMap(last);
                for (BloodTest data : graph) {
                    dataMaps.add(dataMap(data));
                }
                Log.d(TAG, "sendWearBloodTestData entries=" + entries);
                // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putLong("time", new Date().getTime());
                entries.putDataMapArrayList("entries", dataMaps);
                new SendToDataLayerThread(WEARABLE_BLOODTEST_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
            } else
                Log.d(TAG, "sendWearBloodTestData BloodTest count = 0");
        } else {
            Log.e(TAG, "sendWearBloodTestData No connection to wearable available for send BloodTest!");
            return false;
        }
    } catch (NullPointerException e) {
        Log.e(TAG, "Nullpointer exception in sendWearBloodTestData: " + e);
        return false;
    }
    return true;
}
Also used : BloodTest(com.eveningoutpost.dexdrip.Models.BloodTest) ArrayList(java.util.ArrayList) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Example 98 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method dataMap.

private static DataMap dataMap(BgReading bg) {
    // KS
    DataMap dataMap = new DataMap();
    // KS Fix for calibration_uuid not being set in Calibration.create which updates bgReading to new calibration ln 497
    // if (bg.calibration_flag == true) {
    // bg.calibration_uuid = bg.calibration.uuid;
    // }
    dataMap.putString("calibrationUuid", bg.calibration.uuid);
    String json = bg.toS();
    Log.d(TAG, "dataMap BG GSON: " + json);
    dataMap.putString("bgs", json);
    return dataMap;
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 99 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method dataMap.

private DataMap dataMap(AlertType alert, String type) {
    // KS
    DataMap dataMap = new DataMap();
    String json = alert.toS();
    Log.d(TAG, "dataMap BG GSON: " + json);
    dataMap.putString(type, json);
    return dataMap;
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 100 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method resendData.

private void resendData() {
    Log.d(TAG, "resendData ENTER");
    forceGoogleApiConnect();
    Log.d(TAG, "resendData googleApiClient connected ENTER");
    long startTime = new Date().getTime() - (60000 * 60 * 24);
    BgReading last_bg = BgReading.last();
    if (last_bg != null) {
        List<BgReading> graph_bgs = BgReading.latestForGraph(60, startTime);
        BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getApplicationContext());
        if (!graph_bgs.isEmpty()) {
            final int battery = PowerStateReceiver.getBatteryLevel(getApplicationContext());
            DataMap entries = dataMap(last_bg, mPrefs, bgGraphBuilder, battery);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
            for (BgReading bg : graph_bgs) {
                dataMaps.add(dataMap(bg, mPrefs, bgGraphBuilder, battery));
            }
            // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putLong("time", new Date().getTime());
            entries.putDataMapArrayList("entries", dataMaps);
            if (mPrefs.getBoolean("extra_status_line", false)) {
                entries.putString("extra_status_line", Home.extraStatusLine());
            }
            new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Date(java.util.Date) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder) 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