From 64ac3814765a3dac970983b4de4b735786c87887 Mon Sep 17 00:00:00 2001 From: Paola Villarreal Date: Thu, 24 Jul 2014 14:26:07 -0500 Subject: [PATCH] RecipesAndPrinting sample ported to 64-bits --- RecipesAndPrinting/AppDelegate.cs | 4 +- .../InstructionsViewController.cs | 4 +- .../InstructionsViewController.designer.cs | 6 +- RecipesAndPrinting/Main.cs | 4 +- RecipesAndPrinting/Recipe.cs | 4 +- .../RecipeDetailViewController.cs | 32 +++++----- .../RecipeDetailViewController.designer.cs | 10 +-- .../RecipeListTableViewController.cs | 8 +-- .../RecipeListTableViewController.designer.cs | 2 +- .../RecipePhotoViewController.cs | 4 +- RecipesAndPrinting/RecipePrintPageRenderer.cs | 62 +++++++++---------- RecipesAndPrinting/RecipeTableViewCell.cs | 36 +++++------ RecipesAndPrinting/RecipesAndPrinting.csproj | 7 ++- RecipesAndPrinting/RecipesController.cs | 4 +- 14 files changed, 95 insertions(+), 92 deletions(-) diff --git a/RecipesAndPrinting/AppDelegate.cs b/RecipesAndPrinting/AppDelegate.cs index c4c454a2..d0de8457 100644 --- a/RecipesAndPrinting/AppDelegate.cs +++ b/RecipesAndPrinting/AppDelegate.cs @@ -27,8 +27,8 @@ using System; using System.Collections.Generic; using System.Linq; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { diff --git a/RecipesAndPrinting/InstructionsViewController.cs b/RecipesAndPrinting/InstructionsViewController.cs index f2c31698..18b6046c 100644 --- a/RecipesAndPrinting/InstructionsViewController.cs +++ b/RecipesAndPrinting/InstructionsViewController.cs @@ -26,8 +26,8 @@ using System; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { diff --git a/RecipesAndPrinting/InstructionsViewController.designer.cs b/RecipesAndPrinting/InstructionsViewController.designer.cs index 3b3e2fcb..9278ffae 100644 --- a/RecipesAndPrinting/InstructionsViewController.designer.cs +++ b/RecipesAndPrinting/InstructionsViewController.designer.cs @@ -4,7 +4,7 @@ // actions made in the Xcode designer. If it is removed, they will be lost. // Manual changes to this file may not be handled correctly. // -using MonoTouch.Foundation; +using Foundation; namespace RecipesAndPrinting { @@ -12,9 +12,9 @@ namespace RecipesAndPrinting partial class InstructionsViewController { [Outlet] - MonoTouch.UIKit.UITextView instructionsText { get; set; } + UIKit.UITextView instructionsText { get; set; } [Outlet] - MonoTouch.UIKit.UILabel nameLabel { get; set; } + UIKit.UILabel nameLabel { get; set; } } } diff --git a/RecipesAndPrinting/Main.cs b/RecipesAndPrinting/Main.cs index c86280f3..062e61ac 100644 --- a/RecipesAndPrinting/Main.cs +++ b/RecipesAndPrinting/Main.cs @@ -27,8 +27,8 @@ using System; using System.Collections.Generic; using System.Linq; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { diff --git a/RecipesAndPrinting/Recipe.cs b/RecipesAndPrinting/Recipe.cs index be6babdb..fcddd9dc 100644 --- a/RecipesAndPrinting/Recipe.cs +++ b/RecipesAndPrinting/Recipe.cs @@ -29,8 +29,8 @@ using System.Text; using System.Collections; using System.Collections.Generic; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { diff --git a/RecipesAndPrinting/RecipeDetailViewController.cs b/RecipesAndPrinting/RecipeDetailViewController.cs index 28250a5c..79a46332 100644 --- a/RecipesAndPrinting/RecipeDetailViewController.cs +++ b/RecipesAndPrinting/RecipeDetailViewController.cs @@ -25,11 +25,11 @@ // using System; -using System.Drawing; +using CoreGraphics; using System.Collections.Generic; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { @@ -71,12 +71,12 @@ namespace RecipesAndPrinting get { return controller.Recipe; } } - public override int NumberOfSections (UITableView tableView) + public override nint NumberOfSections (UITableView tableView) { return (int) RecipeSection.TotalSections; } - public override string TitleForHeader (UITableView tableView, int section) + public override string TitleForHeader (UITableView tableView, nint section) { if (section == (int) RecipeSection.Instructions) return "Instructions"; @@ -84,25 +84,25 @@ namespace RecipesAndPrinting return null; } - public override int RowsInSection (UITableView tableView, int section) + public override nint RowsInSection (UITableView tableView, nint section) { - switch ((RecipeSection) section) { + switch ((RecipeSection) (int)section) { case RecipeSection.Instructions: return 1; case RecipeSection.Ingredients: return Recipe.Ingredients.Length; default: return 0; } } - UITableViewCell GetIngredientsCellAtIndex (UITableView tableView, int index) + UITableViewCell GetIngredientsCellAtIndex (UITableView tableView, nint index) { UITableViewCell cell = tableView.DequeueReusableCell (IngredientsCellId); - RectangleF computedFrame; + CGRect computedFrame; UILabel amountLabel; if (cell == null) { cell = new UITableViewCell (UITableViewCellStyle.Default, IngredientsCellId); - amountLabel = new UILabel (RectangleF.Empty); + amountLabel = new UILabel (CGRect.Empty); amountLabel.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin; amountLabel.TextColor = UIColor.FromRGBA (50.0f / 255.0f, 79.0f / 255.0f, 133.0f / 255.0f, 1.0f); amountLabel.TextAlignment = UITextAlignment.Right; @@ -118,11 +118,11 @@ namespace RecipesAndPrinting cell.TextLabel.Text = Recipe.Ingredients[index].Name; amountLabel.Text = Recipe.Ingredients[index].Amount; - SizeF desiredSize = amountLabel.SizeThatFits (new SizeF (160.0f, 32.0f)); - float midY = (cell.ContentView.Bounds.Y + cell.ContentView.Bounds.Height) / 2.0f; - float maxX = cell.ContentView.Bounds.Right; + CGSize desiredSize = amountLabel.SizeThatFits (new CGSize (160.0f, 32.0f)); + nfloat midY = (cell.ContentView.Bounds.Y + cell.ContentView.Bounds.Height) / 2.0f; + nfloat maxX = cell.ContentView.Bounds.Right; - computedFrame = new RectangleF (new PointF (maxX - desiredSize.Width - 10.0f, midY - desiredSize.Height / 2.0f), desiredSize); + computedFrame = new CGRect (new CGPoint (maxX - desiredSize.Width - 10.0f, midY - desiredSize.Height / 2.0f), desiredSize); amountLabel.Frame = computedFrame; return cell; @@ -130,7 +130,7 @@ namespace RecipesAndPrinting public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) { - RecipeSection section = (RecipeSection) indexPath.Section; + RecipeSection section = (RecipeSection)(int) indexPath.Section; if (section == (int) RecipeSection.Ingredients) return GetIngredientsCellAtIndex (tableView, indexPath.Row); @@ -154,7 +154,7 @@ namespace RecipesAndPrinting public override NSIndexPath WillSelectRow (UITableView tableView, NSIndexPath indexPath) { - RecipeSection section = (RecipeSection) indexPath.Section; + RecipeSection section = (RecipeSection)(int) indexPath.Section; // Don't allow ingredients to be selected if (section == RecipeSection.Ingredients) { diff --git a/RecipesAndPrinting/RecipeDetailViewController.designer.cs b/RecipesAndPrinting/RecipeDetailViewController.designer.cs index dd872ff6..74f4efb8 100644 --- a/RecipesAndPrinting/RecipeDetailViewController.designer.cs +++ b/RecipesAndPrinting/RecipeDetailViewController.designer.cs @@ -4,7 +4,7 @@ // actions made in the Xcode designer. If it is removed, they will be lost. // Manual changes to this file may not be handled correctly. // -using MonoTouch.Foundation; +using Foundation; namespace RecipesAndPrinting { @@ -12,15 +12,15 @@ namespace RecipesAndPrinting partial class RecipeDetailViewController { [Outlet] - MonoTouch.UIKit.UIView tableHeaderView { get; set; } + UIKit.UIView tableHeaderView { get; set; } [Outlet] - MonoTouch.UIKit.UIButton photoButton { get; set; } + UIKit.UIButton photoButton { get; set; } [Outlet] - MonoTouch.UIKit.UILabel nameLabel { get; set; } + UIKit.UILabel nameLabel { get; set; } [Action ("ShowPhoto:")] - partial void ShowPhoto (MonoTouch.Foundation.NSObject sender); + partial void ShowPhoto (Foundation.NSObject sender); } } diff --git a/RecipesAndPrinting/RecipeListTableViewController.cs b/RecipesAndPrinting/RecipeListTableViewController.cs index 2e98e718..a475cee8 100644 --- a/RecipesAndPrinting/RecipeListTableViewController.cs +++ b/RecipesAndPrinting/RecipeListTableViewController.cs @@ -27,8 +27,8 @@ using System; using System.Collections.Generic; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { @@ -104,12 +104,12 @@ namespace RecipesAndPrinting get { return controller.recipes.Recipes; } } - public override int NumberOfSections (UITableView tableView) + public override nint NumberOfSections (UITableView tableView) { return 1; } - public override int RowsInSection (UITableView tableView, int section) + public override nint RowsInSection (UITableView tableView, nint section) { return Recipes.Length; } diff --git a/RecipesAndPrinting/RecipeListTableViewController.designer.cs b/RecipesAndPrinting/RecipeListTableViewController.designer.cs index f7c7d440..80dc7714 100644 --- a/RecipesAndPrinting/RecipeListTableViewController.designer.cs +++ b/RecipesAndPrinting/RecipeListTableViewController.designer.cs @@ -4,7 +4,7 @@ // actions made in the Xcode designer. If it is removed, they will be lost. // Manual changes to this file may not be handled correctly. // -using MonoTouch.Foundation; +using Foundation; namespace RecipesAndPrinting { diff --git a/RecipesAndPrinting/RecipePhotoViewController.cs b/RecipesAndPrinting/RecipePhotoViewController.cs index 0eed08ef..9d5ab1a3 100644 --- a/RecipesAndPrinting/RecipePhotoViewController.cs +++ b/RecipesAndPrinting/RecipePhotoViewController.cs @@ -26,8 +26,8 @@ using System; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { diff --git a/RecipesAndPrinting/RecipePrintPageRenderer.cs b/RecipesAndPrinting/RecipePrintPageRenderer.cs index 4e3912c4..48537284 100644 --- a/RecipesAndPrinting/RecipePrintPageRenderer.cs +++ b/RecipesAndPrinting/RecipePrintPageRenderer.cs @@ -25,12 +25,12 @@ // using System; -using System.Drawing; +using CoreGraphics; using System.Collections; using System.Collections.Generic; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { @@ -55,9 +55,9 @@ namespace RecipesAndPrinting // Calculate the content area based on the printableRect, that is, the area in which // the printer can print content. a.k.a the imageable area of the paper. - RectangleF ContentArea { + CGRect ContentArea { get { - RectangleF r = PrintableRect; + CGRect r = PrintableRect; r.Height -= HeaderHeight + FooterHeight; r.Y += HeaderHeight; return r; @@ -77,7 +77,7 @@ namespace RecipesAndPrinting // provided by those formatters. // // Therefore, setup the formatters, and ask super to count the pages. - public override int NumberOfPages { + public override nint NumberOfPages { get { PrintFormatters = new UIPrintFormatter [0]; SetupPrintFormatters (); @@ -89,9 +89,9 @@ namespace RecipesAndPrinting // a UIMarkupTextPrintFormatter and add that formatter to the printing job. void SetupPrintFormatters () { - RectangleF contentArea = ContentArea; - float previousFormatterMaxY = contentArea.Top; - int page = 0; + CGRect contentArea = ContentArea; + nfloat previousFormatterMaxY = contentArea.Top; + nint page = 0; foreach (Recipe recipe in recipes) { string html = recipe.HtmlRepresentation; @@ -115,14 +115,14 @@ namespace RecipesAndPrinting AddPrintFormatter (formatter, page); page = formatter.StartPage + formatter.PageCount - 1; - + previousFormatterMaxY = formatter.RectangleForPage (page).Bottom; } } // Custom UIPrintPageRenderer's may override this class to draw a custom print page header. // To illustrate that, this class sets the date in the header. - public override void DrawHeaderForPage (int index, RectangleF headerRect) + public override void DrawHeaderForPage (nint index, CGRect headerRect) { NSDateFormatter dateFormatter = new NSDateFormatter (); dateFormatter.DateFormat = "MMMM d, yyyy 'at' h:mm a"; @@ -134,7 +134,7 @@ namespace RecipesAndPrinting dateString.Dispose (); } - public override void DrawFooterForPage (int index, RectangleF footerRect) + public override void DrawFooterForPage (nint index, CGRect footerRect) { NSString footer = new NSString (string.Format ("Page {0} of {1}", index - pageRange.Location + 1, pageRange.Length)); footer.DrawString (footerRect, SystemFont, UILineBreakMode.Clip, UITextAlignment.Center); @@ -147,13 +147,13 @@ namespace RecipesAndPrinting // We do this to intermix/overlay our custom drawing onto the recipe presentation. // We draw the upper portion of the recipe presentation by hand (image, title, desc), // and the bottom portion is drawn via the UIMarkupTextPrintFormatter. - public override void DrawPrintFormatterForPage (UIPrintFormatter printFormatter, int page) + public override void DrawPrintFormatterForPage (UIPrintFormatter printFormatter, nint page) { base.DrawPrintFormatterForPage (printFormatter, page); // To keep our custom drawing in sync with the printFormatter, base our drawing // on the formatters rect. - RectangleF rect = printFormatter.RectangleForPage (page); + CGRect rect = printFormatter.RectangleForPage (page); // Use a bezier path to draw the borders. // We may potentially choose not to draw either the top or bottom line @@ -169,7 +169,7 @@ namespace RecipesAndPrinting rect.Y -= RecipeInfoHeight; border.MoveTo (rect.Location); - border.AddLineTo (new PointF (rect.Right, rect.Top)); + border.AddLineTo (new CGPoint (rect.Right, rect.Top)); Recipe recipe = recipeFormatterMap[printFormatter]; @@ -179,14 +179,14 @@ namespace RecipesAndPrinting // Draw the left border border.MoveTo (rect.Location); - border.AddLineTo (new PointF (rect.Left, rect.Bottom)); + border.AddLineTo (new CGPoint (rect.Left, rect.Bottom)); // Draw the right border - border.MoveTo (new PointF (rect.Right, rect.Top)); - border.AddLineTo (new PointF (rect.Right, rect.Bottom)); + border.MoveTo (new CGPoint (rect.Right, rect.Top)); + border.AddLineTo (new CGPoint (rect.Right, rect.Bottom)); if (page == printFormatter.StartPage + printFormatter.PageCount - 1) - border.AddLineTo (new PointF (rect.Left, rect.Bottom)); + border.AddLineTo (new CGPoint (rect.Left, rect.Bottom)); // Set the UIColor to be used by the current graphics context, and then stroke // stroke the current path that is defined by the border bezier path. @@ -196,36 +196,36 @@ namespace RecipesAndPrinting // Custom code to draw upper portion of the recipe presentation (image, title, desc). // The argument rect is the full size of the recipe presentation. - void DrawRecipe (Recipe recipe, RectangleF rect) + void DrawRecipe (Recipe recipe, CGRect rect) { DrawRecipeImage (recipe.Image, rect); DrawRecipeName (recipe.Name, rect); DrawRecipeInfo (recipe.AggregatedInfo, rect); } - void DrawRecipeImage (UIImage image, RectangleF rect) + void DrawRecipeImage (UIImage image, CGRect rect) { // Create a new rect based on the size of the header area - RectangleF imageRect = RectangleF.Empty; + CGRect imageRect = CGRect.Empty; // Scale the image to fit in the infoRect - float maxImageDimension = RecipeInfoHeight - Padding * 2; - float largestImageDimension = Math.Max (image.Size.Width, image.Size.Height); - float scale = maxImageDimension / largestImageDimension; + nfloat maxImageDimension = RecipeInfoHeight - Padding * 2; + nfloat largestImageDimension = (nfloat)Math.Max (image.Size.Width, image.Size.Height); + nfloat scale = maxImageDimension / largestImageDimension; - imageRect.Size = new SizeF (image.Size.Width * scale, image.Size.Height * scale); + imageRect.Size = new CGSize (image.Size.Width * scale, image.Size.Height * scale); // Place the image rect at the x,y defined by the argument rect - imageRect.Location = new PointF (rect.Left + Padding, rect.Top + Padding); + imageRect.Location = new CGPoint (rect.Left + Padding, rect.Top + Padding); // Ask the image to draw in the image rect image.Draw (imageRect); } // Custom drawing code to put the recipe name in the title section of the recipe presentation's header. - void DrawRecipeName (string name, RectangleF rect) + void DrawRecipeName (string name, CGRect rect) { - RectangleF nameRect = RectangleF.Empty; + CGRect nameRect = CGRect.Empty; nameRect.X = rect.Left + RecipeInfoHeight; nameRect.Y = rect.Top + Padding; nameRect.Width = rect.Width - RecipeInfoHeight; @@ -240,9 +240,9 @@ namespace RecipesAndPrinting // Custom drawing code to put the recipe recipe description, and prep time // in the title section of the recipe presentation's header. - void DrawRecipeInfo (string info, RectangleF rect) + void DrawRecipeInfo (string info, CGRect rect) { - RectangleF infoRect = RectangleF.Empty; + CGRect infoRect = CGRect.Empty; infoRect.X = rect.Left + RecipeInfoHeight; infoRect.Y = rect.Top + TitleSize * 2; infoRect.Width = rect.Width - RecipeInfoHeight; diff --git a/RecipesAndPrinting/RecipeTableViewCell.cs b/RecipesAndPrinting/RecipeTableViewCell.cs index 34a9b893..934b31e0 100644 --- a/RecipesAndPrinting/RecipeTableViewCell.cs +++ b/RecipesAndPrinting/RecipeTableViewCell.cs @@ -25,10 +25,10 @@ // using System; -using System.Drawing; +using CoreGraphics; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting { @@ -48,23 +48,23 @@ namespace RecipesAndPrinting public RecipeTableViewCell (UITableViewCellStyle style, NSString identifier) : base (style, identifier) { - imageView = new UIImageView (RectangleF.Empty); + imageView = new UIImageView (CGRect.Empty); ContentView.AddSubview (imageView); - descriptionLabel = new UILabel (RectangleF.Empty); + descriptionLabel = new UILabel (CGRect.Empty); descriptionLabel.Font = UIFont.SystemFontOfSize (12.0f); descriptionLabel.TextColor = UIColor.DarkGray; descriptionLabel.HighlightedTextColor = UIColor.White; ContentView.AddSubview (descriptionLabel); - prepTimeLabel = new UILabel (RectangleF.Empty); + prepTimeLabel = new UILabel (CGRect.Empty); prepTimeLabel.TextAlignment = UITextAlignment.Right; prepTimeLabel.Font = UIFont.SystemFontOfSize (12.0f); prepTimeLabel.TextColor = UIColor.Black; prepTimeLabel.HighlightedTextColor = UIColor.White; ContentView.AddSubview (prepTimeLabel); - nameLabel = new UILabel (RectangleF.Empty); + nameLabel = new UILabel (CGRect.Empty); nameLabel.Font = UIFont.BoldSystemFontOfSize (14.0f); nameLabel.TextColor = UIColor.Black; nameLabel.HighlightedTextColor = UIColor.White; @@ -85,39 +85,39 @@ namespace RecipesAndPrinting } } - RectangleF ImageViewFrame { + CGRect ImageViewFrame { get { if (Editing) { - return new RectangleF (EditingInset, 0.0f, ImageSize, ImageSize); + return new CGRect (EditingInset, 0.0f, ImageSize, ImageSize); } else { - return new RectangleF (0.0f, 0.0f, ImageSize, ImageSize); + return new CGRect (0.0f, 0.0f, ImageSize, ImageSize); } } } - RectangleF NameLabelFrame { + CGRect NameLabelFrame { get { if (Editing) { - return new RectangleF (ImageSize + EditingInset + TextLeftMargin, 4.0f, ContentView.Bounds.Width - ImageSize - EditingInset - TextLeftMargin, 16.0f); + return new CGRect (ImageSize + EditingInset + TextLeftMargin, 4.0f, ContentView.Bounds.Width - ImageSize - EditingInset - TextLeftMargin, 16.0f); } else { - return new RectangleF (ImageSize + TextLeftMargin, 4.0f, ContentView.Bounds.Width - ImageSize - TextLeftMargin - PrepTimeWidth, 16.0f); + return new CGRect (ImageSize + TextLeftMargin, 4.0f, ContentView.Bounds.Width - ImageSize - TextLeftMargin - PrepTimeWidth, 16.0f); } } } - RectangleF DescriptionLabelFrame { + CGRect DescriptionLabelFrame { get { if (Editing) { - return new RectangleF (ImageSize + EditingInset + TextLeftMargin, 22.0f, ContentView.Bounds.Width - ImageSize - EditingInset - TextLeftMargin, 16.0f); + return new CGRect (ImageSize + EditingInset + TextLeftMargin, 22.0f, ContentView.Bounds.Width - ImageSize - EditingInset - TextLeftMargin, 16.0f); } else { - return new RectangleF (ImageSize + TextLeftMargin, 22.0f, ContentView.Bounds.Width - ImageSize - TextLeftMargin, 16.0f); + return new CGRect (ImageSize + TextLeftMargin, 22.0f, ContentView.Bounds.Width - ImageSize - TextLeftMargin, 16.0f); } } } - RectangleF PrepTimeLabelFrame { + CGRect PrepTimeLabelFrame { get { - return new RectangleF (ContentView.Bounds.Width - PrepTimeWidth - TextRightMargin, 4.0f, PrepTimeWidth, 16.0f); + return new CGRect (ContentView.Bounds.Width - PrepTimeWidth - TextRightMargin, 4.0f, PrepTimeWidth, 16.0f); } } diff --git a/RecipesAndPrinting/RecipesAndPrinting.csproj b/RecipesAndPrinting/RecipesAndPrinting.csproj index 05a69b4b..5ba59bc1 100644 --- a/RecipesAndPrinting/RecipesAndPrinting.csproj +++ b/RecipesAndPrinting/RecipesAndPrinting.csproj @@ -23,6 +23,7 @@ None True + --registrar:static --nofastsim --override-abi x86_64 none @@ -59,7 +60,9 @@ - + + \Developer\MonoTouch\usr\lib\mono\Xamarin.iOS\Xamarin.iOS.dll + @@ -121,4 +124,4 @@ - \ No newline at end of file + diff --git a/RecipesAndPrinting/RecipesController.cs b/RecipesAndPrinting/RecipesController.cs index e02012f0..7e6bf5fb 100644 --- a/RecipesAndPrinting/RecipesController.cs +++ b/RecipesAndPrinting/RecipesController.cs @@ -30,8 +30,8 @@ using System.Reflection; using System.Collections; using System.Collections.Generic; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace RecipesAndPrinting {