Permalink
Browse files

Merge branch 'master' of https://github.com/xamarin/mobile-samples

1 parent 1cac1db commit cee96ab67a437f4fb4889e6ea6fdd96d3a32813f @conceptdev conceptdev committed Nov 13, 2013
Showing with 1,788 additions and 5,220 deletions.
  1. +1 −1 AsyncAwait/AsyncAwait.sln
  2. +5 −2 AsyncAwait/README.md
  3. +180 −0 AsyncAwait/iOS/AsyncExtrasController.cs
  4. +58 −0 AsyncAwait/iOS/AsyncExtrasController.designer.cs
  5. +118 −0 AsyncAwait/iOS/AsyncExtrasController.xib
  6. +35 −20 AsyncAwait/iOS/ComparisonsOldvsNew/iOSViewController_new.cs
  7. +84 −36 AsyncAwait/iOS/MainStoryboard.storyboard
  8. +6 −2 AsyncAwait/iOS/iOS.csproj
  9. +55 −37 AsyncAwait/iOS/iOSViewController.cs
  10. +8 −1 AsyncAwait/iOS/iOSViewController.designer.cs
  11. +0 −1 ContentControls/AndroidContentControls/AndroidContentControls.csproj
  12. BIN ContentControls/iOSContentControls/Default.png
  13. BIN ContentControls/iOSContentControls/Default@2x.png
  14. BIN ContentControls/iOSContentControls/Images/Icon/512_icon.png
  15. +8 −4 ContentControls/iOSContentControls/Info.plist
  16. BIN ContentControls/iOSContentControls/Resources/Default-568h@2x.png
  17. BIN ContentControls/iOSContentControls/Resources/Icon-60@2x.png
  18. BIN ContentControls/iOSContentControls/Resources/Icon-Small-40@2x.png
  19. BIN ContentControls/iOSContentControls/Resources/Icon-Small.png
  20. BIN ContentControls/iOSContentControls/Resources/Icon-Small@2x.png
  21. BIN ContentControls/iOSContentControls/Resources/Icon.png
  22. BIN ContentControls/iOSContentControls/Resources/Icon@2x.png
  23. +54 −327 ContentControls/iOSContentControls/Screens/iPhone/Browsers/BrowsersHome.xib
  24. +42 −280 ContentControls/iOSContentControls/Screens/iPhone/Browsers/InteractiveBrowser.xib
  25. +30 −227 ContentControls/iOSContentControls/Screens/iPhone/Browsers/LocalBrowser.xib
  26. +85 −493 ContentControls/iOSContentControls/Screens/iPhone/Browsers/WebBrowser.xib
  27. +78 −429 ContentControls/iOSContentControls/Screens/iPhone/CustomizingNavBar/CustomizingNavBarScreen.xib
  28. +33 −239 ContentControls/iOSContentControls/Screens/iPhone/Extra Screens/CustomizableTabScreen.xib
  29. +31 −224 ContentControls/iOSContentControls/Screens/iPhone/Maps/AnnotatedMapScreen.xib
  30. +42 −288 ContentControls/iOSContentControls/Screens/iPhone/Maps/BasicMapScreen.xib
  31. +31 −221 ContentControls/iOSContentControls/Screens/iPhone/Maps/MapWithOverlayScreen.xib
  32. +55 −328 ContentControls/iOSContentControls/Screens/iPhone/Maps/MapsHome.xib
  33. +38 −267 ContentControls/iOSContentControls/Screens/iPhone/Search/SearchScreen.xib
  34. +26 −8 ContentControls/iOSContentControls/iOSContentControls.csproj
  35. BIN ContentControls/iOSContentControls/iTunesArtwork@2x
  36. +1 −1 GraphicsAndAnimation.Android/Resources/Resource.Designer.cs
  37. +0 −1 MWC/MWC.iOS/Info.plist
  38. +4 −3 MWC/MWC.iOS/MWC.iOS.csproj
  39. +2 −1 MultiThreading/AndroidMultiThreading/AndroidMultiThreading.csproj
  40. +6 −0 MultiThreading/AndroidMultiThreading/Properties/AndroidManifest.xml
  41. +40 −1 MultiThreading/AndroidMultiThreading/Resources/Resource.designer.cs
  42. +1 −1 MultiThreading/MultiThreading.sln
  43. +2 −1 Notifications/Notifications.Android/Notifications.Android.csproj
  44. +6 −0 Notifications/Notifications.Android/Properties/AndroidManifest.xml
  45. +95 −95 Notifications/Notifications.sln
  46. BIN Phoneword/PhonewordiOS/Resources/Default-568h@2x.png
  47. +1 −1 SoMA/SoMA.sln
  48. +6 −2 StandardControls/AndroidStandardControls/AndroidStandardControls.csproj
  49. +1 −0 StandardControls/AndroidStandardControls/Home_Adapter.cs
  50. +19 −0 StandardControls/AndroidStandardControls/Resources/Layout/SeekBarScreen.axml
  51. +4 −0 StandardControls/AndroidStandardControls/Resources/Values/dimen.xml
  52. +60 −0 StandardControls/AndroidStandardControls/Screens/ProgressControls/SeekBarScreen.cs
  53. +2 −2 StandardControls/StandardControls.sln
  54. +2 −1 StandardControls/iOSStandardControls/AppDelegate.cs
  55. BIN StandardControls/iOSStandardControls/Default-Landscape~ipad.png
  56. BIN StandardControls/iOSStandardControls/Default-Portrait~ipad.png
  57. BIN StandardControls/iOSStandardControls/Default.png
  58. BIN StandardControls/iOSStandardControls/Default@2x.png
  59. BIN StandardControls/iOSStandardControls/Images/halloween.jpg
  60. +13 −6 StandardControls/iOSStandardControls/Info.plist
  61. BIN StandardControls/iOSStandardControls/Resources/Default-568h@2x.png
  62. BIN StandardControls/iOSStandardControls/Resources/Default-Landscape@2x.png
  63. BIN StandardControls/iOSStandardControls/Resources/Default-Portrait@2x.png
  64. BIN StandardControls/iOSStandardControls/Resources/Icon-60@2x.png
  65. BIN StandardControls/iOSStandardControls/Resources/Icon-72.png
  66. BIN StandardControls/iOSStandardControls/Resources/Icon-72@2x.png
  67. BIN StandardControls/iOSStandardControls/Resources/Icon-76.png
  68. BIN StandardControls/iOSStandardControls/Resources/Icon-76@2x.png
  69. BIN StandardControls/iOSStandardControls/Resources/Icon-Small-40.png
  70. BIN StandardControls/iOSStandardControls/Resources/Icon-Small-40@2x.png
  71. BIN StandardControls/iOSStandardControls/Resources/Icon-Small-50.png
  72. BIN StandardControls/iOSStandardControls/Resources/Icon-Small-50@2x.png
  73. BIN StandardControls/iOSStandardControls/Resources/Icon-Small.png
  74. BIN StandardControls/iOSStandardControls/Resources/Icon-Small@2x.png
  75. BIN StandardControls/iOSStandardControls/Resources/Icon.png
  76. BIN StandardControls/iOSStandardControls/Resources/Icon@2x.png
  77. +0 −2 StandardControls/iOSStandardControls/Screens/iPhone/DatePicker/DatePicker_iPhone.xib.cs
  78. +10 −1 StandardControls/iOSStandardControls/Screens/iPhone/Home/HomeTableViewController.cs
  79. +1 −1 StandardControls/iOSStandardControls/Screens/iPhone/ScrollView/Controller.cs
  80. +117 −595 StandardControls/iOSStandardControls/Screens/iPhone/SegmentedControl/SegmentedControls_iPhone.xib
  81. +1 −1 StandardControls/iOSStandardControls/Screens/iPhone/TapToZoomScrollView/Controller.cs
  82. +36 −10 StandardControls/iOSStandardControls/iOSStandardControls.csproj
  83. BIN StandardControls/iOSStandardControls/iTunesArtwork
  84. BIN StandardControls/iOSStandardControls/iTunesArtwork@2x
  85. +1 −1 TablesLists/TablesLists.sln
  86. +0 −1 TablesLists/iOSTableAndCellStyles/Info.plist
  87. +3 −1 TablesLists/iOSTableAndCellStyles/iOSTableAndCellStyles.csproj
  88. +0 −1 Tasky/Tasky.Core.MD/Tasky.Core.MD.csproj
  89. +2 −2 Tasky/Tasky.sln
  90. +40 −1 Tasky/TaskyDroid/Resources/Resource.designer.cs
  91. +0 −1 Tasky/TaskyDroid/TaskyDroid.csproj
  92. +1 −0 Tasky/TaskyTouch/AppDelegate.cs
  93. +3 −1 Tasky/TaskyTouch/TaskyTouch.csproj
  94. +0 −1 TaskyPro/Tasky.Android/Tasky.Android.csproj
  95. +4 −4 TaskyPro/TaskyMD_Mac.sln
  96. +6 −0 Touch/Touch.Android/Properties/AndroidManifest.xml
  97. +2 −0 Touch/Touch.Android/Touch.Android.csproj
  98. +44 −293 Touch/Touch.iOS/Screens/iPhone/GestureRecognizers/GestureRecognizers_iPhone.xib
  99. +54 −338 Touch/Touch.iOS/Screens/iPhone/Home/Home_iPhone.xib
  100. +59 −378 Touch/Touch.iOS/Screens/iPhone/SimpleTouch/Touches_iPhone.xib
  101. +36 −36 Touch/Touch.sln
@@ -41,6 +41,6 @@ Global
{9F8656FD-07A4-44F7-864E-A94E7C27F529}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
- StartupItem = Droid\Droid.csproj
+ StartupItem = iOS\iOS.csproj
EndGlobalSection
EndGlobal
View
@@ -9,6 +9,9 @@ This sample was first presented in the Xamarin Introduction to C# 5 Async webina
[Xamarin's Introduction to Async article](http://docs.xamarin.com/guides/cross-platform/advanced/async_support_overview)
-The sample apps (for iOS and Android) show a simple implementation of a text & image download using the new C# 5 `async` and `await` syntax.
+The sample apps (for iOS and Android) has two examples:
-Also check out [Miguel's blog post on the subject](http://tirania.org/blog/archive/2013/Aug-15.html).
+* a simple text & image download using the new C# 5 `async` and `await` syntax.
+* another example that shows how to download multiple files in the background and report download progress using `IProgress<T>`/`Progress<T>`. It also demonstrates how to cancel the background downloads using a `CancellationTokenSource`.
+
+Also check out [Miguel's blog post on the subject](http://tirania.org/blog/archive/2013/Aug-15.html).
@@ -0,0 +1,180 @@
+using System;
+using System.Threading.Tasks;
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+using System.Threading;
+using System.Net.Http;
+using System.Collections.Generic;
+using System.Net;
+using System.IO;
+using System.Drawing;
+
+namespace iOS
+{
+ public class DownloadBytesProgress
+ {
+
+ public DownloadBytesProgress(string fileName, int bytesReceived, int totalBytes)
+ {
+ Filename = fileName;
+ BytesReceived = bytesReceived;
+ TotalBytes = totalBytes;
+ }
+ public int TotalBytes { get; private set; }
+ public int BytesReceived { get; private set; }
+ public float PercentComplete { get { return (float) BytesReceived / TotalBytes; } }
+ public string Filename { get; private set; }
+ public bool IsFinished { get { return BytesReceived == TotalBytes; } }
+ }
+
+ public partial class AsyncExtrasController : UIViewController
+ {
+ static readonly string[] ListOfImages = new string[]
+ {
+ "http://xamarin.com/images/tour/amazing-ide.png",
+ "http://xamarin.com/images/how-it-works/chalkboard2.jpg",
+ "http://xamarin.com/images/about/team.jpg",
+ "http://xamarin.com/images/prebuilt/rich-feature-set.jpg",
+ "http://cdn1.xamarin.com/webimages/images/features/shared-code-2.pngXXX",
+ "http://xamarin.com/images/tour/4platforms12.jpg",
+ "http://xamarin.com/images/tour/amazing-ide.png",
+ "http://xamarin.com/images/enterprise/multiple_platforms.png",
+ "http://blog.xamarin.com/wp-content/uploads/2013/07/monkey_cowboy.jpg",
+ "http://docs.xamarin.com/guides/cross-platform/getting_started/introducing_xamarin_studio/Images/19.png"
+ };
+
+
+ List<UIProgressView> progressBars = new List<UIProgressView>();
+ CancellationTokenSource cancellationTokenSource;
+
+ public AsyncExtrasController(IntPtr handle) : base (handle)
+ {
+ }
+
+ public override void DidReceiveMemoryWarning()
+ {
+ // Releases the view if it doesn't have a superview.
+ base.DidReceiveMemoryWarning();
+ }
+
+ public override void ViewDidLoad()
+ {
+ base.ViewDidLoad();
+ StartButton.TouchUpInside += StartDownloadsHandler;
+ CancelButton.TouchUpInside += CancelDownloadsHandler;
+ }
+
+ void CancelDownloadsHandler (object sender, EventArgs e)
+ {
+ if (cancellationTokenSource != null)
+ {
+ StatusTextView.Text = "Cancelling downloads....";
+ cancellationTokenSource.Cancel();
+ }
+ }
+
+ async Task<int> GetBytes(string url, CancellationToken cancelToken, IProgress<DownloadBytesProgress> progressIndicator)
+ {
+ int receivedBytes = 0;
+ int totalBytes = -1;
+ WebClient client = new WebClient();
+
+ using (var stream = await client.OpenReadTaskAsync(url))
+ {
+ byte[] buffer = new byte[4096];
+ Int32.TryParse(client.ResponseHeaders[HttpResponseHeader.ContentLength], out totalBytes);
+
+ for (;;)
+ {
+ int len = await stream.ReadAsync(buffer, 0, buffer.Length);
+ if (len == 0)
+ {
+ await Task.Yield();
+ break;
+ }
+
+ receivedBytes += len;
+ cancelToken.ThrowIfCancellationRequested();
+
+ if (progressIndicator != null)
+ {
+ DownloadBytesProgress args = new DownloadBytesProgress(url, receivedBytes, totalBytes);
+ progressIndicator.Report(args);
+ }
+ }
+ }
+ return receivedBytes;
+ }
+
+ async void StartDownloadsHandler (object sender, EventArgs e)
+ {
+ cancellationTokenSource = new CancellationTokenSource();
+
+ InitializeViews();
+
+ List<Task<int>> tasks = CreateTaskForEachFileToDownload();
+
+ HttpClient client = new HttpClient();
+
+ while (tasks.Count > 0)
+ {
+ var t = await Task.WhenAny(tasks);
+ tasks.Remove(t);
+ ProgressBar.Progress = (float)(ListOfImages.Length - tasks.Count) / ListOfImages.Length;
+ try
+ {
+ await t;
+ ProgressTextView.Text += "** Downloaded " + t.Result + " bytes" + Environment.NewLine;
+ }
+ catch (OperationCanceledException)
+ {
+ ProgressTextView.Text += "## Download was cancelled." + Environment.NewLine;
+ break;
+ }
+ catch (Exception exc)
+ {
+ ProgressTextView.Text += "-- Download ERROR: " + exc.Message + Environment.NewLine;
+ }
+ }
+
+ StatusTextView.Text = "Downloads finished.";
+ cancellationTokenSource = null;
+ }
+
+ void InitializeViews()
+ {
+ StatusTextView.Text = "Downloads starting....";
+ ProgressTextView.Text = String.Empty;
+ ProgressBar.Progress = 0;
+
+ foreach (var item in progressBars)
+ {
+ item.RemoveFromSuperview();
+ }
+ }
+
+ List<Task<int>> CreateTaskForEachFileToDownload()
+ {
+ List<Task<int>> tasks = new List<Task<int>>(ListOfImages.Length);
+
+ for (int idx =0; idx< ListOfImages.Length; idx++)
+ {
+ RectangleF frame = new RectangleF(20f, 276f + idx * 20f, 280f, 2f);
+ UIProgressView pb = new UIProgressView(frame);
+ Add(pb);
+
+ Progress<DownloadBytesProgress> progressReporter = new Progress<DownloadBytesProgress>();
+ progressReporter.ProgressChanged += (s, e) =>
+ {
+ pb.Progress = e.PercentComplete;
+ };
+
+ Task<int> task = GetBytes(ListOfImages[idx], cancellationTokenSource.Token, progressReporter);
+ tasks.Add(task);
+ }
+
+ return tasks;
+ }
+ }
+}
+

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
+ <data>
+ <int key="IBDocument.SystemTarget">1280</int>
+ <string key="IBDocument.SystemVersion">11C25</string>
+ <string key="IBDocument.InterfaceBuilderVersion">1919</string>
+ <string key="IBDocument.AppKitVersion">1138.11</string>
+ <string key="IBDocument.HIToolboxVersion">566.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="NS.object.0">916</string>
+ </object>
+ <array key="IBDocument.IntegratedClassDependencies">
+ <string>IBProxyObject</string>
+ <string>IBUIView</string>
+ </array>
+ <array key="IBDocument.PluginDependencies">
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </array>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+ <integer value="1" key="NS.object.0" />
+ </object>
+ <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <object class="IBProxyObject" id="372490531">
+ <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBProxyObject" id="975951072">
+ <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUIView" id="191373211">
+ <reference key="NSNextResponder" />
+ <int key="NSvFlags">274</int>
+ <string key="NSFrame">{{0, 20}, {320, 460}}</string>
+ <reference key="NSSuperview" />
+ <reference key="NSWindow" />
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ <object class="NSColorSpace" key="NSCustomColorSpace">
+ <int key="NSID">2</int>
+ </object>
+ </object>
+ <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics" />
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ </array>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <array class="NSMutableArray" key="connectionRecords">
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">view</string>
+ <reference key="source" ref="372490531" />
+ <reference key="destination" ref="191373211" />
+ </object>
+ <int key="connectionID">3</int>
+ </object>
+ </array>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <array key="orderedObjects">
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <array key="object" id="0" />
+ <reference key="children" ref="1000" />
+ <nil key="parent" />
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">1</int>
+ <reference key="object" ref="191373211" />
+ <reference key="parent" ref="0" />
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="372490531" />
+ <reference key="parent" ref="0" />
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="975951072" />
+ <reference key="parent" ref="0" />
+ </object>
+ </array>
+ </object>
+ <dictionary class="NSMutableDictionary" key="flattenedProperties">
+ <string key="-1.CustomClassName">AsyncExtrasController</string>
+ <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="-2.CustomClassName">UIResponder</string>
+ <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="unlocalizedProperties" />
+ <nil key="activeLocalization" />
+ <dictionary class="NSMutableDictionary" key="localizations" />
+ <nil key="sourceID" />
+ <int key="maxID">3</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">AsyncExtrasController</string>
+ <string key="superclassName">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">AsyncExtrasController.h</string>
+ </object>
+ </object>
+ </array>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <string key="IBCocoaTouchPluginVersion">916</string>
+ </data>
+</archive>
Oops, something went wrong.

0 comments on commit cee96ab

Please sign in to comment.