use of com.google.android.gms.wearable.PutDataRequest in project xDrip by NightscoutFoundation.
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();
}
}
use of com.google.android.gms.wearable.PutDataRequest in project xDrip by NightscoutFoundation.
the class WatchUpdaterService method sendRequestExtra.
private void sendRequestExtra(String path, String key, String value) {
forceGoogleApiConnect();
if (googleApiClient.isConnected()) {
// NEW_STATUS_PATH
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path);
// unique content
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
// "externalStatusString"
dataMapRequest.getDataMap().putString(key, value);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("sendRequestExtra", "No connection to wearable available!");
}
}
use of com.google.android.gms.wearable.PutDataRequest in project xDrip by NightscoutFoundation.
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!");
}
}
use of com.google.android.gms.wearable.PutDataRequest in project xDrip by NightscoutFoundation.
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);
}
}
use of com.google.android.gms.wearable.PutDataRequest in project xDrip by NightscoutFoundation.
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);
}
}
Aggregations