From 3524e0b79086cff2b0e88ba83e5d4e4c3dd924c5 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Hernandez Diaz Date: Mon, 30 Jun 2014 12:01:14 -0500 Subject: [PATCH] Fixes to compile Fix imports Change autorelease pool Update Project with backup Added single tap event Some minor fixes --- OpenFlowSharp/ImageUtils.cs | 1 + OpenFlowSharp/OpenFlowSharp.csproj | 7 +- OpenFlowSharp/OpenFlowView.cs | 44 ++++++-- OpenFlowSharp/backup/OpenFlowSharp.csproj | 78 +++++++++++++ Sample/Info.plist | 8 ++ Sample/Main.cs | 7 +- Sample/Sample.csproj | 10 +- Sample/SampleViewController.xib.cs | 47 ++++---- Sample/backup/Sample.csproj | 130 ++++++++++++++++++++++ 9 files changed, 288 insertions(+), 44 deletions(-) create mode 100644 OpenFlowSharp/backup/OpenFlowSharp.csproj create mode 100644 Sample/Info.plist create mode 100644 Sample/backup/Sample.csproj diff --git a/OpenFlowSharp/ImageUtils.cs b/OpenFlowSharp/ImageUtils.cs index 4dbea8c..6e8d568 100644 --- a/OpenFlowSharp/ImageUtils.cs +++ b/OpenFlowSharp/ImageUtils.cs @@ -26,6 +26,7 @@ using MonoTouch.UIKit; using MonoTouch.CoreGraphics; using System.Drawing; +using MonoTouch.ObjCRuntime; namespace OpenFlowSharp { diff --git a/OpenFlowSharp/OpenFlowSharp.csproj b/OpenFlowSharp/OpenFlowSharp.csproj index 9065173..7887639 100644 --- a/OpenFlowSharp/OpenFlowSharp.csproj +++ b/OpenFlowSharp/OpenFlowSharp.csproj @@ -6,10 +6,9 @@ 9.0.21022 2.0 {A8CE55FC-1D12-4DB5-A5F8-836928F7BCD9} - {E613F3A2-FE9C-494F-B74E-F63BCB86FEA6};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library OpenFlowSharp - MainWindow.xib OpenFlowSharp 3.0 v3.5 @@ -22,7 +21,6 @@ DEBUG prompt 4 - x86 None True @@ -32,7 +30,6 @@ bin\iPhoneSimulator\Release prompt 4 - x86 None False @@ -44,7 +41,6 @@ DEBUG prompt 4 - x86 iPhone Developer True @@ -54,7 +50,6 @@ bin\iPhone\Release prompt 4 - x86 iPhone Developer False diff --git a/OpenFlowSharp/OpenFlowView.cs b/OpenFlowSharp/OpenFlowView.cs index e57a7be..9a010bf 100644 --- a/OpenFlowSharp/OpenFlowView.cs +++ b/OpenFlowSharp/OpenFlowView.cs @@ -86,7 +86,7 @@ public int NumberOfImages { set { numberOfImages = value; scrollView.ContentSize = new SizeF ((float)(value * coverSpacing + Bounds.Size.Width), Bounds.Size.Height); - if (selectedCoverView == null) + if (selectedCoverView == null && numberOfImages != 0 ) SetSelectedCover (0); Layout (); } @@ -130,6 +130,8 @@ public OpenFlowView (RectangleF bounds, IOpenFlowDataSource dataSource) : base ( this.dataSource = dataSource; SetupInitialState (); + + this.BackgroundColor=UIColor.Clear; #if AUTOMATIC_DEMO Thread t = new Thread (delegate (object a) { @@ -316,6 +318,7 @@ public void SetSelectedCover (int newSelectedCover) UpdateCoverImage (cover); scrollView.Layer.AddSublayer (cover.Layer); LayoutCover (cover, newSelectedCover, false); + this.BringSubviewToFront(cover); } lowerVisibleCover = newLowerBound; @@ -435,16 +438,32 @@ public UIImage this [int idx] { return coverImages [idx]; } set { - var imageWithReflection = ImageUtils.AddImageReflection (value, kReflectionFraction); - coverImages [idx] = imageWithReflection; - coverImageHeights [idx] = value.Size.Height; - - // If the image is onscreen, set its image and call layoutCover - ItemView aCover; - - if (onscreenCovers.TryGetValue (idx, out aCover)){ - aCover.SetImage (imageWithReflection, value.Size.Height, kReflectionFraction); - LayoutCover (aCover, selectedCoverView.Number, false); + if( value != null ) + { + UIImage img; + if( coverImages.TryGetValue( idx-15, out img )) + { + img=null; + coverImages.Remove(idx-15); + } + if( coverImages.TryGetValue( idx+15, out img )) + { + img=null; + coverImages.Remove(idx+15); + } + + + var imageWithReflection = ImageUtils.AddImageReflection (value, kReflectionFraction); + coverImages [idx] = imageWithReflection; + coverImageHeights [idx] = value.Size.Height; + + // If the image is onscreen, set its image and call layoutCover + ItemView aCover; + + if (onscreenCovers.TryGetValue (idx, out aCover)){ + aCover.SetImage (imageWithReflection, value.Size.Height, kReflectionFraction); + LayoutCover (aCover, selectedCoverView.Number, false); + } } } } @@ -500,6 +519,7 @@ public override void TouchesMoved (MonoTouch.Foundation.NSSet touches, UIEvent e } public event EventHandler Changed; + public event EventHandler SingleTap; public override void TouchesEnded (MonoTouch.Foundation.NSSet touches, UIEvent evt) { @@ -513,6 +533,8 @@ public override void TouchesEnded (MonoTouch.Foundation.NSSet touches, UIEvent e if (targetCover != null && (targetCover.Number != selectedCoverView.Number)) SetSelectedCover (targetCover.Number); + if( this.SingleTap != null ) + this.SingleTap(this,new EventArgs()); } CenterOnSelectedCover (true); diff --git a/OpenFlowSharp/backup/OpenFlowSharp.csproj b/OpenFlowSharp/backup/OpenFlowSharp.csproj new file mode 100644 index 0000000..9065173 --- /dev/null +++ b/OpenFlowSharp/backup/OpenFlowSharp.csproj @@ -0,0 +1,78 @@ + + + + Debug + iPhoneSimulator + 9.0.21022 + 2.0 + {A8CE55FC-1D12-4DB5-A5F8-836928F7BCD9} + {E613F3A2-FE9C-494F-B74E-F63BCB86FEA6};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + OpenFlowSharp + MainWindow.xib + OpenFlowSharp + 3.0 + v3.5 + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG + prompt + 4 + x86 + None + True + + + none + false + bin\iPhoneSimulator\Release + prompt + 4 + x86 + None + False + + + true + full + false + bin\iPhone\Debug + DEBUG + prompt + 4 + x86 + iPhone Developer + True + + + none + false + bin\iPhone\Release + prompt + 4 + x86 + iPhone Developer + False + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sample/Info.plist b/Sample/Info.plist new file mode 100644 index 0000000..4880da4 --- /dev/null +++ b/Sample/Info.plist @@ -0,0 +1,8 @@ + + + + + NSMainNibFile + MainWindow + + diff --git a/Sample/Main.cs b/Sample/Main.cs index 9bdfbf2..9c7bd00 100644 --- a/Sample/Main.cs +++ b/Sample/Main.cs @@ -49,10 +49,11 @@ public partial class AppDelegate : UIApplicationDelegate public override bool FinishedLaunching (UIApplication app, NSDictionary options) { sample = new SampleViewController (); - - window.AddSubview (sample.View); + + this.window.RootViewController = sample; window.MakeKeyAndVisible (); - + //ViewDidLoad was not fired at start + sample.ViewDidLoad (); return true; } diff --git a/Sample/Sample.csproj b/Sample/Sample.csproj index 3418694..74ef3bd 100644 --- a/Sample/Sample.csproj +++ b/Sample/Sample.csproj @@ -6,10 +6,9 @@ 9.0.21022 2.0 {BBBC1BB1-9A6B-452F-9894-0D4FD75D7921} - {E613F3A2-FE9C-494F-B74E-F63BCB86FEA6};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe Sample - MainWindow.xib Sample 3.0 v3.5 @@ -79,8 +78,8 @@ - - + + @@ -127,4 +126,7 @@ + + + \ No newline at end of file diff --git a/Sample/SampleViewController.xib.cs b/Sample/SampleViewController.xib.cs index 3aa4362..ce0b695 100644 --- a/Sample/SampleViewController.xib.cs +++ b/Sample/SampleViewController.xib.cs @@ -45,7 +45,7 @@ public partial class SampleViewController : UIViewController, IOpenFlowDataSourc OpenFlowView flowView; AutoResetEvent signal = new AutoResetEvent (false); Queue tasks = new Queue (); - + #region IOpenFlowDataSource implementation UIImage PrepareFlickrPhoto (UIImage image, SizeF cropSize) { @@ -139,7 +139,6 @@ UIImage IOpenFlowDataSource.GetDefaultImage () { return UIImage.FromFile ("default.png"); } - #endregion #region Constructors @@ -162,14 +161,21 @@ void Initialize () { flowView = new OpenFlowView (UIScreen.MainScreen.Bounds, this); View = flowView; - - using (var alertView = new UIAlertView ("OpenFlowSharp Demo Data Source", - "Would you like to download images from Flickr or use 30 sample images included with this project?", - null, "Flickr", - "Samples (all at once)", - "Samples (using threads)")){ + } + + public void ViewDidLoad () + { + base.ViewDidLoad( ); + + Console.WriteLine ("ViewDidLoad"); + + var alertView = new UIAlertView ("OpenFlowSharp Demo Data Source", + "Would you like to download images from Flickr or use 30 sample images included with this project?", + null, "Flickr", + "Samples (all at once)", + "Samples (using threads)"); alertView.Dismissed += delegate(object sender, UIButtonEventArgs e) { - switch (e.ButtonIndex){ + switch (e.ButtonIndex) { // Flickr case 0: flickr = new Flickr (apiKey, sharedSecret); @@ -191,23 +197,23 @@ void Initialize () }); break; - // Load images on demand on a worker thread + // Load images on demand on a worker thread case 2: flowView.NumberOfImages = 30; break; - // Sync case, load all images at startup + // Sync case, load all images at startup case 1: LoadAllImages (); return; } - - // Start our thread queue system - new Thread (Worker).Start (); - signal.Set (); + }; - alertView.Show (); - } + alertView.Show (); + + // Start our thread queue system + new Thread (Worker).Start (); + signal.Set (); } public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) @@ -222,21 +228,22 @@ void Worker () // Create the NSAutoreleasePool so that any NSObjects that // the ObjC runtime creates are disposed using it, otherwise // ObjC just leaks them. - using (var releasePool = new NSAutoreleasePool ()){ while (signal.WaitOne ()){ while (true){ NSAction task; - + lock (tasks){ if (tasks.Count > 0) task = tasks.Dequeue (); else break; } + using (var releasePool = new NSAutoreleasePool ()){ task (); + } + task=null; } } - } } #endregion } diff --git a/Sample/backup/Sample.csproj b/Sample/backup/Sample.csproj new file mode 100644 index 0000000..3418694 --- /dev/null +++ b/Sample/backup/Sample.csproj @@ -0,0 +1,130 @@ + + + + Debug + iPhoneSimulator + 9.0.21022 + 2.0 + {BBBC1BB1-9A6B-452F-9894-0D4FD75D7921} + {E613F3A2-FE9C-494F-B74E-F63BCB86FEA6};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Exe + Sample + MainWindow.xib + Sample + 3.0 + v3.5 + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG + prompt + 4 + None + True + + + none + false + bin\iPhoneSimulator\Release + prompt + 4 + False + None + + + true + full + false + bin\iPhone\Debug + DEBUG + prompt + 4 + True + iPhone Developer: Miguel de Icaza (6YW2BSTNRQ) + None + + + none + false + bin\iPhone\Release + prompt + 4 + False + iPhone Developer + None + + + + + + + + False + flickrnet.dll + + + + + MainWindow.xib + + + + SampleViewController.xib + + + SampleViewController.xib + + + + + + + + + {A8CE55FC-1D12-4DB5-A5F8-836928F7BCD9} + OpenFlowSharp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file