/* * Event handler for whan a pins window is clicked */ async void OnLabelClick(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("Pin clicked"); // Figure out what pin was clicked ProctorCreekPin loc = (ProctorCreekPin)sender; string locName = loc.story.Name; Position latlong = loc.Position; // Loop through story list and find the matching story to this location int storyID = -1; Story story = null; foreach (Story s in storyList) { if (s.Name.Equals(locName)) { // Update storyID storyID = s.ID; story = s; } } // FOR TESTING if (storyID == -1) { Debug.WriteLine("NO STORY FOUND; USING DEFAULT"); storyID = 5; story = storyList[0]; } // Direct to story page await Navigation.PushAsync(new StoryPage(story)); }
/* * Central database is called and the stories are retreived * Map is populated with pins for each location */ protected async override void OnAppearing() { base.OnAppearing(); List <Story> stories = await App.DBManager.GetStoriesAsync(); // Loop through each story foreach (Story s in stories) { // Get story info double lat = s.Lat; double lng = s.Long; string locName = s.Name; int imageID = -1; if (s.Images.Count > 0) { string[] split = s.Images[0].Split('/'); try { imageID = System.Convert.ToInt32(split[4]); } catch (Exception e) { Debug.WriteLine(e.Message); } } //s.ImageURL = await App.DBManager.GetImageURLAsync(s.ID); // Create new pin var pos = new Position(lat, lng); ProctorCreekPin pin = new ProctorCreekPin { Label = "", Position = pos, story = s, ImageURL = await App.DBManager.GetImageURLAsync(imageID), }; pin.Clicked += this.OnLabelClick; map.Pins.Add(pin); storyList.Add(s); } }
//Builds MKAnnotationView for display. MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; //If the annotation is the user's location, simply return null //if (annotation is MKUserLocation) return null; //Grab pin that matches location ProctorCreekPin pin = GetPin(annotation as MKPointAnnotation); //If pin is null, we f****d up if (pin == null) { throw new Exception("Pin not found."); } annotationView = mapView.DequeueReusableAnnotation(pin.Id.ToString()); if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, pin.story.ID.ToString()); //Create container UIStackView. UIStackView containerStackView = new UIStackView(); containerStackView.Axis = UILayoutConstraintAxis.Horizontal; containerStackView.Distribution = UIStackViewDistribution.FillEqually; //Play around with this containerStackView.Alignment = UIStackViewAlignment.Fill; containerStackView.Spacing = (System.nfloat) 16.0; //Create new UIStackView for the left side, and set it up. UIStackView stackViewLeft = new UIStackView(); stackViewLeft.Axis = UILayoutConstraintAxis.Vertical; stackViewLeft.Distribution = UIStackViewDistribution.Fill; stackViewLeft.Alignment = UIStackViewAlignment.Center; stackViewLeft.Spacing = (System.nfloat) 16.0; //Create new UIStackView for the right side, and set it up. UIStackView stackViewRight = new UIStackView(); stackViewRight.Axis = UILayoutConstraintAxis.Vertical; stackViewRight.Distribution = UIStackViewDistribution.EqualSpacing; stackViewRight.Alignment = UIStackViewAlignment.Center; stackViewRight.Spacing = (System.nfloat) 16.0; //Create a new Label for the left side, and set the storyname. UILabel storyNameLabel = new UILabel(); storyNameLabel.Text = pin.story.Name; storyNameLabel.AdjustsFontSizeToFitWidth = true; //Create a new TextView for the right side, and set it to DescriptionShort //from the pin. Also set to not editable. UILabel shortDescText = new PCGUILabel(); shortDescText.Text = pin.story.Details; shortDescText.Lines = 12; shortDescText.UserInteractionEnabled = true; ((PCGUILabel)shortDescText).pin = pin; UITapGestureRecognizer descTextTap = new UITapGestureRecognizer(tap => this.OnShortDescClick(tap)) { NumberOfTapsRequired = 1 }; shortDescText.AddGestureRecognizer(descTextTap); //Create a new Label that says "Continue Reading..." for the right side. UILabel continueReadingLabel = new UILabel(); continueReadingLabel.Text = "Continue Reading"; //Create a new image for the left side, and set it from Story.PictureURL NSData imageData = null; imageData = NSData.FromUrl(new NSUrl(pin.ImageURL)); UIImage image = null; //Check if imageData is null. If it's not, then make an image if (imageData != null) { image = new UIImage(imageData); System.Diagnostics.Debug.WriteLine(image.Size); } //Add the label (for the left side) to stackViewLeft. stackViewLeft.AddArrangedSubview(storyNameLabel); //If the image isn't null, then add a UIImageView to stackView. if (image != null) { UIImageView imageView = new ScaledImageView(image); imageView.ContentMode = UIViewContentMode.ScaleAspectFit; stackViewLeft.AddArrangedSubview(imageView); stackViewLeft.AddConstraint(NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1.0f, 200)); } //Add the labels (for the right side) to stackViewRight. stackViewRight.AddArrangedSubview(shortDescText); //stackViewRight.AddConstraint(topR); //stackViewRight.AddConstraint(sidesR); /*var margins = stackViewRight.LayoutMarginsGuide; * shortDescText.LeadingAnchor.Constraint(equalTo: margins.LeadingAnchor, constant: 20).isActive = true;*/ //stackViewRight.AddArrangedSubview(continueReadingLabel); //Add the left and right StackViews to the container StackView. containerStackView.AddArrangedSubview(stackViewLeft); containerStackView.AddArrangedSubview(stackViewRight); /*var width = NSLayoutConstraint.Create(containerStackView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, 1.0f); * var height = NSLayoutConstraint.Create(containerStackView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, 1.0f); * containerStackView.AddConstraint(width); * containerStackView.AddConstraint(height);*/ annotationView.DetailCalloutAccessoryView = containerStackView; } annotationView.CanShowCallout = true; return(annotationView); }
/* * Generic Mapview function for both Android and IOS * Shown on MainPage when App is started */ public MapView() { // Location of proctor creek var proctorCreek = new Position(33.778822, -84.439945); //Inititialize map centered around proctor creek map = new ProctorCreekMap( MapSpan.FromCenterAndRadius( proctorCreek, Distance.FromMiles(2))) { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; MessagingCenter.Subscribe <ProctorCreekMap, ProctorCreekPin>(this, "Navigation", async(sender, args) => { ProctorCreekPin pin = args; var page1 = new StoryPage(pin.story); await Navigation.PushAsync(page1); }); // Initialize search bar functionality searchBar = new SearchBar { Placeholder = "Search", BackgroundColor = Xamarin.Forms.Color.White }; searchBar.SearchButtonPressed += this.OnSearchClick; //searchBar.TextChanged += this.OnSearchTextChange; // Initialize QR functionality var options = new ZXing.Mobile.MobileBarcodeScanningOptions(); options.PossibleFormats = new List <ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.QR_CODE }; var scanner = new QRScan(options); scanner.OnScanResult += async(result) => { scanner.IsScanning = false; Device.BeginInvokeOnMainThread(async() => { scanner.readout = result.Text; await Navigation.PopAsync(); }); }; Button button = new Button() { Text = "QR" }; button.Clicked += async(sender, e) => { await Navigation.PushAsync(scanner); }; // GUI stuff stack = new StackLayout { Spacing = 0 }; var grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(12, GridUnitType.Star) }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); stack.Children.Add(searchBar); grid.Children.Add(map, 0, 0); Grid.SetRowSpan(map, 2); grid.Children.Add(button, 0, 1); stack.Children.Add(grid); Content = stack; }
//Builds MKAnnotationView for display. MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; //If the annotation is the user's location, simply return null //if (annotation is MKUserLocation) return null; //Grab pin that matches location ProctorCreekPin pin = GetPin(annotation as MKPointAnnotation); //If pin is null, we f****d up if (pin == null) { throw new Exception("Pin not found."); } annotationView = mapView.DequeueReusableAnnotation(pin.Id.ToString()); if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, pin.story.StoryID.ToString()); annotationView.CalloutOffset = new CGPoint(0, 0); //Create container UIStackView. UIStackView containerStackView = new UIStackView(); containerStackView.Axis = UILayoutConstraintAxis.Horizontal; containerStackView.Distribution = UIStackViewDistribution.FillEqually; //Play around with this containerStackView.Alignment = UIStackViewAlignment.Center; containerStackView.Spacing = (System.nfloat) 16.0; //Create new UIStackView for the left side, and set it up. UIStackView stackViewLeft = new UIStackView(); stackViewLeft.Axis = UILayoutConstraintAxis.Vertical; stackViewLeft.Distribution = UIStackViewDistribution.EqualSpacing; stackViewLeft.Alignment = UIStackViewAlignment.Center; stackViewLeft.Spacing = (System.nfloat) 16.0; System.Diagnostics.Debug.WriteLine("Created 1st StackView"); //Create new UIStackView for the right side, and set it up. UIStackView stackViewRight = new UIStackView(); stackViewRight.Axis = UILayoutConstraintAxis.Vertical; stackViewRight.Distribution = UIStackViewDistribution.EqualSpacing; stackViewRight.Alignment = UIStackViewAlignment.Center; stackViewRight.Spacing = (System.nfloat) 16.0; System.Diagnostics.Debug.WriteLine("Created 2nd StackView"); //Create a new Label for the left side, and set the storyname. UILabel storyNameLabel = new UILabel(); storyNameLabel.Text = pin.story.StoryName; System.Diagnostics.Debug.WriteLine("Created StoryNameLabel"); //Create a new TextView for the right side, and set it to DescriptionShort //from the pin. Also set to not editable. UILabel shortDescText = new UILabel(); shortDescText.Text = pin.story.DescriptionLong; shortDescText.Lines = 10; //shortDescText.Editable = false; System.Diagnostics.Debug.WriteLine(shortDescText.Text); //Create a new Label that says "Continue Reading..." for the right side. UILabel continueReadingLabel = new UILabel(); continueReadingLabel.Text = "Continue Reading"; System.Diagnostics.Debug.WriteLine("Created ContinueReadingLabel"); //Create a new image for the left side, and set it from Story.PictureURL NSData imageData = NSData.FromUrl(new NSUrl(pin.story.PictureURL)); UIImage image = null; //Check if imageData is null. If it's not, then make an image if (imageData != null) { image = new UIImage(imageData); } //Add the label (for the left side) to stackViewLeft. stackViewLeft.AddArrangedSubview(storyNameLabel); //If the image isn't null, then add a UIImageView to stackView. if (image != null) { UIImageView imageView = new UIImageView(image); imageView.ContentMode = UIViewContentMode.ScaleAspectFit; stackViewLeft.AddArrangedSubview(imageView); NSLayoutConstraint topL = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, storyNameLabel, NSLayoutAttribute.Bottom, 1.0f, 2.0f); NSLayoutConstraint sidesL = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, stackViewLeft, NSLayoutAttribute.Width, 1.0f, 0.0f); stackViewLeft.AddConstraint(topL); stackViewLeft.AddConstraint(sidesL); } //annotationView.Image = null; //Add the labels (for the right side) to stackViewRight. stackViewRight.AddArrangedSubview(shortDescText); NSLayoutConstraint topR = NSLayoutConstraint.Create(shortDescText, NSLayoutAttribute.Top, NSLayoutRelation.Equal, stackViewRight, NSLayoutAttribute.Top, 1.0f, 2.0f); NSLayoutConstraint sidesR = NSLayoutConstraint.Create(shortDescText, NSLayoutAttribute.Width, NSLayoutRelation.Equal, stackViewRight, NSLayoutAttribute.Width, 1.0f, 0.0f); stackViewRight.AddConstraint(topR); stackViewRight.AddConstraint(sidesR); /*var margins = stackViewRight.LayoutMarginsGuide; * shortDescText.LeadingAnchor.Constraint(equalTo: margins.LeadingAnchor, constant: 20).isActive = true;*/ stackViewRight.AddArrangedSubview(continueReadingLabel); //Add the left and right StackViews to the container StackView. containerStackView.AddArrangedSubview(stackViewLeft); containerStackView.AddArrangedSubview(stackViewRight); //Assign stackViewLeft to the LeftCalloutAccessory of the annotation. annotationView.DetailCalloutAccessoryView = containerStackView; //annotationView.LeftCalloutAccessoryView = new UIImageView(image); //annotationView.RightCalloutAccessoryView = shortDescLabel; //Assign stackViewRight to the RightCalloutAccessory of the annotation. //annotationView.RightCalloutAccessoryView = stackViewRight; } System.Diagnostics.Debug.WriteLine(annotationView.LeftCalloutAccessoryView); annotationView.CanShowCallout = true; return(annotationView); }