Search in sources :

Example 21 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip-plus by jamorham.

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 22 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip-plus by jamorham.

the class AlertType method toSettings.

// Convert all settings to a string and save it in the references. This is needed to allow it's backup.
public static boolean toSettings(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    List<AlertType> alerts = new Select().from(AlertType.class).execute();
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
    String output = gson.toJson(alerts);
    Log.e(TAG, "Created the string " + output);
    prefs.edit().putString("saved_alerts", output).commit();
    return true;
}
Also used : DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) SharedPreferences(android.content.SharedPreferences) GsonBuilder(com.google.gson.GsonBuilder) Select(com.activeandroid.query.Select) Gson(com.google.gson.Gson)

Example 23 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip-plus by jamorham.

the class WatchUpdaterService method syncStepSensorData.

private synchronized void syncStepSensorData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncStepSensorData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    Log.d(TAG, "syncStepSensorData add to Table");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        StepCounter pm = StepCounter.last();
        Log.d(TAG, "syncStepSensorData add Table entries count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncStepSensorData add Table entry=" + entry);
                String record = entry.getString("entry");
                if (record != null) {
                    Log.d(TAG, "syncStepSensorData add Table record=" + record);
                    StepCounter data = gson.fromJson(record, StepCounter.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        Log.d(TAG, "syncStepSensorData add Entry Wear=" + data.toString());
                        Log.d(TAG, "syncStepSensorData WATCH data.metric=" + data.metric + " timestamp=" + JoH.dateTimeText((long) data.timestamp));
                        if (!bBenchmark)
                            data.saveit();
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "STEP", -1);
    }
}
Also used : StepCounter(com.eveningoutpost.dexdrip.Models.StepCounter) 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 24 with DateTypeAdapter

use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip-plus by jamorham.

the class NewCalibration method sensorAndCalibrationsToJson.

private static String sensorAndCalibrationsToJson(Sensor sensor, int limit) {
    SensorCalibrations[] sensorCalibrations = new SensorCalibrations[1];
    sensorCalibrations[0] = new SensorCalibrations();
    sensorCalibrations[0].sensor = sensor;
    sensorCalibrations[0].calibrations = Calibration.getCalibrationsForSensor(sensor, limit);
    if (d)
        Log.d(TAG, "calibrations size " + sensorCalibrations[0].calibrations.size());
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
    String output = gson.toJson(sensorCalibrations);
    if (d)
        Log.d(TAG, "sensorAndCalibrationsToJson created the string " + output);
    return output;
}
Also used : DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)24 GsonBuilder (com.google.gson.GsonBuilder)24 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)24 DataMap (com.google.android.gms.wearable.DataMap)16 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)6 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)4 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)4 SharedPreferences (android.content.SharedPreferences)2 Select (com.activeandroid.query.Select)2 AlertType (com.eveningoutpost.dexdrip.Models.AlertType)2 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)2 StepCounter (com.eveningoutpost.dexdrip.Models.StepCounter)2 TransmitterData (com.eveningoutpost.dexdrip.Models.TransmitterData)2 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)2 UserError (com.eveningoutpost.dexdrip.Models.UserError)2