Beispiel #1
0
 private void UpdateBusLocationsThread()
 {
     while (true)
     {
         var ctime = new StopTime(DateTime.Now);
         for (var a = 0; a < _mapContent.TripPointers.Length; a++)
         {
             var isDelayed = MapUtil.IsTripDelayed(_mapContent.Trips[a].Id);
             var pos       = _mapContent.Trips[a].GetBusLocation(ctime);
             var cpointer  = _mapContent.TripPointers[a];
             if (pos == null)
             {
                 continue;
             }
             if (cpointer >= _mapContent.Map.Pins.Count)
             {
                 continue;
             }
             if (cpointer == -1)
             {
                 _mapContent.TripPointers[a] = _mapContent.Map.Pins.Count;
                 pos.Pin(_mapContent.Map.Pins, isDelayed ? _mapContent.Map.DelayedBusIndices : null, _mapContent.Trips[a].Id);
             }
             else
             {
                 _mapContent.Map.Pins[cpointer].Position = new Position(pos.Latitude, pos.Longitude);
             }
         }
         if (_mapContent.Map.OnPinsUpdated != null)
         {
             Device.BeginInvokeOnMainThread(() => { _mapContent.Map.OnPinsUpdated(); });
         }
     }
 }
Beispiel #2
0
        private MapContent()
        {
            Trips        = MapUtil.GetDefaultTripFile();
            TripPointers = new int[Trips.Count];

            Console.WriteLine("Est. Screen size: " + App.GetScreenWidth() + ", " + App.GetScreenHeight());

            Map             = new DefaultMap();
            FavoritesButton = new Button {
                HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.End,
                WidthRequest      = 50, HeightRequest = 50,
                Image             = (FileImageSource)(ImageSource.FromFile("Star_Button.png")),
                BackgroundColor   = new Color(0, 1, 0),
                Margin            = new Thickness(10, 0, 0, 10),
                #if __IOS__
                CornerRadius = 25,
                #endif
            };

            SettingsButton = new Button {
                HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.End,
                WidthRequest      = 50, HeightRequest = 50,
                Image             = (FileImageSource)(ImageSource.FromFile("Settings_Button.png")),
                BackgroundColor   = new Color(0, 1, 0),
                Margin            = new Thickness(0, 0, 10, 10),
                #if __IOS__
                CornerRadius = 25,
                #endif
            };

            var rightNow = new StopTime(DateTime.Now);

            for (var a = 0; a < Trips.Count; a++)
            {
                var            isDelayed = MapUtil.IsTripDelayed(Trips[a].Id);
                Utility.Vertex vert      = Trips[a].GetBusLocation(rightNow);
                TripPointers[a] = Map.Pins.Count;
                if (vert == null)
                {
                    continue;
                }
                vert.Pin(Map.Pins, (!_taggedRandomBus || isDelayed) ? Map.DelayedBusIndices : null, Trips[a].Id);
                _taggedRandomBus = true;
            }

            MapUtil.Favorites.OnFavouriteAdded += UpdateServer;

            Content = new ContentPage {
                Content = new Grid {
                    Children =
                    {
                        Map,
                        FavoritesButton,
                        SettingsButton
                    }
                }
            };
        }
        public FavouriteTripDisplay(NavigationPage page, DefaultMap map, int tripId)
        {
            Map     = map;
            NavPage = page;

            var isFavorite = MapUtil.Favorites.Contains(tripId);
            var isDelayed  = MapUtil.IsTripDelayed(tripId);

            Trip = Trips.GetTripWithTripId(tripId);

            _favouriteButton = new Button {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Image             = isFavorite ? StarDisabled : StarAccept,
                IsEnabled         = !isFavorite,
                Margin            = new Thickness(0, 40, 0, 0)
            };

            _issueLabel = new Label {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.End,
                Text      = isDelayed ? "Delayed by " + (MapUtil.DelayTable[tripId] / 60) + " minute(s)." : "On Schedule",
                Margin    = new Thickness(0, 20, 0, 0),
                TextColor = isDelayed ? Red : Blue
            };

            _gotoButton = new Button {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.End,
                Text = "Go to Bus..."
            };

            _favouriteButton.Clicked += OnFavourite;
            _gotoButton.Clicked      += OnGoto;

            //TODO just realised this is kinda redundant Content=Content=
            Content = new ContentPage {
                Content = new StackLayout {
                    Children =
                    {
                        new Label {
                            Margin            = new Thickness(0, 40, 0, 0),
                            HorizontalOptions = LayoutOptions.Center,
                            Text = Trip.Route.Name
                        },
                        new Label {
                            HorizontalOptions = LayoutOptions.Center,
                            Text = Trip.Id + " (" + Trip.ListStopTimeRangeAsString() + ")"
                        },
                        _favouriteButton,
                        _issueLabel,
                        _gotoButton
                    }
                }
            };
        }