private static AdaptiveStackPanel GenerateSubgroup(
            AdaptiveSubgroup subgroup,
            bool isFirstGroup,
            double topMarginOffset,
            Thickness externalMargin)
        {
            AdaptiveStackPanel sp = new AdaptiveStackPanel();

            GenerateItems(
                children: subgroup.Children,
                container: sp.Children,
                isFirstGroup: isFirstGroup,
                isInsideGroup: true,
                topMarginOffset: topMarginOffset,
                externalMargin: externalMargin);

            // If we are in the first group, we apply the top margin to the subgroup
            // because some of the items might have negative margins
            if (isFirstGroup)
            {
                sp.Margin = new Thickness(0, externalMargin.Top, 0, 0);
            }

            return(sp);
        }
示例#2
0
        private TileContent BuildLiveTile(List <ResponsiveNotificationText> messages)
        {
            var results  = messages.ElementAt(0);
            var fixtures = messages.ElementAt(1);

            if (!results.Matches.Any() && !fixtures.Matches.Any())
            {
                return(null);
            }

            TileVisual root = new TileVisual();

            TileBinding wideBinding = new TileBinding();
            TileBindingContentAdaptive wideBindingContent = new TileBindingContentAdaptive();

            wideBinding.Content = wideBindingContent;

            TileBinding largeBinding = new TileBinding();
            TileBindingContentAdaptive largeBindingContent = new TileBindingContentAdaptive();

            largeBinding.Content = largeBindingContent;

            foreach (var notificationGroup in messages)
            {
                if (notificationGroup.Matches.Any())
                {
                    var group    = new AdaptiveGroup();
                    var subgroup = new AdaptiveSubgroup()
                    {
                        HintTextStacking = AdaptiveSubgroupTextStacking.Center
                    };
                    subgroup.Children.Add(new AdaptiveText()
                    {
                        Text      = notificationGroup.MatchType,
                        HintStyle = AdaptiveTextStyle.Body
                    });
                    foreach (var match in notificationGroup.Matches)
                    {
                        subgroup.Children.Add(new AdaptiveText()
                        {
                            Text      = match,
                            HintStyle = AdaptiveTextStyle.Caption
                        });
                    }
                    group.Children.Add(subgroup);
                    wideBindingContent.Children.Add(group);
                    largeBindingContent.Children.Add(group);
                }
            }
            root.TileLarge = largeBinding;
            root.TileWide  = wideBinding;

            return(new TileContent()
            {
                Visual = root
            });
        }
示例#3
0
        private static void AssertAdaptiveSubgroup(string expectedSubgroupXml, AdaptiveSubgroup subgroup)
        {
            AdaptiveGroup group = new AdaptiveGroup()
            {
                Children =
                {
                    subgroup
                }
            };

            AssertAdaptiveChild("<group>" + expectedSubgroupXml + "</group>", group);
        }
        private TileBinding CreateTileBinding(TileSize size, string title, int readingTime, string imageSource)
        {
            var binding = new TileBinding()
            {
                Branding = TileBranding.Logo,
                Content  = new TileBindingContentAdaptive()
            };

            // Create the XML in code
            var group    = new AdaptiveGroup();
            var subgroup = new AdaptiveSubgroup();

            // Add the title to the tile
            var tileTitle = new AdaptiveText()
            {
                Text         = title,
                HintMaxLines = size == TileSize.Large ? 3 : 2,
                HintWrap     = true,
                HintStyle    = size == TileSize.Medium ? AdaptiveTextStyle.Caption : AdaptiveTextStyle.Body
            };

            subgroup.Children.Add(tileTitle);

            // Add the reading time
            string resourceName = size == TileSize.Medium ? "LiveTileReadingTimeShort" : "LiveTileReadingTime";

            subgroup.Children.Add(new AdaptiveText()
            {
                Text      = string.Format(_device.GetLocalizedResource(resourceName), readingTime),
                HintStyle = AdaptiveTextStyle.CaptionSubtle
            });

            // Finally add the subgroup to the tile
            group.Children.Add(subgroup);

            // Add the background image if neccessary
            if (!string.IsNullOrEmpty(imageSource))
            {
                (binding.Content as TileBindingContentAdaptive).BackgroundImage = new TileBackgroundImage()
                {
                    Source      = imageSource,
                    HintOverlay = 60
                };
            }

            // Add the group to the tile
            (binding.Content as TileBindingContentAdaptive).Children.Add(group);

            return(binding);
        }
示例#5
0
        private ToastContent BuildNotification(List <ResponsiveNotificationText> messages)
        {
            ToastVisual         root    = new ToastVisual();
            ToastBindingGeneric binding = new ToastBindingGeneric();

            root.BindingGeneric = binding;

            var results  = messages.ElementAt(0);
            var fixtures = messages.ElementAt(1);

            if (!fixtures.Matches.Any() && !results.Matches.Any())
            {
                return(null);
            }

            foreach (var notificationGroup in messages)
            {
                if (notificationGroup.Matches.Any())
                {
                    var group    = new AdaptiveGroup();
                    var subgroup = new AdaptiveSubgroup()
                    {
                        HintTextStacking = AdaptiveSubgroupTextStacking.Center
                    };
                    subgroup.Children.Add(new AdaptiveText()
                    {
                        Text      = notificationGroup.MatchType,
                        HintStyle = AdaptiveTextStyle.Subtitle
                    });
                    foreach (var match in notificationGroup.Matches)
                    {
                        subgroup.Children.Add(new AdaptiveText()
                        {
                            Text      = match,
                            HintStyle = AdaptiveTextStyle.BaseSubtle
                        });
                    }
                    group.Children.Add(subgroup);
                    binding.Children.Add(group);
                }
            }
            return(new ToastContent()
            {
                Visual = root
            });
        }
示例#6
0
        private static TileBindingContentAdaptive CreateTileContent(string prefix, string leftTitle, string leftValue, string rightTitle, string rightValuevalue, string dateTitle, string dateContent)
        {
            //Create a TileContent
            var tileContent = new TileBindingContentAdaptive();

            tileContent.TextStacking = TileTextStacking.Center;
            //Create a groups and subgroups
            var tileGroup = new AdaptiveGroup();

            AdaptiveSubgroup columnGroupLeft   = CreateAdaptiveGroupColumn(prefix + " " + leftTitle, leftValue, dateTitle);
            AdaptiveSubgroup CoulumnGroupRight = CreateAdaptiveGroupColumn(prefix + " " + rightTitle, rightValuevalue, dateContent);

            tileGroup.Children.Add(columnGroupLeft);
            tileGroup.Children.Add(CoulumnGroupRight);


            tileContent.Children.Add(tileGroup);
            return(tileContent);
        }
示例#7
0
        private static AdaptiveSubgroup CreateAdaptiveGroupColumn(string title, string value, string dateValue)
        {
            AdaptiveSubgroup adaptiveColumnGroup = new AdaptiveSubgroup();
            var contentTitle = new AdaptiveText();

            contentTitle.Text = title;

            var contenteValue = new AdaptiveText();

            contenteValue.Text = value;

            var contentDate = new AdaptiveText();

            contentDate.Text = dateValue;

            adaptiveColumnGroup.Children.Add(contentTitle);
            adaptiveColumnGroup.Children.Add(contenteValue);
            adaptiveColumnGroup.Children.Add(contentDate);
            return(adaptiveColumnGroup);
        }
        private static AdaptiveGroup GenerateTileNotificationMediumGroupContent(ViewItemSchedule schedule)
        {
            AdaptiveSubgroup subgroup = new AdaptiveSubgroup()
            {
                Children =
                {
                    new AdaptiveText()
                    {
                        Text = TrimString(schedule.Class.Name, 40)
                    },

                    new AdaptiveText()
                    {
                        Text      = GetTimeString(schedule.StartTime),
                        HintStyle = AdaptiveTextStyle.TitleNumeral
                    }
                }
            };

            if (!string.IsNullOrWhiteSpace(schedule.Room))
            {
                subgroup.Children.Add(new AdaptiveText()
                {
                    Text      = TrimString(schedule.Room, 40),
                    HintStyle = AdaptiveTextStyle.CaptionSubtle,
                    HintWrap  = true
                });
            }

            return(new AdaptiveGroup()
            {
                Children =
                {
                    subgroup
                }
            });
        }
        public ToastNotification CreateCallNotification(IEnumerable <Call> currentCalls)
        {
            List <Call>         calls   = currentCalls.Where(x => x.State != CallState.Disconnected && x.State != CallState.Indeterminate).OrderBy(x => x.State).ToList();
            ToastBindingGeneric content = new ToastBindingGeneric();
            ToastActionsCustom  actions = new ToastActionsCustom();

            switch (calls.Count)
            {
            case 0:
                return(null);

            case 1:
                Call singleCall = calls.First();
                foreach (IToastBindingGenericChild child in CreateVisualForCall(singleCall))
                {
                    content.Children.Add(child);
                }
                foreach (IToastButton button in CreateButtonsForCall(singleCall))
                {
                    actions.Buttons.Add(button);
                }
                break;

            default:
                content.Children.Add(new AdaptiveText()
                {
                    Text = "Dialer - Active calls"
                });
                for (int i0 = 0; i0 < calls.Count / 2; i0++)
                {
                    AdaptiveGroup group = new AdaptiveGroup();
                    for (int i1 = i0 * 2; i1 < i0 * 2 + 2 && i1 < calls.Count; i1++)
                    {
                        AdaptiveSubgroup subgroup = new AdaptiveSubgroup();
                        foreach (IAdaptiveSubgroupChild child in CreateVisualForCall(calls[i1]))
                        {
                            subgroup.Children.Add(child);
                        }
                        group.Children.Add(subgroup);
                    }
                    content.Children.Add(group);
                }
                foreach (IToastButton button in MergeButtons(calls.Select(x => CreateButtonsForCall(x)).SelectMany(x => x)))
                {
                    actions.Buttons.Add(button);
                }
                break;
            }
            Call         incomingCall = calls.FirstOrDefault(x => x.State == CallState.Incoming);
            bool         hasRingTone  = !string.IsNullOrEmpty(incomingCall?.Contact?.RingToneToken);
            ToastContent toastContent = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = content
                },
                Actions = actions,
                Audio   = new ToastAudio()
                {
                    Silent = calls.Any(x => x.State != CallState.Incoming),
                    Loop   = true,
                    Src    = hasRingTone ? new Uri(incomingCall.Contact.RingToneToken) : null
                },
                Launch   = $"{ACTION}={SHOW_CALL_UI}",
                Scenario = ToastScenario.IncomingCall
            };
            ToastNotification notification = new ToastNotification(toastContent.GetXml())
            {
                Tag             = CALL_NOTIFICATION_UI,
                ExpiresOnReboot = true,
                Priority        = ToastNotificationPriority.High,
                Data            = new NotificationData()
                {
                    Values =
                    {
                        { USED_CALLS,        calls.Aggregate(new StringBuilder(), (x, y) => x.Append(y.ID).Append(';'),          x => x.ToString()) },
                        { USED_CALLS_STATES, calls.Aggregate(new StringBuilder(), (x, y) => x.Append((uint)y.State).Append(';'), x => x.ToString()) }
                    }
                }
            };

            return(notification);
        }
示例#10
0
 private static void AssertAdaptiveSubgroupProperty(string expectedPropertyName, string expectedPropertyValue, AdaptiveSubgroup subgroup)
 {
     AssertAdaptiveSubgroup($"<subgroup {expectedPropertyName}='{expectedPropertyValue}' />", subgroup);
 }
示例#11
0
        private static TileBindingContentAdaptive GenerateCondition(Weather weather, ForecastTileType forecastTileType)
        {
            var userlang = GlobalizationPreferences.Languages[0];
            var culture  = new CultureInfo(userlang);

            var content = new TileBindingContentAdaptive
            {
                // Background URI
                BackgroundImage = new TileBackgroundImage()
                {
                    Source = wm.GetBackgroundURI(weather)
                }
            };

            if (forecastTileType == ForecastTileType.Small)
            {
                content.Children.Add(new AdaptiveGroup()
                {
                    Children =
                    {
                        new AdaptiveSubgroup()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text      = weather.update_time.ToString("ddd", culture),
                                    HintStyle = AdaptiveTextStyle.Base,
                                    HintAlign = AdaptiveTextAlign.Center
                                },
                                new AdaptiveText()
                                {
                                    Text      = (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º",
                                    HintStyle = AdaptiveTextStyle.Body,
                                    HintAlign = AdaptiveTextAlign.Center
                                }
                            }
                        }
                    }
                });
            }
            else if (forecastTileType == ForecastTileType.Medium)
            {
                content.Children.Add(new AdaptiveGroup()
                {
                    Children =
                    {
                        new AdaptiveSubgroup()
                        {
                            HintWeight = 1,
                            Children   =
                            {
                                new AdaptiveText()
                                {
                                    Text = null
                                }
                            }
                        },
                        new AdaptiveSubgroup()
                        {
                            HintWeight       = 3,
                            HintTextStacking = AdaptiveSubgroupTextStacking.Center,
                            Children         =
                            {
                                new AdaptiveImage()
                                {
                                    HintRemoveMargin = true,
                                    Source           = wm.GetWeatherIconURI(weather.condition.icon)
                                },
                                new AdaptiveText()
                                {
                                    Text      = (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º",
                                    HintStyle = AdaptiveTextStyle.Body,
                                    HintAlign = AdaptiveTextAlign.Center,
                                }
                            }
                        },
                        new AdaptiveSubgroup()
                        {
                            HintWeight = 1,
                            Children   =
                            {
                                new AdaptiveText()
                                {
                                    Text = null
                                }
                            }
                        }
                    }
                });
            }
            else if (forecastTileType == ForecastTileType.Wide)
            {
                // Current Condition (Extended)
                var forecastGroup = new AdaptiveGroup();

                var condition = new AdaptiveSubgroup()
                {
                    HintWeight = 25,
                    Children   =
                    {
                        new AdaptiveImage()
                        {
                            HintRemoveMargin = true,
                            Source           = wm.GetWeatherIconURI(weather.condition.icon)
                        }
                    },
                    HintTextStacking = AdaptiveSubgroupTextStacking.Center
                };
                var details = new AdaptiveSubgroup()
                {
                    HintWeight = 75,
                    Children   =
                    {
                        new AdaptiveText()
                        {
                            Text      = (String.IsNullOrWhiteSpace(weather.condition.weather)) ? "---" : weather.condition.weather,
                            HintStyle = AdaptiveTextStyle.Caption
                        },
                        new AdaptiveText()
                        {
                            Text = string.Format("{0}: {1}", App.ResLoader.GetString("Temp_Label"),
                                                 (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º"),
                            HintStyle = AdaptiveTextStyle.Caption
                        },
                        new AdaptiveText()
                        {
                            Text = string.Format("{0}: {1}", App.ResLoader.GetString("FeelsLike_Label"),
                                                 (Settings.IsFahrenheit ? Math.Round(weather.condition.feelslike_f) : Math.Round(weather.condition.feelslike_c)) + "º"),
                            HintStyle = AdaptiveTextStyle.CaptionSubtle
                        },
                        new AdaptiveText()
                        {
                            Text = string.Format("{0}: {1}", App.ResLoader.GetString("Wind_Label"),
                                                 Settings.IsFahrenheit ? Math.Round(weather.condition.wind_mph) + " mph" : Math.Round(weather.condition.wind_kph) + " kph"),
                            HintStyle = AdaptiveTextStyle.CaptionSubtle
                        }
                    }
                };

                forecastGroup.Children.Add(condition);
                forecastGroup.Children.Add(details);
                content.Children.Add(forecastGroup);
            }
            else if (forecastTileType == ForecastTileType.Large)
            {
                // Condition + 5-day forecast
                var forecastGroup = new AdaptiveGroup();
                var condition     = weather.condition;

                int forecastLength = LARGE_FORECAST_LENGTH;
                if (weather.forecast.Length < forecastLength)
                {
                    forecastLength = weather.forecast.Length;
                }

                var conditionGroup = new AdaptiveGroup()
                {
                    Children =
                    {
                        new AdaptiveSubgroup()
                        {
                            HintWeight       = 25,
                            HintTextStacking = AdaptiveSubgroupTextStacking.Center,
                            Children         =
                            {
                                new AdaptiveImage()
                                {
                                    Source = wm.GetWeatherIconURI(weather.condition.icon)
                                }
                            }
                        },
                        new AdaptiveSubgroup()
                        {
                            HintWeight = 75,
                            Children   =
                            {
                                new AdaptiveText()
                                {
                                    Text      = (String.IsNullOrWhiteSpace(weather.condition.weather)) ? "---" : weather.condition.weather,
                                    HintStyle = AdaptiveTextStyle.Caption
                                },
                                new AdaptiveText()
                                {
                                    Text = string.Format("{0}: {1}", App.ResLoader.GetString("Temp_Label"),
                                                         (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º"),
                                    HintStyle = AdaptiveTextStyle.Caption
                                },
                                new AdaptiveText()
                                {
                                    Text = string.Format("{0}: {1}", App.ResLoader.GetString("FeelsLike_Label"),
                                                         (Settings.IsFahrenheit ? Math.Round(weather.condition.feelslike_f) : Math.Round(weather.condition.feelslike_c)) + "º"),
                                    HintStyle = AdaptiveTextStyle.CaptionSubtle
                                },
                                new AdaptiveText()
                                {
                                    Text = string.Format("{0}: {1}", App.ResLoader.GetString("Wind_Label"),
                                                         Settings.IsFahrenheit ? Math.Round(weather.condition.wind_mph) + " mph" : Math.Round(weather.condition.wind_kph) + " kph"),
                                    HintStyle = AdaptiveTextStyle.CaptionSubtle
                                }
                            }
                        }
                    }
                };
                var text = new AdaptiveText()
                {
                    Text = ""
                };

                for (int i = 0; i < forecastLength; i++)
                {
                    var forecast = weather.forecast[i];

                    var subgroup = new AdaptiveSubgroup()
                    {
                        HintWeight = 1,
                        Children   =
                        {
                            new AdaptiveText()
                            {
                                Text      = forecast.date.ToString("ddd", culture),
                                HintAlign = AdaptiveTextAlign.Center
                            },
                            new AdaptiveImage()
                            {
                                HintRemoveMargin = true,
                                Source           = wm.GetWeatherIconURI(forecast.icon)
                            },
                            new AdaptiveText()
                            {
                                Text = (Settings.IsFahrenheit ?
                                        Math.Round(double.Parse(forecast.high_f)).ToString() : Math.Round(double.Parse(forecast.high_c)).ToString()) + "º",
                                HintAlign = AdaptiveTextAlign.Center
                            },
                            new AdaptiveText()
                            {
                                Text = (Settings.IsFahrenheit ?
                                        Math.Round(double.Parse(forecast.low_f)).ToString() : Math.Round(double.Parse(forecast.low_c)).ToString()) + "º",
                                HintStyle = AdaptiveTextStyle.CaptionSubtle,
                                HintAlign = AdaptiveTextAlign.Center
                            }
                        }
                    };

                    forecastGroup.Children.Add(subgroup);
                }

                content.Children.Add(conditionGroup);
                content.Children.Add(text);
                content.Children.Add(forecastGroup);
            }

            return(content);
        }
示例#12
0
        private static TileBindingContentAdaptive GenerateHrForecast(Weather weather, ForecastTileType forecastTileType)
        {
            var userlang = GlobalizationPreferences.Languages[0];
            var culture  = new CultureInfo(userlang);

            var content = new TileBindingContentAdaptive
            {
                // Background URI
                BackgroundImage = new TileBackgroundImage()
                {
                    Source = wm.GetBackgroundURI(weather)
                }
            };

            if (forecastTileType == ForecastTileType.Small)
            {
                content.Children.Add(new AdaptiveGroup()
                {
                    Children =
                    {
                        new AdaptiveSubgroup()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text      = weather.update_time.ToString("ddd", culture),
                                    HintStyle = AdaptiveTextStyle.Base,
                                    HintAlign = AdaptiveTextAlign.Center
                                },
                                new AdaptiveText()
                                {
                                    Text      = (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º",
                                    HintStyle = AdaptiveTextStyle.Body,
                                    HintAlign = AdaptiveTextAlign.Center
                                }
                            }
                        }
                    }
                });
            }
            else if (forecastTileType == ForecastTileType.Medium)
            {
                var dateGroup     = new AdaptiveGroup();
                var forecastGroup = new AdaptiveGroup();
                var tempGroup     = new AdaptiveGroup();

                string timeformat = culture.DateTimeFormat.ShortTimePattern.Contains("H") ?
                                    "HH" : "ht";

                int forecastLength = MEDIUM_FORECAST_LENGTH;
                if (weather.hr_forecast.Length < forecastLength)
                {
                    forecastLength = weather.hr_forecast.Length;
                }

                // 3hr forecast
                for (int i = 0; i < forecastLength; i++)
                {
                    var hrforecast = weather.hr_forecast[i];

                    var dateSubgroup = new AdaptiveSubgroup()
                    {
                        HintWeight = 1,
                        Children   =
                        {
                            new AdaptiveText()
                            {
                                Text      = hrforecast.date.ToString(timeformat, culture).ToLower(),
                                HintAlign = AdaptiveTextAlign.Center
                            },
                        }
                    };
                    var iconSubgroup = new AdaptiveSubgroup()
                    {
                        HintWeight = 1,
                        Children   =
                        {
                            new AdaptiveImage()
                            {
                                HintRemoveMargin = true,
                                Source           = wm.GetWeatherIconURI(hrforecast.icon)
                            },
                        }
                    };
                    var tempSubgroup = new AdaptiveSubgroup()
                    {
                        HintWeight       = 1,
                        HintTextStacking = AdaptiveSubgroupTextStacking.Bottom,
                        Children         =
                        {
                            new AdaptiveText()
                            {
                                Text = (Settings.IsFahrenheit ?
                                        Math.Round(double.Parse(hrforecast.high_f)).ToString() : Math.Round(double.Parse(hrforecast.high_c)).ToString()) + "º",
                                HintStyle = AdaptiveTextStyle.Caption,
                                HintAlign = AdaptiveTextAlign.Center
                            }
                        }
                    };

                    dateGroup.Children.Add(dateSubgroup);
                    forecastGroup.Children.Add(iconSubgroup);
                    tempGroup.Children.Add(tempSubgroup);
                }

                content.Children.Add(dateGroup);
                content.Children.Add(forecastGroup);
                content.Children.Add(tempGroup);
            }
            else if (forecastTileType == ForecastTileType.Wide)
            {
                // 5-hr forecast
                var forecastGroup = new AdaptiveGroup();

                string timeformat = culture.DateTimeFormat.ShortTimePattern.Contains("H") ?
                                    "HH" : "ht";

                int forecastLength = LARGE_FORECAST_LENGTH;
                if (weather.hr_forecast.Length < forecastLength)
                {
                    forecastLength = weather.hr_forecast.Length;
                }

                for (int i = 0; i < forecastLength; i++)
                {
                    var hrforecast = weather.hr_forecast[i];

                    var subgroup = new AdaptiveSubgroup()
                    {
                        HintWeight = 1,
                        Children   =
                        {
                            new AdaptiveText()
                            {
                                Text      = hrforecast.date.ToString(timeformat, culture).ToLower(),
                                HintAlign = AdaptiveTextAlign.Center
                            },
                            new AdaptiveImage()
                            {
                                HintRemoveMargin = true,
                                Source           = wm.GetWeatherIconURI(hrforecast.icon)
                            },
                            new AdaptiveText()
                            {
                                Text = (Settings.IsFahrenheit ?
                                        Math.Round(double.Parse(hrforecast.high_f)).ToString() : Math.Round(double.Parse(hrforecast.high_c)).ToString()) + "º",
                                HintAlign = AdaptiveTextAlign.Center
                            },
                        }
                    };

                    forecastGroup.Children.Add(subgroup);
                }

                content.Children.Add(forecastGroup);
            }
            else if (forecastTileType == ForecastTileType.Large)
            {
                // Condition + 5-hr forecast
                var forecastGroup = new AdaptiveGroup();

                string timeformat = culture.DateTimeFormat.ShortTimePattern.Contains("H") ?
                                    "HH" : "ht";
                string poplabel = (weather.source.Equals(WeatherAPI.OpenWeatherMap) || weather.source.Equals(WeatherAPI.MetNo)) ?
                                  App.ResLoader.GetString("Cloudiness_Label") : App.ResLoader.GetString("Precipitation_Label"); // Cloudiness or Precipitation

                int forecastLength = LARGE_FORECAST_LENGTH;
                if (weather.hr_forecast.Length < forecastLength)
                {
                    forecastLength = weather.hr_forecast.Length;
                }

                var conditionGroup = new AdaptiveGroup()
                {
                    Children =
                    {
                        new AdaptiveSubgroup()
                        {
                            HintWeight       = 25,
                            HintTextStacking = AdaptiveSubgroupTextStacking.Center,
                            Children         =
                            {
                                new AdaptiveImage()
                                {
                                    Source = wm.GetWeatherIconURI(weather.condition.icon)
                                }
                            }
                        },
                        new AdaptiveSubgroup()
                        {
                            HintWeight = 75,
                            Children   =
                            {
                                new AdaptiveText()
                                {
                                    Text      = (String.IsNullOrWhiteSpace(weather.condition.weather)) ? "---" : weather.condition.weather,
                                    HintStyle = AdaptiveTextStyle.Caption
                                },
                                new AdaptiveText()
                                {
                                    Text = string.Format("{0}: {1}", App.ResLoader.GetString("Temp_Label"),
                                                         (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º"),
                                    HintStyle = AdaptiveTextStyle.Caption
                                },
                                new AdaptiveText()
                                {
                                    Text = string.Format("{0}: {1}", App.ResLoader.GetString("FeelsLike_Label"),
                                                         (Settings.IsFahrenheit ? Math.Round(weather.condition.feelslike_f) : Math.Round(weather.condition.feelslike_c)) + "º"),
                                    HintStyle = AdaptiveTextStyle.CaptionSubtle
                                },
                                new AdaptiveText()
                                {
                                    Text = string.Format("{0}: {1}", App.ResLoader.GetString("Wind_Label"),
                                                         Settings.IsFahrenheit ? Math.Round(weather.condition.wind_mph) + " mph" : Math.Round(weather.condition.wind_kph) + " kph"),
                                    HintStyle = AdaptiveTextStyle.CaptionSubtle
                                },
                                new AdaptiveText()
                                {
                                    Text = weather.precipitation != null ?
                                           string.Format("{0}: {1}", poplabel, weather.precipitation.pop + "%") : "",
                                    HintStyle = AdaptiveTextStyle.CaptionSubtle
                                }
                            }
                        }
                    }
                };
                var text = new AdaptiveText()
                {
                    Text = ""
                };

                for (int i = 0; i < forecastLength; i++)
                {
                    var hrforecast = weather.hr_forecast[i];

                    var subgroup = new AdaptiveSubgroup()
                    {
                        HintWeight = 1,
                        Children   =
                        {
                            new AdaptiveText()
                            {
                                Text      = hrforecast.date.ToString(timeformat, culture).ToLower(),
                                HintAlign = AdaptiveTextAlign.Center
                            },
                            new AdaptiveImage()
                            {
                                HintRemoveMargin = true,
                                Source           = wm.GetWeatherIconURI(hrforecast.icon)
                            },
                            new AdaptiveText()
                            {
                                Text = (Settings.IsFahrenheit ?
                                        Math.Round(double.Parse(hrforecast.high_f)).ToString() : Math.Round(double.Parse(hrforecast.high_c)).ToString()) + "º",
                                HintAlign = AdaptiveTextAlign.Center
                            },
                        }
                    };

                    forecastGroup.Children.Add(subgroup);
                }

                content.Children.Add(conditionGroup);
                content.Children.Add(text);
                content.Children.Add(forecastGroup);
            }

            return(content);
        }
 private static void AssertAdaptiveSubgroupProperty(string expectedPropertyName, string expectedPropertyValue, AdaptiveSubgroup subgroup)
 {
     AssertAdaptiveSubgroup($"<subgroup {expectedPropertyName}='{expectedPropertyValue}' />", subgroup);
 }
        private static void AssertAdaptiveSubgroup(string expectedSubgroupXml, AdaptiveSubgroup subgroup)
        {
            AdaptiveGroup group = new AdaptiveGroup()
            {
                Children =
                {
                    subgroup
                }
            };

            AssertAdaptiveChild("<group>" + expectedSubgroupXml + "</group>", group);
        }
示例#15
0
        private AdaptiveGroup GetAdaptiveGroup(ScheduleEntryViewModel entry, TileSize size, bool subtle, bool addSpacing)
        {
            AdaptiveSubgroup subgroup;

            switch (size)
            {
            case TileSize.Large:
                subgroup = new AdaptiveSubgroup()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text      = entry.Name,
                            HintStyle = subtle ? AdaptiveTextStyle.BaseSubtle : AdaptiveTextStyle.Base
                        },
                        new AdaptiveText()
                        {
                            Text      = entry.TimeRangeRoomDisplay,
                            HintStyle = subtle ? AdaptiveTextStyle.CaptionSubtle : AdaptiveTextStyle.Caption
                        }
                    }
                };
                break;

            case TileSize.Wide:
                subgroup = new AdaptiveSubgroup()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text      = entry.Name,
                            HintStyle = subtle ? AdaptiveTextStyle.BaseSubtle : AdaptiveTextStyle.Base
                        },
                        new AdaptiveText()
                        {
                            Text      = entry.TimeRangeRoomDisplay,
                            HintStyle = AdaptiveTextStyle.CaptionSubtle
                        }
                    }
                };
                break;

            case TileSize.Medium:
                subgroup = new AdaptiveSubgroup()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text         = entry.Name,
                            HintWrap     = true,
                            HintMaxLines = 2,
                            HintStyle    = subtle ? AdaptiveTextStyle.BaseSubtle : AdaptiveTextStyle.Base
                        },
                        new AdaptiveText()
                        {
                            Text      = entry.TimeRangeDisplay,
                            HintStyle = AdaptiveTextStyle.CaptionSubtle
                        },
                        new AdaptiveText()
                        {
                            Text      = entry.Room,
                            HintStyle = AdaptiveTextStyle.CaptionSubtle
                        }
                    }
                };
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(size));
            }

            if (addSpacing)
            {
                subgroup.Children.Add(new AdaptiveText()
                {
                    HintStyle = AdaptiveTextStyle.Caption
                });
            }

            return(new AdaptiveGroup()
            {
                Children =
                {
                    subgroup
                }
            });
        }