public void OnDataChanged(DataEventBuffer dataEvents) { var events = FreezableUtils.FreezeIterable(dataEvents); dataEvents.Close(); RunOnUiThread(() => { foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast <IDataEvent> (); if (e.Type == DataEvent.TypeChanged) { var dataMap = DataMapItem.FromDataItem(e.DataItem).DataMap; var questionWasAnswered = dataMap.GetBoolean(Constants.QUESTION_WAS_ANSWERED); var questionWasDeleted = dataMap.GetBoolean(Constants.QUESTION_WAS_DELETED); if (questionWasAnswered) { int questionIndex = dataMap.GetInt(Constants.QUESTION_INDEX); bool questionCorrect = dataMap.GetBoolean(Constants.CHOSEN_ANSWER_CORRECT); UpdateQuestionStatus(questionIndex, questionCorrect); AskNextQuestionIfExists(); } else if (questionWasDeleted) { int questionIndex = dataMap.GetInt(Constants.QUESTION_INDEX); MarkQuestionLeftBlank(questionIndex); AskNextQuestionIfExists(); } } } }); }
public override async void OnDataChanged(DataEventBuffer dataEvents) { LOGD(Tag, "OnDataChanged: " + dataEvents); IList events = FreezableUtils.FreezeIterable(dataEvents); dataEvents.Close(); 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 void OnDataChanged (DataEventBuffer buffer) { if (Log.IsLoggable (TAG, LogPriority.Debug)) Log.Debug (TAG, "OnDataChanged: " + buffer + " for " + PackageName); for (int i = 0; i < buffer.Count; i++) { IDataEvent e = Android.Runtime.Extensions.JavaCast<IDataEvent> (buffer.Get (i)); if (e.Type == DataEvent.TypeDeleted) { Log.Info (TAG, e + " deleted"); } else if (e.Type == DataEvent.TypeChanged) { bool alarmOn = (bool)DataMap.FromByteArray (e.DataItem.GetData ()).Get (FIELD_ALARM_ON); if (!alarmOn) { orig_volume = audio_manager.GetStreamVolume (Android.Media.Stream.Alarm); media_player.Reset (); audio_manager.SetStreamVolume (Android.Media.Stream.Alarm, max_volume, 0); media_player.SetAudioStreamType (Android.Media.Stream.Alarm); try { media_player.SetDataSource (ApplicationContext, alarm_sound); media_player.Prepare (); } catch (IOException ex) { Log.Error (TAG, "Failed to prepare media player to play alarm.", ex); } media_player.Start (); } else { audio_manager.SetStreamVolume (Android.Media.Stream.Alarm, orig_volume, 0); if (media_player.IsPlaying) media_player.Stop (); } } } buffer.Close (); }
public void OnDataChanged(DataEventBuffer dataEvents) { var events = FreezableUtils.FreezeIterable(dataEvents); dataEvents.Close(); foreach (var ev in events) { var dataEvent = ((Java.Lang.Object)ev).JavaCast <IDataEvent> (); if (dataEvent.Type != DataEvent.TypeChanged) { continue; } var dataItem = dataEvent.DataItem; if (!dataItem.Uri.Path.Equals(DigitalWatchFaceUtil.PathWithFeature)) { continue; } var dataMapItem = DataMapItem.FromDataItem(dataItem); var config = dataMapItem.DataMap; if (Log.IsLoggable(Tag, LogPriority.Debug)) { Log.Debug(Tag, "Config DataItem updated: " + config); } UpdateUiForConfigDataMap(config); } }
public override void OnDataChanged (DataEventBuffer dataEvents) { LOGD (Tag, "OnDataChanged: " + dataEvents); IList events = FreezableUtils.FreezeIterable (dataEvents); dataEvents.Close (); 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 WearableClass.MessageApi.SendMessage (googleApiClient, nodeId, DataItemReceivedPath, payload); } } }
public override void OnDataChanged(DataEventBuffer buffer) { if (Log.IsLoggable(TAG, LogPriority.Debug)) { Log.Debug(TAG, "OnDataChanged: " + buffer + " for " + PackageName); } for (int i = 0; i < buffer.Count; i++) { IDataEvent e = Android.Runtime.Extensions.JavaCast <IDataEvent>(buffer.Get(i)); if (e.Type == DataEvent.TypeDeleted) { Log.Info(TAG, e + " deleted"); } else if (e.Type == DataEvent.TypeChanged) { bool alarmOn = (bool)DataMap.FromByteArray(e.DataItem.GetData()).Get(FIELD_ALARM_ON); if (!alarmOn) { orig_volume = audio_manager.GetStreamVolume(Android.Media.Stream.Alarm); media_player.Reset(); max_volume = 0; audio_manager.SetStreamVolume(Android.Media.Stream.Alarm, max_volume, 0); media_player.SetAudioStreamType(Android.Media.Stream.Alarm); try { media_player.SetDataSource(ApplicationContext, alarm_sound); media_player.Prepare(); } catch (IOException ex) { Log.Error(TAG, "Failed to prepare media player to play alarm.", ex); } media_player.Start(); } else { audio_manager.SetStreamVolume(Android.Media.Stream.Alarm, orig_volume, 0); if (media_player.IsPlaying) { media_player.Stop(); } } } } buffer.Close(); }
public async void OnDataChanged(DataEventBuffer dataEvents) { DataLayerListenerService.LOGD(Tag, "OnDatachanged() : " + dataEvents); IList events = FreezableUtils.FreezeIterable(dataEvents); dataEvents.Close(); 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); } } }
public void OnDataChanged(DataEventBuffer dataEvents) { LOGD(Tag, "OnDataChanged: " + dataEvents); var events = FreezableUtils.FreezeIterable(dataEvents); dataEvents.Close(); RunOnUiThread(() => { foreach (var e in events) { var ev = ((Java.Lang.Object)e).JavaCast <IDataEvent>(); if (ev.Type == DataEvent.TypeChanged) { dataItemListAdapter.Add( new Event("DataItem Changed", ev.DataItem.ToString())); } else if (ev.Type == DataEvent.TypeDeleted) { dataItemListAdapter.Add( new Event("DataItem Deleted", ev.DataItem.ToString())); } } }); }
public void OnDataChanged(DataEventBuffer dataEvents) { LOGD(Tag, "OnDataChanged: " + dataEvents); var events = new List <IDataEvent> (); events.AddRange(dataEvents); dataEvents.Close(); RunOnUiThread(() => { foreach (var ev in events) { if (ev.Type == DataEvent.TypeChanged) { dataItemListAdapter.Add( new Event("DataItem Changed", ev.DataItem.ToString())); } else if (ev.Type == DataEvent.TypeDeleted) { dataItemListAdapter.Add( new Event("DataItem Deleted", ev.DataItem.ToString())); } } }); }
public override void OnDataChanged (DataEventBuffer eventBuffer) { var events = FreezableUtils.FreezeIterable (eventBuffer); eventBuffer.Close (); var google_api_client = new GoogleApiClientBuilder (this) .AddApi (WearableClass.API) .Build (); var connectionResult = google_api_client.BlockingConnect (Constants.CONNECT_TIMEOUT_MS, TimeUnit.Milliseconds); if (!connectionResult.IsSuccess) { Log.Error (TAG, "QuizListenerService failed to connect to GoogleApiClient."); return; } foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast<IDataEvent> (); if (e.Type == DataEvent.TypeChanged) { var dataItem = e.DataItem; var dataMap = DataMapItem.FromDataItem (dataItem).DataMap; if (dataMap.GetBoolean (Constants.QUESTION_WAS_ANSWERED) || dataMap.GetBoolean (Constants.QUESTION_WAS_DELETED)) { continue; } string question = dataMap.GetString (Constants.QUESTION); int questionIndex = dataMap.GetInt (Constants.QUESTION_INDEX); int questionNum = questionIndex + 1; string[] answers = dataMap.GetStringArray (Constants.ANSWERS); int correctAnswerIndex = dataMap.GetInt (Constants.CORRECT_ANSWER_INDEX); Intent deleteOperation = new Intent (this, typeof(DeleteQuestionService)); deleteOperation.SetData (dataItem.Uri); PendingIntent deleteIntent = PendingIntent.GetService (this, 0, deleteOperation, PendingIntentFlags.UpdateCurrent); //first page of notification contains question as Big Text. var bigTextStyle = new Notification.BigTextStyle () .SetBigContentTitle (GetString (Resource.String.question, questionNum)) .BigText (question); var builder = new Notification.Builder (this) .SetStyle (bigTextStyle) .SetSmallIcon (Resource.Drawable.ic_launcher) .SetLocalOnly (true) .SetDeleteIntent (deleteIntent); //add answers as actions var wearableOptions = new Notification.WearableExtender (); for (int i = 0; i < answers.Length; i++) { Notification answerPage = new Notification.Builder (this) .SetContentTitle (question) .SetContentText (answers [i]) .Extend (new Notification.WearableExtender () .SetContentAction (i)) .Build (); bool correct = (i == correctAnswerIndex); var updateOperation = new Intent (this, typeof(UpdateQuestionService)); //Give each intent a unique action. updateOperation.SetAction ("question_" + questionIndex + "_answer_" + i); updateOperation.SetData (dataItem.Uri); updateOperation.PutExtra (UpdateQuestionService.EXTRA_QUESTION_INDEX, questionIndex); updateOperation.PutExtra (UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct); var updateIntent = PendingIntent.GetService (this, 0, updateOperation, PendingIntentFlags.UpdateCurrent); Notification.Action action = new Notification.Action.Builder ( (int)question_num_to_drawable_id.Get (i), (string)null, updateIntent) .Build (); wearableOptions.AddAction (action).AddPage (answerPage); } builder.Extend (wearableOptions); Notification notification = builder.Build (); ((NotificationManager)GetSystemService (NotificationService)) .Notify (questionIndex, notification); } else if (e.Type == DataEvent.TypeDeleted) { Android.Net.Uri uri = e.DataItem.Uri; //URIs are in the form of "/question/0", "/question/1" etc. //We use the question index as the notification id. int notificationId = Java.Lang.Integer.ParseInt (uri.LastPathSegment); ((NotificationManager)GetSystemService (NotificationService)) .Cancel (notificationId); } ((NotificationManager)GetSystemService (NotificationService)) .Cancel (QUIZ_REPORT_NOTIF_ID); } google_api_client.Disconnect (); }
public void OnDataChanged (DataEventBuffer dataEvents) { var events = FreezableUtils.FreezeIterable (dataEvents); dataEvents.Close (); RunOnUiThread (() => { foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast<IDataEvent> (); if (e.Type == DataEvent.TypeChanged) { var dataMap = DataMapItem.FromDataItem (e.DataItem).DataMap; var questionWasAnswered = dataMap.GetBoolean (Constants.QUESTION_WAS_ANSWERED); var questionWasDeleted = dataMap.GetBoolean (Constants.QUESTION_WAS_DELETED); if (questionWasAnswered) { int questionIndex = dataMap.GetInt (Constants.QUESTION_INDEX); bool questionCorrect = dataMap.GetBoolean (Constants.CHOSEN_ANSWER_CORRECT); UpdateQuestionStatus (questionIndex, questionCorrect); AskNextQuestionIfExists (); } else if (questionWasDeleted) { int questionIndex = dataMap.GetInt (Constants.QUESTION_INDEX); MarkQuestionLeftBlank (questionIndex); AskNextQuestionIfExists (); } } } }); }
public override void OnDataChanged(DataEventBuffer eventBuffer) { var events = FreezableUtils.FreezeIterable(eventBuffer); eventBuffer.Close(); var google_api_client = new GoogleApiClientBuilder(this) .AddApi(WearableClass.API) .Build(); var connectionResult = google_api_client.BlockingConnect(Constants.CONNECT_TIMEOUT_MS, TimeUnit.Milliseconds); if (!connectionResult.IsSuccess) { Log.Error(TAG, "QuizListenerService failed to connect to GoogleApiClient."); return; } foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast <IDataEvent> (); if (e.Type == DataEvent.TypeChanged) { var dataItem = e.DataItem; var dataMap = DataMapItem.FromDataItem(dataItem).DataMap; if (dataMap.GetBoolean(Constants.QUESTION_WAS_ANSWERED) || dataMap.GetBoolean(Constants.QUESTION_WAS_DELETED)) { continue; } string question = dataMap.GetString(Constants.QUESTION); int questionIndex = dataMap.GetInt(Constants.QUESTION_INDEX); int questionNum = questionIndex + 1; string[] answers = dataMap.GetStringArray(Constants.ANSWERS); int correctAnswerIndex = dataMap.GetInt(Constants.CORRECT_ANSWER_INDEX); Intent deleteOperation = new Intent(this, typeof(DeleteQuestionService)); deleteOperation.SetData(dataItem.Uri); PendingIntent deleteIntent = PendingIntent.GetService(this, 0, deleteOperation, PendingIntentFlags.UpdateCurrent); //first page of notification contains question as Big Text. var bigTextStyle = new Notification.BigTextStyle() .SetBigContentTitle(GetString(Resource.String.question, questionNum)) .BigText(question); var builder = new Notification.Builder(this) .SetStyle(bigTextStyle) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetLocalOnly(true) .SetDeleteIntent(deleteIntent); //add answers as actions var wearableOptions = new Notification.WearableExtender(); for (int i = 0; i < answers.Length; i++) { Notification answerPage = new Notification.Builder(this) .SetContentTitle(question) .SetContentText(answers [i]) .Extend(new Notification.WearableExtender() .SetContentAction(i)) .Build(); bool correct = (i == correctAnswerIndex); var updateOperation = new Intent(this, typeof(UpdateQuestionService)); //Give each intent a unique action. updateOperation.SetAction("question_" + questionIndex + "_answer_" + i); updateOperation.SetData(dataItem.Uri); updateOperation.PutExtra(UpdateQuestionService.EXTRA_QUESTION_INDEX, questionIndex); updateOperation.PutExtra(UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct); var updateIntent = PendingIntent.GetService(this, 0, updateOperation, PendingIntentFlags.UpdateCurrent); Notification.Action action = new Notification.Action.Builder( (int)question_num_to_drawable_id.Get(i), (string)null, updateIntent) .Build(); wearableOptions.AddAction(action).AddPage(answerPage); } builder.Extend(wearableOptions); Notification notification = builder.Build(); ((NotificationManager)GetSystemService(NotificationService)) .Notify(questionIndex, notification); } else if (e.Type == DataEvent.TypeDeleted) { Android.Net.Uri uri = e.DataItem.Uri; //URIs are in the form of "/question/0", "/question/1" etc. //We use the question index as the notification id. int notificationId = Java.Lang.Integer.ParseInt(uri.LastPathSegment); ((NotificationManager)GetSystemService(NotificationService)) .Cancel(notificationId); } ((NotificationManager)GetSystemService(NotificationService)) .Cancel(QUIZ_REPORT_NOTIF_ID); } google_api_client.Disconnect(); }
public void OnDataChanged(DataEventBuffer dataEvents) { var events = FreezableUtils.FreezeIterable (dataEvents); dataEvents.Close (); foreach (var ev in events) { var dataEvent = ((Java.Lang.Object)ev).JavaCast<IDataEvent> (); if (dataEvent.Type != DataEvent.TypeChanged) { continue; } var dataItem = dataEvent.DataItem; if (!dataItem.Uri.Path.Equals (DigitalWatchFaceUtil.PathWithFeature)) { continue; } var dataMapItem = DataMapItem.FromDataItem (dataItem); var config = dataMapItem.DataMap; if (Log.IsLoggable (Tag, LogPriority.Debug)) { Log.Debug (Tag, "Config DataItem updated: " + config); } UpdateUiForConfigDataMap (config); } }