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");
}
}
}
}
}
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;
}
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);
}
}
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;
}
Aggregations