UpdateFromWebsite() public static method

public static UpdateFromWebsite ( NSAction onDone ) : bool
onDone NSAction
return bool
        public override void ViewDidAppear(bool animated)
        {
            Util.Log("NearView: Appear");
            NavigationController.NavigationBar.TintColor = Resources.DarkBlue;

            ToggleTapHereView();

            BikeLocation.UpdateFromWebsite(delegate {
                InvokeOnMainThread(delegate {
                    Util.AppDelegate.map.RefreshPinColours();
                    RefreshData();
                });
            });
        }
        public NearDialogViewController() : base(null, false)
        {
            Title = "Nearest Bikes";

            this.RefreshRequested += delegate {
                if (!BikeLocation.UpdateFromWebsite(delegate {
                    InvokeOnMainThread(delegate {
                        Util.AppDelegate.map.RefreshPinColours();
                        RefreshData();

                        ReloadComplete();
                    });
                }))
                {
                    ReloadComplete();
                }
            };

            this.Style = MonoTouch.UIKit.UITableViewStyle.Plain;

            refreshButton = new UIBarButtonItem(UIBarButtonSystemItem.Refresh, delegate {
                if (!updating)
                {
                    updating = true;
                    BikeLocation.UpdateFromWebsite(delegate {
                        InvokeOnMainThread(delegate {
                            Util.AppDelegate.map.RefreshPinColours();
                            RefreshData();
                        });
                    });

                    HasList = true;
                    ToggleTapHereView();
                    UpdateNearestList();
                }
            });

            NavigationItem.RightBarButtonItem = refreshButton;

            if (CLLocationManager.HeadingAvailable)
            {
                compassButton = new UIBarButtonItem(Resources.Compass, UIBarButtonItemStyle.Bordered, delegate {
                    ToggleCompassView();
                });

                NavigationItem.LeftBarButtonItem = compassButton;
            }
        }
Esempio n. 3
0
        public override void ViewDidAppear(bool animated)
        {
            Util.Log("MapView: Appear");
            NavigationController.NavigationBar.TintColor = Resources.DarkBlue;


            //if (gpsButton != null) NavigationItem.RightBarButtonItem = gpsButton;

            BikeLocation.UpdateFromWebsite(delegate {
                InvokeOnMainThread(delegate {
                    RefreshPinColours();
                    //RefreshData();
                });
            });

            if (userLocationWasOn)
            {
                mapView.ShowsUserLocation = true;
            }
            userLocationWasOn = false;
        }
Esempio n. 4
0
        // This method is invoked when the application has loaded its UI and its ready to run
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // If you have defined a view, add it here:
            // window.AddSubview (navigationController.View);

            //TripLog.MakeDummyData();

            Util.Log("In finished launching (with options)");


            bool localNotification = false;

            if (options != null)
            {
                if (Util.IsIOS4OrBetter)
                {
                    UILocalNotification localNotif = (UILocalNotification)options.ObjectForKey(UIApplication.LaunchOptionsLocalNotificationKey);

                    if (localNotif != null)
                    {
                        localNotification = true;
                    }
                }
            }

            Util.LogStartup();


            var bikes = BikeLocation.AllBikes;


            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
            tabBar = new UITabBarController(); MainView = tabBar.View;
            window.AddSubview(MainView);


            near     = new NearDialogViewController();
            map      = new MapViewController();
            tripLog  = new TripLogViewController();
            infoPage = new InfoViewController();


            timer = new TimerViewController {
                TabBarItem = new UITabBarItem("Timer", Resources.Timer, 1)
            };

            tabControllers = new UIViewController[] {
                new UINavigationController(near)
                {
                    TabBarItem = new UITabBarItem("Near", Resources.Near, 0)
                },
                new UINavigationController(map)
                {
                    TabBarItem = new UITabBarItem("Map", Resources.Map, 2)
                },
                timer,
                new UINavigationController(tripLog)
                {
                    TabBarItem = new UITabBarItem("Trip Log", Resources.TripLog, 3)
                },
                new UINavigationController(infoPage)
                {
                    TabBarItem = new UITabBarItem("Info", Resources.Info, 4)
                }
            };


            tabBar.SetViewControllers(tabControllers, false);

            if (localNotification)
            {
                tabBar.SelectedIndex = 2;
            }

            window.MakeKeyAndVisible();

            BikeLocation.UpdateFromWebsite(delegate {
                Util.Log("Update on startup done");
                map.RefreshPinColours();
            });

            Appirator.AppLaunched();
            Analytics.AppLaunched();

            return(true);
        }
Esempio n. 5
0
        public MapViewController() : base()
        {
            BuildView();

            NavigationItem.Title = "Map";



            segmentControl = new UISegmentedControl(new RectangleF(0, 0, 200, 25));
            segmentControl.InsertSegment("Find bikes", 0, false);
            segmentControl.InsertSegment("Find docks", 1, false);
            segmentControl.SelectedSegment = 0;
            segmentControl.ControlStyle    = UISegmentedControlStyle.Bar;
            segmentControl.ValueChanged   += delegate(object sender, EventArgs e) {
                if (segmentControl.SelectedSegment == 0)
                {
                    CurrentDisplayMode = DisplayMode.Bikes;
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_MAP_BIKES, "", 1);
                }
                else
                {
                    CurrentDisplayMode = DisplayMode.Docks;
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_MAP_DOCKS, "", 1);
                }

                RefreshPinColours();

                BikeLocation.UpdateFromWebsite(delegate {
                    InvokeOnMainThread(delegate {
                        RefreshPinColours();
                        //RefreshData();
                    });
                });
            };


            NavigationItem.TitleView = segmentControl;


            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Resources.Routing, UIBarButtonItemStyle.Bordered, delegate {
                //nulls, think about the nulls!

                if (!CLLocationManager.LocationServicesEnabled)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, no location services are available. However, you may still be able to use the timer and map.", null, "Ok");
                    alert.Show();
                    return;
                }

                if (mapView.UserLocation == null || mapView.UserLocation.Location == null)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, your location is not yet available.", null, "Ok");
                    alert.Show();
                    return;
                }



                NSObject[] selectedPins = mapView.SelectedAnnotations;

                if (selectedPins == null || selectedPins.Length > 1)
                {
                    alert = new UIAlertView("Select a dock", "Please pick a cycle docking station to route to.", null, "Ok");
                    alert.Show();
                    return;
                }



                if (selectedPins.Length == 1)
                {
                    CycleAnnotation ca = selectedPins[0] as CycleAnnotation;
                    if (ca != null)
                    {
                        HideDistanceView();

                        var location = mapView.UserLocation.Location.Coordinate;
#if DEBUG
                        location = Locations.BanksideMix;
#endif

                        double distance = BikeLocation.CalculateDistanceInMeters(location, ca.Coordinate);
                        if (distance > 50000)
                        {
                            alert = new UIAlertView("Sorry, your route is too long", "We can only plot cycle routes up to 50km.", null, "Ok");
                            alert.Show();


                            return;
                        }



                        loadingView = new ActivityIndicatorLoadingView();
                        loadingView.Show("Finding your route");
                        Util.TurnOnNetworkActivity();


                        RemoveRouteAnnotation();



                        ThreadPool.QueueUserWorkItem(delegate {
                            using (NSAutoreleasePool newPool = new NSAutoreleasePool())
                            {
                                location = mapView.UserLocation.Location.Coordinate;
#if DEBUG
                                location = Locations.BanksideMix;
#endif

                                MapRouting routing = new MapRouting(location, ca.Coordinate);



                                //routing.FindRoute(delegate {
                                routing.FindRoute(delegate {
                                    InvokeOnMainThread(delegate {
                                        //Console.WriteLine("updating");
                                        loadingView.Hide();
                                        Util.TurnOffNetworkActivity();
                                        if (routing.HasRoute)
                                        {
                                            routeAnnotation = new CSRouteAnnotation(routing.PointsList);
                                            mapView.AddAnnotation(routeAnnotation);

                                            var region = routeAnnotation.Region;

                                            region.Span = new MKCoordinateSpan(region.Span.LatitudeDelta * 1.1f, region.Span.LongitudeDelta * 1.1f);


                                            mapView.SetRegion(region, true);


                                            //need to animate the distance etc here.


                                            ShowDistanceView(routing.DistanceForDisplay, routing.TimeForDisplay);

                                            BikeLocation.LogRoute();
                                        }
                                        else
                                        {
                                            alert = new UIAlertView("No route found", "Sorry, no route could be found or the route is too long.", null, "Ok");
                                            alert.Show();
                                        }
                                    });
                                });
                            }
                        });
                    }
                }
            });

            //NavigationController.NavigationBar.TintColor = Resources.DarkBlue;
            gpsButton = new UIBarButtonItem(Resources.Gps, UIBarButtonItemStyle.Bordered, delegate {
                if (!CLLocationManager.LocationServicesEnabled)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, no location services are available. However, you may still be able to use the timer and map.", null, "Ok");
                    alert.Show();
                    return;
                }

                if (mapView.UserLocation != null)
                {
                    if (mapView.UserLocation.Location != null)
                    {
                        //NavigationItem.RightBarButtonItem = activityButton;

                        BikeLocation.UpdateFromWebsite(delegate {
                            InvokeOnMainThread(delegate {
                                RefreshPinColours();
                                //NavigationItem.RightBarButtonItem = gpsButton;
                            });
                        });

                        CLLocationCoordinate2D location = mapView.UserLocation.Location.Coordinate;
#if DEBUG
                        location = Locations.BanksideMix;
#endif
                        MKCoordinateRegion region = new MKCoordinateRegion(location, new MKCoordinateSpan(0.01, 0.01));

                        region = mapView.RegionThatFits(region);
                        mapView.SetRegion(region, true);
                    }
                }
            });


            NavigationItem.RightBarButtonItem = gpsButton;
        }