Search in sources :

Example 11 with PutDataRequest

use of com.google.android.gms.wearable.PutDataRequest in project xDrip-plus by jamorham.

the class WatchUpdaterService method sendWearToast.

public static void sendWearToast(String msg, int length) {
    if ((googleApiClient != null) && (googleApiClient.isConnected())) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TOAST_NOTIFICATON);
        dataMapRequest.setUrgent();
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putInt("length", length);
        dataMapRequest.getDataMap().putString("msg", msg);
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e(TAG, "No connection to wearable available for toast! " + msg);
    }
}
Also used : PutDataRequest(com.google.android.gms.wearable.PutDataRequest) PutDataMapRequest(com.google.android.gms.wearable.PutDataMapRequest)

Example 12 with PutDataRequest

use of com.google.android.gms.wearable.PutDataRequest in project xDrip-plus by jamorham.

the class WatchUpdaterService method sendWearLocalToast.

public static void sendWearLocalToast(String msg, int length) {
    if ((googleApiClient != null) && (googleApiClient.isConnected())) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TOAST_LOCAL_NOTIFICATON);
        dataMapRequest.setUrgent();
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putInt("length", length);
        dataMapRequest.getDataMap().putString("msg", msg);
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e(TAG, "No connection to wearable available for toast! " + msg);
    }
}
Also used : PutDataRequest(com.google.android.gms.wearable.PutDataRequest) PutDataMapRequest(com.google.android.gms.wearable.PutDataMapRequest)

Example 13 with PutDataRequest

use of com.google.android.gms.wearable.PutDataRequest in project xDrip-plus by jamorham.

the class WatchUpdaterService method sendTreatment.

public static void sendTreatment(double carbs, double insulin, double bloodtest, String injectionJSON, double timeoffset, String timestring) {
    if ((googleApiClient != null) && (googleApiClient.isConnected())) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TREATMENT_PAYLOAD);
        // unique content
        dataMapRequest.setUrgent();
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putDouble("carbs", carbs);
        dataMapRequest.getDataMap().putDouble("insulin", insulin);
        dataMapRequest.getDataMap().putDouble("bloodtest", bloodtest);
        dataMapRequest.getDataMap().putDouble("timeoffset", timeoffset);
        dataMapRequest.getDataMap().putString("timestring", timestring);
        dataMapRequest.getDataMap().putString("injectionJSON", injectionJSON);
        dataMapRequest.getDataMap().putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext())));
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e(TAG, "No connection to wearable available for send treatment!");
    }
}
Also used : PutDataRequest(com.google.android.gms.wearable.PutDataRequest) PutDataMapRequest(com.google.android.gms.wearable.PutDataMapRequest)

Example 14 with PutDataRequest

use of com.google.android.gms.wearable.PutDataRequest in project xDrip-plus by jamorham.

the class WatchUpdaterService method sendRequestExtra.

private void sendRequestExtra(String path, String key, boolean value) {
    forceGoogleApiConnect();
    if (googleApiClient.isConnected()) {
        // NEW_STATUS_PATH
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path);
        // unique content
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        // "externalStatusString"
        dataMapRequest.getDataMap().putBoolean(key, value);
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e("sendRequestExtra", "No connection to wearable available!");
    }
}
Also used : PutDataRequest(com.google.android.gms.wearable.PutDataRequest) PutDataMapRequest(com.google.android.gms.wearable.PutDataMapRequest)

Example 15 with PutDataRequest

use of com.google.android.gms.wearable.PutDataRequest in project xDrip-plus by jamorham.

the class SendToDataLayerThread method sendToWear.

// Debug function to expose where it might be locking up
private synchronized void sendToWear(final DataMap... params) {
    if (!lock.tryLock()) {
        Log.d(TAG, "Concurrent access - waiting for thread unlock");
        // enforce single threading
        lock.lock();
        Log.d(TAG, "Thread unlocked - proceeding");
    }
    lastlock = JoH.tsl();
    try {
        if (state != 0) {
            UserError.Log.e(TAG, "WEAR STATE ERROR: state=" + state);
        }
        state = 1;
        final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS);
        state = 2;
        for (Node node : nodes.getNodes()) {
            state = 3;
            for (DataMap dataMap : params) {
                state = 4;
                PutDataMapRequest putDMR = PutDataMapRequest.create(path);
                state = 5;
                putDMR.getDataMap().putAll(dataMap);
                putDMR.setUrgent();
                state = 6;
                PutDataRequest request = putDMR.asPutDataRequest();
                state = 7;
                DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS);
                state = 8;
                if (result.getStatus().isSuccess()) {
                    UserError.Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
                } else {
                    UserError.Log.e(TAG, "ERROR: failed to send DataMap");
                    result = Wearable.DataApi.putDataItem(googleApiClient, request).await(30, TimeUnit.SECONDS);
                    if (result.getStatus().isSuccess()) {
                        UserError.Log.d(TAG, "DataMap retry: " + dataMap + " sent to: " + node.getDisplayName());
                    } else {
                        UserError.Log.e(TAG, "ERROR on retry: failed to send DataMap: " + result.getStatus().toString());
                    }
                }
                state = 9;
            }
        }
        state = 0;
    } catch (Exception e) {
        UserError.Log.e(TAG, "Got exception in sendToWear: " + e.toString());
    } finally {
        lastlock = 0;
        lock.unlock();
    }
}
Also used : Node(com.google.android.gms.wearable.Node) NodeApi(com.google.android.gms.wearable.NodeApi) PutDataRequest(com.google.android.gms.wearable.PutDataRequest) PutDataMapRequest(com.google.android.gms.wearable.PutDataMapRequest) DataApi(com.google.android.gms.wearable.DataApi) DataMap(com.google.android.gms.wearable.DataMap)

Aggregations

PutDataRequest (com.google.android.gms.wearable.PutDataRequest)19 PutDataMapRequest (com.google.android.gms.wearable.PutDataMapRequest)18 DataApi (com.google.android.gms.wearable.DataApi)2 DataMap (com.google.android.gms.wearable.DataMap)2 Node (com.google.android.gms.wearable.Node)2 NodeApi (com.google.android.gms.wearable.NodeApi)2 ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)1 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)1