Beispiel #1
0
 private void ThrowIfFrozen()
 {
     if (isFrozen)
     {
         throw FreezableUtils.Error(nameof(DotvvmRouteTable));
     }
 }
Beispiel #2
0
        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 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();
                        }
                    }
                }
            });
        }
Beispiel #4
0
            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);
                }
            }
Beispiel #5
0
 private void ThrowIfFrozen()
 {
     if (isFrozen)
     {
         throw FreezableUtils.Error(nameof(DotvvmResourceRepository));
     }
 }
        private void DeleteDataItems(DataItemBuffer dataItems)
        {
            if (mGoogleApiClient.IsConnected)
            {
                // Store the DataItem URIs in a List and close the bugger. Then we use these URIs to delete the DataItems.
                var freezableItems = FreezableUtils.FreezeIterable(dataItems);
                var dataItemList   = new List <IDataItem> ();
                for (int i = 0; i < freezableItems.Count; i++)
                {
                    Log.Verbose(Constants.TAG, "Loop " + i);

                    dataItemList.Add(Android.Runtime.Extensions.JavaCast <IDataItem> ((IJavaObject)freezableItems [i]));
                }
                dataItems.Close();
                if (dataItemList.Count > 0)
                {
                    foreach (IDataItem dataItem in dataItemList)
                    {
                        Android.Net.Uri dataItemUri = dataItem.Uri;
                        // In a real calendar application, this might delete the corresponding calendar event from the calendar
                        // data provider. In this sample, we simply delete the
                        // DataItem, but leave the phone's calendar data intact
                        WearableClass.DataApi.DeleteDataItems(mGoogleApiClient, dataItemUri)
                        .SetResultCallback(new ResultCallback()
                        {
                            OnResultFunc = (Java.Lang.Object deleteResult) => {
                                if (Android.Runtime.Extensions.JavaCast <IDataApiDeleteDataItemsResult>(deleteResult).Status.IsSuccess)
                                {
                                    AppendLog("Successfully deleted data item: " + dataItemUri);
                                }
                                else
                                {
                                    AppendLog("Failed to delete data item: " + dataItemUri);
                                }
                            }
                        });
                    }
                }
                else
                {
                    AppendLog("There are no data items");
                }
            }
            else
            {
                Log.Error(Constants.TAG, "Failed to delete data items" + " - Client disconnected from Google Play Services");
            }
        }
 public void OnResult(DataItemBuffer result)
 {
     if (result.Status.IsSuccess)
     {
         var dataItemList = FreezableUtils.FreezeIterable(result);
         result.Close();
         act.ResetDataItems(dataItemList);
     }
     else
     {
         if (Log.IsLoggable(MainActivity.TAG, LogPriority.Debug))
         {
             Log.Debug(MainActivity.TAG, "Reset quiz: failed to get Data Items to reset");
         }
     }
     result.Close();
 }
Beispiel #8
0
        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);
                }
            }
        }
 public void OnResult(Java.Lang.Object obj)
 {
     if (obj is DataItemBuffer)
     {
         var result = Android.Runtime.Extensions.JavaCast <DataItemBuffer> (obj);
         if (result.Status.IsSuccess)
         {
             var dataItemList = FreezableUtils.FreezeIterable(result);
             result.Close();
             act.ResetDataItems(dataItemList);
         }
         else
         {
             if (Log.IsLoggable(MainActivity.TAG, LogPriority.Debug))
             {
                 Log.Debug(MainActivity.TAG, "Reset quiz: failed to get Data Items to reset");
             }
         }
         result.Close();
     }
 }
Beispiel #10
0
        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()));
                    }
                }
            });
        }
Beispiel #11
0
        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();
        }