Java Code Examples for com.google.android.gms.wearable.DataMap#getDataMapArrayList()

The following examples show how to use com.google.android.gms.wearable.DataMap#getDataMapArrayList() . 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 File: BaseWatchFace.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addToWatchSet(DataMap dataMap) {

        Log.d(TAG, "addToWatchSet bgDataList.size()=" + bgDataList.size());

        ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
        if (entries != null) {
            Log.d(TAG, "addToWatchSet entries.size()=" + entries.size());
            for (DataMap entry : entries) {
                addDataMap(entry);
            }
        } else {
            addDataMap(dataMap);
        }

        for (int i = 0; i < bgDataList.size(); i++) {
            if (bgDataList.get(i).timestamp < (new Date().getTime() - (1000 * 60 * 60 * 5))) {
                Log.d(TAG, "addToWatchSet Remove bgDataList.get(i).timestamp: " + JoH.dateTimeText((long)bgDataList.get(i).timestamp)+ " i: " + i);
                bgDataList.remove(i); //Get rid of anything more than 5 hours old
            }
        }
    }
 
Example 2
Source File: BaseWatchFace.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void addToWatchSetTreats(DataMap dataMap, ArrayList<BgWatchData> dataList) {

        if (d) Log.d(TAG, "addToWatchSetTreats dataList.size()=" + (dataList != null ? dataList.size() : "0"));
        dataList.clear();//necessary since treatments, bloodtest and calibrations can be deleted/invalidated
        ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
        if (entries != null) {
            if (d) Log.d(TAG, "addToWatchSetTreats entries.size()=" + entries.size() + " entries=" + entries);
            for (DataMap entry : entries) {
                addDataMapTreats(entry, dataList);
            }
        }

        if (d) Log.d(TAG, "addToWatchSetTreats dataList.size()=" + dataList.size());
    }
 
Example 3
Source File: CircleWatchface.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "MyWakelockTag");
    wakeLock.acquire(30000);

    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    setSgvLevel((int) dataMap.getLong("sgvLevel"));
    Log.d("CircleWatchface", "sgv level : " + getSgvLevel());
    setSgvString(dataMap.getString("sgvString"));
    Log.d("CircleWatchface", "sgv string : " + getSgvString());
    setRawString(dataMap.getString("rawString"));
    setDelta(dataMap.getString("delta"));
    setDatetime(dataMap.getDouble("timestamp"));
    addToWatchSet(dataMap);


    //start animation?
    // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
    if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
        startAnimation();
    }

    prepareLayout();
    prepareDrawTime();
    invalidate();
    wakeLock.release();
}
 
Example 4
Source File: CircleWatchface.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "MyWakelockTag");
    wakeLock.acquire(30000);

    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    setSgvLevel((int) dataMap.getLong("sgvLevel"));
    Log.d("CircleWatchface", "sgv level : " + getSgvLevel());
    setSgvString(dataMap.getString("sgvString"));
    Log.d("CircleWatchface", "sgv string : " + getSgvString());
    setRawString(dataMap.getString("rawString"));
    setDelta(dataMap.getString("delta"));
    setDatetime(dataMap.getDouble("timestamp"));
    addToWatchSet(dataMap);


    //start animation?
    // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
    if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
        startAnimation();
    }

    prepareLayout();
    prepareDrawTime();
    invalidate();
    wakeLock.release();
}
 
Example 5
Source File: UartConfiguration.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public UartConfiguration(final DataMap dataMap, final long id) {
	name = dataMap.getString(Constants.UART.Configuration.NAME);

	final ArrayList<DataMap> maps = dataMap.getDataMapArrayList(Constants.UART.Configuration.COMMANDS);
	commands = new Command[maps.size()];
	for (int i = 0; i < maps.size(); ++i) {
		commands[i] = new Command(maps.get(i));
	}

	this.id = id;
}
 
Example 6
Source File: WatchUpdaterService.java    From xDrip with 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 7
Source File: CircleWatchface.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "MyWakelockTag");
    wakeLock.acquire(30000);
    Bundle bundle = intent.getBundleExtra("data");
    if (bundle!= null) {
        DataMap dataMap = DataMap.fromBundle(bundle);
        setSgvLevel((int) dataMap.getLong("sgvLevel"));
        Log.d("CircleWatchface", "sgv level : " + getSgvLevel());
        setSgvString(dataMap.getString("sgvString"));
        Log.d("CircleWatchface", "sgv string : " + getSgvString());
        setRawString(dataMap.getString("rawString"));
        setDelta(dataMap.getString("delta"));
        setDatetime(dataMap.getDouble("timestamp"));
        addToWatchSet(dataMap);


        //start animation?
        // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
        if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
            startAnimation();
        }

        prepareLayout();
        prepareDrawTime();
        invalidate();
    }
    wakeLock.release();
}
 
Example 8
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void syncTreatmentsData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncTreatmentsData");

    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    if (entries != null) {
        Log.d(TAG, "syncTreatmentsData count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncTreatmentsData entry=" + entry);
                String record = entry.getString("entry");
                if (record != null && record.length() > 1) {
                    Log.d(TAG, "Received wearable 2: voice payload: " + record);
                    long timestamp = entry.getLong("timestamp");
                    if (timestamp <= PersistentStore.getLong(LAST_RECORD_TIMESTAMP)) {
                        Log.e(TAG, "Ignoring repeated or older sync timestamp");
                        continue;
                    }
                    final long since = JoH.msSince(timestamp);
                    if ((since < -(Constants.SECOND_IN_MS * 5)) || (since > Constants.HOUR_IN_MS * 72)) {
                        JoH.static_toast_long("Rejecting wear treatment as time out of range!");
                        UserError.Log.e(TAG, "Rejecting wear treatment due to time: " + record + " since: " + since);
                    } else {
                        if (record.contains("uuid null")) {
                            Log.e(TAG, "Skipping xx uuid null record!");
                            continue;
                        }
                        receivedText(getApplicationContext(), record);
                        PersistentStore.setLong(LAST_RECORD_TIMESTAMP, timestamp);
                    }
                    Log.d(TAG, "syncTreatmentsData add Table record=" + record);
                    timeOfLastEntry = (long) timestamp + 1;
                    Log.d(TAG, "syncTreatmentsData WATCH treatments timestamp=" + JoH.dateTimeText(timestamp));
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "TREATMENTS", -1);
    }
}
 
Example 9
Source File: ListenerService.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
private void processCityList(DataMap data) {
    ArrayList<City> cities = new ArrayList<City>();
    ArrayList<DataMap> dataCities = data.getDataMapArrayList("cities");

    if (dataCities.size() > 0) {
        for (DataMap city : dataCities) {
            cities.add(new City(city.getLong("id"), city.getString("country"), city.getString("city")));
        }

        BusProvider.getInstance().post(new CitiesEvent(cities));
    } else {
        BusProvider.getInstance().post(new ErrorEvent(getString(R.string.error_zero_cities)));
    }

}
 
Example 10
Source File: CircleWatchface.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final PowerManager.WakeLock wl = JoH.getWakeLock("circle-message-receiver", 60000);
    try {
        DataMap dataMap;
        Bundle bundle = intent.getBundleExtra("msg");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            String msg = dataMap.getString("msg", "");
            int length = dataMap.getInt("length", 0);
            JoH.static_toast(xdrip.getAppContext(), msg, length);
        }
        bundle = intent.getBundleExtra("steps");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            if (mTimeStepsRcvd <= dataMap.getLong("steps_timestamp", 0)) {
                mStepsCount = dataMap.getInt("steps", 0);
                mTimeStepsRcvd = dataMap.getLong("steps_timestamp", 0);
            }
        }
        bundle = intent.getBundleExtra("data");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            setSgvLevel((int) dataMap.getLong("sgvLevel"));
            Log.d(TAG, "CircleWatchface sgv level : " + getSgvLevel());
            setSgvString(dataMap.getString("sgvString"));
            Log.d(TAG, "CircleWatchface sgv string : " + getSgvString());
            setRawString(dataMap.getString("rawString"));
            setDelta(dataMap.getString("delta"));
            setDatetime(dataMap.getDouble("timestamp"));
            mExtraStatusLine = dataMap.getString("extra_status_line");
            addToWatchSet(dataMap);


            //start animation?
            // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
            if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
                startAnimation();
            }

            prepareLayout();
            prepareDrawTime();
            invalidate();
        }
        //status
        bundle = intent.getBundleExtra("status");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            setStatusString(dataMap.getString("externalStatusString"));

            prepareLayout();
            prepareDrawTime();
            invalidate();
        }
    } finally {
        JoH.releaseWakeLock(wl);
    }
}
 
Example 11
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void syncLogData(DataMap dataMap, boolean bBenchmark) {//KS
    Log.d(TAG, "syncLogData");
    long watch_syncLogsRequested = dataMap.getLong("syncLogsRequested", -1);
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    int saved = 0;
    if (entries != null) {

        Gson gson = new GsonBuilder()
                .excludeFieldsWithoutExposeAnnotation()
                .registerTypeAdapter(Date.class, new DateTypeAdapter())
                .serializeSpecialFloatingPointValues()
                .create();

        Log.d(TAG, "syncLogData add Table entries count=" + entries.size() + " watch_syncLogsRequested=" + watch_syncLogsRequested);
        for (DataMap entry : entries) {
            if (entry != null) {
                String record = entry.getString("entry");
                if (record != null) {
                    UserError data = gson.fromJson(record, UserError.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        if (data.shortError != null && !data.shortError.isEmpty()) { //add wear prefix
                            if (!data.shortError.startsWith("wear")) {
                                data.shortError = mPrefs.getString("wear_logs_prefix", "wear") + data.shortError;
                            }
                        }
                        UserError exists = UserError.getForTimestamp(data);
                        if (exists == null && !bBenchmark) {
                            data.save();
                            saved++;
                        } else {
                            //Log.d(TAG, "syncLogData Log entry already exists with shortError=" + data.shortError + " timestamp=" + JoH.dateTimeText((long)data.timestamp));
                        }
                    }
                }
            }
        }
        if (saved > 0) {
            Log.d(TAG, "syncLogData Saved timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " saved=" + saved);
        } else {
            Log.d(TAG, "syncLogData No records saved due to being duplicates! timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " count=" + entries.size());
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "LOG", watch_syncLogsRequested);
    }
}
 
Example 12
Source File: BIGChart.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getBundleExtra("data");
    if (bundle ==null){
        return;
    }
    DataMap dataMap = DataMap.fromBundle(bundle);
    if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");
        rawString = dataMap.getString("rawString");
        sgvString = dataMap.getString("sgvString");
        batteryString = dataMap.getString("battery");
        mSgv.setText(dataMap.getString("sgvString"));

        if(ageLevel()<=0) {
            mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));

        showAgoRawBatt();

        String delta = dataMap.getString("delta");

        if (delta.endsWith(" mg/dl")) {
            mDelta.setText(delta.substring(0, delta.length() - 6));
        } else if (delta.endsWith(" mmol")) {
            mDelta.setText(delta.substring(0, delta.length() - 5));
        }

        if (chart != null) {
            addToWatchSet(dataMap);
            setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
                mRelativeLayout.getMeasuredHeight());
        invalidate();
        setColor();

        //start animation?
        // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
        if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5"))) {
            startAnimation();
        }


    } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
    }
}
 
Example 13
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void syncTreatmentsData(DataMap dataMap, Context context) {
    Log.d(TAG, "syncTreatmentsData");

    boolean changed = false;
    String action = dataMap.getString("action");
    if (action.equals("delete")) {
        Log.d(TAG, "syncTreatmentsData Delete Treatments");
        deleteTreatment(dataMap);
        showTreatments(context, "treats");
    }
    else {
        ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
        if (entries != null) {
            Gson gson = new GsonBuilder()
                        .excludeFieldsWithoutExposeAnnotation()
                        .registerTypeAdapter(Date.class, new DateTypeAdapter())
                        .serializeSpecialFloatingPointValues()
                        .create();
            Log.d(TAG, "syncTreatmentsData add Treatments Table entries count=" + entries.size());
            Sensor.InitDb(context);//ensure database has already been initialized
            for (DataMap entry : entries) {
                if (entry != null) {
                    String record = entry.getString("data");
                    if (record != null) {
                        Treatments data = gson.fromJson(record, Treatments.class);
                        Treatments exists = Treatments.byuuid(data.uuid);
                        if (exists != null) {
                            Log.d(TAG, "syncTreatmentsData save existing Treatments for action insert uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " carbs=" + data.carbs + " insulin=" + data.insulin + " exists.systime=" + JoH.dateTimeText(exists.systimestamp));
                            if (exists.timestamp != data.timestamp) {//currently only tracking timestamp on watch
                                changed = true;
                            }
                            exists.enteredBy = data.enteredBy;
                            exists.eventType = data.eventType;
                            exists.insulin = data.insulin;
                            exists.carbs = data.carbs;
                            exists.created_at = data.created_at;
                            exists.notes = data.notes;
                            exists.timestamp = data.timestamp;
                            exists.systimestamp = exists.systimestamp > 0 ? exists.systimestamp : data.timestamp < last_send_previous_treatments ? data.timestamp : last_send_previous_treatments > 0 ? last_send_previous_treatments - 1 : JoH.tsl();
                            exists.save();
                        } else {
                            changed = true;
                            data.systimestamp = data.timestamp < last_send_previous_treatments ? data.timestamp : last_send_previous_treatments > 0 ? last_send_previous_treatments - 1 : JoH.tsl();
                            data.save();
                            Log.d(TAG, "syncTreatmentsData create new treatment for action insert uuid=" + data.uuid + " timestamp=" + data.timestamp + " timeString=" + JoH.dateTimeText(data.timestamp) + " carbs=" + data.carbs + " insulin=" + data.insulin + " systime=" + JoH.dateTimeText(data.systimestamp));
                        }
                    }
                }
            }
            if (changed) {
                showTreatments(context, "treats");
            }
        }
    }
}
 
Example 14
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void syncCalibrationData(DataMap dataMap, Context context) {//KS
    Log.d(TAG, "syncCalibrationData");

    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, "syncCalibrationData add Calibration Table entries count=" + entries.size());
        Sensor.InitDb(context);//ensure database has already been initialized
        Sensor sensor = Sensor.currentSensor();
        if (sensor != null) {
            for (DataMap entry : entries) {
                if (entry != null) {
                    String calibration = entry.getString("bgs"); // bgs should be refactored to avoid confusion
                    if (calibration != null) {
                        Calibration bgData = gson.fromJson(calibration, Calibration.class);
                        Calibration exists = Calibration.findByUuid(bgData.uuid);
                        bgData.sensor = sensor;
                        if (exists != null) {
                            Log.d(TAG, "syncCalibrationData Calibration exists for uuid=" + bgData.uuid + " bg=" + bgData.bg + " timestamp=" + bgData.timestamp + " timeString=" +  JoH.dateTimeText(bgData.timestamp));
                            if (exists.slope != bgData.slope || exists.slope_confidence != bgData.slope_confidence || exists.timestamp != bgData.timestamp || exists.bg != bgData.bg) {//slope* indicates if shown on graph
                                changed = true;
                            }
                            exists.adjusted_raw_value = bgData.adjusted_raw_value;
                            exists.bg = bgData.bg;
                            exists.check_in = bgData.check_in;
                            exists.distance_from_estimate = bgData.distance_from_estimate;
                            exists.estimate_bg_at_time_of_calibration = bgData.estimate_bg_at_time_of_calibration;
                            exists.estimate_raw_at_time_of_calibration = bgData.estimate_raw_at_time_of_calibration;
                            exists.first_decay = bgData.first_decay;
                            exists.first_intercept = bgData.first_intercept;
                            exists.first_scale = bgData.first_scale;
                            exists.first_slope = bgData.first_slope;
                            exists.intercept = bgData.intercept;
                            exists.possible_bad = bgData.possible_bad;
                            exists.raw_timestamp = bgData.raw_timestamp;
                            exists.raw_value = bgData.raw_value;
                            exists.second_decay = bgData.second_decay;
                            exists.second_intercept = bgData.second_intercept;
                            exists.second_scale = bgData.second_scale;
                            exists.second_slope = bgData.second_slope;
                            exists.sensor = sensor;
                            exists.sensor_age_at_time_of_estimation = bgData.sensor_age_at_time_of_estimation;
                            exists.sensor_confidence = bgData.sensor_confidence;
                            exists.sensor_uuid = bgData.sensor_uuid;
                            exists.slope = bgData.slope;
                            exists.slope_confidence = bgData.slope_confidence;
                            exists.timestamp = bgData.timestamp;
                            exists.save();
                        }
                        else {
                            changed = true;
                            bgData.save();
                            //final boolean adjustPast = mPrefs.getBoolean("rewrite_history", true);
                            Log.d(TAG, "syncCalibrationData Calibration does not exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" +  JoH.dateTimeText(bgData.timestamp));
                            //Calibration.adjustRecentBgReadings(adjustPast ? 30 : 2);
                        }
                        exists = Calibration.findByUuid(bgData.uuid);
                        if (exists != null)
                            Log.d(TAG, "syncCalibrationData Calibration GSON saved BG: " + exists.toS());
                        else
                            Log.d(TAG, "syncCalibrationData Calibration GSON NOT saved");
                    }
                }
            }
        }
        else {
            Log.d(TAG, "syncCalibrationData No Active Sensor!! Request WEARABLE_INITDB_PATH");
            sendData(WEARABLE_INITDB_PATH, null);
        }
        if (changed) {
            showTreatments(context, "cals");
        }
    }
}
 
Example 15
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
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());
        Sensor.InitDb(context);//ensure database has already been initialized
        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");
        }
    }
}
 
Example 16
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void syncLogData(DataMap dataMap, boolean bBenchmark) {//KS
    Log.d(TAG, "syncLogData");
    long watch_syncLogsRequested = dataMap.getLong("syncLogsRequested", -1);
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    int saved = 0;
    if (entries != null) {

        Gson gson = new GsonBuilder()
                .excludeFieldsWithoutExposeAnnotation()
                .registerTypeAdapter(Date.class, new DateTypeAdapter())
                .serializeSpecialFloatingPointValues()
                .create();

        Log.d(TAG, "syncLogData add Table entries count=" + entries.size() + " watch_syncLogsRequested=" + watch_syncLogsRequested);
        for (DataMap entry : entries) {
            if (entry != null) {
                String record = entry.getString("entry");
                if (record != null) {
                    UserError data = gson.fromJson(record, UserError.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        if (data.shortError != null && !data.shortError.isEmpty()) { //add wear prefix
                            if (!data.shortError.startsWith("wear")) {
                                data.shortError = mPrefs.getString("wear_logs_prefix", "wear") + data.shortError;
                            }
                        }
                        UserError exists = UserError.getForTimestamp(data);
                        if (exists == null && !bBenchmark) {
                            data.save();
                            saved++;
                        } else {
                            //Log.d(TAG, "syncLogData Log entry already exists with shortError=" + data.shortError + " timestamp=" + JoH.dateTimeText((long)data.timestamp));
                        }
                    }
                }
            }
        }
        if (saved > 0) {
            Log.d(TAG, "syncLogData Saved timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " saved=" + saved);
        } else {
            Log.d(TAG, "syncLogData No records saved due to being duplicates! timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " count=" + entries.size());
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "LOG", watch_syncLogsRequested);
    }
}
 
Example 17
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
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());
        Sensor.InitDb(context);//ensure database has already been initialized
        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");
                }
            }
        }
    }
}
 
Example 18
Source File: CircleWatchface.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final PowerManager.WakeLock wl = JoH.getWakeLock("circle-message-receiver", 60000);
    try {
        DataMap dataMap;
        Bundle bundle = intent.getBundleExtra("msg");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            String msg = dataMap.getString("msg", "");
            int length = dataMap.getInt("length", 0);
            JoH.static_toast(xdrip.getAppContext(), msg, length);
        }
        bundle = intent.getBundleExtra("steps");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            if (mTimeStepsRcvd <= dataMap.getLong("steps_timestamp", 0)) {
                mStepsCount = dataMap.getInt("steps", 0);
                mTimeStepsRcvd = dataMap.getLong("steps_timestamp", 0);
            }
        }
        bundle = intent.getBundleExtra("data");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            setSgvLevel((int) dataMap.getLong("sgvLevel"));
            Log.d(TAG, "CircleWatchface sgv level : " + getSgvLevel());
            setSgvString(dataMap.getString("sgvString"));
            Log.d(TAG, "CircleWatchface sgv string : " + getSgvString());
            setRawString(dataMap.getString("rawString"));
            setDelta(dataMap.getString("delta"));
            setDatetime(dataMap.getDouble("timestamp"));
            mExtraStatusLine = dataMap.getString("extra_status_line");
            addToWatchSet(dataMap);


            //start animation?
            // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
            if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
                startAnimation();
            }

            prepareLayout();
            prepareDrawTime();
            invalidate();
        }
        //status
        bundle = intent.getBundleExtra("status");
        if (bundle != null) {
            dataMap = DataMap.fromBundle(bundle);
            setStatusString(dataMap.getString("externalStatusString"));

            prepareLayout();
            prepareDrawTime();
            invalidate();
        }
    } finally {
        JoH.releaseWakeLock(wl);
    }
}
 
Example 19
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
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);
                            Log.i(TAG, "syncTransmitterData: BG timestamp create " + Long.toString(bgData.timestamp));//android.util.Log.i
                            BgReading bgExists;

                            //KS TODO wear implements limited alerts, therefore continue to process all alerts on phone for last entry
                            if (count > 1 && idx < count) {
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp, true);//Disable Notifications for bulk insert
                            } 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);
    }
}
 
Example 20
Source File: BIGChart.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");
        rawString = dataMap.getString("rawString");
        sgvString = dataMap.getString("sgvString");
        batteryString = dataMap.getString("battery");
        mSgv.setText(dataMap.getString("sgvString"));

        if(ageLevel()<=0) {
            mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));

        showAgoRawBatt();

        String delta = dataMap.getString("delta");

        if (delta.endsWith(" mg/dl")) {
            mDelta.setText(delta.substring(0, delta.length() - 6));
        } else if (delta.endsWith(" mmol")) {
            mDelta.setText(delta.substring(0, delta.length() - 5));
        }

        if (chart != null) {
            addToWatchSet(dataMap);
            setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
                mRelativeLayout.getMeasuredHeight());
        invalidate();
        setColor();

        //start animation?
        // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
        if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5"))) {
            startAnimation();
        }


    } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
    }
}