Search in sources :

Example 91 with DataMap

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

the class ListenerService method syncBloodTestData.

private synchronized void syncBloodTestData(DataMap dataMap, Context context) {
    // KS
    Log.d(TAG, "syncBloodTestData");
    boolean changed = false;
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        Log.d(TAG, "syncBloodTestData add BloodTest Table entries count=" + entries.size());
        // ensure database has already been initialized
        Sensor.InitDb(context);
        for (DataMap entry : entries) {
            if (entry != null) {
                String record = entry.getString("data");
                if (record != null) {
                    BloodTest data = gson.fromJson(record, BloodTest.class);
                    BloodTest exists = BloodTest.byUUID(data.uuid);
                    if (exists != null) {
                        Log.d(TAG, "syncBloodTestData save existing BloodTest for uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " mgdl=" + data.mgdl + " state=" + data.state);
                        if (exists.mgdl != data.mgdl || exists.state != data.state || exists.timestamp != data.timestamp) {
                            // state indicates if deleted
                            changed = true;
                        }
                        exists.mgdl = data.mgdl;
                        exists.created_timestamp = data.created_timestamp;
                        exists.source = data.source;
                        exists.state = data.state;
                        exists.timestamp = data.timestamp;
                        exists.save();
                    } else {
                        changed = true;
                        data.save();
                        Log.d(TAG, "syncBloodTestData create new BloodTest for uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " mgdl=" + data.mgdl + " state=" + data.state);
                    }
                }
            }
        }
        if (changed) {
            showTreatments(context, "bts");
        }
    }
}
Also used : DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) BloodTest(com.eveningoutpost.dexdrip.Models.BloodTest) Gson(com.google.gson.Gson) DataMap(com.google.android.gms.wearable.DataMap)

Example 92 with DataMap

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

the class ListenerService method syncAlertTypeData.

private void syncAlertTypeData(DataMap dataMap, Context context) {
    // KS
    Log.d(TAG, "syncAlertTypeData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        Log.d(TAG, "syncAlertTypeData add AlertType Table entries count=" + entries.size());
        // ensure database has already been initialized
        Sensor.InitDb(context);
        AlertType.remove_all();
        for (DataMap entry : entries) {
            if (entry != null) {
                String alertrecord = entry.getString("alert");
                if (alertrecord != null) {
                    AlertType data = gson.fromJson(alertrecord, AlertType.class);
                    AlertType exists = AlertType.get_alert(data.uuid);
                    if (exists != null) {
                        Log.d(TAG, "syncAlertTypeData AlertType exists for uuid=" + data.uuid + " name=" + data.name);
                        exists.name = data.name;
                        exists.active = data.active;
                        exists.volume = data.volume;
                        exists.vibrate = data.vibrate;
                        exists.light = data.light;
                        exists.override_silent_mode = data.override_silent_mode;
                        exists.predictive = data.predictive;
                        exists.time_until_threshold_crossed = data.time_until_threshold_crossed;
                        exists.above = data.above;
                        exists.threshold = data.threshold;
                        exists.all_day = data.all_day;
                        exists.start_time_minutes = data.start_time_minutes;
                        exists.end_time_minutes = data.end_time_minutes;
                        exists.minutes_between = data.minutes_between;
                        exists.default_snooze = data.default_snooze;
                        exists.text = data.text;
                        exists.mp3_file = data.mp3_file;
                        exists.save();
                    } else {
                        data.save();
                        Log.d(TAG, "syncAlertTypeData AlertType does not exist for uuid=" + data.uuid);
                    }
                    exists = AlertType.get_alert(data.uuid);
                    if (exists != null)
                        Log.d(TAG, "syncAlertTypeData AlertType GSON saved BG: " + exists.toS());
                    else
                        Log.d(TAG, "syncAlertTypeData AlertType GSON NOT saved");
                }
            }
        }
    }
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) DataMap(com.google.android.gms.wearable.DataMap)

Example 93 with DataMap

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

the class ListenerService method sendTreatment.

public static synchronized void sendTreatment(String notes) {
    Log.d(TAG, "sendTreatment WEARABLE_TREATMENT_PAYLOAD notes=" + notes);
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", System.currentTimeMillis());
    dataMap.putBoolean("watchkeypad", true);
    dataMap.putString("notes", notes);
    dataMap.putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext())));
    Intent intent = new Intent(xdrip.getAppContext(), Simulation.class);
    intent.putExtra(WEARABLE_TREATMENT_PAYLOAD, dataMap.toBundle());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    xdrip.getAppContext().startActivity(intent);
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) DataMap(com.google.android.gms.wearable.DataMap)

Example 94 with DataMap

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

the class ListenerService method overrideLocale.

public boolean overrideLocale(DataMap dataMap) {
    if (mPrefs.getBoolean("overrideLocale", false)) {
        String localeStr = dataMap.getString("locale", "");
        String[] locale = localeStr.split("_");
        final Locale newLocale = locale == null ? new Locale(localeStr) : locale.length > 1 ? new Locale(locale[0], locale[1]) : new Locale(locale[0]);
        final Locale oldLocale = Locale.getDefault();
        if (newLocale != null && !oldLocale.equals(newLocale)) {
            try {
                Log.d(TAG, "overrideLocale locale from " + oldLocale + " to " + newLocale);
                Context context = getApplicationContext();
                final Resources resources = context.getResources();
                final DisplayMetrics metrics = resources.getDisplayMetrics();
                final Configuration config = resources.getConfiguration();
                config.locale = newLocale;
                resources.updateConfiguration(config, metrics);
                Locale.setDefault(newLocale);
                Log.d(TAG, "overrideLocale default locale " + Locale.getDefault() + " resource locale " + context.getResources().getConfiguration().locale);
                DataMap dm = new DataMap();
                dm.putString("locale", localeStr);
                sendLocalMessage("locale", dm);
                return true;
            } catch (Exception e) {
                Log.e(TAG, "overrideLocale Exception e: " + e);
            }
        }
    }
    return false;
}
Also used : Locale(java.util.Locale) Context(android.content.Context) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics) DataMap(com.google.android.gms.wearable.DataMap)

Example 95 with DataMap

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

the class WatchUpdaterService method syncTransmitterData.

private synchronized void syncTransmitterData(DataMap dataMap, boolean bBenchmark) {
    // KS
    Log.d(TAG, "syncTransmitterData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastBG = 0;
    Log.d(TAG, "syncTransmitterData add BgReading Table");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        int idx = 0;
        int count = entries.size();
        Log.d(TAG, "syncTransmitterData add BgReading Table entries count=" + count);
        for (DataMap entry : entries) {
            if (entry != null) {
                // Log.d(TAG, "syncTransmitterData add BgReading Table entry=" + entry);
                idx++;
                String bgrecord = entry.getString("bgs");
                if (bgrecord != null) {
                    // for (TransmitterData bgData : bgs) {
                    // Log.d(TAG, "syncTransmitterData add TransmitterData Table bgrecord=" + bgrecord);
                    TransmitterData bgData = gson.fromJson(bgrecord, TransmitterData.class);
                    // TransmitterData bgData = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(bgrecord, TransmitterData.class);
                    TransmitterData exists = TransmitterData.getForTimestamp(bgData.timestamp);
                    TransmitterData uuidexists = TransmitterData.findByUuid(bgData.uuid);
                    timeOfLastBG = bgData.timestamp + 1;
                    if (exists != null || uuidexists != null) {
                        Log.d(TAG, "syncTransmitterData BG already exists for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                    } else {
                        Log.d(TAG, "syncTransmitterData add BG; does NOT exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                        if (!bBenchmark) {
                            bgData.save();
                            // Check
                            if (TransmitterData.findByUuid(bgData.uuid) != null)
                                Log.d(TAG, "syncTransmitterData: TransmitterData was saved for uuid:" + bgData.uuid);
                            else {
                                Log.e(TAG, "syncTransmitterData: TransmitterData was NOT saved for uuid:" + bgData.uuid);
                                return;
                            }
                            // KS the following is from G5CollectionService processNewTransmitterData()
                            Sensor sensor = Sensor.currentSensor();
                            if (sensor == null) {
                                Log.e(TAG, "syncTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
                                return;
                            }
                            // TODO : LOG if unfiltered or filtered values are zero
                            Sensor.updateBatteryLevel(sensor, bgData.sensor_battery_level);
                            // android.util.Log.i
                            Log.i(TAG, "syncTransmitterData: BG timestamp create " + Long.toString(bgData.timestamp));
                            BgReading bgExists;
                            // KS TODO wear implements limited alerts, therefore continue to process all alerts on phone for last entry
                            if (count > 1 && idx < count) {
                                // Disable Notifications for bulk insert
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp, true);
                            } else {
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp);
                            }
                            if (bgExists != null)
                                Log.d(TAG, "syncTransmitterData BG GSON saved BG: " + bgExists.toS());
                            else
                                Log.e(TAG, "syncTransmitterData BG GSON NOT saved");
                        }
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_BGS count=" + entries.size(), timeOfLastBG, bBenchmark ? "BM" : "BG", -1);
    }
}
Also used : TransmitterData(com.eveningoutpost.dexdrip.Models.TransmitterData) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) DataMap(com.google.android.gms.wearable.DataMap) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

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