Java Code Examples for com.google.gson.internal.bind.DateTypeAdapter

The following examples show how to use com.google.gson.internal.bind.DateTypeAdapter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xDrip   Source File: AlertType.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;

}
 
Example 2
Source Project: xDrip   Source File: AlertType.java    License: GNU General Public License v3.0 6 votes vote down vote up
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(); // always leave this as commit

    return true;

}
 
Example 3
Source Project: xDrip   Source File: GcmActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 4
Source Project: xDrip   Source File: GcmActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 5
Source Project: xDrip-plus   Source File: AlertType.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;

}
 
Example 6
Source Project: xDrip-plus   Source File: AlertType.java    License: GNU General Public License v3.0 6 votes vote down vote up
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(); // always leave this as commit

    return true;

}
 
Example 7
Source Project: xDrip-plus   Source File: GcmActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 8
Source Project: xDrip-plus   Source File: GcmActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 9
Source Project: xDrip-Experimental   Source File: AlertType.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;

}
 
Example 10
Source Project: chuck   Source File: JsonConvertor.java    License: Apache License 2.0 5 votes vote down vote up
public static Gson getInstance() {
    if (gson == null) {
        gson = new GsonBuilder()
                .setPrettyPrinting()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .registerTypeAdapter(Date.class, new DateTypeAdapter())
                .create();
    }
    return gson;
}
 
Example 11
Source Project: xDrip   Source File: UserError.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();

    return gson.toJson(this);
}
 
Example 12
Source Project: xDrip   Source File: Calibration.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 13
Source Project: xDrip   Source File: Sensor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {//KS
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    Log.d("SENSOR", "Sensor toS uuid=" + this.uuid + " started_at=" + this.started_at + " active=" + this.isActive() + " battery=" + this.latest_battery_level + " location=" + this.sensor_location + " stopped_at=" + this.stopped_at);
    return gson.toJson(this);
}
 
Example 14
Source Project: xDrip   Source File: AlertType.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 15
Source Project: xDrip   Source File: TransmitterData.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {//KS
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();

    return gson.toJson(this);
}
 
Example 16
Source Project: xDrip   Source File: BgReading.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 17
Source Project: xDrip   Source File: Calibration.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 18
Source Project: xDrip   Source File: Treatments.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 19
Source Project: xDrip   Source File: Sensor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {//KS
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    Log.d("SENSOR", "Sensor toS uuid=" + this.uuid + " started_at=" + this.started_at + " active=" + this.isActive() + " battery=" + this.latest_battery_level + " location=" + this.sensor_location + " stopped_at=" + this.stopped_at);
    return gson.toJson(this);
}
 
Example 20
Source Project: xDrip   Source File: AlertType.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 21
Source Project: xDrip   Source File: BgReading.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 22
Source Project: xDrip   Source File: WatchUpdaterService.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 23
Source Project: xDrip-plus   Source File: UserError.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();

    return gson.toJson(this);
}
 
Example 24
Source Project: xDrip-plus   Source File: Calibration.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 25
Source Project: xDrip-plus   Source File: Sensor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {//KS
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    Log.d("SENSOR", "Sensor toS uuid=" + this.uuid + " started_at=" + this.started_at + " active=" + this.isActive() + " battery=" + this.latest_battery_level + " location=" + this.sensor_location + " stopped_at=" + this.stopped_at);
    return gson.toJson(this);
}
 
Example 26
Source Project: xDrip-plus   Source File: AlertType.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 27
Source Project: xDrip-plus   Source File: TransmitterData.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {//KS
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();

    return gson.toJson(this);
}
 
Example 28
Source Project: xDrip-plus   Source File: BgReading.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 29
Source Project: xDrip-plus   Source File: Calibration.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}
 
Example 30
Source Project: xDrip-plus   Source File: Treatments.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String toS() {
    Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new DateTypeAdapter())
            .serializeSpecialFloatingPointValues()
            .create();
    return gson.toJson(this);
}