Пример #1
0
        private async Task LoadNearestCinema()
        {
            Geolocator locator = new Geolocator();

            Exception e = null;

            if (App.UserPosition == null)
            {
                try
                {
                    Geoposition pos = await locator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(20));

                    if (pos == null)
                    {
                        return;
                    }

                    App.UserPosition = pos.Coordinate.Point;
                }
                catch (Exception ex)
                {
                    e = ex;
                }
            }

            if (App.UserPosition != null)
            {
                IEnumerable <CinemaInfo> oc = App.Cinemas.Values.OrderBy(c => GeoMath.Distance(App.UserPosition.Position.Latitude, App.UserPosition.Position.Longitude, c.Latitude, c.Longitute, GeoMath.MeasureUnits.Miles)).Take(9);
                if (oc.Count() > 0)
                {
                    foreach (var cinema in oc)
                    {
                        int iCin = cinema.ID;

                        if (!PinnedCinemas.Contains(iCin))
                        {
                            if (App.Cinemas.ContainsKey(iCin))
                            {
                                PinnedCinemas.Add(iCin);

                                CinemaInfo ci      = App.Cinemas[iCin];
                                string     message = null;
                                try
                                {
                                    this.SetTile(iCin, ci, "Nearest");
                                }
                                catch (Exception ex)
                                {
                                    message = ex.Message;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void SetTile(int iCin, CinemaInfo ci = null, string additionalTextualInfo = null)
        {
            Tile t = new Tile()
            {
                CommandParameter = iCin,
                Margin           = new Thickness(0, 0, 10, 10),
                Width            = 200,
                Height           = 200,
                Foreground       = new SolidColorBrush(Colors.White),
                Background       = new ImageBrush()
                {
                    ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/Background.png")),
                    Stretch     = Stretch.UniformToFill
                }
            };

            Grid g = new Grid();

            g.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            g.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });
            g.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Auto)
            });

            TextBlock tbTopText = new TextBlock()
            {
                Margin = new Thickness(10), VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom, TextWrapping = TextWrapping.Wrap
            };
            StringBuilder sb = new StringBuilder();

            if (ci == null)
            {
                tbTopText.Text = "All Cinemas";
                sb.AppendLine("Click to view all cineworld cinemas");
            }
            else
            {
                tbTopText.Text = ci.Name;
                sb.AppendFormat("Click to view whats on at Cineworld {0}\n", ci.Name);
            }
            t.Click += Tile_Click;


            Border bTop = new Border()
            {
                Background = new SolidColorBrush(Colors.Gray), Opacity = 0.7
            };

            bTop.Child = tbTopText;

            Grid.SetColumn(bTop, 0);
            Grid.SetRow(bTop, 0);

            g.Children.Add(bTop);

            if (ci != null)
            {
                TextBlock tbBottomText = new TextBlock()
                {
                    Text = additionalTextualInfo, Margin = new Thickness(10), VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top
                };
                if (App.UserPosition != null)
                {
                    tbBottomText.Text = String.Format("{0:N2} {1}", GeoMath.Distance(App.UserPosition.Position.Latitude, App.UserPosition.Position.Longitude, ci.Latitude, ci.Longitute, Config.Region == Config.RegionDef.UK ? GeoMath.MeasureUnits.Miles : GeoMath.MeasureUnits.Kilometers), (Config.Region == Config.RegionDef.UK ? GeoMath.MeasureUnits.Miles : GeoMath.MeasureUnits.Kilometers).ToString());

                    sb.AppendFormat("{0} from here", tbBottomText.Text);
                }
                else
                {
                    tbBottomText.Text = additionalTextualInfo;
                }

                Border bBottom = new Border()
                {
                    Background = new SolidColorBrush(Colors.Gray), Opacity = 0.9
                };
                bBottom.Child = tbBottomText;

                Grid.SetColumn(bBottom, 0);
                Grid.SetRow(bBottom, 2);
                g.Children.Add(bBottom);
            }

            ToolTipService.SetToolTip(t, sb.ToString());

            t.Content = g;

            this.wpHubTiles.Children.Add(t);
        }