WP7, iPhone,Android
Oh my!
Chris Hardy
Modern .NET day
Reading 23rd October 2010
Chris Hardy
• ASPInsider
• Mobile is my hobby
• http://twitter.com/chrisntr
http://greatfridays.com
http://emmawatson.com
http://dominion-funds.com
Covering...
• Windows Phone 7
• MonoTouch
• MonoDroid
• Code reuse
• Porting code
• Demos
Windows Phone 7
•Windows Only
•Visual Studio 2010 / Expression Blend 4
• Silverlight for Windows Phone...
• Great informat...
MonoTouch
• Mac only
• MonoDevelop
•Apple’s Interface Builder
• Superset of Silverlight 3
• Good community around
MonoDroid(currently in preview form)
• Cross platform
•Visual Studio 2010 / MonoDevelop
• XML Files / DroidDraw
• Superset...
Windows Phone 7
• Metro
• Panorama/Pivot
• Launchers/Choosers
• Tombstoning
Metro
http://crocusgirl.wordpress.com/
Panorama/Pivot
Launchers/Choosers
• CameraCaptureTask
• EmailAddressChooserTask
• MarketplaceHubTask
• PhoneCallTask
• PhotoChooserTask
•...
Tombstoning
sort of multi-tasking
Demo
Twitter on Windows Phone 7
http://www.youtube.com/watch?v=CZcS5PYG9kw
Twitter on Windows Phone 7
What is MonoTouch?
What is Mono?
The .Net Framework
created by Miguel De Icaza
et al.
Miguel de Icaza
Mono’s JIT Engine
CIL
Mono
Memory
Apple Rules
• Contractual Requirements
• No interpreted code
• No shared libraries
• Kernel Limitations
• iPhone OS 2.0+ d...
Mono’s AOT Engine
CIL
Mono
AOT Mono Runtime
ARM
Native
Code
MonoTouch Features
• mtouch
• MonoDevelop iPhone Add-In
• CocoaTouch.NET / monotouch.dll
• Full static AOT compiler
• Supp...
MonoTouch’s APIs
The Bindings
• MonoTouch namespace
• MonoTouch.Foo namespace
• Maps to CocoaTouch’s Foo Framework
• 1:1 Mapping of classes...
Strong Types
• Objective-C
• Arrays are weakly typed:
• NSArray return values.
• MonoTouch has strong types
• UIView[] Sub...
Garbage Collection
• Automatic:
• Mono’s GC will collect objects on demand
• Deterministic:
• Use when you need control.
•...
Linker
and the application size...
Linking Assemblies
App-store MonoTouch
Minimum App Size
~6MB
Integration
• Tight integration between MD and IB
• IB produces XIBs with MD parses
• Automatic class generation in MD
• G...
MonoTouch Events
• Supports Objective-C pattern:
webView.Delegate = new
MyWebViewDelegate();
• C# style events as well:
we...
Debugging
• Console.WriteLine(“Debugging inside of
MonoTouch”);
• printf(“I made it to this line!n”)
Debugger
• MonoTouch debugger leverages Mono’s
new Soft-Debugger
• Supports the Simulator
• Supports the Device...
• even ...
Professional iPhone
Programming with
MonoTouch and .NET/
C#
Wallace B. McClure
Rory Blyth
Martin Bowling
Craig Dunn
and me...
Demo
Twitter on iPhone with MonoTouch
Twitter on iPhone with MonoTouch
Will probably do a video in the future :)
What is MonoDroid?
What is MonoDroid?
What is MonoDroid?
C# on Android
What is MonoDroid?
A commercial product
What is MonoDroid?
Preview release
Not Alpha
Not Beta
What is MonoDroid?
Cross-platform
What is MonoDroid?
Sign-up for preview
access
http://go-mono.com/monodroid/
Demo
Twitter on Android with MonoDroid
Twitter on Android with MonoDroid
http://www.youtube.com/watch?v=TKXgugOj56I
Application Stores
Windows Phone 7
$99 PerYear
iPhone
$99 PerYear
Android
$25 Registration
Code reuse
Code reuse
Json.Net
FlickrNet
XNATouch
Rebuild your libraries
• Can’t just use any DLL
• Re-compile for each lib
• Each framework has its own class library
Not an abstraction!
Not an abstraction!
• Platform specific APIs
• Platform specific look and feel
Mono for WP7?
Mono for WP7?
• Look at Mono code and copy over!
• IQueryable support in WP7
• More later...
Porting over
Hanselminutes
Porting over
Hanselminutes
hanselminutesiphone.codeplex.com
Porting over
Hanselminutes
• Make sure your business logic is separate
• Use actions for returning results
Getting XML
Persisting the XML
Isolated Storage
vs
File Storage
Storing data
void SaveLocal(string data)
{
#if (MonoTouch || MonoDroid)
File.WriteAllText(_localPath, data);
#elif WINDOWS...
Storing data
void SaveLocal(string data)
{
#if (MonoTouch || MonoDroid)
File.WriteAllText(_localPath, data);
#elif WINDOWS...
No File.WriteAllText?
No problem!
Implementing
File.WriteAllText
public static void WriteAllText(IsolatedStorageFileStream fileStream, string data)
{
using (...
Limited WebClient calls
Downloading a file -
MonoTouch
_webClient = new WebClient ();
_webClient.DownloadFileCompleted += (sender, e) =>
{
	

 _file...
Downloading a file WP7
var client = new WebClient();
client.DownloadProgressChanged += (s, e) =>
{
progressBar1.Value = e.P...
Porting your code
• MOMA for Mobile?
Conclusions
Thanks! Any questions?
twitter.com/chrisntr
chrisntr@gmail.com
Upcoming SlideShare
Loading in …5
×

WP7, Droid, iPhone, Oh my!

3,584 views

Published on

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!

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,584
On SlideShare
0
From Embeds
0
Number of Embeds
616
Actions
Shares
0
Downloads
56
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

WP7, Droid, iPhone, Oh my!

  1. 1. WP7, iPhone,Android Oh my! Chris Hardy Modern .NET day Reading 23rd October 2010
  2. 2. Chris Hardy • ASPInsider • Mobile is my hobby • http://twitter.com/chrisntr
  3. 3. http://greatfridays.com
  4. 4. http://emmawatson.com
  5. 5. http://dominion-funds.com
  6. 6. Covering... • Windows Phone 7 • MonoTouch • MonoDroid • Code reuse • Porting code • Demos
  7. 7. Windows Phone 7 •Windows Only •Visual Studio 2010 / Expression Blend 4 • Silverlight for Windows Phone... • Great information for developers
  8. 8. MonoTouch • Mac only • MonoDevelop •Apple’s Interface Builder • Superset of Silverlight 3 • Good community around
  9. 9. MonoDroid(currently in preview form) • Cross platform •Visual Studio 2010 / MonoDevelop • XML Files / DroidDraw • Superset of Silverlight 3 • Early days
  10. 10. Windows Phone 7 • Metro • Panorama/Pivot • Launchers/Choosers • Tombstoning
  11. 11. Metro http://crocusgirl.wordpress.com/
  12. 12. Panorama/Pivot
  13. 13. Launchers/Choosers • CameraCaptureTask • EmailAddressChooserTask • MarketplaceHubTask • PhoneCallTask • PhotoChooserTask • SearchTask • SmsComposeTask
  14. 14. Tombstoning sort of multi-tasking
  15. 15. Demo Twitter on Windows Phone 7
  16. 16. http://www.youtube.com/watch?v=CZcS5PYG9kw Twitter on Windows Phone 7
  17. 17. What is MonoTouch?
  18. 18. What is Mono? The .Net Framework created by Miguel De Icaza et al.
  19. 19. Miguel de Icaza
  20. 20. Mono’s JIT Engine CIL Mono Memory
  21. 21. Apple Rules • Contractual Requirements • No interpreted code • No shared libraries • Kernel Limitations • iPhone OS 2.0+ disables JIT
  22. 22. Mono’s AOT Engine CIL Mono AOT Mono Runtime ARM Native Code
  23. 23. 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...
  24. 24. MonoTouch’s APIs
  25. 25. 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
  26. 26. 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...
  27. 27. 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); }
  28. 28. Linker and the application size...
  29. 29. Linking Assemblies
  30. 30. App-store MonoTouch Minimum App Size ~6MB
  31. 31. 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
  32. 32. MonoTouch Events • Supports Objective-C pattern: webView.Delegate = new MyWebViewDelegate(); • C# style events as well: webView.PageLoaded += delegate { HideSpinningWheel(); }
  33. 33. Debugging • Console.WriteLine(“Debugging inside of MonoTouch”); • printf(“I made it to this line!n”)
  34. 34. Debugger • MonoTouch debugger leverages Mono’s new Soft-Debugger • Supports the Simulator • Supports the Device... • even over WiFi
  35. 35. Professional iPhone Programming with MonoTouch and .NET/ C# Wallace B. McClure Rory Blyth Martin Bowling Craig Dunn and me... Chris Hardy Out Now!
  36. 36. Demo Twitter on iPhone with MonoTouch
  37. 37. Twitter on iPhone with MonoTouch Will probably do a video in the future :)
  38. 38. What is MonoDroid?
  39. 39. What is MonoDroid?
  40. 40. What is MonoDroid? C# on Android
  41. 41. What is MonoDroid? A commercial product
  42. 42. What is MonoDroid? Preview release Not Alpha Not Beta
  43. 43. What is MonoDroid? Cross-platform
  44. 44. What is MonoDroid? Sign-up for preview access http://go-mono.com/monodroid/
  45. 45. Demo Twitter on Android with MonoDroid
  46. 46. Twitter on Android with MonoDroid http://www.youtube.com/watch?v=TKXgugOj56I
  47. 47. Application Stores
  48. 48. Windows Phone 7 $99 PerYear iPhone $99 PerYear Android $25 Registration
  49. 49. Code reuse
  50. 50. Code reuse Json.Net FlickrNet XNATouch
  51. 51. Rebuild your libraries • Can’t just use any DLL • Re-compile for each lib • Each framework has its own class library
  52. 52. Not an abstraction!
  53. 53. Not an abstraction! • Platform specific APIs • Platform specific look and feel
  54. 54. Mono for WP7?
  55. 55. Mono for WP7? • Look at Mono code and copy over! • IQueryable support in WP7 • More later...
  56. 56. Porting over Hanselminutes
  57. 57. Porting over Hanselminutes hanselminutesiphone.codeplex.com
  58. 58. Porting over Hanselminutes • Make sure your business logic is separate • Use actions for returning results
  59. 59. Getting XML
  60. 60. Persisting the XML
  61. 61. Isolated Storage vs File Storage
  62. 62. 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 }
  63. 63. 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 }
  64. 64. No File.WriteAllText? No problem!
  65. 65. 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); } }
  66. 66. Limited WebClient calls
  67. 67. 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);
  68. 68. Downloading a file WP7 var 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));
  69. 69. Porting your code • MOMA for Mobile?
  70. 70. Conclusions
  71. 71. Thanks! Any questions? twitter.com/chrisntr chrisntr@gmail.com

×