use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.
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;
}
use of com.google.gson.internal.bind.DateTypeAdapter 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);
}
}
use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.
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;
}
use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip by NightscoutFoundation.
the class NewCalibration method newCalibrationToJson.
private static String newCalibrationToJson(double bgValue, String uuid, long offset) {
NewCalibration[] newCalibrationArray = new NewCalibration[1];
NewCalibration newCalibration = new NewCalibration();
newCalibration.bgValue = bgValue;
newCalibration.uuid = uuid;
newCalibration.timestamp = JoH.tsl();
newCalibration.offset = offset;
newCalibrationArray[0] = newCalibration;
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
String output = gson.toJson(newCalibrationArray);
Log.d(TAG, "newCalibrationToJson Created the string " + output);
return output;
}
use of com.google.gson.internal.bind.DateTypeAdapter in project xDrip-plus by jamorham.
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");
}
}
}
Aggregations