コード例 #1
0
ファイル: TripLog.cs プロジェクト: ghuntley/londonbikeapp
        public static void ReverseGeocode(TripLog trip)
        {
            if (trip.StartStation != "Unknown" && trip.EndStation != "Unknown")
            {
                return;
            }

            ThreadPool.QueueUserWorkItem(delegate {
                using (NSAutoreleasePool pool = new NSAutoreleasePool()) {
                    Util.Log("Geocoding the start");
                    if (trip.StartStation == "Unknown")
                    {
                        trip.StartStation = ReverseGeocode(trip.StartLat, trip.StartLon);
                    }
                    Util.Log("Geocoding the end");

                    if (trip.EndStation == "Unknown")
                    {
                        trip.EndStation = ReverseGeocode(trip.EndLat, trip.EndLon);
                    }

                    Util.Log("Saving to disk");

                    PersistToDisk();
                }
            });
        }
コード例 #2
0
ファイル: Elements.cs プロジェクト: ghuntley/londonbikeapp
 public TripLogElement(TripLog tripLog, NSAction action) : base("", "", action)
 {
     Trip      = tripLog;
     Caption   = string.Format("{0} to {1}", tripLog.StartStation, tripLog.EndStation);
     Value     = GetValueString();
     Accessory = UITableViewCellAccessory.DisclosureIndicator;
 }
コード例 #3
0
ファイル: TripLog.cs プロジェクト: ghuntley/londonbikeapp
        public static void GetCurrentLocation(TripLog currentLog, bool isStart, NSAction onFound)
        {
            if (!CLLocationManager.LocationServicesEnabled)
            {
                currentLog.SetLocation(-1, -1, isStart);

                onFound();
            }

            locationManager = new CLLocationManager();
            locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;

            locationDelegate = new MyLocationManagerDelegate();

            locationDelegate.OnLocationError += delegate(NSError error) {
                currentLog.SetLocation(-1, -1, isStart);
                locationManager.StopUpdatingLocation();
                onFound();
            };

            locationDelegate.OnLocationUpdate += delegate(CLLocation location) {
                currentLog.SetLocation(location.Coordinate.Latitude, location.Coordinate.Longitude, isStart);
                locationManager.StopUpdatingLocation();

                onFound();
            };

            locationManager.Delegate = locationDelegate;


            locationManager.StartUpdatingLocation();
            locationDelegate.StartTimer(locationManager);
            Util.TurnOnNetworkActivity();
        }
コード例 #4
0
            public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
            {
                //
                // In this method, we need to actually carry out the request
                //
                var section = Container.Root [indexPath.Section];
                var element = section [indexPath.Row];

                section.Remove(element);

                TripLog.RemoveElementAt(indexPath.Row);
            }
コード例 #5
0
ファイル: TripLog.cs プロジェクト: ghuntley/londonbikeapp
        public static void StartNewTripItem()
        {
            currentTripLog                  = new TripLog();
            currentTripLog.Ticks            = DateTime.Now.Ticks;
            currentTripLog.TimeInSeconds    = -1;
            currentTripLog.DistanceInMeters = -1;

            GetCurrentLocation(currentTripLog, true, delegate {
                Util.Log("Found Start location");

#if DEBUG
#if FAKEDATA
                currentTripLog.StartLat = Locations.HydePark.Latitude;
                currentTripLog.StartLon = Locations.HydePark.Longitude;
#endif
#endif

                BikeLocation loc = BikeLocation.FindClosestBike(currentTripLog.StartLat, currentTripLog.StartLon);
                if (loc != null)
                {
                    if (loc.DistanceFromCurrentPoint > 500)
                    {
                        currentTripLog.StartStation = "Unknown";
                    }
                    else
                    {
                        currentTripLog.StartStation = loc.Name;
                    }
                }
                else
                {
                    currentTripLog.StartStation = "Unknown";
                }

                Util.Log("Station: " + currentTripLog.StartStation);

                NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

                defaults.SetString(currentTripLog.AsLine, "triplog_line");
                defaults.Synchronize();
            });
        }
コード例 #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            LoadTimerUserDefaults();

            if (Running)
            {
                StartButton.SetImage(Resources.StopButton, UIControlState.Normal);
                clockTimer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), UpdateTimerDisplay);
            }
            else
            {
                StartButton.SetImage(Resources.StartButton, UIControlState.Normal);
            }
            StartButton.TouchUpInside += delegate {
                if (Running)
                {
                    Running = false;

                    SetTimerUserDefaults();

                    TimeSpan elapsedTime = DateTime.Now - StartDate;

                    int totalSeconds = (int)Math.Truncate(elapsedTime.TotalSeconds);

                    TripLog.StopTripItem(totalSeconds);

                    ClearNotifications();

                    StartButton.SetImage(Resources.StartButton, UIControlState.Normal);
                    //StartButton.SetTitle("Start", UIControlState.Normal);
                    clockTimer.Invalidate();
                    clockTimer = null;

                    //CostLabel.Text = "£0.00";
                    //ElapsedLabel.Text = "0h 00m";
                    PriceIncreaseLabel.Text = "0m";
                    StartedLabel.Text       = "00:00";

                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_TIMER_STOP, "", 1);
                    Analytics.Dispatch();
                    //BackgroundLocationManager.Instance.StopLocationManager();
                }
                else
                {
                    StartDate = DateTime.Now;
                    Running   = true;

                    TripLog.StartNewTripItem();

                    SetNotification(StartDate.AddMinutes(30));


                    SetTimerUserDefaults();

                    StartButton.SetImage(Resources.StopButton, UIControlState.Normal);
                    //StartButton.SetTitle("Stop", UIControlState.Normal);
                    UpdateTimerDisplay();

                    clockTimer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), UpdateTimerDisplay);
                    //BackgroundLocationManager.Instance.StartLocationManager();


                    Analytics.TrackPageView("/timerstart");
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_TIMER_START, "", 1);
                    Analytics.Dispatch();
                }
            };
        }
コード例 #7
0
ファイル: Elements.cs プロジェクト: nicwise/londonbikeapp
 public TripLogElement(TripLog tripLog, NSAction action)
     : base("","",action)
 {
     Trip = tripLog;
     Caption = string.Format("{0} to {1}", tripLog.StartStation, tripLog.EndStation);
     Value = GetValueString();
     Accessory = UITableViewCellAccessory.DisclosureIndicator;
 }
コード例 #8
0
ファイル: TripLog.cs プロジェクト: nicwise/londonbikeapp
        public static void StopTripItem(int totalTime)
        {
            if (currentTripLog == null) {
                NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

                string line = defaults.StringForKey ("triplog_line");

                if (string.IsNullOrEmpty (line))
                    return;

                currentTripLog = new TripLog (line.Split ('|'));
            }

            currentTripLog.TimeInSeconds = totalTime;

            GetCurrentLocation (currentTripLog, false, delegate {

            #if DEBUG
            #if FAKEDATA
                currentTripLog.EndLat = Locations.BanksideMix.Latitude;
                currentTripLog.EndLon = Locations.BanksideMix.Longitude;
                currentTripLog.TimeInSeconds = 1120;
            #endif
            #endif

                Util.Log ("Found End location");
                BikeLocation loc = BikeLocation.FindClosestBike (currentTripLog.EndLat, currentTripLog.EndLon);
                if (loc != null) {
                    if (loc.DistanceFromCurrentPoint > 500) {
                        currentTripLog.EndStation = "Unknown";
                    } else {
                        currentTripLog.EndStation = loc.Name;

                    }
                } else {
                    currentTripLog.EndStation = "Unknown";
                }
                currentTripLog.DistanceInMeters = (int)BikeLocation.CalculateDistanceInMeters (
                                                                                         new CLLocationCoordinate2D (currentTripLog.StartLat, currentTripLog.StartLon),
                                                                                         new CLLocationCoordinate2D (currentTripLog.EndLat, currentTripLog.EndLon));
                BikeLocation.LogTrip (currentTripLog.TimeInSeconds, currentTripLog.DistanceInMeters);

                Util.Log ("End Station: " + currentTripLog.EndStation);
                allTrips.Insert (0, currentTripLog);

                PersistToDisk ();

                if (allTrips.Count > 0)
                    ReverseGeocode (allTrips [0]);

            });
        }
コード例 #9
0
ファイル: TripLog.cs プロジェクト: nicwise/londonbikeapp
        public static void StartNewTripItem()
        {
            currentTripLog = new TripLog ();
            currentTripLog.Ticks = DateTime.Now.Ticks;
            currentTripLog.TimeInSeconds = -1;
            currentTripLog.DistanceInMeters = -1;

            GetCurrentLocation (currentTripLog, true, delegate {

                Util.Log ("Found Start location");

            #if DEBUG
            #if FAKEDATA
                currentTripLog.StartLat = Locations.HydePark.Latitude;
                currentTripLog.StartLon = Locations.HydePark.Longitude;
            #endif
            #endif

                BikeLocation loc = BikeLocation.FindClosestBike (currentTripLog.StartLat, currentTripLog.StartLon);
                if (loc != null) {
                    if (loc.DistanceFromCurrentPoint > 500) {
                        currentTripLog.StartStation = "Unknown";

                    } else {
                        currentTripLog.StartStation = loc.Name;

                    }
                } else {
                    currentTripLog.StartStation = "Unknown";
                }

                Util.Log ("Station: " + currentTripLog.StartStation);

                NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

                defaults.SetString (currentTripLog.AsLine, "triplog_line");
                defaults.Synchronize ();

            });
        }
コード例 #10
0
ファイル: TripLog.cs プロジェクト: nicwise/londonbikeapp
        public static void ReverseGeocode(TripLog trip)
        {
            if (trip.StartStation != "Unknown" && trip.EndStation != "Unknown")
                return;

            ThreadPool.QueueUserWorkItem (delegate {
                using (NSAutoreleasePool pool = new NSAutoreleasePool()) {

                    Util.Log("Geocoding the start");
                    if (trip.StartStation == "Unknown") {
                        trip.StartStation = ReverseGeocode (trip.StartLat, trip.StartLon);
                    }
                    Util.Log ("Geocoding the end");

                    if (trip.EndStation == "Unknown") {
                        trip.EndStation = ReverseGeocode (trip.EndLat, trip.EndLon);
                    }

                    Util.Log ("Saving to disk");

                    PersistToDisk ();

                }
            });
        }
コード例 #11
0
ファイル: TripLog.cs プロジェクト: nicwise/londonbikeapp
        public static void GetCurrentLocation(TripLog currentLog, bool isStart, NSAction onFound)
        {
            if (!CLLocationManager.LocationServicesEnabled)
            {
                currentLog.SetLocation(-1, -1, isStart);

                onFound();
            }

            locationManager = new CLLocationManager();
            locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;

            locationDelegate = new MyLocationManagerDelegate();

            locationDelegate.OnLocationError += delegate(NSError error) {

                currentLog.SetLocation(-1, -1, isStart);
                locationManager.StopUpdatingLocation();
                onFound();
            };

            locationDelegate.OnLocationUpdate += delegate(CLLocation location) {

                currentLog.SetLocation(location.Coordinate.Latitude, location.Coordinate.Longitude, isStart);
                locationManager.StopUpdatingLocation();

                onFound();

            };

            locationManager.Delegate = locationDelegate;

            locationManager.StartUpdatingLocation();
            locationDelegate.StartTimer(locationManager);
            Util.TurnOnNetworkActivity();
        }
コード例 #12
0
ファイル: TripLog.cs プロジェクト: ghuntley/londonbikeapp
        public static void StopTripItem(int totalTime)
        {
            if (currentTripLog == null)
            {
                NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;


                string line = defaults.StringForKey("triplog_line");

                if (string.IsNullOrEmpty(line))
                {
                    return;
                }

                currentTripLog = new TripLog(line.Split('|'));
            }

            currentTripLog.TimeInSeconds = totalTime;

            GetCurrentLocation(currentTripLog, false, delegate {
#if DEBUG
#if FAKEDATA
                currentTripLog.EndLat        = Locations.BanksideMix.Latitude;
                currentTripLog.EndLon        = Locations.BanksideMix.Longitude;
                currentTripLog.TimeInSeconds = 1120;
#endif
#endif

                Util.Log("Found End location");
                BikeLocation loc = BikeLocation.FindClosestBike(currentTripLog.EndLat, currentTripLog.EndLon);
                if (loc != null)
                {
                    if (loc.DistanceFromCurrentPoint > 500)
                    {
                        currentTripLog.EndStation = "Unknown";
                    }
                    else
                    {
                        currentTripLog.EndStation = loc.Name;
                    }
                }
                else
                {
                    currentTripLog.EndStation = "Unknown";
                }
                currentTripLog.DistanceInMeters = (int)BikeLocation.CalculateDistanceInMeters(
                    new CLLocationCoordinate2D(currentTripLog.StartLat, currentTripLog.StartLon),
                    new CLLocationCoordinate2D(currentTripLog.EndLat, currentTripLog.EndLon));
                BikeLocation.LogTrip(currentTripLog.TimeInSeconds, currentTripLog.DistanceInMeters);

                Util.Log("End Station: " + currentTripLog.EndStation);
                allTrips.Insert(0, currentTripLog);



                PersistToDisk();

                if (allTrips.Count > 0)
                {
                    ReverseGeocode(allTrips [0]);
                }
            });
        }