wp7, droid, iphone, oh my!
DESCRIPTION
Slides for the DDD8a Modern .Net day on MonoTouch, MonoDroid and Windows Phone 7. The videos are up on YouTube and are talked over "live" so apologies if they don't make too much sense!TRANSCRIPT
![Page 1: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/1.jpg)
WP7, iPhone, AndroidOh my!
Chris Hardy
Modern .NET dayReading 23rd October 2010
![Page 2: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/2.jpg)
Chris Hardy
• ASPInsider
• Mobile is my hobby
• http://twitter.com/chrisntr
![Page 6: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/6.jpg)
Covering...
• Windows Phone 7
• MonoTouch
• MonoDroid
• Code reuse
• Porting code
• Demos
![Page 7: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/7.jpg)
Windows Phone 7
• Windows Only
• Visual Studio 2010 / Expression Blend 4
• Silverlight for Windows Phone...
• Great information for developers
![Page 8: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/8.jpg)
MonoTouch
• Mac only
• MonoDevelop
• Apple’s Interface Builder
• Superset of Silverlight 3
• Good community around
![Page 9: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/9.jpg)
MonoDroid(currently in preview form)
• Cross platform
• Visual Studio 2010 / MonoDevelop
• XML Files / DroidDraw
• Superset of Silverlight 3
• Early days
![Page 10: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/10.jpg)
Windows Phone 7
• Metro
• Panorama/Pivot
• Launchers/Choosers
• Tombstoning
![Page 11: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/11.jpg)
Metro
http://crocusgirl.wordpress.com/
![Page 12: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/12.jpg)
Panorama/Pivot
![Page 13: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/13.jpg)
Launchers/Choosers• CameraCaptureTask
• EmailAddressChooserTask
• MarketplaceHubTask
• PhoneCallTask
• PhotoChooserTask
• SearchTask
• SmsComposeTask
![Page 14: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/14.jpg)
Tombstoning
sort of multi-tasking
![Page 15: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/15.jpg)
Demo
Twitter on Windows Phone 7
![Page 16: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/16.jpg)
http://www.youtube.com/watch?v=CZcS5PYG9kw
Twitter on Windows Phone 7
![Page 17: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/17.jpg)
What is MonoTouch?
![Page 18: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/18.jpg)
What is Mono?
The .Net Frameworkcreated by Miguel De Icaza
et al.
![Page 19: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/19.jpg)
Miguel de Icaza
![Page 20: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/20.jpg)
Mono’s JIT Engine
CIL
Mono
Memory
![Page 21: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/21.jpg)
Apple Rules
• Contractual Requirements
• No interpreted code
• No shared libraries
• Kernel Limitations
• iPhone OS 2.0+ disables JIT
![Page 22: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/22.jpg)
Mono’s AOT Engine
CIL
Mono
AOTMono Runtime
ARM
Native Code
![Page 23: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/23.jpg)
MonoTouch Features• mtouch• MonoDevelop iPhone Add-In• CocoaTouch.NET / monotouch.dll• Full static AOT compiler• Support for all your existing code• Reflection• Generics• LINQ• Anonymous Methods• Lambda’s etc...
![Page 24: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/24.jpg)
MonoTouch’s APIs
![Page 25: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/25.jpg)
The Bindings• MonoTouch namespace
• MonoTouch.Foo namespace
• Maps to CocoaTouch’s Foo Framework
• 1:1 Mapping of classes.
• MonoTouch.UIKit.UILabel
• CocoaTouch’s UIKit framework, UILabel class
![Page 26: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/26.jpg)
Strong Types
• Objective-C
• Arrays are weakly typed:• NSArray return values.
• MonoTouch has strong types
• UIView[] Subviews { get; }• vs• NSArray *subviews;
• Intellisense - explore the API...
![Page 27: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/27.jpg)
Garbage Collection• Automatic:
• Mono’s GC will collect objects on demand
• Deterministic:
• Use when you need control.
• Every object in MonoTouch implements IDisposable
using (var image = UIImage.FromFile(“foo.png”)){
surface.DrawImage(image, 20, 20);
}
![Page 28: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/28.jpg)
Linkerand the application size...
![Page 29: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/29.jpg)
Linking Assemblies
![Page 30: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/30.jpg)
App-store MonoTouch Minimum App Size
~6MB
![Page 31: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/31.jpg)
Integration
• Tight integration between MD and IB
• IB produces XIBs with MD parses
• Automatic class generation in MD
• Generates partial classes for all types, outlets and actions defined in Interface Builder
![Page 32: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/32.jpg)
MonoTouch Events
• Supports Objective-C pattern:
webView.Delegate = new MyWebViewDelegate();
• C# style events as well:
webView.PageLoaded += delegate {HideSpinningWheel();
}
![Page 33: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/33.jpg)
Debugging
• Console.WriteLine(“Debugging inside of MonoTouch”);
• printf(“I made it to this line!\n”)
![Page 34: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/34.jpg)
Debugger
• MonoTouch debugger leverages Mono’s new Soft-Debugger
• Supports the Simulator
• Supports the Device...
• even over WiFi
![Page 35: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/35.jpg)
Professional iPhone Programming with
MonoTouch and .NET/C#
Wallace B. McClureRory Blyth
Martin BowlingCraig Dunn
and me... Chris Hardy
Out Now!
![Page 36: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/36.jpg)
Demo
Twitter on iPhone with MonoTouch
![Page 37: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/37.jpg)
Twitter on iPhone with MonoTouch
Will probably do a video in the future :)
![Page 38: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/38.jpg)
What is MonoDroid?
![Page 39: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/39.jpg)
What is MonoDroid?
![Page 40: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/40.jpg)
What is MonoDroid?
C# on Android
![Page 41: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/41.jpg)
What is MonoDroid?
A commercial product
![Page 42: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/42.jpg)
What is MonoDroid?
Preview releaseNot AlphaNot Beta
![Page 43: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/43.jpg)
What is MonoDroid?
Cross-platform
![Page 44: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/44.jpg)
What is MonoDroid?
Sign-up for preview access
http://go-mono.com/monodroid/
![Page 45: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/45.jpg)
Demo
Twitter on Android with MonoDroid
![Page 46: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/46.jpg)
Twitter on Android with MonoDroid
http://www.youtube.com/watch?v=TKXgugOj56I
![Page 47: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/47.jpg)
Application Stores
![Page 48: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/48.jpg)
Windows Phone 7$99 Per Year
iPhone$99 Per Year
Android$25 Registration
![Page 49: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/49.jpg)
Code reuse
![Page 50: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/50.jpg)
Code reuse
Json.Net
FlickrNet
XNATouch
![Page 51: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/51.jpg)
Rebuild your libraries
• Can’t just use any DLL
• Re-compile for each lib
• Each framework has its own class library
![Page 52: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/52.jpg)
Not an abstraction!
![Page 53: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/53.jpg)
Not an abstraction!
• Platform specific APIs
• Platform specific look and feel
![Page 54: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/54.jpg)
Mono for WP7?
![Page 55: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/55.jpg)
Mono for WP7?
• Look at Mono code and copy over!
• IQueryable support in WP7
• More later...
![Page 56: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/56.jpg)
Porting over Hanselminutes
![Page 57: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/57.jpg)
Porting over Hanselminutes
hanselminutesiphone.codeplex.com
![Page 58: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/58.jpg)
Porting over Hanselminutes
• Make sure your business logic is separate
• Use actions for returning results
![Page 59: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/59.jpg)
Getting XML
![Page 60: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/60.jpg)
Persisting the XML
![Page 61: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/61.jpg)
Isolated Storagevs
File Storage
![Page 62: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/62.jpg)
Storing data void SaveLocal(string data) {#if (MonoTouch || MonoDroid) File.WriteAllText(_localPath, data);#elif WINDOWS_PHONE using (var appStorage = IsolatedStorageFile.GetUserStoreForApplication()) { var file = appStorage.OpenFile(_localPath, FileMode.Create); FileExtension.WriteAllText(file, data); }#endif }
![Page 63: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/63.jpg)
Storing data void SaveLocal(string data) {#if (MonoTouch || MonoDroid) File.WriteAllText(_localPath, data);#elif WINDOWS_PHONE using (var appStorage = IsolatedStorageFile.GetUserStoreForApplication()) { var file = appStorage.OpenFile(_localPath, FileMode.Create); FileExtension.WriteAllText(file, data); }#endif }
![Page 64: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/64.jpg)
No File.WriteAllText?
No problem!
![Page 65: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/65.jpg)
Implementing File.WriteAllText
public static void WriteAllText(IsolatedStorageFileStream fileStream, string data) { using (StreamWriter sw = new StreamWriter(fileStream)) { sw.Write(data); sw.Close(); } }
public static void WriteAllText(string path, string contents) { WriteAllText(path, contents, Encoding.UTF8); }
public static void WriteAllText(string path, string contents, Encoding encoding) { using (StreamWriter sw = new StreamWriter(path, false, encoding)) { sw.Write(contents); } }
![Page 66: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/66.jpg)
Limited WebClient calls
![Page 67: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/67.jpg)
Downloading a file - MonoTouch
_webClient = new WebClient ();_webClient.DownloadFileCompleted += (sender, e) =>{ _fileDownloaded = true; if (_downloadCompletedSuccessfully) { File.Copy (_show.PartialAudioPath, _show.OfflineAudioPath); } UIHelper.StopInternetActivity ();};
_webClient.DownloadProgressChanged += HandleClientDownloadProgressChanged;
_webClient.DownloadFileAsync (new Uri (_show.Url), _show.PartialAudioPath);
![Page 68: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/68.jpg)
Downloading a file WP7var client = new WebClient();client.DownloadProgressChanged += (s, e) =>{ progressBar1.Value = e.ProgressPercentage / 100;};
client.OpenReadCompleted += (s, e) =>{ using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
using (var fs = new IsolatedStorageFileStream(CurrentShow.OfflineAudioPath, FileMode.Create, isoStore)) { int bytesRead; byte[] bytes = new byte[1024 * 1024 * 1]; // 1meg while ((bytesRead = e.Result.Read(bytes, 0, bytes.Length)) != 0) { fs.Write(bytes, 0, bytesRead); } _fileDownloaded = true; fs.Flush(); }};client.OpenReadAsync(new Uri(CurrentShow.Url, UriKind.Absolute));
![Page 69: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/69.jpg)
Porting your code
• MOMA for Mobile?
![Page 70: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/70.jpg)
Conclusions
![Page 71: WP7, Droid, iPhone, Oh my!](https://reader031.vdocuments.net/reader031/viewer/2022013003/5553083fb4c9054e3f8b4b87/html5/thumbnails/71.jpg)
Thanks! Any questions?twitter.com/[email protected]