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

The following examples show how to use com.google.android.gms.wearable.DataMap#putDouble() . 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: Simulation.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void Approve(View myview) {
    if (watchkeypad) {
        //Treatments.create(carbs, insulin, thisnotes, new Date().getTime());
        DataMap dataMap = new DataMap();
        dataMap.putDouble("timeoffset", timeoffset);
        dataMap.putDouble("carbs", carbs);
        dataMap.putDouble("insulin", insulin);
        dataMap.putDouble("bloodtest", bloodtest);
        dataMap.putString("notes", thisnotes);
        //dataMap.putLong("timestamp", System.currentTimeMillis());
        ListenerService.createTreatment(dataMap, this);
    }
    else
        SendData(this, WEARABLE_APPROVE_TREATMENT, null);
    finish();
}
 
Example 2
Source File: Simulation.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void Approve(View myview) {
    if (watchkeypad) {
        //Treatments.create(carbs, insulin, thisnotes, new Date().getTime());
        DataMap dataMap = new DataMap();
        dataMap.putDouble("timeoffset", timeoffset);
        dataMap.putDouble("carbs", carbs);
        dataMap.putDouble("insulin", insulin);
        dataMap.putDouble("bloodtest", bloodtest);
        dataMap.putString("notes", thisnotes);
        //dataMap.putLong("timestamp", System.currentTimeMillis());
        ListenerService.createTreatment(dataMap, this);
    }
    else
        SendData(this, WEARABLE_APPROVE_TREATMENT, null);
    finish();
}
 
Example 3
Source File: RawDisplayDataBgEntriesTest.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private DataMap dataMapForEntries() {

        DataMap dataMap = new DataMap();
        ArrayList<DataMap> entries = new ArrayList<>();
        for (int i=0; i<12; i++) {
            DataMap entry = new DataMap();
            entry.putLong("timestamp", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*(16-i));
            entry.putDouble("sgvDouble", 145.0-5*i);
            entry.putDouble("high", 170.0);
            entry.putDouble("low", 80.0);
            entry.putInt("color", 0);
            entries.add(entry);
        }
        dataMap.putDataMapArrayList("entries", entries);

        return dataMap;
    }
 
Example 4
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static DataMap dataMapForWatchface(Treatments data) {
    DataMap dataMap = new DataMap();
    //dataMap.putString("notes", data.notes);//TODO
    dataMap.putDouble("timestamp", data.timestamp);
    dataMap.putDouble("high", data.carbs);
    dataMap.putDouble("low", data.insulin);
    return dataMap;
}
 
Example 5
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private DataMap predictionMap(long timestamp, double sgv, int color) {
    DataMap dm = new DataMap();
    dm.putLong("timestamp", timestamp);
    dm.putDouble("sgv", sgv);
    dm.putInt("color", color);
    return dm;
}
 
Example 6
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private DataMap treatmentMap(long date, double bolus, double carbs, boolean isSMB, boolean isValid) {
    DataMap dm = new DataMap();
    dm.putLong("date", date);
    dm.putDouble("bolus", bolus);
    dm.putDouble("carbs", carbs);
    dm.putBoolean("isSMB", isSMB);
    dm.putBoolean("isValid", isValid);
    return dm;
}
 
Example 7
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public synchronized static void sendTreatment(String notes) {
    Log.d(TAG, "sendTreatment WEARABLE_TREATMENT_PAYLOAD notes=" + notes);
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", System.currentTimeMillis());
    dataMap.putBoolean("watchkeypad", true);
    dataMap.putString("notes", notes);
    dataMap.putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext())));
    Intent intent = new Intent(xdrip.getAppContext(), Simulation.class);
    intent.putExtra(WEARABLE_TREATMENT_PAYLOAD, dataMap.toBundle());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    xdrip.getAppContext().startActivity(intent);
}
 
Example 8
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static DataMap dataMapForWatchface(Treatments data) {
    DataMap dataMap = new DataMap();
    //dataMap.putString("notes", data.notes);//TODO
    dataMap.putDouble("timestamp", data.timestamp);
    dataMap.putDouble("high", data.carbs);
    dataMap.putDouble("low", data.insulin);
    return dataMap;
}
 
Example 9
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private DataMap basalMap(long startTime, long endTime, double amount) {
    DataMap dm = new DataMap();
    dm.putLong("starttime", startTime);
    dm.putLong("endtime", endTime);
    dm.putDouble("amount", amount);
    return dm;
}
 
Example 10
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private DataMap tempDatamap(long startTime, double startBasal, long to, double toBasal, double amount) {
    DataMap dm = new DataMap();
    dm.putLong("starttime", startTime);
    dm.putDouble("startBasal", startBasal);
    dm.putLong("endtime", to);
    dm.putDouble("endbasal", toBasal);
    dm.putDouble("amount", amount);
    return dm;
}
 
Example 11
Source File: RawDisplayDataBgEntriesTest.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private DataMap dataMapForEntries(long timestamp, double sgv) {
    DataMap entry = new DataMap();
    entry.putLong("timestamp", timestamp);
    entry.putDouble("sgvDouble", sgv);
    entry.putDouble("high", 160.0);
    entry.putDouble("low", 90.0);
    entry.putInt("color", 1);
    return entry;
}
 
Example 12
Source File: Emmet.java    From Wear-Emmet with Apache License 2.0 4 votes vote down vote up
private void sendDataMap(String path, Object proxy, Method method, Object[] args) throws Throwable {
    final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);

    DataMap datamap = putDataMapRequest.getDataMap();
    datamap.putString("timestamp", new Date().toString());
    datamap.putString(METHOD_NAME, method.getName());

    {
        ArrayList<DataMap> methodDataMapList = new ArrayList<>();

        for (Object argument : args) {
            DataMap map = new DataMap();

            if (argument instanceof Integer) {
                map.putString(PARAM_TYPE, TYPE_INT);
                map.putInt(PARAM_VALUE, (Integer) argument);
            } else if (argument instanceof Float) {
                map.putString(PARAM_TYPE, TYPE_FLOAT);
                map.putFloat(PARAM_VALUE, (Float) argument);
            } else if (argument instanceof Double) {
                map.putString(PARAM_TYPE, TYPE_DOUBLE);
                map.putDouble(PARAM_VALUE, (Double) argument);
            } else if (argument instanceof Long) {
                map.putString(PARAM_TYPE, TYPE_LONG);
                map.putLong(PARAM_VALUE, (Long) argument);
            } else if (argument instanceof String) {
                map.putString(PARAM_TYPE, TYPE_STRING);
                map.putString(PARAM_VALUE, (String) argument);
            } else {
                map.putString(PARAM_TYPE, argument.getClass().getName());
                String encoded = SerialisationUtilsGSON.serialize(argument);
                map.putString(PARAM_VALUE, encoded);
            }

            methodDataMapList.add(map);
        }

        datamap.putDataMapArrayList(METHOD_PARAMS, methodDataMapList);
    }

    if (ENABLE_LOG)
        Log.d(TAG, datamap.toString());

    if (mApiClient != null) {
        if (mApiClient.isConnected()) {
            sendDataMapRequest(putDataMapRequest);
        } else {
            mWaitingDataMapItems.add(putDataMapRequest);
            mApiClient.connect();
        }
    }
}
 
Example 13
Source File: UtilityService.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
/**
 * Transfer the required data over to the wearable
 * @param attractions list of attraction data to transfer over
 */
private void sendDataToWearable(List<Attraction> attractions) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    // It's OK to use blockingConnect() here as we are running in an
    // IntentService that executes work on a separate (background) thread.
    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    // Limit attractions to send
    int count = attractions.size() > Constants.MAX_ATTRACTIONS ?
            Constants.MAX_ATTRACTIONS : attractions.size();

    ArrayList<DataMap> attractionsData = new ArrayList<>(count);

    for (int i = 0; i < count; i++) {
        Attraction attraction = attractions.get(i);

        Bitmap image = null;
        Bitmap secondaryImage = null;

        try {
            // Fetch and resize attraction image bitmap
            image = Glide.with(this)
                    .load(attraction.imageUrl)
                    .asBitmap()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE)
                    .get();

            secondaryImage = Glide.with(this)
                    .load(attraction.secondaryImageUrl)
                    .asBitmap()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE)
                    .get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Exception loading bitmap from network");
        }

        if (image != null && secondaryImage != null) {

            DataMap attractionData = new DataMap();

            String distance = Utils.formatDistanceBetween(
                    Utils.getLocation(this), attraction.location);

            attractionData.putString(Constants.EXTRA_TITLE, attraction.name);
            attractionData.putString(Constants.EXTRA_DESCRIPTION, attraction.description);
            attractionData.putDouble(
                    Constants.EXTRA_LOCATION_LAT, attraction.location.latitude);
            attractionData.putDouble(
                    Constants.EXTRA_LOCATION_LNG, attraction.location.longitude);
            attractionData.putString(Constants.EXTRA_DISTANCE, distance);
            attractionData.putString(Constants.EXTRA_CITY, attraction.city);
            attractionData.putAsset(Constants.EXTRA_IMAGE,
                    Utils.createAssetFromBitmap(image));
            attractionData.putAsset(Constants.EXTRA_IMAGE_SECONDARY,
                    Utils.createAssetFromBitmap(secondaryImage));

            attractionsData.add(attractionData);
        }
    }

    if (connectionResult.isSuccess() && googleApiClient.isConnected()
            && attractionsData.size() > 0) {

        PutDataMapRequest dataMap = PutDataMapRequest.create(Constants.ATTRACTION_PATH);
        dataMap.getDataMap().putDataMapArrayList(Constants.EXTRA_ATTRACTIONS, attractionsData);
        dataMap.getDataMap().putLong(Constants.EXTRA_TIMESTAMP, new Date().getTime());
        PutDataRequest request = dataMap.asPutDataRequest();

        // Send the data over
        DataApi.DataItemResult result =
                Wearable.DataApi.putDataItem(googleApiClient, request).await();

        if (!result.getStatus().isSuccess()) {
            Log.e(TAG, String.format("Error sending data using DataApi (error code = %d)",
                    result.getStatus().getStatusCode()));
        }

    } else {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
    }
    googleApiClient.disconnect();
}
 
Example 14
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) {
    String units = ProfileFunctions.getSystemUnits();

    Double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
    Double highLine = OverviewPlugin.INSTANCE.determineHighLine();

    // convert to mg/dl
    if (!units.equals(Constants.MGDL)) {
        lowLine *= Constants.MMOLL_TO_MGDL;
        highLine *= Constants.MMOLL_TO_MGDL;

    }

    if (lowLine < 1) {
        lowLine = OverviewPlugin.INSTANCE.getBgTargetLow();
    }

    if (highLine < 1) {
        highLine = OverviewPlugin.INSTANCE.getBgTargetHigh();
    }

    long sgvLevel = 0L;
    if (lastBG.value > highLine) {
        sgvLevel = 1;
    } else if (lastBG.value < lowLine) {
        sgvLevel = -1;
    }

    DataMap dataMap = new DataMap();
    dataMap.putString("sgvString", lastBG.valueToUnitsToString(units));
    dataMap.putString("glucoseUnits", units);
    dataMap.putLong("timestamp", lastBG.date);
    if (glucoseStatus == null) {
        dataMap.putString("slopeArrow", "");
        dataMap.putString("delta", "--");
        dataMap.putString("avgDelta", "--");
    } else {
        dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.delta));
        dataMap.putString("delta", deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units));
        dataMap.putString("avgDelta", deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, units));
    }
    dataMap.putLong("sgvLevel", sgvLevel);
    dataMap.putDouble("sgvDouble", lastBG.value);
    dataMap.putDouble("high", highLine);
    dataMap.putDouble("low", lowLine);
    return dataMap;
}
 
Example 15
Source File: RawDisplayDataBasalsTest.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
private DataMap dataMapForBasals() {

        DataMap dataMap = new DataMap();

        ArrayList<DataMap> temps = new ArrayList<>();
        DataMap temp = new DataMap();
        temp.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20);
        temp.putDouble("startBasal", 1.5);
        temp.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10);
        temp.putDouble("endbasal", 1.5);
        temp.putDouble("amount", 1.8);
        temps.add(temp);

        DataMap temp2 = new DataMap();
        temp2.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10);
        temp2.putDouble("startBasal", 1.3);
        temp2.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
        temp2.putDouble("endbasal", 1.3);
        temp2.putDouble("amount", 2.3);
        temps.add(temp2);
        dataMap.putDataMapArrayList("temps", temps);

        ArrayList<DataMap> basals = new ArrayList<>();
        DataMap basal = new DataMap();
        basal.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20);
        basal.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
        basal.putDouble("amount", 1.2);
        basals.add(basal);
        dataMap.putDataMapArrayList("basals", basals);

        ArrayList<DataMap> boluses = new ArrayList<>();
        DataMap bolus = new DataMap();
        bolus.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*17);
        bolus.putDouble("bolus", 5.5);
        bolus.putDouble("carbs", 20.0);
        bolus.putBoolean("isSMB", false);
        bolus.putBoolean("isValid", true);
        boluses.add(bolus);

        DataMap bolus2 = new DataMap();
        bolus2.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*11);
        bolus2.putDouble("bolus", 3.0);
        bolus2.putDouble("carbs", 0.0);
        bolus2.putBoolean("isSMB", false);
        bolus2.putBoolean("isValid", true);
        boluses.add(bolus2);

        DataMap bolus3 = new DataMap();
        bolus3.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*3);
        bolus3.putDouble("bolus", 0.0);
        bolus3.putDouble("carbs", 15.0);
        bolus3.putBoolean("isSMB", true);
        bolus3.putBoolean("isValid", false);
        boluses.add(bolus3);

        dataMap.putDataMapArrayList("boluses", boluses);

        ArrayList<DataMap> predictions = new ArrayList<>();
        for (int i=0; i<10; i++) {
            DataMap prediction = new DataMap();
            prediction.putLong("timestamp", WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS*i);
            prediction.putDouble("sgv", 160-4*i);
            prediction.putInt("color", 0);
            predictions.add(prediction);
        }
        dataMap.putDataMapArrayList("predictions", predictions);

        return dataMap;
    }
 
Example 16
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static DataMap dataMapForWatchface(BloodTest data) {
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", data.timestamp);
    dataMap.putDouble("sgvDouble", data.mgdl);
    return dataMap;
}
 
Example 17
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static DataMap dataMapForWatchface(Calibration data) {
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", data.timestamp);
    dataMap.putDouble("sgvDouble", data.bg);
    return dataMap;
}
 
Example 18
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static DataMap dataMapForWatchface(BloodTest data) {
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", data.timestamp);
    dataMap.putDouble("sgvDouble", data.mgdl);
    return dataMap;
}
 
Example 19
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static DataMap dataMapForWatchface(Calibration data) {
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", data.timestamp);
    dataMap.putDouble("sgvDouble", data.bg);
    return dataMap;
}
 
Example 20
Source File: UtilityService.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
/**
 * Transfer the required data over to the wearable
 * @param attractions list of attraction data to transfer over
 */
private void sendDataToWearable(List<Attraction> attractions) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    // It's OK to use blockingConnect() here as we are running in an
    // IntentService that executes work on a separate (background) thread.
    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    // Limit attractions to send
    int count = attractions.size() > Constants.MAX_ATTRACTIONS ?
            Constants.MAX_ATTRACTIONS : attractions.size();

    ArrayList<DataMap> attractionsData = new ArrayList<>(count);

    for (int i = 0; i < count; i++) {
        Attraction attraction = attractions.get(i);

        Bitmap image = null;
        Bitmap secondaryImage = null;

        try {
            // Fetch and resize attraction image bitmap
            image = Glide.with(this)
                    .load(attraction.imageUrl)
                    .asBitmap()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE)
                    .get();

            secondaryImage = Glide.with(this)
                    .load(attraction.secondaryImageUrl)
                    .asBitmap()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE)
                    .get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Exception loading bitmap from network");
        }

        if (image != null && secondaryImage != null) {

            DataMap attractionData = new DataMap();

            String distance = Utils.formatDistanceBetween(
                    Utils.getLocation(this), attraction.location);

            attractionData.putString(Constants.EXTRA_TITLE, attraction.name);
            attractionData.putString(Constants.EXTRA_DESCRIPTION, attraction.description);
            attractionData.putDouble(
                    Constants.EXTRA_LOCATION_LAT, attraction.location.latitude);
            attractionData.putDouble(
                    Constants.EXTRA_LOCATION_LNG, attraction.location.longitude);
            attractionData.putString(Constants.EXTRA_DISTANCE, distance);
            attractionData.putString(Constants.EXTRA_CITY, attraction.city);
            attractionData.putAsset(Constants.EXTRA_IMAGE,
                    Utils.createAssetFromBitmap(image));
            attractionData.putAsset(Constants.EXTRA_IMAGE_SECONDARY,
                    Utils.createAssetFromBitmap(secondaryImage));

            attractionsData.add(attractionData);
        }
    }

    if (connectionResult.isSuccess() && googleApiClient.isConnected()
            && attractionsData.size() > 0) {

        PutDataMapRequest dataMap = PutDataMapRequest.create(Constants.ATTRACTION_PATH);
        dataMap.getDataMap().putDataMapArrayList(Constants.EXTRA_ATTRACTIONS, attractionsData);
        dataMap.getDataMap().putLong(Constants.EXTRA_TIMESTAMP, new Date().getTime());
        PutDataRequest request = dataMap.asPutDataRequest();

        // Send the data over
        DataApi.DataItemResult result =
                Wearable.DataApi.putDataItem(googleApiClient, request).await();

        if (!result.getStatus().isSuccess()) {
            Log.e(TAG, String.format("Error sending data using DataApi (error code = %d)",
                    result.getStatus().getStatusCode()));
        }

    } else {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
    }
    googleApiClient.disconnect();
}