Permalink
Browse files

Merge pull request #215 from reactiveui/xamarin-mobile

Create Suspension Hosts for iOS and Android
  • Loading branch information...
Paul Betts
Paul Betts committed Apr 9, 2013
2 parents d19c8c4 + 6f133ff commit ceadaa15e28be1b13922551b048488e1eee04e88
Showing with 11,243 additions and 210 deletions.
  1. +112 −0 AndroidPlayground/AndroidPlayground.csproj
  2. +67 −0 AndroidPlayground/App.cs
  3. +21 −0 AndroidPlayground/AppBootstrapper.cs
  4. +19 −0 AndroidPlayground/Assets/AboutAssets.txt
  5. +112 −0 AndroidPlayground/MainActivity.cs
  6. +6 −0 AndroidPlayground/Properties/AndroidManifest.xml
  7. +28 −0 AndroidPlayground/Properties/AssemblyInfo.cs
  8. +44 −0 AndroidPlayground/Resources/AboutResources.txt
  9. +2,064 −0 AndroidPlayground/Resources/Resource.designer.cs
  10. BIN AndroidPlayground/Resources/drawable/Icon.png
  11. +11 −0 AndroidPlayground/Resources/layout/Main.axml
  12. +14 −0 AndroidPlayground/Resources/layout/Secondary.axml
  13. +5 −0 AndroidPlayground/Resources/values/Strings.xml
  14. +103 −0 AndroidPlayground/SecondaryActivity.cs
  15. +77 −0 ReactiveUI.Android/ActivityRoutedViewHost.cs
  16. +12 −0 ReactiveUI.Android/ReactiveUI.Android.csproj
  17. +1 −0 ReactiveUI.Cocoa/ReactiveUI.Cocoa_Monotouch.csproj
  18. +80 −0 ReactiveUI.Cocoa/RouterUINavigationController.cs
  19. +8 −2 ReactiveUI.Cocoa/TargetActionCommandBinder.cs
  20. +141 −0 ReactiveUI.Mobile/AutoSuspendActivityHelper.cs
  21. +149 −0 ReactiveUI.Mobile/AutoSuspendAppDelegate.cs
  22. +42 −0 ReactiveUI.Mobile/BundleSuspensionDriver.cs
  23. +9 −0 ReactiveUI.Mobile/Geolocation.cs
  24. +62 −0 ReactiveUI.Mobile/JsonSuspensionDriver.cs
  25. +160 −0 ReactiveUI.Mobile/ReactiveUI.Mobile_Monodroid.csproj
  26. +93 −0 ReactiveUI.Mobile/ReactiveUI.Mobile_Monotouch.csproj
  27. +6 −0 ReactiveUI.Mobile/ServiceLocationRegistration.cs
  28. +17 −3 ReactiveUI.Mobile/SuspensionHost.cs
  29. +2 −0 ReactiveUI/Properties/AssemblyInfo.cs
  30. +8 −0 ReactiveUI/ReactiveUI_Monodroid.csproj
  31. +6 −1 ReactiveUI/ReactiveUI_Monotouch.csproj
  32. +7 −1 ReactiveUI_Android.sln
  33. +426 −0 ReactiveUI_Mono.sln
  34. +18 −0 ReactiveUI_Monotouch.sln
  35. BIN ext/WP80/Xamarin.Mobile.dll
  36. +54 −29 ext/WP80/Xamarin.Mobile.xml
  37. BIN ext/ios/Xamarin.Mobile.dll
  38. +1,480 −0 ext/ios/Xamarin.Mobile.xml
  39. BIN ext/monodroid/ActionBarSherlock.dll
  40. BIN ext/monodroid/Xamarin.Mobile.dll
  41. +1,480 −0 ext/monodroid/Xamarin.Mobile.xml
  42. BIN ext/winrt/Xamarin.Mobile.dll
  43. +54 −29 ext/winrt/Xamarin.Mobile.xml
  44. +67 −0 iOSPlayground/AppBootstrapper.cs
  45. +32 −19 iOSPlayground/AppDelegate.cs
  46. +2 −0 iOSPlayground/Info.plist
  47. +3,865 −0 iOSPlayground/TinyIoC.cs
  48. +8 −0 iOSPlayground/iOSPlayground.csproj
  49. +48 −2 iOSPlayground/iOSPlaygroundViewController.cs
  50. +16 −8 iOSPlayground/iOSPlaygroundViewController.designer.cs
  51. +207 −116 iOSPlayground/iOSPlaygroundViewController.xib
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{D444AA58-1C6B-4CEE-B5F5-76145E0B86E5}</ProjectGuid>
+ <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <RootNamespace>AndroidPlayground</RootNamespace>
+ <AndroidApplication>True</AndroidApplication>
+ <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
+ <AndroidResgenClass>Resource</AndroidResgenClass>
+ <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
+ <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
+ <AssemblyName>AndroidPlayground</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <AndroidLinkMode>None</AndroidLinkMode>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <AndroidLinkMode>SdkOnly</AndroidLinkMode>
+ <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ <Reference Include="Mono.Android" />
+ <Reference Include="ActionBarSherlock">
+ <HintPath>..\ext\monodroid\ActionBarSherlock.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Core">
+ <HintPath>..\ext\monodroid\System.Reactive.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Interfaces">
+ <HintPath>..\ext\monodroid\System.Reactive.Interfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Linq">
+ <HintPath>..\ext\monodroid\System.Reactive.Linq.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.PlatformServices">
+ <HintPath>..\ext\monodroid\System.Reactive.PlatformServices.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Providers">
+ <HintPath>..\ext\monodroid\System.Reactive.Providers.dll</HintPath>
+ </Reference>
+ <Reference Include="Xamarin.Mobile">
+ <HintPath>..\ext\monodroid\Xamarin.Mobile.dll</HintPath>
+ </Reference>
+ <Reference Include="Mono.Android.Support.v4" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="MainActivity.cs" />
+ <Compile Include="Resources\Resource.designer.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="SecondaryActivity.cs" />
+ <Compile Include="AppBootstrapper.cs" />
+ <Compile Include="App.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\AboutResources.txt" />
+ <None Include="Assets\AboutAssets.txt" />
+ <None Include="Properties\AndroidManifest.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <AndroidResource Include="Resources\layout\Main.axml" />
+ <AndroidResource Include="Resources\values\Strings.xml" />
+ <AndroidResource Include="Resources\drawable\Icon.png" />
+ <AndroidResource Include="Resources\layout\Secondary.axml" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
+ <ItemGroup>
+ <ProjectReference Include="..\ReactiveUI.Android\ReactiveUI.Android.csproj">
+ <Project>{F5A6E11B-B074-4A0B-B937-267D840E31DF}</Project>
+ <Name>ReactiveUI.Android</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ReactiveUI.Routing\ReactiveUI.Routing_Monodroid.csproj">
+ <Project>{E92E477B-BB94-43C1-984E-E177EF9FEDB7}</Project>
+ <Name>ReactiveUI.Routing_Monodroid</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ReactiveUI.Xaml\ReactiveUI.Xaml_Monodroid.csproj">
+ <Project>{E92A477B-BB94-43C1-984E-E177EF9FEDB7}</Project>
+ <Name>ReactiveUI.Xaml_Monodroid</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ReactiveUI\ReactiveUI_Monodroid.csproj">
+ <Project>{F92A477B-BB94-43C1-984E-E177EF9FEDB7}</Project>
+ <Name>ReactiveUI_Monodroid</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ReactiveUI.Mobile\ReactiveUI.Mobile_Monodroid.csproj">
+ <Project>{A92E477B-BB94-43C1-984E-E177EF9FEDB1}</Project>
+ <Name>ReactiveUI.Mobile_Monodroid</Name>
+ </ProjectReference>
+ </ItemGroup>
+</Project>
View
@@ -0,0 +1,67 @@
+using System;
+using ReactiveUI;
+using System.Collections.Generic;
+using System.Linq;
+using ReactiveUI.Routing;
+
+namespace AndroidPlayground
+{
+ public class App
+ {
+ static App _Current;
+ public static App Current {
+ get { return (_Current = _Current ?? new App()); }
+ }
+
+ public FuncServiceLocator Locator { get; protected set; }
+
+ protected App()
+ {
+ var locator = new FuncServiceLocator();
+
+ RxApp.ConfigureServiceLocator(
+ (t,s) => locator.GetAllServices(t,s).FirstOrDefault(),
+ (t,s) => locator.GetAllServices(t,s).ToArray(),
+ (c,t,s) => locator.Register(() => Activator.CreateInstance(c), t, s));
+
+ locator.Register(() => typeof(MainView), typeof(IViewFor<MainViewModel>));
+ locator.Register(() => typeof(SecondaryView), typeof(IViewFor<SecondaryViewModel>));
+
+ RxApp.Register(typeof(AppBootstrapper), typeof(IApplicationRootState));
+
+ Locator = locator;
+ }
+ }
+
+ public class FuncServiceLocator
+ {
+ readonly Dictionary<Tuple<Type, string>, List<Func<object>>> _registry = new Dictionary<Tuple<Type, string>, List<Func<object>>>();
+
+ public void Register(Func<object> factory, Type type, string contract = null)
+ {
+ var pair = Tuple.Create(type, contract ?? "");
+ if (!_registry.ContainsKey(pair)) _registry[pair] = new List<Func<object>>();
+
+ _registry[pair].Add(factory);
+ }
+
+ public IEnumerable<object> GetAllServices(Type type, string contract = null)
+ {
+ var pair = Tuple.Create(type, contract ?? "");
+ if (!_registry.ContainsKey(pair)) {
+ return Enumerable.Empty<object>();
+ }
+
+ return _registry[pair].Select(x => x());
+ }
+
+ public void ClearRegistration(Type type, string contract = null)
+ {
+ var pair = Tuple.Create(type, contract ?? "");
+ if (_registry.ContainsKey(pair)) {
+ _registry.Remove(pair);
+ }
+ }
+ }
+}
+
@@ -0,0 +1,21 @@
+using System;
+using ReactiveUI.Routing;
+using ReactiveUI.Mobile;
+
+namespace AndroidPlayground
+{
+ public class AppBootstrapper : IApplicationRootState
+ {
+ public IRoutingState Router { get; protected set; }
+
+ public AppBootstrapper()
+ {
+ Router = new RoutingState();
+ Router.Navigate.Execute(new MainViewModel(this));
+
+ App.Current.Locator.Register(() => this, typeof(IScreen));
+ App.Current.Locator.Register(() => this, typeof(IApplicationRootState));
+ }
+ }
+}
+
@@ -0,0 +1,19 @@
+Any raw assets you want to be deployed with your application can be placed in
+this directory (and child directories) and given a Build Action of "AndroidAsset".
+
+These files will be deployed with you package and will be accessible using Android's
+AssetManager, like this:
+
+public class ReadAsset : Activity
+{
+ protected override void OnCreate (Bundle bundle)
+ {
+ base.OnCreate (bundle);
+
+ InputStream input = Assets.Open ("my_asset.txt");
+ }
+}
+
+Additionally, some Android functions will automatically load asset files:
+
+Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
@@ -0,0 +1,112 @@
+using System;
+
+using Android.App;
+using Android.Content;
+using Android.Runtime;
+using Android.Views;
+using Android.Widget;
+using Android.OS;
+using ActionbarSherlock.App;
+using ReactiveUI;
+using ReactiveUI.Routing;
+using System.ComponentModel;
+using ReactiveUI.Android;
+using ReactiveUI.Mobile;
+
+namespace AndroidPlayground
+{
+ [Activity (Label = "AndroidPlayground", MainLauncher = true)]
+ public class MainView : SherlockActivity, IViewFor<MainViewModel>, INotifyPropertyChanged
+ {
+ int count = 1;
+ readonly ActivityRoutedViewHost routeHelper;
+ readonly AutoSuspendActivityHelper suspendHelper;
+
+ #region Boring copy-paste code I want to die
+ MainViewModel _ViewModel;
+ public MainViewModel ViewModel {
+ get { return _ViewModel; }
+ set {
+ if (_ViewModel == value) return;
+ _ViewModel = value;
+ if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ViewModel"));
+ }
+ }
+
+ object IViewFor.ViewModel {
+ get { return ViewModel; }
+ set { ViewModel = (MainViewModel)value; }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ #endregion
+
+ public MainView()
+ {
+ // NB: This is dumb.
+ Console.WriteLine(App.Current);
+ RxApp.DeferredScheduler = new AndroidUIScheduler(this);
+
+ suspendHelper = new AutoSuspendActivityHelper(this);
+ suspendHelper.SuspensionHost.SetupDefaultSuspendResume();
+
+ routeHelper = new ActivityRoutedViewHost(this);
+ }
+
+ protected override void OnCreate(Bundle bundle)
+ {
+ base.OnCreate(bundle);
+ suspendHelper.OnCreate(bundle);
+
+ // Set our view from the "main" layout resource
+ SetContentView(Resource.Layout.Main);
+
+ // Get our button from the layout resource,
+ // and attach an event to it
+ Button button = FindViewById<Button>(Resource.Id.myButton);
+
+ button.Click += (o,e) => {
+ ViewModel.HostScreen.Router.Navigate.Execute(new SecondaryViewModel(ViewModel.HostScreen));
+ };
+
+ this.OneWayBind(ViewModel, x => x.UrlPathSegment, x => x.ActionBar.Title);
+ }
+
+ public override bool OnKeyUp(Keycode keyCode, KeyEvent e)
+ {
+ return routeHelper.OnKeyUp(keyCode, e);
+ }
+
+ protected override void OnResume()
+ {
+ base.OnResume();
+ suspendHelper.OnResume();
+ }
+
+ protected override void OnPause()
+ {
+ base.OnPause();
+ suspendHelper.OnPause();
+ }
+
+ protected override void OnSaveInstanceState(Bundle outState)
+ {
+ base.OnSaveInstanceState(outState);
+ suspendHelper.OnSaveInstanceState(outState);
+ }
+ }
+
+ public class MainViewModel : ReactiveObject, IRoutableViewModel
+ {
+ public string UrlPathSegment {
+ get { return "Main!"; }
+ }
+
+ public IScreen HostScreen { get; protected set; }
+
+ public MainViewModel(IScreen hostScreen)
+ {
+ HostScreen = hostScreen ?? RxApp.GetService<IScreen>();
+ }
+ }
+}
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="AndroidPlayground.AndroidPlayground">
+ <uses-sdk />
+ <application android:label="AndroidPlayground">
+ </application>
+</manifest>
@@ -0,0 +1,28 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using Android.App;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("AndroidPlayground")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("paul")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.0")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
Oops, something went wrong.

0 comments on commit ceadaa1

Please sign in to comment.