public override async void OnDataChanged(DataEventBuffer dataEvents) { LOGD(Tag, "OnDataChanged: " + dataEvents); IList events = FreezableUtils.FreezeIterable(dataEvents); dataEvents.Release(); if (!googleApiClient.IsConnected) { ConnectionResult connectionResult = googleApiClient.BlockingConnect(30, TimeUnit.Seconds); if (!connectionResult.IsSuccess) { Log.Error(Tag, "DataLayerListenerService failed to connect to GoogleApiClient"); return; } } // Loop through the events and send a message back to the node that created the data item foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast <IDataEvent> (); var uri = e.DataItem.Uri; if (CountPath.Equals(CountPath)) { // Get the node ID of the node that created the date item from the host portion of the Uri string nodeId = uri.Host; // Set the data of the message to the bytes of the Uri byte[] payload = Encoding.UTF8.GetBytes(uri.ToString()); // Send the rpc await WearableClass.MessageApi.SendMessageAsync(googleApiClient, nodeId, DataItemReceivedPath, payload); } } }
public override async void OnDataChanged (DataEventBuffer dataEvents) { LOGD (Tag, "OnDataChanged: " + dataEvents); IList events = FreezableUtils.FreezeIterable (dataEvents); dataEvents.Release (); if (!googleApiClient.IsConnected) { ConnectionResult connectionResult = googleApiClient.BlockingConnect (30, TimeUnit.Seconds); if (!connectionResult.IsSuccess) { Log.Error (Tag, "DataLayerListenerService failed to connect to GoogleApiClient"); return; } } // Loop through the events and send a message back to the node that created the data item foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast<IDataEvent> (); var uri = e.DataItem.Uri; if (CountPath.Equals (CountPath)) { // Get the node ID of the node that created the date item from the host portion of the Uri string nodeId = uri.Host; // Set the data of the message to the bytes of the Uri byte[] payload = Encoding.UTF8.GetBytes (uri.ToString ()); // Send the rpc await WearableClass.MessageApi.SendMessageAsync (googleApiClient, nodeId, DataItemReceivedPath, payload); } } }
public async void OnDataChanged(DataEventBuffer dataEvents) { DataLayerListenerService.LOGD(Tag, "OnDatachanged() : " + dataEvents); IList events = FreezableUtils.FreezeIterable(dataEvents); dataEvents.Release(); foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast <IDataEvent> (); if (e.Type == DataEvent.TypeChanged) { String path = e.DataItem.Uri.Path; if (DataLayerListenerService.ImagePath.Equals(path)) { DataMapItem dataMapItem = DataMapItem.FromDataItem(e.DataItem); Asset photo = dataMapItem.DataMap.GetAsset(DataLayerListenerService.ImageKey); Bitmap bitmap = await LoadBitmapFromAsset(googleApiClient, photo); handler.Post(() => { DataLayerListenerService.LOGD(Tag, "Setting background image.."); layout.SetBackgroundDrawable(new BitmapDrawable(Resources, bitmap)); }); } else if (DataLayerListenerService.CountPath.Equals(path)) { DataLayerListenerService.LOGD(Tag, "Data Chaged for CountPath"); GenerateEvent("DataItem Changed", e.DataItem.ToString()); } else { DataLayerListenerService.LOGD(Tag, "Unrecognized path: " + path); } } else if (e.Type == DataEvent.TypeDeleted) { GenerateEvent("DataItem Changed", e.DataItem.ToString()); } else { DataLayerListenerService.LOGD("Unknown data event type", "Type = " + e.Type); } } }