Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // For accelerometer readings
            motionManager = new CMMotionManager();
            motionManager.AccelerometerUpdateInterval = 0.01; // 100Hz

            //To handle long presses and bring up path start/end menu
            var longPressManager = new UILongPressGestureRecognizer();

            //Graph loading code
            //Graph loading code
            var assembly = Assembly.GetExecutingAssembly();
            var asset    = assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsfloorWideDoors.xml");
            var asset2   = assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsFloor1.xml");
            var assetSci = assembly.GetManifestResourceStream("Navigator.iOS.Resources.ConFloor.xml");


            pf = new Pathfinding.Pathfinding(new Dictionary <int, Stream>()
            {
                { 0, assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsfloorWideDoors.xml") },
                { 1, assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsFloor1.xml") },
                { 2, assembly.GetManifestResourceStream("Navigator.iOS.Resources.ConFloor.xml") }
            }, assembly.GetManifestResourceStream("Navigator.iOS.Resources.Rooms.xml"));
            pf.CurrentFloor = 0;

            while (true)
            {
                if (pf.Ready)
                {
                    break;
                }
                Thread.Sleep(500);
            }



            //set up the search bar and prediction box
            SearchBar.TintColor = UIColor.White;

            UITextView.AppearanceWhenContainedIn(typeof(UISearchBar)).BackgroundColor  = UIColor.White;
            UITextView.AppearanceWhenContainedIn(typeof(UISearchBar)).TintColor        = UIColor.White;
            UITextField.AppearanceWhenContainedIn(typeof(UISearchBar)).BackgroundColor = UIColor.White;
            UITextField.AppearanceWhenContainedIn(typeof(UISearchBar)).TintColor       = UIColor.White;

            var shadowView = new UIView(SearchPredictionTable.Frame);

            shadowView.BackgroundColor       = UIColor.White;
            shadowView.Layer.ShadowColor     = UIColor.DarkGray.CGColor;
            shadowView.Layer.ShadowOpacity   = 1.0f;
            shadowView.Layer.ShadowRadius    = 6.0f;
            shadowView.Layer.ShadowOffset    = new System.Drawing.SizeF(0f, 3f);
            shadowView.Layer.ShouldRasterize = true;
            shadowView.Layer.MasksToBounds   = false;
            Add(shadowView);


            var blur = UIBlurEffect.FromStyle(UIBlurEffectStyle.Dark);

            topblurView = new UIVisualEffectView(blur)
            {
                Frame = new RectangleF(0, 0, (float)View.Frame.Width, 90)
            };
            bottomblurView = new UIVisualEffectView(blur)
            {
                Frame = new RectangleF(0, (float)View.Frame.Height - 70, (float)View.Frame.Width, 70)
            };

            View.Add(topblurView);
            View.Add(bottomblurView);

            View.BringSubviewToFront(SearchPredictionTable);
            View.BringSubviewToFront(returnButton);
            View.BringSubviewToFront(SearchBar);
            View.BringSubviewToFront(directionsButton);



            var searchController = new CustomSearchController(this, SearchBar, SearchPredictionTable, shadowView, pf.Rooms);

            //var directionsController = new CustomDirectionsController (this, directionsTable, pf.Rooms);

            floorPlanGraph   = Graph.Load(asset);
            floorplanWallCol = UIImage.FromBundle("Images/dcsfloorWideDoors.png");
            wallCollImg      = floorplanWallCol;

            col = new Collision(floorPlanGraph, new StepDetector());

            ((Collision)col).WallCol = new WallCollision((x, y) => GetPixelColor(new PointF(x, y), wallCollImg));
            wallColTest = new WallCollision((x, y) => GetPixelColor(new PointF(x, y), wallCollImg));

            pathView = new PathView(wallColTest, this);

            col.SetLocation(707.0f, 677.0f);
            col.PassHeading(90);
            col.PositionChanged += HandleStepsTaken;

            //Container for floorplan and any overlaid images
            var container = new UIView();

            //Will contain floorplan images
            floorplanImageView = new UIImageView();

            //Load floorplan images
            floorplanImageNoGrid      = UIImage.FromBundle("Images/FinalDcsFloor1.png");
            floorplanImageWithGrid    = UIImage.FromBundle("Images/dcsFloorWideDoorsGrid.png");
            floorplanFirstFloorNoGrid = UIImage.FromBundle("Images/final2ndFloorDisplay.png");
            floorplanSci = UIImage.FromBundle("Images/ConFloorGrid");
            floorplanFirstFloorWallCol = UIImage.FromBundle("Images/dcsFloor1.png");


            //Initiate the location arrow
            locationArrow             = new LocationArrowImageView();
            locationArrow.ScaleFactor = floorplanView.ZoomScale;
            pathView.ScaleFactor      = floorplanView.ZoomScale;
            setStartPoint(690.0f, 840.0f, this.floor);

            //Set sizes for floorplan view and path view
            floorplanView.ContentSize = floorplanImageNoGrid.Size;
            pathView.Frame            = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size);

            //Add subviews to the container (including pathview and floorplanview)
            container.AddSubview(floorplanImageView);
            container.AddSubview(locationArrow);
            floorplanImageView.AddSubview(pathView);
            changeFloorPlanImage(floorplanImageView, floorplanImageNoGrid);
            container.SizeToFit();

            //Adjust scrolling and zooming properties for the floorplanView
            floorplanView.MaximumZoomScale = 1f;
            floorplanView.MinimumZoomScale = .25f;
            floorplanView.AddSubview(container);
            floorplanView.ViewForZoomingInScrollView += (UIScrollView sv) => { return(floorplanImageView); };

            //Variables needed to convert device acceleration to world z direction acceleration
            double accelX = 0, accelY = 0, accelZ = 0;

            //Scale location arrow and paths when zooming the floorplan
            floorplanView.DidZoom += (sender, e) =>
            {
                locationArrow.ScaleFactor = floorplanView.ZoomScale;
                pathView.ScaleFactor      = floorplanView.ZoomScale;
            };



            floorplanView.DraggingStarted += (sender, e) =>
            {
                handleAnimate(topblurView, bottomblurView, true);
            };

            var tapGestureRecognizer = new UITapGestureRecognizer();

            tapGestureRecognizer.NumberOfTapsRequired = 1;
            tapGestureRecognizer.AddTarget(() => {
                handleAnimate(topblurView, bottomblurView, false);
            });
            floorplanView.AddGestureRecognizer(tapGestureRecognizer);


            //LongPressManager will cause the path input menu to appear after a stationary long press
            longPressManager.AllowableMovement = 0;
            longPressManager.AddTarget(() => handleLongPress(longPressManager, floorPlanGraph));
            floorplanView.AddGestureRecognizer(longPressManager);

            //the location manager handles the phone heading
            locationManager = new CLLocationManager();
            locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
            locationManager.HeadingFilter   = 1;
            locationManager.UpdatedHeading += HandleUpdatedHeading;
            locationManager.StartUpdatingHeading();

            //Another testing button

            returnButton.TouchUpInside += delegate { returnToMenu(); };

            directionsButton.TouchUpInside += delegate {
                if (!initStep)
                {
                    //Pass acceleremoter values to the collision class
                    motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue,
                                                            (data, error) =>
                    {
                        accelX = data.Acceleration.X * 9.8;
                        accelY = data.Acceleration.Y * 9.8;
                        accelZ = Math.Sqrt(Math.Pow(accelX, 2) + Math.Pow(accelY, 2) + Math.Pow(data.Acceleration.Z * 9.8, 2));

                        col.PassSensorReadings(CollisionSensorType.Accelometer, accelX,
                                               accelY, accelZ);
                        //displayAccelVal((float)accelZ);
                    });

                    directionsButton.SetTitle("Change Floor", UIControlState.Normal);
                    initStep = true;
                }
                else if (floor == 0)
                {
                    Console.Out.WriteLine("Changing to floor 1 ");
                    floor = 1;
                    changeFloorPlanImage(floorplanImageView, floorplanFirstFloorNoGrid);
                    setStartPoint(447.0f, 850.0f, this.floor, false);

                    wallCollImg = floorplanFirstFloorWallCol;

                    col = new Collision(floorPlanGraph, new StepDetector());

                    ((Collision)col).WallCol = new WallCollision((x, y) => GetPixelColor(new PointF(x, y), wallCollImg));
                    wallColTest = new WallCollision((x, y) => GetPixelColor(new PointF(x, y), wallCollImg));

                    pathView = new PathView(wallColTest, this);

                    col.SetLocation(447, 850);
                    col.PositionChanged += HandleStepsTaken;
                }
                else if (floor == 1)
                {
                    Console.Out.WriteLine("Changing to floor 0 ");
                    floor = 0;
                    changeFloorPlanImage(floorplanImageView, floorplanImageNoGrid);

                    setStartPoint(486.0f, 980.0f, this.floor, false);

                    wallCollImg = floorplanWallCol;

                    col = new Collision(floorPlanGraph, new StepDetector());

                    ((Collision)col).WallCol = new WallCollision((x, y) => GetPixelColor(new PointF(x, y), wallCollImg));
                    wallColTest = new WallCollision((x, y) => GetPixelColor(new PointF(x, y), wallCollImg));

                    pathView = new PathView(wallColTest, this);

                    col.SetLocation(486, 980);
                    col.PositionChanged += HandleStepsTaken;
                }
                else
                {
                    floor = 0;
                }
            };
        }