예제 #1
0
        void UpdateConfigDataItem(int backgroundColor)
        {
            var configKeysToOverwrite = new DataMap();

            configKeysToOverwrite.PutInt(DigitalWatchFaceUtil.KeyBackgroundColor, backgroundColor);
            DigitalWatchFaceUtil.OverwriteKeysInConfigDataMap(googleApiClient, configKeysToOverwrite);
        }
        public static void OverwriteKeysInConfigDataMap(IGoogleApiClient googleApiClient, DataMap configKeysToOverwrite)
        {
            FetchConfigDataMap(googleApiClient,
                               new DataItemResultCallback(dataItemResult => {
                var overwrittenConfig = new DataMap();

                if (dataItemResult.DataItem != null)
                {
                    var dataItem      = dataItemResult.DataItem;
                    var dataMapItem   = DataMapItem.FromDataItem(dataItem);
                    var currentConfig = dataMapItem.DataMap;
                    overwrittenConfig.PutAll(currentConfig);
                }

                overwrittenConfig.PutAll(configKeysToOverwrite);
                DigitalWatchFaceUtil.PutConfigDataItem(googleApiClient, overwrittenConfig);
            })
                               );
        }
예제 #3
0
            void UpdateConfigDataItemAndUiOnStartup()
            {
                DigitalWatchFaceUtil.FetchConfigDataMap(googleApiClient,
                                                        new DigitalWatchFaceUtil.DataItemResultCallback(dataItemResult => {
                    if (dataItemResult.DataItem != null)
                    {
                        var dataItem = dataItemResult.DataItem;
                        if (dataItem != null)
                        {
                            var dataMapItem   = DataMapItem.FromDataItem(dataItem);
                            var startupConfig = dataMapItem.DataMap;

                            SetDefaultValuesForMissingKeys(startupConfig);
                            DigitalWatchFaceUtil.PutConfigDataItem(googleApiClient, startupConfig);
                            UpdateUiForConfigDataMap(startupConfig);
                        }
                    }
                })
                                                        );
            }
예제 #4
0
        public override void OnMessageReceived(IMessageEvent messageEvent)
        {
            if (!messageEvent.Path.Equals(DigitalWatchFaceUtil.PathWithFeature))
            {
                return;
            }
            var rawData = messageEvent.GetData();

            // It's allowed that the message carries only some of the keys used in the config DataItem
            // and skips the ones that we don't want to change.
            var configKeysToOverwrite = DataMap.FromByteArray(rawData);

            if (Log.IsLoggable(Tag, LogPriority.Debug))
            {
                Log.Debug(Tag, "Received watch face config message: " + configKeysToOverwrite);
            }

            if (googleApiClient == null)
            {
                googleApiClient = new GoogleApiClientBuilder(this)
                                  .AddConnectionCallbacks(this)
                                  .AddOnConnectionFailedListener(this)
                                  .AddApi(WearableClass.Api)
                                  .Build();
            }
            if (!googleApiClient.IsConnected)
            {
                var connectionResult = googleApiClient.BlockingConnect(30, TimeUnit.Seconds);
                if (!connectionResult.IsSuccess)
                {
                    Log.Error(Tag, "Failed to connect to GoogleApiClient.");
                    return;
                }
            }

            DigitalWatchFaceUtil.OverwriteKeysInConfigDataMap(googleApiClient, configKeysToOverwrite);
        }