コード例 #1
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            progessBar.Visibility = Visibility.Visible;
            if (!API.isInitialized)
               await API.initializeRoutes();
            // TODO: Assign a collection of bindable groups to this.DefaultViewModel["Groups"]
            
            TileGroup nearbyGroup = new TileGroup();
            TileGroup favoritesGroup = new TileGroup();
            TileGroup actionsGroup = new TileGroup();
            TileGroup routesGroup = new TileGroup();

            routesGroup.Title = "Routes";
            nearbyGroup.Title = "Nearby Stops";
            favoritesGroup.Title = "Favorite Stops";
            actionsGroup.Title = "Actions";

            double lat = 999;
            double longt = 999;
            try
            {
                Geoposition pos = await geo.GetGeopositionAsync();
                lat = pos.Coordinate.Latitude;
                longt = pos.Coordinate.Longitude;
            }
            catch (UnauthorizedAccessException uaex)
            { }
            
            #region All Routes
            List<Route> routes = API.ds.Routes;
            foreach (Route r in routes)
            {
                TileItem item = new TileItem();
                SolidColorBrush brush = new SolidColorBrush();
                brush.Color = ColorConverter.getColor(r.Color);
                item.Items.Add(new TilePiece() { Title = r.Title, Details = r.Stops.Count+" Stops" });
                item.Color = brush;
                item.AssignedObject = r;
                routesGroup.Items.Add(item);

             

            }
            groups.Add(routesGroup);
#endregion

            #region Nearby Stops
            if (lat != 999)
            {
                foreach (Route r in routes)
                {
                    int counter = 0;
                    foreach (Direction d in r.Directions)
                    {
                        foreach (Stop s in d.Stops)
                        {
                            if (counter > 2)
                                break;

                            double distance = 0.6214 * calculateDistance(lat, longt, s.Latitude, s.Longitude);
                            if (distance < 0.5)
                            {
                                TileItem nearbyItem = new TileItem();
                                SolidColorBrush brush = new SolidColorBrush();
                                brush.Color = ColorConverter.getColor(r.Color);
                                nearbyItem.Color = brush;
                                nearbyItem.AssignedObject = s;

                                int[] prediction = await API.getPrediction(r.Tag, d.Tag, s.Tag);
                                if (prediction != null)
                                {
                                    string predictionStr = "";
                                    foreach (int i in prediction)
                                        predictionStr += i + " ";
                                    nearbyItem.Items.Add(new TilePiece() { Title = s.Title, Subtitle = predictionStr });
                                    nearbyGroup.Items.Add(nearbyItem);

                                    counter++;
                                }

                            }

                        }
                    }


                }
            }
            #endregion




            if(nearbyGroup.Items.Count!=0)
                groups.Add(nearbyGroup);

            if (nearbyGroup.Items.Count != 0)
            {
                groups.Add(favoritesGroup);
            }
            actionsGroup.Items.Add(new IItem());
            groups.Add(actionsGroup);
            
            
            this.DefaultViewModel["Groups"] = groups;
            progessBar.Visibility = Visibility.Collapsed;
        }
コード例 #2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            progessBar.Visibility = Visibility.Visible;
            if (!API.isInitialized)
            {
                await API.initializeRoutes();
            }
            // TODO: Assign a collection of bindable groups to this.DefaultViewModel["Groups"]

            TileGroup nearbyGroup    = new TileGroup();
            TileGroup favoritesGroup = new TileGroup();
            TileGroup actionsGroup   = new TileGroup();
            TileGroup routesGroup    = new TileGroup();

            routesGroup.Title    = "Routes";
            nearbyGroup.Title    = "Nearby Stops";
            favoritesGroup.Title = "Favorite Stops";
            actionsGroup.Title   = "Actions";

            double lat   = 999;
            double longt = 999;

            try
            {
                Geoposition pos = await geo.GetGeopositionAsync();

                lat   = pos.Coordinate.Latitude;
                longt = pos.Coordinate.Longitude;
            }
            catch (UnauthorizedAccessException uaex)
            { }

            #region All Routes
            List <Route> routes = API.ds.Routes;
            foreach (Route r in routes)
            {
                TileItem        item  = new TileItem();
                SolidColorBrush brush = new SolidColorBrush();
                brush.Color = ColorConverter.getColor(r.Color);
                item.Items.Add(new TilePiece()
                {
                    Title = r.Title, Details = r.Stops.Count + " Stops"
                });
                item.Color          = brush;
                item.AssignedObject = r;
                routesGroup.Items.Add(item);
            }
            groups.Add(routesGroup);
            #endregion

            #region Nearby Stops
            if (lat != 999)
            {
                foreach (Route r in routes)
                {
                    int counter = 0;
                    foreach (Direction d in r.Directions)
                    {
                        foreach (Stop s in d.Stops)
                        {
                            if (counter > 2)
                            {
                                break;
                            }

                            double distance = 0.6214 * calculateDistance(lat, longt, s.Latitude, s.Longitude);
                            if (distance < 0.5)
                            {
                                TileItem        nearbyItem = new TileItem();
                                SolidColorBrush brush      = new SolidColorBrush();
                                brush.Color               = ColorConverter.getColor(r.Color);
                                nearbyItem.Color          = brush;
                                nearbyItem.AssignedObject = s;

                                int[] prediction = await API.getPrediction(r.Tag, d.Tag, s.Tag);

                                if (prediction != null)
                                {
                                    string predictionStr = "";
                                    foreach (int i in prediction)
                                    {
                                        predictionStr += i + " ";
                                    }
                                    nearbyItem.Items.Add(new TilePiece()
                                    {
                                        Title = s.Title, Subtitle = predictionStr
                                    });
                                    nearbyGroup.Items.Add(nearbyItem);

                                    counter++;
                                }
                            }
                        }
                    }
                }
            }
            #endregion



            if (nearbyGroup.Items.Count != 0)
            {
                groups.Add(nearbyGroup);
            }

            if (nearbyGroup.Items.Count != 0)
            {
                groups.Add(favoritesGroup);
            }
            actionsGroup.Items.Add(new IItem());
            groups.Add(actionsGroup);


            this.DefaultViewModel["Groups"] = groups;
            progessBar.Visibility           = Visibility.Collapsed;
        }