private ComplicationData BuildUpdate(int dataType, Weather weather)
        {
            if (weather?.IsValid() == false || (dataType != ComplicationData.TypeShortText && dataType != ComplicationData.TypeLongText))
            {
                return(null);
            }
            else
            {
                // Temperature
                string temp = Settings.IsFahrenheit ?
                              Math.Round(weather.condition.temp_f) + "º" : Math.Round(weather.condition.temp_c) + "º";
                // Weather Icon
                int weatherIcon = wm.GetWeatherIconResource(weather.condition.icon);
                // Condition text
                string condition = weather.condition.weather;

                var builder = new ComplicationData.Builder(dataType);
                if (dataType == ComplicationData.TypeShortText)
                {
                    builder.SetShortText(ComplicationText.PlainText(temp));
                }
                else if (dataType == ComplicationData.TypeLongText)
                {
                    builder.SetLongText(ComplicationText.PlainText(String.Format("{0}: {1}", condition, temp)));
                }

                builder.SetIcon(Icon.CreateWithResource(this, weatherIcon))
                .SetTapAction(GetTapIntent(this));

                return(builder.Build());
            }
        }
Ejemplo n.º 2
0
        public override void OnComplicationUpdate(int complicationId, int dataType, ComplicationManager complicationManager)
        {
            Log($"OnComplicationUpdate dataType={dataType}");
            var num = new Random((int)Java.Lang.JavaSystem.CurrentTimeMillis()).Next(10, 75);
            ComplicationData complicationData = null;

            switch (dataType)
            {
            case ComplicationData.TypeShortText:
                Log($"OnComplicationUpdate dataType=ShortText");
                complicationData = new ComplicationData.Builder(ComplicationData.TypeShortText)
                                   .SetShortText(ComplicationText.PlainText($"Luck {num}"))
                                   .Build();
                break;

            default:
                Log($"Unexpected complication type {dataType}");
                break;
            }
            if (complicationData != null)
            {
                complicationManager.UpdateComplicationData(complicationId, complicationData);
            }
            else
            {
                complicationManager.NoUpdateRequired(complicationId);
            }
        }